[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pspp-cvs] pspp/src/data ChangeLog filename.c
From: |
Ben Pfaff |
Subject: |
[Pspp-cvs] pspp/src/data ChangeLog filename.c |
Date: |
Sun, 16 Apr 2006 23:35:22 +0000 |
CVSROOT: /cvsroot/pspp
Module name: pspp
Branch:
Changes by: Ben Pfaff <address@hidden> 06/04/16 23:35:20
Modified files:
src/data : ChangeLog filename.c
Log message:
* filename.c: (fn_tilde_expand) Rewrite for cleaner code. Also, now
it only tilde-expands file names, not paths.
(fn_search_path) Tilde-expand one directory at a time.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/data/ChangeLog.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/data/filename.c.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
Patches:
Index: pspp/src/data/ChangeLog
diff -u pspp/src/data/ChangeLog:1.14 pspp/src/data/ChangeLog:1.15
--- pspp/src/data/ChangeLog:1.14 Sun Apr 16 23:08:02 2006
+++ pspp/src/data/ChangeLog Sun Apr 16 23:35:19 2006
@@ -1,16 +1,26 @@
-Sun Apr 16 16:05:28 2006 Ben Pfaff <address@hidden>
+Sun Apr 16 16:33:58 2006 Ben Pfaff <address@hidden>
- Continue reforming error message support. In this phase, we get
- rid of VM() and the other msg() support for "verbosity", replacing
- it by a new function verbose_msg().
+ * filename.c: (fn_tilde_expand) Rewrite for cleaner code.
+ Also, now it only tilde-expands file names, not paths.
+ (fn_search_path) Tilde-expand one directory at a time.
+
+Sun Apr 16 16:28:06 2006 Ben Pfaff <address@hidden>
- * filename.c: (fn_search_path) Rewrite for cleaner code. Also,
+ * filename.c: (fn_search_path) rewrite for cleaner code. Also,
get rid of non-Unixlike version of the code, which has probably
never been tested.
(fn_prepend_dir) Removed (dead code).
* filename.h: (macro DIR_SEPARATOR_STRING) New.
(macro PATH_SEPARATOR_STRING) New.
+Sun Apr 16 16:05:28 2006 Ben Pfaff <address@hidden>
+
+ Continue reforming error message support. In this phase, we get
+ rid of VM() and the other msg() support for "verbosity", replacing
+ it by a new function verbose_msg().
+
+ * filename.c: (fn_search_path) Use verbose_msg() instead of
+ msg(VM(), ...).
Sat Apr 15 19:53:19 2006 Ben Pfaff <address@hidden>
Index: pspp/src/data/filename.c
diff -u pspp/src/data/filename.c:1.9 pspp/src/data/filename.c:1.10
--- pspp/src/data/filename.c:1.9 Sun Apr 16 23:08:02 2006
+++ pspp/src/data/filename.c Sun Apr 16 23:35:20 2006
@@ -160,53 +160,40 @@
char *
fn_tilde_expand (const char *input)
{
- const char *ip;
- struct string output;
-
- if (NULL == strchr (input, '~'))
- return xstrdup (input);
- ds_init (&output, strlen (input));
-
- ip = input;
-
- for (ip = input; *ip; )
- if (*ip != '~' || (ip != input && ip[-1] != PATH_DELIMITER))
- ds_putc (&output, *ip++);
- else
- {
- static const char stop_set[3] = {DIR_SEPARATOR, PATH_DELIMITER, 0};
- const char *cp;
-
- ip++;
-
- cp = ip + strcspn (ip, stop_set);
-
- if (cp > ip)
- {
- struct passwd *pwd;
- char username[9];
-
- strncpy (username, ip, cp - ip + 1);
- username[8] = 0;
- pwd = getpwnam (username);
-
- if (!pwd || !pwd->pw_dir)
- ds_putc (&output, *ip++);
- else
- ds_puts (&output, pwd->pw_dir);
- }
- else
- {
- const char *home = fn_getenv ("HOME");
- if (!home)
- ds_putc (&output, *ip++);
- else
- ds_puts (&output, home);
- }
-
- ip = cp;
- }
-
+ struct string output = DS_INITIALIZER;
+ if (input[0] == '~')
+ {
+ const char *home = NULL;
+ const char *remainder = NULL;
+ if (input[1] == '/' || input[1] == '\0')
+ {
+ home = fn_getenv ("HOME");
+ remainder = input + 1;
+ }
+ else
+ {
+ struct string user_name = DS_INITIALIZER;
+ struct passwd *pwd;
+
+ ds_assign_buffer (&user_name, input + 1, strcspn (input + 1, "/"));
+ pwd = getpwnam (ds_c_str (&user_name));
+ if (pwd != NULL && pwd->pw_dir[0] != '\0')
+ {
+ home = pwd->pw_dir;
+ remainder = input + 1 + ds_length (&user_name);
+ }
+ ds_destroy (&user_name);
+ }
+
+ if (home != NULL)
+ {
+ ds_puts (&output, home);
+ if (*remainder != '\0')
+ ds_puts (&output, remainder);
+ }
+ }
+ if (ds_is_empty (&output))
+ ds_puts (&output, input);
return ds_c_str (&output);
}
#else /* !unix */
@@ -232,24 +219,27 @@
struct string path;
struct string dir = DS_INITIALIZER;
struct string file = DS_INITIALIZER;
- char *tmp_str;
size_t save_idx = 0;
if (fn_absolute_p (base_name))
return fn_tilde_expand (base_name);
- /* Interpolate environment variables and do tilde-expansion. */
+ /* Interpolate environment variables. */
ds_create (&path, path_);
fn_interp_vars (&path, fn_getenv);
- tmp_str = fn_tilde_expand (ds_c_str (&path));
- ds_assign_c_str (&path, tmp_str);
- free (tmp_str);
-
verbose_msg (2, _("searching for \"%s\" in path \"%s\""),
base_name, ds_c_str (&path));
while (ds_separate (&path, &dir, PATH_DELIMITER_STRING, &save_idx))
{
+ /* Do tilde expansion. */
+ if (ds_first (&dir) == '~')
+ {
+ char *tmp_str = fn_tilde_expand (ds_c_str (&dir));
+ ds_assign_c_str (&dir, tmp_str);
+ free (tmp_str);
+ }
+
/* Construct file name. */
ds_clear (&file);
if (prefix != NULL && !fn_absolute_p (ds_c_str (&dir)))