diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2016-10-25 23:14:41 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2016-10-25 23:14:41 +0300 |
commit | ff67a43d663d1f24a9cd26933e57d33af4a4d7a4 (patch) | |
tree | 0b3931dc8d459fc87472c7a7dc83fe210dc2d490 | |
parent | 24e562f07cb9c6d70f49eeb9a74ffba8101ba834 (diff) | |
parent | 8ad38bf4d70682433e3f53fe0637929f28d64e3e (diff) | |
download | egawk-ff67a43d663d1f24a9cd26933e57d33af4a4d7a4.tar.gz egawk-ff67a43d663d1f24a9cd26933e57d33af4a4d7a4.tar.bz2 egawk-ff67a43d663d1f24a9cd26933e57d33af4a4d7a4.zip |
Merge branch 'master' into feature/nocopy
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | io.c | 76 |
3 files changed, 50 insertions, 32 deletions
@@ -16,3 +16,5 @@ gawk stamp-h1 test/fmtspcl.ok + +doc/*.info @@ -1,5 +1,9 @@ 2016-10-25 Arnold D. Robbins <arnold@skeeve.com> + * io.c (init_awkpath): Restore documented behavior whereby + null elements represent the current directory. Sheesh. + Bug reported by "Jun T." <takimoto-j@kba.biglobe.ne.jp>. + Disallow negative arguments to the bitwise functions. * NEWS: Document this. @@ -2732,50 +2732,62 @@ init_awkpath(path_info *pi) int len, i; int max_path; /* (# of allocated paths)-1 */ -#define INC_PATH 5 - pi->max_pathlen = 0; if ((path = getenv(pi->envname)) == NULL || *path == '\0') path = pi->dfltp[0]; - max_path = INC_PATH; + /* count number of separators */ + for (max_path = 0, p = path; *p; p++) + if (*p == envsep) + max_path++; + emalloc(pi->awkpath, char **, (max_path + 1) * sizeof(char *), "init_awkpath"); memset(pi->awkpath, 0, (max_path + 1) * sizeof(char *)); - end = start = path; + start = path; i = 0; + + if (*path == envsep) /* null entry at front of path */ + pi->awkpath[i++] = "."; + while (*start) { - while (*end && *end != envsep) - end++; - len = end - start; - if (len > 0) { - /* +2 is correct here; leave room for / */ - emalloc(p, char *, len + 2, "init_awkpath"); - memcpy(p, start, len); - - /* add directory punctuation if necessary */ - if (! isdirpunct(end[-1])) - p[len++] = '/'; - p[len] = '\0'; - - if (i == max_path) { - max_path += INC_PATH; - erealloc(pi->awkpath, char **, (max_path + 1) * sizeof(char *), "init_awkpath"); - memset(pi->awkpath + i, 0, (INC_PATH + 1) * sizeof(char *)); - } - pi->awkpath[i++] = p; - if (len > pi->max_pathlen) - pi->max_pathlen = len; + if (*start == envsep) { + if (start[1] == envsep) { + pi->awkpath[i++] = "."; + if (pi->max_pathlen == 0) + pi->max_pathlen = 1; + start++; + } else if (start[1] == '\0') { + pi->awkpath[i++] = "."; + if (pi->max_pathlen == 0) + pi->max_pathlen = 1; + break; + } else + start++; + } else { + for (end = start; *end && *end != envsep; end++) + continue; + + len = end - start; + if (len > 0) { + emalloc(p, char *, len + 2, "init_awkpath"); + memcpy(p, start, len); + + /* add directory punctuation if necessary */ + if (! isdirpunct(end[-1])) + p[len++] = '/'; + p[len] = '\0'; + pi->awkpath[i++] = p; + if (len > pi->max_pathlen) + pi->max_pathlen = len; + + start = end; + } else + start++; } - - /* skip one or more envsep char */ - while (*end && *end == envsep) - end++; - start = end; } - pi->awkpath[i] = NULL; -#undef INC_PATH + pi->awkpath[i] = NULL; } /* do_find_source --- search $AWKPATH for file, return NULL if not found */ |