diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2003-01-17 17:05:57 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2003-01-17 17:05:57 +0000 |
commit | c09389519e3b83e995e8ea30e1bc424e55c437ba (patch) | |
tree | ceadd73b0818fe3273b9daa4a92dbd95d20183b1 /indep.c | |
parent | fix indent (diff) | |
download | w3m-c09389519e3b83e995e8ea30e1bc424e55c437ba.tar.gz w3m-c09389519e3b83e995e8ea30e1bc424e55c437ba.zip |
[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>
Diffstat (limited to '')
-rw-r--r-- | indep.c | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -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; + } + else { /* ~user */ + passent = getpwnam(p); + p = ""; } - Strcat_charp(extpath, passent->pw_dir); + 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 |