diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 116 |
1 files changed, 70 insertions, 46 deletions
@@ -240,6 +240,10 @@ int RS_is_null; extern NODE *ARGC_node; extern NODE *ARGV_node; extern NODE *ARGIND_node; +<<<<<<< HEAD +======= +extern NODE **fields_arr; +>>>>>>> xgawk /* init_io --- set up timeout related variables */ @@ -319,7 +323,7 @@ after_beginfile(IOBUF **curfile) errcode = iop->errcode; iop->errcode = 0; errno = 0; - update_ERRNO(); + update_ERRNO_int(errno); iop_close(iop); *curfile = NULL; if (errcode == EISDIR && ! do_traditional) { @@ -396,7 +400,7 @@ nextfile(IOBUF **curfile, int skipping) fd = devopen(fname, binmode("r")); errcode = errno; if (! do_traditional) - update_ERRNO(); + update_ERRNO_int(errno); unref(FILENAME_node->var_value); FILENAME_node->var_value = dupnode(arg); @@ -421,7 +425,7 @@ nextfile(IOBUF **curfile, int skipping) /* FNR is init'ed to 0 */ errno = 0; if (! do_traditional) - update_ERRNO(); + update_ERRNO_int(errno); unref(FILENAME_node->var_value); FILENAME_node->var_value = make_string("-", 1); FILENAME_node->var_value->flags |= MAYBE_NUM; /* be pedantic */ @@ -432,7 +436,7 @@ nextfile(IOBUF **curfile, int skipping) if (iop->fd == INVALID_HANDLE) { errcode = errno; errno = 0; - update_ERRNO(); + update_ERRNO_int(errno); (void) iop_close(iop); *curfile = NULL; fatal(_("cannot open file `%s' for reading (%s)"), @@ -493,7 +497,7 @@ inrec(IOBUF *iop, int *errcode) if (cnt == EOF) { retval = 1; if (*errcode > 0) - update_ERRNO_saved(*errcode); + update_ERRNO_int(*errcode); } else { INCREMENT_REC(NR); INCREMENT_REC(FNR); @@ -1020,8 +1024,7 @@ do_close(int nargs) if (! do_traditional) { /* update ERRNO manually, using errno = ENOENT is a stretch. */ cp = _("close of redirection that was never opened"); - unref(ERRNO_node->var_value); - ERRNO_node->var_value = make_string(cp, strlen(cp)); + update_ERRNO_string(cp, DONT_TRANSLATE); } DEREF(tmp); @@ -1143,7 +1146,7 @@ close_redir(struct redirect *rp, int exitwarn, two_way_close_type how) if (! do_traditional) { /* set ERRNO too so that program can get at it */ - update_ERRNO_saved(save_errno); + update_ERRNO_int(save_errno); } } @@ -2263,7 +2266,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) if (rp == NULL) { if (redir_error) { /* failed redirect */ if (! do_traditional) - update_ERRNO_saved(redir_error); + update_ERRNO_int(redir_error); } return make_number((AWKNUM) -1.0); } @@ -2274,8 +2277,13 @@ do_getline_redir(int into_variable, enum redirval redirtype) errcode = 0; cnt = get_a_record(& s, iop, & errcode); if (errcode != 0) { +<<<<<<< HEAD if (! do_traditional && errcode != -1) update_ERRNO_saved(errcode); +======= + if (! do_traditional && (errcode != -1)) + update_ERRNO_int(errcode); +>>>>>>> xgawk return make_number((AWKNUM) -1.0); } @@ -2322,9 +2330,15 @@ do_getline(int into_variable, IOBUF *iop) errcode = 0; cnt = get_a_record(& s, iop, & errcode); if (errcode != 0) { +<<<<<<< HEAD if (! do_traditional && errcode != -1) update_ERRNO_saved(errcode); if (into_variable) +======= + if (! do_traditional && (errcode != -1)) + update_ERRNO_int(errcode); + if (intovar) +>>>>>>> xgawk (void) POP_ADDRESS(); return make_number((AWKNUM) -1.0); } @@ -2346,35 +2360,45 @@ do_getline(int into_variable, IOBUF *iop) return make_number((AWKNUM) 1.0); } +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; + +static path_info pi_awkpath = { + /* envname */ "AWKPATH", + /* dfltp */ & defpath, + /* try_cwd */ TRUE, +}; -static char **awkpath = NULL; /* array containing library search paths */ -static int max_pathlen; /* length of the longest item in awkpath */ +static path_info pi_awklibpath = { + /* envname */ "AWKLIBPATH", + /* dfltp */ & deflibpath, + /* try_cwd */ FALSE, +}; /* init_awkpath --- split path(=$AWKPATH) into components */ static void -init_awkpath(char *path) +init_awkpath(path_info *pi) { + char *path; char *start, *end, *p; int len, i; - static int max_path = 0; + int max_path; /* (# of allocated paths)-1 */ #define INC_PATH 5 - max_pathlen = 0; - if (path == NULL || *path == '\0') - path = defpath; - - for (i = 0; i < max_path && awkpath[i]; i++) { - efree(awkpath[i]); - awkpath[i] = NULL; - } + pi->max_pathlen = 0; + if ((path = getenv(pi->envname)) == NULL || *path == '\0') + path = pi->dfltp[0]; - if (max_path == 0) { - max_path = INC_PATH; - emalloc(awkpath, char **, (max_path + 1) * sizeof(char *), "init_awkpath"); - memset(awkpath, 0, (max_path + 1) * sizeof(char *)); - } + max_path = INC_PATH; + emalloc(pi->awkpath, char **, (max_path + 1) * sizeof(char *), "init_awkpath"); + memset(pi->awkpath, 0, (max_path + 1) * sizeof(char *)); end = start = path; i = 0; @@ -2393,12 +2417,12 @@ init_awkpath(char *path) if (i == max_path) { max_path += INC_PATH; - erealloc(awkpath, char **, (max_path + 1) * sizeof(char *), "init_awkpath"); - memset(awkpath + i, 0, (INC_PATH + 1) * sizeof(char *)); + erealloc(pi->awkpath, char **, (max_path + 1) * sizeof(char *), "init_awkpath"); + memset(pi->awkpath + i, 0, (INC_PATH + 1) * sizeof(char *)); } - awkpath[i++] = p; - if (len > max_pathlen) - max_pathlen = len; + pi->awkpath[i++] = p; + if (len > pi->max_pathlen) + pi->max_pathlen = len; } /* skip one or more envsep char */ @@ -2406,7 +2430,7 @@ init_awkpath(char *path) end++; start = end; } - awkpath[i] = NULL; + pi->awkpath[i] = NULL; #undef INC_PATH } @@ -2438,7 +2462,7 @@ get_cwd () /* do_find_source --- search $AWKPATH for file, return NULL if not found */ static char * -do_find_source(const char *src, struct stat *stb, int *errcode) +do_find_source(const char *src, struct stat *stb, int *errcode, path_info *pi) { char *path; int i; @@ -2457,7 +2481,7 @@ do_find_source(const char *src, struct stat *stb, int *errcode) } /* try current directory before $AWKPATH search */ - if (stat(src, stb) == 0) { + if (pi->try_cwd && stat(src, stb) == 0) { path = get_cwd(); if (path == NULL) { *errcode = errno; @@ -2469,16 +2493,15 @@ do_find_source(const char *src, struct stat *stb, int *errcode) return path; } - if (awkpath == NULL) - init_awkpath(getenv("AWKPATH")); + if (pi->awkpath == NULL) + init_awkpath(pi); - emalloc(path, char *, max_pathlen + strlen(src) + 1, "do_find_source"); - for (i = 0; awkpath[i] != NULL; i++) { - if (strcmp(awkpath[i], "./") == 0 || strcmp(awkpath[i], ".") == 0) { - /* FIXME: already tried CWD above; Why do it again ? */ + emalloc(path, char *, pi->max_pathlen + strlen(src) + 1, "do_find_source"); + for (i = 0; pi->awkpath[i] != NULL; i++) { + if (strcmp(pi->awkpath[i], "./") == 0 || strcmp(pi->awkpath[i], ".") == 0) *path = '\0'; - } else - strcpy(path, awkpath[i]); + else + strcpy(path, pi->awkpath[i]); strcat(path, src); if (stat(path, stb) == 0) return path; @@ -2496,11 +2519,12 @@ char * find_source(const char *src, struct stat *stb, int *errcode, int is_extlib) { char *path; + path_info *pi = (is_extlib ? & pi_awklibpath : & pi_awkpath); *errcode = 0; if (src == NULL || *src == '\0') return NULL; - path = do_find_source(src, stb, errcode); + path = do_find_source(src, stb, errcode, pi); if (path == NULL && is_extlib) { char *file_ext; @@ -2508,7 +2532,7 @@ find_source(const char *src, struct stat *stb, int *errcode, int is_extlib) size_t src_len; size_t suffix_len; -#define EXTLIB_SUFFIX ".so" +#define EXTLIB_SUFFIX "." SHLIBEXT src_len = strlen(src); suffix_len = strlen(EXTLIB_SUFFIX); @@ -2520,7 +2544,7 @@ find_source(const char *src, struct stat *stb, int *errcode, int is_extlib) save_errno = errno; emalloc(file_ext, char *, src_len + suffix_len + 1, "find_source"); sprintf(file_ext, "%s%s", src, EXTLIB_SUFFIX); - path = do_find_source(file_ext, stb, errcode); + path = do_find_source(file_ext, stb, errcode, pi); efree(file_ext); if (path == NULL) errno = save_errno; @@ -2540,7 +2564,7 @@ find_source(const char *src, struct stat *stb, int *errcode, int is_extlib) emalloc(file_awk, char *, strlen(src) + sizeof(DEFAULT_FILETYPE) + 1, "find_source"); sprintf(file_awk, "%s%s", src, DEFAULT_FILETYPE); - path = do_find_source(file_awk, stb, errcode); + path = do_find_source(file_awk, stb, errcode, pi); efree(file_awk); if (path == NULL) { errno = save_errno; |