Set rc_dir
based on W3M_DIR
environment variable.
By default, w3m puts all of its data in the `~/.w3m/` directory (creating it as necessary). This was not configurable in any way. This commit adds some quick reconfigurability -- when the "W3M_DIR" environment variable is set, w3m will use that location instead. The default location is unchanged. Fixes #130.
This commit is contained in:
@@ -725,7 +725,7 @@ from Tatsuya Kinoshita <tats@debian.org>
|
|||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<p>
|
<p>
|
||||||
It is ~/.w3m/config.
|
By default, it is ~/.w3m/config.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@@ -734,6 +734,12 @@ from Tatsuya Kinoshita <tats@debian.org>
|
|||||||
setting panel. Each line contains one option setting, consisting
|
setting panel. Each line contains one option setting, consisting
|
||||||
of an option name and its value with a space as a separator.
|
of an option name and its value with a space as a separator.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If the W3M_DIR environment variable is set to the name of a
|
||||||
|
directory, w3m will store its files in that directory instead of
|
||||||
|
in ~/.w3m.
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>Without a user-specific configuration file, w3m honours
|
<p>Without a user-specific configuration file, w3m honours
|
||||||
the system wide configuration file /etc/w3m/config.
|
the system wide configuration file /etc/w3m/config.
|
||||||
|
@@ -91,6 +91,11 @@ insertions tagged with "mh 2016-03-29" and "mh 2016-06-11" come from the latest
|
|||||||
from standard input and display it. If it doesn't find a document
|
from standard input and display it. If it doesn't find a document
|
||||||
there either then normally w3m will terminate.
|
there either then normally w3m will terminate.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
You can change how w3m behaves by providing it with options, either
|
||||||
|
via the command line or through the configuration file. The user
|
||||||
|
config file is located at $W3M_DIR/config (~/.w3m/config by default).
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Options include:
|
Options include:
|
||||||
</p>
|
</p>
|
||||||
|
11
doc/w3m.1
11
doc/w3m.1
@@ -266,9 +266,16 @@ $ w3m \-v
|
|||||||
.EE
|
.EE
|
||||||
.\".SH Errors
|
.\".SH Errors
|
||||||
.SH ENVIRONMENT
|
.SH ENVIRONMENT
|
||||||
\fIw3m\fP recognises the environment variable WWW_HOME as defining a
|
\fIw3m\fP recognises the environment variable \fBWWW_HOME\fP as
|
||||||
fallback target for use if it is invoked without one.
|
defining a fallback target for use if it is invoked without one.
|
||||||
|
|
||||||
|
If the \fBW3M_DIR\fP environment variable is set to a directory
|
||||||
|
name, \fIw3m\fP will store its user files there instead of
|
||||||
|
under the ~/.w3m directory.
|
||||||
.SH FILES
|
.SH FILES
|
||||||
|
The default locations of some files are listed below. These
|
||||||
|
locations can be altered via the \fBW3M_DIR\fP environment
|
||||||
|
variable.
|
||||||
.TP
|
.TP
|
||||||
\f(CW~/.w3m/bookmark.html\fP
|
\f(CW~/.w3m/bookmark.html\fP
|
||||||
default bookmark file
|
default bookmark file
|
||||||
|
84
rc.c
84
rc.c
@@ -1238,6 +1238,58 @@ do_mkdir(const char *dir, long mode)
|
|||||||
#endif /* not __MINW32_VERSION */
|
#endif /* not __MINW32_VERSION */
|
||||||
#endif /* not __EMX__ */
|
#endif /* not __EMX__ */
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_recursive_mkdir(const char *dir)
|
||||||
|
{
|
||||||
|
char *ch, *dircpy, tmp;
|
||||||
|
size_t n;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
n = strlen(dir);
|
||||||
|
if (n == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ((dircpy = malloc(n + 1)) == NULL)
|
||||||
|
return -1;
|
||||||
|
strcpy(dircpy, dir);
|
||||||
|
|
||||||
|
ch = dircpy + 1;
|
||||||
|
do {
|
||||||
|
while (!(*ch == '/' || *ch == '\0')) {
|
||||||
|
ch++;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = *ch;
|
||||||
|
*ch = '\0';
|
||||||
|
|
||||||
|
if (stat(dircpy, &st) < 0) {
|
||||||
|
if (errno != ENOENT) { /* no directory */
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
if (do_mkdir(dircpy, 0700) < 0) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
stat(dircpy, &st);
|
||||||
|
}
|
||||||
|
if (!S_ISDIR(st.st_mode)) {
|
||||||
|
/* not a directory */
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
if (!(st.st_mode & S_IWUSR)) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ch = tmp;
|
||||||
|
|
||||||
|
} while (*ch++ != '\0');
|
||||||
|
|
||||||
|
free(dircpy);
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
free(dircpy);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static void loadSiteconf(void);
|
static void loadSiteconf(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1298,13 +1350,16 @@ void
|
|||||||
init_rc(void)
|
init_rc(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct stat st;
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if (rc_dir != NULL)
|
if (rc_dir != NULL)
|
||||||
goto open_rc;
|
goto open_rc;
|
||||||
|
|
||||||
rc_dir = expandPath(RC_DIR);
|
if ((rc_dir = getenv("W3M_DIR")) == NULL || *rc_dir == '\0') {
|
||||||
|
rc_dir = RC_DIR;
|
||||||
|
}
|
||||||
|
rc_dir = expandPath(rc_dir);
|
||||||
|
|
||||||
i = strlen(rc_dir);
|
i = strlen(rc_dir);
|
||||||
if (i > 1 && rc_dir[i - 1] == '/')
|
if (i > 1 && rc_dir[i - 1] == '/')
|
||||||
rc_dir[i - 1] = '\0';
|
rc_dir[i - 1] = '\0';
|
||||||
@@ -1315,30 +1370,9 @@ init_rc(void)
|
|||||||
system_charset_str = display_charset_str;
|
system_charset_str = display_charset_str;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (stat(rc_dir, &st) < 0) {
|
if (do_recursive_mkdir(rc_dir) == -1)
|
||||||
if (errno == ENOENT) { /* no directory */
|
|
||||||
if (do_mkdir(rc_dir, 0700) < 0) {
|
|
||||||
/* fprintf(stderr, "Can't create config directory (%s)!\n", rc_dir); */
|
|
||||||
goto rc_dir_err;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stat(rc_dir, &st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* fprintf(stderr, "Can't open config directory (%s)!\n", rc_dir); */
|
|
||||||
goto rc_dir_err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!S_ISDIR(st.st_mode)) {
|
|
||||||
/* not a directory */
|
|
||||||
/* fprintf(stderr, "%s is not a directory!\n", rc_dir); */
|
|
||||||
goto rc_dir_err;
|
goto rc_dir_err;
|
||||||
}
|
|
||||||
if (!(st.st_mode & S_IWUSR)) {
|
|
||||||
/* fprintf(stderr, "%s is not writable!\n", rc_dir); */
|
|
||||||
goto rc_dir_err;
|
|
||||||
}
|
|
||||||
no_rc_dir = FALSE;
|
no_rc_dir = FALSE;
|
||||||
tmp_dir = rc_dir;
|
tmp_dir = rc_dir;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user