[w3m-dev 03647] expandName() and expandPath()
* etc.c (openSecretFile): use expandPath (expandName): rewrite (file_to_url): use expandPath * file.c (_doFileCopy): use expandPath (doFileSave): use expandPath * indep.c (expandPath): rewrite * linein.c (inputLineHistSearch): use expandPath (next_dcompl): use expandPath (doComplete): use expandPath * local.c (set_cgi_environ): rewrite * mailcap.c (loadMailcap): use expandPath * main.c (svBuf): use expandPath (addDownloadList): use expandPath * rc.c (init_rc): use expandPath (rcFile): rewrite (auxbinFile): use expandPath (libFile): use expandPath (etcFile): use expandPath (helpFile): use expandPath * url.c (loadMimeTypes): use expandPath (loadURIMethods): use expandPath From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
This commit is contained in:
@@ -1,3 +1,28 @@
|
||||
2003-01-18 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
|
||||
|
||||
* [w3m-dev 03647] expandName() and expandPath()
|
||||
* etc.c (openSecretFile): use expandPath
|
||||
(expandName): rewrite
|
||||
(file_to_url): use expandPath
|
||||
* file.c (_doFileCopy): use expandPath
|
||||
(doFileSave): use expandPath
|
||||
* indep.c (expandPath): rewrite
|
||||
* linein.c (inputLineHistSearch): use expandPath
|
||||
(next_dcompl): use expandPath
|
||||
(doComplete): use expandPath
|
||||
* local.c (set_cgi_environ): rewrite
|
||||
* mailcap.c (loadMailcap): use expandPath
|
||||
* main.c (svBuf): use expandPath
|
||||
(addDownloadList): use expandPath
|
||||
* rc.c (init_rc): use expandPath
|
||||
(rcFile): rewrite
|
||||
(auxbinFile): use expandPath
|
||||
(libFile): use expandPath
|
||||
(etcFile): use expandPath
|
||||
(helpFile): use expandPath
|
||||
* url.c (loadMimeTypes): use expandPath
|
||||
(loadURIMethods): use expandPath
|
||||
|
||||
2003-01-18 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
|
||||
|
||||
* [w3m-dev 03646] setup child process, local CGI
|
||||
@@ -6553,4 +6578,4 @@ a * [w3m-dev 03276] compile error on EWS4800
|
||||
* release-0-2-1
|
||||
* import w3m-0.2.1
|
||||
|
||||
$Id: ChangeLog,v 1.686 2003/01/17 16:57:17 ukai Exp $
|
||||
$Id: ChangeLog,v 1.687 2003/01/17 17:05:57 ukai Exp $
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: etc.c,v 1.50 2003/01/17 16:57:18 ukai Exp $ */
|
||||
/* $Id: etc.c,v 1.51 2003/01/17 17:06:00 ukai Exp $ */
|
||||
#include "fm.h"
|
||||
#include <pwd.h>
|
||||
#include "myctype.h"
|
||||
@@ -1046,10 +1046,13 @@ parsePasswd(FILE * fp, int netrc)
|
||||
FILE *
|
||||
openSecretFile(char *fname)
|
||||
{
|
||||
char *efname;
|
||||
struct stat st;
|
||||
|
||||
if (fname == NULL)
|
||||
return NULL;
|
||||
if (stat(expandName(fname), &st) < 0)
|
||||
efname = expandPath(fname);
|
||||
if (stat(efname, &st) < 0)
|
||||
return NULL;
|
||||
|
||||
/* check permissions, if group or others readable or writable,
|
||||
@@ -1076,7 +1079,7 @@ openSecretFile(char *fname)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fopen(expandName(fname), "r");
|
||||
return fopen(efname, "r");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1429,35 +1432,44 @@ myEditor(char *cmd, char *file, int line)
|
||||
char *
|
||||
expandName(char *name)
|
||||
{
|
||||
Str userName = NULL;
|
||||
char *p;
|
||||
struct passwd *passent, *getpwnam(const char *);
|
||||
Str extpath = Strnew();
|
||||
Str extpath = NULL;
|
||||
|
||||
if (name == NULL)
|
||||
return NULL;
|
||||
p = name;
|
||||
if (*p == '/' && *(p + 1) == '~' && IS_ALPHA(*(p + 2))) {
|
||||
if (personal_document_root != NULL) {
|
||||
userName = Strnew();
|
||||
if (*p == '/') {
|
||||
if (*(p + 1) == '~' && IS_ALPHA(*(p + 2)) && personal_document_root) {
|
||||
char *q;
|
||||
p += 2;
|
||||
while (IS_ALNUM(*p) || *p == '_' || *p == '-')
|
||||
Strcat_char(userName, *(p++));
|
||||
passent = getpwnam(userName->ptr);
|
||||
if (passent == NULL) {
|
||||
p = name;
|
||||
goto rest;
|
||||
q = strchr(p, '/');
|
||||
if (q) { /* /~user/dir... */
|
||||
passent = getpwnam(allocStr(p, q - p));
|
||||
p = q;
|
||||
}
|
||||
Strcat_charp(extpath, passent->pw_dir);
|
||||
Strcat_char(extpath, '/');
|
||||
Strcat_charp(extpath, personal_document_root);
|
||||
if (Strcmp_charp(extpath, "/") == 0 && *p == '/')
|
||||
else { /* /~user */
|
||||
passent = getpwnam(p);
|
||||
p = "";
|
||||
}
|
||||
if (!passent)
|
||||
goto rest;
|
||||
extpath = Strnew_m_charp(passent->pw_dir, "/",
|
||||
personal_document_root, NULL);
|
||||
if (*personal_document_root == '\0' && *p == '/')
|
||||
p++;
|
||||
}
|
||||
else
|
||||
goto rest;
|
||||
if (Strcmp_charp(extpath, "/") == 0 && *p == '/')
|
||||
p++;
|
||||
Strcat_charp(extpath, p);
|
||||
return extpath->ptr;
|
||||
}
|
||||
else
|
||||
p = expandPath(p);
|
||||
return expandPath(p);
|
||||
rest:
|
||||
Strcat_charp(extpath, p);
|
||||
return extpath->ptr;
|
||||
return name;
|
||||
}
|
||||
|
||||
char *
|
||||
@@ -1471,7 +1483,7 @@ file_to_url(char *file)
|
||||
char *host = NULL;
|
||||
#endif
|
||||
|
||||
file = expandName(file);
|
||||
file = expandPath(file);
|
||||
#ifdef SUPPORT_NETBIOS_SHARE
|
||||
if (file[0] == '/' && file[1] == '/') {
|
||||
char *p;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: file.c,v 1.188 2003/01/17 16:57:19 ukai Exp $ */
|
||||
/* $Id: file.c,v 1.189 2003/01/17 17:06:01 ukai Exp $ */
|
||||
#include "fm.h"
|
||||
#include <sys/types.h>
|
||||
#include "myctype.h"
|
||||
@@ -7454,7 +7454,7 @@ _doFileCopy(char *tmpf, char *defstr, int download)
|
||||
p = unescape_spaces(Strnew_charp(q))->ptr;
|
||||
p = conv_to_system(q);
|
||||
}
|
||||
p = expandName(p);
|
||||
p = expandPath(p);
|
||||
if (checkOverWrite(p) < 0)
|
||||
return -1;
|
||||
}
|
||||
@@ -7511,7 +7511,7 @@ _doFileCopy(char *tmpf, char *defstr, int download)
|
||||
if (*p == '|' && PermitSaveToPipe)
|
||||
is_pipe = TRUE;
|
||||
else {
|
||||
p = expandName(p);
|
||||
p = expandPath(p);
|
||||
if (checkOverWrite(p) < 0)
|
||||
return -1;
|
||||
}
|
||||
@@ -7606,7 +7606,7 @@ doFileSave(URLFile uf, char *defstr)
|
||||
*(p + 1) = '\0';
|
||||
if (*q == '\0')
|
||||
return -1;
|
||||
p = expandName(q);
|
||||
p = expandPath(q);
|
||||
if (checkOverWrite(p) < 0)
|
||||
return -1;
|
||||
if (checkSaveFile(uf.stream, p) < 0) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: indep.c,v 1.28 2003/01/08 17:24:12 ukai Exp $ */
|
||||
/* $Id: indep.c,v 1.29 2003/01/17 17:06:02 ukai Exp $ */
|
||||
#include "fm.h"
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
@@ -177,10 +177,9 @@ cleanupName(char *name)
|
||||
char *
|
||||
expandPath(char *name)
|
||||
{
|
||||
Str userName = NULL;
|
||||
char *p;
|
||||
struct passwd *passent, *getpwnam(const char *);
|
||||
Str extpath = Strnew();
|
||||
Str extpath = NULL;
|
||||
|
||||
if (name == NULL)
|
||||
return NULL;
|
||||
@@ -188,25 +187,31 @@ expandPath(char *name)
|
||||
if (*p == '~') {
|
||||
p++;
|
||||
if (IS_ALPHA(*p)) {
|
||||
userName = Strnew();
|
||||
while (IS_ALNUM(*p) || *p == '_' || *p == '-')
|
||||
Strcat_char(userName, *(p++));
|
||||
passent = getpwnam(userName->ptr);
|
||||
if (passent == NULL) {
|
||||
p = name;
|
||||
goto rest;
|
||||
char *q = strchr(p, '/');
|
||||
if (q) { /* ~user/dir... */
|
||||
passent = getpwnam(allocStr(p, q - p));
|
||||
p = q;
|
||||
}
|
||||
Strcat_charp(extpath, passent->pw_dir);
|
||||
else { /* ~user */
|
||||
passent = getpwnam(p);
|
||||
p = "";
|
||||
}
|
||||
if (!passent)
|
||||
goto rest;
|
||||
extpath = Strnew_charp(passent->pw_dir);
|
||||
}
|
||||
else {
|
||||
Strcat_charp(extpath, getenv("HOME"));
|
||||
else if (*p == '/' || *p == '\0') { /* ~/dir... or ~ */
|
||||
extpath = Strnew_charp(getenv("HOME"));
|
||||
}
|
||||
else
|
||||
goto rest;
|
||||
if (Strcmp_charp(extpath, "/") == 0 && *p == '/')
|
||||
p++;
|
||||
Strcat_charp(extpath, p);
|
||||
return extpath->ptr;
|
||||
}
|
||||
rest:
|
||||
Strcat_charp(extpath, p);
|
||||
return extpath->ptr;
|
||||
return name;
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRCHR
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: linein.c,v 1.25 2002/11/15 15:36:48 ukai Exp $ */
|
||||
/* $Id: linein.c,v 1.26 2003/01/17 17:06:03 ukai Exp $ */
|
||||
#include "fm.h"
|
||||
#include "local.h"
|
||||
#include "myctype.h"
|
||||
@@ -309,7 +309,7 @@ inputLineHistSearch(char *prompt, char *def_str, int flag, Hist *hist,
|
||||
pushHist(hist, p);
|
||||
}
|
||||
if (flag & IN_FILENAME)
|
||||
return expandName(p);
|
||||
return expandPath(p);
|
||||
else
|
||||
return allocStr(p, -1);
|
||||
}
|
||||
@@ -853,7 +853,7 @@ next_dcompl(int next)
|
||||
f = Strdup(d);
|
||||
Strcat_charp(f, CFileBuf[n]);
|
||||
addstr(conv_from_system(CFileBuf[n]));
|
||||
if (stat(expandName(f->ptr), &st) != -1 && S_ISDIR(st.st_mode))
|
||||
if (stat(expandPath(f->ptr), &st) != -1 && S_ISDIR(st.st_mode))
|
||||
addstr("/");
|
||||
}
|
||||
y++;
|
||||
@@ -957,7 +957,7 @@ doComplete(Str ifn, int *status, int next)
|
||||
if (Strlastchar(CompleteBuf) == '/' && CompleteBuf->length > 1) {
|
||||
Strshrink(CompleteBuf, 1);
|
||||
}
|
||||
if ((d = opendir(expandName(CompleteBuf->ptr))) == NULL) {
|
||||
if ((d = opendir(expandPath(CompleteBuf->ptr))) == NULL) {
|
||||
CompleteBuf = Strdup(ifn);
|
||||
*status = CPL_FAIL;
|
||||
if (cm_mode & CPL_ON)
|
||||
@@ -1031,7 +1031,7 @@ doComplete(Str ifn, int *status, int next)
|
||||
else if (strncmp(p, "file:/", 6) == 0 && p[6] != '/')
|
||||
p = &p[5];
|
||||
}
|
||||
if (stat(expandName(p), &st) != -1 && S_ISDIR(st.st_mode))
|
||||
if (stat(expandPath(p), &st) != -1 && S_ISDIR(st.st_mode))
|
||||
Strcat_char(CompleteBuf, '/');
|
||||
}
|
||||
if (cm_mode & CPL_ON)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: local.c,v 1.22 2003/01/17 16:57:20 ukai Exp $ */
|
||||
/* $Id: local.c,v 1.23 2003/01/17 17:06:03 ukai Exp $ */
|
||||
#include "fm.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -296,19 +296,22 @@ set_cgi_environ(char *name, char *fn, char *req_uri)
|
||||
static Str
|
||||
checkPath(char *fn, char *path)
|
||||
{
|
||||
char *p;
|
||||
Str tmp;
|
||||
struct stat st;
|
||||
while (*path) {
|
||||
tmp = Strnew();
|
||||
while (*path && *path != ':')
|
||||
Strcat_char(tmp, *path++);
|
||||
if (*path == ':')
|
||||
path++;
|
||||
p = strchr(path, ':');
|
||||
tmp = Strnew_charp(expandPath(p ? allocStr(path, p - path) : path));
|
||||
if (Strlastchar(tmp) != '/')
|
||||
Strcat_char(tmp, '/');
|
||||
Strcat_charp(tmp, fn);
|
||||
if (stat(tmp->ptr, &st) == 0)
|
||||
return tmp;
|
||||
if (!p)
|
||||
break;
|
||||
path = p + 1;
|
||||
while (*path == ':')
|
||||
path++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: mailcap.c,v 1.11 2002/12/24 17:20:47 ukai Exp $ */
|
||||
/* $Id: mailcap.c,v 1.12 2003/01/17 17:06:04 ukai Exp $ */
|
||||
#include "fm.h"
|
||||
#include "myctype.h"
|
||||
#include <stdio.h>
|
||||
@@ -187,7 +187,7 @@ loadMailcap(char *filename)
|
||||
Str tmp;
|
||||
struct mailcap *mcap;
|
||||
|
||||
f = fopen(expandName(filename), "r");
|
||||
f = fopen(expandPath(filename), "r");
|
||||
if (f == NULL)
|
||||
return NULL;
|
||||
i = 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: main.c,v 1.194 2003/01/15 17:13:22 ukai Exp $ */
|
||||
/* $Id: main.c,v 1.195 2003/01/17 17:06:04 ukai Exp $ */
|
||||
#define MAINPROGRAM
|
||||
#include "fm.h"
|
||||
#include <signal.h>
|
||||
@@ -4241,7 +4241,7 @@ svBuf(void)
|
||||
file = unescape_spaces(Strnew_charp(qfile))->ptr;
|
||||
file = conv_to_system(file);
|
||||
}
|
||||
file = expandName(file);
|
||||
file = expandPath(file);
|
||||
if (checkOverWrite(file) < 0) {
|
||||
displayBuffer(Currentbuf, B_NORMAL);
|
||||
return;
|
||||
@@ -6080,7 +6080,7 @@ addDownloadList(pid_t pid, char *url, char *save, char *lock, clen_t size)
|
||||
d->url = url;
|
||||
if (save[0] != '/' && save[0] != '~')
|
||||
save = Strnew_m_charp(CurrentDir, "/", save, NULL)->ptr;
|
||||
d->save = expandName(save);
|
||||
d->save = expandPath(save);
|
||||
d->lock = lock;
|
||||
d->size = size;
|
||||
d->time = time(0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: rc.c,v 1.76 2003/01/17 16:58:17 ukai Exp $ */
|
||||
/* $Id: rc.c,v 1.77 2003/01/17 17:06:05 ukai Exp $ */
|
||||
/*
|
||||
* Initialization file etc.
|
||||
*/
|
||||
@@ -1375,7 +1375,7 @@ init_rc(void)
|
||||
if (config_file != NULL)
|
||||
goto open_rc;
|
||||
|
||||
rc_dir = expandName(RC_DIR);
|
||||
rc_dir = expandPath(RC_DIR);
|
||||
i = strlen(rc_dir);
|
||||
if (i > 1 && rc_dir[i - 1] == '/')
|
||||
rc_dir[i - 1] = '\0';
|
||||
@@ -1580,53 +1580,35 @@ rcFile(char *base)
|
||||
(base[0] == '.'
|
||||
&& (base[1] == '/' || (base[1] == '.' && base[2] == '/')))
|
||||
|| (base[0] == '~' && base[1] == '/')))
|
||||
return expandName(base);
|
||||
else {
|
||||
Str file = Strnew_charp(rc_dir);
|
||||
|
||||
if (Strlastchar(file) != '/')
|
||||
Strcat_char(file, '/');
|
||||
Strcat_charp(file, base);
|
||||
return expandName(file->ptr);
|
||||
}
|
||||
/* /file, ./file, ../file, ~/file */
|
||||
return expandPath(base);
|
||||
return expandPath(Strnew_m_charp(rc_dir, "/", base, NULL)->ptr);
|
||||
}
|
||||
|
||||
char *
|
||||
auxbinFile(char *base)
|
||||
{
|
||||
Str file = Strnew_charp(w3m_auxbin_dir());
|
||||
Strcat_char(file, '/');
|
||||
Strcat_charp(file, base);
|
||||
return expandName(file->ptr);
|
||||
return expandPath(Strnew_m_charp(w3m_auxbin_dir(), "/", base, NULL)->ptr);
|
||||
}
|
||||
|
||||
#if 0 /* not used */
|
||||
char *
|
||||
libFile(char *base)
|
||||
{
|
||||
Str file = Strnew_charp(w3m_lib_dir());
|
||||
Strcat_char(file, '/');
|
||||
Strcat_charp(file, base);
|
||||
return expandName(file->ptr);
|
||||
return expandPath(Strnew_m_charp(w3m_lib_dir(), "/", base, NULL)->ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
char *
|
||||
etcFile(char *base)
|
||||
{
|
||||
Str file = Strnew_charp(w3m_etc_dir());
|
||||
Strcat_char(file, '/');
|
||||
Strcat_charp(file, base);
|
||||
return expandName(file->ptr);
|
||||
return expandPath(Strnew_m_charp(w3m_etc_dir(), "/", base, NULL)->ptr);
|
||||
}
|
||||
|
||||
#ifndef USE_HELP_CGI
|
||||
char *
|
||||
helpFile(char *base)
|
||||
{
|
||||
Str file = Strnew_charp(w3m_help_dir());
|
||||
Strcat_char(file, '/');
|
||||
Strcat_charp(file, base);
|
||||
return expandName(file->ptr);
|
||||
return expandPath(Strnew_m_charp(w3m_help_dir(), "/", base, NULL)->ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: url.c,v 1.68 2003/01/11 15:54:09 ukai Exp $ */
|
||||
/* $Id: url.c,v 1.69 2003/01/17 17:06:06 ukai Exp $ */
|
||||
#include "fm.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -154,7 +154,7 @@ loadMimeTypes(char *filename)
|
||||
Str tmp;
|
||||
struct table2 *mtypes;
|
||||
|
||||
f = fopen(expandName(filename), "r");
|
||||
f = fopen(expandPath(filename), "r");
|
||||
if (f == NULL)
|
||||
return NULL;
|
||||
n = 0;
|
||||
@@ -2103,7 +2103,7 @@ loadURIMethods(char *filename)
|
||||
struct table2 *um;
|
||||
char *up, *p;
|
||||
|
||||
f = fopen(expandName(filename), "r");
|
||||
f = fopen(expandPath(filename), "r");
|
||||
if (f == NULL)
|
||||
return NULL;
|
||||
i = 0;
|
||||
|
||||
Reference in New Issue
Block a user