bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] proposed diff for AWK*PATH inconsitencies


From: Aharon Robbins
Subject: [bug-gawk] proposed diff for AWK*PATH inconsitencies
Date: Tue, 14 Oct 2014 22:35:29 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Hi Andy et al.

I think this fix covers what needs doing. Please review.

Thanks,

Arnold
----------------------------
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 001dd8b..03989dc 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -4254,15 +4254,17 @@ on the command line with the @option{-f} option.
 In most @command{awk}
 implementations, you must supply a precise path name for each program
 file, unless the file is in the current directory.
-But in @command{gawk}, if the @value{FN} supplied to the @option{-f}
+But with @command{gawk}, if the @value{FN} supplied to the @option{-f}
 or @option{-i} options
 does not contain a directory separator @samp{/}, then @command{gawk} searches 
a list of
 directories (called the @dfn{search path}), one by one, looking for a
 file with the specified name.
 
 The search path is a string consisting of directory names
-separated by address@hidden on MS-Windows and MS-DOS.}.  @command{gawk} gets 
its search path from the
+separated by address@hidden on MS-Windows and MS-DOS.}
address@hidden gets its search path from the
 @env{AWKPATH} environment variable.  If that variable does not exist,
+or if it has an empty value,
 @command{gawk} uses a default path,
 @samp{.:/usr/local/share/address@hidden version of @command{gawk}
 may use a different directory; it
@@ -4297,19 +4299,19 @@ directory.
 colon or by placing two colons next to each other address@hidden::}].)
 
 @quotation NOTE
address@hidden always looks in the current directory @emph{before}
-searching @env{AWKPATH}. Thus, while you can include the current directory
-in the search path, either explicitly or with a null entry, there is no
-real reason to do so.
address@hidden Prior to 4.0, gawk searched the current directory after the
address@hidden path search, but it's not worth documenting it.
+To include the current directory in the path, either place @file{.}
+as an entry in the path or write a null entry in the path.
+
+Different past versions of @command{gawk} would also look explicitly in
+the current directory, either before or after the path search.  As of
address@hidden 4.1.2, this no longer happens, and if you wish to look
+in the current directory, you must include @file{.} either as a separate
+entry, or as a null entry in the search path.
 @end quotation
 
-If @env{AWKPATH} is not defined in the
-environment, @command{gawk} places its default search path into
address@hidden"AWKPATH"]}. This makes it easy to determine
-the actual search path that @command{gawk} used
-from within an @command{awk} program.
address@hidden places the value of the search path that it used into
address@hidden"AWKPATH"]}. This provides access to the actual search
+path value from within an @command{awk} program.
 
 While you can change @code{ENVIRON["AWKPATH"]} within your @command{awk}
 program, this has no effect on the running program's behavior.  This makes
@@ -4333,6 +4335,15 @@ the platform.  For example, on GNU/Linux systems, the 
suffix @samp{.so}
 is used.  The search path specified is also used for extensions loaded
 via the @code{@@load} keyword (@pxref{Loading Shared Libraries}).
 
+If @code{AWKLIBPATH} does not exist in the environment, or if it has
+an empty value, @command{gawk} uses a default path. The default path
+is typically @samp{/usr/local/lib/gawk}, although it can vary depending
+upon how @command{gawk} was built.
+
address@hidden places the value of the search path that it used into
address@hidden"AWKLIBPATH"]}. This provides access to the actual search
+path value from within an @command{awk} program.
+
 @node Other Environment Variables
 @subsection Other Environment Variables
 
diff --git a/io.c b/io.c
index 7154a71..32caadf 100644
--- a/io.c
+++ b/io.c
@@ -2505,7 +2505,6 @@ do_getline(int into_variable, IOBUF *iop)
 typedef struct {
        const char *envname;
        char **dfltp;           /* pointer to address of default path */
-       char try_cwd;           /* always search current directory? */
        char **awkpath;         /* array containing library search paths */ 
        int max_pathlen;        /* length of the longest item in awkpath */ 
 } path_info;
@@ -2513,13 +2512,11 @@ typedef struct {
 static path_info pi_awkpath = {
        /* envname */   "AWKPATH",
        /* dfltp */     & defpath,
-       /* try_cwd */   true,
 };
 
 static path_info pi_awklibpath = {
        /* envname */   "AWKLIBPATH",
        /* dfltp */     & deflibpath,
-       /* try_cwd */   false,
 };
 
 /* init_awkpath --- split path(=$AWKPATH) into components */
@@ -2577,30 +2574,6 @@ init_awkpath(path_info *pi)
 #undef INC_PATH
 }
 
-/* get_cwd -- get current working directory */
-
-static char *
-get_cwd ()
-{
-#define BSIZE  100
-       char *buf;
-       size_t bsize = BSIZE;
-
-       emalloc(buf, char *, bsize * sizeof(char), "get_cwd");
-       while (true) {
-               if (getcwd(buf, bsize) == buf)
-                       return buf;
-               if (errno != ERANGE) {
-                       efree(buf);
-                       return NULL;
-               }
-               bsize *= 2;
-               erealloc(buf, char *, bsize * sizeof(char), "get_cwd");
-       }
-#undef BSIZE
-}
-
-
 /* do_find_source --- search $AWKPATH for file, return NULL if not found */ 
 
 static char *
@@ -2622,24 +2595,6 @@ do_find_source(const char *src, struct stat *stb, int 
*errcode, path_info *pi)
                return NULL;
        }
 
-       /* try current directory before $AWKPATH search */
-       if (pi->try_cwd && stat(src, stb) == 0) {
-               path = get_cwd();
-               if (path == NULL) {
-                       *errcode = errno;
-                       return NULL;
-               }
-               erealloc(path, char *, strlen(path) + strlen(src) + 2, 
"do_find_source");
-#ifdef VMS
-               if (strcspn(path,">]:") == strlen(path))
-                       strcat(path, "/");
-#else
-               strcat(path, "/");
-#endif
-               strcat(path, src);
-               return path;
-       }
-
        if (pi->awkpath == NULL)
                init_awkpath(pi);
 
diff --git a/main.c b/main.c
index 03decbb..3bee048 100644
--- a/main.c
+++ b/main.c
@@ -1078,18 +1078,23 @@ path_environ(const char *pname, const char *dflt)
        NODE *tmp;
 
        tmp = make_string(pname, strlen(pname));
-       if (! in_array(ENVIRON_node, tmp)) {
-               /*
-                * On VMS, environ[] only holds a subset of what getenv() can
-                * find, so look AWKPATH up before resorting to default path.
-                */
-               val = getenv(pname);
-               if (val == NULL)
-                       val = dflt;
-               aptr = assoc_lookup(ENVIRON_node, tmp);
+       /*
+        * On VMS, environ[] only holds a subset of what getenv() can
+        * find, so look AWKPATH up before resorting to default path.
+        */
+       val = getenv(pname);
+       if (val == NULL || *val == '\0')
+               val = dflt;
+       aptr = assoc_lookup(ENVIRON_node, tmp);
+       /*
+        * If original value was the empty string, set it to
+        * the default value.
+        */
+       if ((*aptr)->stlen == 0) {
                unref(*aptr);
                *aptr = make_string(val, strlen(val));
        }
+
        unref(tmp);
 }
 
@@ -1136,6 +1141,11 @@ load_environ()
        /*
         * Put AWKPATH and AWKLIBPATH into ENVIRON if not already there.
         * This allows querying it from within awk programs.
+        *
+        * October 2014:
+        * If their values are "", override with the default values;
+        * since 2.10 AWKPATH used default value if environment's
+        * value was "".
         */
        path_environ("AWKPATH", defpath);
        path_environ("AWKLIBPATH", deflibpath);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]