diff --git a/NEWS b/NEWS index 9e65d72827ec..c3833d8b8d8f 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,42 @@ This documents significant changes in the dev branch of ksh 93u+m. For full details, see the git log at: https://github.com/ksh93/ksh Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library. +2024-03-07: + +- Fixed a bug that caused some systems to corrupt the display of multibyte + characters in the command prompt. + +2024-03-05: + +- Fixed a regression, introduced on 2021-02-07, that made the common AST + options '--???ESC' and '--???noESC' ineffective for enabling/disabling + ANSI escape codes for emphasis in the output of --man or --help. + (Type, e.g., print '--???' for more information about common options.) + +- Fixed a rare crash in the 'print' built-in due to the use of uninitialised + memory while parsing options. Bug introduced in ksh 93u+ 2012-05-31. + +- Fixed a 2021-04-14 regression: the 'exec' command (which runs a command + that replaces the shell process and therefore should only run external + commands) would run a path-bound built-in if /opt/ast/bin is in PATH. + +- Fixed a corner case bug: a ${ shared-state command substitution;} failed to + capture the standard output of a command that replces the shell via 'exec'. + +2024-02-29: + +- Improved the robustness of the routines handling the execution by ksh of a + script without an initial #! path. More memory is freed up after ksh forks. + +- Fixed a crash that could occur after 'typeset +x var' when var was imported + from the environment and then a discipline function was set for it. + +2024-02-23: + +- [v1.1] The commands ':', 'true', 'false', 'break' and 'continue' have been + optimised to run faster in loops in certain common cases. For example, the + 'true' in 'while true; do some_stuff || break; done' now runs faster. + 2024-02-22: - Fixed a crash that occurred when starting ksh with no TERM variable in the diff --git a/bin/package b/bin/package index 6bcdb9e2af13..cd9a52fbc1a2 100755 --- a/bin/package +++ b/bin/package @@ -151,7 +151,7 @@ command=${0##*/} case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in 0123) USAGE=$' [-? -@(#)$Id: '$command$' (ksh 93u+m) 2024-02-22 $ +@(#)$Id: '$command$' (ksh 93u+m) 2024-03-07 $ ] [-author?Glenn Fowler ] [-author?Contributors to https://github.com/ksh93/ksh] @@ -579,7 +579,7 @@ SEE ALSO pkgadd(1), pkgmk(1), rpm(1), sh(1), tar(1), optget(3) IMPLEMENTATION - version package (ksh 93u+m) 2024-02-22 + version package (ksh 93u+m) 2024-03-07 author Glenn Fowler author Contributors to https://github.com/ksh93/ksh copyright (c) 1994-2012 AT&T Intellectual Property @@ -2113,10 +2113,7 @@ case $x in case $KEEP_SHELL in 0) save_PATH=$PATH - if PATH=$(getconf PATH 2>/dev/null) - then PATH=$PATH:$path - else PATH=/bin:/usr/bin:/sbin:/usr/sbin:$path - fi + PATH=$DEFPATH:$path for i in ksh ksh93 mksh yash bash sh do if onpath "$i" && checksh "$_onpath_" then SHELL=$_onpath_ @@ -2138,7 +2135,7 @@ case $x in # tame the environment - unset ERROR_OPTIONS ENV + unset ERROR_OPTIONS ENV _KSHRC_WELCOMED_ # finalize the views @@ -3066,18 +3063,9 @@ make|view) case $EXECROOT in $INSTALLROOT) $make cd $INSTALLROOT/bin - if executable /bin/cp - then cp=/bin/cp - else cp=cp - fi - if executable /bin/mv - then mv=/bin/mv - else mv=mv - fi - if executable /bin/rm - then rm=/bin/rm - else rm=rm - fi + cp=$(PATH=$DEFPATH; command -v cp) || cp=cp + mv=$(PATH=$DEFPATH; command -v mv) || mv=mv + rm=$(PATH=$DEFPATH; command -v rm) || rm=rm for i in \ ksh tee cp ln mv rm \ *ast*.dll *cmd*.dll *dll*.dll *shell*.dll diff --git a/src/Mamfile b/src/Mamfile index 7e9ee1000c5e..45233fa46095 100644 --- a/src/Mamfile +++ b/src/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 make test virtual make test_announce virtual @@ -13,5 +13,10 @@ make test virtual make all virtual exec - ${MAMAKE} -r '*/*' ${MAMAKEARGS} done + make announce_build_done virtual notrace + prev cmd/ksh93/ksh + exec - ${<} -c 'print "# KornShell $KSH_VERSION"' + exec - echo "# Type 'bin/package use' to try it out" + done done done diff --git a/src/cmd/INIT/Mamfile b/src/cmd/INIT/Mamfile index d723e5733d24..385381c3c321 100644 --- a/src/cmd/INIT/Mamfile +++ b/src/cmd/INIT/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 setv INSTALLROOT ../../.. setv CC cc diff --git a/src/cmd/INIT/README-mamake.md b/src/cmd/INIT/README-mamake.md index db545e572ffd..9b12ab29e2d2 100644 --- a/src/cmd/INIT/README-mamake.md +++ b/src/cmd/INIT/README-mamake.md @@ -75,7 +75,7 @@ higher than the previous highest one; details of those changes are documented throughout this file and listed in the appendix below. This makes it possible to test or backport old code using the current build system. Current Mamfiles should use the highest strict level available. -The current highest available strict level is **2**. +The current highest available strict level is **3**. ## MAM variables ## @@ -184,6 +184,9 @@ dependencies of its own, it may even be empty; this has the effect of merely declaring a dependency on a prerequisite file, such as a source code file that comes with the distribution or a file generated by a previously run Mamfile. +Making a prerequisite that is currently being made, or one that has already +been made, produces a warning; at strict level 3 and up, this is an error. + One or more *attribute*s may be specified by appending them to the `make` command. (At strict levels \< 2, they may also be appended to the `done` command; the effect is the same either way. At strict level 1, this produces a deprecation warning.) @@ -238,6 +241,9 @@ The `prev` command is used in two ways: in a manner equivalent to an empty `make`...`done` block, with the optional *attribute*s applied to the new rule, and a nonexistent prerequisite is an error unless a `virtual` or `dontcare` attribute is given. + Declaring a dependency on a prerequisite that is currently being made + (i.e.: directly or indirectly within that prerequisite's block) produces + a warning; at strict level 3 and up, this is an error. ### Setting MAM variables ### @@ -363,7 +369,7 @@ building, and executed as normal commands while building the current directory. #### …while scanning and sorting leaf directories #### -If there is a leaf directory named `INIT`, it will always be built before +Any leaf directories with names that start with `INIT` will always be built before all others. For all other leaf directories, the presence of any `bind` command of the form `bind -lfoo` anywhere in a leaf directory's Mamfile causes the leaf directory named `libfoo` (if it exists) @@ -379,12 +385,17 @@ causes a MAM variable `mam_lib`*libraryname* to be defined (see **MAM variables* The variable will contain either the compiler argument for linking to the library *libraryname* (either the `-l`*libraryname* flag, or the full path in case of a static library) or, if the `dontcare` attribute is specified, possibly the empty string. +Any library dependencies are also included (see below). This can be used both for AST libraries shipped with the distribution and for system libraries. -If the library file is found in the distribution, -its time stamp is checked and the current target is marked as outdated if it is newer. +For each corresponding *.a library archive dependency built previously, +its time stamp is checked and the current target is marked as outdated if it is +newer, as if a `prev` had been executed for it. -The effect of `bind` is global, not scoped; it takes effect for all commands -physically following it, regardless of `make`…`done` nesting level. +The variable set by `bind` is global, but the marking of the target as +outdated applies to the current rule only, so it may be necessary to +repeat a `bind` command when statically linking executables that depend +on a library, otherwise they may not be relinked when the library changes. +The `mam_lib`*libraryname* variable will not be regenerated when repeating a `bind`. There is also a mechanism to communicate library dependency information across Mamfiles and `mamake` invocations. If a file named *libraryname*`.req` in the current directory @@ -415,9 +426,10 @@ The *variable* is restored to its previous state after the loop completes. Note that `loop` causes repeated reading and processing of Mamfile lines, *not* necessarily repeated execution. For instance, a loop can be used to consolidate repetitive `make`…`done` rules. However, each rule is only made -once and subsequent rules by the same name are skipped over. So it only -makes sense to do this if the contained make target names are modified by -the expansion of the iteration *variable*. +once and subsequent rules by the same name are an error at strict level 3 +and up, or skipped over at strict \< 3. So it only makes sense to do this +if the contained make target names are modified by the expansion of the +iteration *variable*. `loop` requires a seekable input file (i.e.: not a pipe). @@ -437,6 +449,8 @@ maintain Mamfiles by hand. The following lists the important changes. * The automatic variables `${@}`, `${<}`, `${^}` and `${?}` have been added. * An iteration block command, `loop`…`done`, has been added. * A command to set common code for shell actions, `shim`, has been added. +* Attempting to make a rule that has already been made produces a warning. +* Attempting to declare a dependency on a rule currently being made produces a warning. * **At strict level 1 and up:** * Appending attributes to `done` instead of `make` is deprecated and produces a warning. @@ -456,3 +470,6 @@ maintain Mamfiles by hand. The following lists the important changes. without scanning the values for recursive variable references. * `setv` does not remove leading and trailing `"` from the value. * Shell actions have pathname expansion (globbing) disabled by default. +* **At strict level 3 and up:** + * Attempting to make a rule that has already been made is an error. + * Attempting to declare a dependency on a rule currently being made is an error. diff --git a/src/cmd/INIT/mamake.c b/src/cmd/INIT/mamake.c index 9d19de56b0f7..15624c59ac97 100644 --- a/src/cmd/INIT/mamake.c +++ b/src/cmd/INIT/mamake.c @@ -27,7 +27,7 @@ * coded for portability */ -#define RELEASE_DATE "2024-02-17" +#define RELEASE_DATE "2024-03-08" static char id[] = "\n@(#)$Id: mamake (ksh 93u+m) " RELEASE_DATE " $\0\n"; #if _PACKAGE_ast @@ -171,7 +171,6 @@ static const char usage[] = #define CHUNK 4096 #define KEY(a,b,c,d) ((((unsigned long)(a))<<24)|(((unsigned long)(b))<<16)|(((unsigned long)(c))<<8)|(((unsigned long)(d)))) #define NOW ((unsigned long)time(NULL)) -#define ROTATE(p,l,r,t) ((t)=(p)->l,(p)->l=(t)->r,(t)->r=(p),(p)=(t)) #define RULE_active 0x0001 /* active target */ #define RULE_dontcare 0x0002 /* ok if not found */ @@ -206,17 +205,17 @@ typedef FILE Stdio_t; typedef struct Buf_s /* buffer stream */ { - struct Buf_s* old; /* next dropped buffer */ - char* end; /* 1 past end of buffer */ - char* nxt; /* next char to add */ - char* buf; /* buffer space */ + struct Buf_s *old; /* next dropped buffer */ + char *end; /* 1 past end of buffer */ + char *nxt; /* next char to add */ + char *buf; /* buffer space */ } Buf_t; typedef struct Dict_item_s /* dictionary item */ { - struct Dict_item_s* left; /* left child */ - struct Dict_item_s* right; /* right child */ - void* value; /* user defined value */ + struct Dict_item_s *left; /* left child */ + struct Dict_item_s *right; /* right child */ + void *value; /* user defined value */ #if __STDC_VERSION__ >= 199901L char name[]; /* 0 terminated name */ #else @@ -226,21 +225,21 @@ typedef struct Dict_item_s /* dictionary item */ typedef struct Dict_s /* dictionary handle */ { - Dict_item_t* root; /* root item */ + Dict_item_t *root; /* root item */ } Dict_t; typedef struct List_s /* Rule_t list */ { - struct List_s* next; /* next in list */ - struct Rule_s* rule; /* list item */ + struct List_s *next; /* next in list */ + struct Rule_s *rule; /* list item */ } List_t; typedef struct Rule_s /* rule item */ { - char* name; /* unbound name */ - char* path; /* bound path */ - List_t* prereqs; /* prerequisites */ - struct Rule_s* leaf; /* recursion leaf alias */ + char *name; /* unbound name */ + char *path; /* bound path */ + List_t *prereqs; /* prerequisites */ + struct Rule_s *leaf; /* recursion leaf alias */ int flags; /* RULE_* flags */ int making; /* currently make()ing */ unsigned long time; /* modification time */ @@ -249,15 +248,15 @@ typedef struct Rule_s /* rule item */ typedef struct Stream_s /* input file stream stack */ { - Stdio_t* fp; /* read stream */ - char* file; /* stream path */ + Stdio_t *fp; /* read stream */ + char *file; /* stream path */ unsigned long line; /* stream line */ int flags; /* stream flags */ } Stream_t; typedef struct View_s /* viewpath level */ { - struct View_s* next; /* next level in viewpath */ + struct View_s *next; /* next level in viewpath */ int node; /* viewpath node path length */ #if __STDC_VERSION__ >= 199901L char dir[]; /* viewpath level dir prefix */ @@ -270,21 +269,21 @@ static struct /* program state */ { int strict; /* strict mode activated if set */ - Buf_t* old; /* dropped buffers */ - Buf_t* opt; /* option buffer */ + Buf_t *old; /* dropped buffers */ + Buf_t *opt; /* option buffer */ - Dict_t* leaf; /* recursion leaf dictionary */ - Dict_t* rules; /* rule dictionary */ - Dict_t* vars; /* variable dictionary */ + Dict_t *leaf; /* recursion leaf dictionary */ + Dict_t *rules; /* rule dictionary */ + Dict_t *vars; /* variable dictionary */ - View_t* view; /* viewpath levels */ + View_t *view; /* viewpath levels */ - char* directory; /* work in this directory */ - char* id; /* command name */ - char* file; /* first input file */ - char* pwd; /* current directory */ - char* recurse; /* recursion pattern */ - char* shell; /* ${SHELL} */ + char *directory; /* work in this directory */ + char *id; /* command name */ + char *file; /* first input file */ + char *pwd; /* current directory */ + char *recurse; /* recursion pattern */ + char *shell; /* ${SHELL} */ int active; /* targets currently active */ int debug; /* negative of debug level */ @@ -300,24 +299,24 @@ static struct /* program state */ int verified; /* don't bother with verify() */ Stream_t streams[4]; /* input file stream stack */ - Stream_t* sp; /* input stream stack pointer */ + Stream_t *sp; /* input stream stack pointer */ - char* shim; /* finished shim */ - Buf_t* shim_buf; /* shim being built up */ + char *shim; /* finished shim */ + Buf_t *shim_buf; /* shim being built up */ } state; -static unsigned long make(Rule_t*, int, unsigned long, Buf_t**); +static unsigned long make(Rule_t *, int, unsigned long, Buf_t **); static char mamfile[] = "Mamfile"; static char sh[] = "/bin/sh"; static char empty[] = ""; -static Dict_item_t* auto_making; /* ${@} - name of rule being made */ -static Dict_item_t* auto_prev; /* ${<} - name of last prerequisite */ -static Dict_item_t* auto_allprev; /* ${^} - space-separated names of all prerequisites */ -static Dict_item_t* auto_updprev; /* ${?} - space-separated names of updated prerequisites */ +static Dict_item_t *auto_making; /* ${@} - name of rule being made */ +static Dict_item_t *auto_prev; /* ${<} - name of last prerequisite */ +static Dict_item_t *auto_allprev; /* ${^} - space-separated names of all prerequisites */ +static Dict_item_t *auto_updprev; /* ${?} - space-separated names of updated prerequisites */ -extern char** environ; +extern char **environ; #if !_PACKAGE_ast @@ -329,8 +328,7 @@ extern char** environ; * emit usage message and exit */ -static void -usage(void) +static void usage(void) { fprintf(stderr, "Usage: %s" " [-iknFKNV]" @@ -350,8 +348,7 @@ usage(void) * output error message identification */ -static void -identify(Stdio_t* sp) +static void identify(Stdio_t * sp) { if (state.directory) fprintf(sp, "%s [%s]: ", state.id, state.directory); @@ -369,8 +366,7 @@ identify(Stdio_t* sp) * >2 exit(level-2) */ -static void -report(int level, char* text, char* item, unsigned long stamp) +static void report(int level, char *text, char *item, unsigned long stamp) { int i; @@ -412,8 +408,7 @@ report(int level, char* text, char* item, unsigned long stamp) * don't know how to make or exit code making */ -static void -dont(Rule_t* r, int code, int keepgoing) +static void dont(Rule_t *r, int code, int keepgoing) { identify(stderr); if (!code) @@ -435,10 +430,9 @@ dont(Rule_t* r, int code, int keepgoing) * open a buffer stream */ -static Buf_t* -buffer(void) +static Buf_t *buffer(void) { - Buf_t* buf; + Buf_t *buf; if (buf = state.old) state.old = state.old->old; @@ -453,8 +447,7 @@ buffer(void) * close a buffer stream */ -static void -drop(Buf_t* buf) +static void drop(Buf_t *buf) { buf->old = state.old; state.old = buf; @@ -464,8 +457,7 @@ drop(Buf_t* buf) * append str length n to buffer and return the buffer base */ -static char* -appendn(Buf_t* buf, char* str, int n) +static char *appendn(Buf_t *buf, char *str, int n) { int m; int i; @@ -489,8 +481,7 @@ appendn(Buf_t* buf, char* str, int n) * if str==0 then next pointer reset to base */ -static char* -append(Buf_t* buf, char* str) +static char *append(Buf_t *buf, char *str) { if (str) return appendn(buf, str, strlen(str)); @@ -503,10 +494,9 @@ append(Buf_t* buf, char* str) * allocate space for s and return the copy */ -static char* -reduplicate(char* orig, char* s) +static char *reduplicate(char *orig, char *s) { - char* t; + char *t; int n; n = strlen(s); @@ -522,8 +512,7 @@ reduplicate(char* orig, char* s) return t; } -static char* -duplicate(char* s) +static char *duplicate(char *s) { return reduplicate(NULL, s); } @@ -532,10 +521,9 @@ duplicate(char* s) * open a new dictionary */ -static Dict_t* -dictionary(void) +static Dict_t *dictionary(void) { - Dict_t* dict; + Dict_t *dict; if (!(dict = newof(0, Dict_t, 1, 0))) report(3, "out of memory [dictionary]", NULL, 0); @@ -543,24 +531,16 @@ dictionary(void) } /* - * return the value for item name in dictionary dict - * if value!=0 then name entry value is created if necessary and set - * uses top-down splaying (ala Tarjan and Sleator) + * Return a pointer to item 'name' in dictionary 'dict'. + * If create!=0, then the item is created if necessary. + * Uses top-down splaying (ala Tarjan and Sleator). */ -static void* -search(Dict_t* dict, char* name, void* value) +static Dict_item_t *search(Dict_t *dict, char *name, int create) { int cmp; - Dict_item_t* root; - Dict_item_t* t; - Dict_item_t* left; - Dict_item_t* right; - Dict_item_t* lroot; - Dict_item_t* rroot; - - root = dict->root; - left = right = lroot = rroot = 0; + Dict_item_t *root = dict->root, *left = NULL, *right = NULL, *lroot = NULL, *rroot = NULL; + while (root) { if (!(cmp = strcmp(name, root->name))) @@ -569,7 +549,11 @@ search(Dict_t* dict, char* name, void* value) { if (root->left && (cmp = strcmp(name, root->left->name)) <= 0) { - ROTATE(root, left, right, t); + /* rotate(left, right) */ + Dict_item_t *t = root->left; + root->left = t->right; + t->right = root; + root = t; if (!cmp) break; } @@ -579,13 +563,17 @@ search(Dict_t* dict, char* name, void* value) rroot = root; right = root; root = root->left; - right->left = 0; + right->left = NULL; } else { if (root->right && (cmp = strcmp(name, root->right->name)) >= 0) { - ROTATE(root, right, left, t); + /* rotate(right, left) */ + Dict_item_t *t = root->right; + root->right = t->left; + t->left = root; + root = t; if (!cmp) break; } @@ -595,7 +583,7 @@ search(Dict_t* dict, char* name, void* value) lroot = root; left = root; root = root->right; - left->right = 0; + left->right = NULL; } } if (root) @@ -609,7 +597,7 @@ search(Dict_t* dict, char* name, void* value) else lroot = root->left; } - else if (value) + else if (create) { if (!(root = newof(0, Dict_item_t, 1, strlen(name) + 1))) { @@ -620,12 +608,10 @@ search(Dict_t* dict, char* name, void* value) } if (root) { - if (value) - root->value = value; root->left = lroot; root->right = rroot; dict->root = root; - return value ? root : root->value; + return root; } if (left) { @@ -640,14 +626,25 @@ search(Dict_t* dict, char* name, void* value) return NULL; } +static void setval(Dict_t *dict, char *name, void *value) +{ + Dict_item_t *node = search(dict, name, 1); + node->value = value; +} + +static void *getval(Dict_t *dict, char *name) +{ + Dict_item_t *node = search(dict, name, 0); + return node ? node->value : NULL; +} + /* * low level for walk() */ -static int -apply(Dict_t* dict, Dict_item_t* item, int (*func)(Dict_item_t*, void*), void* handle) +static int apply(Dict_t *dict, Dict_item_t *item, int (*func)(Dict_item_t *, void *), void *handle) { - Dict_item_t* right; + Dict_item_t *right; do { @@ -664,8 +661,7 @@ apply(Dict_t* dict, Dict_item_t* item, int (*func)(Dict_item_t*, void*), void* h * apply func to each dictionary item */ -static int -walk(Dict_t* dict, int (*func)(Dict_item_t*, void*), void* handle) +static int walk(Dict_t *dict, int (*func)(Dict_item_t *, void *), void *handle) { return dict->root ? apply(dict, dict->root, func, handle) : 0; } @@ -674,17 +670,19 @@ walk(Dict_t* dict, int (*func)(Dict_item_t*, void*), void* handle) * return a rule pointer for name */ -static Rule_t* -rule(char* name) +static Rule_t *rule(char *name) { - Rule_t* r; + Rule_t *r; - if (!(r = (Rule_t*)search(state.rules, name, NULL))) + if (!(r = getval(state.rules, name))) { + Dict_item_t *rnode; int n; if (!(r = newof(0, Rule_t, 1, 0))) report(3, "out of memory [rule]", name, 0); - r->name = ((Dict_item_t*)search(state.rules, name, r))->name; + rnode = search(state.rules, name, 1); + rnode->value = r; + r->name = rnode->name; r->line = state.sp ? state.sp->line : 0; /* * Since ksh 93u+m removed proto(1) including the *.lic license @@ -701,10 +699,9 @@ rule(char* name) * prepend p onto rule r prereqs */ -static void -cons(Rule_t* r, Rule_t* p) +static void cons(Rule_t *r, Rule_t *p) { - List_t* x; + List_t *x; for (x = r->prereqs; x && x->rule != p; x = x->next); if (!x) @@ -721,26 +718,19 @@ cons(Rule_t* r, Rule_t* p) * initialize the viewpath */ -static void -view(void) +static void view(void) { - char* s; - char* t; - char* p; - View_t* vp; - - View_t* zp; - int c; - int n; - - Stat_t st; - Stat_t ts; - + char *s, *t, *p; + View_t *vp, *zp; + int c, n; + Stat_t st, ts; char buf[CHUNK]; + Dict_item_t *vnode; if (stat(".", &st)) report(3, "cannot stat", ".", 0); - if ((s = (char*)search(state.vars, "PWD", NULL)) && !stat(s, &ts) && + vnode = search(state.vars, "PWD", 1); + if ((s = vnode->value) && !stat(s, &ts) && ts.st_dev == st.st_dev && ts.st_ino == st.st_ino) state.pwd = s; if (!state.pwd) @@ -748,9 +738,9 @@ view(void) if (!getcwd(buf, sizeof(buf) - 1)) report(3, "cannot determine PWD", NULL, 0); state.pwd = duplicate(buf); - search(state.vars, "PWD", state.pwd); + vnode->value = state.pwd; } - if ((s = (char*)search(state.vars, "VPATH", NULL)) && *s) + if ((s = getval(state.vars, "VPATH")) && *s) { p = NULL; zp = NULL; @@ -798,7 +788,7 @@ view(void) n = strlen(s); if (!p) abort(); - if (!(vp = newof(0, View_t, 1, strlen(p) + n + 1))) + if (!(vp = newof(0, View_t, 1, strlen(p) + n + 2))) report(3, "out of memory [view]", s, 0); vp->node = n + 1; strcpy(vp->dir, s); @@ -821,8 +811,7 @@ view(void) * return next '?' or '}' in nested '}' */ -static char* -cond(char* s) +static char *cond(char *s) { int n; @@ -858,8 +847,7 @@ cond(char* s) * expand var refs from s into buf */ -static void -substitute(Buf_t* buf, char* s) +static void substitute(Buf_t *buf, char *s) { char *t, *q; char *v; /* variable's value */ @@ -905,7 +893,7 @@ substitute(Buf_t* buf, char* s) /* Obtain value */ - v = (char*)search(state.vars, t, NULL); + v = getval(state.vars, t); /* * In strict >= 2, always keep ${foo:-bar}, ${foo:+bar}, ${foo:=bar}, ${foo=bar} @@ -925,7 +913,7 @@ substitute(Buf_t* buf, char* s) /* A really absurd hack, see check for found_AR further below */ - if (t[0] == 'A' && t[1] == 'R' && t[2] == 0) + if (strcmp(t, "AR") == 0) found_AR = 1; /* Un-terminate the variable name */ @@ -1059,8 +1047,7 @@ substitute(Buf_t* buf, char* s) * expand var refs from s into buf and return buf base */ -static char* -expand(Buf_t* buf, char* s) +static char *expand(Buf_t *buf, char *s) { substitute(buf, s); return use(buf); @@ -1070,12 +1057,11 @@ expand(Buf_t* buf, char* s) * stat() with .exe check */ -static char* -status(Buf_t* buf, int off, char* path, struct stat* st) +static char *status(Buf_t *buf, int off, char *path, struct stat *st) { - int r; - char* s; - Buf_t* tmp; + int r; + char *s; + Buf_t *tmp; if (!stat(path, st)) return path; @@ -1109,14 +1095,11 @@ status(Buf_t* buf, int off, char* path, struct stat* st) * return path to file */ -static char* -find(Buf_t* buf, char* file, struct stat* st) +static char *find(Buf_t *buf, char *file, struct stat *st) { - char* s; - View_t* vp; - int node; - int c; - int o; + char *s; + View_t *vp; + int node, c, o; if (s = status(buf, 0, file, st)) { @@ -1174,11 +1157,10 @@ find(Buf_t* buf, char* file, struct stat* st) * bind r to a file and return the modify time */ -static unsigned long -bindfile(Rule_t* r) +static unsigned long bindfile(Rule_t *r) { - char* s; - Buf_t* buf; + char *s; + Buf_t *buf; struct stat st; buf = buffer(); @@ -1197,8 +1179,7 @@ bindfile(Rule_t* r) * pop the current input file */ -static int -pop(void) +static int pop(void) { int r; @@ -1221,11 +1202,10 @@ pop(void) * push file onto the input stack */ -static int -push(char* file, Stdio_t* fp, int flags) +static int push(char *file, Stdio_t *fp, int flags) { - char* path; - Buf_t* buf; + char *path; + Buf_t *buf; struct stat st; if (!state.sp) @@ -1280,8 +1260,7 @@ push(char* file, Stdio_t* fp, int flags) * return the next input line */ -static char* -input(void) +static char *input(void) { static char input[8*CHUNK]; /* input buffer */ char *e; @@ -1306,13 +1285,12 @@ input(void) * even on systems that otherwise demand #! magic (can you say Cygwin) */ -static int -execute(char* s) +static int execute(char *s) { - int c; - Buf_t* buf; + int c; + Buf_t *buf; - if (!state.shell && (!(state.shell = (char*)search(state.vars, "SHELL", NULL)) || !strcmp(state.shell, sh))) + if (!state.shell && (!(state.shell = getval(state.vars, "SHELL")) || !strcmp(state.shell, sh))) state.shell = sh; buf = buffer(); append(buf, state.shell); @@ -1343,17 +1321,13 @@ execute(char* s) * run action s to update r */ -static unsigned long -run(Rule_t* r, char* s) +static unsigned long run(Rule_t *r, char *s) { - Rule_t* q; - char* t; - int c; - int i; - int j; - int x; - Stat_t st; - Buf_t* buf; + Rule_t *q; + char *t; + int c, i, j, x; + Stat_t st; + Buf_t *buf; if (r->flags & RULE_error) return r->time; @@ -1427,7 +1401,7 @@ run(Rule_t* r, char* s) * If the word matches the name of a non-generated prerequisite, * replace it with its canonical path within the source directory. */ - if ((q = (Rule_t*)search(state.rules, t, NULL)) && q->path && !(q->flags & RULE_generated)) + if ((q = getval(state.rules, t)) && q->path && !(q->flags & RULE_generated)) append(buf, q->path); else { @@ -1507,23 +1481,17 @@ run(Rule_t* r, char* s) * return the full path for s using buf workspace */ -static char* -path(Buf_t* buf, char* s, int must) +static char *path(Buf_t *buf, char *s, int must) { - char* p; - char* d; - char* x; - char* e; - int c; - int t; - int o; - Stat_t st; + char *p, *d, *x, *e; + int c, t, o; + Stat_t st; for (e = s; *e && !isspace(*e); e++); t = *e; if ((x = status(buf, 0, s, &st)) && (st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))) return x; - if (!(p = (char*)search(state.vars, "PATH", NULL))) + if (!(p = getval(state.vars, "PATH"))) report(3, "variable not defined", "PATH", 0); do { @@ -1556,22 +1524,17 @@ path(Buf_t* buf, char* s, int must) * done on the first `setv CC ...' */ -static void -probe(void) +static void probe(void) { - char* cc; - char* s; - unsigned long h; - unsigned long q; - Buf_t* buf; - Buf_t* pro; - Buf_t* tmp; + char *cc, *s; + unsigned long h, q; + Buf_t *buf, *pro, *tmp; struct stat st; static char let[] = "ABCDEFGHIJKLMNOP"; static char cmd[] = "mamprobe"; - if (!(cc = (char*)search(state.vars, "CC", NULL))) + if (!(cc = getval(state.vars, "CC"))) cc = "cc"; buf = buffer(); s = path(buf, cmd, 1); @@ -1580,7 +1543,7 @@ probe(void) s = cc = path(pro, cc, 1); for (h = 0; *s; s++) h = h * 0x63c63cd9L + *s + 0x9c39c33dL; - if (!(s = (char*)search(state.vars, "INSTALLROOT", NULL))) + if (!(s = getval(state.vars, "INSTALLROOT"))) report(3, "variable must be defined", "INSTALLROOT", 0); append(buf, s); append(buf, "/lib/probe/C/mam/"); @@ -1612,10 +1575,9 @@ probe(void) * add attributes in s to r */ -static void -attributes(Rule_t* r, char* s) +static void attributes(Rule_t *r, char *s) { - char* t; + char *t; int n; for (;;) @@ -1679,20 +1641,19 @@ attributes(Rule_t* r, char* s) #define LIB_VARPREFIX "mam_lib" -static char* -require(char* lib, int dontcare) +static char *require(char *lib, int dontcare) { static int dynamic = -1; char *s, *r, varname[64]; if (dynamic < 0) - dynamic = (s = search(state.vars, "mam_cc_L", NULL)) ? atoi(s) : 0; + dynamic = (s = getval(state.vars, "mam_cc_L")) ? atoi(s) : 0; if (strlen(lib + 2) > sizeof(varname) - sizeof(LIB_VARPREFIX)) report(3, "-lname too long", lib, 0); sprintf(varname, LIB_VARPREFIX "%s", lib + 2); - if (!(r = search(state.vars, varname, NULL))) + if (!(r = getval(state.vars, varname))) { Buf_t *buf = buffer(), *tmp = buffer(); int c, tofree = 0; @@ -1704,10 +1665,10 @@ require(char* lib, int dontcare) { if (s) append(buf, s); - if (r = search(state.vars, "mam_cc_PREFIX_ARCHIVE", NULL)) + if (r = getval(state.vars, "mam_cc_PREFIX_ARCHIVE")) append(buf, r); append(buf, lib + 2); - if (r = search(state.vars, "mam_cc_SUFFIX_ARCHIVE", NULL)) + if (r = getval(state.vars, "mam_cc_SUFFIX_ARCHIVE")) append(buf, r); r = expand(tmp, use(buf)); if (!stat(r, &st)) @@ -1721,10 +1682,10 @@ require(char* lib, int dontcare) if (dynamic) { append(buf, s); - if (r = search(state.vars, "mam_cc_PREFIX_SHARED", NULL)) + if (r = getval(state.vars, "mam_cc_PREFIX_SHARED")) append(buf, r); append(buf, lib + 2); - if (r = search(state.vars, "mam_cc_SUFFIX_SHARED", NULL)) + if (r = getval(state.vars, "mam_cc_SUFFIX_SHARED")) append(buf, r); r = expand(tmp, use(buf)); if (!stat(r, &st)) @@ -1739,7 +1700,7 @@ require(char* lib, int dontcare) tofree = 1; r = duplicate(r); } - search(state.vars, varname, r); + setval(state.vars, varname, r); append(tmp, lib + 2); append(tmp, ".req"); if (!(f = fopen(use(tmp), "r"))) @@ -1788,7 +1749,7 @@ require(char* lib, int dontcare) } } r = duplicate(r); - search(state.vars, varname, r); + setval(state.vars, varname, r); drop(tmp); drop(buf); } @@ -1799,8 +1760,7 @@ require(char* lib, int dontcare) * update ${<}, ${^} and ${?} */ -static void -update_allprev(Rule_t *r, char *all, char *upd) +static void update_allprev(Rule_t *r, char *all, char *upd) { char *name = r->name; unsigned long n = strlen(name), nn; @@ -1838,8 +1798,7 @@ update_allprev(Rule_t *r, char *all, char *upd) * If inloop==0, modtime must be initialised to zero and parentcmd is ignored. */ -static unsigned long -make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) +static unsigned long make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) { char *s; char *u; /* command name */ @@ -1905,7 +1864,7 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) else s = 0; /* only bother if t is a path to a *.a we built (i.e. not -l...) */ - if (*t == '/') + if (t[0] != '-' || t[1] != 'l') { q = rule(expand(buf, t)); attributes(q, v); @@ -1956,12 +1915,12 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) /* show a nice trace header */ /* ...mamfile path: make relative to ${PACKAGEROOT} */ if (*fname == '/' - && (val = search(state.vars, "PACKAGEROOT", NULL)) && (len = strlen(val)) + && (val = getval(state.vars, "PACKAGEROOT")) && (len = strlen(val)) && strncmp(fname, val, len) == 0 && fname[len] == '/' && fname[++len]) fname += len; /* ...rule name: change install root path prefix back to '${INSTALLROOT}' for brevity */ if (*rname == '/' - && (val = search(state.vars, "INSTALLROOT", NULL)) && (len = strlen(val)) + && (val = getval(state.vars, "INSTALLROOT")) && (len = strlen(val)) && strncmp(rname, val, len) == 0 && rname[len] == '/' && rname[len + 1]) rname += len, rnamepre = "${INSTALLROOT}"; fprintf(stderr, "\n# %s: %lu-%lu: make %s%s\n", @@ -2032,8 +1991,9 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) /* iterate through one or more whitespace-separated words */ vname = duplicate(expand(buf, t)); w = words = duplicate(expand(buf, v)); - save_value = search(state.vars, vname, NULL); - vnode = search(state.vars, vname, empty); + vnode = search(state.vars, vname, 1); + save_value = vnode->value; + vnode->value = empty; for (w = words; w; w = nextw) { /* zero-terminate current word and find next word */ @@ -2065,19 +2025,24 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) } case KEY('m','a','k','e'): - q = rule(expand(buf, t)); - if (!q->making) + { + char *save_making = auto_making->value; + char *save_allprev = auto_allprev->value; + char *save_updprev = auto_updprev->value; + char *name = expand(buf, t); + if ((q = getval(state.rules, name)) && (q->flags & RULE_made)) + report(state.strict < 3 ? 1 : 3, "rule already made", name, 0); + if (!q) + q = rule(name); + /* set ${@}; empty ${?}, ${^} and ${<} */ + auto_making->value = q->name; + auto_updprev->value = empty; + auto_allprev->value = empty; + auto_prev->value = reduplicate(auto_prev->value, empty); + if (q->making) + report(state.strict < 3 ? 1 : 3, "rule already being made", name, 0); + else { - char *save_making = auto_making->value; - char *save_allprev = auto_allprev->value; - char *save_updprev = auto_updprev->value; - - /* set ${@}; empty ${?}, ${^} and ${<} */ - auto_making->value = q->name; - auto_updprev->value = empty; - auto_allprev->value = empty; - auto_prev->value = reduplicate(auto_prev->value, empty); - /* make the target */ attributes(q, v); x = make(q, 0, 0, NULL); @@ -2085,24 +2050,24 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) modtime = x; if (q->flags & RULE_error) r->flags |= RULE_error; - - /* update ${<}, restore/update ${^} and ${?} */ - if (auto_allprev->value != empty) - free(auto_allprev->value); - if (auto_updprev->value != empty) - free(auto_updprev->value); - update_allprev(q, save_allprev, save_updprev); - /* restore ${@} */ - auto_making->value = save_making; } + /* update ${<}, restore/update ${^} and ${?} */ + if (auto_allprev->value != empty) + free(auto_allprev->value); + if (auto_updprev->value != empty) + free(auto_updprev->value); + update_allprev(q, save_allprev, save_updprev); + /* restore ${@} */ + auto_making->value = save_making; continue; + } case KEY('p','r','e','v'): { char *name = expand(buf, t); if (!state.strict) q = rule(name); /* for backward compat */ - else if (!(q = (Rule_t*)search(state.rules, name, NULL))) + else if (!(q = getval(state.rules, name))) { /* * 'prev' on a nonexistent rule, i.e., without a preceding 'make'...'done': * special-case this as a way to declare a simple source file prerequisite @@ -2114,10 +2079,13 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) if (!(q->flags & (RULE_dontcare | RULE_exists))) dont(q, 0, state.keepgoing); } + q->flags |= RULE_made; } else if (*v) report(3, v, "prev: superfluous attributes", 0); - if (!q->making) + if (q->making) + report(state.strict < 3 ? 1 : 3, "rule already being made", name, 0); + else { if (!(q->flags & RULE_ignore) && modtime < q->time) modtime = q->time; @@ -2133,7 +2101,7 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) } case KEY('s','e','t','v'): - if (!search(state.vars, t, NULL)) + if (!getval(state.vars, t)) { if (*v == '"' && state.strict < 2) { @@ -2145,11 +2113,11 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) } } v = duplicate(expand(buf, v)); - search(state.vars, t, v); + setval(state.vars, t, v); if (strcmp(t, "MAMAKE_STRICT") == 0) - state.strict = *v ? strtol(v, NULL, 10) : 1; + state.strict = *v ? atoi(v) : 1; } - if (!state.probed && t[0] == 'C' && t[1] == 'C' && !t[2]) + if (!state.probed && strcmp(t, "CC") == 0) { state.probed = 1; probe(); @@ -2202,10 +2170,9 @@ make(Rule_t *r, int inloop, unsigned long modtime, Buf_t **parentcmd) * verify that active targets were made */ -static int -verify(Dict_item_t* item, void* handle) +static int verify(Dict_item_t *item, void *handle) { - Rule_t* r = (Rule_t*)item->value; + Rule_t *r = item->value; if ((r->flags & (RULE_active|RULE_error|RULE_made)) == RULE_active) dont(r, 0, 1); @@ -2216,44 +2183,59 @@ verify(Dict_item_t* item, void* handle) * return 1 if name is an initializer */ -static int -initializer(char* name) +static int initializer(char *name) { - char* s; + char *s; if (s = strrchr(name, '/')) s++; else s = name; - return s[0] == 'I' && s[1] == 'N' && s[2] == 'I' && s[3] == 'T'; + return !strncmp(s, "INIT", 4); } /* * update recursion leaf r and its prerequisites */ -static int -update(Rule_t* r) +static int update(Rule_t *r) { - List_t* x; - Buf_t* buf; - - static char cmd[] = "${MAMAKE} -C "; - static char arg[] = " ${MAMAKEARGS}"; + List_t *x; + Buf_t *buf; + /* topological sort */ r->flags |= RULE_made; if (r->leaf) r->leaf->flags |= RULE_made; for (x = r->prereqs; x; x = x->next) if (x->rule->leaf && !(x->rule->flags & RULE_made)) update(x->rule); + buf = buffer(); - substitute(buf, cmd); + + /* announce */ + { + char *p, *q; + int n; + append(buf, state.pwd); + add(buf, '/'); + append(buf, r->name); + p = use(buf); + /* show path relative to ${INSTALLROOT} */ + q = getval(state.vars, "INSTALLROOT"); + if (q && strncmp(p, q, n = strlen(q)) == 0) + p += n + 1; + fprintf(stderr, "\n# ... making %s ...\n", p); + if (state.explain) + fprintf(stderr, "# reason: recursion\n"); + } + + /* do */ + append(buf, getval(state.vars, "MAMAKE")); + append(buf, " -C "); append(buf, r->name); - substitute(buf, arg); - fprintf(stderr, "\n# ... making %s ...\n", r->name); - if (state.explain) - fprintf(stderr, "# reason: recursion\n"); + add(buf, ' '); + append(buf, getval(state.vars, "MAMAKEARGS")); run(r, use(buf)); drop(buf); return 0; @@ -2263,14 +2245,12 @@ update(Rule_t* r) * scan Mamfile prereqs */ -static int -scan(Dict_item_t* item, void* handle) +static int scan(Dict_item_t *item, void *handle) { - Rule_t* r = (Rule_t*)item->value; - char* s; - char* t; - Rule_t* q; - Buf_t* buf; + Rule_t *r = item->value; + char *s, *t; + Rule_t *q; + Buf_t *buf; /* * drop non-leaf rules @@ -2311,7 +2291,7 @@ scan(Dict_item_t* item, void* handle) for (s = t; *s && !isspace(*s); s++); *s = '\0'; /* add a rule and prepend it onto the prerequisites */ - if ((q = (Rule_t*)search(state.leaf, t, NULL)) && q != r) + if ((q = getval(state.leaf, t)) && q != r) cons(r, q); } pop(); @@ -2324,12 +2304,11 @@ scan(Dict_item_t* item, void* handle) * descend into op and its prereqs */ -static int -descend(Dict_item_t* item, void* handle) +static int descend(Dict_item_t *item, void *handle) { - Rule_t* r = (Rule_t*)item->value; + Rule_t *r = item->value; - if (!state.active && (!(r->flags & RULE_active) || !(r = (Rule_t*)search(state.leaf, r->name, NULL)))) + if (!state.active && (!(r->flags & RULE_active) || !(r = getval(state.leaf, r->name)))) return 0; return r->leaf && !(r->flags & RULE_made) ? update(r) : 0; } @@ -2338,14 +2317,13 @@ descend(Dict_item_t* item, void* handle) * append the non-leaf active targets to state.opt */ -static int -active(Dict_item_t* item, void* handle) +static int active(Dict_item_t *item, void *handle) { - Rule_t* r = (Rule_t*)item->value; + Rule_t *r = item->value; if (r->flags & RULE_active) { - if (r->leaf || search(state.leaf, r->name, NULL)) + if (r->leaf || getval(state.leaf, r->name)) state.active = 0; else { @@ -2360,14 +2338,11 @@ active(Dict_item_t* item, void* handle) * recurse on mamfiles in subdirs matching pattern */ -static int -recurse(char* pattern) +static int recurse(char *pattern) { - char* s; - char* t; - Rule_t* r; - Buf_t* buf; - Buf_t* tmp; + char *s, *t; + Rule_t *r; + Buf_t *buf, *tmp; struct stat st; /* @@ -2395,7 +2370,7 @@ recurse(char* pattern) else t = r->name; r->leaf = rule(t); - search(state.leaf, t, r); + setval(state.leaf, t, r); } } pop(); @@ -2411,7 +2386,7 @@ recurse(char* pattern) state.active = 1; walk(state.rules, active, NULL); } - search(state.vars, "MAMAKEARGS", duplicate(use(state.opt) + 1)); + setval(state.vars, "MAMAKEARGS", duplicate(use(state.opt) + 1)); /* * scan the Mamfile and descend @@ -2428,15 +2403,11 @@ recurse(char* pattern) return 0; } -int -main(int argc, char** argv) +int main(int argc, char **argv) { - char** e; - char* s; - char* t; - char* v; - Buf_t* tmp; - int c; + char **e, *s, *t, *v; + Buf_t *tmp; + int c; /* * initialize the state @@ -2450,7 +2421,7 @@ main(int argc, char** argv) state.shim_buf = buffer(); state.rules = dictionary(); state.vars = dictionary(); - search(state.vars, "MAMAKE", *argv); + setval(state.vars, "MAMAKE", *argv); /* * parse the options @@ -2488,7 +2459,8 @@ main(int argc, char** argv) case 'K': continue; case 'V': - fprintf(stdout, "%s\n", id + 10); + write(1, id + 10, strlen(id) - 12); + putchar('\n'); exit(0); case 'f': append(state.opt, " -f "); @@ -2508,11 +2480,11 @@ main(int argc, char** argv) continue; case 'G': append(state.opt, " -G"); - search(state.vars, "-debug-symbols", "1"); + setval(state.vars, "-debug-symbols", "1"); continue; case 'S': append(state.opt, " -S"); - search(state.vars, "-strip-symbols", "1"); + setval(state.vars, "-strip-symbols", "1"); continue; case '?': error(ERROR_usage(2), "%s", opt_info.arg); @@ -2556,7 +2528,7 @@ main(int argc, char** argv) c = 0; v = "1"; } - search(state.vars, s - 1, v); + setval(state.vars, s - 1, v); if (c) *t = c; continue; @@ -2595,16 +2567,17 @@ main(int argc, char** argv) continue; case 'G': append(state.opt, " -G"); - search(state.vars, "-debug-symbols", "1"); + setval(state.vars, "-debug-symbols", "1"); continue; case 'K': continue; case 'S': append(state.opt, " -S"); - search(state.vars, "-strip-symbols", "1"); + setval(state.vars, "-strip-symbols", "1"); continue; case 'V': - fprintf(stdout, "%s\n", id + 10); + write(1, id + 10, strlen(id) - 12); + putchar('\n'); exit(0); case 'f': case 'r': @@ -2667,7 +2640,7 @@ main(int argc, char** argv) if (*t == '=') { *t = 0; - search(state.vars, s, t + 1); + setval(state.vars, s, t + 1); *t = '='; break; } @@ -2678,10 +2651,11 @@ main(int argc, char** argv) * initialize the automatic variables */ - auto_making = search(state.vars, "@", empty); - auto_prev = search(state.vars, "<", empty); - auto_allprev = search(state.vars, "^", empty); - auto_updprev = search(state.vars, "?", empty); + auto_making = search(state.vars, "@", 1); + auto_prev = search(state.vars, "<", 1); + auto_allprev = search(state.vars, "^", 1); + auto_updprev = search(state.vars, "?", 1); + auto_making->value = auto_prev->value = auto_allprev->value = auto_updprev->value = empty; /* * grab the command line targets and variable definitions @@ -2698,11 +2672,11 @@ main(int argc, char** argv) t--; c = *t; *t = 0; - search(state.vars, s, v); + setval(state.vars, s, v); tmp = buffer(); append(tmp, s); append(tmp, ".FORCE"); - search(state.vars, use(tmp), v); + setval(state.vars, use(tmp), v); drop(tmp); *t = c; break; @@ -2748,7 +2722,7 @@ main(int argc, char** argv) * read the mamfile(s) and bring the targets up to date */ - search(state.vars, "MAMAKEARGS", duplicate(use(state.opt) + 1)); + setval(state.vars, "MAMAKEARGS", duplicate(use(state.opt) + 1)); push(state.file, NULL, STREAM_MUST); make(rule(""), 0, 0, NULL); pop(); diff --git a/src/cmd/Mamfile b/src/cmd/Mamfile index aae421ab2bce..ea55150f50f2 100644 --- a/src/cmd/Mamfile +++ b/src/cmd/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 make test virtual make install virtual diff --git a/src/cmd/builtin/Mamfile b/src/cmd/builtin/Mamfile index e7ecc3cbac7a..fc18b4478e6d 100644 --- a/src/cmd/builtin/Mamfile +++ b/src/cmd/builtin/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 setv INSTALLROOT ../../.. setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast @@ -34,7 +34,8 @@ make install virtual prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit make ${PACKAGE_ast_INCLUDE}/endian.h implicit make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_common.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_common.h done done done @@ -46,14 +47,16 @@ make install virtual make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit prev ${PACKAGE_ast_INCLUDE}/endian.h make ${PACKAGE_ast_INCLUDE}/wchar.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h done done done make ${PACKAGE_ast_INCLUDE}/stdio.h implicit make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_std.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_std.h done done prev ${PACKAGE_ast_INCLUDE}/ast_common.h diff --git a/src/cmd/builtin/pty.c b/src/cmd/builtin/pty.c index 86ea8f75bff5..0ff54befc435 100644 --- a/src/cmd/builtin/pty.c +++ b/src/cmd/builtin/pty.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2013 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -407,12 +407,12 @@ process(Sfio_t* mp, Sfio_t* lp, int delay, int timeout) } for (i = t = 0; i < n; i++) { - if (!(sfvalue(sps[i]) & SF_READ)) + if (!(sfvalue(sps[i]) & SFIO_READ)) /*skip*/; else if (sps[i] == mp) { t++; - if (!(s = (char*)sfreserve(mp, SF_UNBOUND, -1))) + if (!(s = (char*)sfreserve(mp, SFIO_UNBOUND, -1))) { sfclose(mp); mp = 0; @@ -587,7 +587,7 @@ masterline(Sfio_t* mp, Sfio_t* lp, char* prompt, int must, int timeout, Master_t } goto done; } - if ((n = sfpoll(&mp, 1, timeout)) <= 0 || !((int)sfvalue(mp) & SF_READ)) + if ((n = sfpoll(&mp, 1, timeout)) <= 0 || !((int)sfvalue(mp) & SFIO_READ)) { if (n < 0) { @@ -623,7 +623,7 @@ masterline(Sfio_t* mp, Sfio_t* lp, char* prompt, int must, int timeout, Master_t } return NULL; } - if (!(s = sfreserve(mp, SF_UNBOUND, -1))) + if (!(s = sfreserve(mp, SFIO_UNBOUND, -1))) { if (!prompt) { @@ -652,7 +652,7 @@ masterline(Sfio_t* mp, Sfio_t* lp, char* prompt, int must, int timeout, Master_t error(-2, "b \"%s\"", fmtnesq(s, "\"", n)); if ((bp->max - bp->end) < n) { - a = roundof(bp->max - bp->buf + n, SF_BUFSIZE); + a = roundof(bp->max - bp->buf + n, SFIO_BUFSIZE); r = bp->buf; if (!(bp->buf = vmnewof(bp->vm, bp->buf, char, a, 0))) outofmemory(); @@ -790,11 +790,11 @@ dialogue(Sfio_t* mp, Sfio_t* lp, int delay, int timeout) if (!(vm = vmopen(Vmdcheap, Vmbest, 0)) || !(cond = vmnewof(vm, 0, Cond_t, 1, 0)) || !(master = vmnewof(vm, 0, Master_t, 1, 0)) || - !(master->buf = vmnewof(vm, 0, char, 2 * SF_BUFSIZE, 0))) + !(master->buf = vmnewof(vm, 0, char, 2 * SFIO_BUFSIZE, 0))) outofmemory(); master->vm = vm; master->cur = master->end = master->buf; - master->max = master->buf + 2 * SF_BUFSIZE - 1; + master->max = master->buf + 2 * SFIO_BUFSIZE - 1; master->restore = -1; errno = 0; id = error_info.id; @@ -1077,7 +1077,7 @@ b_pty(int argc, char** argv, Shbltin_t* context) error(ERROR_system(1), "unable to create pty"); UNREACHABLE(); } - if (!(mp = sfnew(NULL, 0, SF_UNBOUND, master, SF_READ|SF_WRITE))) + if (!(mp = sfnew(NULL, 0, SFIO_UNBOUND, master, SFIO_READ|SFIO_WRITE))) { error(ERROR_system(1), "cannot open master stream"); UNREACHABLE(); diff --git a/src/cmd/ksh93/COMPATIBILITY b/src/cmd/ksh93/COMPATIBILITY index 0a4fc327b004..0fd8d0fa4268 100644 --- a/src/cmd/ksh93/COMPATIBILITY +++ b/src/cmd/ksh93/COMPATIBILITY @@ -8,6 +8,9 @@ For more details, see the NEWS file and for complete details, see the git log. from the environment. Any script that depends on this will need to be changed to typeset the expected attributes itself. +2. Defining a function called '.sh.tilde' is an error. To customize tilde + expansion, use .sh.tilde.get instead (see the manual page for details). + ____________________________________________________________________________ ksh 93u+m/1.0.9 vs. ksh 93u+ diff --git a/src/cmd/ksh93/Mamfile b/src/cmd/ksh93/Mamfile index 0df25ec19856..58875a437a75 100644 --- a/src/cmd/ksh93/Mamfile +++ b/src/cmd/ksh93/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 setv INSTALLROOT ../../.. setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast setv CC cc @@ -27,7 +27,8 @@ make install virtual prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit make ${PACKAGE_ast_INCLUDE}/endian.h implicit make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_common.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_common.h done done done @@ -39,14 +40,16 @@ make install virtual make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit prev ${PACKAGE_ast_INCLUDE}/endian.h make ${PACKAGE_ast_INCLUDE}/wchar.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h done done done make ${PACKAGE_ast_INCLUDE}/stdio.h implicit make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit prev ${PACKAGE_ast_INCLUDE}/sfio_s.h - prev ${PACKAGE_ast_INCLUDE}/ast_std.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_std.h done done prev ${PACKAGE_ast_INCLUDE}/ast_common.h @@ -147,6 +150,10 @@ make install virtual prev ${PACKAGE_ast_INCLUDE}/sig.h implicit prev ${PACKAGE_ast_INCLUDE}/glob.h implicit prev ${PACKAGE_ast_INCLUDE}/releaseflags.h implicit + make ${PACKAGE_ast_INCLUDE}/lc.h implicit + prev ${PACKAGE_ast_INCLUDE}/ast.h + done + prev ${PACKAGE_ast_INCLUDE}/ast_tty.h implicit note * note * Library dependencies @@ -178,7 +185,7 @@ make install virtual prev ${PACKAGE_ast_INCLUDE}/dlldefs.h done - loop F options externs sigfeatures time dynamic ttys locale cmds poll rlimits + loop F options externs sigfeatures time dynamic locale cmds poll rlimits make FEATURE/${F} implicit prev features/${F} exec - ${iffe_run} ${<} @@ -324,7 +331,7 @@ make install virtual prev ${PACKAGE_ast_INCLUDE}/option.h done - make include/regress.h + make include/regress.h implicit done make include/argnod.h implicit @@ -369,7 +376,7 @@ make install virtual done make include/terminal.h implicit - prev FEATURE/ttys + prev ${PACKAGE_ast_INCLUDE}/ast_tty.h done make include/edit.h implicit @@ -425,7 +432,7 @@ make install virtual prev ${PACKAGE_ast_INCLUDE}/releaseflags.h done - make include/timeout.h + make include/timeout.h implicit done note * @@ -938,6 +945,7 @@ make install virtual prev include/shtable.h prev ${PACKAGE_ast_INCLUDE}/ccode.h prev include/defs.h + prev ${PACKAGE_ast_INCLUDE}/lc.h prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h prev ${PACKAGE_ast_INCLUDE}/ast.h prev shopt.h @@ -1207,7 +1215,7 @@ make install virtual shim - } make ksh - prev libshell.a + bind -lshell make pmain.o prev sh/pmain.c exec - ${compile} ${<} @@ -1216,7 +1224,7 @@ make install virtual done ksh make shcomp - prev libshell.a + bind -lshell make shcomp.o prev sh/shcomp.c exec - ${compile} ${<} @@ -1228,7 +1236,6 @@ make install virtual note * Pre-install note * - prev libshell.a loop DIR bin include/ast lib/lib man/man1 man/man3 fun etc make ${INSTALLROOT}/${DIR} exec - mkdir -p ${@} @@ -1276,11 +1283,6 @@ make install virtual prev kshrc.sh exec - cp -f ${<} ${@} done - make announce_build_done notrace virtual - prev ksh - exec - ${<} -c 'print \# KornShell $KSH_VERSION ' - exec - echo "# Type 'bin/package use' to try it out" - done done install note * diff --git a/src/cmd/ksh93/README b/src/cmd/ksh93/README index 41f0d1779bfc..d4c3d0855364 100644 --- a/src/cmd/ksh93/README +++ b/src/cmd/ksh93/README @@ -119,8 +119,6 @@ The options have the following defaults and meanings: NOECHOE off Disable the '-e' option to the 'echo' command, unless SHOPT_ECHOPRINT is enabled. - OLDTERMIO off Use either termios or termio at runtime. - OPTIMIZE on Optimize loop invariants for with for and while loops. PRINTF_LEGACY The printf built-in accepts a format operand that starts diff --git a/src/cmd/ksh93/SHOPT.sh b/src/cmd/ksh93/SHOPT.sh index 902f2ba572b8..51a59682288e 100644 --- a/src/cmd/ksh93/SHOPT.sh +++ b/src/cmd/ksh93/SHOPT.sh @@ -28,7 +28,6 @@ SHOPT MKSERVICE=0 # enable the mkservice and eloop builtins SHOPT MULTIBYTE= # multibyte character handling SHOPT NAMESPACE=1 # allow namespaces SHOPT NOECHOE=0 # turn off 'echo -e' when SHOPT_ECHOPRINT is disabled -SHOPT OLDTERMIO= # support both TCGETA and TCGETS SHOPT OPTIMIZE=1 # optimize loop invariants SHOPT P_SUID=0 # real UIDs >= this value require -p for set[ug]id (to turn off, use empty, not 0) SHOPT PRINTF_LEGACY= # allow noncompliant printf(1) syntax (format arg starting with '-' without prior '--') diff --git a/src/cmd/ksh93/bltins/cd_pwd.c b/src/cmd/ksh93/bltins/cd_pwd.c index fa765fba6472..5cc3d4fc4d0c 100644 --- a/src/cmd/ksh93/bltins/cd_pwd.c +++ b/src/cmd/ksh93/bltins/cd_pwd.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -171,7 +171,7 @@ int b_cd(int argc, char *argv[],Shbltin_t *context) #endif /* _WINIX */ if(*stkptr(sh.stk,PATH_OFFSET)!='/') { - char *last=(char*)stkfreeze(sh.stk,1); + char *last = stkfreeze(sh.stk,1); stkseek(sh.stk,PATH_OFFSET); sfputr(sh.stk,oldpwd,-1); /* don't add '/' if oldpwd is / itself */ diff --git a/src/cmd/ksh93/bltins/getopts.c b/src/cmd/ksh93/bltins/getopts.c index 5374d088fff7..0e93110736be 100644 --- a/src/cmd/ksh93/bltins/getopts.c +++ b/src/cmd/ksh93/bltins/getopts.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -41,7 +41,7 @@ static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp) #endif /* SHOPT_NAMESPACE */ { int savtop = stktell(stkp); - char *savptr = stkfreeze(stkp,0); + void *savptr = stkfreeze(stkp,0); sfputc(stkp,'$'); sfputc(stkp,'('); sfputr(stkp,s,')'); diff --git a/src/cmd/ksh93/bltins/hist.c b/src/cmd/ksh93/bltins/hist.c index 4be11d1a6a9b..8a69ce12c5b5 100644 --- a/src/cmd/ksh93/bltins/hist.c +++ b/src/cmd/ksh93/bltins/hist.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -213,7 +213,7 @@ int b_hist(int argc,char *argv[], Shbltin_t *context) errormsg(SH_DICT,ERROR_system(1),e_create,fname); UNREACHABLE(); } - outfile= sfnew(NULL,sh.outbuff,IOBSIZE,fdo,SF_WRITE); + outfile= sfnew(NULL,sh.outbuff,IOBSIZE,fdo,SFIO_WRITE); arg = "\n"; nflag++; } @@ -279,7 +279,7 @@ int b_hist(int argc,char *argv[], Shbltin_t *context) errormsg(SH_DICT,ERROR_exit(1),e_toodeep,"history"); UNREACHABLE(); } - iop = sfnew(NULL,buff,IOBSIZE,fdo,SF_READ); + iop = sfnew(NULL,buff,IOBSIZE,fdo,SFIO_READ); sh_eval(iop,1); /* this will close fdo */ hist_depth--; } diff --git a/src/cmd/ksh93/bltins/misc.c b/src/cmd/ksh93/bltins/misc.c index 92b018352ec9..74cd2f73f677 100644 --- a/src/cmd/ksh93/bltins/misc.c +++ b/src/cmd/ksh93/bltins/misc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -64,6 +64,8 @@ static void noexport(Namval_t* np, void *data) { NOT_USED(data); + if(sh.subshell && !sh.subshare) + sh_assignok(np,0); nv_offattr(np,NV_EXPORT); } @@ -77,11 +79,9 @@ int b_redirect(int argc,char *argv[],Shbltin_t *context){} int b_exec(int argc,char *argv[], Shbltin_t *context) { int n; - struct checkpt *pp; const char *pname; int clear = 0; char *arg0 = 0; - NOT_USED(argc); NOT_USED(context); sh.st.ioset = 0; while (n = optget(argv, *argv[0]=='r' ? sh_optredirect : sh_optexec)) switch (n) @@ -115,16 +115,13 @@ int b_exec(int argc,char *argv[], Shbltin_t *context) /* from here on, it's 'exec' with args, so we're replacing the shell */ if(sh_isoption(SH_RESTRICTED)) - { errormsg(SH_DICT,ERROR_exit(1),e_restricted,argv[0]); - UNREACHABLE(); - } else { struct argnod *arg=sh.envlist; Namval_t* np; char *cp; - if(sh.subshell && !sh.subshare) + if(arg0 && sh.subshell && !sh.subshare) sh_subfork(); if(clear) nv_scan(sh.var_tree,noexport,0,NV_EXPORT,NV_EXPORT); @@ -148,14 +145,25 @@ int b_exec(int argc,char *argv[], Shbltin_t *context) /* if the main shell is about to be replaced, decrease SHLVL to cancel out a subsequent increase */ if(!sh.realsubshell) (*SHLVL->nvalue.ip)--; - /* force bad exec to terminate shell */ - pp = (struct checkpt*)sh.jmplist; - pp->mode = SH_JMPEXIT; + sh_onstate(SH_EXEC); + if(sh.subshell && !sh.subshare) + { + struct dolnod *dp = stkalloc(sh.stk, sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argc*sizeof(char*));; + struct comnod *t = stkalloc(sh.stk,sizeof(struct comnod)); + memset(t, 0, sizeof(struct comnod)); + dp->dolnum = argc; + dp->dolbot = ARG_SPARE; + memcpy(dp->dolval+ARG_SPARE, argv, (argc+1)*sizeof(char*)); + t->comarg = (struct argnod*)dp; + sh_exec((Shnode_t*)t,sh_isstate(SH_ERREXIT)); + sh_offstate(SH_EXEC); + siglongjmp(*sh.jmplist,SH_JMPEXIT); + } sh_sigreset(2); sh_freeup(); path_exec(pname,argv,NULL); } - return 1; + UNREACHABLE(); } int b_let(int argc,char *argv[],Shbltin_t *context) @@ -312,7 +320,7 @@ int b_dot_cmd(int n,char *argv[],Shbltin_t *context) else { buffer = sh_malloc(IOBSIZE+1); - iop = sfnew(NULL,buffer,IOBSIZE,fd,SF_READ); + iop = sfnew(NULL,buffer,IOBSIZE,fd,SFIO_READ); sh_offstate(SH_NOFORK); sh_eval(iop,sh_isstate(SH_PROFILE)?SH_FUNEVAL:0); } @@ -578,7 +586,7 @@ int b_times(int argc, char *argv[], Shbltin_t *context) return 0; } -#ifdef _cmd_universe +#if _cmd_universe /* * There are several universe styles that are masked by the getuniv(), * setuniv() calls. diff --git a/src/cmd/ksh93/bltins/mkservice.c b/src/cmd/ksh93/bltins/mkservice.c index 0836285e2ae1..401368b4d5c0 100644 --- a/src/cmd/ksh93/bltins/mkservice.c +++ b/src/cmd/ksh93/bltins/mkservice.c @@ -228,7 +228,7 @@ static int waitnotify(int fd, long timeout, int rw) *pstream++ = sh_fd2sfio(file_list[i]); } for(i=0; i < pstream-poll_list; i++) - sfset(poll_list[i],SF_WRITE,0); + sfset(poll_list[i],SFIO_WRITE,0); nready = ready = 0; errno = 0; #ifdef DEBUG @@ -245,7 +245,7 @@ static int waitnotify(int fd, long timeout, int rw) sfputc(sfstderr,'\n'); #endif for(i=0; i < pstream-poll_list; i++) - sfset(poll_list[i],SF_WRITE,1); + sfset(poll_list[i],SFIO_WRITE,1); if(nready<=0) return errno? -1: 0; if(special && poll_list[0]==special) diff --git a/src/cmd/ksh93/bltins/print.c b/src/cmd/ksh93/bltins/print.c index 77357847a861..93e0ef7dce3f 100644 --- a/src/cmd/ksh93/bltins/print.c +++ b/src/cmd/ksh93/bltins/print.c @@ -176,6 +176,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context) Namval_t *vname=0; Optdisc_t disc; exitval = 0; + memset(&disc, 0, sizeof(disc)); disc.version = OPT_VERSION; disc.infof = infof; if(argc>0) @@ -307,7 +308,9 @@ int b_print(int argc, char *argv[], Shbltin_t *context) errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg); UNREACHABLE(); } +#if SHOPT_PRINTF_LEGACY skipopts: +#endif /* SHOPT_PRINTF_LEGACY */ opt_info.disc = NULL; argv += opt_info.index; if(error_info.errors || (argc<0 && !(format = *argv++))) @@ -353,13 +356,13 @@ int b_print(int argc, char *argv[], Shbltin_t *context) if(!(outfile=sh.sftable[fd])) { sh_onstate(SH_NOTRACK); - n = SF_WRITE|((n&IOREAD)?SF_READ:0); + n = SFIO_WRITE|((n&IOREAD)?SFIO_READ:0); sh.sftable[fd] = outfile = sfnew(NULL,sh.outbuff,IOBSIZE,fd,n); sh_offstate(SH_NOTRACK); - sfpool(outfile,sh.outpool,SF_WRITE); + sfpool(outfile,sh.outpool,SFIO_WRITE); } /* turn off share to guarantee atomic writes for printf */ - n = sfset(outfile,SF_SHARE|SF_PUBLIC,0); + n = sfset(outfile,SFIO_SHARE|SFIO_PUBLIC,0); printf_v: if(format) { @@ -372,7 +375,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context) pdata.hdr.reloadf = reload; pdata.nextarg = argv; sh_offstate(SH_STOPOK); - pool=sfpool(sfstderr,NULL,SF_WRITE); + pool=sfpool(sfstderr,NULL,SFIO_WRITE); do { pdata.argv0 = pdata.nextarg; @@ -384,7 +387,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context) if(pdata.nextarg == nullarg && pdata.argsize>0) if(sfwrite(outfile,stkptr(sh.stk,stktell(sh.stk)),pdata.argsize) < 0) exitval = 1; - sfpool(sfstderr,pool,SF_WRITE); + sfpool(sfstderr,pool,SFIO_WRITE); if (pdata.err) exitval = 1; } @@ -422,8 +425,8 @@ int b_print(int argc, char *argv[], Shbltin_t *context) #endif /* !SHOPT_SCRIPTONLY */ else { - if(n&SF_SHARE) - sfset(outfile,SF_SHARE|SF_PUBLIC,1); + if(n&SFIO_SHARE) + sfset(outfile,SFIO_SHARE|SFIO_PUBLIC,1); if (sfsync(outfile) < 0) exitval = 1; } diff --git a/src/cmd/ksh93/bltins/read.c b/src/cmd/ksh93/bltins/read.c index ba4229ec3d6c..2186c99e7fce 100644 --- a/src/cmd/ksh93/bltins/read.c +++ b/src/cmd/ksh93/bltins/read.c @@ -178,7 +178,7 @@ int b_read(int argc,char *argv[], Shbltin_t *context) } bypass: sh.prompt = default_prompt; - if(r && (sh.prompt=(char*)sfreserve(sfstderr,r,SF_LOCKR))) + if(r && (sh.prompt=(char*)sfreserve(sfstderr,r,SFIO_LOCKR))) { memcpy(sh.prompt,prompt,r); sfwrite(sfstderr,sh.prompt,r-1); @@ -277,11 +277,11 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, Sflong_t } else if(flags&C_FLAG) { - char *sp = np->nvenv; + void *sp = np->nvmeta; delim = -1; nv_unset(np); if(!nv_isattr(np,NV_MINIMAL)) - np->nvenv = sp; + np->nvmeta = sp; nv_setvtree(np); } else @@ -349,9 +349,9 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, Sflong_t flags |= NN_FLAG; size = nv_size(np); } - was_write = (sfset(iop,SF_WRITE,0)&SF_WRITE)!=0; + was_write = (sfset(iop,SFIO_WRITE,0)&SFIO_WRITE)!=0; if(fd==0) - was_share = (sfset(iop,SF_SHARE,sh.redir0!=2)&SF_SHARE)!=0; + was_share = (sfset(iop,SFIO_SHARE,sh.redir0!=2)&SFIO_SHARE)!=0; if(timeout || (sh.fdstatus[fd]&(IOTTY|IONOSEEK))) { sh_pushcontext(&buff,1); @@ -381,7 +381,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, Sflong_t else end = var + sizeof(buf) - 1; up = cur = var; - if((sfset(iop,SF_SHARE,1)&SF_SHARE) && fd!=0) + if((sfset(iop,SFIO_SHARE,1)&SFIO_SHARE) && fd!=0) was_share = 1; if(size==0) { @@ -408,7 +408,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, Sflong_t else { f = 1; - if(cp = sfreserve(iop,c,SF_LOCKR)) + if(cp = sfreserve(iop,c,SFIO_LOCKR)) m = sfvalue(iop); else if(flags&NN_FLAG) { @@ -419,7 +419,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, Sflong_t else { c = sfvalue(iop); - m = (cp = sfreserve(iop,c,SF_LOCKR)) ? sfvalue(iop) : 0; + m = (cp = sfreserve(iop,c,SFIO_LOCKR)) ? sfvalue(iop) : 0; } } if(m>0 && (flags&N_FLAG) && !binary && (v=memchr(cp,'\n',m))) @@ -499,7 +499,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, Sflong_t var = sh_memdup(var,c+1); nv_putval(np,var,NV_RAW); nv_setsize(np,c); - if(!nv_isattr(np,NV_IMPORT|NV_EXPORT) && (mp=(Namval_t*)np->nvenv)) + if(!nv_isattr(np,NV_MINIMAL|NV_EXPORT) && (mp = np->nvmeta)) nv_setsize(mp,c); } } @@ -843,9 +843,9 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, Sflong_t if(timeout || (sh.fdstatus[fd]&(IOTTY|IONOSEEK))) sh_popcontext(&buff); if(was_write) - sfset(iop,SF_WRITE,1); + sfset(iop,SFIO_WRITE,1); if(!was_share) - sfset(iop,SF_SHARE,0); + sfset(iop,SFIO_SHARE,0); if((sh.fdstatus[fd]&IOTTY) && !keytrap) tty_cooked(fd); #if !SHOPT_SCRIPTONLY diff --git a/src/cmd/ksh93/bltins/test.c b/src/cmd/ksh93/bltins/test.c index 220534ab5e31..48b391d4ebf6 100644 --- a/src/cmd/ksh93/bltins/test.c +++ b/src/cmd/ksh93/bltins/test.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -613,7 +613,7 @@ int sh_access(const char *name, int mode) goto skip; if(sh.userid==sh.euserid && sh.groupid==sh.egroupid) return access(name,mode); -#ifdef _lib_setreuid +#if _lib_setreuid /* swap the real UID to effective, check access then restore */ /* first swap real and effective GID, if different */ if(sh.groupid==sh.euserid || setregid(sh.egroupid,sh.groupid)==0) @@ -649,7 +649,7 @@ int sh_access(const char *name, int mode) mode <<= 6; else if(sh.egroupid == statb.st_gid) mode <<= 3; -#ifdef _lib_getgroups +#if _lib_getgroups /* on some systems you can be in several groups */ else { @@ -665,7 +665,7 @@ int sh_access(const char *name, int mode) maxgroups = (int)astconf_long(CONF_NGROUPS_MAX); } } - groups = (gid_t*)stkalloc(sh.stk,(maxgroups+1)*sizeof(gid_t)); + groups = stkalloc(sh.stk,(maxgroups+1)*sizeof(gid_t)); n = getgroups(maxgroups,groups); while(--n >= 0) { diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index 22932cf3bcf2..ce24663b7fb7 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -233,7 +233,7 @@ int b_typeset(int argc,char *argv[],Shbltin_t *context) } else if(argv[0][0] != 't') /* not ypeset */ { - char **new_argv = (char **)stkalloc(sh.stk, (argc + 2) * sizeof(char*)); + char **new_argv = stkalloc(sh.stk, (argc + 2) * sizeof(char*)); error_info.id = new_argv[0] = SYSTYPESET->nvname; if(argv[0][0] == 'a') /* utoload == typeset -fu */ new_argv[1] = "-fu"; @@ -549,7 +549,7 @@ int b_typeset(int argc,char *argv[],Shbltin_t *context) } else if(nv_isnull(tdata.tp) && sh.envlist) /* only create a type command if there were assignment(s) */ nv_newtype(tdata.tp); - tdata.tp->nvenv = tdata.help; + tdata.tp->nvmeta = tdata.help; flag &= ~NV_TYPE; if(nv_isattr(tdata.tp,NV_TAGGED)) { @@ -790,7 +790,7 @@ static int setall(char **argv,int flag,Dt_t *troot,struct tdata *tp) } if(nv_isnull(np) && !nv_isarray(np) && nv_isattr(np,NV_NOFREE)) nv_offattr(np,NV_NOFREE); - else if(tp->tp && !nv_isattr(np,NV_MINIMAL|NV_EXPORT) && (mp=(Namval_t*)np->nvenv) && (ap=nv_arrayptr(mp)) && (ap->nelem&ARRAY_TREE)) + else if(tp->tp && !nv_isattr(np,NV_MINIMAL|NV_EXPORT) && (mp = np->nvmeta) && (ap = nv_arrayptr(mp)) && (ap->nelem & ARRAY_TREE)) { errormsg(SH_DICT,ERROR_exit(1),e_typecompat,nv_name(np)); UNREACHABLE(); @@ -958,7 +958,7 @@ static int setall(char **argv,int flag,Dt_t *troot,struct tdata *tp) } if(tp->help && !nv_isattr(np,NV_MINIMAL|NV_EXPORT)) { - np->nvenv = tp->help; + np->nvmeta = tp->help; nv_onattr(np,NV_EXPORT); } if(last) @@ -1607,7 +1607,7 @@ static void print_scan(Sfio_t *file, int flag, Dt_t *root, int option,struct tda if(flag==NV_LTOU || flag==NV_UTOL) tp->scanmask |= NV_UTOL|NV_LTOU; namec = nv_scan(root, nullscan, tp, tp->scanmask, flag&~NV_IARRAY); - argv = tp->argnam = (char**)stkalloc(sh.stk,(namec+1)*sizeof(char*)); + argv = tp->argnam = stkalloc(sh.stk,(namec+1)*sizeof(char*)); namec = nv_scan(root, pushname, tp, tp->scanmask, flag&~NV_IARRAY); if(mbcoll()) strsort(argv,namec,strcoll); diff --git a/src/cmd/ksh93/bltins/ulimit.c b/src/cmd/ksh93/bltins/ulimit.c index 2a187b9879ed..21ec383dab43 100644 --- a/src/cmd/ksh93/bltins/ulimit.c +++ b/src/cmd/ksh93/bltins/ulimit.c @@ -68,7 +68,7 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context) char *limit; int mode=0, n; unsigned long hit = 0; -#ifdef _lib_getrlimit +#if _lib_getrlimit struct rlimit rlp; #endif /* _lib_getrlimit */ const Limit_t* tp; @@ -160,7 +160,7 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context) } else { -#ifdef _lib_getrlimit +#if _lib_getrlimit if(getrlimit(n,&rlp) <0) { errormsg(SH_DICT,ERROR_system(1),e_number,limit); @@ -188,7 +188,7 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context) { if(!nosupport) { -#ifdef _lib_getrlimit +#if _lib_getrlimit if(getrlimit(n,&rlp)<0) { errormsg(SH_DICT,ERROR_system(0),e_limit,tp->description); @@ -200,7 +200,7 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context) if(mode&SOFT) i = rlp.rlim_cur; #else -# ifdef _lib_ulimit +# if _lib_ulimit n--; # endif /* _lib_ulimit */ i = -1; diff --git a/src/cmd/ksh93/data/builtins.c b/src/cmd/ksh93/data/builtins.c index 45bafd9a99d4..50055a306807 100644 --- a/src/cmd/ksh93/data/builtins.c +++ b/src/cmd/ksh93/data/builtins.c @@ -120,7 +120,7 @@ const struct shtable3 shtab_builtins[] = "times", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(times), "ulimit", NV_BLTIN|BLT_ENV, bltin(ulimit), "umask", NV_BLTIN|BLT_ENV, bltin(umask), -#ifdef _cmd_universe +#if _cmd_universe "universe", NV_BLTIN|BLT_ENV, bltin(universe), #endif /* _cmd_universe */ "wait", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(wait), @@ -657,13 +657,14 @@ const char sh_opteval[] = ; const char sh_optexec[] = -"[-1c?\n@(#)$Id: exec (ksh 93u+m) 2020-06-11 $\n]" +"[-1c?\n@(#)$Id: exec (ksh 93u+m) 2024-03-04 $\n]" "[--catalog?" SH_DICT "]" "[+NAME?exec - execute command, open/close and duplicate file descriptors]" "[+DESCRIPTION?\bexec\b is a special built-in command that can be used to " "manipulate file descriptors or to replace the current shell " "with a new command.]" -"[+?If \acommand\a is specified, then the current shell process will be " +"[+?If \acommand\a is specified, then \acommand\a is searched on PATH as " + "an external command and the current shell process will be " "replaced by \acommand\a rather than running \acommand\a and waiting " "for it to complete. Note that there is no need to use " "\bexec\b to enhance performance since the shell implicitly " diff --git a/src/cmd/ksh93/data/msg.c b/src/cmd/ksh93/data/msg.c index 2091f785280c..698daeb0435c 100644 --- a/src/cmd/ksh93/data/msg.c +++ b/src/cmd/ksh93/data/msg.c @@ -85,7 +85,7 @@ const char e_defined[] = "%s: function not defined"; const char e_subscript[] = "%s: subscript out of range"; const char e_toodeep[] = "%s: recursion too deep"; const char e_access[] = "permission denied"; -#ifdef _cmd_universe +#if _cmd_universe const char e_nouniverse[] = "universe not accessible"; #endif /* _cmd_universe */ const char e_direct[] = "bad directory"; diff --git a/src/cmd/ksh93/edit/completion.c b/src/cmd/ksh93/edit/completion.c index 9686025df4f9..fdb1e8578795 100644 --- a/src/cmd/ksh93/edit/completion.c +++ b/src/cmd/ksh93/edit/completion.c @@ -277,8 +277,8 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) ep->e_nlist = 0; } } - comptr = (struct comnod*)stkalloc(sh.stk,sizeof(struct comnod)); - ap = (struct argnod*)stkseek(sh.stk,ARGVAL); + comptr = stkalloc(sh.stk,sizeof(struct comnod)); + ap = stkseek(sh.stk,ARGVAL); #if SHOPT_MULTIBYTE { int c = *cur; @@ -368,7 +368,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) } if(addstar) sfputc(sh.stk,addstar); - ap = (struct argnod*)stkfreeze(sh.stk,1); + ap = stkfreeze(sh.stk,1); } if(mode!='*') sh_onoption(SH_MARKDIRS); diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c index 8bbbcf378d7a..78e0ea7c100c 100644 --- a/src/cmd/ksh93/edit/edit.c +++ b/src/cmd/ksh93/edit/edit.c @@ -32,7 +32,7 @@ #include #include #include "FEATURE/time" -#ifdef _hdr_utime +#if _hdr_utime # include # include #endif @@ -105,28 +105,6 @@ static char *erase_eos; /* erase to end of screen */ #define ECHOMODE 3 #define SYSERR -1 -#if SHOPT_OLDTERMIO -# undef tcgetattr -# undef tcsetattr -#endif /* SHOPT_OLDTERMIO */ - -#ifdef RT -# define VENIX 1 -#endif /* RT */ - - -#ifdef _hdr_sgtty -# ifdef TIOCGETP - static int l_mask; - static struct tchars l_ttychars; - static struct ltchars l_chars; - static char l_changed; /* set if mode bits changed */ -# define L_CHARS 4 -# define T_CHARS 2 -# define L_MASK 1 -# endif /* TIOCGETP */ -#endif /* _hdr_sgtty */ - static int keytrap(Edit_t *,char*, int, int, int); #ifndef _POSIX_DISABLE @@ -149,7 +127,7 @@ int tty_check(int fd) Sfio_t *sp; ep->e_savefd = -1; if(fd < 0 || fd > sh.lim.open_max || sh.fdstatus[fd] == IOCLOSE - || (sp = sh.sftable[fd]) && (sfset(sp,0,0) & SF_STRING)) + || (sp = sh.sftable[fd]) && (sfset(sp,0,0) & SFIO_STRING)) return 0; return tty_get(fd,&tty)==0; } @@ -220,18 +198,6 @@ void tty_cooked(int fd) return; if(fd < 0) fd = ep->e_savefd; -#ifdef L_MASK - /* restore flags */ - if(l_changed&L_MASK) - ioctl(fd,TIOCLSET,&l_mask); - if(l_changed&T_CHARS) - /* restore alternate break character */ - ioctl(fd,TIOCSETC,&l_ttychars); - if(l_changed&L_CHARS) - /* restore alternate break character */ - ioctl(fd,TIOCSLTC,&l_chars); - l_changed = 0; -#endif /* L_MASK */ /*** don't do tty_set unless ttyparm has valid data ***/ if(tty_set(fd, TCSANOW, &ttyparm) == SYSERR) return; @@ -248,9 +214,6 @@ void tty_cooked(int fd) int tty_raw(int fd, int echomode) { int echo = echomode; -#ifdef L_MASK - struct ltchars lchars; -#endif /* L_MASK */ Edit_t *ep = (Edit_t*)(sh.ed_context); if(ep->e_raw==RAWMODE) return echo?-1:0; @@ -258,95 +221,57 @@ int tty_raw(int fd, int echomode) return echo?0:-1; if(tty_get(fd,&ttyparm) == SYSERR) return -1; -#if L_MASK || VENIX - if(ttyparm.sg_flags&LCASE) - return -1; - if(!(ttyparm.sg_flags&ECHO)) - { - if(!echomode) - return -1; - echo = 0; - } - nttyparm = ttyparm; - if(!echo) - nttyparm.sg_flags &= ~(ECHO | TBDELAY); -# ifdef CBREAK - nttyparm.sg_flags |= CBREAK; -# else - nttyparm.sg_flags |= RAW; -# endif /* CBREAK */ - ep->e_erase = ttyparm.sg_erase; - ep->e_kill = ttyparm.sg_kill; - ep->e_eof = cntl('D'); - ep->e_werase = cntl('W'); - ep->e_lnext = cntl('V'); - if( tty_set(fd, TCSADRAIN, &nttyparm) == SYSERR ) - return -1; - ep->e_ttyspeed = (ttyparm.sg_ospeed>=B1200?FAST:SLOW); -# ifdef TIOCGLTC - /* try to remove effect of ^V and ^Y and ^O */ - if(ioctl(fd,TIOCGLTC,&l_chars) != SYSERR) - { - lchars = l_chars; - lchars.t_lnextc = -1; - lchars.t_flushc = -1; - lchars.t_dsuspc = -1; /* no delayed stop process signal */ - if(ioctl(fd,TIOCSLTC,&lchars) != SYSERR) - l_changed |= L_CHARS; - } -# endif /* TIOCGLTC */ -#else if (!(ttyparm.c_lflag & ECHO )) { if(!echomode) return -1; echo = 0; } -# ifdef FLUSHO +#ifdef FLUSHO ttyparm.c_lflag &= ~FLUSHO; -# endif /* FLUSHO */ +#endif /* FLUSHO */ nttyparm = ttyparm; -# ifndef u370 +#ifndef u370 nttyparm.c_iflag &= ~(IGNPAR|PARMRK|INLCR|IGNCR|ICRNL); nttyparm.c_iflag |= BRKINT; -# else +#else nttyparm.c_iflag &= ~(IGNBRK|PARMRK|INLCR|IGNCR|ICRNL|INPCK); nttyparm.c_iflag |= (BRKINT|IGNPAR); -# endif /* u370 */ +#endif /* u370 */ if(echo) nttyparm.c_lflag &= ~(ICANON); else nttyparm.c_lflag &= ~(ICANON|ISIG|ECHO|ECHOK); nttyparm.c_cc[VTIME] = 0; nttyparm.c_cc[VMIN] = 1; -# ifdef VREPRINT +#ifdef VREPRINT nttyparm.c_cc[VREPRINT] = _POSIX_DISABLE; -# endif /* VREPRINT */ -# ifdef VDISCARD +#endif /* VREPRINT */ +#ifdef VDISCARD nttyparm.c_cc[VDISCARD] = _POSIX_DISABLE; -# endif /* VDISCARD */ -# ifdef VDSUSP +#endif /* VDISCARD */ +#ifdef VDSUSP nttyparm.c_cc[VDSUSP] = _POSIX_DISABLE; -# endif /* VDSUSP */ -# ifdef VWERASE +#endif /* VDSUSP */ +#ifdef VWERASE if(ttyparm.c_cc[VWERASE] == _POSIX_DISABLE) ep->e_werase = cntl('W'); else ep->e_werase = nttyparm.c_cc[VWERASE]; nttyparm.c_cc[VWERASE] = _POSIX_DISABLE; -# else +#else ep->e_werase = cntl('W'); -# endif /* VWERASE */ -# ifdef VLNEXT +#endif /* VWERASE */ +#ifdef VLNEXT if(ttyparm.c_cc[VLNEXT] == _POSIX_DISABLE ) ep->e_lnext = cntl('V'); else ep->e_lnext = nttyparm.c_cc[VLNEXT]; nttyparm.c_cc[VLNEXT] = _POSIX_DISABLE; -# else +#else ep->e_lnext = cntl('V'); -# endif /* VLNEXT */ +#endif /* VLNEXT */ ep->e_intr = ttyparm.c_cc[VINTR]; ep->e_eof = ttyparm.c_cc[VEOF]; ep->e_erase = ttyparm.c_cc[VERASE]; @@ -354,7 +279,6 @@ int tty_raw(int fd, int echomode) if( tty_set(fd, TCSADRAIN, &nttyparm) == SYSERR ) return -1; ep->e_ttyspeed = (cfgetospeed(&ttyparm)>=B1200?FAST:SLOW); -#endif ep->e_raw = (echomode?ECHOMODE:RAWMODE); return 0; } @@ -377,7 +301,7 @@ int ed_window(void) return cols; } -/* E_FLUSH() +/* ED_FLUSH() * * Flush the output buffer. * @@ -652,12 +576,12 @@ void ed_setup(Edit_t *ep, int fd, int reedit) ep->e_outlast = ep->e_outptr + MAXLINE; return; } - qlen = sfset(sfstderr,SF_READ,0); - /* make sure SF_READ not on */ - ep->e_outbase = ep->e_outptr = (char*)sfreserve(sfstderr,SF_UNBOUND,SF_LOCKR); + qlen = sfset(sfstderr,SFIO_READ,0); + /* make sure SFIO_READ not on */ + ep->e_outbase = ep->e_outptr = (char*)sfreserve(sfstderr,SFIO_UNBOUND,SFIO_LOCKR); ep->e_outlast = ep->e_outptr + sfvalue(sfstderr); if(qlen) - sfset(sfstderr,SF_READ,1); + sfset(sfstderr,SFIO_READ,1); sfwrite(sfstderr,ep->e_outptr,0); ep->e_eol = reedit; if(ep->e_default && (pp = nv_getval(ep->e_default))) @@ -672,11 +596,12 @@ void ed_setup(Edit_t *ep, int fd, int reedit) } } -static void ed_putstring(Edit_t *ep, const char *str) +void ed_putstring(Edit_t *ep, const char *str) { int c; - while(c = *str++) - ed_putchar(ep,c); + mbinit(); + while (c = mbchar(str)) + ed_putchar(ep, c < 0 ? '?' : c); } static void ed_nputchar(Edit_t *ep, int n, int c) @@ -782,7 +707,7 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit) } if(rv < 0) { -#ifdef _hdr_utime +#if _hdr_utime # define fixtime() if(isdevtty)utime(ep->e_tty,&utimes) int isdevtty=0; struct stat statb; @@ -1008,31 +933,20 @@ void ed_ungetchar(Edit_t *ep,int c) #endif /* SHOPT_ESH || SHOPT_VSH */ #if SHOPT_ESH || SHOPT_VSH + /* - * put a character into the output buffer + * put a byte into the output buffer */ -void ed_putchar(Edit_t *ep,int c) +#if SHOPT_MULTIBYTE +static void ed_putbyte(Edit_t *ep,int c) +#else +void ed_putchar(Edit_t *ep,int c) +#endif /* SHOPT_MULTIBYTE */ { - char buf[8]; char *dp = ep->e_outptr; - int i,size=1; if(!dp) return; - buf[0] = c; -#if SHOPT_MULTIBYTE - /* check for place holder */ - if(c == MARKER) - return; - if((size = mbconv(buf, (wchar_t)c)) > 1) - { - for (i = 0; i < (size-1); i++) - *dp++ = buf[i]; - c = buf[i]; - } - else - buf[0] = c; -#endif /* SHOPT_MULTIBYTE */ *dp++ = c; *dp = '\0'; if(dp >= ep->e_outlast) @@ -1040,6 +954,25 @@ void ed_putchar(Edit_t *ep,int c) else ep->e_outptr = dp; } + +#if SHOPT_MULTIBYTE +/* + * put a character into the output buffer + */ + +void ed_putchar(Edit_t *ep,int c) +{ + char buf[8]; + int size, i; + /* check for placeholder */ + if(c == MARKER) + return; + size = mbconv(buf, (wchar_t)c); + for (i = 0; i < size; i++) + ed_putbyte(ep,buf[i]); +} +#endif /* SHOPT_MULTIBYTE */ + #endif /* SHOPT_ESH || SHOPT_VSH */ #if SHOPT_ESH || SHOPT_VSH @@ -1305,7 +1238,7 @@ int ed_external(const genchar *src, char *dest) char buffer[MAXLINE*sizeof(genchar)] = ""; c = ed_external(src,buffer); -#ifdef _lib_wcscpy +#if _lib_wcscpy wcscpy((wchar_t *)dest,(const wchar_t *)buffer); #else strcopy(dest,buffer); @@ -1368,81 +1301,6 @@ int ed_genlen(const genchar *str) } #endif /* (SHOPT_ESH || SHOPT_VSH) && SHOPT_MULTIBYTE */ -#if SHOPT_OLDTERMIO - -# include - -#ifndef ECHOCTL -# define ECHOCTL 0 -#endif /* !ECHOCTL */ -#define ott ep->e_ott - -/* - * For backward compatibility only - * This version will use termios when possible, otherwise termio - */ - -int tcgetattr(int fd, struct termios *tt) -{ - Edit_t *ep = (Edit_t*)(sh.ed_context); - int r,i; - ep->e_tcgeta = 0; - ep->e_echoctl = (ECHOCTL!=0); - if((r=ioctl(fd,TCGETS,tt))>=0 || errno!=EINVAL) - return r; - if((r=ioctl(fd,TCGETA,&ott)) >= 0) - { - tt->c_lflag = ott.c_lflag; - tt->c_oflag = ott.c_oflag; - tt->c_iflag = ott.c_iflag; - tt->c_cflag = ott.c_cflag; - for(i=0; ic_cc[i] = ott.c_cc[i]; - ep->e_tcgeta++; - ep->e_echoctl = 0; - } - return r; -} - -int tcsetattr(int fd,int mode,struct termios *tt) -{ - Edit_t *ep = (Edit_t*)(sh.ed_context); - int r; - if(ep->e_tcgeta) - { - int i; - ott.c_lflag = tt->c_lflag; - ott.c_oflag = tt->c_oflag; - ott.c_iflag = tt->c_iflag; - ott.c_cflag = tt->c_cflag; - for(i=0; ic_cc[i]; - if(tt->c_lflag&ECHOCTL) - { - ott.c_lflag &= ~(ECHOCTL|IEXTEN); - ott.c_iflag &= ~(IGNCR|ICRNL); - ott.c_iflag |= INLCR; - ott.c_cc[VEOF]= ESC; /* ESC -> eof char */ - ott.c_cc[VEOL] = '\r'; /* CR -> eol char */ - ott.c_cc[VEOL2] = tt->c_cc[VEOF]; /* EOF -> eol char */ - } - switch(mode) - { - case TCSANOW: - mode = TCSETA; - break; - case TCSADRAIN: - mode = TCSETAW; - break; - case TCSAFLUSH: - mode = TCSETAF; - } - return ioctl(fd,mode,&ott); - } - return ioctl(fd,mode,tt); -} -#endif /* SHOPT_OLDTERMIO */ - /* * Execute keyboard trap on given buffer of given size * < 0 for vi insert mode @@ -1497,6 +1355,10 @@ void *ed_open(void) return ed; } +/* + * ioctl, tcgetattr and tcsetattr are mapped to these versions in terminal.h + */ + #undef ioctl int sh_ioctl(int fd, int cmd, void* val, int sz) { @@ -1523,22 +1385,20 @@ int sh_ioctl(int fd, int cmd, void* val, int sz) return r; } -#ifdef _lib_tcgetattr -# undef tcgetattr +#undef tcgetattr int sh_tcgetattr(int fd, struct termios *tty) - { +{ int r,err = errno; while((r=tcgetattr(fd,tty)) < 0 && errno==EINTR) errno = err; return r; - } +} -# undef tcsetattr +#undef tcsetattr int sh_tcsetattr(int fd, int cmd, struct termios *tty) - { +{ int r,err = errno; while((r=tcsetattr(fd,cmd,tty)) < 0 && errno==EINTR) errno = err; return r; - } -#endif +} diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index 5a0b9d7123ba..61a948510687 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -171,7 +171,6 @@ typedef enum static void draw(Emacs_t*,Draw_t); static int escape(Emacs_t*,genchar*, int); -static void putstring(Emacs_t*,char*); static int dosearch(Emacs_t*,genchar*,int); static void search(Emacs_t*,genchar*,int); static void setcursor(Emacs_t*,int, int); @@ -600,7 +599,7 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit) if (ep->terminal == PAPER) { putchar(ep->ed,'\n'); - putstring(ep,Prompt); + ed_putstring(ep->ed,Prompt); } c = ed_getchar(ep->ed,0); if (c != usrkill) @@ -614,7 +613,7 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit) { ep->terminal = PAPER; putchar(ep->ed,'\n'); - putstring(ep,Prompt); + ed_putstring(ep->ed,Prompt); } } continue; @@ -756,14 +755,6 @@ static void show_info(Emacs_t *ep,const char *str) draw(ep,UPDATE); } -static void putstring(Emacs_t* ep,char *sp) -{ - int c; - while (c= *sp++) - putchar(ep->ed,c); -} - - static int escape(Emacs_t* ep,genchar *out,int count) { int i,value; @@ -1532,10 +1523,10 @@ static void draw(Emacs_t *ep,Draw_t option) #define BOTH '*' #define UPPER '>' - genchar *sptr; /* Pointer within screen */ + genchar *sptr; /* Pointer within screen */ genchar nscreen[2*MAXLINE]; /* New entire screen */ genchar *ncursor; /* New cursor */ - genchar *nptr; /* Pointer to New screen */ + genchar *nptr; /* Pointer to New screen */ char longline; /* Line overflow */ genchar *logcursor; genchar *nscend; /* end of logical screen */ @@ -1559,7 +1550,7 @@ static void draw(Emacs_t *ep,Draw_t option) return; } *ep->cursor = '\0'; - putstring(ep,Prompt); /* start with prompt */ + ed_putstring(ep->ed,Prompt); /* start with prompt */ } /********************* diff --git a/src/cmd/ksh93/edit/history.c b/src/cmd/ksh93/edit/history.c index 25832a59265b..c3e2b8a0aca1 100644 --- a/src/cmd/ksh93/edit/history.c +++ b/src/cmd/ksh93/edit/history.c @@ -276,7 +276,7 @@ int sh_histinit(void) sh.hist_ptr = hist_ptr = hp; hp->histsize = maxlines; hp->histmask = histmask; - hp->histfp= sfnew(NULL,hp->histbuff,HIST_BSIZE,fd,SF_READ|SF_WRITE|SF_APPENDWR|SF_SHARE); + hp->histfp= sfnew(NULL,hp->histbuff,HIST_BSIZE,fd,SFIO_READ|SFIO_WRITE|SFIO_APPENDWR|SFIO_SHARE); memset((char*)hp->histcmds,0,sizeof(off_t)*(hp->histmask+1)); hp->histind = 1; hp->histcmds[1] = 2; @@ -338,7 +338,7 @@ int sh_histinit(void) #endif /* SHOPT_ACCTFILE */ #if SHOPT_AUDIT { - char buff[SF_BUFSIZE]; + char buff[SFIO_BUFSIZE]; hp->auditfp = 0; if(sh_isstate(SH_INTERACTIVE) && (hp->auditmask=sh_checkaudit(hp,SHOPT_AUDITFILE, buff, sizeof(buff)))) { @@ -356,7 +356,7 @@ int sh_histinit(void) fcntl(fd,F_SETFD,FD_CLOEXEC); const char* tty = ttyname(2); hp->tty = sh_strdup(tty?tty:"notty"); - hp->auditfp = sfnew(NULL,NULL,-1,fd,SF_WRITE); + hp->auditfp = sfnew(NULL,NULL,-1,fd,SFIO_WRITE); } } } @@ -462,7 +462,7 @@ static History_t* hist_trim(History_t *hp, int n) if(newp <=oldp) break; } - if(!(buff=(char*)sfreserve(hist_old->histfp,SF_UNBOUND,0))) + if(!(buff=(char*)sfreserve(hist_old->histfp,SFIO_UNBOUND,0))) break; *(endbuff=(cp=buff)+sfvalue(hist_old->histfp)) = 0; /* copy to null byte */ @@ -496,7 +496,7 @@ static int hist_nearend(History_t *hp, Sfio_t *iop, off_t size) goto begin; /* skip to marker command and return the number */ /* numbering commands occur after a null and begin with HIST_CMDNO */ - while(cp=buff=(unsigned char*)sfreserve(iop,SF_UNBOUND,SF_LOCKR)) + while(cp=buff=(unsigned char*)sfreserve(iop,SFIO_UNBOUND,SFIO_LOCKR)) { n = sfvalue(iop); *(endbuff=cp+n) = 0; @@ -570,7 +570,7 @@ void hist_eof(History_t *hp) } again: sfseek(hp->histfp,count,SEEK_SET); - while(cp=(char*)sfreserve(hp->histfp,SF_UNBOUND,0)) + while(cp=(char*)sfreserve(hp->histfp,SFIO_UNBOUND,0)) { n = sfvalue(hp->histfp); *(endbuff = cp+n) = 0; @@ -687,7 +687,7 @@ void hist_flush(History_t *hp) char *buff; if(hp) { - if(buff=(char*)sfreserve(hp->histfp,0,SF_LOCKR)) + if(buff=(char*)sfreserve(hp->histfp,0,SFIO_LOCKR)) { hp->histflush = sfvalue(hp->histfp)+1; sfwrite(hp->histfp,buff,0); @@ -1104,7 +1104,7 @@ static int hist_exceptf(Sfio_t* fp, int type, void *data, Sfdisc_t *handle) int newfd,oldfd; History_t *hp = (History_t*)handle; NOT_USED(data); - if(type==SF_WRITE) + if(type==SFIO_WRITE) { if(errno==ENOSPC || hp->histwfail++ >= 10) return 0; diff --git a/src/cmd/ksh93/edit/vi.c b/src/cmd/ksh93/edit/vi.c index 29b315c0bcaa..3a328dd88bf3 100644 --- a/src/cmd/ksh93/edit/vi.c +++ b/src/cmd/ksh93/edit/vi.c @@ -181,7 +181,6 @@ static int getcount(Vi_t*,int); static void getline(Vi_t*,int); static int getrchar(Vi_t*); static int mvcursor(Vi_t*,int); -static void pr_string(Vi_t*,const char*); static void refresh(Vi_t*,int); static void replace(Vi_t*,int, int); static void restore_v(Vi_t*); @@ -1640,20 +1639,6 @@ static int mvcursor(Vi_t* vp,int motion) return 1; } -/* - * print a string - */ - -static void pr_string(Vi_t *vp, const char *sp) -{ - /*** copy string sp ***/ - char *ptr = editb.e_outptr; - while(*sp) - *ptr++ = *sp++; - editb.e_outptr = ptr; - return; -} - /*{ VI_REDRAW( ) * * Print the prompt and force a total refresh. @@ -1666,7 +1651,7 @@ static void pr_string(Vi_t *vp, const char *sp) void vi_redraw(void *ep) { Vi_t *vp = (Vi_t*)ep; - pr_string(vp,Prompt); + ed_putstring(vp->ed,Prompt); window[0] = '\0'; cur_phys = vp->first_wind; vp->ofirst_wind = INVALID; @@ -2610,7 +2595,7 @@ static int textmod(Vi_t *vp,int c, int mode) #if SHOPT_MULTIBYTE static int _isalph(int v) { -#ifdef _lib_iswalnum +#if _lib_iswalnum return iswalnum(v) || v=='_'; #else return (v&~STRIP) || isalnum(v) || v=='_'; diff --git a/src/cmd/ksh93/features/externs b/src/cmd/ksh93/features/externs index 957b9297a543..d9e9774053d0 100644 --- a/src/cmd/ksh93/features/externs +++ b/src/cmd/ksh93/features/externs @@ -83,7 +83,7 @@ tst note{ determining default number of extra bytes per argument for arguments l int bytec; error_info.id="_arg_extrabytes test (child)"; - argv = (char **)stkalloc(stkstd, (argmax / 2 + 1) * sizeof(char*)); + argv = stkalloc(stkstd, (argmax / 2 + 1) * sizeof(char*)); argc = bytec = 0; while(bytec < argmax) { diff --git a/src/cmd/ksh93/features/poll b/src/cmd/ksh93/features/poll index 727a0905595b..691c254820d5 100644 --- a/src/cmd/ksh93/features/poll +++ b/src/cmd/ksh93/features/poll @@ -123,31 +123,31 @@ tst socketpair_shutdown_mode note{ fchmod() after socketpair() shutdown() }end e } }end cat{ - #ifdef _lib_poll + #if _lib_poll # define poll _SYS_poll #else # undef _hdr_poll # undef _sys_poll #endif /* _lib_poll */ - #ifdef _hdr_poll + #if _hdr_poll # include #else - # ifdef _sys_poll + # if _sys_poll # include # endif /* _sys_poll */ #endif /* _hdr_poll */ - #ifdef _lib_poll + #if _lib_poll # undef poll extern int poll(struct pollfd*,unsigned long,int); #endif /* _lib_poll */ - #ifdef _lib_select + #if _lib_select # ifndef FD_ZERO # define FD_ZERO(x) (*(x)=0) # endif /* FD_ZERO */ # ifndef FD_SET # define FD_SET(n,x) (*(x)|=(1L<<(n))) # endif /* FD_SET */ - # ifndef _typ_fd_set + # if !_typ_fd_set typedef long fd_set; # endif /* _typ_fd_set */ #endif /* _lib_select */ diff --git a/src/cmd/ksh93/features/sigfeatures b/src/cmd/ksh93/features/sigfeatures index 88dc4559f2fb..f60dc6faa048 100644 --- a/src/cmd/ksh93/features/sigfeatures +++ b/src/cmd/ksh93/features/sigfeatures @@ -2,10 +2,10 @@ lib sigblock,sigrelse,sigsetmask,sigprocmask,sigvec typ sigset_t ast.h signal.h mem sigvec.sv_mask signal.h cat{ - #ifndef _mem_sigvec_sv_mask + #if !_mem_sigvec_sv_mask # undef _lib_sigvec #endif - #ifdef _lib_sigprocmask + #if _lib_sigprocmask # define sh_sigaction(s,action) do { sigset_t ss;\ sigemptyset(&ss); \ if(s) sigaddset(&ss,(s)); \ @@ -15,14 +15,14 @@ cat{ # define sigblock(s) sh_sigaction(s,SIG_BLOCK) # define sig_begin() sh_sigaction(0,SIG_SETMASK) #else - # ifndef _lib_sigblock + # if !_lib_sigblock # define sigblock(s) # endif - # ifdef _lib_sigsetmask + # if _lib_sigsetmask # define sigrelease(s) sigsetmask(0) # define sig_begin() sigsetmask(0) # else - # ifdef _lib_sigrelse + # if _lib_sigrelse # define sigrelease sigrelse # define sig_begin() # else diff --git a/src/cmd/ksh93/features/ttys b/src/cmd/ksh93/features/ttys deleted file mode 100644 index 693dbd1be1a0..000000000000 --- a/src/cmd/ksh93/features/ttys +++ /dev/null @@ -1,3 +0,0 @@ -hdr termios,termio,sgtty -sys termios,termio,ioctl,bsdtty,nttyio,filio -lib tcgetattr,tcgetpgrp termios.h diff --git a/src/cmd/ksh93/fun/man b/src/cmd/ksh93/fun/man index eb7799dfd585..a60df466f06e 100755 --- a/src/cmd/ksh93/fun/man +++ b/src/cmd/ksh93/fun/man @@ -23,6 +23,9 @@ # to your regular 'man' command so you won't notice a difference. Result: you # can just use 'man somecommand' for everything. # +# If you want to pass extra options to your operating system's "man" command, +# put those in the .sh.manopts variable. +# # This function only handles 'man' commands with a single argument. If more # or less than one argument is given, it passes control to the system's 'man'. # @@ -85,8 +88,17 @@ namespace man show_selfdoc() { - typeset -x ERROR_OPTIONS=emphasis - export LINES COLUMNS + typeset -x COLUMNS=$COLUMNS # export in local scope + if ((stdout_on_terminal)); then + # enable emphasis only for pagers that support ANSI escapes + typeset pager=${PAGER:-less} + case ${pager##*/} in + less | less[[:blank:]]* | most | most[[:blank:]]* ) + typeset -x ERROR_OPTIONS=emphasis ;; + esac + else + COLUMNS=80 + fi case $1 in test ) command test '--??man' -- ;; [ ) command [ '--??man' -- ] ;; @@ -101,9 +113,14 @@ namespace man pager() { - typeset IFS # local default split... - set -o noglob # ...and no pathname expansion... - ${PAGER:-less -R} # ...so we can safely split $PAGER + typeset pager=${MANPAGER:-${PAGER-}} + ((!stdout_on_terminal)) && pager=cat + case $pager in + '') pager='less -R' ;; + less | */less | less[[:blank:]]* | */less[[:blank:]]*) + pager+=' -R' ;; + esac + $pager } # Try if a system manual page in a section exists. Unfortunately, we @@ -114,7 +131,7 @@ namespace man try_os_man() { - [[ $2 != */* && $(command man -s "$1" "$2" 2>/dev/null) == *$'\n'*$'\n'*$'\n'* ]] + [[ $2 != */* && $(command man ${.sh.manopts-} -s "$1" "$2" 2>/dev/null) == *$'\n'*$'\n'*$'\n'* ]] } # The main function puts it all together. When given a single argument, @@ -128,17 +145,17 @@ namespace man main() { if (($# != 1)); then - command man "$@" + command man ${.sh.manopts-} "$@" elif builtin_has_selfdoc "$1"; then show_selfdoc "$1" | pager elif try_os_man 1 "$1"; then - command man -s 1 "$1" + command man ${.sh.manopts-} -s 1 "$1" elif try_os_man 8 "$1"; then - command man -s 8 "$1" + command man ${.sh.manopts-} -s 8 "$1" elif extcmd_has_selfdoc "$1"; then show_selfdoc "$1" | pager else - command man "$1" + command man ${.sh.manopts-} "$1" fi } } @@ -159,6 +176,13 @@ namespace man function man { + typeset IFS # local default split... + set -o noglob # ...and no pathname expansion, for safe field splitting + # set stdout_on_terminal to 1 if standard output is on a terminal; + # this needs flagging now as show_selfdoc() will have stdout on a pipe + [[ -t 1 ]] + typeset -si stdout_on_terminal=$((! $?)) + # and off we go .man.main "$@" } diff --git a/src/cmd/ksh93/include/builtins.h b/src/cmd/ksh93/include/builtins.h index ed7124c315bc..07e0bd569600 100644 --- a/src/cmd/ksh93/include/builtins.h +++ b/src/cmd/ksh93/include/builtins.h @@ -96,7 +96,7 @@ extern int b_let(int, char*[],Shbltin_t*); extern int b_read(int, char*[],Shbltin_t*); extern int b_ulimit(int, char*[],Shbltin_t*); extern int b_umask(int, char*[],Shbltin_t*); -#ifdef _cmd_universe +#if _cmd_universe extern int b_universe(int, char*[],Shbltin_t*); #endif /* _cmd_universe */ extern int b_wait(int, char*[],Shbltin_t*); @@ -133,7 +133,7 @@ extern const char e_toomanyops[]; extern const char e_toodeep[]; extern const char e_badname[]; extern const char e_badsyntax[]; -#ifdef _cmd_universe +#if _cmd_universe extern const char e_nouniverse[]; #endif /* _cmd_universe */ extern const char e_histopen[]; @@ -193,7 +193,7 @@ extern const char sh_optulimit[]; extern const char sh_optumask[]; extern const char sh_optunalias[]; extern const char sh_optwait[]; -#ifdef _cmd_universe +#if _cmd_universe extern const char sh_optuniverse[]; #endif /* _cmd_universe */ extern const char sh_optunset[]; diff --git a/src/cmd/ksh93/include/defs.h b/src/cmd/ksh93/include/defs.h index 393264396991..568d6aee7130 100644 --- a/src/cmd/ksh93/include/defs.h +++ b/src/cmd/ksh93/include/defs.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -116,7 +116,6 @@ extern void sh_chktrap(void); extern void sh_deparse(Sfio_t*,const Shnode_t*,int,int); extern int sh_debug(const char*,const char*,const char*,char *const[],int); extern char **sh_envgen(void); -extern void sh_envnolocal(Namval_t*,void*); extern Sfdouble_t sh_arith(const char*); extern void *sh_arithcomp(char*); extern pid_t sh_fork(int,int*); diff --git a/src/cmd/ksh93/include/edit.h b/src/cmd/ksh93/include/edit.h index 912512e23855..aa4131347e3c 100644 --- a/src/cmd/ksh93/include/edit.h +++ b/src/cmd/ksh93/include/edit.h @@ -96,15 +96,10 @@ typedef struct edit int e_fd; /* file descriptor */ int e_ttyspeed; /* line speed, also indicates tty parameters are valid */ int e_tabcount; -#ifdef _hdr_utime +#if _hdr_utime ino_t e_tty_ino; dev_t e_tty_dev; char *e_tty; -#endif -#if SHOPT_OLDTERMIO - char e_echoctl; - char e_tcgeta; - struct termio e_ott; #endif int *e_globals; /* global variables */ genchar *e_window; /* display window image */ @@ -158,6 +153,7 @@ typedef struct edit #define TCAP_ERASE_EOS "cd" extern void ed_putchar(Edit_t*, int); +extern void ed_putstring(Edit_t*, const char*); extern void ed_ringbell(void); extern void ed_setup(Edit_t*,int, int); extern void ed_flush(Edit_t*); diff --git a/src/cmd/ksh93/include/io.h b/src/cmd/ksh93/include/io.h index 300325479bdb..f3c8ca78b224 100644 --- a/src/cmd/ksh93/include/io.h +++ b/src/cmd/ksh93/include/io.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -25,7 +25,7 @@ #include #ifndef IOBSIZE -# define IOBSIZE (SF_BUFSIZE*sizeof(char*)) +# define IOBSIZE (SFIO_BUFSIZE*sizeof(char*)) #endif /* IOBSIZE */ #define IOMAXTRY 20 diff --git a/src/cmd/ksh93/include/name.h b/src/cmd/ksh93/include/name.h index 73f77b14fe19..a9885afab12f 100644 --- a/src/cmd/ksh93/include/name.h +++ b/src/cmd/ksh93/include/name.h @@ -24,7 +24,7 @@ #define _NV_PRIVATE \ Namfun_t *nvfun; /* pointer to trap functions */ \ union Value nvalue; /* value field */ \ - char *nvenv; /* pointer to environment name */ + void *nvmeta; /* pointer to any of various kinds of type-dependent data */ #include #include @@ -115,7 +115,7 @@ struct Ufunction /* attributes of Namval_t items */ /* The following attributes are for internal use */ -#define NV_NOCHANGE (NV_EXPORT|NV_IMPORT|NV_RDONLY|NV_TAGGED|NV_NOFREE|NV_ARRAY) +#define NV_NOCHANGE (NV_EXPORT|NV_MINIMAL|NV_RDONLY|NV_TAGGED|NV_NOFREE|NV_ARRAY) #define NV_ATTRIBUTES (~(NV_NOSCOPE|NV_ARRAY|NV_NOARRAY|NV_IDENT|NV_ASSIGN|NV_REF|NV_VARNAME|NV_STATIC)) #define NV_PARAM NV_NODISC /* expansion use positional params */ @@ -128,7 +128,7 @@ struct Ufunction #define NV_STATICF NV_INTEGER /* static class function */ #define NV_NOPRINT (NV_LTOU|NV_UTOL) /* do not print */ -#define NV_NOALIAS (NV_NOPRINT|NV_IMPORT) +#define NV_NOALIAS (NV_NOPRINT|NV_MINIMAL) #define NV_NOEXPAND NV_RJUST /* do not expand alias */ #define NV_BLTIN (NV_NOPRINT|NV_EXPORT) #define BLT_ENV (NV_RDONLY) /* non-stoppable, @@ -136,7 +136,7 @@ struct Ufunction #define BLT_SPC (NV_LJUST) /* special built-ins */ #define BLT_EXIT (NV_RJUST) /* exit value can be > 255 or < 0 */ #define BLT_DCL (NV_TAGGED) /* declaration command */ -#define BLT_NOSFIO (NV_IMPORT) /* doesn't use sfio */ +#define BLT_NOSFIO (NV_MINIMAL) /* doesn't use sfio */ #define NV_OPTGET (NV_BINARY) /* function calls getopts */ #define nv_isref(n) (nv_isattr((n),NV_REF|NV_TAGGED|NV_FUNCT)==NV_REF) #define is_abuiltin(n) (nv_isattr(n,NV_BLTIN|NV_INTEGER)==NV_BLTIN) diff --git a/src/cmd/ksh93/include/nval.h b/src/cmd/ksh93/include/nval.h index 969163ff137e..17b9ba2bacd2 100644 --- a/src/cmd/ksh93/include/nval.h +++ b/src/cmd/ksh93/include/nval.h @@ -137,8 +137,7 @@ struct Namval #define NV_ARRAY 0x400 /* node is an array */ #define NV_REF 0x4000 /* reference bit */ #define NV_TABLE 0x800 /* node is a dictionary table */ -#define NV_IMPORT 0x1000 /* value imported from environment */ -#define NV_MINIMAL NV_IMPORT /* node does not contain all fields */ +#define NV_MINIMAL 0x1000 /* node does not contain all fields */ #if SHOPT_OPTIMIZE #define NV_NOOPTIMIZE NV_TABLE /* disable loop invariants optimizer */ #else diff --git a/src/cmd/ksh93/include/shell.h b/src/cmd/ksh93/include/shell.h index e99b6bd10e41..0792a0471124 100644 --- a/src/cmd/ksh93/include/shell.h +++ b/src/cmd/ksh93/include/shell.h @@ -82,6 +82,7 @@ typedef union Shnode_u Shnode_t; #define SH_COMPLETE 19 /* set for command completion */ #define SH_XARG 21 /* set while in xarg (command -x) mode */ #define SH_NOTILDEXP 22 /* set to disable tilde expansion */ +#define SH_EXEC 23 /* set while in exec(1) */ /* * Shell options (set -o). Used with sh_isoption(), sh_onoption(), sh_offoption(). @@ -346,7 +347,8 @@ struct Shell_s int xargmin; int xargmax; int xargexit; - int nenv; + int save_env_n; /* number of saved pointers to environment variables with invalid names */ + char **save_env; /* saved pointers to environment variables with invalid names */ mode_t mask; void *init_context; void *mac_context; @@ -383,6 +385,7 @@ struct Shell_s char *mathnodes; char *bltin_dir; char tilde_block; /* set to block .sh.tilde.{get,set} discipline */ + char dont_optimize_builtins; /* nv_putsub() hack for nv_create() to avoid double arithmetic evaluation */ char nv_putsub_already_called_sh_arith; int nv_putsub_idx; /* saves array index obtained by nv_putsub() using sh_arith() */ @@ -430,7 +433,7 @@ extern Libcomp_t *liblist; extern void sh_subfork(void); extern Shell_t *sh_init(int,char*[],Shinit_f); -extern int sh_reinit(char*[]); +extern void sh_reinit(void); extern int sh_eval(Sfio_t*,int); extern void sh_delay(double,int); extern void *sh_parse(Sfio_t*,int); diff --git a/src/cmd/ksh93/include/terminal.h b/src/cmd/ksh93/include/terminal.h index 64e0e4cf0cfa..146bf8bfae7f 100644 --- a/src/cmd/ksh93/include/terminal.h +++ b/src/cmd/ksh93/include/terminal.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -20,167 +20,11 @@ #ifndef _terminal_ #define _terminal_ 1 -#include "FEATURE/ttys" /* * terminal interface - * complicated by the fact that there are so many variations - * This will use POSIX interface where available */ -#ifdef _hdr_termios -# include -# if __sgi__ || sgi /* special hack to eliminate ^M problem */ -# ifndef ECHOCTL -# define ECHOCTL ECHOE -# endif /* ECHOCTL */ -# ifndef CNSUSP -# define CNSUSP CNSWTCH -# endif /* CNSUSP */ -# endif /* sgi */ -# ifdef _NEXT_SOURCE -# define _lib_tcgetattr 1 -# define _lib_tcgetpgrp 1 -# endif /* _NEXT_SOURCE */ -#else -# if defined(_sys_termios) && defined(_lib_tcgetattr) -# include -# define _hdr_termios -# else -# undef _sys_termios -# endif /* _sys_termios */ -#endif /* _hdr_termios */ - -#ifdef _hdr_termios -# undef _hdr_sgtty -# undef tcgetattr -# undef tcsetattr -# undef tcgetpgrp -# undef tcsetpgrp -# undef cfgetospeed -# ifndef TCSANOW -# define TCSANOW TCSETS -# define TCSADRAIN TCSETSW -# define TCSAFLUSH TCSETSF -# endif /* TCSANOW */ - /* The following corrects bugs in some implementations */ -# if defined(TCSADFLUSH) && !defined(TCSAFLUSH) -# define TCSAFLUSH TCSADFLUSH -# endif /* TCSADFLUSH */ -# ifndef _lib_tcgetattr -# undef tcgetattr -# define tcgetattr(fd,tty) ioctl(fd, TCGETS, tty) -# undef tcsetattr -# define tcsetattr(fd,action,tty) ioctl(fd, action, tty) -# undef cfgetospeed -# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD) -# endif /* _lib_tcgetattr */ -# undef TIOCGETC -# if SHOPT_OLDTERMIO /* use both termios and termio */ -# ifdef _hdr_termio -# include -# else -# ifdef _sys_termio -# include -# define _hdr_termio 1 -# else -# undef SHOPT_OLDTERMIO -# endif /* _sys_termio */ -# endif /* _hdr_termio */ -# endif /* SHOPT_OLDTERMIO */ -#else -# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD) -# undef SHOPT_OLDTERMIO -# ifdef _hdr_termio -# include -# else -# ifdef _sys_termio -# include -# define _hdr_termio 1 -# endif /* _sys_termio */ -# endif /* _hdr_termio */ -# ifdef _hdr_termio -# define termios termio -# undef TIOCGETC -# define tcgetattr(fd,tty) ioctl(fd, TCGETA, tty) -# define tcsetattr(fd,action,tty) ioctl(fd, action, tty) - -# ifdef _sys_bsdtty -# include -# endif /* _sys_bsdtty */ -# else -# ifdef _hdr_sgtty -# include -# ifndef LPENDIN -# ifdef _sys_nttyio -# include -# endif /* _sys_nttyio */ -# endif /* LPENDIN */ -# define termios sgttyb -# ifdef TIOCSETN -# undef TCSETAW -# endif /* TIOCSETN */ -# ifdef TIOCGETP -# define tcgetattr(fd,tty) ioctl(fd, TIOCGETP, tty) -# define tcsetattr(fd,action,tty) ioctl(fd, action, tty) -# else -# define tcgetattr(fd,tty) gtty(fd, tty) -# define tcsetattr(fd,action,tty) stty(fd, tty) -# endif /* TIOCGETP */ -# endif /* _hdr_sgtty */ -# endif /* hdr_termio */ - -# ifndef TCSANOW -# ifdef TCSETAW -# define TCSANOW TCSETA -# ifdef u370 - /* delays are too long, don't wait for output to drain */ -# define TCSADRAIN TCSETA -# else -# define TCSADRAIN TCSETAW -# endif /* u370 */ -# define TCSAFLUSH TCSETAF -# else -# ifdef TIOCSETN -# define TCSANOW TIOCSETN -# define TCSADRAIN TIOCSETN -# define TCSAFLUSH TIOCSETP -# endif /* TIOCSETN */ -# endif /* TCSETAW */ -# endif /* TCSANOW */ -#endif /* _hdr_termios */ - -/* set ECHOCTL if driver can echo control characters as ^c */ -#ifdef LCTLECH -# ifndef ECHOCTL -# define ECHOCTL LCTLECH -# endif /* !ECHOCTL */ -#endif /* LCTLECH */ -#ifdef LNEW_CTLECH -# ifndef ECHOCTL -# define ECHOCTL LNEW_CTLECH -# endif /* !ECHOCTL */ -#endif /* LNEW_CTLECH */ -#ifdef LNEW_PENDIN -# ifndef PENDIN -# define PENDIN LNEW_PENDIN -# endif /* !PENDIN */ -#endif /* LNEW_PENDIN */ - -#ifdef _sys_filio -# ifndef FIONREAD -# include -# endif /* FIONREAD */ -#endif /* _sys_filio */ -/* set FIORDCHK if you can check for characters in input queue */ -#ifdef FIONREAD -# ifndef FIORDCHK -# define FIORDCHK FIONREAD -# endif /* !FIORDCHK */ -#endif /* FIONREAD */ - -#if _sys_ioctl -#include -#endif +#include extern int tty_alt(int); extern void tty_cooked(int); @@ -189,13 +33,11 @@ extern int tty_raw(int,int); extern int tty_check(int); extern int tty_set(int, int, struct termios*); extern int sh_ioctl(int,int,void*,int); -#undef ioctl -#define ioctl(a,b,c) sh_ioctl(a,b,c,sizeof(c)) -#ifdef _lib_tcgetattr - extern int sh_tcgetattr(int,struct termios*); - extern int sh_tcsetattr(int,int,struct termios*); -# define tcgetattr(a,b) sh_tcgetattr(a,b) -# define tcsetattr(a,b,c) sh_tcsetattr(a,b,c) -#endif +extern int sh_tcgetattr(int,struct termios*); +extern int sh_tcsetattr(int,int,struct termios*); + +#define ioctl(a,b,c) sh_ioctl(a,b,c,sizeof(c)) +#define tcgetattr(a,b) sh_tcgetattr(a,b) +#define tcsetattr(a,b,c) sh_tcsetattr(a,b,c) #endif /* _terminal_ */ diff --git a/src/cmd/ksh93/include/ulimit.h b/src/cmd/ksh93/include/ulimit.h index 0a658b59f969..72c257101eb9 100644 --- a/src/cmd/ksh93/include/ulimit.h +++ b/src/cmd/ksh93/include/ulimit.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -39,7 +39,7 @@ # endif # undef _lib_ulimit #else -# ifdef _sys_vlimit +# if _sys_vlimit # include # undef _lib_ulimit # define RLIMIT_FSIZE LIM_FSIZE @@ -51,7 +51,7 @@ # define RLIMIT_RSS LIM_MAXRSS # endif /* LIM_MAXRSS */ # else -# ifdef _lib_ulimit +# if _lib_ulimit # define vlimit ulimit # endif /* _lib_ulimit */ # endif /* _lib_vlimit */ @@ -74,7 +74,7 @@ #else # define _no_ulimit #endif -#ifndef _typ_rlim_t +#if !_typ_rlim_t typedef long rlim_t; #endif diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 8c9a22de6836..1318c572ab38 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -18,7 +18,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.1.0-alpha" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2024-02-22" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2024-03-07" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2024 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/kshrc.sh b/src/cmd/ksh93/kshrc.sh index 0344b68ae6ad..db92d4900c27 100644 --- a/src/cmd/ksh93/kshrc.sh +++ b/src/cmd/ksh93/kshrc.sh @@ -16,33 +16,64 @@ # A nice default .kshrc for 'bin/package use' # Feel free to adapt and use as your own ~/.kshrc -# NOTE: much of this requires ksh 93u+m + +case ${KSH_VERSION-} in +Version*) + ;; +*) # not ksh93: unset ENV and relaunch with default setup + ENV=''; export ENV # the ancient Bourne shell needs this + unset ENV + exec "$0" ${1+"$@"} + ;; +esac + +# Enable ** patterns +set --globstar + +# Disable \ escaping annoyance if supported +# (e.g. \ breaks a subsequent arrow key). +# This will be disabled by default in 93u+m/1.1 +# You can always use the 'stty lnext' character (^V). +[[ -o ?backslashctrl ]] && set --nobackslashctrl # create a namespace for global kshrc stuff typeset .rc .rc.me=${0##*/} # a $0 without dir that won't change in functions .rc.uid=${ id -u; } -.rc.uname=${ id -un; } .rc.host=${ uname -n; } .rc.host=${.rc.host%%.*} # remove domain .rc.tty=${ tty; } -.rc.tty=${.rc.tty##*/} # remove dir +.rc.tty=${.rc.tty#/dev/} -# ANSI foreground colours -.rc.clr=( - [magenta]=$'\E[35m' - [blue]=$'\E[34m' - [cyan]=$'\E[36m' - [red]=$'\E[31m' -) +if [[ -v INSTALLROOT ]] +then # do not intefere with the regular ksh history + [[ -d $INSTALLROOT/var ]] || mkdir -p "$INSTALLROOT/var" + HISTFILE=$INSTALLROOT/var/sh_history_${.rc.tty//\//_} +fi + +if ((.sh.version < 20230403)) +then print -r "${.rc.me}: ${.sh.version} is too old for this kshrc; reducing" >&2 + if ((.sh.version < 20220201)) # later ksh does this itself + then [[ ! -o vi && ! -o emacs && ! -o gmacs && -o ?emacs ]] && set --emacs + fi + PS1='<$?>!:${PWD#${PWD%/*/*/*}/} $ ' + return +fi -# Formatting codes +# Formatting and colour codes .rc.fmt=( - [ansiprefix]=$'\E[' [reset]=$'\E[0m' [underline]=$'\E[4m' [bold]=$'\E[1m' + + [magenta]=$'\E[35m' + [blue]=$'\E[34m' + [cyan]=$'\E[36m' + [red]=$'\E[31m' + + [status0]=$'\E[32m' # zero exit status: green + [status1]=$'\E[31m' # nonzero exit status: red ) # extend tilde expansion functionality: @@ -86,7 +117,7 @@ function RELPWD.get function RELPWD.keep.set { typeset -si i n - let "(n=${.sh.value}) ? 1 : 1" 2>/dev/null || n=2 + let "(n=${.sh.value}) ? 1 : 1" 2>/dev/null || n=3 ((n>64)) && n=64 # sanity check ((n<1)) && .sh.value='' && return .sh.value='*' @@ -116,19 +147,31 @@ function GITBRANCH.get esac } -# the regular (PS1) and line continuation (PS2) prompts +# ${.rc.status} is a nicely formatted/coloured $? +function .rc.status.get +{ + typeset e=$? + typeset clr=${.rc.fmt[status$((e > 0))]} + typeset q1=$'\u00AB' q2=$'\u00BB' + ((${#q1}==1 && ${#q2}==1)) || q1='<' q2='>' + if ((e>256)) # add signal name + then typeset s=${ kill -l "$e"; } + [[ $s == *[A-Z]* ]] && e+="/SIG$s" + fi + .sh.value=${.rc.fmt[reset]}$q1$clr$e${.rc.fmt[reset]}$q2 +} +# Regular (PS1) prompt. typeset -sui .rc.ps2_lineno=0 case ${.rc.uid} in -0) .rc.clr1=${.rc.clr[magenta]} .rc.clr2=${.rc.clr[red]} .rc.char='#' ;; -*) .rc.clr1=${.rc.clr[blue]} .rc.clr2=${.rc.clr[cyan]} .rc.char='$' ;; +0) .rc.clr1=${.rc.fmt[magenta]} .rc.clr2=${.rc.fmt[red]} .rc.char='#' ;; +*) .rc.clr1=${.rc.fmt[blue]} .rc.clr2=${.rc.fmt[cyan]} .rc.char='$' ;; esac - # use single quotes to avoid expanding variables now, because PS1 is special: # it expands variables in its value even without a discipline function. # Also, '!' expands to the history file number (see 'man fc'). -PS1='${.rc.fmt[ansiprefix]}$((${?}?31:32))m$?${.rc.fmt[reset]}<${.rc.clr1}!${.rc.fmt[reset]}' -PS1+=':${.rc.clr2}${RELPWD}${GITBRANCH:+${.rc.clr1}[${GITBRANCH}]}${.rc.fmt[reset]} ${.rc.char} ' +PS1='${.rc.status}${.rc.clr1}!${.rc.fmt[reset]}:${.rc.clr2}${RELPWD}' +PS1+='${GITBRANCH:+${.rc.clr1}[${GITBRANCH}]}${.rc.fmt[reset]} ${.rc.char} ' function PS1.get { @@ -136,14 +179,14 @@ function PS1.get .rc.ps2_lineno=0 } -# PS2 (like normal variables) does not expand anything by itself, -# but we can use a discipline function to make it act dynamically +# PS2 line continuation prompt. It does not expand anything by itself, +# but we can use a discipline function to make it act dynamically. function PS2.get { typeset clr1 clr2 char case ${.rc.uid} in - 0) clr1=${.rc.clr[magenta]} clr2=${.rc.clr[red]} ;; - *) clr1=${.rc.clr[blue]} clr2=${.rc.clr[cyan]} ;; + 0) clr1=${.rc.fmt[magenta]} clr2=${.rc.fmt[red]} ;; + *) clr1=${.rc.fmt[blue]} clr2=${.rc.fmt[cyan]} ;; esac char=$'\u22d7' # greater-than with dot (UTF-8) ((${#char}==1)) || char='>' @@ -158,7 +201,7 @@ function PS2.get "${.rc.fmt[reset]}" } -# stuff for when this is run from 'bin/package use' +# Stuff for when this is run from 'bin/package use'. if [[ -v INSTALLROOT ]] then # make shipped functions available @@ -169,16 +212,16 @@ then esac export FPATH autoload autocd cd dirs man mcd popd pushd - # do not intefere with the regular ksh history - [[ -d $INSTALLROOT/var ]] || mkdir -p "$INSTALLROOT/var" - HISTFILE=$INSTALLROOT/var/sh_history_${.rc.tty} - - # Print welcome message - set -- ${.sh.version} - print -r "${.rc.fmt[bold]}Welcome to ksh ${.rc.clr[red]}$3 ${.rc.clr[blue]}$4${.rc.fmt[reset]} on ${.rc.fmt[bold]}${.rc.host} (${.rc.tty})${.rc.fmt[reset]}" - set -- - print -r -- "- Have a look at ${.rc.fmt[bold]}~ast/etc/kshrc${.rc.fmt[reset]} to see all the cool stuff activated here" - print -r -- "- Type '${.rc.fmt[bold]}builtin${.rc.fmt[reset]}' for a list of built-in commands (with and without path)" - print -r -- "- Get help: use '${.rc.fmt[bold]}man${.rc.fmt[reset]} ${.rc.fmt[underline]}commandname${.rc.fmt[reset]}' for everything, even built-in commands" - print -r -- "- Autoloadable functions have been activated. Check them out in ${.rc.fmt[bold]}~ast/fun${.rc.fmt[reset]}" + + # Print welcome message; do not repeat for child or exec'd shells + if [[ ! -v _KSHRC_WELCOMED_ ]] + then set -- ${.sh.version} + print -r "${.rc.fmt[bold]}Welcome to ksh ${.rc.fmt[red]}$3 ${.rc.fmt[blue]}$4${.rc.fmt[reset]} on ${.rc.fmt[bold]}${.rc.host} (${.rc.tty})${.rc.fmt[reset]}" + set -- + print -r -- "- Have a look at ${.rc.fmt[bold]}~ast/etc/kshrc${.rc.fmt[reset]} to see all the cool stuff activated here" + print -r -- "- Type '${.rc.fmt[bold]}builtin${.rc.fmt[reset]}' for a list of built-in commands (with and without path)" + print -r -- "- Autoloadable functions have been activated. Check them out in ${.rc.fmt[bold]}~ast/fun${.rc.fmt[reset]}" + print -r -- "- Get help: use '${.rc.fmt[bold]}man${.rc.fmt[reset]} ${.rc.fmt[underline]}commandname${.rc.fmt[reset]}' for everything, even built-in commands" + export _KSHRC_WELCOMED_=y + fi fi diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index 0fcd73bbea3a..2833e6394d60 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -6670,7 +6670,8 @@ If .I arg\^ is given, the command specified by -the arguments is executed in place of this shell +the arguments is seaerched on PATH as an external command +and executed in place of the current shell without creating a new process. The value of the .SM diff --git a/src/cmd/ksh93/sh/args.c b/src/cmd/ksh93/sh/args.c index cee50bf0b3e4..f5905980b21f 100644 --- a/src/cmd/ksh93/sh/args.c +++ b/src/cmd/ksh93/sh/args.c @@ -337,7 +337,7 @@ int sh_argopts(int argc,char *argv[]) errormsg(SH_DICT,ERROR_system(3),e_create,ap->kiafile); UNREACHABLE(); } - if(!(lp->kiatmp=sftmp(2*SF_BUFSIZE))) + if(!(lp->kiatmp=sftmp(2*SFIO_BUFSIZE))) { errormsg(SH_DICT,ERROR_system(3),e_tmpcreate); UNREACHABLE(); @@ -681,7 +681,7 @@ char **sh_argbuild(int *nargs, const struct comnod *comptr,int flag) * TODO: find/fix root cause, eliminate argi */ argn = *nargs + 1; /* allow room to prepend args */ - comargn=(char**)stkalloc(sh.stk,(unsigned)(argn+1)*sizeof(char*)); + comargn = stkalloc(sh.stk,(unsigned)(argn+1)*sizeof(char*)); comargm = comargn += argn; *comargn = NULL; if(!argp) @@ -724,7 +724,7 @@ struct argnod *sh_argprocsub(struct argnod *argp) int savestates = sh_getstate(); char savejobcontrol = job.jobcontrol; unsigned int savesubshell = sh.subshell; - ap = (struct argnod*)stkseek(sh.stk,ARGVAL); + ap = stkseek(sh.stk,ARGVAL); ap->argflag |= ARG_MAKE; ap->argflag &= ~ARG_RAW; fd = argp->argflag&ARG_RAW; @@ -752,7 +752,7 @@ struct argnod *sh_argprocsub(struct argnod *argp) sfputr(sh.stk,sh.fifo,0); #endif /* SHOPT_DEVFD */ sfputr(sh.stk,fmtint(pv[fd],1),0); - ap = (struct argnod*)stkfreeze(sh.stk,0); + ap = stkfreeze(sh.stk,0); sh.inpipe = sh.outpipe = 0; /* turn off job control */ sh_offstate(SH_INTERACTIVE); diff --git a/src/cmd/ksh93/sh/arith.c b/src/cmd/ksh93/sh/arith.c index ba017647ba4d..a54443834b55 100644 --- a/src/cmd/ksh93/sh/arith.c +++ b/src/cmd/ksh93/sh/arith.c @@ -182,7 +182,7 @@ static Namval_t *scope(Namval_t *np,struct lval *lvalue,int assign) if(ap && !ap->table) ap->table = dtopen(&_Nvdisc,Dtoset); if(ap && ap->table && (nq=nv_search(nv_getsub(np),ap->table,NV_ADD))) - nq->nvenv = (char*)np; + nq->nvmeta = np; if(nq && nv_isnull(nq)) np = nv_arraychild(np,nq,0); } diff --git a/src/cmd/ksh93/sh/array.c b/src/cmd/ksh93/sh/array.c index e7dde7f9cf60..156db4994c1e 100644 --- a/src/cmd/ksh93/sh/array.c +++ b/src/cmd/ksh93/sh/array.c @@ -378,7 +378,7 @@ static Namval_t *array_find(Namval_t *np,Namarr_t *arp, int flag) sfprintf(sh.strbuf,"%d",ap->cur); cp = sfstruse(sh.strbuf); mp = nv_search(cp, ap->header.table, NV_ADD); - mp->nvenv = (char*)np; + mp->nvmeta = np; nv_arraychild(np,mp,0); } if(up->np && array_isbit(ap->bits,ap->cur,ARRAY_CHILD)) @@ -446,7 +446,7 @@ static Namfun_t *array_clone(Namval_t *np, Namval_t *mp, int flags, Namfun_t *fp do { if(nq=nv_opensub(np)) - nq->nvenv = (void*)mp; + nq->nvmeta = mp; } while(nv_nextsub(np)); } @@ -790,7 +790,7 @@ static void array_copytree(Namval_t *np, Namval_t *mp) nv_disc(np,(Namfun_t*)fp, NV_FIRST); fp->nofree |= 1; nv_onattr(np,NV_ARRAY); - mp->nvenv = (char*)np; + mp->nvmeta = np; } /* @@ -1028,7 +1028,7 @@ Namval_t *nv_arraychild(Namval_t *np, Namval_t *nq, int c) if((tp=nv_type(np)) || c) { ap->nelem |= ARRAY_NOCLONE; - nq->nvenv = (char*)np; + nq->nvmeta = np; if(c=='t') nv_clone(tp,nq, 0); else @@ -1036,7 +1036,7 @@ Namval_t *nv_arraychild(Namval_t *np, Namval_t *nq, int c) nv_offattr(nq,NV_ARRAY); ap->nelem &= ~ARRAY_NOCLONE; } - nq->nvenv = (char*)np; + nq->nvmeta = np; if((fp=nq->nvfun) && fp->disc && fp->disc->setdisc && (fp = nv_disc(nq,fp,NV_POP))) free(fp); if(!ap->fun) @@ -1237,7 +1237,7 @@ Namval_t *nv_putsub(Namval_t *np,char *sp,long mode) sfprintf(sh.strbuf,"%d",ap->cur); cp = sfstruse(sh.strbuf); mp = nv_search(cp, ap->header.table, NV_ADD); - mp->nvenv = (char*)np; + mp->nvmeta = np; nv_arraychild(np,mp,0); nv_setvtree(mp); } @@ -1720,7 +1720,7 @@ void *nv_associative(Namval_t *np,const char *sp,int mode) return ap->cur; case NV_ACURRENT: if(ap->cur) - ap->cur->nvenv = (char*)np; + ap->cur->nvmeta = np; return ap->cur; case NV_ANAME: if(ap->cur) @@ -1749,7 +1749,7 @@ void *nv_associative(Namval_t *np,const char *sp,int mode) if((mp || (mp=nv_search(sp,ap->header.table,mode))) && nv_isnull(mp) && (mode&NV_ADD)) { nv_onattr(mp,type); - mp->nvenv = (char*)np; + mp->nvmeta = np; if((mode&NV_ADD) && nv_type(np)) nv_arraychild(np,mp,0); if(sh.subshell) diff --git a/src/cmd/ksh93/sh/deparse.c b/src/cmd/ksh93/sh/deparse.c index a50b4fc9a512..ee7f53d9bbaf 100644 --- a/src/cmd/ksh93/sh/deparse.c +++ b/src/cmd/ksh93/sh/deparse.c @@ -613,7 +613,7 @@ static void here_body(const struct ionod *iop) { Sfio_t *infile; if(iop->iofile&IOSTRG) - infile = sfnew(NULL,iop->ioname,iop->iosize,-1,SF_STRING|SF_READ); + infile = sfnew(NULL,iop->ioname,iop->iosize,-1,SFIO_STRING|SFIO_READ); else sfseek(infile=sh.heredocs,iop->iooffset,SEEK_SET); sfmove(infile,outfile,iop->iosize,-1); diff --git a/src/cmd/ksh93/sh/expand.c b/src/cmd/ksh93/sh/expand.c index 10b307d9aba3..940dbe08cafc 100644 --- a/src/cmd/ksh93/sh/expand.c +++ b/src/cmd/ksh93/sh/expand.c @@ -115,7 +115,7 @@ int path_expand(const char *pattern, struct argnod **arghead, int musttrim) */ if((ap = (struct argnod*)gp->gl_list) && !ap->argnxt.ap && strcmp(ap->argval,trimmedpat)==0) { - gp->gl_list = (globlist_t*)stkalloc(sh.stk,ARGVAL+strlen(pattern)+1); + gp->gl_list = stkalloc(sh.stk,ARGVAL+strlen(pattern)+1); memcpy(gp->gl_list,ap,ARGVAL); /* copy fields *before* argval/gl_path */ strcpy(gp->gl_list->gl_path,pattern); } @@ -149,9 +149,9 @@ static int scantree(Dt_t *tree, const char *pattern, struct argnod **arghead) continue; if(strmatch(cp=nv_name(np),pattern)) { - (void)stkseek(sh.stk,ARGVAL); + stkseek(sh.stk,ARGVAL); sfputr(sh.stk,cp,-1); - ap = (struct argnod*)stkfreeze(sh.stk,1); + ap = stkfreeze(sh.stk,1); ap->argbegin = NULL; ap->argchn.ap = *arghead; ap->argflag = ARG_RAW|ARG_MAKE; @@ -431,13 +431,13 @@ int path_generate(struct argnod *todo, struct argnod **arghead, int musttrim) brace = *cp; *cp = 0; sh_sigcheck(); - ap = (struct argnod*)stkseek(sh.stk,ARGVAL); + ap = stkseek(sh.stk,ARGVAL); ap->argflag = ARG_RAW; ap->argchn.ap = todo; sfputr(sh.stk,apin->argval,-1); sfputr(sh.stk,pat,-1); sfputr(sh.stk,rescan,-1); - todo = ap = (struct argnod*)stkfreeze(sh.stk,1); + todo = ap = stkfreeze(sh.stk,1); if(brace == '}') break; if(!range) diff --git a/src/cmd/ksh93/sh/fault.c b/src/cmd/ksh93/sh/fault.c index 9ba82462eceb..523857140898 100644 --- a/src/cmd/ksh93/sh/fault.c +++ b/src/cmd/ksh93/sh/fault.c @@ -497,7 +497,7 @@ int sh_trap(const char *trap, int mode) char was_no_trapdontexec = !sh.st.trapdontexec; char save_chldexitsig = sh.chldexitsig; int staktop = stktell(sh.stk); - char *savptr = stkfreeze(sh.stk,0); + void *savptr = stkfreeze(sh.stk,0); struct checkpt buff; Fcin_t savefc; fcsave(&savefc); @@ -571,6 +571,7 @@ void sh_exit(int xno) sh.exitval |= (sig=sh.lastsig); if(pp && pp->mode>1) cursig = -1; + sh_offstate(SH_EXEC); if((sh.trapnote&SH_SIGTSTP) && job.jobcontrol) { /* ^Z detected by the shell */ @@ -617,7 +618,7 @@ void sh_exit(int xno) } /* unlock output pool */ sh_offstate(SH_NOTRACK); - if(!(pool=sfpool(NULL,sh.outpool,SF_WRITE))) + if(!(pool=sfpool(NULL,sh.outpool,SFIO_WRITE))) pool = sh.outpool; /* can't happen? */ sfclrlock(pool); if(sh.lastsig==SIGPIPE) @@ -693,7 +694,7 @@ noreturn void sh_done(int sig) /* generate fault termination code */ if(RLIMIT_CORE!=RLIMIT_UNKNOWN) { -#ifdef _lib_getrlimit +#if _lib_getrlimit struct rlimit rlp; getrlimit(RLIMIT_CORE,&rlp); rlp.rlim_cur = 0; diff --git a/src/cmd/ksh93/sh/fcin.c b/src/cmd/ksh93/sh/fcin.c index fc6a293914ca..f5c6622f82dc 100644 --- a/src/cmd/ksh93/sh/fcin.c +++ b/src/cmd/ksh93/sh/fcin.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -43,7 +43,7 @@ int fcfopen(Sfio_t* f) _Fcin.fcbuff = _Fcin.fcptr; _Fcin._fcfile = f; fcsave(&save); - if(!(buff=(char*)sfreserve(f,SF_UNBOUND,SF_LOCKR))) + if(!(buff=(char*)sfreserve(f,SFIO_UNBOUND,SFIO_LOCKR))) { fcrestore(&save); _Fcin.fcchar = 0; @@ -56,7 +56,7 @@ int fcfopen(Sfio_t* f) fcrestore(&save); sfread(f,buff,0); _Fcin.fcoff = sftell(f);; - buff = (char*)sfreserve(f,SF_UNBOUND,SF_LOCKR); + buff = (char*)sfreserve(f,SFIO_UNBOUND,SFIO_LOCKR); _Fcin.fclast = (_Fcin.fcptr=_Fcin.fcbuff=(unsigned char*)buff)+n; if(sffileno(f) >= 0) *_Fcin.fclast = 0; diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 879970887fb2..bc8a08229db5 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -231,7 +231,7 @@ static int rand_shift; /* * Exception callback routine for stk(3) and sh_*alloc wrappers. */ -static noreturn char *nomemory(size_t s) +static noreturn void *nomemory(size_t s) { errormsg(SH_DICT, ERROR_SYSTEM|ERROR_PANIC, "out of memory (needed %llu bytes)", (uintmax_t)s); UNREACHABLE(); @@ -818,7 +818,7 @@ static void put_lastarg(Namval_t* np,const char *val,int flags,Namfun_t *fp) nv_offattr(np,NV_NOFREE); sh.lastarg = (char*)val; nv_offattr(np,NV_EXPORT); - np->nvenv = 0; + np->nvmeta = NULL; } static void match2d(struct match *mp) @@ -1310,7 +1310,7 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) sh.lex_context = sh_lexopen(0,1); sh.radixpoint = '.'; /* pre-locale init */ sh.strbuf = sfstropen(); - sh.stk = stkstd; + stkoverflow(sh.stk = stkstd, nomemory); sfsetbuf(sh.strbuf,NULL,64); error_info.catalog = e_dict; #if SHOPT_REGRESS @@ -1359,7 +1359,6 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) sh_ioinit(); /* initialize signal handling */ sh_siginit(); - stkinstall(NULL,nomemory); /* set up memory for name-value pairs */ sh.init_context = nv_init(); /* initialize shell type */ @@ -1381,8 +1380,8 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) sfprintf(sh.strbuf,"%s/.kshrc",nv_getval(HOME)); nv_putval(ENVNOD,sfstruse(sh.strbuf),NV_RDONLY); } - *SHLVL->nvalue.ip +=1; - nv_offattr(SHLVL,NV_IMPORT); + /* increase SHLVL */ + shlvl++; #if SHOPT_SPAWN { /* @@ -1532,34 +1531,68 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) return &sh; } +/* + * Close all the dictionaries on a viewpath + */ +static void freeup_tree(Dt_t *tree) +{ + Dt_t *view; + while(view = dtview(tree, NULL)) + { + dtclose(tree); + tree = view; + } + dtclose(tree); +} + /* * Reinitialize before executing a script without a #! path. - * This is done in a fork of the shell, so "exporting" is done by deleting all non-exported variables. + * This is done in a fork of the shell. */ -int sh_reinit(char *argv[]) +void sh_reinit(void) { Shopt_t opt; Namval_t *np,*npnext; Dt_t *dp; - int nofree; - char *savfpath = NULL; - sh.subshell = sh.realsubshell = sh.comsub = sh.curenv = sh.jobenv = sh.inuse_bits = sh.fn_depth = sh.dot_depth = 0; - sh.envlist = NULL; - sh.last_root = sh.var_tree; + sh_onstate(SH_INIT); + sh_offstate(SH_FORKED); + /* Reset shell options; inherit some */ + memset(&opt,0,sizeof(opt)); + if(sh_isoption(SH_POSIX)) + on_option(&opt,SH_POSIX); +#if SHOPT_ESH + if(sh_isoption(SH_EMACS)) + on_option(&opt,SH_EMACS); + if(sh_isoption(SH_GMACS)) + on_option(&opt,SH_GMACS); +#endif +#if SHOPT_VSH + if(sh_isoption(SH_VI)) + on_option(&opt,SH_VI); +#endif + sh.options = opt; + /* Reset here-document */ if(sh.heredocs) { sfclose(sh.heredocs); sh.heredocs = 0; } - /* Unset tilde expansion disciplines */ - _nv_unset(SH_TILDENOD,NV_RDONLY); - /* save FPATH and treat specially */ - if(nv_isattr(FPATHNOD,NV_EXPORT)) - savfpath = sh_strdup(nv_getval(FPATHNOD)); - _nv_unset(FPATHNOD,NV_RDONLY); - /* Remove non-exported variables, first pass (see sh_envnolocal() in name.c) */ - nv_scan(sh.var_tree,sh_envnolocal,NULL,NV_EXPORT,0); - nv_scan(sh.var_tree,sh_envnolocal,NULL,NV_ARRAY,NV_ARRAY); + /* Reset arguments */ + if(sh.arglist) + sh_argreset(sh.arglist,NULL); + sh.shname = error_info.id = sh_strdup(sh.st.dolv[0]); + /* Reset traps and signals */ + memset(sh.st.trapcom,0,(sh.st.trapmax+1)*sizeof(char*)); + sh_sigreset(0); + sh.st.filename = sh_strdup(sh.lastarg); + nv_delete(NULL, NULL, 0); + job.exitval = 0; + sh.inpipe = sh.outpipe = 0; + job_clear(); + job.in_critical = 0; + /* update $$, $PPID */ + sh.ppid = sh.current_ppid; + sh.pid = sh.current_pid; #if SHOPT_NAMESPACE if(sh.namespace) { @@ -1567,148 +1600,107 @@ int sh_reinit(char *argv[]) if(dp==sh.var_tree) sh.var_tree = dtview(dp,0); _nv_unset(sh.namespace,NV_RDONLY); - sh.namespace = 0; + sh.namespace = NULL; } #endif /* SHOPT_NAMESPACE */ - /* Delete remaining non-exported, non-default variables; remove attributes from exported variables */ - for(np = dtfirst(sh.var_tree); np; np = npnext) - { - if((dp = sh.var_tree)->walk) - dp = dp->walk; - npnext = (Namval_t*)dtnext(sh.var_tree,np); - /* skip default variables (already handled by sh_envnolocal()) */ - if(np >= sh.bltin_nodes && np < &sh.bltin_nodes[nvars]) - continue; - if(nv_isattr(np,NV_EXPORT)) - { - char *cp = NULL; - /* do not export attributes */ - if(nv_isattr(np,NV_INTEGER)) /* any kind of numeric? */ - { - cp = sh_strdup(nv_getval(np)); /* save string value */ - _nv_unset(np,NV_RDONLY); /* free numeric value */ - } - nv_setattr(np,NV_EXPORT); /* turn off everything except export */ - if(cp) - np->nvalue.cp = cp; /* replace by string value */ - } - else - { - nofree = nv_isattr(np,NV_NOFREE); /* note: returns bitmask, not boolean */ - _nv_unset(np,NV_RDONLY); /* also clears NV_NOFREE attr, if any */ - nv_delete(np,dp,nofree); - } - } - /* Delete types */ - for(np = dtfirst(sh.typedict); np; np = npnext) - { - if((dp = sh.typedict)->walk) - dp = dp->walk; - npnext = (Namval_t*)dtnext(sh.typedict,np); - nv_delete(np,dp,0); - } - /* Delete functions/built-ins. Note: fun_tree has a viewpath to bltin_tree */ - for(np = dtfirst(sh.fun_tree); np; np = npnext) - { - if((dp = sh.fun_tree)->walk) - dp = dp->walk; - npnext = (Namval_t*)dtnext(sh.fun_tree,np); - nv_delete(np, dp, NV_NOFREE); - } - while(dp = dtview(sh.fun_tree, NULL)) - { - dtclose(sh.fun_tree); - sh.fun_tree = dp; - } - sh.fun_base = sh.fun_tree; - dtclear(sh.fun_base); - /* Re-init built-ins as per nv_init() */ - free(sh.bltin_cmds); - sh.bltin_tree = sh_inittree((const struct shtable2*)shtab_builtins); - dtview(sh.fun_tree,sh.bltin_tree); /* Delete aliases */ for(np = dtfirst(sh.alias_tree); np; np = npnext) { if((dp = sh.alias_tree)->walk) - dp = dp->walk; + dp = dp->walk; /* the dictionary in which the item was found */ npnext = (Namval_t*)dtnext(sh.alias_tree,np); - _nv_unset(np,nv_isattr(np,NV_NOFREE)); + _nv_unset(np,NV_RDONLY); nv_delete(np,dp,0); } /* Delete hash table entries */ for(np = dtfirst(sh.track_tree); np; np = npnext) { if((dp = sh.track_tree)->walk) - dp = dp->walk; + dp = dp->walk; /* the dictionary in which the item was found */ npnext = (Namval_t*)dtnext(sh.track_tree,np); - nofree = nv_isattr(np,NV_NOFREE); /* note: returns bitmask, not boolean */ - _nv_unset(np,NV_RDONLY); /* also clears NV_NOFREE attr, if any */ - nv_delete(np,dp,nofree); + _nv_unset(np,NV_RDONLY); + nv_delete(np,dp,0); } - while(dp = dtview(sh.track_tree, NULL)) + /* Delete types */ + for(np = dtfirst(sh.typedict); np; np = npnext) { - dtclose(sh.track_tree); - sh.track_tree = dp; + if((dp = sh.typedict)->walk) + dp = dp->walk; /* the dictionary in which the item was found */ + npnext = (Namval_t*)dtnext(sh.typedict,np); + nv_delete(np,dp,0); } -#if SHOPT_STATS - /* Reset statistics */ - free(sh.stats); - stat_init(); -#endif - /* Reset shell options; inherit some */ - memset(&opt,0,sizeof(opt)); - if(sh_isoption(SH_POSIX)) - on_option(&opt,SH_POSIX); -#if SHOPT_ESH - if(sh_isoption(SH_EMACS)) - on_option(&opt,SH_EMACS); - if(sh_isoption(SH_GMACS)) - on_option(&opt,SH_GMACS); -#endif -#if SHOPT_VSH - if(sh_isoption(SH_VI)) - on_option(&opt,SH_VI); -#endif - sh.options = opt; - /* set up new args */ - if(argv) - sh.arglist = sh_argcreate(argv); - if(sh.arglist) - sh_argreset(sh.arglist,NULL); - sh.shname = error_info.id = sh_strdup(sh.st.dolv[0]); - sh_offstate(SH_FORKED); - /* Reset traps and signals */ - memset(sh.st.trapcom,0,(sh.st.trapmax+1)*sizeof(char*)); - sh_sigreset(0); - /* increase SHLVL */ - if(!(SHLVL->nvalue.ip)) + /* Unset all variables (don't delete yet) */ + for(np = dtfirst(sh.var_tree); np; np = npnext) { - shlvl = 0; - SHLVL->nvalue.ip = &shlvl; - nv_onattr(SHLVL,NV_INTEGER|NV_EXPORT|NV_NOFREE); + int nofree; + npnext = (Namval_t*)dtnext(sh.var_tree,np); + if(np==DOTSHNOD || np==L_ARGNOD) /* TODO: unset these without crashing */ + continue; + if(nv_isref(np)) + nv_unref(np); + if(nv_isarray(np)) + nv_putsub(np,NULL,ARRAY_UNDEF); + nofree = nv_isattr(np,NV_NOFREE); /* note: returns bitmask, not boolean */ + _nv_unset(np,NV_RDONLY); /* also clears NV_NOFREE attr, if any */ + nv_setattr(np,nofree); + } + /* Delete functions and built-ins. Note: fun_tree has a viewpath to bltin_tree */ + for(np = dtfirst(sh.fun_tree); np; np = npnext) + { + if((dp = sh.fun_tree)->walk) + dp = dp->walk; /* the dictionary in which the item was found */ + npnext = (Namval_t*)dtnext(sh.fun_tree,np); + if(dp==sh.bltin_tree) + { + if(np->nvalue.bfp) + sh_addbuiltin(nv_name(np), np->nvalue.bfp, pointerof(1)); + } + else if(is_afunction(np)) + { + _nv_unset(np,NV_RDONLY); + nv_delete(np,dp,NV_FUNCTION); + } } - *SHLVL->nvalue.ip +=1; - nv_offattr(SHLVL,NV_IMPORT); - sh.st.filename = sh_strdup(sh.lastarg); - nv_delete(NULL, NULL, 0); - job.exitval = 0; - sh.inpipe = sh.outpipe = 0; - job_clear(); - job.in_critical = 0; - /* update $$, $PPID */ - sh.ppid = sh.current_ppid; - sh.pid = sh.current_pid; - /* restore an exported FPATH */ - if(savfpath) + /* Delete all variables in a separate pass; this avoids 'no parent' errors while + * unsetting variables or discipline functions with dot names like .foo.bar */ + for(np = dtfirst(sh.var_tree); np; np = npnext) { - nv_setattr(FPATHNOD,NV_EXPORT); - nv_putval(FPATHNOD,savfpath,0); - free(savfpath); + if((dp = sh.var_tree)->walk) + dp = dp->walk; /* the dictionary in which the item was found */ + npnext = (Namval_t*)dtnext(sh.var_tree,np); + /* cannot delete default variables */ + if(np >= sh.bltin_nodes && np < &sh.bltin_nodes[nvars]) + continue; + nv_delete(np,dp,nv_isattr(np,NV_NOFREE)); } + /* Reset state for subshells, environment, job control, function calls and file descriptors */ + sh.subshell = sh.realsubshell = sh.comsub = sh.curenv = sh.jobenv = sh.inuse_bits = sh.fn_depth = sh.dot_depth = 0; + sh.envlist = NULL; + sh.last_root = NULL; + /* Free up the dictionary trees themselves */ + freeup_tree(sh.fun_tree); /* includes sh.bltin_tree */ + freeup_tree(sh.alias_tree); + freeup_tree(sh.track_tree); + freeup_tree(sh.typedict); + freeup_tree(sh.var_tree); +#if SHOPT_STATS + free(sh.stats); + sh.stats = NULL; +#endif + /* Re-init variables, functions and built-ins */ + free(sh.bltin_cmds); + free(sh.bltin_nodes); + free(sh.mathnodes); + free(sh.init_context); + sh.init_context = nv_init(); + /* Re-import the environment (re-exported in exscript()) */ + env_init(); + /* Increase SHLVL */ + shlvl++; /* call user init function, if any */ if(sh.userinit) (*sh.userinit)(&sh, 1); - return 1; + sh_offstate(SH_INIT); } /* @@ -1723,8 +1715,6 @@ Namfun_t *nv_cover(Namval_t *np) return NULL; } -static const char *shdiscnames[] = { "tilde", 0}; - #if SHOPT_STATS struct Stats { @@ -1937,7 +1927,6 @@ static Init_t *nv_init(void) sh.fun_base = sh.fun_tree = dtopen(&_Nvdisc,Dtoset); dtview(sh.fun_tree,sh.bltin_tree); nv_mount(DOTSHNOD, "type", sh.typedict=dtopen(&_Nvdisc,Dtoset)); - nv_adddisc(DOTSHNOD, shdiscnames, NULL); DOTSHNOD->nvalue.cp = Empty; nv_onattr(DOTSHNOD,NV_RDONLY); SH_LINENO->nvalue.ip = &sh.st.lineno; @@ -1984,7 +1973,7 @@ Dt_t *sh_inittree(const struct shtable2 *name_vals) np->nvname = (char*)tp->sh_name; treep = base_treep; } - np->nvenv = 0; + np->nvmeta = NULL; if(name_vals==(const struct shtable2*)shtab_builtins) np->nvalue.bfp = (void*)((struct shtable3*)tp)->sh_value; else @@ -2012,29 +2001,31 @@ Dt_t *sh_inittree(const struct shtable2 *name_vals) * read in the process environment and set up name-value pairs * skip over items that are not name-value pairs */ -void env_init(void) +static void env_init(void) { char *cp; - Namval_t *np; char **ep=environ; + int save_env_n = 0; if(ep) { while(cp = *ep++) { if(strncmp(cp,"KSH_VERSION=",12)==0) continue; - else if(np = nv_open(cp,sh.var_tree,(NV_EXPORT|NV_IDENT|NV_ASSIGN|NV_NOFAIL))) - { - nv_onattr(np,NV_IMPORT); - np->nvenv = cp; - } - else /* swap with front */ - { - ep[-1] = environ[sh.nenv]; - environ[sh.nenv++] = cp; + if(!nv_open(cp,sh.var_tree,(NV_EXPORT|NV_IDENT|NV_ASSIGN|NV_NOFAIL)) && !sh.save_env_n) + { /* + * If the shell assignment via nv_open() failed, we cannot import this + * env var (invalid name); save it for sh_envgen() to pass it on to + * child processes. This does not need to be re-done after forking. + */ + save_env_n++; + sh.save_env = sh_realloc(sh.save_env, save_env_n*sizeof(char*)); + sh.save_env[save_env_n-1] = cp; } } } + if(save_env_n) + sh.save_env_n = save_env_n; if(nv_isnull(PWDNOD) || nv_isattr(PWDNOD,NV_TAGGED)) { nv_offattr(PWDNOD,NV_TAGGED); diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index d63d7f40414a..08224c9012be 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -473,11 +473,11 @@ void sh_ioinit(void) sh.errbuff = (char*)sh_malloc(IOBSIZE/4); sfsetbuf(sfstderr,sh.errbuff,IOBSIZE/4); sfsetbuf(sfstdout,sh.outbuff,IOBSIZE); - sfpool(sfstdout,sh.outpool,SF_WRITE); - sfpool(sfstderr,sh.outpool,SF_WRITE); - sfset(sfstdout,SF_LINE,0); - sfset(sfstderr,SF_LINE,0); - sfset(sfstdin,SF_SHARE|SF_PUBLIC,1); + sfpool(sfstdout,sh.outpool,SFIO_WRITE); + sfpool(sfstderr,sh.outpool,SFIO_WRITE); + sfset(sfstdout,SFIO_LINE,0); + sfset(sfstderr,SFIO_LINE,0); + sfset(sfstdin,SFIO_SHARE|SFIO_PUBLIC,1); } /* @@ -486,9 +486,9 @@ void sh_ioinit(void) static int outexcept(Sfio_t *iop,int type,void *data,Sfdisc_t *handle) { static int active = 0; - if(type==SF_DPOP || type==SF_FINAL) + if(type==SFIO_DPOP || type==SFIO_FINAL) free(handle); - else if(type==SF_WRITE && (*(ssize_t*)data)<0 && sffileno(iop)!=2) + else if(type==SFIO_WRITE && (*(ssize_t*)data)<0 && sffileno(iop)!=2) switch (errno) { case EINTR: @@ -508,7 +508,7 @@ static int outexcept(Sfio_t *iop,int type,void *data,Sfdisc_t *handle) active = 1; ((struct checkpt*)sh.jmplist)->mode = 0; sfpurge(iop); - sfpool(iop,NULL,SF_WRITE); + sfpool(iop,NULL,SFIO_WRITE); errno = save; /* * Note: UNREACHABLE() is avoided here because this errormsg() call will return. @@ -536,7 +536,7 @@ Sfio_t *sh_iostream(int fd) { Sfio_t *iop; int status = sh_iocheckfd(fd); - int flags = SF_WRITE; + int flags = SFIO_WRITE; char *bp; Sfdisc_t *dp; if(status==IOCLOSE) @@ -555,18 +555,18 @@ Sfio_t *sh_iostream(int fd) if(status&IOREAD) { bp = (char *)sh_malloc(IOBSIZE+1); - flags |= SF_READ; + flags |= SFIO_READ; if(!(status&IOWRITE)) - flags &= ~SF_WRITE; + flags &= ~SFIO_WRITE; } else bp = sh.outbuff; if(status&IODUP) - flags |= SF_SHARE|SF_PUBLIC; + flags |= SFIO_SHARE|SFIO_PUBLIC; if((iop = sh.sftable[fd]) && sffileno(iop)>=0) { if(status&IOTTY) - sfset(iop,SF_LINE|SF_WCWIDTH,1); + sfset(iop,SFIO_LINE|SFIO_WCWIDTH,1); sfsetbuf(iop, bp, IOBSIZE); } else if(!(iop=sfnew((fd<=2?iop:0),bp,IOBSIZE,fd,flags))) @@ -574,16 +574,16 @@ Sfio_t *sh_iostream(int fd) dp = sh_newof(0,Sfdisc_t,1,0); if(status&IOREAD) { - sfset(iop,SF_MALLOC,1); + sfset(iop,SFIO_MALLOC,1); if(!(status&IOWRITE)) - sfset(iop,SF_IOCHECK,1); + sfset(iop,SFIO_IOCHECK,1); dp->exceptf = slowexcept; if(status&IOTTY) dp->readf = slowread; else if(status&IONOSEEK) { dp->readf = piperead; - sfset(iop, SF_IOINTR,1); + sfset(iop, SFIO_IOINTR,1); } else dp->readf = 0; @@ -596,7 +596,7 @@ Sfio_t *sh_iostream(int fd) dp->exceptf = pipeexcept; else dp->exceptf = outexcept; - sfpool(iop,sh.outpool,SF_WRITE); + sfpool(iop,sh.outpool,SFIO_WRITE); } sfdisc(iop,dp); sh.sftable[fd] = iop; @@ -668,7 +668,7 @@ int sh_iorenumber(int f1,int f2) sh.fdstatus[f2] = (sh.fdstatus[f1]&~IOCLEX); sfsetfd(spnew,f2); sfswap(spnew,sp); - sfset(sp,SF_SHARE|SF_PUBLIC,1); + sfset(sp,SFIO_SHARE|SFIO_PUBLIC,1); } else { @@ -690,7 +690,7 @@ int sh_iorenumber(int f1,int f2) { sfsetfd(sp,f2); if(f2<=2) - sfset(sp,SF_SHARE|SF_PUBLIC,1); + sfset(sp,SFIO_SHARE|SFIO_PUBLIC,1); } if(f2>=sh.lim.open_max) sh_iovalidfd(f2); @@ -868,7 +868,7 @@ int sh_open(const char *path, int flags, ...) mode = IOREAD; if(fd >= sh.lim.open_max) sh_iovalidfd(fd); - if((sp = sh.sftable[fd]) && (sfset(sp,0,0) & SF_STRING)) + if((sp = sh.sftable[fd]) && (sfset(sp,0,0) & SFIO_STRING)) { int n,err=errno; if((n = sh_fcntl(fd,F_DUPFD,10)) >= 10) @@ -987,12 +987,12 @@ static int io_patseek(regex_t *rp, Sfio_t* sp, int flags) { char *cp, *match; int r, fd=sffileno(sp), close_exec = sh.fdstatus[fd]&IOCLEX; - int was_share,s=(PIPE_BUF>SF_BUFSIZE?SF_BUFSIZE:PIPE_BUF); + int was_share,s=(PIPE_BUF>SFIO_BUFSIZE?SFIO_BUFSIZE:PIPE_BUF); size_t n,m; sh.fdstatus[sffileno(sp)] |= IOCLEX; if(fd==0) - was_share = sfset(sp,SF_SHARE,1); - while((cp=sfreserve(sp, -s, SF_LOCKR)) || (cp=sfreserve(sp,SF_UNBOUND, SF_LOCKR))) + was_share = sfset(sp,SFIO_SHARE,1); + while((cp=sfreserve(sp, -s, SFIO_LOCKR)) || (cp=sfreserve(sp,SFIO_UNBOUND, SFIO_LOCKR))) { m = n = sfvalue(sp); while(n>0 && cp[n-1]!='\n') @@ -1015,8 +1015,8 @@ static int io_patseek(regex_t *rp, Sfio_t* sp, int flags) } if(!close_exec) sh.fdstatus[sffileno(sp)] &= ~IOCLEX; - if(fd==0 && !(was_share&SF_SHARE)) - sfset(sp, SF_SHARE,0); + if(fd==0 && !(was_share&SFIO_SHARE)) + sfset(sp, SFIO_SHARE,0); return 0; } @@ -1190,7 +1190,7 @@ int sh_redirect(struct ionod *iop, int flag) { if(iof&IOLSEEK) { - struct argnod *ap = (struct argnod*)stkalloc(sh.stk,ARGVAL+strlen(iop->ioname)); + struct argnod *ap = stkalloc(sh.stk,ARGVAL+strlen(iop->ioname)); memset(ap, 0, ARGVAL); ap->argflag = ARG_MAC; strcpy(ap->argval,iop->ioname); @@ -1202,7 +1202,7 @@ int sh_redirect(struct ionod *iop, int flag) if((iof&IOPROCSUB) && !(iof&IOLSEEK)) { /* handle process substitution passed to redirection */ - struct argnod *ap = (struct argnod*)stkalloc(sh.stk,ARGVAL+strlen(iop->ioname)); + struct argnod *ap = stkalloc(sh.stk,ARGVAL+strlen(iop->ioname)); memset(ap, 0, ARGVAL); if(iof&IOPUT) ap->argflag = ARG_RAW; @@ -1621,12 +1621,12 @@ static int io_heredoc(struct ionod *iop, const char *name, int traceon) if(fno>=0 || (iop->iofile&IOQUOTE)) { /* This is a quoted here-document, not expansion */ - sfmove(infile,tmp,SF_UNBOUND,-1); + sfmove(infile,tmp,SFIO_UNBOUND,-1); sfclose(infile); if(sffileno(tmp)>0) { sfsetbuf(tmp,sh_malloc(IOBSIZE+1),IOBSIZE); - sfset(tmp,SF_MALLOC,1); + sfset(tmp,SFIO_MALLOC,1); } sfseek(sh.heredocs,off,SEEK_SET); if(fno>=0) @@ -1866,14 +1866,14 @@ int sh_ioaccess(int fd,int mode) static int slowexcept(Sfio_t *iop,int type,void *data,Sfdisc_t *handle) { int n,fno; - if(type==SF_DPOP || type==SF_FINAL) + if(type==SFIO_DPOP || type==SFIO_FINAL) free(handle); - if(type==SF_WRITE && ERROR_PIPE(errno)) + if(type==SFIO_WRITE && ERROR_PIPE(errno)) { sfpurge(iop); return -1; } - if(type!=SF_READ) + if(type!=SFIO_READ) return 0; if((sh.trapnote&(SH_SIGSET|SH_SIGTRAP)) && errno!=EIO && errno!=ENXIO) errno = EINTR; @@ -1961,7 +1961,7 @@ static ssize_t piperead(Sfio_t *iop,void *buff,size_t size,Sfdisc_t *handle) if(sh_isstate(SH_INTERACTIVE) && fd==0 && io_prompt(iop,sh.nextprompt)<0 && errno==EIO) return 0; sh_onstate(SH_TTYWAIT); - if(!(sh.fdstatus[fd]&IOCLEX) && (sfset(iop,0,0)&SF_SHARE)) + if(!(sh.fdstatus[fd]&IOCLEX) && (sfset(iop,0,0)&SFIO_SHARE)) size = ed_read(sh.ed_context, fd, (char*)buff, size,0); else size = sfrd(iop,buff,size,handle); @@ -2156,7 +2156,7 @@ static int io_prompt(Sfio_t *iop,int flag) flag = 0; if(flag==0) return sfsync(sfstderr); - sfflags = sfset(sfstderr,SF_SHARE|SF_PUBLIC|SF_READ,0); + sfflags = sfset(sfstderr,SFIO_SHARE|SFIO_PUBLIC|SFIO_READ,0); if(!(sh.prompt=(char*)sfreserve(sfstderr,0,0))) sh.prompt = ""; switch(flag) @@ -2201,7 +2201,7 @@ static int io_prompt(Sfio_t *iop,int flag) /* PS2 prompt. Save stack state to avoid corrupting command substitutions * in case we're executing a PS2.get discipline function at parse time. */ int savestacktop = stktell(sh.stk); - char *savestackptr = stkfreeze(sh.stk,0); + void *savestackptr = stkfreeze(sh.stk,0); cp = nv_getval(sh_scoped(PS2NOD)); stkset(sh.stk, savestackptr, savestacktop); break; @@ -2217,7 +2217,7 @@ static int io_prompt(Sfio_t *iop,int flag) done: if(*sh.prompt && (endprompt=(char*)sfreserve(sfstderr,0,0))) *endprompt = 0; - sfset(sfstderr,sfflags&SF_READ|SF_SHARE|SF_PUBLIC,1); + sfset(sfstderr,sfflags&SFIO_READ|SFIO_SHARE|SFIO_PUBLIC,1); return sfsync(sfstderr); } @@ -2227,9 +2227,9 @@ static int io_prompt(Sfio_t *iop,int flag) */ static int pipeexcept(Sfio_t* iop, int mode, void *data, Sfdisc_t* handle) { - if(mode==SF_DPOP || mode==SF_FINAL) + if(mode==SFIO_DPOP || mode==SFIO_FINAL) free(handle); - else if(mode==SF_WRITE && ERROR_PIPE(errno)) + else if(mode==SFIO_WRITE && ERROR_PIPE(errno)) { sfpurge(iop); return -1; @@ -2246,21 +2246,21 @@ static void sftrack(Sfio_t* sp, int flag, void* data) struct checkpt *pp; int mode; int newfd = integralof(data); - if(flag==SF_SETFD || flag==SF_CLOSING) + if(flag==SFIO_SETFD || flag==SFIO_CLOSING) { if(newfd<0) - flag = SF_CLOSING; + flag = SFIO_CLOSING; if(fdnotify) - (*fdnotify)(sffileno(sp),flag==SF_CLOSING?-1:newfd); + (*fdnotify)(sffileno(sp),flag==SFIO_CLOSING?-1:newfd); } #ifdef DEBUG - if(flag==SF_READ || flag==SF_WRITE) + if(flag==SFIO_READ || flag==SFIO_WRITE) { char *z = fmtint(sh.current_pid,0); write(ERRIO,z,strlen(z)); write(ERRIO,": ",2); write(ERRIO,"attempt to ",11); - if(flag==SF_READ) + if(flag==SFIO_READ) write(ERRIO,"read from",9); else write(ERRIO,"write to",8); @@ -2273,20 +2273,20 @@ static void sftrack(Sfio_t* sp, int flag, void* data) if(sh_isstate(SH_NOTRACK)) return; mode = sfset(sp,0,0); - if(sp==sh.heredocs && fd < 10 && flag==SF_SETFD) + if(sp==sh.heredocs && fd < 10 && flag==SFIO_SETFD) { fd = sfsetfd(sp,10); fcntl(fd,F_SETFD,FD_CLOEXEC); } if(fd < 3) return; - if(flag==SF_NEW) + if(flag==SFIO_NEW) { if(!sh.sftable[fd] && sh.fdstatus[fd]==IOCLOSE) { sh.sftable[fd] = sp; - flag = (mode&SF_WRITE)?IOWRITE:0; - if(mode&SF_READ) + flag = (mode&SFIO_WRITE)?IOWRITE:0; + if(mode&SFIO_READ) flag |= IOREAD; sh.fdstatus[fd] = flag; sh_iostream(fd); @@ -2307,7 +2307,7 @@ static void sftrack(Sfio_t* sp, int flag, void* data) if(fdnotify) (*fdnotify)(-1,sffileno(sp)); } - else if(flag==SF_CLOSING || (flag==SF_SETFD && newfd<=2)) + else if(flag==SFIO_CLOSING || (flag==SFIO_SETFD && newfd<=2)) { sh.sftable[fd] = 0; sh.fdstatus[fd]=IOCLOSE; @@ -2369,11 +2369,11 @@ static int eval_exceptf(Sfio_t *iop,int type, void *data, Sfdisc_t *handle) int len; /* no more to do */ - if(type!=SF_READ || !(cp = ep->argv[0])) + if(type!=SFIO_READ || !(cp = ep->argv[0])) { - if(type==SF_CLOSING) - sfdisc(iop,SF_POPDISC); - else if(ep && (type==SF_DPOP || type==SF_FINAL)) + if(type==SFIO_CLOSING) + sfdisc(iop,SFIO_POPDISC); + else if(ep && (type==SFIO_DPOP || type==SFIO_FINAL)) free(ep); return 0; } @@ -2411,7 +2411,7 @@ static Sfio_t *subopen(Sfio_t* sp, off_t offset, long size) disp->oldsp = sp; disp->offset = offset; disp->size = disp->left = size; - sp = sfnew(NULL,(char*)(disp+1),IOBSIZE,PSEUDOFD,SF_READ); + sp = sfnew(NULL,(char*)(disp+1),IOBSIZE,PSEUDOFD,SFIO_READ); sfdisc(sp,&disp->disc); return sp; } @@ -2442,23 +2442,23 @@ static ssize_t subread(Sfio_t* sp,void* buff,size_t size,Sfdisc_t* handle) static int subexcept(Sfio_t* sp,int mode, void *data, Sfdisc_t* handle) { struct subfile *disp = (struct subfile*)handle; - if(mode==SF_CLOSING) + if(mode==SFIO_CLOSING) { - sfdisc(sp,SF_POPDISC); + sfdisc(sp,SFIO_POPDISC); sfsetfd(sp,-1); return 0; } - else if(disp && (mode==SF_DPOP || mode==SF_FINAL)) + else if(disp && (mode==SFIO_DPOP || mode==SFIO_FINAL)) { free(disp); return 0; } - else if (mode==SF_ATEXIT) + else if (mode==SFIO_ATEXIT) { - sfdisc(sp, SF_POPDISC); + sfdisc(sp, SFIO_POPDISC); return 0; } - else if(mode==SF_READ) + else if(mode==SFIO_READ) return 0; return -1; } @@ -2554,7 +2554,7 @@ ssize_t sh_write(int fd, const void* buff, size_t n) off_t sh_seek(int fd, off_t offset, int whence) { Sfio_t *sp; - if((sp=sh.sftable[fd]) && (sfset(sp,0,0)&(SF_READ|SF_WRITE))) + if((sp=sh.sftable[fd]) && (sfset(sp,0,0)&(SFIO_READ|SFIO_WRITE))) return sfseek(sp,offset,whence); else return lseek(fd,offset,whence); @@ -2615,7 +2615,7 @@ mode_t sh_umask(mode_t m) /* * give file descriptor and , return an iostream pointer - * must be SF_READ or SF_WRITE + * must be SFIO_READ or SFIO_WRITE * must be a non-negative number ofr SH_IOCOPROCESS or SH_IOHISTFILE. * returns NULL on failure and may set errno. */ @@ -2623,7 +2623,7 @@ Sfio_t *sh_iogetiop(int fd, int mode) { int n; Sfio_t *iop=0; - if(mode!=SF_READ && mode!=SF_WRITE) + if(mode!=SFIO_READ && mode!=SFIO_WRITE) { errno = EINVAL; return iop; @@ -2636,7 +2636,7 @@ Sfio_t *sh_iogetiop(int fd, int mode) fd = sffileno(sh.hist_ptr->histfp); break; case SH_IOCOPROCESS: - if(mode==SF_WRITE) + if(mode==SFIO_WRITE) fd = sh.coutpipe; else fd = sh.cpipe[0]; @@ -2652,9 +2652,9 @@ Sfio_t *sh_iogetiop(int fd, int mode) } if(!(n=sh.fdstatus[fd])) n = sh_iocheckfd(fd); - if(mode==SF_WRITE && !(n&IOWRITE)) + if(mode==SFIO_WRITE && !(n&IOWRITE)) return iop; - if(mode==SF_READ && !(n&IOREAD)) + if(mode==SFIO_READ && !(n&IOREAD)) return iop; if(!(iop = sh.sftable[fd])) iop=sh_iostream(fd); @@ -2679,9 +2679,9 @@ Sfio_t *sh_fd2sfio(int fd) { int flags=0; if(status&IOREAD) - flags |= SF_READ; + flags |= SFIO_READ; if(status&IOWRITE) - flags |= SF_WRITE; + flags |= SFIO_WRITE; sp = sfnew(NULL, NULL, -1, fd,flags); sh.sftable[fd] = sp; } diff --git a/src/cmd/ksh93/sh/jobs.c b/src/cmd/ksh93/sh/jobs.c index 442abe8502fd..4d80978a0454 100644 --- a/src/cmd/ksh93/sh/jobs.c +++ b/src/cmd/ksh93/sh/jobs.c @@ -181,21 +181,6 @@ static char *job_string; static void job_unstop(struct process*, int); static void job_fgrp(struct process*, int); -#ifndef _lib_tcgetpgrp -# ifdef TIOCGPGRP - static int _i_; -# define tcgetpgrp(a) (ioctl(a, TIOCGPGRP, &_i_)>=0?_i_:-1) -# endif /* TIOCGPGRP */ - int tcsetpgrp(int fd,pid_t pgrp) - { - int pgid = pgrp; -# ifdef TIOCGPGRP - return ioctl(fd, TIOCSPGRP, &pgid); -# else - return -1; -# endif /* TIOCGPGRP */ - } -#endif /* _lib_tcgetpgrp */ #ifndef OTTYDISC # undef NTTYDISC diff --git a/src/cmd/ksh93/sh/lex.c b/src/cmd/ksh93/sh/lex.c index 26c72d96dc62..7439e4969e79 100644 --- a/src/cmd/ksh93/sh/lex.c +++ b/src/cmd/ksh93/sh/lex.c @@ -94,7 +94,8 @@ static void refvar(Lex_t *lp, int type) else { int n,offset = stktell(sh.stk); - char *savptr,*begin; + void *savptr; + char *begin; off = offset + (fcseek(0)-(type+1)) - fcfirst(); if(lp->lexd.kiaoff < offset) { @@ -150,7 +151,7 @@ static void lex_advance(Sfio_t *iop, const char *buff, int size, void *context) size -= (lp->lexd.first-(char*)buff); buff = lp->lexd.first; if(!lp->lexd.noarg) - lp->arg = (struct argnod*)stkseek(sh.stk,ARGVAL); + lp->arg = stkseek(sh.stk,ARGVAL); #if SHOPT_KIA lp->lexd.kiaoff += ARGVAL; #endif /* SHOPT_KIA */ @@ -1252,7 +1253,7 @@ int sh_lex(Lex_t* lp) state = fcfirst(); n = fcseek(0)-(char*)state; if(!lp->arg) - lp->arg = (struct argnod*)stkseek(sh.stk,ARGVAL); + lp->arg = stkseek(sh.stk,ARGVAL); if(n>0) sfwrite(sh.stk,state,n); sfputc(sh.stk,0); @@ -1286,7 +1287,7 @@ int sh_lex(Lex_t* lp) { /* Redirection of the form {varname}>file, etc. */ stkseek(sh.stk,stktell(sh.stk)-1); - lp->arg = (struct argnod*)stkfreeze(sh.stk,1); + lp->arg = stkfreeze(sh.stk,1); return lp->token=IOVNAME; } c = wordflags; @@ -1310,7 +1311,7 @@ int sh_lex(Lex_t* lp) } if(c==0 || (c&(ARG_MAC|ARG_EXP|ARG_MESSAGE))) { - lp->arg = (struct argnod*)stkfreeze(sh.stk,1); + lp->arg = stkfreeze(sh.stk,1); lp->arg->argflag = (c?c:ARG_RAW); } else if(mode==ST_NONE) @@ -2112,7 +2113,7 @@ noreturn void sh_syntax(Lex_t *lp) Sfio_t *top; while(fcget()>0); fcclose(); - while(top=sfstack(sp,SF_POPSTACK)) + while(top=sfstack(sp,SFIO_POPSTACK)) sfclose(top); } else @@ -2202,7 +2203,7 @@ static struct argnod *endword(int mode) stkseek(sh.stk,dp - (unsigned char*)stkptr(sh.stk,0)); if(mode<=0) { - argp = (struct argnod*)stkfreeze(sh.stk,0); + argp = stkfreeze(sh.stk,0); argp->argflag = ARG_RAW|ARG_QUOTED; } return argp; @@ -2411,19 +2412,19 @@ static int alias_exceptf(Sfio_t *iop,int type,void *data, Sfdisc_t *handle) Namval_t *np; Lex_t *lp; NOT_USED(data); - if(type==0 || type==SF_ATEXIT || !ap) + if(type==0 || type==SFIO_ATEXIT || !ap) return 0; lp = ap->lp; np = ap->np; - if(type!=SF_READ) + if(type!=SFIO_READ) { - if(type==SF_CLOSING) + if(type==SFIO_CLOSING) { - Sfdisc_t *dp = sfdisc(iop,SF_POPDISC); + Sfdisc_t *dp = sfdisc(iop,SFIO_POPDISC); if(dp!=handle) sfdisc(iop,dp); } - else if(type==SF_DPOP || type==SF_FINAL) + else if(type==SFIO_DPOP || type==SFIO_FINAL) free(ap); goto done; } diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index 2d5ee6a42a97..6d18514413b6 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -1484,7 +1484,7 @@ static int varsub(Mac_t *mp) if(np && (type==M_BRACE ? !nv_isnull(np) : (type==M_TREE || !c || !ap))) { /* Either the parameter is set, or it's a special type of expansion where 'unset' doesn't apply. */ - char *savptr; + void *savptr; c = *((unsigned char*)stkptr(stkp,offset-1)); savptr = stkfreeze(stkp,0); if(type==M_VNAME || (type==M_SUBNAME && ap)) @@ -2156,7 +2156,8 @@ static void comsubst(Mac_t *mp,Shnode_t* t, int type) struct slnod *saveslp = sh.st.staklist; Mac_t savemac = *mp; int savtop = stktell(stkp); - char lastc=0, *savptr = stkfreeze(stkp,0); + char lastc = '\0'; + void *savptr = stkfreeze(stkp,0); int was_history = sh_isstate(SH_HISTORY); int was_verbose = sh_isstate(SH_VERBOSE); int was_interactive = sh_isstate(SH_INTERACTIVE); @@ -2218,7 +2219,7 @@ static void comsubst(Mac_t *mp,Shnode_t* t, int type) sh_offstate(SH_VERBOSE); if(mp->sp) sfsync(mp->sp); /* flush before executing command */ - sp = sfnew(NULL,str,c,-1,SF_STRING|SF_READ); + sp = sfnew(NULL,str,c,-1,SFIO_STRING|SFIO_READ); c = sh.inlineno; sh.inlineno = error_info.line+sh.st.firstline; t = (Shnode_t*)sh_parse(sp,SH_EOF|SH_NL); @@ -2255,7 +2256,7 @@ static void comsubst(Mac_t *mp,Shnode_t* t, int type) if(!(sp=sh.sftable[fd])) { char *cp = (char*)sh_malloc(IOBSIZE+1); - sp = sfnew(NULL,cp,IOBSIZE,fd,SF_READ|SF_MALLOC); + sp = sfnew(NULL,cp,IOBSIZE,fd,SFIO_READ|SFIO_MALLOC); } } else @@ -2283,7 +2284,7 @@ static void comsubst(Mac_t *mp,Shnode_t* t, int type) sfsetbuf(sp,sp,0); bufsize = sfvalue(sp); /* read command substitution output and put on stack or here-doc */ - sfpool(sp, NULL, SF_WRITE); + sfpool(sp, NULL, SFIO_WRITE); sh_offstate(SH_INTERACTIVE); if((foff = sfseek(sp,0,SEEK_END)) > 0) { @@ -2292,7 +2293,7 @@ static void comsubst(Mac_t *mp,Shnode_t* t, int type) stkseek(stkp,soff+foff+64); stkseek(stkp,soff); } - while((str=(char*)sfreserve(sp,SF_UNBOUND,0)) && (c=bufsize=sfvalue(sp))>0) + while((str=(char*)sfreserve(sp,SFIO_UNBOUND,0)) && (c=bufsize=sfvalue(sp))>0) { #if SHOPT_CRNL /* eliminate */ @@ -2573,7 +2574,7 @@ static void endfield(Mac_t *mp,int split) Stk_t *stkp = sh.stk; if(stktell(stkp) > ARGVAL || split) { - argp = (struct argnod*)stkfreeze(stkp,1); + argp = stkfreeze(stkp,1); argp->argnxt.cp = 0; argp->argflag = 0; mp->atmode = 0; diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index 01f3720d61bf..64aadb4d2a73 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -64,7 +64,7 @@ static struct stat lastmail; static time_t mailtime; static char beenhere = 0; -#ifdef _lib_sigvec +#if _lib_sigvec void clearsigmask(int sig) { struct sigvec vec; @@ -116,7 +116,7 @@ int sh_main(int ac, char *av[], Shinit_f userinit) int i; int rshflag; /* set for restricted shell */ char *command; -#ifdef _lib_sigvec +#if _lib_sigvec /* This is to clear mask that may be left on by rlogin */ clearsigmask(SIGALRM); clearsigmask(SIGHUP); @@ -133,9 +133,8 @@ int sh_main(int ac, char *av[], Shinit_f userinit) if(sigsetjmp(*((sigjmp_buf*)sh.jmpbuffer),0)) { /* begin script execution here */ - sh_reinit(NULL); + sh_reinit(); } - sh.fn_depth = sh.dot_depth = 0; command = error_info.id; path_pwd(); iop = NULL; @@ -230,7 +229,7 @@ int sh_main(int ac, char *av[], Shinit_f userinit) if(sh.comdiv) { shell_c: - iop = sfnew(NULL,sh.comdiv,strlen(sh.comdiv),0,SF_STRING|SF_READ); + iop = sfnew(NULL,sh.comdiv,strlen(sh.comdiv),0,SFIO_STRING|SFIO_READ); } else { @@ -450,7 +449,7 @@ static void exfile(Sfio_t *iop,int fno) { while(fcget()>0); fcclose(); - while(top=sfstack(iop,SF_POPSTACK)) + while(top=sfstack(iop,SFIO_POPSTACK)) sfclose(top); } /* @@ -609,6 +608,7 @@ static void exfile(Sfio_t *iop,int fno) { execflags |= sh_state(SH_NOFORK); } + sh.dont_optimize_builtins = 0; sh.st.breakcnt = 0; sh_exec(t,execflags); if(sh.forked) diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index 4b4e372bea68..356203159cec 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -1177,7 +1177,7 @@ Namval_t *nv_create(const char *name, Dt_t *root, int flags, Namfun_t *dp) if(n && ap && !ap->table) ap->table = dtopen(&_Nvdisc,Dtoset); if(ap && ap->table && (nq=nv_search(sub,ap->table,n))) - nq->nvenv = (char*)np; + nq->nvmeta = np; if(nq && nv_isnull(nq)) nq = nv_arraychild(np,nq,c); } @@ -1672,8 +1672,6 @@ void nv_putval(Namval_t *np, const char *string, int flags) up = np->nvalue.up; if(up && up->cp==Empty) up->cp = 0; - if(nv_isattr(np,NV_EXPORT)) - nv_offattr(np,NV_IMPORT); if(nv_isattr (np, NV_INTEGER)) { if(nv_isattr(np, NV_DOUBLE) == NV_DOUBLE) @@ -1870,7 +1868,7 @@ void nv_putval(Namval_t *np, const char *string, int flags) } if(nv_isattr(np, NV_HOST|NV_INTEGER)==NV_HOST && sp) { -#ifdef _lib_pathnative +#if _lib_pathnative /* * return the host file name given the UNIX name */ @@ -2143,11 +2141,8 @@ static char *staknam(Namval_t *np, char *value) char *p,*q; q = stkalloc(sh.stk,strlen(nv_name(np))+(value?strlen(value):0)+2); p=strcopy(q,nv_name(np)); - if(value) - { - *p++ = '='; - strcpy(p,value); - } + *p++ = '='; + strcpy(p,value); return q; } @@ -2161,9 +2156,7 @@ static void pushnam(Namval_t *np, void *data) if(strchr(np->nvname,'.')) return; ap->tp = 0; - if(nv_isattr(np,NV_IMPORT) && np->nvenv) - *ap->argnam++ = np->nvenv; - else if(value=nv_getval(np)) + if(value=nv_getval(np)) *ap->argnam++ = staknam(np,value); } @@ -2180,11 +2173,13 @@ char **sh_envgen(void) /* L_ARGNOD gets generated automatically as full path name of command */ nv_offattr(L_ARGNOD,NV_EXPORT); namec = nv_scan(sh.var_tree,nullscan,NULL,NV_EXPORT,NV_EXPORT); - namec += sh.nenv; - er = (char**)stkalloc(sh.stk,(namec+4)*sizeof(char*)); - data.argnam = (er+=2) + sh.nenv; - if(sh.nenv) - memcpy(er,environ,sh.nenv*sizeof(char*)); + namec += sh.save_env_n; + er = stkalloc(sh.stk,(namec+4)*sizeof(char*)); + data.argnam = (er+=2) + sh.save_env_n; + /* Pass non-imported env vars to child */ + if(sh.save_env_n) + memcpy(er,sh.save_env,sh.save_env_n*sizeof(char*)); + /* Add exported vars */ nv_scan(sh.var_tree, pushnam,&data,NV_EXPORT, NV_EXPORT); *data.argnam = 0; return er; @@ -2305,53 +2300,6 @@ void sh_scope(struct argnod *envlist, int fun) sh.var_tree = newscope; } -/* - * Remove freeable local space associated with the nvalue field - * of nnod. This includes any strings representing the value(s) of the - * node, as well as its dope vector, if it is an array. - */ -void sh_envnolocal (Namval_t *np, void *data) -{ - char *cp = 0, was_export = nv_isattr(np,NV_EXPORT)!=0; - NOT_USED(data); - if(np==VERSIONNOD && nv_isref(np)) - return; - if(np==L_ARGNOD) - return; - if(np == sh.namespace) - return; - if(nv_isref(np)) - nv_unref(np); - if(nv_isattr(np,NV_EXPORT) && nv_isarray(np)) - { - nv_putsub(np,NULL,0); - if(cp = nv_getval(np)) - cp = sh_strdup(cp); - } - if(nv_isattr(np,NV_EXPORT|NV_NOFREE)) - { - if(nv_isref(np) && np!=VERSIONNOD) - { - nv_offattr(np,NV_NOFREE|NV_REF); - free(np->nvalue.nrp); - np->nvalue.cp = 0; - } - if(!cp) - return; - } - if(nv_isarray(np)) - nv_putsub(np,NULL,ARRAY_UNDEF); - _nv_unset(np,NV_RDONLY); - nv_setattr(np,0); - if(cp) - { - nv_putval(np,cp,0); - free(cp); - } - if(was_export) - nv_onattr(np,NV_EXPORT); -} - static void table_unset(Dt_t *root, int flags, Dt_t *oroot) { Namval_t *np,*nq, *npnext; @@ -2405,7 +2353,7 @@ static void table_unset(Dt_t *root, int flags, Dt_t *oroot) * will retain its attributes. * can contain NV_RDONLY to override the readonly attribute * being cleared. - * can contain NV_EXPORT to override preserve nvenv + * can contain NV_EXPORT to preserve nvmeta. */ void _nv_unset(Namval_t *np,int flags) { @@ -2422,7 +2370,7 @@ void _nv_unset(Namval_t *np,int flags) } if(is_afunction(np) && np->nvalue.ip) { - struct slnod *slp = (struct slnod*)(np->nvenv); + struct slnod *slp = np->nvmeta; if(np->nvalue.rp->running) { np->nvalue.rp->running |= 1; @@ -2532,7 +2480,7 @@ void _nv_unset(Namval_t *np,int flags) if(nv_isattr(np,NV_EXPORT) && !strchr(np->nvname,'[')) env_change(); if(!(flags&NV_EXPORT) || nv_isattr(np,NV_EXPORT)) - np->nvenv = 0; + np->nvmeta = NULL; nv_setattr(np,0); } else @@ -2910,8 +2858,6 @@ void nv_newattr (Namval_t *np, unsigned newatts, int size) /* handle attributes that do not change data separately */ n = np->nvflag; trans = !(n&NV_INTEGER) && (n&(NV_LTOU|NV_UTOL)); /* transcode to lower or upper case */ - if(newatts&NV_EXPORT) - nv_offattr(np,NV_IMPORT); if(((n^newatts)&NV_EXPORT)) /* EXPORT attribute has been toggled */ { /* record changes to the environment */ @@ -3159,7 +3105,8 @@ int nv_rename(Namval_t *np, int flags) Namval_t *last_table = sh.last_table; Dt_t *last_root = sh.last_root; Dt_t *hp = 0; - char *nvenv=0,*prefix=sh.prefix; + void *nvmeta = NULL; + char *prefix = sh.prefix; Namarr_t *ap; if(nv_isattr(np,NV_PARAM) && sh.st.prevst) { @@ -3167,8 +3114,8 @@ int nv_rename(Namval_t *np, int flags) hp = dtvnext(sh.var_tree); } if(!nv_isattr(np,NV_MINIMAL)) - nvenv = np->nvenv; - if(nvenv || (cp = nv_name(np)) && nv_isarray(np) && cp[strlen(cp)-1] == ']') + nvmeta = np->nvmeta; + if(nvmeta || (cp = nv_name(np)) && nv_isarray(np) && cp[strlen(cp)-1] == ']') arraynp = 1; if(!(cp=nv_getval(np))) { @@ -3218,12 +3165,12 @@ int nv_rename(Namval_t *np, int flags) { if(ap = nv_arrayptr(np)) ap->nelem++; - mp->nvenv = nvenv = (void*)np; + mp->nvmeta = nvmeta = np; } } if(mp) { - nvenv = (char*)np; + nvmeta = np; np = mp; } if(nr==np) @@ -3247,7 +3194,7 @@ int nv_rename(Namval_t *np, int flags) sh.last_root = last_root; if(flags&NV_MOVE) { - if(arraynp && !nv_isattr(np,NV_MINIMAL) && (mp=(Namval_t*)np->nvenv) && (ap=nv_arrayptr(mp)) && !ap->fun) + if(arraynp && !nv_isattr(np,NV_MINIMAL) && (mp = np->nvmeta) && (ap = nv_arrayptr(mp)) && !ap->fun) ap->nelem++; } if((nv_arrayptr(nr) && !arraynr) || nv_isvtree(nr)) @@ -3259,7 +3206,7 @@ int nv_rename(Namval_t *np, int flags) if(ap->table) mp = nv_search(nv_getsub(np),ap->table,NV_ADD); nv_arraychild(np,mp,0); - nvenv = (void*)np; + nvmeta = np; } else mp = np; @@ -3285,10 +3232,10 @@ int nv_rename(Namval_t *np, int flags) } else nv_clone(nr,mp,(flags&NV_MOVE)|NV_COMVAR); - mp->nvenv = nvenv; + mp->nvmeta = nvmeta; if(flags&NV_MOVE) { - if(arraynr && !nv_isattr(nr,NV_MINIMAL) && (mp=(Namval_t*)nr->nvenv) && (ap=nv_arrayptr(mp))) + if(arraynr && !nv_isattr(nr,NV_MINIMAL) && (mp = nr->nvmeta) && (ap = nv_arrayptr(mp))) { nv_putsub(mp,nr->nvname,0); _nv_unset(mp,0); @@ -3301,7 +3248,7 @@ int nv_rename(Namval_t *np, int flags) nv_putval(np,nv_getval(nr),0); if(flags&NV_MOVE) { - if(!nv_isattr(nr,NV_MINIMAL) && (mp=(Namval_t*)(nr->nvenv)) && (ap=nv_arrayptr(mp))) + if(!nv_isattr(nr,NV_MINIMAL) && (mp = nr->nvmeta) && (ap = nv_arrayptr(mp))) ap->nelem--; _nv_unset(nr,0); } @@ -3555,9 +3502,9 @@ char *nv_name(Namval_t *np) #if SHOPT_FIXEDARRAY ap = nv_arrayptr(np); #endif /* SHOPT_FIXEDARRAY */ - if(!nv_isattr(np,NV_MINIMAL|NV_EXPORT) && np->nvenv) + if(!nv_isattr(np,NV_MINIMAL|NV_EXPORT) && np->nvmeta) { - Namval_t *nq= sh.last_table, *mp= (Namval_t*)np->nvenv; + Namval_t *nq = sh.last_table, *mp = np->nvmeta; if(np==sh.last_table) sh.last_table = 0; if(nv_isarray(mp)) diff --git a/src/cmd/ksh93/sh/nvdisc.c b/src/cmd/ksh93/sh/nvdisc.c index 1e2b62b41f82..1bde05296758 100644 --- a/src/cmd/ksh93/sh/nvdisc.c +++ b/src/cmd/ksh93/sh/nvdisc.c @@ -328,11 +328,8 @@ static void assign(Namval_t *np,const char* val,int flags,Namfun_t *handle) /* restore everything but the nvlink field */ memcpy(&SH_VALNOD->nvname, &node.nvname, sizeof(node)-sizeof(node.nvlink)); } - else if(sh_isstate(SH_INIT) || np==SH_FUNNAMENOD) - { - /* don't free functions during reinitialization */ + else if(np==SH_FUNNAMENOD) nv_putv(np,val,flags,handle); - } else if(!nq || !isblocked(bp,type)) { Dt_t *root = sh_subfuntree(1); @@ -342,7 +339,7 @@ static void assign(Namval_t *np,const char* val,int flags,Namfun_t *handle) block(bp,type); nv_disc(np,handle,NV_POP); if(!nv_isattr(np,NV_MINIMAL)) - pp = (Namval_t*)np->nvenv; + pp = np->nvmeta; nv_putv(np, val, flags, handle); if(sh.subshell) goto done; @@ -912,11 +909,11 @@ int nv_clone(Namval_t *np, Namval_t *mp, int flags) { if(nv_isattr(mp,NV_EXPORT|NV_MINIMAL) == (NV_EXPORT|NV_MINIMAL)) { - mp->nvenv = 0; + mp->nvmeta = NULL; nv_offattr(mp,NV_MINIMAL); } - if(!(flags&NV_COMVAR) && !nv_isattr(np,NV_MINIMAL) && np->nvenv && !(nv_isattr(mp,NV_MINIMAL))) - mp->nvenv = np->nvenv; + if(!(flags&NV_COMVAR) && !nv_isattr(np,NV_MINIMAL) && np->nvmeta && !(nv_isattr(mp,NV_MINIMAL))) + mp->nvmeta = np->nvmeta; mp->nvflag &= NV_MINIMAL; mp->nvflag |= np->nvflag&~(NV_ARRAY|NV_MINIMAL|NV_NOFREE); flag = mp->nvflag; @@ -951,10 +948,10 @@ int nv_clone(Namval_t *np, Namval_t *mp, int flags) np->nvalue.cp = 0; if(!nv_isattr(np,NV_MINIMAL) || nv_isattr(mp,NV_EXPORT)) { - mp->nvenv = np->nvenv; + mp->nvmeta = np->nvmeta; if(nv_isattr(np,NV_MINIMAL)) { - np->nvenv = 0; + np->nvmeta = NULL; np->nvflag = NV_EXPORT; } else @@ -966,7 +963,7 @@ int nv_clone(Namval_t *np, Namval_t *mp, int flags) return 1; } else if((flags&NV_ARRAY) && !nv_isattr(np,NV_MINIMAL)) - mp->nvenv = np->nvenv; + mp->nvmeta = np->nvmeta; if(nv_isattr(np,NV_INTEGER) && !nv_isarray(np) && mp->nvalue.ip!=np->nvalue.ip && np->nvalue.cp!=Empty) { mp->nvalue.ip = (int*)num_clone(np,np->nvalue.ip); @@ -1105,8 +1102,8 @@ Namval_t *nv_bfsearch(const char *name, Dt_t *root, Namval_t **var, char **last) return np; } #endif /* SHOPT_NAMESPACE */ - while(nv_isarray(nq) && !nv_isattr(nq,NV_MINIMAL|NV_EXPORT) && nq->nvenv && nv_isarray((Namval_t*)nq->nvenv)) - nq = (Namval_t*)nq->nvenv; + while(nv_isarray(nq) && !nv_isattr(nq,NV_MINIMAL|NV_EXPORT) && nq->nvmeta && nv_isarray((Namval_t*)nq->nvmeta)) + nq = nq->nvmeta; return (Namval_t*)nv_setdisc(nq,dname,nq,(Namfun_t*)nq); done: stkseek(sh.stk,offset); @@ -1144,7 +1141,7 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra) stkseek(sh.stk,offset); if(extra == (void*)1) { - if(nv_isattr(np,BLT_SPC)) + if(nv_isattr(np,BLT_SPC) && !sh_isstate(SH_INIT)) { /* builtin(1) cannot delete special builtins */ errormsg(SH_DICT,ERROR_exit(1),"cannot delete: %s%s",name,is_spcbuiltin); @@ -1169,7 +1166,7 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra) return np; if(!bltin) bltin = funptr(np); - if(np->nvenv) + if(np->nvmeta) dtdelete(sh.bltin_tree,np); if(extra == (void*)1) return NULL; @@ -1186,8 +1183,8 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra) np->nvfun = (Namfun_t*)extra; return np; } - np->nvenv = 0; - np->nvfun = 0; + np->nvmeta = NULL; + np->nvfun = NULL; if(bltin) { np->nvalue.bfp = bltin; @@ -1315,7 +1312,7 @@ static char *get_table(Namval_t *np, Namfun_t *fp) if(out) sfseek(out,0,SEEK_SET); else - out = sfnew(NULL,NULL,-1,-1,SF_WRITE|SF_STRING); + out = sfnew(NULL,NULL,-1,-1,SFIO_WRITE|SFIO_STRING); for(np=(Namval_t*)dtfirst(root);np;np=(Namval_t*)dtnext(root,np)) { if(!nv_isnull(np) || np->nvfun || nv_isattr(np,~NV_NOFREE)) diff --git a/src/cmd/ksh93/sh/nvtree.c b/src/cmd/ksh93/sh/nvtree.c index 9405a79f9fd1..9da1c4b5d110 100644 --- a/src/cmd/ksh93/sh/nvtree.c +++ b/src/cmd/ksh93/sh/nvtree.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -727,7 +727,9 @@ static void outval(char *name, const char *vname, struct Walk *wp) _nv_unset(np,NV_RDONLY); if(sh.subshell || (wp->flags!=NV_RDONLY) || nv_isattr(np,NV_MINIMAL|NV_NOFREE)) wp->root = 0; - nv_delete(np,wp->root,nv_isattr(np,NV_MINIMAL)?NV_NOFREE:0); + /* Delete the node from the tree and free np, unless we're unsetting variables in sh_reinit() */ + if(!sh_isstate(SH_INIT)) + nv_delete(np,wp->root,nv_isattr(np,NV_MINIMAL)?NV_NOFREE:0); return; } if(isarray==1 && !nq) @@ -942,7 +944,7 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) Sfio_t *outfile; Sfoff_t off = 0; int len, savtop = stktell(sh.stk); - char *savptr = stkfreeze(sh.stk,0); + void *savptr = stkfreeze(sh.stk,0); struct argnod *ap=0; struct argnod *arglist=0; char *name,*cp, **argv; @@ -1006,7 +1008,7 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) } stkseek(sh.stk,ARGVAL); sfputr(sh.stk,cp,-1); - ap = (struct argnod*)stkfreeze(sh.stk,1); + ap = stkfreeze(sh.stk,1); ap->argflag = ARG_RAW; ap->argchn.ap = arglist; n++; @@ -1018,7 +1020,7 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) sh.var_tree = save_tree; return NULL; } - argv = (char**)stkalloc(sh.stk,(n+1)*sizeof(char*)); + argv = stkalloc(sh.stk,(n+1)*sizeof(char*)); argv += n; *argv = 0; for(; ap; ap=ap->argchn.ap) @@ -1026,7 +1028,7 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) if(flags&1) outfile = 0; else if(!(outfile=out)) - outfile = out = sfnew(NULL,NULL,-1,-1,SF_WRITE|SF_STRING); + outfile = out = sfnew(NULL,NULL,-1,-1,SFIO_WRITE|SFIO_STRING); else if(flags&NV_TABLE) off = sftell(outfile); else diff --git a/src/cmd/ksh93/sh/nvtype.c b/src/cmd/ksh93/sh/nvtype.c index 6e9b484c198a..10e0799ac317 100644 --- a/src/cmd/ksh93/sh/nvtype.c +++ b/src/cmd/ksh93/sh/nvtype.c @@ -527,7 +527,7 @@ static void put_type(Namval_t* np, const char* val, int flag, Namfun_t* fp) Namfun_t *pp; if((pp=nv_hasdisc(nq,fp->disc)) && pp->type==fp->type) { - if(!nq->nvenv) + if(!nq->nvmeta) flag |= NV_EXPORT; _nv_unset(np, flag); nv_clone(nq,np,NV_IARRAY); @@ -582,7 +582,7 @@ static Namfun_t *clone_inttype(Namval_t* np, Namval_t *mp, int flags, Namfun_t * else mp->nvalue.cp = (char*)(fp+1); if(!nv_isattr(mp,NV_MINIMAL)) - mp->nvenv = 0; + mp->nvmeta = NULL; nv_offattr(mp,NV_RDONLY); return pp; } @@ -616,8 +616,8 @@ static int typeinfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp) tp = fp->type; nv_offattr(np,NV_RDONLY); fp->type = 0; - if(np->nvenv) - sfprintf(out,"[+?\b%s\b is a %s.]\n", tp->nvname, np->nvenv); + if(np->nvmeta) + sfprintf(out,"[+?\b%s\b is a %s.]\n", tp->nvname, (char*)np->nvmeta); cp = (char*)out->_next; sfprintf(out,"[+?\b%s\b is a %n ", tp->nvname, &i); nv_attribute(np,out,NULL, 1); @@ -642,7 +642,7 @@ static int typeinfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp) return 0; } help = &dp->names[dp->ndisc]; - sp = sfnew(NULL,buffer,sizeof(buffer),-1,SF_STRING|SF_WRITE); + sp = sfnew(NULL,buffer,sizeof(buffer),-1,SFIO_STRING|SFIO_WRITE); sfprintf(out,"[+?\b%s\b defines the following fields:]{\n",np->nvname); for(i=0; i < dp->numnodes; i++) { @@ -844,8 +844,8 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes) } if(nv_isattr(np,NV_REF)) iref++; - if(np->nvenv) - size += strlen((char*)np->nvenv)+1; + if(np->nvmeta) + size += strlen(np->nvmeta) + 1; if(strcmp(&np->nvname[m],NV_DATA)==0 && !nv_type(np)) continue; if(qp) @@ -971,7 +971,7 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes) char *val=nv_getval(np); nq = nv_namptr(pp->nodes,0); nq->nvfun = 0; - nv_putval(nq,(val?val:0),nv_isattr(np,~(NV_IMPORT|NV_EXPORT|NV_ARRAY))); + nv_putval(nq,(val?val:0),nv_isattr(np,~(NV_MINIMAL|NV_EXPORT|NV_ARRAY))); nq->nvflag = np->nvflag|NV_NOFREE|NV_MINIMAL; goto skip; } @@ -1015,17 +1015,17 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes) goto skip; } nq = nv_namptr(pp->nodes,k); - if(np->nvenv) + if(np->nvmeta) { /* need to save the string pointer */ nv_offattr(np,NV_EXPORT); help[k] = cp; - cp = strcopy(cp,np->nvenv); + cp = strcopy(cp,np->nvmeta); j = *help[k]; if(islower(j)) *help[k] = toupper(j); *cp++ = 0; - np->nvenv = 0; + np->nvmeta = NULL; } nq->nvname = cp; if(name && strncmp(name,&np->nvname[m],n)==0 && np->nvname[m+n]=='.') @@ -1035,7 +1035,7 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes) n = cp-name; *cp++ = 0; nq->nvsize = np->nvsize; - nq->nvflag = (np->nvflag&~(NV_IMPORT|NV_EXPORT))|NV_NOFREE|NV_MINIMAL; + nq->nvflag = (np->nvflag&~NV_EXPORT)|NV_NOFREE|NV_MINIMAL; if(dp = (Namtype_t*)nv_hasdisc(np, &type_disc)) { int r,kfirst=k; @@ -1196,7 +1196,7 @@ Namval_t *nv_mkinttype(char *name, size_t size, int sign, const char *help, Namd fp->disc = dp; mp->nvalue.cp = (char*)(fp+1) + sizeof(Namdisc_t); nv_setsize(mp,10); - mp->nvenv = (char*)help; + mp->nvmeta = (void*)help; nv_onattr(mp,NV_NOFREE|NV_RDONLY|NV_INTEGER|NV_EXPORT); if(size==16) nv_onattr(mp,NV_INT16P); diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index 373ed7f9bb2b..8d8765c954b1 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -38,7 +38,7 @@ #include "history.h" #include "version.h" -#define HERE_MEM SF_BUFSIZE /* size of here-docs kept in memory */ +#define HERE_MEM SFIO_BUFSIZE /* size of here-docs kept in memory */ /* These routines are local to this module */ @@ -68,7 +68,7 @@ static unsigned dcl_recursion; static int opt_get; -#define getnode(type) ((Shnode_t*)stkalloc(sh.stk,sizeof(struct type))) +#define getnode(type) stkalloc(sh.stk,sizeof(struct type)) #if SHOPT_KIA /* @@ -442,7 +442,7 @@ void *sh_parse(Sfio_t *iop, int flag) fcrestore(&sav_input); lexp->arg = sav_arg; /* unstack any completed alias expansions */ - if((sfset(iop,0,0)&SF_STRING) && !sfreserve(iop,0,-1)) + if((sfset(iop,0,0)&SFIO_STRING) && !sfreserve(iop,0,-1)) { Sfio_t *sp = sfstack(iop,NULL); if(sp) @@ -677,7 +677,7 @@ static struct regnod* syncase(Lex_t *lexp,int esym) struct regnod *r; if(tok==esym) return NULL; - r = (struct regnod*)stkalloc(sh.stk,sizeof(struct regnod)); + r = stkalloc(sh.stk,sizeof(struct regnod)); r->regptr=0; r->regflag=0; if(tok==LPAREN) @@ -736,7 +736,7 @@ static Shnode_t *arithfor(Lex_t *lexp,Shnode_t *tf) for(n=0; ; n++) { int c; - argp = (struct argnod*)stkseek(sh.stk,ARGVAL); + argp = stkseek(sh.stk,ARGVAL); argp->argnxt.ap = 0; argp->argchn.cp = 0; argp->argflag = argflag; @@ -757,7 +757,7 @@ static Shnode_t *arithfor(Lex_t *lexp,Shnode_t *tf) /* check for empty condition and treat as while((1)) */ if(offset==ARGVAL) sfputc(sh.stk,'1'); - argp = (struct argnod*)stkfreeze(sh.stk,1); + argp = stkfreeze(sh.stk,1); t = getanode(lexp,argp); if(n==0) tf = makelist(lexp,TLST,t,tw); @@ -767,7 +767,7 @@ static Shnode_t *arithfor(Lex_t *lexp,Shnode_t *tf) while((offset=fcpeek(0)) && isspace(offset)) fcseek(1); sfputr(sh.stk,fcseek(0),-1); - argp = (struct argnod*)stkfreeze(sh.stk,1); + argp = stkfreeze(sh.stk,1); fcrestore(&sav_input); if(n<2) { @@ -878,10 +878,10 @@ static Shnode_t *funct(Lex_t *lexp) jmpval = sigsetjmp(buff.buff,0); if(jmpval == 0) { - /* create a new stack frame to compile the command */ - savstak = stkopen(STK_SMALL); - savstak = stkinstall(savstak, 0); - slp = (struct slnod*)stkalloc(sh.stk,sizeof(struct slnod)+sizeof(struct functnod)); + /* create a new stack to compile the command */ + savstak = sh.stk; + sh.stk = stkopen(STK_SMALL); + slp = stkalloc(sh.stk,sizeof(struct slnod)+sizeof(struct functnod)); slp->slchild = 0; slp->slnext = sh.st.staklist; sh.st.staklist = 0; @@ -899,7 +899,7 @@ static Shnode_t *funct(Lex_t *lexp) fp->functnam = stkcopy(sh.stk,sh.st.filename); if(size) { - struct dolnod *dp = (struct dolnod*)stkalloc(sh.stk,size); + struct dolnod *dp = stkalloc(sh.stk,size); char *cp, *sp, **argv, **old = ((struct dolnod*)t->funct.functargs->comarg)->dolval+1; argv = ((char**)(dp->dolval))+1; dp->dolnum = ((struct dolnod*)t->funct.functargs->comarg)->dolnum; @@ -915,7 +915,7 @@ static Shnode_t *funct(Lex_t *lexp) { /* functname() simple_command: copy current word token to current stack frame */ size_t sz = ARGVAL + strlen(lexp->arg->argval) + 1; /* include terminating 0 */ - struct argnod *ap = (struct argnod*)stkalloc(sh.stk,sz); + struct argnod *ap = stkalloc(sh.stk,sz); memcpy(ap,lexp->arg,sz); lexp->arg = ap; } @@ -928,7 +928,8 @@ static Shnode_t *funct(Lex_t *lexp) /* restore the old stack */ if(slp) { - slp->slptr = stkinstall(savstak,0); + slp->slptr = sh.stk; + sh.stk = savstak; slp->slchild = sh.st.staklist; } #if SHOPT_KIA @@ -1027,14 +1028,14 @@ static struct argnod *assign(Lex_t *lexp, struct argnod *ap, int type) if((n=skipnl(lexp,0))==RPAREN || n==LPAREN) { struct argnod *ar,*aq,**settail; - ac = (struct comnod*)getnode(comnod); + ac = getnode(comnod); memset(ac,0,sizeof(*ac)); comarray: settail= &ac->comset; ac->comline = sh_getlineno(lexp); while(n==LPAREN) { - ar = (struct argnod*)stkseek(sh.stk,ARGVAL); + ar = stkseek(sh.stk,ARGVAL); ar->argflag= ARG_ASSIGN; sfprintf(sh.stk,"[%d]=",index++); if(aq=ac->comarg) @@ -1043,7 +1044,7 @@ static struct argnod *assign(Lex_t *lexp, struct argnod *ap, int type) sfprintf(sh.stk,"%s",aq->argval); ar->argflag |= aq->argflag; } - ar = (struct argnod*)stkfreeze(sh.stk,1); + ar = stkfreeze(sh.stk,1); ar->argnxt.ap = 0; if(!aq) ar = assign(lexp,ar,0); @@ -1054,11 +1055,11 @@ static struct argnod *assign(Lex_t *lexp, struct argnod *ap, int type) continue; while((n = skipnl(lexp,0))==0) { - ar = (struct argnod*)stkseek(sh.stk,ARGVAL); + ar = stkseek(sh.stk,ARGVAL); ar->argflag= ARG_ASSIGN; sfprintf(sh.stk,"[%d]=",index++); sfputr(sh.stk,lexp->arg->argval,-1); - ar = (struct argnod*)stkfreeze(sh.stk,1); + ar = stkfreeze(sh.stk,1); ar->argnxt.ap = 0; ar->argflag = lexp->arg->argflag; *settail = ar; @@ -1285,7 +1286,7 @@ static Shnode_t *item(Lex_t *lexp,int flag) /* some Linux scripts assume this */ if(sh_isoption(SH_NOEXEC)) errormsg(SH_DICT,ERROR_warn(0),e_lexemptyfor,sh.inlineno-(lexp->token=='\n')); - t->for_.forlst = (struct comnod*)getnode(comnod); + t->for_.forlst = getnode(comnod); (t->for_.forlst)->comarg = 0; (t->for_.forlst)->comset = 0; (t->for_.forlst)->comnamp = 0; @@ -1395,7 +1396,7 @@ static struct argnod *process_sub(Lex_t *lexp,int tok) Shnode_t *t; int mode = (tok==OPROCSYM); t = sh_cmd(lexp,RPAREN,SH_NL); - argp = (struct argnod*)stkalloc(sh.stk,sizeof(struct argnod)); + argp = stkalloc(sh.stk,sizeof(struct argnod)); *argp->argval = 0; argp->argchn.ap = (struct argnod*)makeparent(lexp,mode?TFORK|FPIN|FAMP|FPCL:TFORK|FPOU,t); argp->argflag = (ARG_EXP|mode); @@ -1425,7 +1426,7 @@ static Shnode_t *simple(Lex_t *lexp,int flag, struct ionod *io) flag |= SH_ARRAY; associative = 1; } - t = (struct comnod*)getnode(comnod); + t = getnode(comnod); t->comio=io; /* initial io chain */ /* set command line number for error messages */ t->comline = sh_getlineno(lexp); @@ -1461,7 +1462,7 @@ static Shnode_t *simple(Lex_t *lexp,int flag, struct ionod *io) { stkseek(sh.stk,ARGVAL); sfwrite(sh.stk,argp->argval,lexp->varnamelength); - ap=(struct argnod*)stkfreeze(sh.stk,1); + ap = stkfreeze(sh.stk,1); ap->argflag = ARG_RAW; ap->argchn.ap = 0; } @@ -1713,13 +1714,13 @@ static struct ionod *inout(Lex_t *lexp,struct ionod *lastio,int flag) return lastio; } lexp->digits=0; - iop=(struct ionod*) stkalloc(sh.stk,sizeof(struct ionod)); + iop = stkalloc(sh.stk,sizeof(struct ionod)); iop->iodelim = 0; if(token=sh_lex(lexp)) { if(token==RPAREN && (iof&IOLSEEK) && lexp->comsub) { - lexp->arg = (struct argnod*)stkalloc(sh.stk,sizeof(struct argnod)+3); + lexp->arg = stkalloc(sh.stk,sizeof(struct argnod)+3); strcpy(lexp->arg->argval,"CUR"); lexp->arg->argflag = ARG_RAW; iof |= IOARITH; @@ -1790,7 +1791,7 @@ static struct ionod *inout(Lex_t *lexp,struct ionod *lastio,int flag) if(errout) { /* redirect standard output to standard error */ - ioq = (struct ionod*)stkalloc(sh.stk,sizeof(struct ionod)); + ioq = stkalloc(sh.stk,sizeof(struct ionod)); memset(ioq,0,sizeof(*ioq)); ioq->ioname = "1"; ioq->iolst = 0; @@ -1851,7 +1852,7 @@ static struct argnod *qscan(struct comnod *ac,int argn) errormsg(SH_DICT,ERROR_warn(0),message,ac->comline); } /* leave space for an extra argument at the front */ - dp = (struct dolnod*)stkalloc(sh.stk,(unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*)); + dp = stkalloc(sh.stk,(unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*)); cp = dp->dolval+ARG_SPARE; dp->dolnum = argn; dp->dolbot = ARG_SPARE; @@ -2079,9 +2080,8 @@ int kiaclose(Lex_t *lexp) nv_scan(lexp->entity_tree,kia_add,lexp,NV_TAGGED,0); off1 = sfseek(lexp->kiafile,0,SEEK_END); sfseek(lexp->kiatmp,0,SEEK_SET); - sfmove(lexp->kiatmp,lexp->kiafile,SF_UNBOUND,-1); + sfmove(lexp->kiatmp,lexp->kiafile,SFIO_UNBOUND,-1); off2 = sfseek(lexp->kiafile,0,SEEK_END); -#ifdef SF_BUFCONST if(off2==off1) n= sfprintf(lexp->kiafile,"DIRECTORY\nENTITY;%lld;%d\nDIRECTORY;",(Sflong_t)lexp->kiabegin,(size_t)(off1-lexp->kiabegin)); else @@ -2089,13 +2089,6 @@ int kiaclose(Lex_t *lexp) if(off2 >= INT_MAX) off2 = -(n+12); sfprintf(lexp->kiafile,"%010.10lld;%010d\n",(Sflong_t)off2+10, n+12); -#else - if(off2==off1) - n= sfprintf(lexp->kiafile,"DIRECTORY\nENTITY;%d;%d\nDIRECTORY;",lexp->kiabegin,off1-lexp->kiabegin); - else - n= sfprintf(lexp->kiafile,"DIRECTORY\nENTITY;%d;%d\nRELATIONSHIP;%d;%d\nDIRECTORY;",lexp->kiabegin,off1-lexp->kiabegin,off1,off2-off1); - sfprintf(lexp->kiafile,"%010d;%010d\n",off2+10, n+12); -#endif } return sfclose(lexp->kiafile); } diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index 54f665db9ec3..cda76140379d 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -574,7 +574,7 @@ static void funload(int fno, const char *name) sh.funload = 1; sh.inlineno = 1; error_info.line = 0; - sh_eval(sfnew(NULL,buff,IOBSIZE,fno,SF_READ),SH_FUNEVAL); + sh_eval(sfnew(NULL,buff,IOBSIZE,fno,SFIO_READ),SH_FUNEVAL); sh_close(fno); sh.readscript = 0; #if SHOPT_NAMESPACE @@ -728,8 +728,8 @@ Pathcomp_t *path_absolute(const char *name, Pathcomp_t *pp, int flag) sh.path_err = ENOENT; return NULL; } - isfun = (oldpp->flags&PATH_FPATH); - if(!isfun) + isfun = (oldpp->flags&PATH_FPATH) && !sh_isstate(SH_EXEC) && !sh_isstate(SH_XARG); + if(!isfun && !sh_isstate(SH_EXEC) && !sh_isstate(SH_XARG)) { #if SHOPT_DYNAMIC Shbltin_f addr; @@ -797,7 +797,7 @@ Pathcomp_t *path_absolute(const char *name, Pathcomp_t *pp, int flag) (!(np = sh_addbuiltin(stkptr(sh.stk,PATH_OFFSET),NULL,NULL)) || funptr(np)!=addr) && (np = sh_addbuiltin(stkptr(sh.stk,PATH_OFFSET),addr,NULL))) { - np->nvenv = dll; + np->nvmeta = dll; goto found; } if(*stkptr(sh.stk,PATH_OFFSET)=='/' && nv_search(stkptr(sh.stk,PATH_OFFSET),sh.bltin_tree,0)) @@ -982,6 +982,8 @@ noreturn void path_exec(const char *arg0,char *argv[],struct argnod *local) } else opath = arg0; + if(sh.subshell) + sh_subtmpfile(); spawnpid = path_spawn(opath,argv,envp,libpath,0); if(spawnpid==-1 && sh.path_err!=ENOENT) { @@ -1026,7 +1028,7 @@ pid_t path_spawn(const char *opath,char **argv, char **envp, Pathcomp_t *libpath char *s, *v; int r, n, pidsize=0; pid_t pid= -1; - if(nv_search(opath,sh.bltin_tree,0)) + if(!sh_isstate(SH_EXEC) && nv_search(opath,sh.bltin_tree,0)) { /* Found a path-bound built-in. Since this was not caught earlier in sh_exec(), it must have been found on a temporarily assigned PATH, as with 'PATH=/opt/ast/bin:$PATH cat'. @@ -1186,7 +1188,10 @@ pid_t path_spawn(const char *opath,char **argv, char **envp, Pathcomp_t *libpath case EISDIR: return -1; case ENOEXEC: - errno = ENOEXEC; + /* + * A script without #! -- it starts here. Summary of events: + * fork; exscript; longjmp back to sh_main; sh_reinit; exfile + */ if(spawn) { if(sh.subshell) @@ -1276,7 +1281,7 @@ static noreturn void exscript(char *path,char *argv[],char **envp) } sh.cpid = 0; if(sp=fcfile()) - while(sfstack(sp,SF_POPSTACK)); + while(sfstack(sp,SFIO_POPSTACK)); job_clear(); if(sh.infd>0 && (sh.fdstatus[sh.infd]&IOCLEX)) sh_close(sh.infd); @@ -1304,6 +1309,26 @@ static noreturn void exscript(char *path,char *argv[],char **envp) sh_offstate(SH_FORKED); if(sh.sigflag[SIGCHLD]==SH_SIGOFF) sh.sigflag[SIGCHLD] = SH_SIGFAULT; + /* + * Export -x vars to new environment now, before longjmp & removing any local scope. + * Since sh_envgen() puts it all on the stack, create a stack to preserve 'environ'. + */ + { + static Stk_t *envstk; + Stk_t *savstk = sh.stk; + if (envstk) + stkset(envstk, NULL, 0); + else + envstk = stkopen(STK_SMALL); + sh.stk = envstk; + environ = sh_envgen(); + sh.stk = savstk; + stkfreeze(envstk,0); + } + /* + * Longjmp with SH_JMPSCRIPT triggers a chain of longjmps to restore state as appropriate, + * ending up back in sh_main() which then calls sh_reinit() and executes the script. + */ siglongjmp(*sh.jmplist,SH_JMPSCRIPT); UNREACHABLE(); /* silence warning on Haiku */ } @@ -1434,7 +1459,7 @@ static Pathcomp_t *path_addcomp(Pathcomp_t *first, Pathcomp_t *old,const char *n else first = pp; pp->flags = flag; - if(strcmp(name,SH_CMDLIB_DIR)==0) + if(!sh_isstate(SH_EXEC) && strcmp(name,SH_CMDLIB_DIR)==0) { pp->dev = 1; pp->blib = pp->bbuf = sh_malloc(sizeof(LIBCMD)); @@ -1745,7 +1770,7 @@ static Namfun_t talias_init = { &talias_disc, 1 }; void path_settrackedalias(const char *name, Pathcomp_t *pp) { Namval_t *np; - if(sh_isstate(SH_DEFPATH) || sh_isstate(SH_XARG)) + if(sh_isstate(SH_DEFPATH) || sh_isstate(SH_XARG) || sh_isstate(SH_EXEC)) return; if(!(np = nv_search(name,sh_subtracktree(1),NV_ADD|NV_NOSCOPE))) return; @@ -1781,6 +1806,7 @@ Namval_t *path_gettrackedalias(const char *name) Namval_t *np; if(!sh_isstate(SH_DEFPATH) && !sh_isstate(SH_XARG) + && !sh_isstate(SH_EXEC) && (np=nv_search(name,sh.track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp) diff --git a/src/cmd/ksh93/sh/shcomp.c b/src/cmd/ksh93/sh/shcomp.c index fcf120e140d2..3789f8a2bb2a 100644 --- a/src/cmd/ksh93/sh/shcomp.c +++ b/src/cmd/ksh93/sh/shcomp.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -212,7 +212,7 @@ int main(int argc, char *argv[]) } /* copy any remaining input */ if(!sfeof(in)) - sfmove(in,out,SF_UNBOUND,-1); + sfmove(in,out,SFIO_UNBOUND,-1); if(in!=sfstdin) sfclose(in); if(out!=sfstdout) diff --git a/src/cmd/ksh93/sh/streval.c b/src/cmd/ksh93/sh/streval.c index cfff4b39204b..79f75ee1402f 100644 --- a/src/cmd/ksh93/sh/streval.c +++ b/src/cmd/ksh93/sh/streval.c @@ -172,7 +172,7 @@ Sfdouble_t arith_exec(Arith_t *ep) if(ep->staksize < SMALL_STACK) sp = small_stack; else - sp = (Sfdouble_t*)stkalloc(sh.stk,ep->staksize*(sizeof(Sfdouble_t)+1)); + sp = stkalloc(sh.stk,ep->staksize*(sizeof(Sfdouble_t)+1)); tp = (char*)(sp+ep->staksize); tp--,sp--; while(c = *cp++) @@ -915,7 +915,7 @@ Arith_t *arith_compile(const char *string,char **last,Sfdouble_t(*fun)(const cha } sfputc(sh.stk,0); offset = stktell(sh.stk); - ep = (Arith_t*)stkfreeze(sh.stk,0); + ep = stkfreeze(sh.stk,0); ep->expr = string; ep->elen = strlen(string); ep->code = (unsigned char*)(ep+1); diff --git a/src/cmd/ksh93/sh/string.c b/src/cmd/ksh93/sh/string.c index 3db86b30ac0b..435845692256 100644 --- a/src/cmd/ksh93/sh/string.c +++ b/src/cmd/ksh93/sh/string.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -23,6 +23,7 @@ #include "shopt.h" #include #include +#include #include "defs.h" #include #include "shtable.h" @@ -306,10 +307,10 @@ static char *sh_fmtcsv(const char *string) */ static int sh_isprint(int c) { - if(!mbwide()) /* not in multibyte locale? */ + if(!mbwide() || ('a'==97 && c<=127)) /* not in multibyte locale, or multibyte but c is ASCII? */ return isprint(c); /* use plain isprint(3) */ - else if(c == ' ') /* optimisation: check ASCII space first */ - return 1; /* return true like isprint(3) */ + else if(!(lcinfo(LC_CTYPE)->lc->flags&LC_utf8)) /* not in UTF-8 locale? */ + return iswgraph(c); /* the test below would not be valid */ else if(iswgraph(0x5E38) && !iswgraph(0xFEFF)) /* can we use iswgraph(3)? */ return iswgraph(c); /* use iswgraph(3) */ else /* fallback: */ @@ -412,7 +413,7 @@ char *sh_fmtq(const char *string) if(mbwide()) { /* We're in a multibyte locale */ - if(c<0 || c<128 && !isprint(c)) + if(c<0 || ('a'!=97 || c<128) && !isprint(c)) { /* Invalid multibyte char, or unprintable ASCII char: quote as hex byte */ c = *((unsigned char *)op); diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index 344af33e7415..a6223117e603 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -108,7 +108,7 @@ static unsigned int subenv; */ void sh_subtmpfile(void) { - if(sfset(sfstdout,0,0)&SF_STRING) + if(sfset(sfstdout,0,0)&SFIO_STRING) { int fd; struct checkpt *pp = (struct checkpt*)sh.jmplist; @@ -126,7 +126,7 @@ void sh_subtmpfile(void) UNREACHABLE(); } /* popping a discipline forces a /tmp file create */ - sfdisc(sfstdout,SF_POPDISC); + sfdisc(sfstdout,SFIO_POPDISC); if((fd=sffileno(sfstdout))<0) { errormsg(SH_DICT,ERROR_SYSTEM|ERROR_PANIC,"could not create temp file"); @@ -143,8 +143,8 @@ void sh_subtmpfile(void) sh.fdstatus[fd] = IOCLOSE; } sh_iostream(1); - sfset(sfstdout,SF_SHARE|SF_PUBLIC,1); - sfpool(sfstdout,sh.outpool,SF_WRITE); + sfset(sfstdout,SFIO_SHARE|SFIO_PUBLIC,1); + sfpool(sfstdout,sh.outpool,SFIO_WRITE); if(pp && pp->olist && pp->olist->strm == sfstdout) pp->olist->strm = 0; } @@ -349,7 +349,7 @@ static void nv_restore(struct subshell *sp) } nv_setsize(mp,nv_size(np)); if(!(flags&NV_MINIMAL)) - mp->nvenv = np->nvenv; + mp->nvmeta = np->nvmeta; mp->nvfun = np->nvfun; if(np->nvfun && nofree) np->nvfun->nofree = nofree; @@ -613,7 +613,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) UNREACHABLE(); } sfswap(iop,sfstdout); - sfset(sfstdout,SF_READ,0); + sfset(sfstdout,SFIO_READ,0); sh.fdstatus[1] = IOWRITE; flags |= sh_state(SH_NOFORK); } @@ -726,7 +726,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) sh.fdstatus[fd] = (sh.fdstatus[1]|IOCLEX); sh.fdstatus[1] = IOCLOSE; } - sfset(iop,SF_READ,1); + sfset(iop,SFIO_READ,1); } if(sp->saveout) sfswap(sp->saveout,sfstdout); diff --git a/src/cmd/ksh93/sh/trestore.c b/src/cmd/ksh93/sh/trestore.c index e14146e862c5..5a58ddbf0a9a 100644 --- a/src/cmd/ksh93/sh/trestore.c +++ b/src/cmd/ksh93/sh/trestore.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -40,7 +40,7 @@ static void r_comarg(struct comnod*); static Sfio_t *infile; -#define getnode(type) ((Shnode_t*)stkalloc(sh.stk,sizeof(struct type))) +#define getnode(type) stkalloc(sh.stk,sizeof(struct type)) Shnode_t *sh_trestore(Sfio_t *in) { @@ -134,9 +134,9 @@ static Shnode_t *r_tree(void) t = getnode(functnod); t->funct.functline = sfgetu(infile); t->funct.functnam = r_string(); - savstak = stkopen(STK_SMALL); - savstak = stkinstall(savstak, 0); - slp = (struct slnod*)stkalloc(sh.stk,sizeof(struct slnod)+sizeof(struct functnod)); + savstak = sh.stk; + sh.stk = stkopen(STK_SMALL); + slp = stkalloc(sh.stk,sizeof(struct slnod)+sizeof(struct functnod)); slp->slchild = 0; slp->slnext = sh.st.staklist; sh.st.staklist = 0; @@ -148,7 +148,8 @@ static Shnode_t *r_tree(void) t->funct.functtre = r_tree(); t->funct.functstak = slp; t->funct.functargs = (struct comnod*)r_tree(); - slp->slptr = stkinstall(savstak,0); + slp->slptr = sh.stk; + sh.stk = savstak; slp->slchild = sh.st.staklist; break; } @@ -176,7 +177,7 @@ static struct argnod *r_arg(void) Stk_t *stkp=sh.stk; while((l=sfgetu(infile))>0) { - ap = (struct argnod*)stkseek(stkp,(unsigned)l+ARGVAL); + ap = stkseek(stkp,(unsigned)l+ARGVAL); if(!aptop) aptop = ap; else @@ -189,7 +190,7 @@ static struct argnod *r_arg(void) ap->argval[l] = 0; ap->argchn.cp = 0; ap->argflag = sfgetc(infile); - ap = (struct argnod*)stkfreeze(stkp,0); + ap = stkfreeze(stkp,0); if(*ap->argval==0 && (ap->argflag&ARG_EXP)) ap->argchn.ap = (struct argnod*)r_tree(); else if(*ap->argval==0 && (ap->argflag&~(ARG_APPEND|ARG_MESSAGE|ARG_QUOTED|ARG_ARRAY))==0) @@ -285,7 +286,7 @@ static struct dolnod *r_comlist(void) char **argv; if((l=sfgetl(infile))>0) { - dol = (struct dolnod*)stkalloc(sh.stk,sizeof(struct dolnod) + sizeof(char*)*(l+ARG_SPARE)); + dol = stkalloc(sh.stk,sizeof(struct dolnod) + sizeof(char*)*(l+ARG_SPARE)); dol->dolnum = l; dol->dolbot = ARG_SPARE; argv = dol->dolval+ARG_SPARE; @@ -300,7 +301,7 @@ static struct regnod *r_switch(void) struct regnod *reg=0,*regold,*regtop=0; while((l=sfgetl(infile))>=0) { - reg = (struct regnod*)getnode(regnod); + reg = getnode(regnod); if(!regtop) regtop = reg; else diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 1ee01bd6704d..aed2dc622fea 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -544,8 +544,8 @@ int sh_debug(const char *trap, const char *name, const char *subscript, char *co { Namval_t *np = SH_COMMANDNOD; int n=4, offset=stktell(sh.stk); - char *sav = stkfreeze(sh.stk,0); - struct sh_scoped *savst = (struct sh_scoped*)stkalloc(sh.stk,sizeof(struct sh_scoped)); + void *sav = stkfreeze(sh.stk,0); + struct sh_scoped *savst = stkalloc(sh.stk,sizeof(struct sh_scoped)); const char *cp = "+=( "; if(sh.indebug) return 0; @@ -612,7 +612,7 @@ int sh_eval(Sfio_t *iop, int mode) struct slnod *saveslp = sh.st.staklist; int jmpval; struct checkpt *pp = (struct checkpt*)sh.jmplist; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); static Sfio_t *io_save; volatile int traceon=0, lineno=0; int binscript=sh.binscript; @@ -717,7 +717,7 @@ static long set_instance(Namval_t *nq, Namval_t *node, struct Namref *nr) char *sp=0,*cp; Namarr_t *ap; Namval_t *np; - if(!nv_isattr(nq,NV_MINIMAL|NV_EXPORT|NV_ARRAY) && (np=(Namval_t*)nq->nvenv) && nv_isarray(np)) + if(!nv_isattr(nq,NV_MINIMAL|NV_EXPORT|NV_ARRAY) && (np = nq->nvmeta) && nv_isarray(np)) nq = np; cp = nv_name(nq); memset(nr,0,sizeof(*nr)); @@ -744,8 +744,8 @@ static long set_instance(Namval_t *nq, Namval_t *node, struct Namref *nr) memcpy(node,L_ARGNOD,sizeof(*node)); L_ARGNOD->nvalue.nrp = nr; L_ARGNOD->nvflag = NV_REF|NV_NOFREE; - L_ARGNOD->nvfun = 0; - L_ARGNOD->nvenv = 0; + L_ARGNOD->nvfun = NULL; + L_ARGNOD->nvmeta = NULL; if(sp) { nv_putval(SH_SUBSCRNOD,nr->sub=sp,NV_NOFREE); @@ -776,7 +776,7 @@ static void unset_instance(Namval_t *nq, Namval_t *node, struct Namref *nr,long savein = dup(0); if(fd==0) fd = savein; - sp = sfnew(NULL,NULL,SF_UNBOUND,fd,SF_READ); + sp = sfnew(NULL,NULL,SFIO_UNBOUND,fd,SFIO_READ); while(close(0)<0 && errno==EINTR) errno = err; open(e_devnull,O_RDONLY); @@ -865,15 +865,59 @@ static int check_exec_optimization(int type, int execflg, int execflg2, struct i */ int sh_exec(const Shnode_t *t, int flags) { + int type; + int mainloop; sh_sigcheck(); - if(t && sh.st.breakcnt==0 && !sh_isoption(SH_NOEXEC)) + /* Bail out on no command, break/continue, or noexec */ + if(!t || sh.st.breakcnt || sh_isoption(SH_NOEXEC)) + return sh.exitval; + /* Set up state */ + sh.exitval = 0; + sh.lastsig = 0; + sh.chldexitsig = 0; + type = t->tre.tretyp; + mainloop = (flags&sh_state(SH_INTERACTIVE)); + if(mainloop) + { + if(pipejob==2) + job_unlock(); + nlock = 0; + pipejob = 0; + job.curpgid = 0; + job.curjobid = 0; + flags &= ~sh_state(SH_INTERACTIVE); + } + /* Optimize a simple literal ':', 'true', 'false', 'break', 'continue' if the conditions are right */ + else if(type==TCOM && !sh.dont_optimize_builtins) /* no COMSCAN bit in 'type' => no expansions */ + { + Namval_t *np; + Shbltin_f fp; + if((np = (Namval_t*)t->com.comnamp) && (fp = funptr(np)) + && (fp==b_true || (fp==b_false && !sh_isoption(SH_ERREXIT) && !sh.st.trap[SH_ERRTRAP]) + || fp==b_break && t->com.comarg->argchn.len==1) /* for break/continue: 1 arg (command name) */ + && !t->com.comset /* no variable assignments list */ + && !t->com.comio /* no I/O redirections */ + && !sh_isoption(SH_XTRACE) + && !sh.st.trap[SH_DEBUGTRAP]) + { + /* Execute optimized basic versions of the builtins */ + if(fp==b_false) + ++sh.exitval; + else if(fp==b_break && sh.st.loopcnt) + sh.st.breakcnt = np==SYSCONT ? -1 : 1; + /* Set $?, possibly execute traps, and we're out of here */ + exitset(); + if(sh.trapnote) + sh_chktrap(); + return sh.exitval; + } + } + /* Normal command execution */ { - int type = t->tre.tretyp; char *com0 = 0; int errorflg = (flags&sh_state(SH_ERREXIT))|(flags & ARG_OPTIMIZE); int execflg = (flags&sh_state(SH_NOFORK)); int execflg2 = (flags&sh_state(SH_FORKED)); - int mainloop = (flags&sh_state(SH_INTERACTIVE)); int topfd = sh.topfd; char *sav=stkfreeze(sh.stk,0); char *cp=0, **com=0, *comn; @@ -883,22 +927,9 @@ int sh_exec(const Shnode_t *t, int flags) volatile int was_errexit = sh_isstate(SH_ERREXIT); volatile int was_monitor = sh_isstate(SH_MONITOR); volatile int echeck = 0; - if(flags&sh_state(SH_INTERACTIVE)) - { - if(pipejob==2) - job_unlock(); - nlock = 0; - pipejob = 0; - job.curpgid = 0; - job.curjobid = 0; - flags &= ~sh_state(SH_INTERACTIVE); - } sh_offstate(SH_DEFPATH); if(!(flags & sh_state(SH_ERREXIT))) sh_offstate(SH_ERREXIT); - sh.exitval=0; - sh.lastsig = 0; - sh.chldexitsig = 0; switch(type&COMMSK) { /* @@ -971,7 +1002,7 @@ int sh_exec(const Shnode_t *t, int flags) } if(com0) { - if((!np || !np->nvflag) && !strchr(com0,'/')) + if((!np || !np->nvflag) && !sh_isstate(SH_EXEC) && !strchr(com0,'/')) { Dt_t *root = command?sh.bltin_tree:sh.fun_tree; np = nv_bfsearch(com0, root, &nq, &cp); @@ -1050,14 +1081,18 @@ int sh_exec(const Shnode_t *t, int flags) else { /* avoid exit on error from nv_setlist, e.g. read-only variable */ - struct checkpt *chkp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *chkp = stkalloc(sh.stk,sizeof(struct checkpt)); sh_pushcontext(chkp,SH_JMPCMD); jmpval = sigsetjmp(chkp->buff,0); if(!jmpval) nv_setlist(argp,flgs,tp); sh_popcontext(chkp); if(jmpval) /* error occurred */ + { + if(jmpval>SH_JMPCMD) + siglongjmp(*sh.jmplist,jmpval); goto setexit; + } } if(np==sh.typeinit) sh.typeinit = 0; @@ -1119,7 +1154,7 @@ int sh_exec(const Shnode_t *t, int flags) } if(io) sfsync(sh.outpool); - if(!np) + if(!np && !sh_isstate(SH_EXEC)) { if(*com0 == '/' && !sh_isoption(SH_RESTRICTED)) { @@ -1157,17 +1192,23 @@ int sh_exec(const Shnode_t *t, int flags) /* check for builtins */ if(np && is_abuiltin(np)) { - volatile char scope=0, share=0, was_mktype=(sh.mktype!=NULL); - volatile void *save_ptr; - volatile void *save_data; - int save_prompt; - int was_nofork = execflg?sh_isstate(SH_NOFORK):0; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + volatile char scope, share, was_mktype, was_nofork; + volatile void *save_ptr; + volatile void *save_data; + int save_prompt; + struct checkpt *buffp; + /* Fallback optimization for ':'/'true' and 'false' */ + if(!io && !argp && (funptr(np)==b_true || funptr(np)==b_false && ++sh.exitval)) + goto setexit; + scope = 0, share = 0; + was_mktype = sh.mktype!=NULL; + was_nofork = execflg && sh_isstate(SH_NOFORK); bp = &sh.bltindata; save_ptr = bp->ptr; save_data = bp->data; if(execflg) sh_onstate(SH_NOFORK); + buffp = stkalloc(sh.stk,sizeof(struct checkpt)); sh_pushcontext(buffp,SH_JMPCMD); jmpval = sigsetjmp(buffp->buff,0); if(jmpval == 0) @@ -1199,10 +1240,10 @@ int sh_exec(const Shnode_t *t, int flags) if(!(nv_isattr(np,BLT_ENV))) { sfsync(NULL); - share = sfset(sfstdin,SF_SHARE,0); + share = sfset(sfstdin,SFIO_SHARE,0); sh_onstate(SH_STOPOK); - sfpool(sfstderr,NULL,SF_WRITE); - sfset(sfstderr,SF_LINE,1); + sfpool(sfstderr,NULL,SFIO_WRITE); + sfset(sfstderr,SFIO_LINE,1); save_prompt = sh.nextprompt; sh.nextprompt = 0; } @@ -1272,11 +1313,11 @@ int sh_exec(const Shnode_t *t, int flags) if(!(nv_isattr(np,BLT_ENV))) { sh_offstate(SH_STOPOK); - if(share&SF_SHARE) - sfset(sfstdin,SF_PUBLIC|SF_SHARE,1); - sfset(sfstderr,SF_LINE,0); - sfpool(sfstderr,sh.outpool,SF_WRITE); - sfpool(sfstdin,NULL,SF_WRITE); + if(share&SFIO_SHARE) + sfset(sfstdin,SFIO_PUBLIC|SFIO_SHARE,1); + sfset(sfstderr,SFIO_LINE,0); + sfpool(sfstderr,sh.outpool,SFIO_WRITE); + sfpool(sfstdin,NULL,SFIO_WRITE); sh.nextprompt = save_prompt; } sh_popcontext(buffp); @@ -1309,7 +1350,7 @@ int sh_exec(const Shnode_t *t, int flags) { volatile int indx; volatile char scope = 0; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); #if SHOPT_NAMESPACE Namval_t *namespace=0; #endif /* SHOPT_NAMESPACE */ @@ -1345,7 +1386,7 @@ int sh_exec(const Shnode_t *t, int flags) } } /* increase refcnt for unset */ - slp = (struct slnod*)np->nvenv; + slp = np->nvmeta; sh_funstaks(slp->slchild,1); if(slp->slptr) stklink(slp->slptr); @@ -1355,8 +1396,8 @@ int sh_exec(const Shnode_t *t, int flags) if(nv_isattr(np,NV_STATICF) && (mp=nv_type(nq))) nq = mp; sh.last_table = last_table; - nodep = (Namval_t*)stkalloc(sh.stk,sizeof(Namval_t)); - nrp = (struct Namref*)stkalloc(sh.stk,sizeof(struct Namref)); + nodep = stkalloc(sh.stk,sizeof(Namval_t)); + nrp = stkalloc(sh.stk,sizeof(struct Namref)); mode = set_instance(nq,nodep,nrp); } if(io) @@ -1529,7 +1570,7 @@ int sh_exec(const Shnode_t *t, int flags) */ { volatile int jmpval; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); struct ionod *iop; int rewrite=0; #if !SHOPT_DEVFD @@ -1671,7 +1712,7 @@ int sh_exec(const Shnode_t *t, int flags) pid_t pid = 0; int jmpval, waitall = 0; int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); if(sh.subshell && !sh.subshare && t->fork.forkio) { /* Subshell forking workaround for https://github.com/ksh93/ksh/issues/161 @@ -1701,7 +1742,7 @@ int sh_exec(const Shnode_t *t, int flags) * treat as non-shareable to improve performance */ if(simple) - sfset(sfstdin,SF_PUBLIC|SF_SHARE,0); + sfset(sfstdin,SFIO_PUBLIC|SFIO_SHARE,0); waitall = job.waitall; job.waitall = 0; pid = job.parent; @@ -1762,7 +1803,7 @@ int sh_exec(const Shnode_t *t, int flags) /* This is the last command, so avoid creating a subshell */ char *savsig; int nsig,jmpval; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); sh.st.otrapcom = 0; if((nsig=sh.st.trapmax*sizeof(char*))>0 || sh.st.trapcom[0]) { @@ -1823,7 +1864,7 @@ int sh_exec(const Shnode_t *t, int flags) job.curpgid = 0; while((tn=tn->lst.lstrit) && tn->tre.tretyp==TFIL) job.waitall++; - exitval = job.exitval = (int*)stkalloc(sh.stk,job.waitall*sizeof(int)); + exitval = job.exitval = stkalloc(sh.stk,job.waitall*sizeof(int)); memset(exitval,0,job.waitall*sizeof(int)); } else @@ -1952,7 +1993,7 @@ int sh_exec(const Shnode_t *t, int flags) char *av[5]; #if SHOPT_OPTIMIZE int jmpval = ((struct checkpt*)sh.jmplist)->mode; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); void *optlist = sh.optlist; sh.optlist = 0; sh_tclear(t->for_.fortre); @@ -2080,13 +2121,16 @@ int sh_exec(const Shnode_t *t, int flags) volatile int r=0; int first = ARG_OPTIMIZE; Shnode_t *tt = t->wh.whtre; + char always_true; + Namval_t *np; + Shbltin_f fp; #if SHOPT_FILESCAN Sfio_t *iop=0; int savein=-1; #endif /* SHOPT_FILESCAN */ #if SHOPT_OPTIMIZE int jmpval = ((struct checkpt*)sh.jmplist)->mode; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); void *optlist = sh.optlist; sh.optlist = 0; sh_tclear(t->wh.whtre); @@ -2110,18 +2154,27 @@ int sh_exec(const Shnode_t *t, int flags) iop = openstream(tt->com.comio,&savein); } #endif /* SHOPT_FILESCAN */ + /* Optimization: don't call sh_exec() for simple 'while :', 'while true' or 'until false' */ + always_true = (tt->tre.tretyp==TCOM /* one simple command (no COMSCAN = no expansions) */ + && !sh.dont_optimize_builtins + && (np = (Namval_t*)tt->com.comnamp) && (fp = funptr(np)) + && (type==TWH && fp==b_true || type==TUN && fp==b_false) + && !tt->com.comset /* no variable assignments list */ + && !tt->com.comio /* no I/O redirections */ + && !sh_isoption(SH_XTRACE) + && !sh.st.trap[SH_DEBUGTRAP]); sh.st.loopcnt++; while(sh.st.breakcnt==0) { #if SHOPT_FILESCAN if(iop) { - if(!(sh.cur_line=sfgetr(iop,'\n',SF_STRING))) + if(!(sh.cur_line=sfgetr(iop,'\n',SFIO_STRING))) break; } else #endif /* SHOPT_FILESCAN */ - if((sh_exec(tt,first)==0)!=(type==TWH)) + if(!always_true && (sh_exec(tt,first)==0)!=(type==TWH)) break; r = sh_exec(t->wh.dotre,first|errorflg); /* decrease 'continue' level */ @@ -2355,7 +2408,7 @@ int sh_exec(const Shnode_t *t, int flags) Namval_t *oldnspace = sh.namespace; int offset = stktell(sh.stk); int flags=NV_NOARRAY|NV_VARNAME; - struct checkpt *chkp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *chkp = stkalloc(sh.stk,sizeof(struct checkpt)); int jmpval; if(cp) { @@ -2390,7 +2443,6 @@ int sh_exec(const Shnode_t *t, int flags) #endif /* SHOPT_NAMESPACE */ /* look for discipline functions */ error_info.line = t->funct.functline-sh.st.firstline; - /* Function names cannot be special builtin */ if(cp || sh.prefix) { int offset = stktell(sh.stk); @@ -2412,10 +2464,15 @@ int sh_exec(const Shnode_t *t, int flags) sfprintf(sh.stk,"%s.%s%c",nv_name(npv),cp,0); fname = stkptr(sh.stk,offset); } - else if((mp=nv_search(fname,sh.bltin_tree,0)) && nv_isattr(mp,BLT_SPC)) + else if((mp=nv_search(fname,sh.bltin_tree,0))) { - errormsg(SH_DICT,ERROR_exit(1),e_badfun,fname); - UNREACHABLE(); + if(nv_isattr(mp,BLT_SPC)) + { /* Function names cannot be special builtin */ + errormsg(SH_DICT,ERROR_exit(1),e_badfun,fname); + UNREACHABLE(); + } + if(funptr(mp)==b_true || funptr(mp)==b_false || funptr(mp)==b_break) + sh.dont_optimize_builtins = 1; } #if SHOPT_NAMESPACE if(sh.namespace && !sh.prefix && *fname!='.') @@ -2436,7 +2493,7 @@ int sh_exec(const Shnode_t *t, int flags) if(np->nvalue.rp) { struct Ufunction *rp = np->nvalue.rp; - slp = (struct slnod*)np->nvenv; + slp = np->nvmeta; sh_funstaks(slp->slchild,-1); if(slp->slptr) { @@ -2481,7 +2538,7 @@ int sh_exec(const Shnode_t *t, int flags) sh_funstaks(slp->slchild,1); if(slp->slptr) stklink(slp->slptr); - np->nvenv = (char*)slp; + np->nvmeta = slp; nv_funtree(np) = (int*)(t->funct.functtre); np->nvalue.rp->lineno = t->funct.functline; np->nvalue.rp->nspace = sh.namespace; @@ -2654,15 +2711,15 @@ int sh_exec(const Shnode_t *t, int flags) int sh_run(int argn, char *argv[]) { struct dolnod *dp; - struct comnod *t = (struct comnod*)stkalloc(sh.stk,sizeof(struct comnod)); + struct comnod *t = stkalloc(sh.stk,sizeof(struct comnod)); int savtop = stktell(sh.stk); - char *savptr = stkfreeze(sh.stk,0); + void *savptr = stkfreeze(sh.stk,0); Opt_t *op, *np = optctx(0, 0); Shbltin_t bltindata; bltindata = sh.bltindata; op = optctx(np, 0); memset(t, 0, sizeof(struct comnod)); - dp = (struct dolnod*)stkalloc(sh.stk, (unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*)); + dp = stkalloc(sh.stk, (unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*)); dp->dolnum = argn; dp->dolbot = ARG_SPARE; memcpy(dp->dolval+ARG_SPARE, argv, (argn+1)*sizeof(char*)); @@ -2691,7 +2748,7 @@ int sh_trace(char *argv[], int nl) int decl = (nl&2); nl &= ~2; /* make this trace atomic */ - sfset(sfstderr,SF_SHARE|SF_PUBLIC,0); + sfset(sfstderr,SFIO_SHARE|SFIO_PUBLIC,0); if(!(cp=nv_getval(sh_scoped(PS4NOD)))) cp = "+ "; else @@ -2728,7 +2785,7 @@ int sh_trace(char *argv[], int nl) sfputr(sfstderr,cp,*argv?' ':nl); } } - sfset(sfstderr,SF_SHARE|SF_PUBLIC,1); + sfset(sfstderr,SFIO_SHARE|SFIO_PUBLIC,1); return 1; } return 0; @@ -2919,12 +2976,12 @@ Sfdouble_t sh_mathfun(void *fp, int nargs, Sfdouble_t *arg) np = (Namval_t*)fp; funenv.node = np; funenv.nref = nref; - funenv.env = 0; + funenv.env = NULL; memcpy(&node,SH_VALNOD,sizeof(node)); - SH_VALNOD->nvfun = 0; - SH_VALNOD->nvenv = 0; + SH_VALNOD->nvfun = NULL; + SH_VALNOD->nvmeta = NULL; SH_VALNOD->nvflag = NV_LDOUBLE|NV_NOFREE; - SH_VALNOD->nvalue.ldp = 0; + SH_VALNOD->nvalue.ldp = NULL; for(i=0; i < nargs; i++) { *nr++ = mp = nv_namptr(sh.mathnodes,i); @@ -2932,14 +2989,14 @@ Sfdouble_t sh_mathfun(void *fp, int nargs, Sfdouble_t *arg) } *nr = 0; SH_VALNOD->nvalue.ldp = &d; - argv[0] = np->nvname; - argv[1] = 0; + argv[0] = np->nvname; + argv[1] = NULL; sh_funscope(1,argv,0,&funenv,0); while(mp= *nr++) - mp->nvalue.ldp = 0; + mp->nvalue.ldp = NULL; SH_VALNOD->nvfun = node.nvfun; SH_VALNOD->nvflag = node.nvflag; - SH_VALNOD->nvenv = node.nvenv; + SH_VALNOD->nvmeta = node.nvmeta; SH_VALNOD->nvalue.ldp = node.nvalue.ldp; return d; } @@ -2954,7 +3011,7 @@ int sh_funscope(int argn, char *argv[],int(*fun)(void*),void *arg,int execflg) char *trap; int nsig; struct dolnod *argsav=0,*saveargfor; - struct sh_scoped *savst = (struct sh_scoped*)stkalloc(sh.stk,sizeof(struct sh_scoped)); + struct sh_scoped *savst = stkalloc(sh.stk,sizeof(struct sh_scoped)); struct sh_scoped *prevscope = sh.st.self; struct argnod *envlist=0; int isig,jmpval; @@ -2963,7 +3020,7 @@ int sh_funscope(int argn, char *argv[],int(*fun)(void*),void *arg,int execflg) char save_invoc_local; char **savsig, *save_debugtrap = 0; struct funenv *fp = 0; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); Namval_t *nspace = sh.namespace; Dt_t *last_root = sh.last_root; Shopt_t options; @@ -3218,7 +3275,7 @@ int sh_fun(Namval_t *np, Namval_t *nq, char *argv[]) if(nq) mode = set_instance(nq,&node, &nr); jmpthresh = is_abuiltin(np) ? SH_JMPCMD : SH_JMPFUN; - checkpoint = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + checkpoint = stkalloc(sh.stk,sizeof(struct checkpt)); sh_pushcontext(checkpoint, jmpthresh); jmpval = sigsetjmp(checkpoint->buff,1); if(jmpval == 0) @@ -3315,7 +3372,7 @@ static void sigreset(int mode) static pid_t sh_ntfork(const Shnode_t *t,char *argv[],int *jobid,int topfd) { static pid_t spawnpid; - struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt)); + struct checkpt *buffp = stkalloc(sh.stk,sizeof(struct checkpt)); int jmpval,jobfork=0; volatile int scope=0, sigwasset=0; char **arge, *path; diff --git a/src/cmd/ksh93/shell.3 b/src/cmd/ksh93/shell.3 index 18ca15bd744f..b0e3bf4ee7ed 100644 --- a/src/cmd/ksh93/shell.3 +++ b/src/cmd/ksh93/shell.3 @@ -408,7 +408,7 @@ The previous installed \f3sh_waitnotify()\fP function pointer is returned. The \f3sh_iogetiop()\fP function returns a pointer to the Sfio stream corresponding to file descriptor number \fIfd\fP and the given mode \fImode\fP. The mode can be either -\f3SF_READ\fP or \f3SF_WRITE\fP. +\f3SFIO_READ\fP or \f3SFIO_WRITE\fP. The \fIfd\fP argument can the number of an open file descriptor or one of the following symbolic constants: .IP diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 419419745c5e..d1434718c7f8 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -1692,5 +1692,10 @@ exp='\\ \\\\' [[ $got == "$exp" ]] || err_exit "printf '%b %1$s'" \ "(expected $(printf %q "$exp"), got $(printf %q "$got"))" +# ====== +case $(PATH=/opt/ast/bin:$PATH; exec cat '--???SECTION' 2>&1) in +1) err_exit "'exec' runs non-external command" ;; +esac + # ====== exit $((Errors<125?Errors:125)) diff --git a/src/cmd/ksh93/tests/coprocess.sh b/src/cmd/ksh93/tests/coprocess.sh index 18b524189a69..db8306fe3a09 100755 --- a/src/cmd/ksh93/tests/coprocess.sh +++ b/src/cmd/ksh93/tests/coprocess.sh @@ -156,7 +156,7 @@ do integer i for ((i = 1; i <= N; i++)) do print $i |& - sleep 0.01 + sleep 0.02 r=$r$($cat <&p) wait $! done diff --git a/src/cmd/ksh93/tests/subshell.sh b/src/cmd/ksh93/tests/subshell.sh index fb770612d0d7..3e4f259cc6b4 100755 --- a/src/cmd/ksh93/tests/subshell.sh +++ b/src/cmd/ksh93/tests/subshell.sh @@ -1195,5 +1195,17 @@ sleep_pid=$! "(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))" kill "$sleep_pid" 2>/dev/null +# ====== +unset x +exp=$'1\nx= 2' +got=$( + ((.sh.version <= 20210430)) && ulimit -c 0 # fork to stop 'exec' from ending whole script (see commit 88a1f3d6) + echo 1 + ( x=${ sh() { echo BADFUN; }; foo=BADOUTPUT exec sh -c 'echo $foo'; echo BADEXEC; } ) + echo x=$x 2 +) +[[ $got == "$exp" ]] || err_exit "incorrect result from 'exec' in subshare in subshell" \ + "(expected $(printf %q "$exp"), got $(printf %q "$got"))" + # ====== exit $((Errors<125?Errors:125)) diff --git a/src/cmd/ksh93/tests/types.sh b/src/cmd/ksh93/tests/types.sh index 944d51837427..ed8af512d2b3 100755 --- a/src/cmd/ksh93/tests/types.sh +++ b/src/cmd/ksh93/tests/types.sh @@ -673,7 +673,7 @@ exp=': trap: is a special shell builtin' # ====== # Bugs involving scripts without a #! path -# Hashbangless scripts are executed in a reinitialised fork of ksh, which is very bug-prone. +# Hashbangless scripts are executed in a reinitialised fork of ksh. # https://github.com/ksh93/ksh/issues/350 # Some of these fixed bugs don't involve types at all, but the tests need to go somewhere. # Plus, invoking these from an environment with a bunch of types defined is an additional test. diff --git a/src/cmd/ksh93/tests/variables.sh b/src/cmd/ksh93/tests/variables.sh index aaed3943d773..0f314351454b 100755 --- a/src/cmd/ksh93/tests/variables.sh +++ b/src/cmd/ksh93/tests/variables.sh @@ -905,6 +905,10 @@ $SHELL -c "$cmd" 2>/dev/null || err_exit "'$cmd' exit status $?, expected 0" SHLVL=1 level=$($SHELL -c $'$SHELL -c \'print -r "$SHLVL"\'') [[ $level == 3 ]] || err_exit "SHLVL should be 3 not $level" +echo 'print -r "$SHLVL"' >script +chmod +x script +level=$($SHELL -c '$SHELL ./script') +[[ $level == 3 ]] || err_exit "SHLVL should be 3 not $level" [[ $($SHELL -c '{ x=1; : ${x.};print ok;}' 2> /dev/null) == ok ]] || err_exit '${x.} where x is a simple variable causes shell to abort' diff --git a/src/lib/Mamfile b/src/lib/Mamfile index aae421ab2bce..ea55150f50f2 100644 --- a/src/lib/Mamfile +++ b/src/lib/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 make test virtual make install virtual diff --git a/src/lib/libast/Mamfile b/src/lib/libast/Mamfile index 276e92a40922..578d0a19472e 100644 --- a/src/lib/libast/Mamfile +++ b/src/lib/libast/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 setv INSTALLROOT ../../.. setv PACKAGEROOT ../../../../.. setv CC cc @@ -16,7 +16,7 @@ setv LDFLAGS note * note * iffe and cc invocations are mostly the same but some add custom flags; -note * set shim functions for brevity and "single source of truth" while still allowing this +note * set shim functions for brevity and "single source of truth" while allowing for variety in invocations note * shim - invoke_iffe() @@ -219,6 +219,63 @@ make install virtual exec - cp -f ${<} ${@} done + make ast_fs.h implicit + make FEATURE/fs implicit + prev features/fs + exec - invoke_iffe ${<} + done + exec - cp -f ${<} ${@} + done + + make ast_tty.h implicit + make FEATURE/tty implicit + prev features/tty + exec - invoke_iffe ${<} + done + exec - cp -f ${<} ${@} + done + + make ast_fcntl.h implicit + prev ast_fs.h + make FEATURE/fcntl + prev ast_fs.h + make features/fcntl.c + prev FEATURE/tty + prev FEATURE/fs + prev FEATURE/lib + prev FEATURE/standards + done + exec - invoke_iffe ${<} -I. -Icomp -Iinclude -Istd + done + exec - cp -f ${<} ${@} + done + + make ast_botch.h implicit + make FEATURE/botch + make features/botch.c + prev FEATURE/sys + prev FEATURE/lib + done + exec - invoke_iffe ${<} -I. -Icomp -Iinclude -Istd + done + exec - cp -f ${<} ${@} + done + + make ast_wchar.h implicit + make FEATURE/wchar + prev std/wctype.h implicit + prev std/stdio.h implicit + prev ast_common.h + make features/wchar + prev ast_common.h + done + exec - invoke_iffe ${<} + done + exec - cp -f ${<} ${@} + prev std/stdio.h + prev ast_common.h + done + note * note * Generate system library dependency information note * @@ -303,26 +360,39 @@ make install virtual exec - cp -f ${<} ${@} done ast_limits.h + note * note * Declare implicit header dependencies note * make include/ast.h implicit prev ast_api.h - prev include/vmalloc.h - prev include/sfio.h - prev include/ast_std.h implicit - done - - make include/vmalloc.h implicit - prev ast_common.h - prev include/ast_std.h - done - - make include/sfio.h implicit - prev include/sfio_s.h implicit - prev ast_common.h - prev include/ast_std.h + make include/ast_std.h + make include/regex.h implicit + prev ast_api.h + prev ast_wchar.h + prev ast_common.h + done + prev comp/getopt.h + prev ast_map.h + prev ast_botch.h + prev ast_limits.h + prev ast_fcntl.h + prev include/ast_getopt.h + prev ast_sys.h + prev ast_lib.h + prev ast_common.h + prev ast_standards.h + done include/ast_std.h + make include/sfio.h implicit + prev include/sfio_s.h implicit + prev ast_common.h + prev include/ast_std.h + done + make include/vmalloc.h implicit + prev ast_common.h + prev include/ast_std.h + done done prev dir/dirstd.h implicit @@ -341,29 +411,6 @@ make install virtual exec - cp -f ${<} ${@} done - make ast_fs.h implicit - make FEATURE/fs implicit - prev features/fs - exec - invoke_iffe ${<} - done - exec - cp -f ${<} ${@} - done - - make ast_wchar.h implicit - make FEATURE/wchar - prev std/wctype.h - prev std/stdio.h - prev ast_common.h - make features/wchar - prev ast_common.h - done - exec - invoke_iffe ${<} - done - exec - cp -f ${<} ${@} - prev std/stdio.h - prev ast_common.h - done - make ast_wctype.h implicit make FEATURE/wctype prev features/wctype @@ -376,62 +423,12 @@ make install virtual exec - cp -f ${<} ${@} done - make ast_botch.h implicit - make FEATURE/botch - make features/botch.c - prev FEATURE/sys - prev FEATURE/lib - done - exec - invoke_iffe ${<} -I. -Icomp -Iinclude -Istd - done - exec - cp -f ${<} ${@} - done - - make ast_tty.h implicit - make FEATURE/tty implicit - prev features/tty - exec - invoke_iffe ${<} - done - exec - cp -f ${<} ${@} - done - - make ast_fcntl.h implicit - prev ast_fs.h - make FEATURE/fcntl - prev ast_fs.h - make features/fcntl.c - prev FEATURE/tty - prev FEATURE/fs - prev FEATURE/lib - prev FEATURE/standards - done - exec - invoke_iffe ${<} -I. -Icomp -Iinclude -Istd - done - exec - cp -f ${<} ${@} - done - make ast_stdio.h implicit prev include/sfio_s.h prev include/ast_std.h make FEATURE/stdio prev include/sfio_s.h - make include/ast_std.h - make include/regex.h implicit - prev ast_api.h - prev ast_wchar.h - prev ast_common.h - done - prev comp/getopt.h - prev ast_map.h - prev ast_botch.h - prev ast_limits.h - prev ast_fcntl.h - prev include/ast_getopt.h - prev ast_sys.h - prev ast_lib.h - prev ast_common.h - prev ast_standards.h - done include/ast_std.h + prev include/ast_std.h prev features/stdio exec - invoke_iffe ${<} done FEATURE/stdio @@ -516,8 +513,9 @@ make install virtual prev include/ast.h prev port/lc.tab make lctab.c - prev port/lclang.h - prev port/lclib.h + make port/lclang.h implicit + prev include/ast_windows.h implicit + done make lcgen make port/lcgen.c prev std/stdio.h @@ -527,6 +525,18 @@ make install virtual exec - lcgen lc.h lctab.c < port/lc.tab done done + note * The following block was moved out of lc.h to resolve a circular dependency on lc.h. + note * We have to break the dependency loop somewhere: lctab.c depends on lclib.h but we cannot declare that here. + make port/lclib.h implicit + prev lc.h + make include/error.h implicit + make include/option.h implicit + prev include/ast.h + done + prev include/ast.h + done + prev include/ast.h + done make ast_ndbm.h implicit make FEATURE/ndbm implicit @@ -623,12 +633,7 @@ make install virtual prev dir/dirlib.h prev ast_lib.h done - make include/error.h implicit - make include/option.h implicit - prev include/ast.h - done - prev include/ast.h - done + prev include/error.h prev FEATURE/syscall prev include/ast.h done @@ -1048,13 +1053,9 @@ make install virtual make path/pathexists.c prev include/error.h prev include/ls.h - make port/lclib.h implicit - prev lc.h - prev include/error.h - prev include/ast.h - done + prev port/lclib.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make pathfind.o @@ -1197,7 +1198,7 @@ make install virtual prev features/prog exec - invoke_iffe ${<} done - prev include/ast_windows.h implicit + prev include/ast_windows.h prev include/ast.h done exec - compile ${<} @@ -1400,7 +1401,7 @@ make install virtual prev include/ccode.h prev port/lclib.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include -DERROR_CATALOG=\""libast"\" + exec - compile ${<} -Iport -DERROR_CATALOG=\""libast"\" done make errorf.o @@ -1421,14 +1422,14 @@ make install virtual make misc/errorx.c prev port/lclib.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make localeconv.o make comp/localeconv.c prev port/lclib.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make setlocale.o @@ -1444,7 +1445,7 @@ make install virtual prev port/lclib.h prev ast_standards.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make translate.o @@ -1457,7 +1458,7 @@ make install virtual prev include/cdt.h prev port/lclib.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make catopen.o @@ -1492,7 +1493,7 @@ make install virtual prev std/dirent.h prev include/ast.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make lc.o @@ -1501,17 +1502,15 @@ make install virtual prev features/locale exec - invoke_iffe ${<} done - make port/lclang.h implicit - prev include/ast_windows.h - done + prev port/lclang.h prev port/lclib.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make lctab.o prev lctab.c - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make mc.o @@ -1522,7 +1521,6 @@ make install virtual prev include/vmalloc.h prev std/iconv.h prev port/lclib.h - prev sfio/sfhdr.h make sfio/sfhdr.h implicit prev port/lclib.h prev std/wchar.h @@ -1543,7 +1541,7 @@ make install virtual done done done - exec - compile ${<} ${DEBUG+-DDEBUG=${DEBUG}} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} ${DEBUG+-DDEBUG=${DEBUG}} -Iport -Isfio done make base64.o @@ -1760,7 +1758,7 @@ make install virtual prev port/lclib.h prev include/ast.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make fmttmx.o @@ -2044,7 +2042,7 @@ make install virtual prev include/cdt.h prev include/ast.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make tmmake.o @@ -2265,47 +2263,6 @@ make install virtual exec - compile ${<} -Imisc done - make vecargs.o - make vec/vecargs.c - prev include/vecargs.h implicit - prev include/ast.h - done - exec - compile ${<} - done - - make vecfile.o - make vec/vecfile.c - prev include/vecargs.h - prev include/ls.h - prev include/ast.h - done - exec - compile ${<} - done - - make vecfree.o - make vec/vecfree.c - prev include/vecargs.h - prev include/ast.h - done - exec - compile ${<} - done - - make vecload.o - make vec/vecload.c - prev include/vecargs.h - prev include/ast.h - done - exec - compile ${<} - done - - make vecstring.o - make vec/vecstring.c - prev include/vecargs.h - prev include/ast.h - done - exec - compile ${<} - done - make univdata.o make misc/univdata.c prev misc/univlib.h @@ -2477,7 +2434,7 @@ make install virtual done prev include/ast.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make strtold.o @@ -2488,7 +2445,7 @@ make install virtual prev ast_lib.h prev ast_common.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make strtol.o @@ -2499,7 +2456,7 @@ make install virtual prev include/ast.h done done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strtoll.o @@ -2508,14 +2465,14 @@ make install virtual prev ast_map.h prev include/ast.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strtoul.o make comp/strtoul.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strtoull.o @@ -2524,21 +2481,21 @@ make install virtual prev ast_map.h prev include/ast.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strton.o make string/strton.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strtonll.o make string/strtonll.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strntod.o @@ -2546,7 +2503,7 @@ make install virtual prev sfio/sfstrtof.h prev include/ast.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make strntold.o @@ -2554,49 +2511,49 @@ make install virtual prev sfio/sfstrtof.h prev include/ast.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make strnton.o make string/strnton.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strntonll.o make string/strntonll.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strntol.o make string/strntol.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strntoll.o make string/strntoll.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strntoul.o make string/strntoul.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strntoull.o make string/strntoull.c prev string/strtoi.h done - exec - compile ${<} -Iport -Isfio -Istring -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istring done make strcasecmp.o @@ -2621,7 +2578,7 @@ make install virtual done prev port/lclib.h done - exec - compile ${<} -Iport -I${INSTALLROOT}/include + exec - compile ${<} -Iport done make mktemp.o @@ -2968,56 +2925,56 @@ make install virtual prev sfio/sfhdr.h done done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdcdos.o make disc/sfdcdos.c prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdcfilter.o make disc/sfdcfilter.c prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdcseekable.o make disc/sfdcseekable.c prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdcslow.o make disc/sfdcslow.c prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdcsubstr.o make disc/sfdcsubstr.c prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdctee.o make disc/sfdctee.c prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdcunion.o make disc/sfdcunion.c prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdcmore.o @@ -3025,14 +2982,14 @@ make install virtual prev ast_tty.h prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make sfdcprefix.o make disc/sfdcprefix.c prev disc/sfdchdr.h done - exec - compile ${<} -Idisc -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Idisc -Iport -Isfio done make wc.o @@ -3261,7 +3218,7 @@ make install virtual prev port/lclib.h prev regex/reglib.h done - exec - compile ${<} -Iport -Iregex -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Iregex done make regcache.o @@ -3371,84 +3328,84 @@ make install virtual done done done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtdisc.o make cdt/dtdisc.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dthash.o make cdt/dthash.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtlist.o make cdt/dtlist.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtmethod.o make cdt/dtmethod.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtopen.o make cdt/dtopen.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtstat.o make cdt/dtstat.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtstrhash.o make cdt/dtstrhash.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dttree.o make cdt/dttree.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtuser.o make cdt/dtuser.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtview.o make cdt/dtview.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtwalk.o make cdt/dtwalk.c prev cdt/dthdr.h done - exec - compile ${<} -Icdt -I${INSTALLROOT}/include/ast + exec - compile ${<} -Icdt done make dtnew.o @@ -3469,49 +3426,49 @@ make install virtual make sfio/sfclose.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfclrlock.o make sfio/sfclrlock.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfdisc.o make sfio/sfdisc.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfdlen.o make sfio/sfdlen.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfexcept.o make sfio/sfexcept.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfgetl.o make sfio/sfgetl.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfgetu.o make sfio/sfgetu.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfcvt.o @@ -3519,70 +3476,70 @@ make install virtual prev sfio/sfhdr.h prev FEATURE/standards done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfecvt.o make sfio/sfecvt.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sffcvt.o make sfio/sffcvt.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfextern.o make sfio/sfextern.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sffilbuf.o make sfio/sffilbuf.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfflsbuf.o make sfio/sfflsbuf.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfprints.o make sfio/sfprints.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfgetd.o make sfio/sfgetd.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfgetr.o make sfio/sfgetr.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfllen.o make sfio/sfllen.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfmode.o @@ -3591,70 +3548,70 @@ make install virtual prev sig.h prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfmove.o make sfio/sfmove.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfnew.o make sfio/sfnew.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfpkrd.o make sfio/sfpkrd.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfnotify.o make sfio/sfnotify.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfnputc.o make sfio/sfnputc.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfopen.o make sfio/sfopen.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfpeek.o make sfio/sfpeek.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfpoll.o make sfio/sfpoll.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfpool.o make sfio/sfpool.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfpopen.o @@ -3662,140 +3619,140 @@ make install virtual prev include/proc.h prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfprintf.o make sfio/sfprintf.c prev sfio/sfhdr.h done - exec - compile ${<} ${mam_cc_NOPROTECT} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} ${mam_cc_NOPROTECT} -Iport -Isfio done make sfputd.o make sfio/sfputd.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfputl.o make sfio/sfputl.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfputr.o make sfio/sfputr.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfputu.o make sfio/sfputu.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfrd.o make sfio/sfrd.c prev sfio/sfhdr.h done - exec - compile ${<} ${DEBUG+-DDEBUG=${DEBUG}} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} ${DEBUG+-DDEBUG=${DEBUG}} -Iport -Isfio done make sfread.o make sfio/sfread.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfreserve.o make sfio/sfreserve.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfscanf.o make sfio/sfscanf.c prev sfio/sfhdr.h done - exec - compile ${<} ${mam_cc_NOPROTECT} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} ${mam_cc_NOPROTECT} -Iport -Isfio done make sfseek.o make sfio/sfseek.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfset.o make sfio/sfset.c prev sfio/sfhdr.h done - exec - compile ${<} ${DEBUG+-DDEBUG=${DEBUG}} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} ${DEBUG+-DDEBUG=${DEBUG}} -Iport -Isfio done make sfsetbuf.o make sfio/sfsetbuf.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfsetfd.o make sfio/sfsetfd.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfsize.o make sfio/sfsize.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfsk.o make sfio/sfsk.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfstack.o make sfio/sfstack.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfstrtod.o make sfio/sfstrtod.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfsync.o make sfio/sfsync.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfswap.o make sfio/sfswap.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sftable.o @@ -3810,28 +3767,28 @@ make install virtual prev FEATURE/float prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sftell.o make sfio/sftell.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sftmp.o make sfio/sftmp.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfungetc.o make sfio/sfungetc.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfvprintf.o @@ -3839,7 +3796,7 @@ make install virtual prev include/ccode.h prev sfio/sfhdr.h done - exec - compile ${<} ${mam_cc_NOPROTECT} ${DEBUG+-DDEBUG=${DEBUG}} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} ${mam_cc_NOPROTECT} ${DEBUG+-DDEBUG=${DEBUG}} -Iport -Isfio done make sfvscanf.o @@ -3847,210 +3804,210 @@ make install virtual prev sfio/sfstrtof.h prev sfio/sfhdr.h done - exec - compile ${<} ${mam_cc_NOPROTECT} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} ${mam_cc_NOPROTECT} -Iport -Isfio done make sfwr.o make sfio/sfwr.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfwrite.o make sfio/sfwrite.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfpurge.o make sfio/sfpurge.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfraise.o make sfio/sfraise.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfwalk.o make sfio/sfwalk.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfgetm.o make sfio/sfgetm.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfputm.o make sfio/sfputm.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make sfresize.o make sfio/sfresize.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfclrerr.o make sfio/_sfclrerr.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfeof.o make sfio/_sfeof.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sferror.o make sfio/_sferror.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sffileno.o make sfio/_sffileno.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfopen.o make sfio/_sfopen.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfstacked.o make sfio/_sfstacked.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfvalue.o make sfio/_sfvalue.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfgetc.o make sfio/_sfgetc.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfgetl.o make sfio/_sfgetl.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfgetl2.o make sfio/_sfgetl2.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfgetu.o make sfio/_sfgetu.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfgetu2.o make sfio/_sfgetu2.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfdlen.o make sfio/_sfdlen.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfllen.o make sfio/_sfllen.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfslen.o make sfio/_sfslen.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfulen.o make sfio/_sfulen.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfputc.o make sfio/_sfputc.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfputd.o make sfio/_sfputd.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfputl.o make sfio/_sfputl.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfputm.o make sfio/_sfputm.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make _sfputu.o make sfio/_sfputu.c prev sfio/sfhdr.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make clearerr.o @@ -4061,427 +4018,420 @@ make install virtual prev ast_standards.h done done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fclose.o make stdio/fclose.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fdopen.o make stdio/fdopen.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fflush.o make stdio/fflush.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fgetc.o make stdio/fgetc.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fgetpos.o make stdio/fgetpos.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fgets.o make stdio/fgets.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fopen.o make stdio/fopen.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fprintf.o make stdio/fprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fpurge.o make stdio/fpurge.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fputs.o make stdio/fputs.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fread.o make stdio/fread.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make freopen.o make stdio/freopen.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fscanf.o make stdio/fscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fseek.o make stdio/fseek.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fseeko.o make stdio/fseeko.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fsetpos.o make stdio/fsetpos.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make ftell.o make stdio/ftell.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make ftello.o make stdio/ftello.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fwrite.o make stdio/fwrite.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make getw.o make stdio/getw.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make pclose.o make stdio/pclose.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make popen.o make stdio/popen.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make printf.o make stdio/printf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include - done - - make putchar.o - make stdio/putchar.c - prev stdio/stdhdr.h - done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make puts.o make stdio/puts.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make putw.o make stdio/putw.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make rewind.o make stdio/rewind.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make scanf.o make stdio/scanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make setbuf.o make stdio/setbuf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make setbuffer.o make stdio/setbuffer.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make setlinebuf.o make stdio/setlinebuf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make setvbuf.o make stdio/setvbuf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make snprintf.o make stdio/snprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make sprintf.o make stdio/sprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make sscanf.o make stdio/sscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make asprintf.o make stdio/asprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vasprintf.o make stdio/vasprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make tmpfile.o make stdio/tmpfile.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make ungetc.o make stdio/ungetc.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vfprintf.o make stdio/vfprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vfscanf.o make stdio/vfscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vprintf.o make stdio/vprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vscanf.o make stdio/vscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vsnprintf.o make stdio/vsnprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vsprintf.o make stdio/vsprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vsscanf.o make stdio/vsscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _doprnt.o make stdio/_doprnt.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _doscan.o make stdio/_doscan.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _filbuf.o make stdio/_filbuf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _flsbuf.o make stdio/_flsbuf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _stdopen.o make stdio/_stdopen.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _stdprintf.o make stdio/_stdprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _stdscanf.o make stdio/_stdscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _stdsprnt.o make stdio/_stdsprnt.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _stdvbuf.o make stdio/_stdvbuf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _stdvsnprnt.o make stdio/_stdvsnprnt.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _stdvsprnt.o make stdio/_stdvsprnt.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make _stdvsscn.o make stdio/_stdvsscn.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fgetwc.o make stdio/fgetwc.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fwprintf.o make stdio/fwprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make putwchar.o @@ -4489,63 +4439,63 @@ make install virtual prev ast_wchar.h prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vfwscanf.o make stdio/vfwscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make wprintf.o make stdio/wprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fgetws.o make stdio/fgetws.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fwscanf.o make stdio/fwscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make swprintf.o make stdio/swprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vswprintf.o make stdio/vswprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make wscanf.o make stdio/wscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fputwc.o make stdio/fputwc.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make getwc.o @@ -4553,28 +4503,28 @@ make install virtual prev ast_wchar.h prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make swscanf.o make stdio/swscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vswscanf.o make stdio/vswscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fputws.o make stdio/fputws.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make getwchar.o @@ -4582,28 +4532,28 @@ make install virtual prev ast_wchar.h prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make ungetwc.o make stdio/ungetwc.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vwprintf.o make stdio/vwprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fwide.o make stdio/fwide.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make putwc.o @@ -4611,56 +4561,56 @@ make install virtual prev ast_wchar.h prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vfwprintf.o make stdio/vfwprintf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make vwscanf.o make stdio/vwscanf.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make stdio_c99.o make stdio/stdio_c99.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fcloseall.o make stdio/fcloseall.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make fmemopen.o make stdio/fmemopen.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make getdelim.o make stdio/getdelim.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make getline.o make stdio/getline.c prev stdio/stdhdr.h done - exec - compile ${<} -Iport -Isfio -Istdio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio -Istdio done make frexp.o @@ -4712,7 +4662,7 @@ make install virtual prev include/ast.h prev include/sfio_t.h done - exec - compile ${<} -Iport -Isfio -I${INSTALLROOT}/include + exec - compile ${<} -Iport -Isfio done make astquery.o @@ -4998,8 +4948,6 @@ make install virtual note * pre-install libast in $INSTALLROOT note * - prev libast.a - note * ensure preinstallation directories exist loop DIR include/ast lib/lib lib/file man/man3 make ${INSTALLROOT}/${DIR} @@ -5019,7 +4967,7 @@ make install virtual done note * section 3 manual pages - loop SECT3MAN LIBAST aso ast cdt chr compat error find fmt fmtls ftwalk getcwd hash iblocks int ip6 magic mem mime modecanon optget path proc re regex setenviron sfio sig spawnveg stk strcopy strdup strelapsed strerror stresc streval strgid strmatch stropt strperm strsignal strsort strtape strton struid swap tab tm tmx tok touch tv vecargs vmalloc + loop SECT3MAN LIBAST aso ast cdt chr compat error find fmt fmtls ftwalk getcwd hash iblocks int ip6 magic mem mime modecanon optget path proc re regex setenviron sfio sig spawnveg stk strcopy strdup strelapsed strerror stresc streval strgid strmatch stropt strperm strsignal strsort strtape strton struid swap tab tm tmx tok touch tv vmalloc make ${INSTALLROOT}/man/man3/${SECT3MAN}.3 prev man/${SECT3MAN}.3 exec - cp -f ${<} ${@} @@ -5035,7 +4983,7 @@ make install virtual done done note * ...main AST headers - loop HDR ast ast_dir ast_getopt ast_std ast_windows ccode cdt cmdarg debug dt error find ftwalk fts glob hash hashkey hashpart ip6 ls magic mc mime mnt modecanon modex namval option proc recfmt regex sfio sfio_s sfio_t sfdisc shcmd stk swap tar times tm tok usage vdb vecargs vmalloc wait magicid fnv aso + loop HDR ast ast_dir ast_getopt ast_std ast_windows ccode cdt cmdarg debug dt error find ftwalk fts glob hash hashkey hashpart ip6 ls magic mc mime mnt modecanon modex namval option proc recfmt regex sfio sfio_s sfio_t sfdisc shcmd stk stak swap tar times tm tok usage vdb vmalloc wait magicid fnv aso make ${INSTALLROOT}/include/ast/${HDR}.h prev include/${HDR}.h exec - cp -f ${<} ${@} diff --git a/src/lib/libast/comp/conf.tab b/src/lib/libast/comp/conf.tab index 0d2430711b55..bf59ba1a81a2 100644 --- a/src/lib/libast/comp/conf.tab +++ b/src/lib/libast/comp/conf.tab @@ -473,7 +473,7 @@ SEMAPHORES POSIX SC 1 CDFUW SEM_NSEMS_MAX POSIX SC 1 LMU 256 SEM_VALUE_MAX POSIX SC 1 LMU 32767 SF_BUFSIZE AST XX 1 MUX sh{ - sed -e '/[ ]*#[ ]*define[ ][ ]*SF_BUFSIZE[ ]/!d' -e 's/^[^0-9]*//' -e 's/[^0-9]*$//' $PACKAGEROOT/src/lib/libast/include/sfio.h + sed -e '/[ ]*#[ ]*define[ ][ ]*SFIO_BUFSIZE[ ]/!d' -e 's/^[^0-9]*//' -e 's/[^0-9]*$//' $PACKAGEROOT/src/lib/libast/include/sfio.h } SH AST CS 1 MU sh{ ifs=$IFS diff --git a/src/lib/libast/comp/iconv.c b/src/lib/libast/comp/iconv.c index 8290d7e33e62..54917fe81eb8 100644 --- a/src/lib/libast/comp/iconv.c +++ b/src/lib/libast/comp/iconv.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -987,7 +987,7 @@ _ast_iconv(_ast_iconv_t cd, char** fb, size_t* fn, char** tb, size_t* tn) { if (cc->to.fun) { - if (!cc->buf && !(cc->buf = oldof(0, char, cc->size = SF_BUFSIZE, 0))) + if (!cc->buf && !(cc->buf = oldof(0, char, cc->size = SFIO_BUFSIZE, 0))) { errno = ENOMEM; return -1; @@ -1021,7 +1021,7 @@ _ast_iconv(_ast_iconv_t cd, char** fb, size_t* fn, char** tb, size_t* tn) { if (!(m = cc->from.map)) return (*cc->to.fun)(cc->cvt, fb, fn, tb, tn); - if (!cc->buf && !(cc->buf = oldof(0, char, cc->size = SF_BUFSIZE, 0))) + if (!cc->buf && !(cc->buf = oldof(0, char, cc->size = SFIO_BUFSIZE, 0))) { errno = ENOMEM; return -1; @@ -1094,7 +1094,7 @@ _ast_iconv_write(_ast_iconv_t cd, Sfio_t* op, char** fb, size_t* fn, Iconv_disc_ ok = 1; while (ok && *fn > 0) { - if (!(tb = (char*)sfreserve(op, -(tn + 1), SF_WRITE|SF_LOCKR)) || !(tn = sfvalue(op))) + if (!(tb = (char*)sfreserve(op, -(tn + 1), SFIO_WRITE|SFIO_LOCKR)) || !(tn = sfvalue(op))) { if (!r) r = -1; @@ -1197,14 +1197,14 @@ _ast_iconv_move(_ast_iconv_t cd, Sfio_t* ip, Sfio_t* op, size_t n, Iconv_disc_t* fn = n; do { - if (n != SF_UNBOUND) + if (n != SFIO_UNBOUND) n = -((ssize_t)(n & (((size_t)(~0))>>1))); - if ((!(fb = (char*)sfreserve(ip, n, locked = SF_LOCKR)) || !(fo = sfvalue(ip))) && + if ((!(fb = (char*)sfreserve(ip, n, locked = SFIO_LOCKR)) || !(fo = sfvalue(ip))) && (!(fb = (char*)sfreserve(ip, n, locked = 0)) || !(fo = sfvalue(ip)))) break; fs = fb; fn = fo; - if (!(tb = (char*)sfreserve(op, SF_UNBOUND, SF_WRITE|SF_LOCKR))) + if (!(tb = (char*)sfreserve(op, SFIO_UNBOUND, SFIO_WRITE|SFIO_LOCKR))) { if (!r) r = -1; @@ -1257,7 +1257,7 @@ _ast_iconv_move(_ast_iconv_t cd, Sfio_t* ip, Sfio_t* op, size_t n, Iconv_disc_t* else for (i = fn; --i >= (fs - fb);) sfungetc(ip, fb[i]); - if (n != SF_UNBOUND) + if (n != SFIO_UNBOUND) { if (n <= (fs - fb)) break; diff --git a/src/lib/libast/comp/spawnveg.c b/src/lib/libast/comp/spawnveg.c index ef759caec667..f4efe46791cf 100644 --- a/src/lib/libast/comp/spawnveg.c +++ b/src/lib/libast/comp/spawnveg.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -205,13 +205,8 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, i pgid = getpid(); if (setpgid(0, pgid) < 0 && errno == EPERM) setpgid(pgid, 0); -#if _lib_tcgetpgrp if (m) tcsetpgrp(2, pgid); -#elif defined(TIOCSPGRP) - if (m) - ioctl(2, TIOCSPGRP, &pgid); -#endif /* _lib_tcgetpgrp */ } execve(path, argv, envv); if (err[0] != -1) diff --git a/src/lib/libast/disc/sfdcdio.c b/src/lib/libast/disc/sfdcdio.c index 8e83e7dbe7f1..515e16af44a3 100644 --- a/src/lib/libast/disc/sfdcdio.c +++ b/src/lib/libast/disc/sfdcdio.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -63,7 +63,7 @@ static ssize_t diordwr(Sfio_t* f, void* buf, size_t n, Direct_t* di, int type) if((io = rw) > di->dio.d_maxiosz ) io = di->dio.d_maxiosz; - if(type == SF_READ) + if(type == SFIO_READ) rv = read(f->file,buf,io); else rv = write(f->file,buf,io); @@ -84,7 +84,7 @@ static ssize_t diordwr(Sfio_t* f, void* buf, size_t n, Direct_t* di, int type) } if((rw = n-done) > 0 && - (rv = type == SF_READ ? read(f->file,buf,rw) : write(f->file,buf,rw)) > 0 ) + (rv = type == SFIO_READ ? read(f->file,buf,rw) : write(f->file,buf,rw)) > 0 ) done += rv; return done ? done : rv; @@ -92,19 +92,19 @@ static ssize_t diordwr(Sfio_t* f, void* buf, size_t n, Direct_t* di, int type) static ssize_t dioread(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) { - return diordwr(f, buf, n, (Direct_t*)disc, SF_READ); + return diordwr(f, buf, n, (Direct_t*)disc, SFIO_READ); } static ssize_t diowrite(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) { - return diordwr(f, buf, n, (Direct_t*)disc, SF_WRITE); + return diordwr(f, buf, n, (Direct_t*)disc, SFIO_WRITE); } static int dioexcept(Sfio_t* f, int type, void* data, Sfdisc_t* disc) { Direct_t* di = (Direct_t*)disc; - if(type == SF_FINAL || type == SF_DPOP) + if(type == SFIO_FINAL || type == SFIO_DPOP) { if(di->cntl&FDIRECT) { di->cntl &= ~FDIRECT; @@ -128,7 +128,7 @@ int sfdcdio(Sfio_t* f, size_t bufsize) void* buf; Direct_t* di; - if(f->extent < 0 || (f->flags&SF_STRING)) + if(f->extent < 0 || (f->flags&SFIO_STRING)) return -1; if((cntl = fcntl(f->file,F_GETFL,0)) < 0) @@ -160,7 +160,7 @@ int sfdcdio(Sfio_t* f, size_t bufsize) sfsetbuf(f,buf,bufsize); if(sfsetbuf(f,buf,0) == buf) - sfset(f,SF_MALLOC,1); + sfset(f,SFIO_MALLOC,1); else { free(buf); free(di); diff --git a/src/lib/libast/disc/sfdcdos.c b/src/lib/libast/disc/sfdcdos.c index d63b91852194..33a5e57164f9 100644 --- a/src/lib/libast/disc/sfdcdos.c +++ b/src/lib/libast/disc/sfdcdos.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -327,7 +327,7 @@ static Sfoff_t dos_seek(Sfio_t *iop, Sfoff_t offset, int whence, Sfdisc_t* disc) static int dos_except(Sfio_t *iop, int type, void *arg, Sfdisc_t *disc) { Dosdisc_t *dp = (Dosdisc_t*)disc; - if(type==SF_DPOP || type==SF_FINAL) + if(type==SFIO_DPOP || type==SFIO_FINAL) { if(dp->bsize>0) free(dp->buff); @@ -343,7 +343,7 @@ int sfdcdos(Sfio_t *f) Dosdisc_t *dos; /* this is a readonly discipline */ - if(sfset(f,0,0)&SF_WRITE) + if(sfset(f,0,0)&SFIO_WRITE) return -1; if(!(dos = (Dosdisc_t*)malloc(sizeof(Dosdisc_t))) ) diff --git a/src/lib/libast/disc/sfdcfilter.c b/src/lib/libast/disc/sfdcfilter.c index f27d7f2acdd8..1c4f21cf0581 100644 --- a/src/lib/libast/disc/sfdcfilter.c +++ b/src/lib/libast/disc/sfdcfilter.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -52,18 +52,18 @@ static ssize_t filterread(Sfio_t* f, /* stream reading from */ } else { /* eof, close write end of pipes */ - sfset(fi->filter,SF_READ,0); + sfset(fi->filter,SFIO_READ,0); close(sffileno(fi->filter)); - sfset(fi->filter,SF_READ,1); + sfset(fi->filter,SFIO_READ,1); fi->next = fi->endb = NULL; } } if(fi->next && (w = fi->endb - fi->next) > 0 ) { /* see if pipe is ready for write */ - sfset(fi->filter, SF_READ, 0); + sfset(fi->filter, SFIO_READ, 0); r = sfpoll(&fi->filter, 1, 1); - sfset(fi->filter, SF_READ, 1); + sfset(fi->filter, SFIO_READ, 1); if(r == 1) /* non-blocking write */ { errno = 0; @@ -75,9 +75,9 @@ static ssize_t filterread(Sfio_t* f, /* stream reading from */ } /* see if pipe is ready for read */ - sfset(fi->filter, SF_WRITE, 0); + sfset(fi->filter, SFIO_WRITE, 0); w = sfpoll(&fi->filter, 1, fi->next ? 1 : -1); - sfset(fi->filter, SF_WRITE, 1); + sfset(fi->filter, SFIO_WRITE, 1); if(!fi->next || w == 1) /* non-blocking read */ { errno = 0; @@ -109,7 +109,7 @@ static Sfoff_t filterseek(Sfio_t* f, Sfoff_t addr, int offset, Sfdisc_t* disc) /* on close, remove the discipline */ static int filterexcept(Sfio_t* f, int type, void* data, Sfdisc_t* disc) { - if(type == SF_FINAL || type == SF_DPOP) + if(type == SFIO_FINAL || type == SFIO_DPOP) { sfclose(((Filter_t*)disc)->filter); free(disc); } diff --git a/src/lib/libast/disc/sfdcmore.c b/src/lib/libast/disc/sfdcmore.c index 53ad6ce247ce..17cc95aacb4a 100644 --- a/src/lib/libast/disc/sfdcmore.c +++ b/src/lib/libast/disc/sfdcmore.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -232,22 +232,22 @@ static int moreexcept(Sfio_t* f, int type, void* data, Sfdisc_t* dp) { More_t* more = (More_t*)dp; - if (type == SF_FINAL || type == SF_DPOP) + if (type == SFIO_FINAL || type == SFIO_DPOP) { if (f = more->input) { more->input = 0; - sfdisc(f, SF_POPDISC); + sfdisc(f, SFIO_POPDISC); } else if (f = more->error) { more->error = 0; - sfdisc(f, SF_POPDISC); + sfdisc(f, SFIO_POPDISC); } else free(dp); } - else if (type == SF_SYNC) + else if (type == SFIO_SYNC) { more->match = 0; more->row = 1; @@ -272,7 +272,7 @@ int sfdcmore(Sfio_t* f, const char* prompt, int rows, int cols) * this is a writeonly discipline for interactive io */ - if (!(sfset(f, 0, 0) & SF_WRITE) || !isatty(sffileno(sfstdin)) || !isatty(sffileno(sfstdout))) + if (!(sfset(f, 0, 0) & SFIO_WRITE) || !isatty(sffileno(sfstdin)) || !isatty(sffileno(sfstdout))) return -1; if (!prompt) prompt = "\033[7m More\033[m"; @@ -307,13 +307,13 @@ int sfdcmore(Sfio_t* f, const char* prompt, int rows, int cols) { if (sfdisc(sfstdin, &more->disc) != &more->disc) { - sfdisc(f, SF_POPDISC); + sfdisc(f, SFIO_POPDISC); return -1; } more->input = sfstdin; if (sfdisc(sfstderr, &more->disc) != &more->disc) { - sfdisc(f, SF_POPDISC); + sfdisc(f, SFIO_POPDISC); return -1; } more->error = sfstdin; diff --git a/src/lib/libast/disc/sfdcprefix.c b/src/lib/libast/disc/sfdcprefix.c index a120ab2bd011..45ef11df596e 100644 --- a/src/lib/libast/disc/sfdcprefix.c +++ b/src/lib/libast/disc/sfdcprefix.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -81,7 +81,7 @@ static ssize_t pfxwrite(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* dp) static int pfxexcept(Sfio_t* f, int type, void* data, Sfdisc_t* dp) { - if (type == SF_FINAL || type == SF_DPOP) + if (type == SFIO_FINAL || type == SFIO_DPOP) free(dp); return 0; } @@ -100,7 +100,7 @@ int sfdcprefix(Sfio_t* f, const char* prefix) * this is a writeonly discipline */ - if (!prefix || !(n = strlen(prefix)) || !(sfset(f, 0, 0) & SF_WRITE)) + if (!prefix || !(n = strlen(prefix)) || !(sfset(f, 0, 0) & SFIO_WRITE)) return -1; if (!(pfx = (Prefix_t*)malloc(sizeof(Prefix_t) + n))) return -1; diff --git a/src/lib/libast/disc/sfdcseekable.c b/src/lib/libast/disc/sfdcseekable.c index ff42bf5cb046..a0c734fb711e 100644 --- a/src/lib/libast/disc/sfdcseekable.c +++ b/src/lib/libast/disc/sfdcseekable.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -89,7 +89,7 @@ static Sfoff_t skseek(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) { Seek_t* sk; Sfio_t* sf; - char buf[SF_BUFSIZE]; + char buf[SFIO_BUFSIZE]; ssize_t r, w; sk = (Seek_t*)disc; @@ -147,8 +147,8 @@ static int skexcept(Sfio_t* f, int type, void* data, Sfdisc_t* disc) switch (type) { - case SF_FINAL: - case SF_DPOP: + case SFIO_FINAL: + case SFIO_DPOP: sfclose(sk->shadow); free(disc); break; @@ -178,7 +178,7 @@ int sfdcseekable(Sfio_t* f) sk->disc.writef = skwrite; sk->disc.seekf = skseek; sk->disc.exceptf = skexcept; - sk->shadow = sftmp(SF_BUFSIZE); + sk->shadow = sftmp(SFIO_BUFSIZE); sk->discard = 0; sk->extent = 0; sk->eof = 0; diff --git a/src/lib/libast/disc/sfdcslow.c b/src/lib/libast/disc/sfdcslow.c index 79db843f0ec3..c46e768b8d11 100644 --- a/src/lib/libast/disc/sfdcslow.c +++ b/src/lib/libast/disc/sfdcslow.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -33,12 +33,12 @@ static int slowexcept(Sfio_t* f, int type, void* v, Sfdisc_t* disc) switch (type) { - case SF_FINAL: - case SF_DPOP: + case SFIO_FINAL: + case SFIO_DPOP: free(disc); break; - case SF_READ: - case SF_WRITE: + case SFIO_READ: + case SFIO_WRITE: if (errno == EINTR) return -1; break; @@ -63,7 +63,7 @@ int sfdcslow(Sfio_t* f) { free(disc); return -1; } - sfset(f,SF_IOINTR,1); + sfset(f,SFIO_IOINTR,1); return 0; } diff --git a/src/lib/libast/disc/sfdcsubstr.c b/src/lib/libast/disc/sfdcsubstr.c index 07a0d694651c..2bcbfa146207 100644 --- a/src/lib/libast/disc/sfdcsubstr.c +++ b/src/lib/libast/disc/sfdcsubstr.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -57,7 +57,7 @@ static ssize_t streamio(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc, int type if(sfsk(f,here,SEEK_SET,disc) != here) io = 0; else - { if(type == SF_WRITE) + { if(type == SFIO_WRITE) io = sfwr(f,buf,n,disc); else io = sfrd(f,buf,n,disc); if(io > 0) @@ -72,12 +72,12 @@ static ssize_t streamio(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc, int type static ssize_t streamwrite(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) { - return streamio(f,(void*)buf,n,disc,SF_WRITE); + return streamio(f,(void*)buf,n,disc,SFIO_WRITE); } static ssize_t streamread(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) { - return streamio(f,buf,n,disc,SF_READ); + return streamio(f,buf,n,disc,SFIO_READ); } static Sfoff_t streamseek(Sfio_t* f, Sfoff_t pos, int type, Sfdisc_t* disc) @@ -119,7 +119,7 @@ static Sfoff_t streamseek(Sfio_t* f, Sfoff_t pos, int type, Sfdisc_t* disc) static int streamexcept(Sfio_t* f, int type, void* data, Sfdisc_t* disc) { - if(type == SF_FINAL || type == SF_DPOP) + if(type == SFIO_FINAL || type == SFIO_DPOP) free(disc); return 0; } @@ -139,7 +139,7 @@ Sfio_t* sfdcsubstream(Sfio_t* f, /* stream */ else sfseek(parent,here,SEEK_SET); sfpurge(parent); - if (!(sp = f) && !(sp = sfnew(NULL, NULL, (size_t)SF_UNBOUND, dup(sffileno(parent)), parent->flags))) + if (!(sp = f) && !(sp = sfnew(NULL, NULL, (size_t)SFIO_UNBOUND, dup(sffileno(parent)), parent->flags))) return NULL; if(!(su = (Subfile_t*)malloc(sizeof(Subfile_t)))) diff --git a/src/lib/libast/disc/sfdctee.c b/src/lib/libast/disc/sfdctee.c index 5172c7e2ab9e..9e700b6419f1 100644 --- a/src/lib/libast/disc/sfdctee.c +++ b/src/lib/libast/disc/sfdctee.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -51,7 +51,7 @@ static ssize_t teewrite(Sfio_t* f, /* the stream being written to */ /* on close, remove the discipline */ static int teeexcept(Sfio_t* f, int type, void* data, Sfdisc_t* disc) { - if(type == SF_FINAL || type == SF_DPOP) + if(type == SFIO_FINAL || type == SFIO_DPOP) free(disc); return 0; diff --git a/src/lib/libast/disc/sfdcunion.c b/src/lib/libast/disc/sfdcunion.c index 2d476787618a..52979175bb04 100644 --- a/src/lib/libast/disc/sfdcunion.c +++ b/src/lib/libast/disc/sfdcunion.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -125,7 +125,7 @@ static Sfoff_t unseek(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) /* on close, remove the discipline */ static int unexcept(Sfio_t* f, int type, void* data, Sfdisc_t* disc) { - if(type == SF_FINAL || type == SF_DPOP) + if(type == SFIO_FINAL || type == SFIO_DPOP) free(disc); return 0; diff --git a/src/lib/libast/features/api b/src/lib/libast/features/api index 824e4ad2f16a..e2a6840607a6 100644 --- a/src/lib/libast/features/api +++ b/src/lib/libast/features/api @@ -1,6 +1,6 @@ iff AST_API -ver ast 20240121 +ver ast 20240303 api ast 20120528 regexec regnexec regrexec regsubexec diff --git a/src/lib/libast/features/common b/src/lib/libast/features/common index 1867109615b9..4195db15fb6b 100644 --- a/src/lib/libast/features/common +++ b/src/lib/libast/features/common @@ -4,8 +4,6 @@ sys types typ long.double,size_t,ssize_t typ __va_list stdio.h -mac SF_APPEND,SF_CLOSE sys/stat.h sys/socket.h - std noreturn note{ noreturn ok }end compile{ #include #include @@ -259,7 +257,7 @@ tst - output{ "pointer", sizeof(void*), COND * 4, "float", sizeof(float), 0, "double", sizeof(double), 0, - #ifdef _typ_long_double + #if _typ_long_double "long_double", sizeof(long double), 0, #endif }; @@ -310,7 +308,7 @@ tst - -DN=1 - -DN=0 output{ { "float", sizeof(float), "double", sizeof(double), - #ifdef _typ_long_double + #if _typ_long_double "long double", sizeof(long double), #endif }; @@ -321,7 +319,7 @@ tst - -DN=1 - -DN=0 output{ int t; int m = 1; - #ifdef _typ_long_double + #if _typ_long_double long double p; char buf[64]; diff --git a/src/lib/libast/features/sfio b/src/lib/libast/features/sfio index 3e8a33ad6e53..d210ac60487e 100644 --- a/src/lib/libast/features/sfio +++ b/src/lib/libast/features/sfio @@ -4,8 +4,6 @@ sys filio,ioctl lib qfrexp,qldexp key signed -typ struct.sf_hdtr sys/socket.h - tst - note{ number of bits in pointer }end output{ #include int diff --git a/src/lib/libast/features/stdio b/src/lib/libast/features/stdio index 753c9642f52f..ee89b4536163 100644 --- a/src/lib/libast/features/stdio +++ b/src/lib/libast/features/stdio @@ -29,7 +29,7 @@ cat{ #if defined(_AST_H) || defined(_SFIO_H) - #define BUFSIZ SF_BUFSIZE + #define BUFSIZ SFIO_BUFSIZE #else @@ -53,8 +53,8 @@ cat{ #define _sf_(f) ((struct _sfio_s*)(f)) - #define _SF_EOF 0000200 - #define _SF_ERROR 0000400 + #define _SFIO_EOF 0000200 + #define _SFIO_ERROR 0000400 #endif @@ -343,8 +343,8 @@ cat{ extern FILE _Sfstdout; extern FILE _Sfstderr; - #define feof(f) (_sf_(f)->_flags&_SF_EOF) - #define ferror(f) (_sf_(f)->_flags&_SF_ERROR) + #define feof(f) (_sf_(f)->_flags&_SFIO_EOF) + #define ferror(f) (_sf_(f)->_flags&_SFIO_ERROR) #define fileno(f) (_sf_(f)->_file) #define fputc(c,f) (_sf_(f)->_next>=_sf_(f)->_endw?_sfflsbuf(_sf_(f),(int)((unsigned char)(c))):(int)(*_sf_(f)->_next++=(unsigned char)(c))) #define getc(f) (_sf_(f)->_next>=_sf_(f)->_endr?_sffilbuf(_sf_(f),0):(int)(*_sf_(f)->_next++)) diff --git a/src/lib/libast/features/sys b/src/lib/libast/features/sys index 79fcda7e3cf1..676ae384effd 100644 --- a/src/lib/libast/features/sys +++ b/src/lib/libast/features/sys @@ -192,19 +192,13 @@ extern setuid int (uid_t) extern sleep unsigned (unsigned int) extern srand void (unsigned int) extern strcasecmp int (const char*, const char*) -extern strcat char* (char*, const char*) -extern strcmp int (const char*, const char*) extern strcoll int (const char*, const char*) -extern strcpy char* (char*, const char*) extern strcspn size_t (const char*, const char*) extern strdup char* (const char*) extern strlcat size_t (char*, const char*, size_t) extern strlcpy size_t (char*, const char*, size_t) extern strlen size_t (const char*) extern strncasecmp int (const char*, const char*, size_t) -extern strncat char* (char*, const char*, size_t) -extern strncmp int (const char*, const char*, size_t) -extern strncpy char* (char*, const char*, size_t) extern strpbrk char* (const char*, const char*) extern strspn size_t (const char*, const char*) extern strtok char* (char*, const char*) diff --git a/src/lib/libast/features/tty b/src/lib/libast/features/tty index 179e0e85a6ff..c0c7ead24813 100644 --- a/src/lib/libast/features/tty +++ b/src/lib/libast/features/tty @@ -1,113 +1,43 @@ -hdr termios,termio,sgtty,sys/ioctl -sys termios,termio,ioctl,bsdtty,nttyio,ttyio -lib tcgetattr,tcgetpgrp termios.h +hdr termios fail{ + echo "$0: POSIX termios.h is required" >&2 + exit 1 +}end +lib tcgetattr termios.h fail{ + echo "$0: POSIX tcgetattr(3) is required" >&2 + exit 1 +}end +lib tcgetpgrp unistd.h fail{ + echo "$0: POSIX tcgetpgrp(3) is required" >&2 + exit 1 +}end +sys ioctl mac _POSIX_VDISABLE termios.h mem termios.c_line termios.h cat{ -#ifdef _hdr_termios -# if _mac__POSIX_VDISABLE -# undef _POSIX_VDISABLE -# endif -# include -#else -# if defined(_sys_termios) && defined(_lib_tcgetattr) -# include -# define _hdr_termios 1 -# else -# undef _sys_termios -# endif /* _sys_termios */ -#endif /* _hdr_termios */ - -#ifdef _hdr_termios -# undef _hdr_sgtty -# undef tcgetattr -# undef tcsetattr -# undef tcgetpgrp -# undef tcsetpgrp -# undef cfgetospeed -# ifndef TCSANOW -# define TCSANOW TCSETS -# define TCSADRAIN TCSETSW -# define TCSAFLUSH TCSETSF -# endif /* TCSANOW */ - /* The following corrects bugs in some implementations */ -# if defined(TCSADFLUSH) && !defined(TCSAFLUSH) -# define TCSAFLUSH TCSADFLUSH -# endif /* TCSADFLUSH */ -# ifndef _lib_tcgetattr -# undef tcgetattr -# define tcgetattr(fd,tty) ioctl(fd, TCGETS, tty) -# undef tcsetattr -# define tcsetattr(fd,action,tty) ioctl(fd, action, tty) -# undef cfgetospeed -# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD) -# endif /* _lib_tcgetattr */ -# undef TIOCGETC -#else -# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD) -# define cfgetispeed(tp) ((tp)->c_cflag & CBAUD) -# define cfsetispeed(tp,val) ((tp)->c_cflag &=~ CBAUD,(tp)->c_cflag|=(val)) -# define cfsetospeed(tp,val) ((tp)->c_cflag &=~ CBAUD,(tp)->c_cflag|=(val)) -# ifdef _hdr_termio -# include -# else -# ifdef _sys_termio -# include -# define _hdr_termio 1 -# endif /* _sys_termio */ -# endif /* _hdr_termio */ -# ifdef _hdr_termio -# define termios termio -# undef TIOCGETC -# define tcgetattr(fd,tty) ioctl(fd, TCGETA, tty) -# define tcsetattr(fd,action,tty) ioctl(fd, action, tty) - -# ifdef _sys_bsdtty -# include -# endif /* _sys_bsdtty */ -# else -# ifdef _hdr_sgtty -# include -# ifndef LPENDIN -# ifdef _sys_nttyio -# include -# endif /* _sys_nttyio */ -# endif /* LPENDIN */ -# define termios sgttyb -# ifdef TIOCSETN -# undef TCSETAW -# endif /* TIOCSETN */ -# ifdef TIOCGETP -# define tcgetattr(fd,tty) ioctl(fd, TIOCGETP, tty) -# define tcsetattr(fd,action,tty) ioctl(fd, action, tty) -# else -# define tcgetattr(fd,tty) gtty(fd, tty) -# define tcsetattr(fd,action,tty) stty(fd, tty) -# endif /* TIOCGETP */ -# else -# ifdef _sys_ttyio -# include -# endif -# endif /* _hdr_sgtty */ -# endif /* hdr_termio */ - -# ifndef TCSANOW -# ifdef TCSETAW -# define TCSANOW TCSETA -# define TCSAFLUSH TCSETAF -# else -# ifdef TIOCSETN -# define TCSANOW TIOCSETN -# define TCSADRAIN TIOCSETN -# define TCSAFLUSH TIOCSETP -# endif /* TIOCSETN */ -# endif /* TCSETAW */ -# endif /* TCSANOW */ -#endif /* _hdr_termios */ - -#if _hdr_sys_ioctl +#if _mac__POSIX_VDISABLE +# undef _POSIX_VDISABLE +#endif +#include + +#undef tcgetattr +#undef tcsetattr +#undef tcgetpgrp +#undef tcsetpgrp +#undef cfgetospeed +#ifndef TCSANOW +# define TCSANOW TCSETS +# define TCSADRAIN TCSETSW +# define TCSAFLUSH TCSETSF +#endif /* TCSANOW */ +/* The following corrects bugs in some implementations */ +#if defined(TCSADFLUSH) && !defined(TCSAFLUSH) +# define TCSAFLUSH TCSADFLUSH +#endif /* TCSADFLUSH */ +#undef TIOCGETC + +#if _sys_ioctl # include #endif diff --git a/src/lib/libast/include/ast.h b/src/lib/libast/include/ast.h index b6ee243a530f..af742f1e987f 100644 --- a/src/lib/libast/include/ast.h +++ b/src/lib/libast/include/ast.h @@ -45,7 +45,7 @@ #endif /* - * workaround botched headers that assume + * work around botched headers that assume */ #ifndef FILE @@ -97,14 +97,9 @@ struct _sfio_s; #define EXIT_NOTFOUND 127 /* command not found */ #define EXIT_NOEXEC 126 /* other exec error */ -#define EXIT_CODE(x) ((x) & EXIT_QUIT) -#define EXIT_CORE(x) (EXIT_CODE(x) | 256 | 128) +#define EXIT_CODE(x) ((x) & 255) #define EXIT_TERM(x) (EXIT_CODE(x) | 256) -#define EXIT_STATUS(x) (((x) & 63) ? (x) : EXIT_CODE((x) >> 8)) -#define EXITED_CORE(x) (((x) & (256 | 128)) == (256 | 128) || ((x) & (128 | 64)) == (128 | 64)) -#define EXITED_TERM(x) ((x) & (256 | 128)) - /* * astconflist() flags */ @@ -258,8 +253,8 @@ typedef struct #define roundof(x,y) (((x)+(y)-1)&~((y)-1)) #define ssizeof(x) ((int)sizeof(x)) -#define streq(a,b) (*(a)==*(b)&&!strcmp(a,b)) -#define strneq(a,b,n) (*(a)==*(b)&&!strncmp(a,b,n)) +#define streq(a,b) (!strcmp(a,b)) +#define strneq(a,b,n) (!strncmp(a,b,n)) #define strsignal(s) fmtsignal(s) #define NiL NULL /* for backward compatibility */ diff --git a/src/lib/libast/include/ast_windows.h b/src/lib/libast/include/ast_windows.h index 318f6863e199..3be0e0a0ad60 100644 --- a/src/lib/libast/include/ast_windows.h +++ b/src/lib/libast/include/ast_windows.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -29,8 +29,6 @@ #ifndef _AST_WINDOWS_H #define _AST_WINDOWS_H 1 -#undef SF_ERROR /* clash in */ - /* * For some reason, DECLSPEC_NORETURN breaks when compiling with * -std=c99. C11 does not have this problem, so for C99 and below diff --git a/src/lib/libast/include/sfio.h b/src/lib/libast/include/sfio.h index 84eaf394094b..e962442113f9 100644 --- a/src/lib/libast/include/sfio.h +++ b/src/lib/libast/include/sfio.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -21,7 +21,7 @@ #ifndef _SFIO_H #define _SFIO_H 1 -#define SFIO_VERSION 20230517L +#define SFIO_VERSION 20240303L /* Public header file for the sfio library ** @@ -119,69 +119,58 @@ struct _sffmt_s #endif /* bits for various types of files */ -#define SF_READ 0000001 /* open for reading */ -#define SF_WRITE 0000002 /* open for writing */ -#define SF_STRING 0000004 /* a string stream */ -#define SF_APPENDWR 0000010 /* file is in append mode only */ -#define SF_MALLOC 0000020 /* buffer is malloc'd */ -#define SF_LINE 0000040 /* line buffering */ -#define SF_SHARE 0000100 /* stream with shared file descriptor */ -#define SF_EOF 0000200 /* eof was detected */ -#define SF_ERROR 0000400 /* an error happened */ -#define SF_STATIC 0001000 /* a stream that cannot be freed */ -#define SF_IOCHECK 0002000 /* call exceptf before doing IO */ -#define SF_PUBLIC 0004000 /* SF_SHARE and follow physical seek */ -#define SF_WHOLE 0020000 /* preserve wholeness of sfwrite/sfputr */ -#define SF_IOINTR 0040000 /* return on interrupts */ -#define SF_WCWIDTH 0100000 /* wcwidth display stream */ +#define SFIO_READ 0000001 /* open for reading */ +#define SFIO_WRITE 0000002 /* open for writing */ +#define SFIO_STRING 0000004 /* a string stream */ +#define SFIO_APPENDWR 0000010 /* file is in append mode only */ +#define SFIO_MALLOC 0000020 /* buffer is malloc'd */ +#define SFIO_LINE 0000040 /* line buffering */ +#define SFIO_SHARE 0000100 /* stream with shared file descriptor */ +#define SFIO_EOF 0000200 /* eof was detected */ +#define SFIO_ERROR 0000400 /* an error happened */ +#define SFIO_STATIC 0001000 /* a stream that cannot be freed */ +#define SFIO_IOCHECK 0002000 /* call exceptf before doing IO */ +#define SFIO_PUBLIC 0004000 /* SFIO_SHARE and follow physical seek */ +#define SFIO_WHOLE 0020000 /* preserve wholeness of sfwrite/sfputr */ +#define SFIO_IOINTR 0040000 /* return on interrupts */ +#define SFIO_WCWIDTH 0100000 /* wcwidth display stream */ #define SFIO_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */ -#ifdef _typ_struct_sf_hdtr -#define _SF_HIDESFFLAGS 1 -#endif -#define SF_SETS 0177163 /* flags passable to sfset() */ +#define SFIO_SETS 0177163 /* flags passable to sfset() */ -#ifndef _SF_NO_OBSOLETE -#define SF_BUFCONST 0400000 /* unused flag - for compatibility only */ +#ifndef _SFIO_NO_OBSOLETE +#define SFIO_BUFCONST 0400000 /* unused flag - for compatibility only */ #endif /* for sfgetr/sfreserve to hold a record */ -#define SF_LOCKR 0000010 /* lock record, stop access to stream */ -#define SF_LASTR 0000020 /* get the last incomplete record */ - -/* exception events: SF_NEW(0), SF_READ(1), SF_WRITE(2) and the below */ -#define SF_SEEK 3 /* seek error */ -#define SF_CLOSING 4 /* when stream is about to be closed */ -#define SF_DPUSH 5 /* when discipline is being pushed */ -#define SF_DPOP 6 /* when discipline is being popped */ -#define SF_DPOLL 7 /* see if stream is ready for I/O */ -#define SF_DBUFFER 8 /* buffer not empty during push or pop */ -#define SF_SYNC 9 /* announcing start/end synchronization */ -#define SF_PURGE 10 /* a sfpurge() call was issued */ -#define SF_FINAL 11 /* closing is done except stream free */ -#define SF_READY 12 /* a polled stream is ready */ -#define SF_LOCKED 13 /* stream is in a locked state */ -#define SF_ATEXIT 14 /* process is exiting */ -#define SF_EVENT 100 /* start of user-defined events */ +#define SFIO_LOCKR 0000010 /* lock record, stop access to stream */ +#define SFIO_LASTR 0000020 /* get the last incomplete record */ + +/* exception events: SFIO_NEW(0), SFIO_READ(1), SFIO_WRITE(2) and the below */ +#define SFIO_SEEK 3 /* seek error */ +#define SFIO_CLOSING 4 /* when stream is about to be closed */ +#define SFIO_DPUSH 5 /* when discipline is being pushed */ +#define SFIO_DPOP 6 /* when discipline is being popped */ +#define SFIO_DPOLL 7 /* see if stream is ready for I/O */ +#define SFIO_DBUFFER 8 /* buffer not empty during push or pop */ +#define SFIO_SYNC 9 /* announcing start/end synchronization */ +#define SFIO_PURGE 10 /* a sfpurge() call was issued */ +#define SFIO_FINAL 11 /* closing is done except stream free */ +#define SFIO_READY 12 /* a polled stream is ready */ +#define SFIO_LOCKED 13 /* stream is in a locked state */ +#define SFIO_ATEXIT 14 /* process is exiting */ +#define SFIO_EVENT 100 /* start of user-defined events */ /* for stack and disciplines */ -#define SF_POPSTACK NULL /* pop the stream stack */ -#define SF_POPDISC NULL /* pop the discipline stack */ +#define SFIO_POPSTACK NULL /* pop the stream stack */ +#define SFIO_POPDISC NULL /* pop the discipline stack */ /* for the notify function and discipline exception */ -#define SF_NEW 0 /* new stream */ -#define SF_SETFD (-1) /* about to set the file descriptor */ - -#define SF_BUFSIZE 8192 /* default buffer size */ -#define SF_UNBOUND (-1) /* unbounded buffer size */ +#define SFIO_NEW 0 /* new stream */ +#define SFIO_SETFD (-1) /* about to set the file descriptor */ -/* namespace incursion workarounds -- migrate to the new names */ -#if !_mac_SF_APPEND -#define SF_APPEND SF_APPENDWR /* BSDI sys/stat.h */ -#endif -#if !_mac_SF_CLOSE -#define SF_CLOSE SF_CLOSING /* AIX sys/socket.h */ -#endif +#define SFIO_BUFSIZE 8192 /* default buffer size */ +#define SFIO_UNBOUND (-1) /* unbounded buffer size */ extern ssize_t _Sfi; extern ssize_t _Sfmaxr; @@ -284,41 +273,41 @@ extern ssize_t sfslen(void); extern ssize_t sfmaxr(ssize_t, int); /* coding long integers in a portable and compact fashion */ -#define SF_SBITS 6 -#define SF_UBITS 7 -#define SF_BBITS 8 -#define SF_SIGN (1 << SF_SBITS) -#define SF_MORE (1 << SF_UBITS) -#define SF_BYTE (1 << SF_BBITS) -#define SF_U1 SF_MORE -#define SF_U2 (SF_U1*SF_U1) -#define SF_U3 (SF_U2*SF_U1) -#define SF_U4 (SF_U3*SF_U1) - -#define _SF_(f) ((Sfio_t*)(f)) - -#define __sf_putd(f,v) (_sfputd(_SF_(f),(Sfdouble_t)(v))) -#define __sf_putl(f,v) (_sfputl(_SF_(f),(Sflong_t)(v))) -#define __sf_putu(f,v) (_sfputu(_SF_(f),(Sfulong_t)(v))) -#define __sf_putm(f,v,m) (_sfputm(_SF_(f),(Sfulong_t)(v),(Sfulong_t)(m))) - -#define __sf_putc(f,c) (_SF_(f)->_next >= _SF_(f)->_endw ? \ - _sfflsbuf(_SF_(f),(int)((unsigned char)(c))) : \ - (int)(*_SF_(f)->_next++ = (unsigned char)(c)) ) -#define __sf_getc(f) (_SF_(f)->_next >= _SF_(f)->_endr ? _sffilbuf(_SF_(f),0) : \ - (int)(*_SF_(f)->_next++) ) +#define SFIO_SBITS 6 +#define SFIO_UBITS 7 +#define SFIO_BBITS 8 +#define SFIO_SIGN (1 << SFIO_SBITS) +#define SFIO_MORE (1 << SFIO_UBITS) +#define SFIO_BYTE (1 << SFIO_BBITS) +#define SFIO_U1 SFIO_MORE +#define SFIO_U2 (SFIO_U1*SFIO_U1) +#define SFIO_U3 (SFIO_U2*SFIO_U1) +#define SFIO_U4 (SFIO_U3*SFIO_U1) + +#define _SFIO_(f) ((Sfio_t*)(f)) + +#define __sf_putd(f,v) (_sfputd(_SFIO_(f),(Sfdouble_t)(v))) +#define __sf_putl(f,v) (_sfputl(_SFIO_(f),(Sflong_t)(v))) +#define __sf_putu(f,v) (_sfputu(_SFIO_(f),(Sfulong_t)(v))) +#define __sf_putm(f,v,m) (_sfputm(_SFIO_(f),(Sfulong_t)(v),(Sfulong_t)(m))) + +#define __sf_putc(f,c) (_SFIO_(f)->_next >= _SFIO_(f)->_endw ? \ + _sfflsbuf(_SFIO_(f),(int)((unsigned char)(c))) : \ + (int)(*_SFIO_(f)->_next++ = (unsigned char)(c)) ) +#define __sf_getc(f) (_SFIO_(f)->_next >= _SFIO_(f)->_endr ? _sffilbuf(_SFIO_(f),0) : \ + (int)(*_SFIO_(f)->_next++) ) #define __sf_dlen(v) (_sfdlen((Sfdouble_t)(v)) ) #define __sf_llen(v) (_sfllen((Sflong_t)(v)) ) -#define __sf_ulen(v) ((Sfulong_t)(v) < SF_U1 ? 1 : (Sfulong_t)(v) < SF_U2 ? 2 : \ - (Sfulong_t)(v) < SF_U3 ? 3 : (Sfulong_t)(v) < SF_U4 ? 4 : 5) - -#define __sf_fileno(f) (_SF_(f)->_file) -#define __sf_eof(f) (_SF_(f)->_flags&SF_EOF) -#define __sf_error(f) (_SF_(f)->_flags&SF_ERROR) -#define __sf_clrerr(f) (_SF_(f)->_flags &= ~(SF_ERROR|SF_EOF)) -#define __sf_stacked(f) (_SF_(f)->_push != NULL) -#define __sf_value(f) (_SF_(f)->_val) +#define __sf_ulen(v) ((Sfulong_t)(v) < SFIO_U1 ? 1 : (Sfulong_t)(v) < SFIO_U2 ? 2 : \ + (Sfulong_t)(v) < SFIO_U3 ? 3 : (Sfulong_t)(v) < SFIO_U4 ? 4 : 5) + +#define __sf_fileno(f) (_SFIO_(f)->_file) +#define __sf_eof(f) (_SFIO_(f)->_flags&SFIO_EOF) +#define __sf_error(f) (_SFIO_(f)->_flags&SFIO_ERROR) +#define __sf_clrerr(f) (_SFIO_(f)->_flags &= ~(SFIO_ERROR|SFIO_EOF)) +#define __sf_stacked(f) (_SFIO_(f)->_push != NULL) +#define __sf_value(f) (_SFIO_(f)->_val) #define __sf_slen() (_Sfi) #define __sf_maxr(n,s) ((s)?((_Sfi=_Sfmaxr),(_Sfmaxr=(n)),_Sfi):_Sfmaxr) @@ -374,7 +363,7 @@ __INLINE__ ssize_t sfmaxr(ssize_t n, int s) { return __sf_maxr(n,s); } #ifndef _SFSTR_H /* GSF's string manipulation stuff */ #define _SFSTR_H 1 -#define sfstropen() sfnew(0, 0, -1, -1, SF_READ|SF_WRITE|SF_STRING) +#define sfstropen() sfnew(0, 0, -1, -1, SFIO_READ|SFIO_WRITE|SFIO_STRING) #define sfstrclose(f) sfclose(f) #define sfstrseek(f,p,m) \ @@ -401,19 +390,14 @@ __INLINE__ ssize_t sfmaxr(ssize_t n, int s) { return __sf_maxr(n,s); } ) #define sfstrrsrv(f,n) \ - (sfreserve((f),(n),SF_WRITE|SF_LOCKR), sfwrite((f),(f)->_next,0), \ + (sfreserve((f),(n),SFIO_WRITE|SFIO_LOCKR), sfwrite((f),(f)->_next,0), \ ((f)->_next+(n) <= (f)->_data+(f)->_size ? (char*)(f)->_next : (char*)0) \ ) #define sfstrbuf(f,b,n,m) \ - (sfsetbuf((f),(b),(n)), ((f)->_flags |= (m) ? SF_MALLOC : 0), \ + (sfsetbuf((f),(b),(n)), ((f)->_flags |= (m) ? SFIO_MALLOC : 0), \ ((f)->_data == (unsigned char*)(b) ? 0 : -1) \ ) #endif /* _SFSTR_H */ - -#ifdef _SF_HIDESFFLAGS -#undef SFIO_FLAGS -#define SFIO_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */ -#endif #endif /* _SFIO_H */ diff --git a/src/lib/libast/include/sfio_t.h b/src/lib/libast/include/sfio_t.h index 192eaf1a9ba3..c6af3c3f34f0 100644 --- a/src/lib/libast/include/sfio_t.h +++ b/src/lib/libast/include/sfio_t.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -56,14 +56,14 @@ #include "sfio.h" /* mode bit to indicate that the structure hasn't been initialized */ -#define SF_INIT 0000004 -#define SF_DCDOWN 00010000 +#define SFIO_INIT 0000004 +#define SFIO_DCDOWN 00010000 /* shorthand for common stream types */ -#define SF_RDWR (SF_READ|SF_WRITE) -#define SF_RDSTR (SF_READ|SF_STRING) -#define SF_WRSTR (SF_WRITE|SF_STRING) -#define SF_RDWRSTR (SF_RDWR|SF_STRING) +#define SFIO_RDWR (SFIO_READ|SFIO_WRITE) +#define SFIO_RDSTR (SFIO_READ|SFIO_STRING) +#define SFIO_WRSTR (SFIO_WRITE|SFIO_STRING) +#define SFIO_RDWRSTR (SFIO_RDWR|SFIO_STRING) /* for static initialization of an Sfio_t structure */ #define SFNEW(data,size,file,type,disc) \ @@ -82,7 +82,7 @@ 0, /* ngetr */ \ {0}, /* tiny */ \ 0, /* bits */ \ - (unsigned int)(((type)&(SF_RDWR))|SF_INIT), /* mode */ \ + (unsigned int)(((type)&(SFIO_RDWR))|SFIO_INIT), /* mode */ \ (struct _sfdisc_s*)(disc), /* disc */ \ NULL, /* pool */ \ NULL, /* rsrv */ \ @@ -122,9 +122,9 @@ ) /* expose next stream inside discipline function; state saved in int f */ -#define SFDCNEXT(sp,f) (((f)=(sp)->bits&SF_DCDOWN),(sp)->bits|=SF_DCDOWN) +#define SFDCNEXT(sp,f) (((f)=(sp)->bits&SFIO_DCDOWN),(sp)->bits|=SFIO_DCDOWN) /* restore SFDCNEXT() state from int f */ -#define SFDCPREV(sp,f) ((f)?(0):((sp)->bits&=~SF_DCDOWN)) +#define SFDCPREV(sp,f) ((f)?(0):((sp)->bits&=~SFIO_DCDOWN)) #endif /* _SFIO_T_H */ diff --git a/src/lib/libast/include/vecargs.h b/src/lib/libast/include/stak.h similarity index 58% rename from src/lib/libast/include/vecargs.h rename to src/lib/libast/include/stak.h index 898be594400d..8d4a18b60aec 100644 --- a/src/lib/libast/include/vecargs.h +++ b/src/lib/libast/include/stak.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -17,19 +17,35 @@ * * ***********************************************************************/ /* - * Glenn Fowler + * David Korn * AT&T Research * - * vector argument interface definitions + * Obsolete interface definitions for a stack-like storage library. + * These now simply map onto the current stk(3) functions as below. */ -#ifndef _VECARGS_H -#define _VECARGS_H +#ifndef _STAK_H +#define _STAK_H -extern int vecargs(char**, int*, char***); -extern char** vecfile(const char*); -extern void vecfree(char**, int); -extern char** vecload(char*); -extern char** vecstring(const char*); +#include + +#define Stak_t Sfio_t +#define staksp stkstd +#define STAK_SMALL STK_SMALL + +#define stakptr(n) stkptr(stkstd,n) +#define staktell() stktell(stkstd) +#define stakputc(c) sfputc(stkstd,(c)) +#define stakwrite(b,n) sfwrite(stkstd,(b),(n)) +#define stakputs(s) (sfputr(stkstd,(s),0),--stkstd->_next) +#define stakseek(n) stkseek(stkstd,n) +#define stakcreate(n) stkopen(n) +#define stakinstall(s,f) stkinstall(s,f) +#define stakdelete(s) stkclose(s) +#define staklink(s) stklink(s) +#define stakalloc(n) stkalloc(stkstd,n) +#define stakcopy(s) stkcopy(stkstd,s) +#define stakset(c,n) stkset(stkstd,c,n) +#define stakfreeze(n) stkfreeze(stkstd,n) #endif diff --git a/src/lib/libast/include/stk.h b/src/lib/libast/include/stk.h index 9593e1849fab..17ad8e9068e6 100644 --- a/src/lib/libast/include/stk.h +++ b/src/lib/libast/include/stk.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -35,25 +35,27 @@ #define Stk_t Sfio_t -#define STK_SMALL 1 /* small stkopen stack */ +/* option bits for stkopen() */ +#define STK_SMALL 1 /* allocate small stack frames */ #define STK_NULL 2 /* return NULL on overflow */ #define stkptr(sp,n) ((char*)((sp)->_data)+(n)) #define stktop(sp) ((char*)(sp)->_next) #define stktell(sp) ((sp)->_next-(sp)->_data) -#define stkseek(sp,n) ((n)==0?(char*)((sp)->_next=(sp)->_data):_stkseek(sp,n)) +#define stkseek(sp,n) ((n)==0?(void*)((sp)->_next=(sp)->_data):_stkseek(sp,n)) extern Sfio_t _Stk_data; extern Stk_t* stkopen(int); -extern Stk_t* stkinstall(Stk_t*, char*(*)(size_t)); +extern Stk_t* stkinstall(Stk_t*, char*(*)(size_t)); /* deprecated */ +extern void stkoverflow(Stk_t*, void*(*)(size_t)); extern int stkclose(Stk_t*); extern unsigned int stklink(Stk_t*); -extern char* stkalloc(Stk_t*, size_t); +extern void* stkalloc(Stk_t*, size_t); extern char* stkcopy(Stk_t*, const char*); -extern char* stkset(Stk_t*, char*, size_t); -extern char* _stkseek(Stk_t*, ssize_t); -extern char* stkfreeze(Stk_t*, size_t); +extern void* stkset(Stk_t*, void*, size_t); +extern void* _stkseek(Stk_t*, ssize_t); +extern void* stkfreeze(Stk_t*, size_t); extern int stkon(Stk_t*, char*); #endif diff --git a/src/lib/libast/man/setenviron.3 b/src/lib/libast/man/setenviron.3 index 818f7fc0d496..f26c32ca7679 100644 --- a/src/lib/libast/man/setenviron.3 +++ b/src/lib/libast/man/setenviron.3 @@ -73,7 +73,3 @@ convention of as the first environment variable name. .SH "SEE ALSO" env(1), exec(2) -.SH BUGS -POSIX will eventually settle on an interface. -It has already picked a few of the names we did in .2 drafts. -This is about the third name change for ours. diff --git a/src/lib/libast/man/sfio.3 b/src/lib/libast/man/sfio.3 index 2e3ab93db3a4..b5172d90dfc4 100644 --- a/src/lib/libast/man/sfio.3 +++ b/src/lib/libast/man/sfio.3 @@ -1,5 +1,5 @@ .fp 5 CW -.TH SFIO 3 "12 February 2022" +.TH SFIO 3 "2 March 2024" .SH NAME \fBsfio\fR \- safe/fast string/file input/output .SH SYNOPSIS @@ -51,18 +51,18 @@ SFIO_VERSION .Ss "BIT FLAGS" .nf .ft 5 -SF_STRING -SF_READ -SF_WRITE -SF_APPENDWR (SF_APPEND) -SF_LINE -SF_SHARE -SF_PUBLIC -SF_MALLOC -SF_STATIC -SF_IOCHECK -SF_WHOLE -SF_IOINTR +SFIO_STRING +SFIO_READ +SFIO_WRITE +SFIO_APPENDWR +SFIO_LINE +SFIO_SHARE +SFIO_PUBLIC +SFIO_MALLOC +SFIO_STATIC +SFIO_IOCHECK +SFIO_WHOLE +SFIO_IOINTR .ft 1 .fi .Ss "OPENING/CLOSING STREAMS" @@ -166,22 +166,22 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc); ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc); Sfoff_t sfsk(Sfio_t* f, Sfoff_t offset, int type, Sfdisc_t* disc); -SF_NEW -SF_READ -SF_WRITE -SF_SEEK -SF_CLOSING (SF_CLOSE) -SF_DPUSH -SF_DPOP -SF_DPOLL -SF_DBUFFER -SF_SYNC -SF_PURGE -SF_FINAL -SF_READY -SF_LOCKED -SF_ATEXIT -SF_EVENT +SFIO_NEW +SFIO_READ +SFIO_WRITE +SFIO_SEEK +SFIO_CLOSING +SFIO_DPUSH +SFIO_DPOP +SFIO_DPOLL +SFIO_DBUFFER +SFIO_SYNC +SFIO_PURGE +SFIO_FINAL +SFIO_READY +SFIO_LOCKED +SFIO_ATEXIT +SFIO_EVENT .ft 1 .fi .Ss "STREAM CONTROL" @@ -335,46 +335,46 @@ A number of bit flags control stream operations. They are set either at stream initialization or by calling \f3sfset()\fP. Following are the flags: .Tp -\f3SF_STRING\fP: +\f3SFIO_STRING\fP: The stream is memory-based. .Tp -\f3SF_READ\fP, \f3SF_WRITE\fP, \f3SF_APPENDWR\fP (\f3SF_APPEND\fP): -Flags \f3SF_READ\fP and \f3SF_WRITE\fP indicate readability and writability. -Flag \f3SF_APPENDWR\fP asserts that the stream is a file opened in append mode +\f3SFIO_READ\fP, \f3SFIO_WRITE\fP, \f3SFIO_APPENDWR\fP: +Flags \f3SFIO_READ\fP and \f3SFIO_WRITE\fP indicate readability and writability. +Flag \f3SFIO_APPENDWR\fP asserts that the stream is a file opened in append mode (see \f3open(2)\fP and \f3fcntl(2)\fP) so that data is always output at the end of file. On systems without direct support for append mode, Sfio uses \f3lseek(2)\fP or its discipline replacement to approximate this behavior. .Tp -\f3SF_LINE\fP: +\f3SFIO_LINE\fP: The stream is line-oriented. -For a \f3SF_WRITE\fP stream, +For a \f3SFIO_WRITE\fP stream, this means that buffered data is flushed whenever a new-line character, \f3\en\fP, is output. -For a \f3SF_READ\fP stream, \f3SF_LINE\fP is only +For a \f3SFIO_READ\fP stream, \f3SFIO_LINE\fP is only significant during calls to functions in the \f3sfscanf()\fP family. -\f3SF_LINE\fP is set on initialization of +\f3SFIO_LINE\fP is set on initialization of any stream representing a terminal device. .Tp -\f3SF_SHARE\fP, \f3SF_PUBLIC\fP: -Flag \f3SF_SHARE\fP means that the underlying file descriptor +\f3SFIO_SHARE\fP, \f3SFIO_PUBLIC\fP: +Flag \f3SFIO_SHARE\fP means that the underlying file descriptor is shared by independent entities (for example, multiple processes). -For a seekable file stream, \f3SF_SHARE\fP means that +For a seekable file stream, \f3SFIO_SHARE\fP means that the logical stream and the physical file positions will be made the same before a system call to perform physical I/O. There are different possibilities. -If \f3SF_PUBLIC\fP is not set, +If \f3SFIO_PUBLIC\fP is not set, the physical file position is made equal to the logical stream position. -If \f3SF_PUBLIC\fP is set, there are two cases. +If \f3SFIO_PUBLIC\fP is set, there are two cases. If the physical file position has changed from its last known position, the logical stream position is made equal to the new physical file position. Finally, if the physical file location remains the same as its last known position, the physical file position is made the same as the logical stream position. For an unseekable stream (e.g., pipes or terminal devices), if possible, -\f3SF_SHARE\fP means that +\f3SFIO_SHARE\fP means that the block and record I/O operations (\f3sfread()\fP, \f3sfwrite()\fP, \f3sfmove()\fP, \f3sfgetr()\fP, \f3sfputr()\fP, \f3sfreserve()\fP, \f3sfscanf()\fP and \f3sfvprintf()\fP) will ensure: @@ -383,37 +383,37 @@ and \f3sfvprintf()\fP) will ensure: Note, however, that (2) is not always possible without proper OS facilities such as \f3recv(2)\fP or \f3streamio(4)\fP. -A standard stream that is seekable will be initialized with \f3SF_SHARE|SF_PUBLIC\fP. +A standard stream that is seekable will be initialized with \f3SFIO_SHARE|SFIO_PUBLIC\fP. .Tp -\f3SF_MALLOC\fP: +\f3SFIO_MALLOC\fP: The stream buffer was obtained via \f3malloc(3)\fP and can be reallocated or freed. .Tp -\f3SF_STATIC\fP: +\f3SFIO_STATIC\fP: The stream structure should not be freed when closed (\f3sfclose()\fP). This flag is used by an applications that allocate their own stream structures. Such applications must use the header file \f3sfio_t.h\fP instead of \f3sfio.h\fP. .Tp -\f3SF_IOCHECK\fP: +\f3SFIO_IOCHECK\fP: If the stream has a discipline exception handler, exceptions will be raised in \f3sfsync()\fP, \f3sfpurge()\fP or before a system call \f3read(2)\fP or \f3write(2)\fP (see \f3sfdisc()\fP). .Tp -\f3SF_WHOLE\fP: +\f3SFIO_WHOLE\fP: This flag guarantees that data written in any single \f3sfwrite()\fP or \f3sfputr()\fP call will always be output as a whole to the output device. This is useful in certain applications (e.g., networking) where a complex object must be output without being split in different system calls. Note that the respective stream still buffers data as much as the buffer can accommodate. .Tp -\f3SF_IOINTR\fP: +\f3SFIO_IOINTR\fP: This flag indicates that I/O system calls should not be resumed after being interrupted by signals. It is useful for aborting I/O operations on such interruptions. Note, however, that certain operating systems (e.g., BSD Unix systems) may automatically resume interrupted system calls outside the scope of the library. On such systems, -\f3SF_IOINTR\fP will be ineffective. +\f3SFIO_IOINTR\fP will be ineffective. .Ss "OPENING/CLOSING STREAMS" .Ss " Sfio_t* sfnew(Sfio_t* f, void* buf, size_t size, int fd, int flags)" This function creates or renews a stream. @@ -422,10 +422,10 @@ It returns the new stream on success and \f3NULL\fP on error. \f3f\fP: If \f3f\fP is \f3NULL\fP, a new stream is created. Otherwise, \f3f\fP is reused. -In this case, if \f3flags\fP does not have \f3SF_EOF\fP, +In this case, if \f3flags\fP does not have \f3SFIO_EOF\fP, \f3f\fP shall be closed via \f3sfclose()\fP before being reused. During a stream renewal, buffer, pool and discipline stack are preserved. -Note that, except for \f3SF_STATIC\fP streams, +Note that, except for \f3SFIO_STATIC\fP streams, renewing a stream already closed will result in undefined behavior. .Tp \f3buf\fP, \f3size\fP: @@ -433,14 +433,14 @@ These determine a buffering scheme. See \f3sfsetbuf()\fP for more details. .Tp \f3fd\fP: -If \f3SF_STRING\fP is specified in \f3flags\fP, this is ignored. +If \f3SFIO_STRING\fP is specified in \f3flags\fP, this is ignored. Otherwise, \f3fd\fP is a file descriptor (e.g., from \f3open(2)\fP) to use for raw data I/O. Note that Sfio supports unseekable file descriptors opened for both read and write, e.g., sockets. .Tp \f3flags\fP: -This is composed from \f3SF_EOF\fP and +This is composed from \f3SFIO_EOF\fP and bit values defined in the \fBBIT FLAGS\fP section. .Ss " Sfio_t* sfopen(Sfio_t* f, const char* string, const char* mode)" @@ -452,7 +452,7 @@ In this case, \f3sfopen()\fP returns \f3f\fP on success and \f3NULL\fP on error. This somewhat unusual usage of \f3sfopen()\fP is good for resetting certain predefined modes in standard streams including \fItext/binary\fP and \fIappend\fP that are inherited from some parent process. -Note also that \f3SF_READ\fP and \f3SF_WRITE\fP can only be reset if the stream +Note also that \f3SFIO_READ\fP and \f3SFIO_WRITE\fP can only be reset if the stream is not yet initialized. \f3sfopen()\fP is normally used to create a new stream or renew a stream. @@ -515,7 +515,7 @@ and the given command \f3cmd\fP. When the interpreter is \f3/bin/sh\fP or if there are no shell meta-characters in \f3cmd\fP. .Ss " Sfio_t* sfstropen(void)" Shorthand that opens a new string buffer for reading and writing; -same as \f3sfnew(NULL,NULL,-1,-1,SF_READ|SF_WRITE|SF_STRING)\fP. +same as \f3sfnew(NULL,NULL,-1,-1,SFIO_READ|SFIO_WRITE|SFIO_STRING)\fP. See also .BR sfstruse() . .Ss " Sfio_t* sftmp(size_t size)" @@ -523,7 +523,7 @@ This function creates a stream for temporary data. It returns the new stream or \f3NULL\fP on error. A stream created by \f3sftmp()\fP can be completely or partially memory-resident. -If \f3size\fP is \f3SF_UNBOUND\fP, the stream is a pure string stream. +If \f3size\fP is \f3SFIO_UNBOUND\fP, the stream is a pure string stream. If \f3size\fP is zero, the stream is a pure file stream. Otherwise, the stream is first created as a string stream but when its buffer grows larger than \f3size\fP or on any attempt to change disciplines, @@ -538,7 +538,7 @@ If \f3TMPPATH\fP is undefined, If neither of \f3TMPPATH\fP and \f3TMPDIR\fP are defined, \f3/tmp\fP is used. .Ss " int sfclose(Sfio_t* f)" This function closes the stream \f3f\fP and frees its resources. -\f3SF_STATIC\fP should be used if the stream space is to be preserved. +\f3SFIO_STATIC\fP should be used if the stream space is to be preserved. If \f3f\fP is the base of a stream stack (see \f3sfstack()\fP), all streams on the stack are closed. If \f3f\fP is a \f3sfpopen\fP-stream, @@ -546,15 +546,15 @@ If \f3f\fP is a \f3sfpopen\fP-stream, and returns its exit status. \f3sfclose()\fP returns \f3-1\fP for failure and \f30\fP for success. -\f3SF_READ|SF_SHARE\fP and \f3SF_WRITE\fP streams +\f3SFIO_READ|SFIO_SHARE\fP and \f3SFIO_WRITE\fP streams are synchronized before closing (see \f3sfsync()\fP). If \f3f\fP has disciplines, their exception handlers will be called twice. The first exception handler call has the \f3type\fP argument as one of -\f3SF_CLOSING\fP or \f3SF_NEW\fP (see \f3sfdisc()\fP). -The latter, \f3SF_NEW\fP is used when a stream is being closed via \f3sfnew()\fP +\f3SFIO_CLOSING\fP or \f3SFIO_NEW\fP (see \f3sfdisc()\fP). +The latter, \f3SFIO_NEW\fP is used when a stream is being closed via \f3sfnew()\fP so that it can be renewed. -The second call uses \f3type\fP as \f3SF_FINAL\fP +The second call uses \f3type\fP as \f3SFIO_FINAL\fP and is done after all closing operations have succeeded but before the stream itself is deallocated. In either case, if the exception handler returns a negative value, @@ -625,16 +625,16 @@ See also \f3sfmaxr()\fP for limiting the amount of data read to construct a reco The \f3type\fP argument is composed of some subset of the below bit flags: .Tp -\f3SF_STRING\fP: +\f3SFIO_STRING\fP: A null byte will replace the record separator to make the record into a C string. Otherwise, the record separator is left alone. .Tp -\f3SF_LOCKR\fP: +\f3SFIO_LOCKR\fP: Upon successfully obtaining a record \f3r\fP, the stream will be locked from further access until it is released with a call \f3sfread(f,r,0)\fP. .Tp -\f3SF_LASTR\fP: +\f3SFIO_LASTR\fP: This should be used only after a failed \f3sfgetr()\fP to retrieve the last incomplete record. In this case, \f3rsc\fP is ignored. .Ss " ssize_t sfputr(Sfio_t* f, const char* s, int rsc)" @@ -662,16 +662,16 @@ This function reads up to \f3n\fP bytes from \f3f\fP into buffer \f3buf\fP. It returns the number of bytes actually read or \f3-1\fP on error. .Ss " ssize_t sfwrite(Sfio_t* f, const void* buf, size_t n)" This function writes \f3n\fP bytes from \f3buf\fP to \f3f\fP. -If \f3f\fP is \f3SF_STRING\fP, and the buffer is not large enough, -an \f3SF_WRITE\fP exception shall be raised. +If \f3f\fP is \f3SFIO_STRING\fP, and the buffer is not large enough, +an \f3SFIO_WRITE\fP exception shall be raised. \f3sfwrite()\fP returns the number of bytes written or \f3-1\fP on failure. .Ss " Sfoff_t sfseek(Sfio_t* f, Sfoff_t offset, int type)" This function sets a new I/O position for \f3f\fP. It returns the new position or \f3-1\fP on failure. -If the stream is a \f3SF_STRING\fP stream and the new +If the stream is a \f3SFIO_STRING\fP stream and the new address is beyond the current buffer extent, -an \f3SF_SEEK\fP exception will be raised (see \f3sfdisc()\fP). +an \f3SFIO_SEEK\fP exception will be raised (see \f3sfdisc()\fP). The new position is determined based on \f3offset\fP and \f3type\fP which is composed from the bit flags: @@ -680,18 +680,18 @@ The new position is determined based on \f3offset\fP and \f3offset\fP is the desired position. .Tp \f31\fP or \f3SEEK_CUR\fP: -\f3offset\fP is relative to the current position (see \f3SF_PUBLIC\fP below). +\f3offset\fP is relative to the current position (see \f3SFIO_PUBLIC\fP below). .Tp \f32\fP or \f3SEEK_END\fP: \f3offset\fP is relative to the physical end of file. .Tp -\f3SF_SHARE\fP: -The stream is treated as if it has the control bit \f3SF_SHARE\fP on. +\f3SFIO_SHARE\fP: +The stream is treated as if it has the control bit \f3SFIO_SHARE\fP on. This implies that a system call seek will be done to ensure that the location seeking to is valid. .Tp -\f3SF_PUBLIC\fP: -The stream is treated as if it has the control bit \f3SF_PUBLIC\fP on. +\f3SFIO_PUBLIC\fP: +The stream is treated as if it has the control bit \f3SFIO_PUBLIC\fP on. If the physical file position has changed from its last known location, the current position is taken as the new physical position. Otherwise, the current position is the logical stream position. @@ -699,19 +699,19 @@ Otherwise, the current position is the logical stream position. This function reserves a data block from the stream \f3f\fP. It returns the reserved data block on success and \f3NULL\fP on failure. -If \f3f\fP is a \f3SF_READ\fP stream, the data block is a segment of input data. -If \f3f\fP is a \f3SF_WRITE\fP stream, the data block is a buffer +If \f3f\fP is a \f3SFIO_READ\fP stream, the data block is a segment of input data. +If \f3f\fP is a \f3SFIO_WRITE\fP stream, the data block is a buffer suitable for writing output data. -For consistency, if \f3f\fP is opened with \f3SF_READ|SF_WRITE\fP, -it will normally be treated as if it is a \f3SF_READ\fP stream +For consistency, if \f3f\fP is opened with \f3SFIO_READ|SFIO_WRITE\fP, +it will normally be treated as if it is a \f3SFIO_READ\fP stream (see \f3sfset()\fP for forcing a particular mode) but the returned buffer can also be written into (more below). -However, it is possible to bias to \f3SF_WRITE\fP when the \f3type\fP -argument is non-negative by adding the \f3SF_WRITE\fP bit \f3type\fP. +However, it is possible to bias to \f3SFIO_WRITE\fP when the \f3type\fP +argument is non-negative by adding the \f3SFIO_WRITE\fP bit \f3type\fP. In any case, a reserved data block is guaranteed to be valid only until a future access to the stream \f3f\fP. -When \f3f\fP is \f3SF_READ\fP, \f3SF_SHARE\fP and unseekable, +When \f3f\fP is \f3SFIO_READ\fP, \f3SFIO_SHARE\fP and unseekable, \f3sfreserve()\fP will attempt to peek at input data without consuming it. This enables separate processes to share in reading input from unseekable file descriptors (e.g., pipes or devices). @@ -723,12 +723,12 @@ After a \f3sfreserve()\fP call, whether or not it succeeds, \f3sfvalue(f)\fP gives the size of the available data block. Any partially reserved data block after a failed \f3sfreserve()\fP call can be obtained in another \f3sfreserve()\fP call with the argument -\f3type\fP being \f3SF_LASTR\fP. The second argument \f3n\fP +\f3type\fP being \f3SFIO_LASTR\fP. The second argument \f3n\fP to \f3sfreserve()\fP will be ignored in this case. A \f3sfreserve()\fP call is successful if it can obtain a data block of size at least the absolute value of \f3n\fP. -For a \f3SF_READ\fP atream, the argument \f3n\fP is treated as follows: +For a \f3SFIO_READ\fP atream, the argument \f3n\fP is treated as follows: .Tp \f3n < 0\fP: \f3sfreserve()\fP attempts to get \fIat least\fP \f3|n|\fP bytes @@ -741,21 +741,21 @@ but does not consume it (as consistent with \f3n == 0\fP). If \f3type != 0\fP, no attempt will be made to read data into the buffer. For example, the call \f3sfreserve(f, 0, -1)\fP only returns the buffer status, i.e., size of existing buffered data and pointer to such data, if any. -The call \f3sfreserve(f, 0, SF_LOCKR)\fP is similar but also locks the stream. +The call \f3sfreserve(f, 0, SFIO_LOCKR)\fP is similar but also locks the stream. .Tp \f3n > 0\fP: \f3sfreserve()\fP will use attempt to get \fIat most\fP \f3n\fP bytes into -the buffer. Further, if \f3type == 3SF_LOCKR\fP (see below), read attempts +the buffer. Further, if \f3type == 3SFIO_LOCKR\fP (see below), read attempts end on a positive amount. For a successful reservation, the argument \f3type\fP dictates treatment as follows: .Tp -\f3type == SF_LASTR\fP: -After a \f3sfreserve()\fP call with \f3type != SF_LOCKR\fP fails, +\f3type == SFIO_LASTR\fP: +After a \f3sfreserve()\fP call with \f3type != SFIO_LOCKR\fP fails, there may be some left over data not accessible via conventional Sfio calls. Immediately after such a failed call, -another call to \f3sfreserve\fP with \f3type == SF_LASTR\fP will return any left over +another call to \f3sfreserve\fP with \f3type == SFIO_LASTR\fP will return any left over data and also advance the stream I/O position by the amount of returned data. .Tp \f3type < 0\fP: @@ -766,20 +766,20 @@ For example, a successful \f3sfreserve(f, -1, -1)\fP call will return a buffer of data and simultaneously advance the stream I/O position by the amount indicated by \f3sfvalue(f)\fP. .Tp -\f3type == SF_LOCKR\fP: +\f3type == SFIO_LOCKR\fP: The stream I/O position remains unchanged. In addition, \f3f\fP will be locked from further access. -As appropriate to the stream type (\f3SF_READ\fP, \f3SF_WRITE\fP or both), +As appropriate to the stream type (\f3SFIO_READ\fP, \f3SFIO_WRITE\fP or both), \f3f\fP can be unlocked later with one of \f3sfread(f,rsrv,size)\fP or \f3sfwrite(f,rsrv,size)\fP where \f3rsrv\fP is the reserved data block and \f3size\fP is the amount of -data to be consumed. For example, if \f3f\fP is a locked \f3SF_READ\fP stream, +data to be consumed. For example, if \f3f\fP is a locked \f3SFIO_READ\fP stream, the call \f3sfread(f,rsrv,1)\fP will reopen the stream and simultaneously advance the stream I/O position by \f31\fP. Finally, a stream opened for both reading and writing can release the lock with either call (with associated operational semantics!) For example, the below code reads 10 bytes of data from a stream -opened with both \f3SF_READ\fP and \f3SF_WRITE\fP, modifies the data in place, +opened with both \f3SFIO_READ\fP and \f3SFIO_WRITE\fP, modifies the data in place, then rewrites the new data back to the stream: .nf .ft 5 @@ -823,12 +823,12 @@ original formatting pair and without any extension functions. The top environment of a stack, say \f3fe\fP, is automatically popped whenever its format string is completely processed. In this case, its event-handling function (if any) is called -as \f3(*eventf)(f,SF_FINAL,NULL,fe)\fP. +as \f3(*eventf)(f,SFIO_FINAL,NULL,fe)\fP. The top environment can also be popped by giving an argument \f3NULL\fP to \f3%!\fP or by returning a negative value in an extension function. In these cases, the event-handling function is called -as \f3(*eventf)(f,SF_DPOP,form,fe)\fP where \f3form\fP is the remainder +as \f3(*eventf)(f,SFIO_DPOP,form,fe)\fP where \f3form\fP is the remainder of the format string. A negative return value from the event handling function will prevent the environment from being popped. @@ -1267,7 +1267,7 @@ the number of items successfully scanned or \f3-1\fP on error. .PP A white space character (blank, tab, or new-line) in \f3format\fP normally matches a maximal sequence of input white space characters. -However, if the input stream is in \f3SF_LINE\fP mode (see \f3sfset()\fP), +However, if the input stream is in \f3SFIO_LINE\fP mode (see \f3sfset()\fP), a new-line character only matches white spaces up to an input new-line character. This is useful to avoid blocking when scanning typed inputs. .PP @@ -1418,7 +1418,7 @@ it can also be explicitly set via the call \f3sfsetbuf(f, (void*)f, size)\fP. In invocations of \f3sfsetbuf()\fP other than the above case, the \f3size\fP argument is treated as follows: .Tp -\f3size == SF_UNBOUND\fP: +\f3size == SFIO_UNBOUND\fP: Sfio will pick a suitable buffer size. If \f3buf\fP is \f3NULL\fP, Sfio will also pick a suitable buffering scheme (such as memory mapping). @@ -1442,10 +1442,10 @@ In this case, no attempt will be made to synchronize the stream. This function synchronizes the logical and physical views of stream \f3f\fP. It returns a negative value for failure and \f30\fP for success. -For a \f3SF_WRITE\fP stream, synchronization means to write out any buffered data. -For a seekable \f3SF_READ\fP file stream, +For a \f3SFIO_WRITE\fP stream, synchronization means to write out any buffered data. +For a seekable \f3SFIO_READ\fP file stream, the physical file position is aligned with the logical stream position and, -if \f3SF_SHARE\fP is on, buffered data is discarded. +if \f3SFIO_SHARE\fP is on, buffered data is discarded. If \f3f\fP is \f3NULL\fP, all streams are synchronized. If \f3f\fP is the base of a stream stack (see \f3sfstack()\fP), all stacked streams are synchronized. @@ -1453,7 +1453,7 @@ Note that a stacked stream can only be synchronized this way. If \f3f\fP is in a pool (see \f3sfpool()\fP) but not being the head, the pool head is synchronized. -If \f3f\fP has flag \f3SF_IOCHECK\fP, the \f3SF_SYNC\fP event is raised +If \f3f\fP has flag \f3SFIO_IOCHECK\fP, the \f3SFIO_SYNC\fP event is raised before and after synchronization. See \f3sfdisc()\fP for details. .Ss " int sfpoll(Sfio_t** flist, int n, int timeout)" This function polls a set of streams to see if I/O operations @@ -1463,9 +1463,9 @@ If a stream has a discipline, the exception function may be called before and after the stream is polled (see \f3sfdisc()\fP for details). After a successful \f3sfpoll()\fP call, for each ready stream \f3f\fP, \f3sfvalue(f)\fP returns -a bit combination of \f3SF_READ\fP and \f3SF_WRITE\fP to tell which I/O -mode is available. If \f3SF_READ\fP is available, an attempt to read -a byte will not block. If \f3SF_WRITE\fP is available, +a bit combination of \f3SFIO_READ\fP and \f3SFIO_WRITE\fP to tell which I/O +mode is available. If \f3SFIO_READ\fP is available, an attempt to read +a byte will not block. If \f3SFIO_WRITE\fP is available, an attempt to flush will not block. \f3sfpoll()\fP returns the number of ready streams or \f3-1\fP on failure. .Tp @@ -1478,11 +1478,11 @@ of \f3flist\fP in the same relative order. This defines an elapse time in milliseconds to wait to see if any stream is ready for I/O. If \f3timeout\fP is negative, \f3sfpoll()\fP will block until some stream become ready. -Note that \f3SF_STRING\fP and normal file streams never block +Note that \f3SFIO_STRING\fP and normal file streams never block and are always ready for I/O. If a stream with discipline is being polled and its readiness is as yet undetermined (e.g., empty buffer,) -the discipline exception function will be called with \f3SF_DPOLL\fP +the discipline exception function will be called with \f3SFIO_DPOLL\fP before querying the operating system. .Ss " Sfio_t* sfpool(Sfio_t* f, Sfio_t* poolf, int mode)" This function manipulates pools of streams. @@ -1506,22 +1506,22 @@ In this case, \f3poolf\fP is returned. .Tp \f3mode\fP: If \f3poolf\fP is already in a pool, \f3mode\fP is ignored. -Otherwise, \f3mode\fP should be \f30\fP or \f3SF_SHARE\fP. -A \f3SF_SHARE\fP pool contains streams with \f3SF_WRITE\fP mode. +Otherwise, \f3mode\fP should be \f30\fP or \f3SFIO_SHARE\fP. +A \f3SFIO_SHARE\fP pool contains streams with \f3SFIO_WRITE\fP mode. In addition, on change to a new head stream, buffered write data of the current head is transferred to the new head. .Ss " int sfpurge(Sfio_t* f)" This function discards all buffered data -unless \f3f\fP is a \f3SF_STRING\fP stream. -Note that if \f3f\fP is a \f3SF_READ\fP stream based on an unseekable device, +unless \f3f\fP is a \f3SFIO_STRING\fP stream. +Note that if \f3f\fP is a \f3SFIO_READ\fP stream based on an unseekable device, purged data will not be recoverable. If \f3f\fP is a \f3sfpopen\fP-stream opened for both read and write, data of both the read and write pipe ends will be purged (see \f3sfset()\fP to selectively turn off read or write mode if one set of data is to be preserved). -After purging, if \f3f\fP has flag \f3SF_IOCHECK\fP, -the event \f3SF_PURGE\fP is raised. +After purging, if \f3f\fP has flag \f3SFIO_IOCHECK\fP, +the event \f3SFIO_PURGE\fP is raised. \f3sfpurge()\fP returns \f3-1\fP for failure and \f30\fP for success. .Ss "DISCIPLINE, EVENT-HANDLING" .PP @@ -1552,7 +1552,7 @@ to traverse the entire discipline stack of a stream \f3f\fP as follows: .ft 1 .fi -If \f3disc\fP is \f3SF_POPDISC\fP or \f3NULL\fP, +If \f3disc\fP is \f3SFIO_POPDISC\fP or \f3NULL\fP, the top element of the stack, if any, is popped and its address is returned. Otherwise, \f3disc\fP is pushed onto the discipline stack. In this case, if successful, \f3sfdisc()\fP returns @@ -1594,7 +1594,7 @@ The on-going operation shall terminate. \f3>0\fP: If the event was raised due to an I/O error, the error has been repaired and the on-going operation shall continue normally. -For some events, e.g., \f3SF_DPOLL\fP, the return value may also have +For some events, e.g., \f3SFIO_DPOLL\fP, the return value may also have additional meanings. .Tp \f3=0\fP: @@ -1606,14 +1606,14 @@ stream. The argument \f3type\fP of \f3(*exceptf)()\fP identifies the particular exceptional event: .Tp -\f3SF_LOCKED\fP: +\f3SFIO_LOCKED\fP: The stream cannot be accessed because it was frozen by certain operations such as \f3sfreserve()\fP or \f3sfstack()\fP. .Tp -\f3SF_READ\fP, \f3SF_WRITE\fP: +\f3SFIO_READ\fP, \f3SFIO_WRITE\fP: These events are raised around reading and writing operations. -If \f3SF_IOCHECK\fP is on, \f3SF_READ\fP and \f3SF_WRITE\fP +If \f3SFIO_IOCHECK\fP is on, \f3SFIO_READ\fP and \f3SFIO_WRITE\fP are raised immediately before \f3read(2) and write(2)\fP calls. In this case, \f3*((ssize_t*)value)\fP is the amount of data to be processed. The return value of \f3(*exceptf)()\fP, if negative, @@ -1623,35 +1623,35 @@ If it is positive, the stream is ready for I/O but the amount should be restricted to the amount specified by this value. If the return value is zero, the I/O operation is carried out normally. -\f3SF_READ\fP and \f3SF_WRITE\fP are also raised on operation failures. +\f3SFIO_READ\fP and \f3SFIO_WRITE\fP are also raised on operation failures. In such a case, \f3*((ssize_t*)value)\fP is the return value from the failed operation. .Tp -\f3SF_SEEK\fP: +\f3SFIO_SEEK\fP: This event is raised when a seek operation fails. .Tp -\f3SF_NEW\fP, \f3SF_CLOSING\fP (\f3SF_CLOSE\fP), \f3SF_FINAL\fP: +\f3SFIO_NEW\fP, \f3SFIO_CLOSING\fP, \f3SFIO_FINAL\fP: These events are raised during a stream closing. -\f3SF_NEW\fP is raised for a stream about to be closed to be renewed (see \f3sfnew()\fP). -\f3SF_CLOSING\fP is raised for a stream about to be closed. -\f3SF_FINAL\fP is raised after a stream has been closed and before +\f3SFIO_NEW\fP is raised for a stream about to be closed to be renewed (see \f3sfnew()\fP). +\f3SFIO_CLOSING\fP is raised for a stream about to be closed. +\f3SFIO_FINAL\fP is raised after a stream has been closed and before its space is to be destroyed (see \f3sfclose()\fP). For these events, a non-zero return value from \f3(*exceptf)()\fP causes \f3sfclose()\fP to return immediately with the same value. .Tp -\f3SF_DPUSH\fP, \f3SF_DPOP\fP, \f3SF_DBUFFER\fP: -Events \f3SF_DPUSH\fP and \f3SF_DPOP\fP are raised when a +\f3SFIO_DPUSH\fP, \f3SFIO_DPOP\fP, \f3SFIO_DBUFFER\fP: +Events \f3SFIO_DPUSH\fP and \f3SFIO_DPOP\fP are raised when a discipline is about to be pushed or popped. \f3(Sfdisc_t*)value\fP is the to-be top discipline, if any. A stream buffer is always synchronized before pushing or popping a discipline. -If this synchronization fails, \f3SF_DBUFFER\fP will be raised with +If this synchronization fails, \f3SFIO_DBUFFER\fP will be raised with \f3*((size_t*)value)\fP being the amount of data still in the buffer. If the return value of \f3exceptf\fP is non-negative, the push or pop operation will continue normally; otherwise, \f3sfdisc()\fP returns failure. .Tp -\f3SF_DPOLL\fP: +\f3SFIO_DPOLL\fP: This event is raised by \f3sfpoll()\fP to see if the stream is ready for I/O. \f3*((int*)value)\fP indicates a time-out interval to wait. @@ -1659,32 +1659,32 @@ A negative return value from the exception function means blocking. A zero return value means that \f3sfpoll()\fP should query the underlying file descriptor. A positive return value means non-blocking. In addition, -this value will be a bit combination of \f3SF_READ\fP and \f3SF_WRITE\fP +this value will be a bit combination of \f3SFIO_READ\fP and \f3SFIO_WRITE\fP to indicate what I/O modes are ready. .Tp -\f3SF_READY\fP: +\f3SFIO_READY\fP: This event is raised by \f3sfpoll()\fP for each ready stream. The third argument to the event handler is an integer composed with -the two bits \f3SF_READ\fP and \f3SF_WRITE\fP to indicate which +the two bits \f3SFIO_READ\fP and \f3SFIO_WRITE\fP to indicate which I/O modes are ready. .Tp -\f3SF_SYNC\fP, \f3SF_PURGE\fP: -If \f3SF_IOCHECK\fP is set, +\f3SFIO_SYNC\fP, \f3SFIO_PURGE\fP: +If \f3SFIO_IOCHECK\fP is set, these events are raised respectively for a \f3sfsync()\fP or \f3sfpurge()\fP call. In each case, the respective event is raised once before the appropriate operation (synchronization or purging) with \f3((int)value)\fP being \f31\fP and once after with \f3((int)value)\fP being \f30\fP. Note that \f3sfsync()\fP is called for each -\f3SF_WRITE\fP or \f3SF_SHARE|SF_READ\fP stream on closing. +\f3SFIO_WRITE\fP or \f3SFIO_SHARE|SFIO_READ\fP stream on closing. .Tp -\f3SF_ATEXIT\fP: +\f3SFIO_ATEXIT\fP: This event is raised for each open stream before the process exits. .Ss " int sfraise(Sfio_t* f, int type, void* data)" If \f3f\fP is non-\f3NULL\fP, \f3sfraise()\fP calls all exception handlers of \f3f\fP with the event \f3type\fP and associated \f3data\fP. If an exception handler returns a non-zero value, \f3sfraise()\fP immediate returns the same value. -Application-defined events should start from the value \f3SF_EVENT\fP +Application-defined events should start from the value \f3SFIO_EVENT\fP so as to avoid confusion with system-defined events, \f3sfraise()\fP returns \f30\fP on success and \f3-1\fP on failure. @@ -1715,14 +1715,14 @@ This function sets control flags for the stream \f3f\fP. It returns the previous set of flags or \f30\fP on error. Settable flags are: -\f3SF_READ\fP, \f3SF_WRITE\fP, \f3SF_IOCHECK\fP, -\f3SF_LINE\fP, \f3SF_SHARE\fP, \f3SF_PUBLIC\fP, \f3SF_MALLOC\fP and -\f3SF_STATIC\fP. -Note that \f3SF_READ\fP and \f3SF_WRITE\fP can be turned on or off only -if the stream was opened as \f3SF_READ|SF_WRITE\fP. +\f3SFIO_READ\fP, \f3SFIO_WRITE\fP, \f3SFIO_IOCHECK\fP, +\f3SFIO_LINE\fP, \f3SFIO_SHARE\fP, \f3SFIO_PUBLIC\fP, \f3SFIO_MALLOC\fP and +\f3SFIO_STATIC\fP. +Note that \f3SFIO_READ\fP and \f3SFIO_WRITE\fP can be turned on or off only +if the stream was opened as \f3SFIO_READ|SFIO_WRITE\fP. Turning off one of them means that the stream is to be treated exclusively in the other mode. It is not possible to turn off both. -If legal, an attempt to turn on either \f3SF_READ\fP or \f3SF_WRITE\fP +If legal, an attempt to turn on either \f3SFIO_READ\fP or \f3SFIO_WRITE\fP will cause the stream to be in the given I/O mode. .Tp \f3set == 0:\fP @@ -1739,7 +1739,7 @@ specified flags. .Ss " int sfsetfd(Sfio_t* f, int fd)" This function changes the file descriptor of \f3f\fP. Before a change is realized, -\f3(*notify)(f,SF_SETFD,newfd)\fP (see \f3sfnotify()\fP) is called. +\f3(*notify)(f,SFIO_SETFD,newfd)\fP (see \f3sfnotify()\fP) is called. \f3sfsetfd()\fP returns \f3-1\fP on failure and the new file descriptor on success. .Tp \f3fd >= 0\fP: @@ -1771,7 +1771,7 @@ This is the base stream of the stack. If it is \f3NULL\fP, \f3sfstack()\fP does nothing and returns \f3top\fP. .Tp \f3top\fP: -If this is \f3SF_POPSTACK\fP or \f3NULL\fP, +If this is \f3SFIO_POPSTACK\fP or \f3NULL\fP, the stack is popped and \f3sfstack()\fP returns the popped stream. Otherwise, \f3top\fP is pushed on top of the stack identified by \f3base\fP and \f3sfstack()\fP returns the \f3base\fP stream. @@ -1779,7 +1779,7 @@ and \f3sfstack()\fP returns the \f3base\fP stream. Makes the string in a Sfio string buffer ready for use and makes the buffer ready for reuse. This is done by writing a terminating 0 byte to the given -.B SF_STRING +.B SFIO_STRING buffer, setting the I/O position to the start of the buffer so that subsequent write operations will overwrite it, and returning a pointer to the beginning of the string. @@ -1796,7 +1796,7 @@ If \f3f\fP is not seekable or if its size is not determinable, \f3sfsize()\fP returns \f3-1\fP. .Ss " Sfoff_t sftell(Sfio_t* f)" This function returns the current I/O position in stream \f3f\fP. -Note that if \f3f\fP is \f3SF_APPEND\fP +Note that if \f3f\fP is \f3SFIO_APPENDWR\fP and a writing operation was just performed, the current I/O position is at the physical end of file. If \f3f\fP is unseekable, \f3sftell\fP returns the number of bytes @@ -1829,21 +1829,21 @@ This sets a function \f3(*notify)()\fP to be called as \f3(*notify)(f, type, data)\fP on various stream events. Arguments \f3type\fP and \f3data\fP indicate the reason for the call and accompanying data: .Tp -\f3SF_NEW\fP: +\f3SFIO_NEW\fP: \f3f\fP is being opened and \f3data\fP is the underlying file descriptor. .Tp -\f3SF_CLOSING\fP (\f3SF_CLOSE\fP): +\f3SFIO_CLOSING\fP: \f3f\fP is the stream being closed and \f3data\fP is the underlying file descriptor. .Tp -\f3SF_SETFD\fP: +\f3SFIO_SETFD\fP: The file descriptor of \f3f\fP is being changed to the one defined by \f3data\fP (see \f3sfsetfd()\fP). .Tp -\f3SF_READ\fP: +\f3SFIO_READ\fP: An attempt to change \f3f\fP to read mode failed. \f3data\fP is the file descriptor of the stream. .Tp -\f3SF_WRITE\fP: +\f3SFIO_WRITE\fP: An attempt to change \f3f\fP to write mode failed. \f3data\fP is the file descriptor of the stream. .Ss " int sfwalk(Sfwalk_f walkf, void* data, int type)" @@ -1853,8 +1853,8 @@ On such a call, if the return value is negative, \f3sfwalk()\fP will terminate. \f3sfwalk()\fP returns 0 if no stream was processed. Otherwise, it returns the return value from the last invocation of \f3walkf()\fP. -As an example, the call \f3sfwalk(walkf, data, SF_READ)\fP will iterate over all streams -opened for reading. Similarly, \f3sfwalk(walkf, data, SF_READ|SF_WRITE)\fP +As an example, the call \f3sfwalk(walkf, data, SFIO_READ)\fP will iterate over all streams +opened for reading. Similarly, \f3sfwalk(walkf, data, SFIO_READ|SFIO_WRITE)\fP iterates over all streams opened for both reading and writing. Lastly, \f3sfwalk(walkf, data, 0)\fP iterates over all streams. .Ss "MISCELLANEOUS FUNCTIONS" @@ -1986,7 +1986,7 @@ The latter are typically declared of the type \f3Sfio_t*\fP. Certain older Stdio applications require these to be declared as addresses of structures so that static initializations of the sort ``\f3FILE*\ f\ =\ stdin;\fP'' would work. -Such applications should use the compile time flag \f3SF_FILE_STRUCT\fP +Such applications should use the compile time flag \f3SFIO_FILE_STRUCT\fP to achieve the desired effect. .PP Below are the supported Stdio functions: diff --git a/src/lib/libast/man/stk.3 b/src/lib/libast/man/stk.3 index cfc2959adb71..2a88017de324 100644 --- a/src/lib/libast/man/stk.3 +++ b/src/lib/libast/man/stk.3 @@ -4,24 +4,30 @@ \fBstk\fR \- data stack storage library .SH SYNOPSIS .ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i +.de Ss +.fl +.ne 3 +.SS "\\$1" +.. .PP .nf \f3 #include Stk_t *stkopen(int \fIflags\fP); +void stkoverflow(Stk_t *\fIstack\fP, void *(\fIoverflow\fP)(size_t)); Stk_t *stkinstall(Stk_t *\fIstack\fP, char *(\fIoverflow\fP)(size_t)); int stkclose(Stk_t *\fIstack\fP); unsigned int stklink(Stk_t *\fIstack\fP) -char *stkalloc(Stk_t *\fIstack\fP, unsigned \fIsize\fP); +void *stkalloc(Stk_t *\fIstack\fP, unsigned \fIsize\fP); char *stkcopy(Stk_t *\fIstack\fP, const char *\fIstring\fP); -char *stkset(Stk_t *\fIstack\fP, char *\fIaddress\fP, unsigned \fIoffset\fP); +void *stkset(Stk_t *\fIstack\fP, void *\fIaddress\fP, unsigned \fIoffset\fP); -char *stkseek(Stk_t *\fIstack\fP, unsigned \fIoffset\fP); +void *stkseek(Stk_t *\fIstack\fP, unsigned \fIoffset\fP); int stktell(Stk_t *\fIstack\fP); char *stkptr(Stk_t *\fIstack\fP, unsigned \fIoffset\fP); -char *stkfreeze(Stk_t *\fIstack\fP, unsigned \fIextra\fP); +void *stkfreeze(Stk_t *\fIstack\fP, unsigned \fIextra\fP); int stkon(Stk *\fIstack\fP, char* \fIaddr\fP) \fR .fi @@ -33,16 +39,15 @@ A stack abstraction consists of an ordered list of contiguous memory regions, called stack frames, that can hold objects of arbitrary size. A stack is represented by the type \f3Stk_t\fP -defined in header \f3\fP. +defined in the header \f3\fP. The type \f3Stk_t\fP is compatible with the type \f3Sfio_t\fP defined by the \f3sfio\fP(3) library. +There is a preset initial stack which can be referenced +by the constant \f3stkstd\fP (stack standard). .PP -At any instant there is one active stack which can be referenced -by the constant \f3stkstd\fP. -Variable size objects can be -added to the active stack +Objects of variable size can be +added to a stack, and programs can reference these objects directly with pointers. -.PP In addition, the last object on the stack (referred to here as the current object) can be built incrementally. @@ -53,50 +58,72 @@ its location might change so that it is necessary to reference the object with relative offsets ranging from zero to the current offset of the object. .PP -There is a preset initial active stack. -To use an additional stack, it is necessary to create it and to -install it as the active stack. +The \f3sfio\fP(3) output functions can be used to build +the current object incrementally. +An object that is built incrementally on the stack will +always occupy contiguous memory within a stack frame, +but until \f3stkfreeze\fP() is called, +the location in memory for the object can change. +There is a current offset associated with the current object that +determines where subsequent operations apply. +Initially, this offset is zero, and the offset changes as a result +of the operations you specify. +.Ss "Descriptions of the functions" .PP -A stack is created with the \f3stkopen\fP() function. +The \f3stkopen\fP() function creates a new stack. The \fIflags\fP argument is an options bitmask. If the \f3STK_SMALL\fP bit is set, the stack allocates memory in -small blocks, optimizing for memory usage at the expense of performance. +small blocks, optimizing memory usage at the expense of performance. If the \f3STK_NULL\fP bit is set, a stack overflow will cause stack operations to return a null pointer instead of throwing an exception. +If the \f3STK_NULL\fP bit is not set and the \f3stkstd\fP stack has +a custom overflow function set (see \f3stkoverflow\fP() below), +then the new stack inherits the pointer to that overflow function. If successful, \f3stkopen\fP() returns a pointer to a stack whose reference count is 1. Otherwise, \f3stkopen\fP() returns a null pointer. .PP -The \f3stklink\fP() function increases the reference count for the -given \fIstack\fP and returns the increased count. -.PP -The \f3stkinstall\fP() function -makes the specified \fIstack\fP the active stack and returns a pointer -to the previous active stack. -If the \fIoverflow\fP argument is not null and the stack was not opened with -the \f3STK_NULL\fP option, \fIoverflow\fP specifies a function that will +The \f3stkoverflow\fP() function specifies a function that will be called whenever \f3malloc\fP(3) fails while trying to grow the stack. The \fIoverflow\fP function will be called with the size that was passed to \f3malloc\fP(3). The \fIoverflow\fP function can call \f3exit\fP(3), call \f3longjmp\fP(3) or return. -If the \f3overflow\fP function returns, +If the \f2overflow\fP function returns, it must return a pointer to a memory region of the given size. -The default action is to write an error to standard error and to +If \f2overflow\fP is \f3NULL\fP, then the stack overflow action +is reset to the default. +If the stack was opened with the \f3STK_NULL\fP option, +the default is to return a null pointer, +otherwise the default is to write an error to standard error and to call \f3exit\fP(2) with a non-zero exit value. +.PP +The \f3stkinstall\fP() function +is deprecated and provided for backward compatibility. +\f3stkinstall\fP() makes \f3stkstd\fP refer to the specified \fIstack\fP pointer +and returns a pointer to the previous \f3stkstd\fP stack. +If the \fIoverflow\fP argument is not null and the stack was not opened with +the \f3STK_NULL\fP option, then \fIoverflow\fP sets the overflow action +(see \f3overflow\fP() above). When \fIstack\fP is a null pointer, -the active stack is not changed -but the \fIoverflow\fP function for the active stack can be changed -and a pointer to the active stack is returned. +the \f3stkstd\fP stack is not changed +but the \fIoverflow\fP function for the \f3stkstd\fP stack can be changed +and a pointer to the \f3stkstd\fP stack is returned. +(Current usage is simply +passing the pointer to the desired stack to the \f3stk\fP functions, +and using \f3stkoverflow\fP() to set the stack overflow function). .PP The \f3stkclose\fP() function decrements the reference count and frees the memory associated with the specified stack when the reference count is zero. The effect of subsequent references to objects -on the stack are undefined. +on the stack is undefined. +.PP +The \f3stklink\fP() function increases the reference count for the +given \fIstack\fP and returns the increased count. .PP The \f3stkalloc\fP() function returns an aligned pointer to space on the @@ -122,17 +149,6 @@ If \fIaddress\fP is null, the stack is reset to the beginning. If it is non-null, but is not the address of an object on the stack, the program aborts and dumps core. .PP -The \f3sfio\fP(3) output functions can be used to build -current object incrementally. -An object that is built incrementally on the stack will -always occupy contiguous memory within a stack frame but -until \f3stkfreeze\fP() is called, -the location in memory for the object can change. -There is a current offset associated with the current object that -determines where subsequent operations apply. -Initially, this offset is zero, and the offset changes as a result -of the operations you specify. -.PP The \f3stkseek\fP() function is used set the offset for the current object. The \fIoffset\fP argument to \f3stkseek\fP() specifies the new @@ -149,6 +165,9 @@ for the current object into a memory address on the stack. This address is only valid until another stack operation is given. The result is not defined if \fIoffset\fP exceeds the size of the current object. +This function returns a \f3char\fP pointer instead of \f3void\fP pointer +to make it easy to dereference the return value directly and read +an individual byte on the stack. .PP The \f3stkfreeze\fP() function terminates the current object on the @@ -167,10 +186,17 @@ interface was derived from similar routines in the KornShell code that is used for building parse trees and carrying out expansions. It provides an efficient mechanism for grouping dynamically allocated objects so that they can be freed all at once rather than individually. +.PP +In 2024, as part of changes made by +Martijn Dekker for ksh 93u+m, +the return types of \f3stkalloc\fP(), \f3stkset\fP(), \f3stkseek\fP() and +\f3stkfreeze\fP() were changed from \f3char*\fP to \f3void*\fP, +the \f3stkoverflow\fP() function was added, +and the \f3stkinstall\fP() function was deprecated. .SH AUTHOR - David Korn +David Korn .SH SEE ALSO -\f3exit(2)\fP -\f3longjmp(3)\fP -\f3malloc(3)\fP -\f3sfio(3)\fP +\f3exit\fP(2), +\f3longjmp\fP(3), +\f3malloc\fP(3), +\f3sfio\fP(3) diff --git a/src/lib/libast/man/tok.3 b/src/lib/libast/man/tok.3 index a1fcbc25640b..680664d077fc 100644 --- a/src/lib/libast/man/tok.3 +++ b/src/lib/libast/man/tok.3 @@ -195,12 +195,12 @@ This is done by pushing an discipline onto a string or file stream. Seeks are disabled on the resulting stream. If -.L "flags == SF_READ" +.L "flags == SFIO_READ" then .L input is a file name; If -.L "flags == SF_STRING" +.L "flags == SFIO_STRING" then .L input is a 0 terminated string; diff --git a/src/lib/libast/man/vecargs.3 b/src/lib/libast/man/vecargs.3 deleted file mode 100644 index c003b229ef36..000000000000 --- a/src/lib/libast/man/vecargs.3 +++ /dev/null @@ -1,126 +0,0 @@ -.fp 5 CW -.de Af -.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2 -.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" -.. -.de aF -.ie \\$3 .ft \\$1 -.el \{\ -.ds ;G \& -.nr ;G \\n(.f -.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" -\\*(;G -.ft \\n(;G \} -.. -.de L -.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" -.. -.de LR -.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" -.. -.de RL -.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" -.. -.de EX \" start example -.ta 1i 2i 3i 4i 5i 6i -.PP -.RS -.PD 0 -.ft 5 -.nf -.. -.de EE \" end example -.fi -.ft -.PD -.RE -.PP -.. -.TH VECARGS 3 -.SH NAME -vecargs \- command argument vector insertion routines -.SH SYNOPSIS -.L "#include " -.sp -.L "char** vecload(char* string);" -.L "char** vecfile(const char* path);" -.L "char** vecstring(const char* string);" -.L "void vecfree(char**, int);" -.L "int vecargs(char** vec, int* argcp, char*** argvp);" -.SH DESCRIPTION -.L vecload -loads a string vector from lines in -.LR string . -.L string -may be modified upon return. -Each line in -.L string -is treated as a new vector element. -Lines with -.L # -as the first character are comments. -.I \enewline -joins consecutive lines. -A string vector pointer is returned, 0 on error. -.PP -.L vecfile -constructs a string vector by calling -.L vecload -on the contents of the file named by -.LR path . -The string vector pointer is returned, 0 on error. -.PP -.L vecstring -constructs a string vector by calling -.L vecload -on a copy of -.LR string . -The string vector pointer is returned, 0 on error. -.PP -.L vecfree -frees a string vector allocated by -.LR vecfile , -.L vecload -or -.LR vecstring . -.PP -.L vecargs -inserts the string vector -.L vec -(as returned by -.LR vecfile , -.L vecload -or -.LR vecstring ) -between -.L "(*argvp)[0]" -and -.LR "(*argvp)[1]" , -sliding -.L "(*argvp)[1] ..." -over. -NULL and empty string args in -.L vec -are not copied. -.L "vecfree(vec)" -is called before the return. -.L \-1 -is returned if the insertion failed. -.SH EXAMPLES -.L vecargs -is commonly used to modify command -.L argv -from fixed files. -For example, -.IR make (1) -checks for the files -.L ./Makeargs -and -.L ./makeargs -to modify its arguments on startup. -Its a handy way to override default options on a directory by directory basis -without modify the standard control files -(\f3Makefile\fP in this case). -.SH CAVEATS -This paradigm is not recommended for all commands; only a few exceptions -make sense. diff --git a/src/lib/libast/misc/fastfind.c b/src/lib/libast/misc/fastfind.c index 6b7660d62411..b5f316f10519 100644 --- a/src/lib/libast/misc/fastfind.c +++ b/src/lib/libast/misc/fastfind.c @@ -299,7 +299,7 @@ findopen(const char* file, const char* pattern, const char* type, Finddisc_t* di } if (s) *s = '/'; - if (!(fp->fp = sfnew(NULL, NULL, (size_t)SF_UNBOUND, fd, SF_WRITE))) + if (!(fp->fp = sfnew(NULL, NULL, (size_t)SFIO_UNBOUND, fd, SFIO_WRITE))) { if (fp->disc->errorf) (*fp->disc->errorf)(fp, fp->disc, ERROR_SYSTEM|2, "%s: cannot open tmp file", fp->encode.temp); @@ -1219,7 +1219,7 @@ findsync(Find_t* fp) * append the front compressed strings */ - if (sfmove(fp->fp, sp, SF_UNBOUND, -1) < 0 || !sfeof(fp->fp)) + if (sfmove(fp->fp, sp, SFIO_UNBOUND, -1) < 0 || !sfeof(fp->fp)) { sfclose(sp); if (fp->disc->errorf) diff --git a/src/lib/libast/misc/glob.c b/src/lib/libast/misc/glob.c index bb9a0293e6d1..88a8523f95db 100644 --- a/src/lib/libast/misc/glob.c +++ b/src/lib/libast/misc/glob.c @@ -73,6 +73,8 @@ typedef int (*GL_stat_f)(const char*, struct stat*); #include +static Stk_t *globstk = stkstd; + /* * default gl_diropen */ @@ -158,7 +160,7 @@ static char* gl_nextdir(glob_t* gp, char* dir) { if (!(dir = gp->gl_nextpath)) - dir = gp->gl_nextpath = stkcopy(stkstd,pathbin()); + dir = gp->gl_nextpath = stkcopy(globstk,pathbin()); switch (*gp->gl_nextpath) { case 0: @@ -237,46 +239,46 @@ addmatch(glob_t* gp, const char* dir, const char* pat, const char* rescan, char* int offset; int type; - stkseek(stkstd,MATCHPATH(gp)); + stkseek(globstk,MATCHPATH(gp)); if (dir) { - sfputr(stkstd,dir,-1); - sfputc(stkstd,gp->gl_delim); + sfputr(globstk,dir,-1); + sfputc(globstk,gp->gl_delim); } if (endslash) *endslash = 0; - sfputr(stkstd,pat,-1); + sfputr(globstk,pat,-1); if (rescan) { - if ((*gp->gl_type)(gp, stkptr(stkstd,MATCHPATH(gp)), 0) != GLOB_DIR) + if ((*gp->gl_type)(gp, stkptr(globstk,MATCHPATH(gp)), 0) != GLOB_DIR) return; - sfputc(stkstd,gp->gl_delim); - offset = stktell(stkstd); + sfputc(globstk,gp->gl_delim); + offset = stktell(globstk); /* if null, reserve room for . */ if (*rescan) - sfputr(stkstd,rescan,-1); + sfputr(globstk,rescan,-1); else - sfputc(stkstd,0); - sfputc(stkstd,0); - rescan = stkptr(stkstd,offset); - ap = (globlist_t*)stkfreeze(stkstd,0); + sfputc(globstk,0); + sfputc(globstk,0); + rescan = stkptr(globstk,offset); + ap = stkfreeze(globstk,0); ap->gl_begin = (char*)rescan; ap->gl_next = gp->gl_rescan; gp->gl_rescan = ap; } else { - if (!endslash && (gp->gl_flags & GLOB_MARK) && (type = (*gp->gl_type)(gp, stkptr(stkstd,MATCHPATH(gp)), 0))) + if (!endslash && (gp->gl_flags & GLOB_MARK) && (type = (*gp->gl_type)(gp, stkptr(globstk,MATCHPATH(gp)), 0))) { if ((gp->gl_flags & GLOB_COMPLETE) && type != GLOB_EXE) { - stkseek(stkstd,0); + stkseek(globstk,0); return; } else if (type == GLOB_DIR && (gp->gl_flags & GLOB_MARK)) - sfputc(stkstd,gp->gl_delim); + sfputc(globstk,gp->gl_delim); } - ap = (globlist_t*)stkfreeze(stkstd,1); + ap = stkfreeze(globstk,1); ap->gl_next = gp->gl_match; gp->gl_match = ap; gp->gl_pathc++; @@ -697,7 +699,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t } skip = gp->gl_pathc; if (gp->gl_stak) - oldstak = stkinstall(gp->gl_stak, 0); + oldstak = globstk, globstk = gp->gl_stak; if (flags & GLOB_DOOFFS) extra += gp->gl_offs; if (gp->gl_suffix) @@ -761,7 +763,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t break; } } - top = ap = (globlist_t*)stkalloc(stkstd,(optlen ? 2 : 1) * strlen(pattern) + sizeof(globlist_t) + suflen + gp->gl_extra); + top = ap = stkalloc(globstk,(optlen ? 2 : 1) * strlen(pattern) + sizeof(globlist_t) + suflen + gp->gl_extra); ap->gl_next = 0; ap->gl_flags = 0; ap->gl_begin = ap->gl_path + gp->gl_extra; @@ -799,7 +801,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t gp->gl_list = gp->gl_match; else { - argv = (char**)stkalloc(stkstd,(gp->gl_pathc + extra) * sizeof(char*)); + argv = stkalloc(globstk,(gp->gl_pathc + extra) * sizeof(char*)); if (gp->gl_flags & GLOB_APPEND) { skip += --extra; @@ -832,7 +834,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t if (gp->gl_starstar > 1) gp->gl_flags &= ~GLOB_STARSTAR; if (gp->gl_stak) - stkinstall(oldstak, 0); + globstk = oldstak; return gp->gl_error; } diff --git a/src/lib/libast/misc/magic.c b/src/lib/libast/misc/magic.c index dfc421229890..c2c06f84c3f1 100644 --- a/src/lib/libast/misc/magic.c +++ b/src/lib/libast/misc/magic.c @@ -151,8 +151,8 @@ typedef unsigned long Cctype_t; Entry_t* magiclast; /* last entry in magic */ \ char* mime; /* MIME type */ \ unsigned char* x2n; /* CC_ALIEN=>CC_NATIVE */ \ - char fbuf[SF_BUFSIZE + 1]; /* file data */ \ - char xbuf[SF_BUFSIZE + 1]; /* indirect file data */ \ + char fbuf[SFIO_BUFSIZE + 1]; /* file data */ \ + char xbuf[SFIO_BUFSIZE + 1]; /* indirect file data */ \ char nbuf[256]; /* !CC_NATIVE data */ \ char mbuf[64]; /* mime string */ \ char sbuf[64]; /* type suffix string */ \ @@ -291,7 +291,7 @@ getdata(Magic_t* mp, long off, int siz) { if (off + siz > mp->fbmx) return NULL; - n = (off / (SF_BUFSIZE / 2)) * (SF_BUFSIZE / 2); + n = (off / (SFIO_BUFSIZE / 2)) * (SFIO_BUFSIZE / 2); if (sfseek(mp->fp, n, SEEK_SET) != n) return NULL; if ((mp->xbsz = sfread(mp->fp, mp->xbuf, sizeof(mp->xbuf) - 1)) < 0) @@ -1241,11 +1241,11 @@ cklang(Magic_t* mp, const char* file, char* buf, char* end, struct stat* st) mp->mime = "application/x-tex"; goto qualify; } - if (mp->fbsz < SF_BUFSIZE && + if (mp->fbsz < SFIO_BUFSIZE && (mp->multi['('] == mp->multi[')'] && mp->multi['{'] == mp->multi['}'] && mp->multi['['] == mp->multi[']']) || - mp->fbsz >= SF_BUFSIZE && + mp->fbsz >= SFIO_BUFSIZE && (mp->multi['('] >= mp->multi[')'] && mp->multi['{'] >= mp->multi['}'] && mp->multi['['] >= mp->multi[']'])) @@ -1295,8 +1295,8 @@ cklang(Magic_t* mp, const char* file, char* buf, char* end, struct stat* st) } } if (mp->identifier[ID_MAM1] >= 2 && mp->identifier[ID_MAM3] >= 2 && - (mp->fbsz < SF_BUFSIZE && mp->identifier[ID_MAM1] == mp->identifier[ID_MAM2] || - mp->fbsz >= SF_BUFSIZE && mp->identifier[ID_MAM1] >= mp->identifier[ID_MAM2])) + (mp->fbsz < SFIO_BUFSIZE && mp->identifier[ID_MAM1] == mp->identifier[ID_MAM2] || + mp->fbsz >= SFIO_BUFSIZE && mp->identifier[ID_MAM1] >= mp->identifier[ID_MAM2])) { id_mam: s = T("mam program"); diff --git a/src/lib/libast/misc/mime.c b/src/lib/libast/misc/mime.c index f9243921c9d0..a65fbb00c067 100644 --- a/src/lib/libast/misc/mime.c +++ b/src/lib/libast/misc/mime.c @@ -314,7 +314,7 @@ mimeload(Mime_t* mp, const char* file, unsigned long flags) if (!(s = sfstruse(mp->buf))) return -1; } - if (fp = tokline(s, SF_READ, NULL)) + if (fp = tokline(s, SFIO_READ, NULL)) { while (t = sfgetr(fp, '\n', 1)) if (mimeset(mp, t, flags)) diff --git a/src/lib/libast/misc/optget.c b/src/lib/libast/misc/optget.c index 846d3853d3e1..211dd8e20a53 100644 --- a/src/lib/libast/misc/optget.c +++ b/src/lib/libast/misc/optget.c @@ -206,8 +206,9 @@ static const List_t help_head[] = C("\b-?\b and \b--?\b* options are the same \ for all \bAST\b commands. For any \aitem\a below, if \b--\b\aitem\a is not \ supported by a given command then it is equivalent to \b--\?\?\b\aitem\a. The \ -\b--\?\?\b form should be used for portability. All output is written to the \ -standard error."), +\b--\?\?\b form should be used for portability. \ +All output is written to the standard error. \ +Note that question marks should be quoted to avoid pathanme expansion."), }; static const Help_t styles[] = @@ -255,8 +256,11 @@ static const List_t help_tail[] = the \aoption\a output in the \aitem\a style. Otherwise print \ \bversion=\b\an\a where \an\a>0 if \b--\?\?\b\aitem\a is supported, \b0\b \ if not."), + ':', C("\?\?\?\?\?\?EMPHASIS"), + C("Equivalent to \b--\?\?\?ESC\b."), ':', C("\?\?\?\?\?\?ESC"), - C("Emit escape codes even if output is not a terminal."), + C("Emit ANSI escape codes for emphasis even if standard error is not on a terminal. \ +Use \b--\?\?noESC\b to emit no escape codes even if standard error is on a terminal."), ':', C("\?\?\?\?\?\?MAN[=\asection\a]]"), C("List the \bman\b(1) section title for \asection\a [the \ current command]]."), @@ -2514,21 +2518,22 @@ opthelp(const char* oopts, const char* what) sfputc(mp, '\f'); break; default: - state.emphasis = 0; - if (x = getenv("ERROR_OPTIONS")) + if (!state.emphasis) { - if (strmatch(x, "*noemphasi*")) - break; - if (strmatch(x, "*emphasi*")) + if (x = getenv("ERROR_OPTIONS")) { - state.emphasis = 1; - break; + if (strmatch(x, "*noemphasi*")) + break; + if (strmatch(x, "*emphasi*")) + { + state.emphasis = 1; + break; + } } + if (isatty(sffileno(sfstderr)) && (x = getenv("TERM")) + && strmatch(x, "(ansi|cons|dtterm|linux|screen|sun|vt???|wsvt|xterm)*")) + state.emphasis = 1; } - if (isatty(sffileno(sfstderr)) - && (x = getenv("TERM")) - && strmatch(x, "(ansi|cons|dtterm|linux|screen|sun|vt???|wsvt|xterm)*")) - state.emphasis = 1; break; } x = ""; @@ -4301,6 +4306,7 @@ optget(char** argv, const char* oopts) if (!oopts) return 0; + state.emphasis = 0; state.pindex = opt_info.index; state.poffset = opt_info.offset; if (!opt_info.index) diff --git a/src/lib/libast/misc/stk.c b/src/lib/libast/misc/stk.c index ea103b44034d..a009a95f9bd1 100644 --- a/src/lib/libast/misc/stk.c +++ b/src/lib/libast/misc/stk.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -53,12 +53,13 @@ #define STK_FSIZE (1024*sizeof(char*)) #define STK_HDRSIZE (sizeof(Sfio_t)+sizeof(Sfdisc_t)) -typedef char* (*_stk_overflow_)(size_t); +typedef void* (*_stk_overflow_)(size_t); +typedef char* (*_old_stk_overflow_)(size_t); /* for stkinstall (deprecated) */ static int stkexcept(Sfio_t*,int,void*,Sfdisc_t*); static Sfdisc_t stkdisc = { 0, 0, 0, stkexcept }; -Sfio_t _Stak_data = SFNEW(NULL,0,-1,SF_STATIC|SF_WRITE|SF_STRING,&stkdisc); +Sfio_t _Stak_data = SFNEW(NULL,0,-1,SFIO_STATIC|SFIO_WRITE|SFIO_STRING,&stkdisc); struct frame { @@ -86,40 +87,16 @@ static char *stkgrow(Sfio_t*, size_t); #define stk2stream(sp) ((Sfio_t*)(((char*)(sp))-STK_HDRSIZE)) #define stkleft(stream) ((stream)->_endb-(stream)->_data) - -#ifdef STKSTATS - static struct - { - int create; - int delete; - int install; - int alloc; - int copy; - int puts; - int seek; - int set; - int grow; - int addsize; - int delsize; - int movsize; - } _stkstats; -# define increment(x) (_stkstats.x++) -# define count(x,n) (_stkstats.x += (n)) -#else -# define increment(x) -# define count(x,n) -#endif /* STKSTATS */ - -static const char Omsg[] = "malloc failed while growing stack\n"; +static const char Omsg[] = "out of memory while growing stack\n"; /* * default overflow exception */ -static noreturn char *overflow(size_t n) +static noreturn void *overflow(size_t n) { NoP(n); write(2,Omsg, sizeof(Omsg)-1); - exit(2); + exit(128); UNREACHABLE(); } @@ -132,7 +109,7 @@ static void stkinit(size_t size) init = size; sp = stkopen(0); init = 1; - stkinstall(sp,overflow); + stkinstall(sp,(_old_stk_overflow_)overflow); } static int stkexcept(Sfio_t *stream, int type, void* val, Sfdisc_t* dp) @@ -141,14 +118,13 @@ static int stkexcept(Sfio_t *stream, int type, void* val, Sfdisc_t* dp) NoP(val); switch(type) { - case SF_CLOSING: + case SFIO_CLOSING: { struct stk *sp = stream2stk(stream); char *cp = sp->stkbase; struct frame *fp; if(--sp->stkref == 0) { - increment(delete); if(stream==stkstd) stkset(stream,NULL,0); else @@ -172,13 +148,13 @@ static int stkexcept(Sfio_t *stream, int type, void* val, Sfdisc_t* dp) stream->_data = stream->_next = 0; } return 0; - case SF_FINAL: + case SFIO_FINAL: free(stream); return 1; - case SF_DPOP: + case SFIO_DPOP: return -1; - case SF_WRITE: - case SF_SEEK: + case SFIO_WRITE: + case SFIO_SEEK: { long size = sfvalue(stream); if(init) @@ -195,7 +171,7 @@ static int stkexcept(Sfio_t *stream, int type, void* val, Sfdisc_t* dp) stkinit(size); } return 1; - case SF_NEW: + case SFIO_NEW: return -1; } return 0; @@ -214,13 +190,11 @@ Sfio_t *stkopen(int flags) char *cp; if(!(stream=newof(NULL,Sfio_t, 1, sizeof(*dp)+sizeof(*sp)))) return NULL; - increment(create); - count(addsize,sizeof(*stream)+sizeof(*dp)+sizeof(*sp)); dp = (Sfdisc_t*)(stream+1); dp->exceptf = stkexcept; sp = (struct stk*)(dp+1); sp->stkref = 1; - sp->stkflags = (flags&STK_SMALL); + sp->stkflags = flags; if(flags&STK_NULL) sp->stkoverflow = 0; else sp->stkoverflow = stkcur?stkcur->stkoverflow:overflow; bsize = init+sizeof(struct frame); @@ -234,14 +208,13 @@ Sfio_t *stkopen(int flags) free(stream); return NULL; } - count(addsize,sizeof(*fp)+bsize); cp = (char*)(fp+1); sp->stkbase = (char*)fp; fp->prev = 0; fp->nalias = 0; fp->aliases = 0; fp->end = sp->stkend = cp+bsize; - if(!sfnew(stream,cp,bsize,-1,SF_STRING|SF_WRITE|SF_STATIC|SF_EOF)) + if(!sfnew(stream,cp,bsize,-1,SFIO_STRING|SFIO_WRITE|SFIO_STATIC|SFIO_EOF)) return NULL; sfdisc(stream,dp); return stream; @@ -252,7 +225,7 @@ Sfio_t *stkopen(int flags) * if is not null, it becomes the new current stack * becomes the new overflow function */ -Sfio_t *stkinstall(Sfio_t *stream, _stk_overflow_ oflow) +Sfio_t *stkinstall(Sfio_t *stream, _old_stk_overflow_ oflow) { Sfio_t *old; struct stk *sp; @@ -260,15 +233,14 @@ Sfio_t *stkinstall(Sfio_t *stream, _stk_overflow_ oflow) { stkinit(1); if(oflow) - stkcur->stkoverflow = oflow; + stkcur->stkoverflow = (_stk_overflow_)oflow; return NULL; } - increment(install); old = stkcur?stk2stream(stkcur):0; if(stream) { sp = stream2stk(stream); - while(sfstack(stkstd, SF_POPSTACK)); + while(sfstack(stkstd, SFIO_POPSTACK)); if(stream!=stkstd) sfstack(stkstd,stream); stkcur = sp; @@ -276,10 +248,22 @@ Sfio_t *stkinstall(Sfio_t *stream, _stk_overflow_ oflow) else sp = stkcur; if(oflow) - sp->stkoverflow = oflow; + sp->stkoverflow = (_stk_overflow_)oflow; return old; } +/* + * set or unset the overflow function + */ +void stkoverflow(Sfio_t *stream, _stk_overflow_ oflow) +{ + struct stk *sp; + if(!init) + stkinit(1); + sp = stream2stk(stream); + sp->stkoverflow = oflow ? oflow : (sp->stkflags & STK_NULL ? NULL : overflow); +} + /* * increase the reference count on the given */ @@ -319,21 +303,20 @@ int stkon(Sfio_t * stream, char* loc) return 0; } /* - * reset the bottom of the current stack back to - * if is null, then the stack is reset to the beginning - * if is not in this stack, the program dumps core + * reset the bottom of the current stack back to
+ * if
is null, then the stack is reset to the beginning + * if
is not in this stack, the program dumps core * otherwise, the top of the stack is set to stkbot+ */ -char *stkset(Sfio_t * stream, char* loc, size_t offset) +void *stkset(Sfio_t *stream, void *address, size_t offset) { struct stk *sp = stream2stk(stream); - char *cp; + char *cp, *loc = (char*)address; struct frame *fp; int frames = 0; int n; if(!init) stkinit(offset+1); - increment(set); while(1) { fp = (struct frame*)sp->stkbase; @@ -376,45 +359,43 @@ char *stkset(Sfio_t * stream, char* loc, size_t offset) else stream->_data = stream->_next = (unsigned char*)cp; found: - return (char*)stream->_data; + return stream->_data; } /* * allocate bytes on the current stack */ -char *stkalloc(Sfio_t *stream, size_t n) +void *stkalloc(Sfio_t *stream, size_t n) { unsigned char *old; if(!init) stkinit(n); - increment(alloc); n = roundof(n,STK_ALIGN); if(stkleft(stream) <= (int)n && !stkgrow(stream,n)) return NULL; old = stream->_data; stream->_data = stream->_next = old+n; - return (char*)old; + return old; } /* * begin a new stack word of at least bytes */ -char *_stkseek(Sfio_t *stream, ssize_t n) +void *_stkseek(Sfio_t *stream, ssize_t n) { if(!init) stkinit(n); - increment(seek); if(stkleft(stream) <= n && !stkgrow(stream,n)) return NULL; stream->_next = stream->_data+n; - return (char*)stream->_data; + return stream->_data; } /* * advance the stack to the current top * if extra is non-zero, first add extra bytes and zero the first */ -char *stkfreeze(Sfio_t *stream, size_t extra) +void *stkfreeze(Sfio_t *stream, size_t extra) { unsigned char *old, *top; if(!init) @@ -462,7 +443,6 @@ char *stkcopy(Sfio_t *stream, const char* str) n = roundof(cp-(unsigned char*)str,STK_ALIGN); if(!init) stkinit(n); - increment(copy); if(stkleft(stream) <= n && !stkgrow(stream,n)) cp = 0; else @@ -515,8 +495,6 @@ static char *stkgrow(Sfio_t *stream, size_t size) cp = newof(dp, char, n, nn*sizeof(char*)); if(!cp && (!sp->stkoverflow || !(cp = (*sp->stkoverflow)(n)))) return NULL; - increment(grow); - count(addsize,n - (dp?m:0)); if(dp==cp) { nn--; @@ -542,10 +520,7 @@ static char *stkgrow(Sfio_t *stream, size_t size) fp->aliases[nn-1] = oldbase + roundof(sizeof(struct frame),STK_ALIGN); } if(m && !dp) - { memcpy(cp,(char*)stream->_data,m); - count(movsize,m); - } sfsetbuf(stream,cp,sp->stkend-cp); return (char*)(stream->_next = stream->_data+m); } diff --git a/src/lib/libast/path/pathicase.c b/src/lib/libast/path/pathicase.c index ad4ea9f038b4..27e95818789f 100644 --- a/src/lib/libast/path/pathicase.c +++ b/src/lib/libast/path/pathicase.c @@ -23,14 +23,14 @@ #if _hdr_linux_msdos_fs #include #endif -#if _hdr_sys_ioctl +#if _sys_ioctl #include #endif -#if _hdr_sys_ioctl && _hdr_linux_fs && defined(FS_IOC_GETFLAGS) && defined(FS_CASEFOLD_FL) +#if _sys_ioctl && _hdr_linux_fs && defined(FS_IOC_GETFLAGS) && defined(FS_CASEFOLD_FL) #define _linux_casefold 1 #endif -#if _hdr_sys_ioctl && _hdr_linux_msdos_fs && defined(FAT_IOCTL_GET_ATTRIBUTES) +#if _sys_ioctl && _hdr_linux_msdos_fs && defined(FAT_IOCTL_GET_ATTRIBUTES) #define _linux_fatfs 1 #endif diff --git a/src/lib/libast/port/astconf.c b/src/lib/libast/port/astconf.c index 3a168e98fda8..b9289a103ee5 100644 --- a/src/lib/libast/port/astconf.c +++ b/src/lib/libast/port/astconf.c @@ -1314,9 +1314,9 @@ nativeconf(Proc_t** pp, const char* operand) ops[1] = 0; if (*pp = procopen(_pth_getconf, cmd, environ, ops, PROC_READ)) { - if (sp = sfnew(NULL, NULL, SF_UNBOUND, (*pp)->rfd, SF_READ)) + if (sp = sfnew(NULL, NULL, SFIO_UNBOUND, (*pp)->rfd, SFIO_READ)) { - sfdisc(sp, SF_POPDISC); + sfdisc(sp, SFIO_POPDISC); return sp; } procclose(*pp); diff --git a/src/lib/libast/regex/regnexec.c b/src/lib/libast/regex/regnexec.c index 46ec1a55f83e..78dc9e16625f 100644 --- a/src/lib/libast/regex/regnexec.c +++ b/src/lib/libast/regex/regnexec.c @@ -150,7 +150,7 @@ vecopen(int inc, int siz) inc = 16; if (!(sp = stkopen(STK_SMALL|STK_NULL))) return NULL; - if (!(v = (Vector_t*)stkseek(sp, sizeof(Vector_t) + inc * siz))) + if (!(v = stkseek(sp, sizeof(Vector_t) + inc * siz))) { stkclose(sp); return NULL; @@ -171,7 +171,7 @@ vecseek(Vector_t** p, int index) if (index >= v->max) { while ((v->max += v->inc) <= index); - if (!(v = (Vector_t*)stkseek(v->stk, sizeof(Vector_t) + v->max * v->siz))) + if (!(v = stkseek(v->stk, sizeof(Vector_t) + v->max * v->siz))) return NULL; *p = v; v->vec = (char*)v + sizeof(Vector_t); @@ -207,7 +207,7 @@ stkpush(Stk_t* sp, size_t size) stknew(sp, &p); size = sizeof(Stk_frame_t) + sizeof(size_t) + size - 1; - if (!(f = (Stk_frame_t*)stkalloc(sp, sizeof(Stk_frame_t) + sizeof(Stk_frame_t*) + size - 1))) + if (!(f = stkalloc(sp, sizeof(Stk_frame_t) + sizeof(Stk_frame_t*) + size - 1))) return NULL; f->pos = p; stkframe(sp) = f; @@ -252,7 +252,7 @@ _matchpush(Env_t* env, Rex_t* rex) if (rex->re.group.number <= 0 || (num = rex->re.group.last - rex->re.group.number + 1) <= 0) num = 0; - if (!(f = (Match_frame_t*)stkpush(env->mst, sizeof(Match_frame_t) + (num - 1) * sizeof(regmatch_t)))) + if (!(f = stkpush(env->mst, sizeof(Match_frame_t) + (num - 1) * sizeof(regmatch_t)))) { env->error = REG_ESPACE; return 1; @@ -960,7 +960,7 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI e = env->end; if (!(rex->flags & REG_MINIMAL)) { - if (!(b = (unsigned char*)stkpush(env->mst, n))) + if (!(b = stkpush(env->mst, n))) { env->error = REG_ESPACE; return BAD; @@ -1110,7 +1110,7 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI } else { - if (!(b = (unsigned char*)stkpush(env->mst, n))) + if (!(b = stkpush(env->mst, n))) { env->error = REG_ESPACE; return BAD; @@ -1422,7 +1422,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _ n = ((i + 7) >> 3) + 1; catcher.type = REX_NEG_CATCH; catcher.re.neg_catch.beg = s; - if (!(p = (unsigned char*)stkpush(env->mst, n))) + if (!(p = stkpush(env->mst, n))) return BAD; memset(catcher.re.neg_catch.index = p, 0, n); catcher.next = rex->next; @@ -1521,7 +1521,7 @@ DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", _ } else { - if (!(b = (unsigned char*)stkpush(env->mst, n))) + if (!(b = stkpush(env->mst, n))) { env->error = REG_ESPACE; return BAD; @@ -1888,7 +1888,7 @@ regnexec_20120528(const regex_t* p, const char* s, size_t len, size_t nmatch, re if (env->stack = env->hard || !(env->flags & REG_NOSUB) && nmatch) { n = env->nsub; - if (!(env->match = (regmatch_t*)stkpush(env->mst, 2 * (n + 1) * sizeof(regmatch_t))) || + if (!(env->match = stkpush(env->mst, 2 * (n + 1) * sizeof(regmatch_t))) || !env->pos && !(env->pos = vecopen(16, sizeof(Pos_t))) || !env->bestpos && !(env->bestpos = vecopen(16, sizeof(Pos_t)))) { diff --git a/src/lib/libast/sfio/_sfgetl.c b/src/lib/libast/sfio/_sfgetl.c index 8948831a53c0..5ea3c7adbc2a 100644 --- a/src/lib/libast/sfio/_sfgetl.c +++ b/src/lib/libast/sfio/_sfgetl.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -25,6 +25,6 @@ extern Sflong_t _sfgetl(Sfio_t* f) { - sfungetc(f, (unsigned char)_SF_(f)->val); + sfungetc(f, (unsigned char)_SFIO_(f)->val); return sfgetl(f); } diff --git a/src/lib/libast/sfio/_sfgetu.c b/src/lib/libast/sfio/_sfgetu.c index 5e504eb32e9e..1ae8ced0d601 100644 --- a/src/lib/libast/sfio/_sfgetu.c +++ b/src/lib/libast/sfio/_sfgetu.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -25,6 +25,6 @@ extern Sfulong_t _sfgetu(Sfio_t* f) { - sfungetc(f, (unsigned char)_SF_(f)->val); + sfungetc(f, (unsigned char)_SFIO_(f)->val); return sfgetu(f); } diff --git a/src/lib/libast/sfio/_sfopen.c b/src/lib/libast/sfio/_sfopen.c index 2e13dac3f0e1..2d80b24d1047 100644 --- a/src/lib/libast/sfio/_sfopen.c +++ b/src/lib/libast/sfio/_sfopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -37,20 +37,20 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ return NULL; /* changing the control flags */ - if(f && !file && !((f->flags|sflags)&SF_STRING) ) - { if(f->mode&SF_INIT ) /* stream uninitialized, ok to set flags */ - { f->flags |= (sflags & (SFIO_FLAGS & ~SF_RDWR)); + if(f && !file && !((f->flags|sflags)&SFIO_STRING) ) + { if(f->mode&SFIO_INIT ) /* stream uninitialized, ok to set flags */ + { f->flags |= (sflags & (SFIO_FLAGS & ~SFIO_RDWR)); - if((sflags &= SF_RDWR) != 0) /* reset read/write modes */ - { f->flags = (f->flags & ~SF_RDWR) | sflags; + if((sflags &= SFIO_RDWR) != 0) /* reset read/write modes */ + { f->flags = (f->flags & ~SFIO_RDWR) | sflags; - if((f->flags&SF_RDWR) == SF_RDWR) - f->bits |= SF_BOTH; - else f->bits &= ~SF_BOTH; + if((f->flags&SFIO_RDWR) == SFIO_RDWR) + f->bits |= SFIO_BOTH; + else f->bits &= ~SFIO_BOTH; - if(f->flags&SF_READ) - f->mode = (f->mode&~SF_WRITE)|SF_READ; - else f->mode = (f->mode&~SF_READ)|SF_WRITE; + if(f->flags&SFIO_READ) + f->mode = (f->mode&~SFIO_WRITE)|SFIO_READ; + else f->mode = (f->mode&~SFIO_READ)|SFIO_WRITE; } } else /* make sure there is no buffered data */ @@ -66,7 +66,7 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ fcntl(f->file, F_SETFL, ctl); } #if !O_cloexec - if (fflags & SF_FD_CLOEXEC) + if (fflags & SFIO_FD_CLOEXEC) SETCLOEXEC(f->file); #endif } @@ -74,9 +74,9 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ return f; } - if(sflags&SF_STRING) + if(sflags&SFIO_STRING) { f = sfnew(f,(char*)file, - file ? (size_t)strlen((char*)file) : (size_t)SF_UNBOUND, + file ? (size_t)strlen((char*)file) : (size_t)SFIO_UNBOUND, -1,sflags); } else @@ -84,7 +84,7 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ return NULL; #if _has_oflags /* open the file */ - while((fd = open((char*)file,oflags,SF_CREATMODE)) < 0 && errno == EINTR) + while((fd = open((char*)file,oflags,SFIO_CREATMODE)) < 0 && errno == EINTR) errno = 0; #else while((fd = open(file,oflags&O_ACCMODE)) < 0 && errno == EINTR) @@ -96,14 +96,14 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ } if(oflags&O_TRUNC ) /* truncate file */ { int tf; - while((tf = creat(file,SF_CREATMODE)) < 0 && + while((tf = creat(file,SFIO_CREATMODE)) < 0 && errno == EINTR) errno = 0; CLOSE(tf); } } else if(oflags&O_CREAT) - { while((fd = creat(file,SF_CREATMODE)) < 0 && errno == EINTR) + { while((fd = creat(file,SFIO_CREATMODE)) < 0 && errno == EINTR) errno = 0; if((oflags&O_ACCMODE) != O_WRONLY) { /* the file now exists, reopen it for read/write */ @@ -119,7 +119,7 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ /* we may have to reset the file descriptor to its old value */ oldfd = f ? f->file : -1; - if((f = sfnew(f,NULL,(size_t)SF_UNBOUND,fd,sflags)) && oldfd >= 0) + if((f = sfnew(f,NULL,(size_t)SFIO_UNBOUND,fd,sflags)) && oldfd >= 0) (void)sfsetfd(f,oldfd); } @@ -138,7 +138,7 @@ int _sftype(const char* mode, int* oflagsp, int* fflagsp) while(1) switch(*mode++) { case 'a' : - sflags |= SF_WRITE | SF_APPENDWR; + sflags |= SFIO_WRITE | SFIO_APPENDWR; oflags |= O_WRONLY | O_APPEND | O_CREAT; continue; case 'b' : @@ -146,22 +146,22 @@ int _sftype(const char* mode, int* oflagsp, int* fflagsp) continue; case 'e' : oflags |= O_cloexec; - fflags |= SF_FD_CLOEXEC; + fflags |= SFIO_FD_CLOEXEC; continue; case 'r' : - sflags |= SF_READ; + sflags |= SFIO_READ; oflags |= O_RDONLY; continue; case 's' : - sflags |= SF_STRING; + sflags |= SFIO_STRING; continue; case 't' : oflags |= O_TEXT; continue; case 'w' : - sflags |= SF_WRITE; + sflags |= SFIO_WRITE; oflags |= O_WRONLY | O_CREAT; - if(!(sflags&SF_READ)) + if(!(sflags&SFIO_READ)) oflags |= O_TRUNC; continue; case 'x' : @@ -171,11 +171,11 @@ int _sftype(const char* mode, int* oflagsp, int* fflagsp) /* stdio compatibility -- fd >= FOPEN_MAX (or other magic number) ok */ continue; case 'W' : - sflags |= SF_WCWIDTH; + sflags |= SFIO_WCWIDTH; continue; case '+' : if(sflags) - sflags |= SF_READ|SF_WRITE; + sflags |= SFIO_READ|SFIO_WRITE; continue; default : if(!(oflags&O_CREAT) ) @@ -184,14 +184,14 @@ int _sftype(const char* mode, int* oflagsp, int* fflagsp) if(!(oflags&(O_BINARY|O_TEXT))) oflags |= O_BINARY; #endif - if((sflags&SF_RDWR) == SF_RDWR) + if((sflags&SFIO_RDWR) == SFIO_RDWR) oflags = (oflags&~O_ACCMODE)|O_RDWR; if(oflagsp) *oflagsp = oflags; if(fflagsp) *fflagsp = fflags; - if((sflags&(SF_STRING|SF_RDWR)) == SF_STRING) - sflags |= SF_READ; + if((sflags&(SFIO_STRING|SFIO_RDWR)) == SFIO_STRING) + sflags |= SFIO_READ; return sflags; } } diff --git a/src/lib/libast/sfio/_sfputd.c b/src/lib/libast/sfio/_sfputd.c index 98ef854a9c10..953d98339466 100644 --- a/src/lib/libast/sfio/_sfputd.c +++ b/src/lib/libast/sfio/_sfputd.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,7 +32,7 @@ int _sfputd(Sfio_t* f, Sfdouble_t v) uchar c[N_ARRAY]; Sfdouble_t x; - if(!f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + if(!f || (f->mode != SFIO_WRITE && _sfmode(f,SFIO_WRITE,0) < 0)) return -1; SFLOCK(f,0); @@ -63,17 +63,17 @@ int _sfputd(Sfio_t* f, Sfdouble_t v) s = (ends = &c[0])+sizeof(c); while(s > ends) - { /* get 2^SF_PRECIS precision at a time */ - n = (int)(x = ldexpl(v,SF_PRECIS)); - *--s = n|SF_MORE; + { /* get 2^SFIO_PRECIS precision at a time */ + n = (int)(x = ldexpl(v,SFIO_PRECIS)); + *--s = n|SFIO_MORE; v = x-n; if(v <= 0.) break; } - /* last byte is not SF_MORE */ + /* last byte is not SFIO_MORE */ ends = &c[0] + sizeof(c) -1; - *ends &= ~SF_MORE; + *ends &= ~SFIO_MORE; /* write out coded bytes */ n = ends - s + 1; diff --git a/src/lib/libast/sfio/_sfputl.c b/src/lib/libast/sfio/_sfputl.c index 1ea5fbe5f944..de189b38f974 100644 --- a/src/lib/libast/sfio/_sfputl.c +++ b/src/lib/libast/sfio/_sfputl.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,22 +32,22 @@ int _sfputl(Sfio_t* f, /* write a portable long to this stream */ ssize_t n, p; uchar c[N_ARRAY]; - if(!f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + if(!f || (f->mode != SFIO_WRITE && _sfmode(f,SFIO_WRITE,0) < 0)) return -1; SFLOCK(f,0); s = ps = &(c[N_ARRAY-1]); if(v < 0) - { /* add 1 to avoid 2-complement problems with -SF_MAXINT */ + { /* add 1 to avoid 2-complement problems with -SFIO_MAXINT */ v = -(v+1); - *s = (uchar)(SFSVALUE(v) | SF_SIGN); + *s = (uchar)(SFSVALUE(v) | SFIO_SIGN); } else *s = (uchar)(SFSVALUE(v)); - v = (Sfulong_t)v >> SF_SBITS; + v = (Sfulong_t)v >> SFIO_SBITS; while(v > 0) - { *--s = (uchar)(SFUVALUE(v) | SF_MORE); - v = (Sfulong_t)v >> SF_UBITS; + { *--s = (uchar)(SFUVALUE(v) | SFIO_MORE); + v = (Sfulong_t)v >> SFIO_UBITS; } n = (ps-s)+1; diff --git a/src/lib/libast/sfio/_sfputm.c b/src/lib/libast/sfio/_sfputm.c index 06da3983f5bf..348ca21d2584 100644 --- a/src/lib/libast/sfio/_sfputm.c +++ b/src/lib/libast/sfio/_sfputm.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -33,15 +33,15 @@ int _sfputm(Sfio_t* f, /* write a portable ulong to this stream */ ssize_t n, p; uchar c[N_ARRAY]; - if(!f || v > m || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + if(!f || v > m || (f->mode != SFIO_WRITE && _sfmode(f,SFIO_WRITE,0) < 0)) return -1; SFLOCK(f,0); - /* code v as integers in base SF_UBASE */ + /* code v as integers in base SFIO_UBASE */ s = ps = &(c[N_ARRAY-1]); *s = (uchar)SFBVALUE(v); - while((m >>= SF_BBITS) > 0 ) - { v >>= SF_BBITS; + while((m >>= SFIO_BBITS) > 0 ) + { v >>= SFIO_BBITS; *--s = (uchar)SFBVALUE(v); } n = (ps-s)+1; diff --git a/src/lib/libast/sfio/_sfputu.c b/src/lib/libast/sfio/_sfputu.c index cf0d09851e1f..33f57610b8b0 100644 --- a/src/lib/libast/sfio/_sfputu.c +++ b/src/lib/libast/sfio/_sfputu.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,15 +32,15 @@ int _sfputu(Sfio_t* f, /* write a portable ulong to this stream */ ssize_t n, p; uchar c[N_ARRAY]; - if(!f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + if(!f || (f->mode != SFIO_WRITE && _sfmode(f,SFIO_WRITE,0) < 0)) return -1; SFLOCK(f,0); - /* code v as integers in base SF_UBASE */ + /* code v as integers in base SFIO_UBASE */ s = ps = &(c[N_ARRAY-1]); *s = (uchar)SFUVALUE(v); - while((v >>= SF_UBITS) ) - *--s = (uchar)(SFUVALUE(v) | SF_MORE); + while((v >>= SFIO_UBITS) ) + *--s = (uchar)(SFUVALUE(v) | SFIO_MORE); n = (ps-s)+1; if(n > 8 || SFWPEEK(f,ps,p) < n) diff --git a/src/lib/libast/sfio/sfclose.c b/src/lib/libast/sfio/sfclose.c index b7f44c208c1e..2f8370c33358 100644 --- a/src/lib/libast/sfio/sfclose.c +++ b/src/lib/libast/sfio/sfclose.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -33,10 +33,10 @@ int sfclose(Sfio_t* f) GETLOCAL(f,local); - if(!(f->mode&SF_INIT) && - SFMODE(f,local) != (f->mode&SF_RDWR) && - SFMODE(f,local) != (f->mode&(SF_READ|SF_SYNCED)) && - _sfmode(f,SF_SYNCED,local) < 0) + if(!(f->mode&SFIO_INIT) && + SFMODE(f,local) != (f->mode&SFIO_RDWR) && + SFMODE(f,local) != (f->mode&(SFIO_READ|SFIO_SYNCED)) && + _sfmode(f,SFIO_SYNCED,local) < 0) return -1; /* closing a stack of streams */ @@ -56,14 +56,14 @@ int sfclose(Sfio_t* f) if(f->disc == _Sfudisc) /* closing the ungetc stream */ f->disc = NULL; else if(f->file >= 0) /* sync file pointer */ - { f->bits |= SF_ENDING; + { f->bits |= SFIO_ENDING; rv = sfsync(f); } SFLOCK(f,0); /* raise discipline exceptions */ - if(f->disc && (ex = SFRAISE(f,local ? SF_NEW : SF_CLOSING,NULL)) != 0) + if(f->disc && (ex = SFRAISE(f,local ? SFIO_NEW : SFIO_CLOSING,NULL)) != 0) return ex; if(!local && f->pool) @@ -82,24 +82,24 @@ int sfclose(Sfio_t* f) } } else - { f->mode &= ~SF_LOCK; /**/ASSERT(_Sfpmove); + { f->mode &= ~SFIO_LOCK; /**/ASSERT(_Sfpmove); if((*_Sfpmove)(f,-1) < 0) { SFOPEN(f,0); return -1; } - f->mode |= SF_LOCK; + f->mode |= SFIO_LOCK; } f->pool = NULL; } - if(f->data && (!local || (f->flags&SF_STRING) || (f->bits&SF_MMAP) ) ) + if(f->data && (!local || (f->flags&SFIO_STRING) || (f->bits&SFIO_MMAP) ) ) { /* free buffer */ #ifdef MAP_TYPE - if(f->bits&SF_MMAP) + if(f->bits&SFIO_MMAP) SFMUNMAP(f,f->data,f->endb-f->data); else #endif - if(f->flags&SF_MALLOC) + if(f->flags&SFIO_MALLOC) data = f->data; f->data = NULL; @@ -108,8 +108,8 @@ int sfclose(Sfio_t* f) /* zap the file descriptor */ if(_Sfnotify) - (*_Sfnotify)(f, SF_CLOSING, (void*)((long)f->file)); - if(f->file >= 0 && !(f->flags&SF_STRING)) + (*_Sfnotify)(f, SFIO_CLOSING, (void*)((long)f->file)); + if(f->file >= 0 && !(f->flags&SFIO_STRING)) { while(close(f->file) < 0 ) { if(errno == EINTR) errno = 0; @@ -122,7 +122,7 @@ int sfclose(Sfio_t* f) f->file = -1; SFKILL(f); - f->flags &= SF_STATIC; + f->flags &= SFIO_STATIC; f->here = 0; f->extent = -1; f->endb = f->endr = f->endw = f->next = f->data; @@ -138,17 +138,17 @@ int sfclose(Sfio_t* f) rv = _sfpclose(f); if(!local) - { if(f->disc && (ex = SFRAISE(f,SF_FINAL,NULL)) != 0 ) + { if(f->disc && (ex = SFRAISE(f,SFIO_FINAL,NULL)) != 0 ) { rv = ex; goto done; } - if(!(f->flags&SF_STATIC) ) + if(!(f->flags&SFIO_STATIC) ) free(f); else { f->disc = NULL; f->stdio = NULL; - f->mode = SF_AVAIL; + f->mode = SFIO_AVAIL; } } diff --git a/src/lib/libast/sfio/sfclrlock.c b/src/lib/libast/sfio/sfclrlock.c index d8f40733686d..4ad39b67b223 100644 --- a/src/lib/libast/sfio/sfclrlock.c +++ b/src/lib/libast/sfio/sfclrlock.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -29,24 +29,24 @@ int sfclrlock(Sfio_t* f) int rv; /* already closed */ - if(f && (f->mode&SF_AVAIL) || !f) + if(f && (f->mode&SFIO_AVAIL) || !f) return 0; /* clear error bits */ - f->flags &= ~(SF_ERROR|SF_EOF); + f->flags &= ~(SFIO_ERROR|SFIO_EOF); /* clear peek locks */ - if(f->mode&SF_PKRD) + if(f->mode&SFIO_PKRD) { f->here -= f->endb-f->next; f->endb = f->next; } SFCLRBITS(f); - /* throw away all lock bits except for stacking state SF_PUSH */ - f->mode &= (SF_RDWR|SF_INIT|SF_POOL|SF_PUSH|SF_SYNCED|SF_STDIO); + /* throw away all lock bits except for stacking state SFIO_PUSH */ + f->mode &= (SFIO_RDWR|SFIO_INIT|SFIO_POOL|SFIO_PUSH|SFIO_SYNCED|SFIO_STDIO); - rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SFIO_FLAGS); + rv = (f->mode&SFIO_PUSH) ? 0 : (f->flags&SFIO_FLAGS); return rv; } diff --git a/src/lib/libast/sfio/sfcvt.c b/src/lib/libast/sfio/sfcvt.c index 86cd3f72be34..70bbf75b1a47 100644 --- a/src/lib/libast/sfio/sfcvt.c +++ b/src/lib/libast/sfio/sfcvt.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -29,10 +29,10 @@ static char *lc_inf = "inf", *uc_inf = "INF"; static char *lc_nan = "nan", *uc_nan = "NAN"; static char *Zero = "0"; -#define SF_INF ((_Sfi = 3), strlcpy(buf, (format & SFFMT_UPPER) ? uc_inf : lc_inf, size), buf) -#define SF_NAN ((_Sfi = 3), strlcpy(buf, (format & SFFMT_UPPER) ? uc_nan : lc_nan, size), buf) -#define SF_ZERO ((_Sfi = 1), strlcpy(buf, Zero, size), buf) -#define SF_INTPART (SF_IDIGITS/2) +#define SFIO_INF ((_Sfi = 3), strlcpy(buf, (format & SFFMT_UPPER) ? uc_inf : lc_inf, size), buf) +#define SFIO_NAN ((_Sfi = 3), strlcpy(buf, (format & SFFMT_UPPER) ? uc_nan : lc_nan, size), buf) +#define SFIO_ZERO ((_Sfi = 1), strlcpy(buf, Zero, size), buf) +#define SFIO_INTPART (SFIO_IDIGITS/2) #if !_lib_isnan #undef isnan @@ -136,7 +136,7 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ if (f < 0) #endif *sign = 1; - return SF_NAN; + return SFIO_NAN; } #if _lib_isinf if (n = isinf(f)) @@ -147,7 +147,7 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ if (n < 0 || f < 0) #endif *sign = 1; - return SF_INF; + return SFIO_INF; } #endif @@ -161,9 +161,9 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ } if(f < LDBL_MIN) - return SF_ZERO; + return SFIO_ZERO; if(f > LDBL_MAX) - return SF_INF; + return SFIO_INF; if(format & SFFMT_AFORMAT) { Sfdouble_t g; @@ -193,26 +193,26 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ n = 0; if(f >= (Sfdouble_t)CVT_LDBL_MAXINT) { /* scale to a small enough number to fit an int */ - v = SF_MAXEXP10-1; + v = SFIO_MAXEXP10-1; do { if(f < _Sfpos10[v]) v -= 1; else { f *= _Sfneg10[v]; - if((n += (1<= SF_IDIGITS) - return SF_INF; + if((n += (1<= SFIO_IDIGITS) + return SFIO_INF; } } while(f >= (Sfdouble_t)CVT_LDBL_MAXINT); } else if(f > 0.0 && f < 0.1) { /* scale to avoid excessive multiply by 10 below */ - v = SF_MAXEXP10-1; + v = SFIO_MAXEXP10-1; do { if(f <= _Sfneg10[v]) { f *= _Sfpos10[v]; - if((n += (1<= SF_IDIGITS) - return SF_INF; + if((n += (1<= SFIO_IDIGITS) + return SFIO_INF; } else if (--v < 0) break; @@ -221,7 +221,7 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ } *decpt = (int)n; - b = sp = buf + SF_INTPART; + b = sp = buf + SFIO_INTPART; if((v = (CVT_LDBL_INT)f) != 0) { /* translate the integer part */ f -= (Sfdouble_t)v; @@ -229,10 +229,10 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ sfucvt(v,sp,n,ep,CVT_LDBL_INT,unsigned CVT_LDBL_INT); n = b-sp; - if((*decpt += (int)n) >= SF_IDIGITS) - return SF_INF; + if((*decpt += (int)n) >= SFIO_IDIGITS) + return SFIO_INF; b = sp; - sp = buf + SF_INTPART; + sp = buf + SFIO_INTPART; } else n = 0; @@ -286,7 +286,7 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ if (f < 0) #endif *sign = 1; - return SF_NAN; + return SFIO_NAN; } #if _lib_isinf if (n = isinf(f)) @@ -297,7 +297,7 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ if (n < 0 || f < 0) #endif *sign = 1; - return SF_INF; + return SFIO_INF; } #endif @@ -311,9 +311,9 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ } if(f < DBL_MIN) - return SF_ZERO; + return SFIO_ZERO; if(f > DBL_MAX) - return SF_INF; + return SFIO_INF; if(format & SFFMT_AFORMAT) { double g; @@ -342,25 +342,25 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ n = 0; if(f >= (double)CVT_DBL_MAXINT) { /* scale to a small enough number to fit an int */ - v = SF_MAXEXP10-1; + v = SFIO_MAXEXP10-1; do { if(f < _Sfpos10[v]) v -= 1; else { f *= _Sfneg10[v]; - if((n += (1<= SF_IDIGITS) - return SF_INF; + if((n += (1<= SFIO_IDIGITS) + return SFIO_INF; } } while(f >= (double)CVT_DBL_MAXINT); } else if(f > 0.0 && f < 0.1) { /* scale to avoid excessive multiply by 10 below */ - v = SF_MAXEXP10-1; + v = SFIO_MAXEXP10-1; do { if(f <= _Sfneg10[v]) { f *= _Sfpos10[v]; - if((n += (1<= SF_IDIGITS) - return SF_INF; + if((n += (1<= SFIO_IDIGITS) + return SFIO_INF; } else if(--v < 0) break; @@ -369,7 +369,7 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ } *decpt = (int)n; - b = sp = buf + SF_INTPART; + b = sp = buf + SFIO_INTPART; if((v = (CVT_DBL_INT)f) != 0) { /* translate the integer part */ f -= (double)v; @@ -377,10 +377,10 @@ char* _sfcvt(void* vp, /* pointer to value to convert */ sfucvt(v,sp,n,ep,CVT_DBL_INT,unsigned CVT_DBL_INT); n = b-sp; - if((*decpt += (int)n) >= SF_IDIGITS) - return SF_INF; + if((*decpt += (int)n) >= SFIO_IDIGITS) + return SFIO_INF; b = sp; - sp = buf + SF_INTPART; + sp = buf + SFIO_INTPART; } else n = 0; diff --git a/src/lib/libast/sfio/sfdisc.c b/src/lib/libast/sfio/sfdisc.c index 435ae9d15aba..3efc3cfce02b 100644 --- a/src/lib/libast/sfio/sfdisc.c +++ b/src/lib/libast/sfio/sfdisc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -47,7 +47,7 @@ typedef struct _dccache_s static int _dccaexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc) { - if(disc && type == SF_FINAL) + if(disc && type == SFIO_FINAL) free(disc); return 0; } @@ -100,13 +100,13 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) if((Sfio_t*)disc == f) /* special case to get the top discipline */ return f->disc; - if((f->flags&SF_READ) && f->proc && (f->mode&SF_WRITE) ) + if((f->flags&SFIO_READ) && f->proc && (f->mode&SFIO_WRITE) ) { /* make sure in read mode to check for read-ahead data */ - if(_sfmode(f,SF_READ,0) < 0) + if(_sfmode(f,SFIO_READ,0) < 0) return NULL; } else - { if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) + { if((f->mode&SFIO_RDWR) != f->mode && _sfmode(f,0,0) < 0) return NULL; } @@ -118,25 +118,25 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) goto done; /* synchronize before switching to a new discipline */ - if(!(f->flags&SF_STRING)) + if(!(f->flags&SFIO_STRING)) { (void)SFSYNC(f); /* do a silent buffer synch */ - if((f->mode&SF_READ) && (f->mode&SF_SYNCED) ) - { f->mode &= ~SF_SYNCED; + if((f->mode&SFIO_READ) && (f->mode&SFIO_SYNCED) ) + { f->mode &= ~SFIO_SYNCED; f->endb = f->next = f->endr = f->endw = f->data; } /* if there is buffered data, ask app before proceeding */ - if(((f->mode&SF_WRITE) && (n = f->next-f->data) > 0) || - ((f->mode&SF_READ) && (n = f->endb-f->next) > 0) ) + if(((f->mode&SFIO_WRITE) && (n = f->next-f->data) > 0) || + ((f->mode&SFIO_READ) && (n = f->endb-f->next) > 0) ) { int rv = 0; if(rv == 0 && f->disc && f->disc->exceptf) /* ask current discipline */ { SFOPEN(f,0); - rv = (*f->disc->exceptf)(f, SF_DBUFFER, &n, f->disc); + rv = (*f->disc->exceptf)(f, SFIO_DBUFFER, &n, f->disc); SFLOCK(f,0); } if(rv == 0 && disc && disc->exceptf) /* ask discipline being pushed */ { SFOPEN(f,0); - rv = (*disc->exceptf)(f, SF_DBUFFER, &n, disc); + rv = (*disc->exceptf)(f, SFIO_DBUFFER, &n, disc); SFLOCK(f,0); } if(rv < 0) @@ -144,7 +144,7 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) } /* trick the new discipline into processing already buffered data */ - if((f->mode&SF_READ) && n > 0 && disc && disc->readf ) + if((f->mode&SFIO_READ) && n > 0 && disc && disc->readf ) { if(!(dcca = (Dccache_t*)malloc(sizeof(Dccache_t)+n)) ) goto done; memclear(dcca, sizeof(Dccache_t)); @@ -170,14 +170,14 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) GETDISCF(owritef,writef); GETDISCF(oseekf,seekf); - if(disc == SF_POPDISC) + if(disc == SFIO_POPDISC) { /* popping, warn the being popped discipline */ if(!(d = f->disc) ) goto done; disc = d->disc; if(d->exceptf) { SFOPEN(f,0); - if((*(d->exceptf))(f,SF_DPOP,disc,d) < 0 ) + if((*(d->exceptf))(f,SFIO_DPOP,disc,d) < 0 ) goto done; SFLOCK(f,0); } @@ -191,7 +191,7 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) d = f->disc; if(d && d->exceptf) { SFOPEN(f,0); - if( (*(d->exceptf))(f,SF_DPUSH,disc,d) < 0 ) + if( (*(d->exceptf))(f,SFIO_DPUSH,disc,d) < 0 ) goto done; SFLOCK(f,0); } @@ -212,7 +212,7 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) rdisc = disc; } - if(!(f->flags&SF_STRING) ) + if(!(f->flags&SFIO_STRING) ) { /* this stream may have to be reinitialized */ int reinit = 0; #define DISCF(dst,iof) (dst ? dst->iof : NULL) @@ -230,15 +230,15 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) if(reinit) { SETLOCAL(f); - f->bits &= ~SF_NULL; /* turn off /dev/null handling */ - if((f->bits&SF_MMAP) || (f->mode&SF_INIT)) - sfsetbuf(f,NULL,(size_t)SF_UNBOUND); + f->bits &= ~SFIO_NULL; /* turn off /dev/null handling */ + if((f->bits&SFIO_MMAP) || (f->mode&SFIO_INIT)) + sfsetbuf(f,NULL,(size_t)SFIO_UNBOUND); else if(f->data == f->tiny) sfsetbuf(f,NULL,0); else { int flags = f->flags; sfsetbuf(f,f->data,f->size); - f->flags |= (flags&SF_MALLOC); + f->flags |= (flags&SFIO_MALLOC); } } } diff --git a/src/lib/libast/sfio/sfdlen.c b/src/lib/libast/sfio/sfdlen.c index e8406438c00a..36bb2551021f 100644 --- a/src/lib/libast/sfio/sfdlen.c +++ b/src/lib/libast/sfio/sfdlen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -39,8 +39,8 @@ int _sfdlen(Sfdouble_t v) else exp = 0; for(w = 1; w <= N_ARRAY; ++w) - { /* get 2^SF_PRECIS precision at a time */ - n = (int)(x = ldexpl(v,SF_PRECIS)); + { /* get 2^SFIO_PRECIS precision at a time */ + n = (int)(x = ldexpl(v,SFIO_PRECIS)); v = x-n; if(v <= 0.) break; diff --git a/src/lib/libast/sfio/sfecvt.c b/src/lib/libast/sfio/sfecvt.c index dacf46a4635f..4c9ab04f1d26 100644 --- a/src/lib/libast/sfio/sfecvt.c +++ b/src/lib/libast/sfio/sfecvt.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -24,7 +24,7 @@ char* sfecvt(double dval, /* value to convert */ int* sign) /* to return sign */ { int len; - static char buf[SF_MAXDIGITS]; + static char buf[SFIO_MAXDIGITS]; return _sfcvt(&dval,buf,sizeof(buf),n_digit,decpt,sign,&len,SFFMT_EFORMAT); } diff --git a/src/lib/libast/sfio/sfexcept.c b/src/lib/libast/sfio/sfexcept.c index efd67401ee8a..bf3791a503fe 100644 --- a/src/lib/libast/sfio/sfexcept.c +++ b/src/lib/libast/sfio/sfexcept.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -35,10 +35,10 @@ int _sfexcept(Sfio_t* f, /* stream where the exception happened */ return -1; GETLOCAL(f,local); - lock = f->mode&SF_LOCK; + lock = f->mode&SFIO_LOCK; if(local && io <= 0) - f->flags |= io < 0 ? SF_ERROR : SF_EOF; + f->flags |= io < 0 ? SFIO_ERROR : SFIO_EOF; if(disc && disc->exceptf) { /* let the stream be generally accessible for this duration */ @@ -53,28 +53,28 @@ int _sfexcept(Sfio_t* f, /* stream where the exception happened */ if(local && lock) SFLOCK(f,0); - if(io > 0 && !(f->flags&SF_STRING) ) + if(io > 0 && !(f->flags&SFIO_STRING) ) return ev; if(ev < 0) - return SF_EDONE; + return SFIO_EDONE; if(ev > 0) - return SF_EDISC; + return SFIO_EDISC; } - if(f->flags&SF_STRING) - { if(type == SF_READ) + if(f->flags&SFIO_STRING) + { if(type == SFIO_READ) goto chk_stack; - else if(type != SF_WRITE && type != SF_SEEK) - return SF_EDONE; + else if(type != SFIO_WRITE && type != SFIO_SEEK) + return SFIO_EDONE; if(local && io >= 0) - { if(f->size >= 0 && !(f->flags&SF_MALLOC)) + { if(f->size >= 0 && !(f->flags&SFIO_MALLOC)) goto chk_stack; /* extend buffer */ if((size = f->size) < 0) size = 0; if((io -= size) <= 0) - io = SF_GRAIN; - size = ((size+io+SF_GRAIN-1)/SF_GRAIN)*SF_GRAIN; + io = SFIO_GRAIN; + size = ((size+io+SFIO_GRAIN-1)/SFIO_GRAIN)*SFIO_GRAIN; if(f->size > 0) data = (uchar*)realloc((char*)f->data,size); else data = (uchar*)malloc(size); @@ -85,24 +85,24 @@ int _sfexcept(Sfio_t* f, /* stream where the exception happened */ f->endr = f->endw = f->data = data; f->size = size; } - return SF_EDISC; + return SFIO_EDISC; } if(errno == EINTR) - { if(_Sfexiting || (f->bits&SF_ENDING) || /* stop being a hero */ - (f->flags&SF_IOINTR) ) /* application requests to return */ - return SF_EDONE; + { if(_Sfexiting || (f->bits&SFIO_ENDING) || /* stop being a hero */ + (f->flags&SFIO_IOINTR) ) /* application requests to return */ + return SFIO_EDONE; /* a normal interrupt, we can continue */ errno = 0; - f->flags &= ~(SF_EOF|SF_ERROR); - return SF_ECONT; + f->flags &= ~(SFIO_EOF|SFIO_ERROR); + return SFIO_ECONT; } chk_stack: if(local && f->push && - ((type == SF_READ && f->next >= f->endb) || - (type == SF_WRITE && f->next <= f->data))) + ((type == SFIO_READ && f->next >= f->endb) || + (type == SFIO_WRITE && f->next <= f->data))) { /* pop the stack */ Sfio_t *pf; @@ -117,9 +117,9 @@ int _sfexcept(Sfio_t* f, /* stream where the exception happened */ if(lock) SFLOCK(f,0); - ev = ev < 0 ? SF_EDONE : SF_ESTACK; + ev = ev < 0 ? SFIO_EDONE : SFIO_ESTACK; } - else ev = SF_EDONE; + else ev = SFIO_EDONE; return ev; } diff --git a/src/lib/libast/sfio/sfextern.c b/src/lib/libast/sfio/sfextern.c index cf8fecf4aead..961dbbe83cdd 100644 --- a/src/lib/libast/sfio/sfextern.c +++ b/src/lib/libast/sfio/sfextern.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -44,9 +44,9 @@ Sfextern_t _Sfextern = ssize_t _Sfi = -1; /* value for a few fast macro functions */ ssize_t _Sfmaxr = 0; /* default (unlimited) max record size */ -Sfio_t _Sfstdin = SFNEW(NULL,-1,0,(SF_READ |SF_STATIC),NULL); -Sfio_t _Sfstdout = SFNEW(NULL,-1,1,(SF_WRITE|SF_STATIC),NULL); -Sfio_t _Sfstderr = SFNEW(NULL,-1,2,(SF_WRITE|SF_STATIC),NULL); +Sfio_t _Sfstdin = SFNEW(NULL,-1,0,(SFIO_READ |SFIO_STATIC),NULL); +Sfio_t _Sfstdout = SFNEW(NULL,-1,1,(SFIO_WRITE|SFIO_STATIC),NULL); +Sfio_t _Sfstderr = SFNEW(NULL,-1,2,(SFIO_WRITE|SFIO_STATIC),NULL); #undef sfstdin #undef sfstdout diff --git a/src/lib/libast/sfio/sffcvt.c b/src/lib/libast/sfio/sffcvt.c index 16834590ba6e..29872f701506 100644 --- a/src/lib/libast/sfio/sffcvt.c +++ b/src/lib/libast/sfio/sffcvt.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -24,7 +24,7 @@ char *sffcvt(double dval, /* value to convert */ int* sign) /* to return sign */ { int len; - static char buf[SF_MAXDIGITS]; + static char buf[SFIO_MAXDIGITS]; return _sfcvt(&dval,buf,sizeof(buf),n_digit,decpt,sign,&len,0); } diff --git a/src/lib/libast/sfio/sffilbuf.c b/src/lib/libast/sfio/sffilbuf.c index b2422ea8861c..7c8f64a5b333 100644 --- a/src/lib/libast/sfio/sffilbuf.c +++ b/src/lib/libast/sfio/sffilbuf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -40,14 +40,14 @@ int _sffilbuf(Sfio_t* f, /* fill the read buffer of this stream */ GETLOCAL(f,local); /* any peek data must be preserved across stacked streams */ - rcrv = f->mode&(SF_RC|SF_RV|SF_LOCK); + rcrv = f->mode&(SFIO_RC|SFIO_RV|SFIO_LOCK); rc = f->getr; - justseek = f->bits&SF_JUSTSEEK; f->bits &= ~SF_JUSTSEEK; + justseek = f->bits&SFIO_JUSTSEEK; f->bits &= ~SFIO_JUSTSEEK; - for(first = 1;; first = 0, (f->mode &= ~SF_LOCK) ) + for(first = 1;; first = 0, (f->mode &= ~SFIO_LOCK) ) { /* check mode */ - if(SFMODE(f,local) != SF_READ && _sfmode(f,SF_READ,local) < 0) + if(SFMODE(f,local) != SFIO_READ && _sfmode(f,SFIO_READ,local) < 0) return -1; SFLOCK(f,local); @@ -56,11 +56,11 @@ int _sffilbuf(Sfio_t* f, /* fill the read buffer of this stream */ { /* on first iteration, n is amount beyond current buffer; afterward, n is the exact amount requested */ if((first && n <= 0) || (!first && n <= r) || - (f->flags&SF_STRING)) + (f->flags&SFIO_STRING)) break; /* try shifting left to make room for new data */ - if(!(f->bits&SF_MMAP) && f->next > f->data && + if(!(f->bits&SFIO_MMAP) && f->next > f->data && n > (f->size - (f->endb-f->data)) ) { ssize_t s = r; @@ -76,15 +76,15 @@ int _sffilbuf(Sfio_t* f, /* fill the read buffer of this stream */ f->endb = f->data + s; } } - else if(!(f->flags&SF_STRING) && !(f->bits&SF_MMAP) ) + else if(!(f->flags&SFIO_STRING) && !(f->bits&SFIO_MMAP) ) f->next = f->endb = f->endr = f->data; - if(f->bits&SF_MMAP) + if(f->bits&SFIO_MMAP) r = n > 0 ? n : f->size; - else if(!(f->flags&SF_STRING) ) + else if(!(f->flags&SFIO_STRING) ) { r = f->size - (f->endb - f->data); /* available buffer */ if(n > 0) - { if(r > n && f->extent < 0 && (f->flags&SF_SHARE) ) + { if(r > n && f->extent < 0 && (f->flags&SFIO_SHARE) ) r = n; /* read only as much as requested */ else if(justseek && n <= f->iosz && f->iosz <= f->size) r = f->iosz; /* limit buffer filling */ diff --git a/src/lib/libast/sfio/sfflsbuf.c b/src/lib/libast/sfio/sfflsbuf.c index 41d27c25c502..d48e7c4e03ae 100644 --- a/src/lib/libast/sfio/sfflsbuf.c +++ b/src/lib/libast/sfio/sfflsbuf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -19,7 +19,7 @@ #include "sfhdr.h" /* Write a buffer out to a file descriptor or -** extending a buffer for a SF_STRING stream. +** extending a buffer for a SFIO_STRING stream. ** ** Written by Kiem-Phong Vo */ @@ -38,23 +38,23 @@ int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */ GETLOCAL(f,local); - for(written = 0;; f->mode &= ~SF_LOCK) + for(written = 0;; f->mode &= ~SFIO_LOCK) { /* check stream mode */ - if(SFMODE(f,local) != SF_WRITE && _sfmode(f,SF_WRITE,local) < 0) + if(SFMODE(f,local) != SFIO_WRITE && _sfmode(f,SFIO_WRITE,local) < 0) return -1; SFLOCK(f,local); /* current data extent */ n = f->next - (data = f->data); - if(n == (f->endb-data) && (f->flags&SF_STRING)) + if(n == (f->endb-data) && (f->flags&SFIO_STRING)) { /* call sfwr() to extend string buffer and process events */ - w = ((f->bits&SF_PUTR) && f->val > 0) ? f->val : 1; + w = ((f->bits&SFIO_PUTR) && f->val > 0) ? f->val : 1; (void)SFWR(f, data, w, f->disc); - /* !(f->flags&SF_STRING) is required because exception + /* !(f->flags&SFIO_STRING) is required because exception handlers may turn a string stream to a file stream */ - if(f->next < f->endb || !(f->flags&SF_STRING) ) + if(f->next < f->endb || !(f->flags&SFIO_STRING) ) n = f->next - (data = f->data); else { SFOPEN(f,local); @@ -67,7 +67,7 @@ int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */ if(n < (f->endb - (data = f->data))) { *f->next++ = c; if(c == '\n' && - (f->flags&SF_LINE) && !(f->flags&SF_STRING)) + (f->flags&SFIO_LINE) && !(f->flags&SFIO_STRING)) { c = -1; n += 1; } @@ -82,7 +82,7 @@ int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */ } } - if(n == 0 || (f->flags&SF_STRING)) + if(n == 0 || (f->flags&SFIO_STRING)) break; isall = SFISALL(f,isall); @@ -102,7 +102,7 @@ int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */ return -1; } } - else /* w < 0 means SF_EDISC or SF_ESTACK in sfwr() */ + else /* w < 0 means SFIO_EDISC or SFIO_ESTACK in sfwr() */ { if(c < 0) /* back to the calling write operation */ break; else continue; /* try again to write out c */ diff --git a/src/lib/libast/sfio/sfgetd.c b/src/lib/libast/sfio/sfgetd.c index 28a97cbb3d44..c7bef0a7c30b 100644 --- a/src/lib/libast/sfio/sfgetd.c +++ b/src/lib/libast/sfio/sfgetd.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,7 +32,7 @@ Sfdouble_t sfgetd(Sfio_t* f) if(!f || (sign = sfgetc(f)) < 0 || (exp = (int)sfgetu(f)) < 0) return -1.; - if(f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) + if(f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0) return -1.; SFLOCK(f,0); @@ -41,7 +41,7 @@ Sfdouble_t sfgetd(Sfio_t* f) for(;;) { /* fast read for data */ if(SFRPEEK(f,s,p) <= 0) - { f->flags |= SF_ERROR; + { f->flags |= SFIO_ERROR; v = -1.; goto done; } @@ -49,8 +49,8 @@ Sfdouble_t sfgetd(Sfio_t* f) for(ends = s+p; s < ends; ) { c = *s++; v += SFUVALUE(c); - v = ldexpl(v,-SF_PRECIS); - if(!(c&SF_MORE)) + v = ldexpl(v,-SFIO_PRECIS); + if(!(c&SFIO_MORE)) { f->next = s; goto done; } diff --git a/src/lib/libast/sfio/sfgetl.c b/src/lib/libast/sfio/sfgetl.c index 9ba9f8251a7f..7328fba609b8 100644 --- a/src/lib/libast/sfio/sfgetl.c +++ b/src/lib/libast/sfio/sfgetl.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -29,25 +29,25 @@ Sflong_t sfgetl(Sfio_t* f) uchar *s, *ends, c; int p; - if(!f || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + if(!f || (f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0)) return (Sflong_t)(-1); SFLOCK(f,0); for(v = 0;;) { if(SFRPEEK(f,s,p) <= 0) - { f->flags |= SF_ERROR; + { f->flags |= SFIO_ERROR; v = (Sflong_t)(-1); goto done; } for(ends = s+p; s < ends;) { c = *s++; - if(c&SF_MORE) - v = ((Sfulong_t)v << SF_UBITS) | SFUVALUE(c); + if(c&SFIO_MORE) + v = ((Sfulong_t)v << SFIO_UBITS) | SFUVALUE(c); else { /* special translation for this byte */ - v = ((Sfulong_t)v << SF_SBITS) | SFSVALUE(c); + v = ((Sfulong_t)v << SFIO_SBITS) | SFSVALUE(c); f->next = s; - v = (c&SF_SIGN) ? -v-1 : v; + v = (c&SFIO_SIGN) ? -v-1 : v; goto done; } } diff --git a/src/lib/libast/sfio/sfgetm.c b/src/lib/libast/sfio/sfgetm.c index a91cff1b8846..554909cbc517 100644 --- a/src/lib/libast/sfio/sfgetm.c +++ b/src/lib/libast/sfio/sfgetm.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -29,21 +29,21 @@ Sfulong_t sfgetm(Sfio_t* f, Sfulong_t m) uchar *s, *ends, c; int p; - if(!f || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + if(!f || (f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0)) return (Sfulong_t)(-1); SFLOCK(f,0); for(v = 0;; ) { if(SFRPEEK(f,s,p) <= 0) - { f->flags |= SF_ERROR; + { f->flags |= SFIO_ERROR; v = (Sfulong_t)(-1); goto done; } for(ends = s+p; s < ends;) { c = *s++; - v = (v << SF_BBITS) | SFBVALUE(c); - if((m >>= SF_BBITS) <= 0) + v = (v << SFIO_BBITS) | SFBVALUE(c); + if((m >>= SFIO_BBITS) <= 0) { f->next = s; goto done; } diff --git a/src/lib/libast/sfio/sfgetr.c b/src/lib/libast/sfio/sfgetr.c index 2269881efcae..d765eabf6b77 100644 --- a/src/lib/libast/sfio/sfgetr.c +++ b/src/lib/libast/sfio/sfgetr.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -33,7 +33,7 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ int found; Sfrsrv_t* rsrv; - if(!f || rc < 0 || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + if(!f || rc < 0 || (f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0)) return NULL; SFLOCK(f,0); @@ -44,10 +44,10 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ found = 0; /* compatibility mode */ - type = type < 0 ? SF_LASTR : type == 1 ? SF_STRING : type; + type = type < 0 ? SFIO_LASTR : type == 1 ? SFIO_STRING : type; - if(type&SF_LASTR) /* return the broken record */ - { if((f->flags&SF_STRING) && (un = f->endb - f->next)) + if(type&SFIO_LASTR) /* return the broken record */ + { if((f->flags&SFIO_STRING) && (un = f->endb - f->next)) { us = f->next; f->next = f->endb; found = 1; @@ -64,7 +64,7 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ if((n = (ends = f->endb) - (s = f->next)) <= 0) { /* for unseekable devices, peek-read 1 record */ f->getr = rc; - f->mode |= SF_RC; + f->mode |= SFIO_RC; /* fill buffer the conventional way */ if(SFRPEEK(f,s,n) <= 0) @@ -73,7 +73,7 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ } else { ends = s+n; - if(f->mode&SF_RC) + if(f->mode&SFIO_RC) { s = ends[-1] == rc ? ends-1 : ends; goto do_copy; } @@ -94,8 +94,8 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ found = 1; if(!us && - (!(type&SF_STRING) || !(f->flags&SF_STRING) || - ((f->flags&SF_STRING) && (f->bits&SF_BOTH) ) ) ) + (!(type&SFIO_STRING) || !(f->flags&SFIO_STRING) || + ((f->flags&SFIO_STRING) && (f->bits&SFIO_BOTH) ) ) ) { /* returning data in buffer */ us = f->next; un = s - f->next; @@ -107,7 +107,7 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ /* amount to be read */ n = s - f->next; - if(!found && (_Sfmaxr > 0 && un+n+1 >= _Sfmaxr || (f->flags&SF_STRING))) /* already exceed limit */ + if(!found && (_Sfmaxr > 0 && un+n+1 >= _Sfmaxr || (f->flags&SFIO_STRING))) /* already exceed limit */ { us = NULL; goto done; } @@ -135,11 +135,11 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ done: _Sfi = f->val = un; f->getr = 0; - if(found && rc != 0 && (type&SF_STRING) ) + if(found && rc != 0 && (type&SFIO_STRING) ) { us[un-1] = '\0'; if(us >= f->data && us < f->endb) { f->getr = rc; - f->mode |= SF_GETR; + f->mode |= SFIO_GETR; } } @@ -149,8 +149,8 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ SFOPEN(f,0); - if(us && (type&SF_LOCKR) ) - { f->mode |= SF_PEEK|SF_GETR; + if(us && (type&SFIO_LOCKR) ) + { f->mode |= SFIO_PEEK|SFIO_GETR; f->endr = f->data; } diff --git a/src/lib/libast/sfio/sfgetu.c b/src/lib/libast/sfio/sfgetu.c index 1bb05db9da48..d80bc02417c8 100644 --- a/src/lib/libast/sfio/sfgetu.c +++ b/src/lib/libast/sfio/sfgetu.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -29,21 +29,21 @@ Sfulong_t sfgetu(Sfio_t* f) uchar *s, *ends, c; int p; - if(!f || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + if(!f || (f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0)) return (Sfulong_t)(-1); SFLOCK(f,0); for(v = 0;;) { if(SFRPEEK(f,s,p) <= 0) - { f->flags |= SF_ERROR; + { f->flags |= SFIO_ERROR; v = (Sfulong_t)(-1); goto done; } for(ends = s+p; s < ends;) { c = *s++; - v = (v << SF_UBITS) | SFUVALUE(c); - if(!(c&SF_MORE)) + v = (v << SFIO_UBITS) | SFUVALUE(c); + if(!(c&SFIO_MORE)) { f->next = s; goto done; } diff --git a/src/lib/libast/sfio/sfhdr.h b/src/lib/libast/sfio/sfhdr.h index 64ee68ed5eba..ef1d04d98ab6 100644 --- a/src/lib/libast/sfio/sfhdr.h +++ b/src/lib/libast/sfio/sfhdr.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -115,13 +115,7 @@ #endif #if _socket_peek -#if __FreeBSD__ && __BSD_VISIBLE -#undef __BSD_VISIBLE /* Hide conflicting SF_SYNC definition. [Added 2022-01-20. TODO: review periodically] */ #include -#define __BSD_VISIBLE 1 -#else -#include -#endif #endif /* to test for executable access mode of a file */ @@ -130,51 +124,51 @@ #endif /* Private flags in the "bits" field */ -#define SF_MMAP 00000001 /* in memory mapping mode */ -#define SF_BOTH 00000002 /* both read/write */ -#define SF_HOLE 00000004 /* a hole of zero's was created */ -#define SF_NULL 00000010 /* stream is /dev/null */ -#define SF_SEQUENTIAL 00000020 /* sequential access */ -#define SF_JUSTSEEK 00000040 /* just did a sfseek */ -#define SF_PRIVATE 00000100 /* private stream to Sfio */ -#define SF_ENDING 00000200 /* no re-io on interrupts at closing */ -#define SF_WIDE 00000400 /* in wide mode - stdio only */ -#define SF_PUTR 00001000 /* in sfputr() */ +#define SFIO_MMAP 00000001 /* in memory mapping mode */ +#define SFIO_BOTH 00000002 /* both read/write */ +#define SFIO_HOLE 00000004 /* a hole of zero's was created */ +#define SFIO_NULL 00000010 /* stream is /dev/null */ +#define SFIO_SEQUENTIAL 00000020 /* sequential access */ +#define SFIO_JUSTSEEK 00000040 /* just did a sfseek */ +#define SFIO_PRIVATE 00000100 /* private stream to Sfio */ +#define SFIO_ENDING 00000200 /* no re-io on interrupts at closing */ +#define SFIO_WIDE 00000400 /* in wide mode - stdio only */ +#define SFIO_PUTR 00001000 /* in sfputr() */ /* "bits" flags that must be cleared in sfclrlock */ -#define SF_TMPBITS 00170000 -#define SF_DCDOWN 00010000 /* recurse down the discipline stack */ +#define SFIO_TMPBITS 00170000 +#define SFIO_DCDOWN 00010000 /* recurse down the discipline stack */ -#define SF_WCFORMAT 00020000 /* wchar_t formatting - stdio only */ +#define SFIO_WCFORMAT 00020000 /* wchar_t formatting - stdio only */ #if _has_multibyte -#define SFWCSET(f) ((f)->bits |= SF_WCFORMAT) -#define SFWCGET(f,v) (((v) = (f)->bits & SF_WCFORMAT), ((f)->bits &= ~SF_WCFORMAT) ) +#define SFWCSET(f) ((f)->bits |= SFIO_WCFORMAT) +#define SFWCGET(f,v) (((v) = (f)->bits & SFIO_WCFORMAT), ((f)->bits &= ~SFIO_WCFORMAT) ) #else #define SFWCSET(f) #define SFWCGET(f,v) #endif -#define SF_MVSIZE 00040000 /* f->size was reset in sfmove() */ -#define SFMVSET(f) (((f)->size *= SF_NMAP), ((f)->bits |= SF_MVSIZE) ) -#define SFMVUNSET(f) (!((f)->bits&SF_MVSIZE) ? 0 : \ - (((f)->bits &= ~SF_MVSIZE), ((f)->size /= SF_NMAP)) ) +#define SFIO_MVSIZE 00040000 /* f->size was reset in sfmove() */ +#define SFMVSET(f) (((f)->size *= SFIO_NMAP), ((f)->bits |= SFIO_MVSIZE) ) +#define SFMVUNSET(f) (!((f)->bits&SFIO_MVSIZE) ? 0 : \ + (((f)->bits &= ~SFIO_MVSIZE), ((f)->size /= SFIO_NMAP)) ) -#define SFCLRBITS(f) (SFMVUNSET(f), ((f)->bits &= ~SF_TMPBITS) ) +#define SFCLRBITS(f) (SFMVUNSET(f), ((f)->bits &= ~SFIO_TMPBITS) ) -/* bits for the mode field, SF_INIT defined in sfio_t.h */ -#define SF_RC 00000010 /* peeking for a record */ -#define SF_RV 00000020 /* reserve without read or most write */ -#define SF_LOCK 00000040 /* stream is locked for io op */ -#define SF_PUSH 00000100 /* stream has been pushed */ -#define SF_POOL 00000200 /* stream is in a pool but not current */ -#define SF_PEEK 00000400 /* there is a pending peek */ -#define SF_PKRD 00001000 /* did a peek read */ -#define SF_GETR 00002000 /* did a getr on this stream */ -#define SF_SYNCED 00004000 /* stream was synced */ -#define SF_STDIO 00010000 /* given up the buffer to stdio */ -#define SF_AVAIL 00020000 /* was closed, available for reuse */ -#define SF_LOCAL 00100000 /* sentinel for a local call */ +/* bits for the mode field, SFIO_INIT defined in sfio_t.h */ +#define SFIO_RC 00000010 /* peeking for a record */ +#define SFIO_RV 00000020 /* reserve without read or most write */ +#define SFIO_LOCK 00000040 /* stream is locked for io op */ +#define SFIO_PUSH 00000100 /* stream has been pushed */ +#define SFIO_POOL 00000200 /* stream is in a pool but not current */ +#define SFIO_PEEK 00000400 /* there is a pending peek */ +#define SFIO_PKRD 00001000 /* did a peek read */ +#define SFIO_GETR 00002000 /* did a getr on this stream */ +#define SFIO_SYNCED 00004000 /* stream was synced */ +#define SFIO_STDIO 00010000 /* given up the buffer to stdio */ +#define SFIO_AVAIL 00020000 /* was closed, available for reuse */ +#define SFIO_LOCAL 00100000 /* sentinel for a local call */ #ifdef DEBUG #define ASSERT(p) ((p) ? 0 : (abort(),0) ) @@ -240,9 +234,9 @@ #endif #ifdef S_IRUSR -#define SF_CREATMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) +#define SFIO_CREATMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) #else -#define SF_CREATMODE 0666 +#define SFIO_CREATMODE 0666 #endif /* set close-on-exec */ @@ -259,7 +253,7 @@ # endif /*FIOCLEX*/ #endif /*F_SETFD*/ -#define SF_FD_CLOEXEC 0x0001 +#define SFIO_FD_CLOEXEC 0x0001 /* function to get the decimal point for local environment */ #include "lclib.h" @@ -420,28 +414,28 @@ typedef struct _sfextern_s } Sfextern_t; /* get the real value of a byte in a coded long or ulong */ -#define SFUVALUE(v) (((ulong)(v))&(SF_MORE-1)) -#define SFSVALUE(v) ((( long)(v))&(SF_SIGN-1)) -#define SFBVALUE(v) (((ulong)(v))&(SF_BYTE-1)) +#define SFUVALUE(v) (((ulong)(v))&(SFIO_MORE-1)) +#define SFSVALUE(v) ((( long)(v))&(SFIO_SIGN-1)) +#define SFBVALUE(v) (((ulong)(v))&(SFIO_BYTE-1)) /* pick this many bits in each iteration of double encoding */ -#define SF_PRECIS 7 +#define SFIO_PRECIS 7 /* grain size for buffer increment */ -#define SF_GRAIN 1024 -#define SF_PAGE ((ssize_t)(SF_GRAIN*sizeof(int)*2)) +#define SFIO_GRAIN 1024 +#define SFIO_PAGE ((ssize_t)(SFIO_GRAIN*sizeof(int)*2)) /* when the buffer is empty, certain io requests may be better done directly on the given application buffers. The below condition determines when. */ #define SFDIRECT(f,n) (((ssize_t)(n) >= (f)->size) || \ - ((n) >= SF_GRAIN && (ssize_t)(n) >= (f)->size/16 ) ) + ((n) >= SFIO_GRAIN && (ssize_t)(n) >= (f)->size/16 ) ) /* number of pages to memory map at a time */ #if _ptr_bits >= 64 -#define SF_NMAP 1024 +#define SFIO_NMAP 1024 #else -#define SF_NMAP 32 +#define SFIO_NMAP 32 #endif #ifndef MAP_VARIABLE @@ -477,23 +471,23 @@ typedef struct _sfextern_s /* the bottomless bit bucket */ #define DEVNULL "/dev/null" -#define SFSETNULL(f) ((f)->extent = (Sfoff_t)(-1), (f)->bits |= SF_NULL) -#define SFISNULL(f) ((f)->extent < 0 && ((f)->bits&SF_NULL) ) +#define SFSETNULL(f) ((f)->extent = (Sfoff_t)(-1), (f)->bits |= SFIO_NULL) +#define SFISNULL(f) ((f)->extent < 0 && ((f)->bits&SFIO_NULL) ) -#define SFKILL(f) ((f)->mode = (SF_AVAIL|SF_LOCK) ) -#define SFKILLED(f) (((f)->mode&(SF_AVAIL|SF_LOCK)) == (SF_AVAIL|SF_LOCK) ) +#define SFKILL(f) ((f)->mode = (SFIO_AVAIL|SFIO_LOCK) ) +#define SFKILLED(f) (((f)->mode&(SFIO_AVAIL|SFIO_LOCK)) == (SFIO_AVAIL|SFIO_LOCK) ) /* exception types */ -#define SF_EDONE 0 /* stop this operation and return */ -#define SF_EDISC 1 /* discipline says it's ok */ -#define SF_ESTACK 2 /* stack was popped */ -#define SF_ECONT 3 /* can continue normally */ - -#define SETLOCAL(f) ((f)->mode |= SF_LOCAL) -#define GETLOCAL(f,v) ((v) = ((f)->mode&SF_LOCAL), (f)->mode &= ~SF_LOCAL, (v)) -#define SFWRALL(f) ((f)->mode |= SF_RV) -#define SFISALL(f,v) ((((v) = (f)->mode&SF_RV) ? ((f)->mode &= ~SF_RV) : 0), \ - ((v) || ((f)->flags&(SF_SHARE|SF_APPENDWR|SF_WHOLE)) ) ) +#define SFIO_EDONE 0 /* stop this operation and return */ +#define SFIO_EDISC 1 /* discipline says it's ok */ +#define SFIO_ESTACK 2 /* stack was popped */ +#define SFIO_ECONT 3 /* can continue normally */ + +#define SETLOCAL(f) ((f)->mode |= SFIO_LOCAL) +#define GETLOCAL(f,v) ((v) = ((f)->mode&SFIO_LOCAL), (f)->mode &= ~SFIO_LOCAL, (v)) +#define SFWRALL(f) ((f)->mode |= SFIO_RV) +#define SFISALL(f,v) ((((v) = (f)->mode&SFIO_RV) ? ((f)->mode &= ~SFIO_RV) : 0), \ + ((v) || ((f)->flags&(SFIO_SHARE|SFIO_APPENDWR|SFIO_WHOLE)) ) ) #define SFSK(f,a,o,d) (SETLOCAL(f),sfsk(f,(Sfoff_t)a,o,d)) #define SFRD(f,b,n,d) (SETLOCAL(f),sfrd(f,b,n,d)) #define SFWR(f,b,n,d) (SETLOCAL(f),sfwr(f,b,n,d)) @@ -509,20 +503,20 @@ typedef struct _sfextern_s #define SFRAISE(f,e,d) (SETLOCAL(f),sfraise(f,e,d)) /* lock/open a stream */ -#define SFMODE(f,l) ((f)->mode & ~(SF_RV|SF_RC|((l) ? SF_LOCK : 0)) ) -#define SFLOCK(f,l) (void)((f)->mode |= SF_LOCK, (f)->endr = (f)->endw = (f)->data) +#define SFMODE(f,l) ((f)->mode & ~(SFIO_RV|SFIO_RC|((l) ? SFIO_LOCK : 0)) ) +#define SFLOCK(f,l) (void)((f)->mode |= SFIO_LOCK, (f)->endr = (f)->endw = (f)->data) #define _SFOPENRD(f) ((f)->endr = (f)->endb) -#define _SFOPENWR(f) ((f)->endw = ((f)->flags&SF_LINE) ? (f)->data : (f)->endb) -#define _SFOPEN(f) ((f)->mode == SF_READ ? _SFOPENRD(f) : \ - (f)->mode == SF_WRITE ? _SFOPENWR(f) : \ +#define _SFOPENWR(f) ((f)->endw = ((f)->flags&SFIO_LINE) ? (f)->data : (f)->endb) +#define _SFOPEN(f) ((f)->mode == SFIO_READ ? _SFOPENRD(f) : \ + (f)->mode == SFIO_WRITE ? _SFOPENWR(f) : \ ((f)->endw = (f)->endr = (f)->data) ) #define SFOPEN(f,l) (void)((l) ? 0 : \ - ((f)->mode &= ~(SF_LOCK|SF_RC|SF_RV), _SFOPEN(f), 0) ) + ((f)->mode &= ~(SFIO_LOCK|SFIO_RC|SFIO_RV), _SFOPEN(f), 0) ) /* check to see if the stream can be accessed */ -#define SFFROZEN(f) (((f)->mode&(SF_PUSH|SF_LOCK|SF_PEEK)) ? 1 : \ - !((f)->mode&SF_STDIO) ? 0 : \ - _Sfstdsync ? (*_Sfstdsync)(f) : (((f)->mode &= ~SF_STDIO),0) ) +#define SFFROZEN(f) (((f)->mode&(SFIO_PUSH|SFIO_LOCK|SFIO_PEEK)) ? 1 : \ + !((f)->mode&SFIO_STDIO) ? 0 : \ + _Sfstdsync ? (*_Sfstdsync)(f) : (((f)->mode &= ~SFIO_STDIO),0) ) /* set discipline code */ @@ -530,24 +524,24 @@ typedef struct _sfextern_s { Sfdisc_t* d; \ if(!(dc)) \ d = (dc) = (f)->disc; \ - else d = (f->bits&SF_DCDOWN) ? ((dc) = (dc)->disc) : (dc); \ + else d = (f->bits&SFIO_DCDOWN) ? ((dc) = (dc)->disc) : (dc); \ while(d && !(d->iof)) d = d->disc; \ if(d) (dc) = d; \ } #define SFDCRD(f,buf,n,dc,rv) \ - { int dcdown = f->bits&SF_DCDOWN; f->bits |= SF_DCDOWN; \ + { int dcdown = f->bits&SFIO_DCDOWN; f->bits |= SFIO_DCDOWN; \ rv = (*dc->readf)(f,buf,n,dc); \ - if(!dcdown) f->bits &= ~SF_DCDOWN; \ + if(!dcdown) f->bits &= ~SFIO_DCDOWN; \ } #define SFDCWR(f,buf,n,dc,rv) \ - { int dcdown = f->bits&SF_DCDOWN; f->bits |= SF_DCDOWN; \ + { int dcdown = f->bits&SFIO_DCDOWN; f->bits |= SFIO_DCDOWN; \ rv = (*dc->writef)(f,buf,n,dc); \ - if(!dcdown) f->bits &= ~SF_DCDOWN; \ + if(!dcdown) f->bits &= ~SFIO_DCDOWN; \ } #define SFDCSK(f,addr,type,dc,rv) \ - { int dcdown = f->bits&SF_DCDOWN; f->bits |= SF_DCDOWN; \ + { int dcdown = f->bits&SFIO_DCDOWN; f->bits |= SFIO_DCDOWN; \ rv = (*dc->seekf)(f,addr,type,dc); \ - if(!dcdown) f->bits &= ~SF_DCDOWN; \ + if(!dcdown) f->bits &= ~SFIO_DCDOWN; \ } /* fast peek of a stream */ @@ -597,21 +591,21 @@ typedef struct _sfextern_s #define O_TEMPORARY 000 #endif -#define SF_RADIX 64 /* maximum integer conversion base */ +#define SFIO_RADIX 64 /* maximum integer conversion base */ -#define SF_MAXCHAR ((uchar)(~0)) +#define SFIO_MAXCHAR ((uchar)(~0)) /* floating point to ASCII conversion */ -#define SF_MAXEXP10 6 -#define SF_MAXPOW10 (1 << SF_MAXEXP10) +#define SFIO_MAXEXP10 6 +#define SFIO_MAXPOW10 (1 << SFIO_MAXEXP10) #if !_ast_fltmax_double -#define SF_FDIGITS 1024 /* max allowed fractional digits */ -#define SF_IDIGITS (8*1024) /* max number of digits in int part */ +#define SFIO_FDIGITS 1024 /* max allowed fractional digits */ +#define SFIO_IDIGITS (8*1024) /* max number of digits in int part */ #else -#define SF_FDIGITS 256 /* max allowed fractional digits */ -#define SF_IDIGITS 1024 /* max number of digits in int part */ +#define SFIO_FDIGITS 256 /* max allowed fractional digits */ +#define SFIO_IDIGITS 1024 /* max number of digits in int part */ #endif -#define SF_MAXDIGITS (((SF_FDIGITS+SF_IDIGITS)/sizeof(int) + 1)*sizeof(int)) +#define SFIO_MAXDIGITS (((SFIO_FDIGITS+SFIO_IDIGITS)/sizeof(int) + 1)*sizeof(int)) /* tables for numerical translation */ #define _Sfpos10 (_Sftable.sf_pos10) @@ -645,8 +639,8 @@ struct _sfieee_s Sfdouble_t ldblinf; /* Sfdouble_t INF */ }; typedef struct _sftab_ -{ Sfdouble_t sf_pos10[SF_MAXEXP10]; /* positive powers of 10 */ - Sfdouble_t sf_neg10[SF_MAXEXP10]; /* negative powers of 10 */ +{ Sfdouble_t sf_pos10[SFIO_MAXEXP10]; /* positive powers of 10 */ + Sfdouble_t sf_neg10[SFIO_MAXEXP10]; /* negative powers of 10 */ uchar sf_dec[200]; /* ASCII reps of values < 100 */ char* sf_digits; /* digits for general bases */ int (*sf_cvinitf)(); /* initialization function */ @@ -656,9 +650,9 @@ typedef struct _sftab_ float* sf_flt_pow10; /* float powers of 10 */ double* sf_dbl_pow10; /* double powers of 10 */ Sfdouble_t* sf_ldbl_pow10; /* Sfdouble_t powers of 10 */ - uchar sf_cv36[SF_MAXCHAR+1]; /* conversion for base [2-36] */ - uchar sf_cv64[SF_MAXCHAR+1]; /* conversion for base [37-64] */ - uchar sf_type[SF_MAXCHAR+1]; /* conversion formats&types */ + uchar sf_cv36[SFIO_MAXCHAR+1]; /* conversion for base [2-36] */ + uchar sf_cv64[SFIO_MAXCHAR+1]; /* conversion for base [37-64] */ + uchar sf_type[SFIO_MAXCHAR+1]; /* conversion formats&types */ Sfieee_t sf_ieee; /* IEEE floating point constants*/ } Sftab_t; @@ -793,9 +787,4 @@ extern long double ldexpl(long double, int); #endif #endif -#ifdef _SF_HIDESFFLAGS -#undef SFIO_FLAGS -#define SFIO_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */ -#endif - #endif /*_SFHDR_H*/ diff --git a/src/lib/libast/sfio/sfllen.c b/src/lib/libast/sfio/sfllen.c index c67c1134d8de..260d3ce86d4d 100644 --- a/src/lib/libast/sfio/sfllen.c +++ b/src/lib/libast/sfio/sfllen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -26,6 +26,6 @@ int _sfllen(Sflong_t v) { if(v < 0) v = -(v+1); - v = (Sfulong_t)v >> SF_SBITS; + v = (Sfulong_t)v >> SFIO_SBITS; return 1 + (v > 0 ? sfulen(v) : 0); } diff --git a/src/lib/libast/sfio/sfmode.c b/src/lib/libast/sfio/sfmode.c index d028c7114689..28624f13279b 100644 --- a/src/lib/libast/sfio/sfmode.c +++ b/src/lib/libast/sfio/sfmode.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -38,7 +38,7 @@ static char* Version = "\n@(#)$Id: sfio (AT&T Labs - Research) 2009-09-15 $\0\n" ** 09/09/1999 (thread-safe) ** 02/01/2001 (adaptive buffering) ** 05/31/2002 (multi-byte handling in sfvprintf/vscanf) -** 09/06/2002 (SF_IOINTR flag) +** 09/06/2002 (SFIO_IOINTR flag) ** 11/15/2002 (%#c for sfvprintf) ** 05/31/2003 (sfsetbuf(f,f,align_size) to set alignment for data) ** (%I1d is fixed to handle "signed char" correctly) @@ -76,19 +76,19 @@ static void _sfcleanup(void) SFLOCK(f,0); /* let application know that we are leaving */ - (void)SFRAISE(f, SF_ATEXIT, NULL); + (void)SFRAISE(f, SFIO_ATEXIT, NULL); - if(f->flags&SF_STRING) + if(f->flags&SFIO_STRING) continue; /* from now on, write streams are unbuffered */ - pool = f->mode&SF_POOL; - f->mode &= ~SF_POOL; - if((f->flags&SF_WRITE) && !(f->mode&SF_WRITE)) - (void)_sfmode(f,SF_WRITE,1); + pool = f->mode&SFIO_POOL; + f->mode &= ~SFIO_POOL; + if((f->flags&SFIO_WRITE) && !(f->mode&SFIO_WRITE)) + (void)_sfmode(f,SFIO_WRITE,1); if(f->data && - ((f->bits&SF_MMAP) || - ((f->mode&SF_WRITE) && f->next == f->data) ) ) + ((f->bits&SFIO_MMAP) || + ((f->mode&SFIO_WRITE) && f->next == f->data) ) ) (void)SFSETBUF(f,NULL,0); f->mode |= pool; @@ -151,7 +151,7 @@ Sfrsrv_t* _sfrsrv(Sfio_t* f, ssize_t size) Sfrsrv_t *rsrv, *rs; /* make buffer if nothing yet */ - size = ((size + SF_GRAIN-1)/SF_GRAIN)*SF_GRAIN; + size = ((size + SFIO_GRAIN-1)/SFIO_GRAIN)*SFIO_GRAIN; if(!(rsrv = f->rsrv) || size > rsrv->size) { if(!(rs = (Sfrsrv_t*)malloc(size+sizeof(Sfrsrv_t)))) size = -1; @@ -187,7 +187,7 @@ int _sfpopen(Sfio_t* f, int fd, int pid, int stdio) /* stdio popen() does not re p->size = p->ndata = 0; p->rdata = NULL; p->file = fd; - p->sigp = (!stdio && pid >= 0 && (f->flags&SF_WRITE)) ? 1 : 0; + p->sigp = (!stdio && pid >= 0 && (f->flags&SFIO_WRITE)) ? 1 : 0; /* protect from broken pipe signal */ if(p->sigp) @@ -250,7 +250,7 @@ static int _sfpmode(Sfio_t* f, int type) if(!(p = f->proc) ) return -1; - if(type == SF_WRITE) + if(type == SFIO_WRITE) { /* save unread data */ p->ndata = f->endb-f->next; if(p->ndata > p->size) @@ -297,25 +297,25 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream int rv = 0; - if(wanted&SF_SYNCED) /* for (SF_SYNCED|SF_READ) stream, just junk data */ - { wanted &= ~SF_SYNCED; - if((f->mode&(SF_SYNCED|SF_READ)) == (SF_SYNCED|SF_READ) ) + if(wanted&SFIO_SYNCED) /* for (SFIO_SYNCED|SFIO_READ) stream, just junk data */ + { wanted &= ~SFIO_SYNCED; + if((f->mode&(SFIO_SYNCED|SFIO_READ)) == (SFIO_SYNCED|SFIO_READ) ) { f->next = f->endb = f->endr = f->data; - f->mode &= ~SF_SYNCED; + f->mode &= ~SFIO_SYNCED; } } - if((!local && SFFROZEN(f)) || (!(f->flags&SF_STRING) && f->file < 0)) + if((!local && SFFROZEN(f)) || (!(f->flags&SFIO_STRING) && f->file < 0)) { if(local || !f->disc || !f->disc->exceptf) { local = 1; goto err_notify; } for(;;) - { if((rv = (*f->disc->exceptf)(f,SF_LOCKED,0,f->disc)) < 0) + { if((rv = (*f->disc->exceptf)(f,SFIO_LOCKED,0,f->disc)) < 0) return rv; if((!local && SFFROZEN(f)) || - (!(f->flags&SF_STRING) && f->file < 0) ) + (!(f->flags&SFIO_STRING) && f->file < 0) ) { if(rv == 0) { local = 1; goto err_notify; @@ -326,16 +326,16 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream } } - if(f->mode&SF_GETR) - { f->mode &= ~SF_GETR; + if(f->mode&SFIO_GETR) + { f->mode &= ~SFIO_GETR; #ifdef MAP_TYPE - if(f->bits&SF_MMAP) + if(f->bits&SFIO_MMAP) { if (!++f->ngetr) f->tiny[0]++; - if(((f->tiny[0]<<8)|f->ngetr) >= (4*SF_NMAP) ) + if(((f->tiny[0]<<8)|f->ngetr) >= (4*SFIO_NMAP) ) { /* turn off mmap to avoid page faulting */ - sfsetbuf(f,f->tiny,(size_t)SF_UNBOUND); + sfsetbuf(f,f->tiny,(size_t)SFIO_UNBOUND); f->ngetr = f->tiny[0] = 0; } } @@ -346,29 +346,29 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream } } - if(f->mode&SF_STDIO) /* synchronizing with stdio pointers */ + if(f->mode&SFIO_STDIO) /* synchronizing with stdio pointers */ (*_Sfstdsync)(f); - if(f->disc == _Sfudisc && wanted == SF_WRITE && + if(f->disc == _Sfudisc && wanted == SFIO_WRITE && sfclose((*_Sfstack)(f,NULL)) < 0 ) { local = 1; goto err_notify; } - if(f->mode&SF_POOL) + if(f->mode&SFIO_POOL) { /* move to head of pool */ if(f == f->pool->sf[0] || (*_Sfpmove)(f,0) < 0 ) { local = 1; goto err_notify; } - f->mode &= ~SF_POOL; + f->mode &= ~SFIO_POOL; } SFLOCK(f,local); /* buffer initialization */ - wanted &= SF_RDWR; - if(f->mode&SF_INIT) + wanted &= SFIO_RDWR; + if(f->mode&SFIO_INIT) { if(!f->pool && _sfsetpool(f) < 0) { rv = -1; @@ -378,24 +378,24 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream if(wanted == 0) goto done; - if(wanted != (int)(f->mode&SF_RDWR) && !(f->flags&wanted) ) + if(wanted != (int)(f->mode&SFIO_RDWR) && !(f->flags&wanted) ) goto err_notify; - if((f->flags&SF_STRING) && f->size >= 0 && f->data) - { f->mode &= ~SF_INIT; - f->extent = ((f->flags&SF_READ) || (f->bits&SF_BOTH)) ? + if((f->flags&SFIO_STRING) && f->size >= 0 && f->data) + { f->mode &= ~SFIO_INIT; + f->extent = ((f->flags&SFIO_READ) || (f->bits&SFIO_BOTH)) ? f->size : 0; f->here = 0; f->endb = f->data + f->size; f->next = f->endr = f->endw = f->data; - if(f->mode&SF_READ) + if(f->mode&SFIO_READ) f->endr = f->endb; else f->endw = f->endb; } else { n = f->flags; (void)SFSETBUF(f,f->data,f->size); - f->flags |= (n&SF_MALLOC); + f->flags |= (n&SFIO_MALLOC); } } @@ -404,15 +404,15 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream switch(SFMODE(f,1)) { - case SF_WRITE: /* switching to SF_READ */ - if(wanted == 0 || wanted == SF_WRITE) + case SFIO_WRITE: /* switching to SFIO_READ */ + if(wanted == 0 || wanted == SFIO_WRITE) break; - if(!(f->flags&SF_READ) ) + if(!(f->flags&SFIO_READ) ) goto err_notify; - else if(f->flags&SF_STRING) + else if(f->flags&SFIO_STRING) { SFSTRSIZE(f); f->endb = f->data+f->extent; - f->mode = SF_READ; + f->mode = SFIO_READ; break; } @@ -426,7 +426,7 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream f->size = sizeof(f->tiny); } f->next = f->endr = f->endw = f->endb = f->data; - f->mode = SF_READ|SF_LOCK; + f->mode = SFIO_READ|SFIO_LOCK; /* restore saved read data for coprocess */ if(f->proc && _sfpmode(f,wanted) < 0) @@ -434,17 +434,17 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream break; - case (SF_READ|SF_SYNCED): /* a previously sync-ed read stream */ - if(wanted != SF_WRITE) + case (SFIO_READ|SFIO_SYNCED): /* a previously sync-ed read stream */ + if(wanted != SFIO_WRITE) { /* just reset the pointers */ - f->mode = SF_READ|SF_LOCK; + f->mode = SFIO_READ|SFIO_LOCK; /* see if must go with new physical location */ - if((f->flags&(SF_SHARE|SF_PUBLIC)) == (SF_SHARE|SF_PUBLIC) && + if((f->flags&(SFIO_SHARE|SFIO_PUBLIC)) == (SFIO_SHARE|SFIO_PUBLIC) && (addr = SFSK(f,0,SEEK_CUR,f->disc)) != f->here) { #ifdef MAP_TYPE - if((f->bits&SF_MMAP) && f->data) + if((f->bits&SFIO_MMAP) && f->data) { SFMUNMAP(f,f->data,f->endb-f->data); f->data = NULL; } @@ -463,14 +463,14 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream } /* FALLTHROUGH */ - case SF_READ: /* switching to SF_WRITE */ - if(wanted != SF_WRITE) + case SFIO_READ: /* switching to SFIO_WRITE */ + if(wanted != SFIO_WRITE) break; - else if(!(f->flags&SF_WRITE)) + else if(!(f->flags&SFIO_WRITE)) goto err_notify; - else if(f->flags&SF_STRING) + else if(f->flags&SFIO_STRING) { f->endb = f->data+f->size; - f->mode = SF_WRITE|SF_LOCK; + f->mode = SFIO_WRITE|SFIO_LOCK; break; } @@ -479,9 +479,9 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream goto err_notify; /* reset buffer and seek pointer */ - if(!(f->mode&SF_SYNCED) ) + if(!(f->mode&SFIO_SYNCED) ) { intptr_t nn = f->endb - f->next; - if(f->extent >= 0 && (nn > 0 || (f->data && (f->bits&SF_MMAP))) ) + if(f->extent >= 0 && (nn > 0 || (f->data && (f->bits&SFIO_MMAP))) ) { /* reset file pointer */ addr = f->here - nn; if(SFSK(f,addr,SEEK_SET,f->disc) < 0) @@ -490,12 +490,12 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream } } - f->mode = SF_WRITE|SF_LOCK; + f->mode = SFIO_WRITE|SFIO_LOCK; #ifdef MAP_TYPE - if(f->bits&SF_MMAP) + if(f->bits&SFIO_MMAP) { if(f->data) SFMUNMAP(f,f->data,f->endb-f->data); - (void)SFSETBUF(f,f->tiny,(size_t)SF_UNBOUND); + (void)SFSETBUF(f,f->tiny,(size_t)SFIO_UNBOUND); } #endif if(f->data == f->tiny) @@ -508,11 +508,11 @@ int _sfmode(Sfio_t* f, /* change r/w mode and sync file pointer for this stream default: /* unknown case */ err_notify: - if((wanted &= SF_RDWR) == 0 && (wanted = f->flags&SF_RDWR) == SF_RDWR) - wanted = SF_READ; + if((wanted &= SFIO_RDWR) == 0 && (wanted = f->flags&SFIO_RDWR) == SFIO_RDWR) + wanted = SFIO_READ; /* set errno for operations that access wrong stream type */ - if(wanted != (f->mode&SF_RDWR) && f->file >= 0) + if(wanted != (f->mode&SFIO_RDWR) && f->file >= 0) errno = EBADF; if(_Sfnotify) /* notify application of the error */ diff --git a/src/lib/libast/sfio/sfmove.c b/src/lib/libast/sfio/sfmove.c index cbf6976a134e..b638a5c8ae95 100644 --- a/src/lib/libast/sfio/sfmove.c +++ b/src/lib/libast/sfio/sfmove.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -67,19 +67,19 @@ Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */ } /* get the streams into the right mode */ - if(fr->mode != SF_READ && _sfmode(fr,SF_READ,0) < 0) + if(fr->mode != SFIO_READ && _sfmode(fr,SFIO_READ,0) < 0) break; SFLOCK(fr,0); /* flush the write buffer as necessary to make room */ if(fw) - { if(fw->mode != SF_WRITE && _sfmode(fw,SF_WRITE,0) < 0 ) + { if(fw->mode != SFIO_WRITE && _sfmode(fw,SFIO_WRITE,0) < 0 ) break; SFLOCK(fw,0); if(fw->next >= fw->endb || (fw->next > fw->data && fr->extent < 0 && - (fw->extent < 0 || (fw->flags&SF_SHARE)) ) ) + (fw->extent < 0 || (fw->flags&SFIO_SHARE)) ) ) if(SFFLSBUF(fw,-1) < 0 ) break; } @@ -95,9 +95,9 @@ Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */ } /* about to move all, set map to a large amount */ - if(n < 0 && (fr->bits&SF_MMAP) && !(fr->bits&SF_MVSIZE) ) + if(n < 0 && (fr->bits&SFIO_MMAP) && !(fr->bits&SFIO_MVSIZE) ) { SFMVSET(fr); - fr->bits |= SF_SEQUENTIAL; /* sequentially access data */ + fr->bits |= SFIO_SEQUENTIAL; /* sequentially access data */ } /* try reading a block of data */ @@ -110,23 +110,23 @@ Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */ { /* amount of data remained to be read */ if((w = n > MAX_SSIZE ? MAX_SSIZE : (ssize_t)n) < 0) { if(fr->extent < 0) - w = fr->data == fr->tiny ? SF_GRAIN : fr->size; - else if((fr->extent-fr->here) > SF_NMAP*SF_PAGE) - w = SF_NMAP*SF_PAGE; + w = fr->data == fr->tiny ? SFIO_GRAIN : fr->size; + else if((fr->extent-fr->here) > SFIO_NMAP*SFIO_PAGE) + w = SFIO_NMAP*SFIO_PAGE; else w = (ssize_t)(fr->extent-fr->here); } /* use a decent buffer for data transfer but make sure that if we overread, the left over can be retrieved */ - if(!(fr->flags&SF_STRING) && !(fr->bits&SF_MMAP) && + if(!(fr->flags&SFIO_STRING) && !(fr->bits&SFIO_MMAP) && (n < 0 || fr->extent >= 0) ) - { ssize_t maxw = 4*(_Sfpage > 0 ? _Sfpage : SF_PAGE); + { ssize_t maxw = 4*(_Sfpage > 0 ? _Sfpage : SFIO_PAGE); /* direct transfer to a seekable write stream */ if(fw && fw->extent >= 0 && w <= (fw->endb-fw->next) ) { w = fw->endb - (next = fw->next); - direct = SF_WRITE; + direct = SFIO_WRITE; } else if(w > fr->size && maxw > fr->size) { /* making our own buffer */ @@ -138,14 +138,14 @@ Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */ if(rbuf) { next = rbuf; w = rsize; - direct = SF_STRING; + direct = SFIO_STRING; } } } if(!direct) { /* make sure we don't read too far ahead */ - if(n > 0 && fr->extent < 0 && (fr->flags&SF_SHARE) ) + if(n > 0 && fr->extent < 0 && (fr->flags&SFIO_SHARE) ) { if((Sfoff_t)(r = fr->size) > n) r = (ssize_t)n; } @@ -190,7 +190,7 @@ Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */ } if(fw) - { if(direct == SF_WRITE) + { if(direct == SFIO_WRITE) fw->next += r; else if(r <= (fw->endb-fw->next) ) { memmove(fw->next,next,r); @@ -214,12 +214,12 @@ Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */ SFOPEN(fw,0); } - if(n < 0 && (fr->bits&SF_MMAP) && (fr->bits&SF_MVSIZE)) + if(n < 0 && (fr->bits&SFIO_MMAP) && (fr->bits&SFIO_MVSIZE)) { /* back to normal access mode */ SFMVUNSET(fr); - if((fr->bits&SF_SEQUENTIAL) && (fr->data)) + if((fr->bits&SFIO_SEQUENTIAL) && (fr->data)) SFMMSEQOFF(fr,fr->data,fr->endb-fr->data); - fr->bits &= ~SF_SEQUENTIAL; + fr->bits &= ~SFIO_SEQUENTIAL; } if(rbuf) diff --git a/src/lib/libast/sfio/sfnew.c b/src/lib/libast/sfio/sfnew.c index b0b36fdf7fa5..76b9db52e10d 100644 --- a/src/lib/libast/sfio/sfnew.c +++ b/src/lib/libast/sfio/sfnew.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -35,18 +35,18 @@ Sfio_t* sfnew(Sfio_t* oldf, /* old stream to be reused */ int sflags; - if(!(flags&SF_RDWR)) + if(!(flags&SFIO_RDWR)) return NULL; sflags = 0; if((f = oldf) ) - { if(flags&SF_EOF) + { if(flags&SFIO_EOF) { SFCLEAR(f); oldf = NULL; } - else if(f->mode&SF_AVAIL) - { /* only allow SF_STATIC to be already closed */ - if(!(f->flags&SF_STATIC) ) + else if(f->mode&SFIO_AVAIL) + { /* only allow SFIO_STATIC to be already closed */ + if(!(f->flags&SFIO_STATIC) ) return NULL; sflags = f->flags; oldf = NULL; @@ -55,26 +55,26 @@ Sfio_t* sfnew(Sfio_t* oldf, /* old stream to be reused */ { /* reopening an open stream, close it first */ sflags = f->flags; - if(((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) || + if(((f->mode&SFIO_RDWR) != f->mode && _sfmode(f,0,0) < 0) || SFCLOSE(f) < 0 ) return NULL; - if(f->data && ((flags&SF_STRING) || size != (size_t)SF_UNBOUND) ) - { if(sflags&SF_MALLOC) + if(f->data && ((flags&SFIO_STRING) || size != (size_t)SFIO_UNBOUND) ) + { if(sflags&SFIO_MALLOC) free(f->data); f->data = NULL; } if(!f->data) - sflags &= ~SF_MALLOC; + sflags &= ~SFIO_MALLOC; } } if(!f) { /* reuse a standard stream structure if possible */ - if(!(flags&SF_STRING) && file >= 0 && file <= 2) + if(!(flags&SFIO_STRING) && file >= 0 && file <= 2) { f = file == 0 ? sfstdin : file == 1 ? sfstdout : sfstderr; if(f) - { if(f->mode&SF_AVAIL) + { if(f->mode&SFIO_AVAIL) { sflags = f->flags; SFCLEAR(f); } @@ -90,25 +90,25 @@ Sfio_t* sfnew(Sfio_t* oldf, /* old stream to be reused */ } /* stream type */ - f->mode = (flags&SF_READ) ? SF_READ : SF_WRITE; - f->flags = (flags&SFIO_FLAGS) | (sflags&(SF_MALLOC|SF_STATIC)); - f->bits = (flags&SF_RDWR) == SF_RDWR ? SF_BOTH : 0; + f->mode = (flags&SFIO_READ) ? SFIO_READ : SFIO_WRITE; + f->flags = (flags&SFIO_FLAGS) | (sflags&(SFIO_MALLOC|SFIO_STATIC)); + f->bits = (flags&SFIO_RDWR) == SFIO_RDWR ? SFIO_BOTH : 0; f->file = file; f->here = f->extent = 0; f->getr = f->tiny[0] = 0; - f->mode |= SF_INIT; - if(size != (size_t)SF_UNBOUND) + f->mode |= SFIO_INIT; + if(size != (size_t)SFIO_UNBOUND) { f->size = size; f->data = size <= 0 ? NULL : (uchar*)buf; } f->endb = f->endr = f->endw = f->next = f->data; if(_Sfnotify) - (*_Sfnotify)(f, SF_NEW, (void*)((long)f->file)); + (*_Sfnotify)(f, SFIO_NEW, (void*)((long)f->file)); - if(f->flags&SF_STRING) - (void)_sfmode(f,f->mode&SF_RDWR,0); + if(f->flags&SFIO_STRING) + (void)_sfmode(f,f->mode&SFIO_RDWR,0); return f; } diff --git a/src/lib/libast/sfio/sfnputc.c b/src/lib/libast/sfio/sfnputc.c index 7e1ee7e1d0b7..6a8bc9c569a3 100644 --- a/src/lib/libast/sfio/sfnputc.c +++ b/src/lib/libast/sfio/sfnputc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -36,7 +36,7 @@ ssize_t sfnputc(Sfio_t* f, /* file to write */ return -1; GETLOCAL(f,local); - if(SFMODE(f,local) != SF_WRITE && _sfmode(f,SF_WRITE,local) < 0) + if(SFMODE(f,local) != SFIO_WRITE && _sfmode(f,SFIO_WRITE,local) < 0) return -1; SFLOCK(f,local); diff --git a/src/lib/libast/sfio/sfpeek.c b/src/lib/libast/sfio/sfpeek.c index 954306ccc9c8..eb8da4766270 100644 --- a/src/lib/libast/sfio/sfpeek.c +++ b/src/lib/libast/sfio/sfpeek.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,10 +32,10 @@ extern ssize_t sfpeek(Sfio_t* f, /* file to peek */ /* query for the extent of the remainder of the buffer */ if((sz = size) == 0 || !bp) - { if(f->mode&SF_INIT) + { if(f->mode&SFIO_INIT) (void)_sfmode(f,0,0); - if((f->flags&SF_RDWRSTR) == SF_RDWRSTR) + if((f->flags&SFIO_RDWRSTR) == SFIO_RDWRSTR) { SFSTRSIZE(f); n = (f->data+f->here) - f->next; } @@ -50,8 +50,8 @@ extern ssize_t sfpeek(Sfio_t* f, /* file to peek */ /* else fall down and fill buffer */ } - if(!(mode = f->flags&SF_READ) ) - mode = SF_WRITE; + if(!(mode = f->flags&SFIO_READ) ) + mode = SFIO_WRITE; if((int)f->mode != mode && _sfmode(f,mode,0) < 0) return -1; @@ -63,7 +63,7 @@ extern ssize_t sfpeek(Sfio_t* f, /* file to peek */ if((n = sfvalue(f)) > 0) { *bp = f->next; if(sz < 0) - { f->mode |= SF_PEEK; + { f->mode |= SFIO_PEEK; f->endr = f->endw = f->data; } else diff --git a/src/lib/libast/sfio/sfpoll.c b/src/lib/libast/sfio/sfpoll.c index 3c5f0c277aaf..b09df6531897 100644 --- a/src/lib/libast/sfio/sfpoll.c +++ b/src/lib/libast/sfio/sfpoll.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -41,12 +41,12 @@ int sfpoll(Sfio_t** fa, /* array of streams to poll */ return -1; check = status+n; /* streams that need polling */ - /* a SF_READ stream is ready if there is buffered read data */ -#define RDREADY(f) (((f->mode&SF_READ) && f->next < f->endb) || \ - ((f->mode&SF_WRITE) && f->proc && f->proc->ndata > 0) ) + /* a SFIO_READ stream is ready if there is buffered read data */ +#define RDREADY(f) (((f->mode&SFIO_READ) && f->next < f->endb) || \ + ((f->mode&SFIO_WRITE) && f->proc && f->proc->ndata > 0) ) - /* a SF_WRITE stream is ready if there is no write data */ -#define WRREADY(f) (!(f->mode&SF_WRITE) || f->next == f->data) + /* a SFIO_WRITE stream is ready if there is no write data */ +#define WRREADY(f) (!(f->mode&SFIO_WRITE) || f->next == f->data) #define HASAUXFD(f) (f->proc && f->proc->file >= 0 && f->proc->file != f->file) @@ -55,28 +55,28 @@ int sfpoll(Sfio_t** fa, /* array of streams to poll */ status[r] = 0; /* terminate poll on interrupt? */ - if(f->flags&SF_IOINTR) + if(f->flags&SFIO_IOINTR) eintr++; /* check accessibility */ - m = f->mode&SF_RDWR; + m = f->mode&SFIO_RDWR; if((int)f->mode != m && _sfmode(f,m,0) < 0) continue; - if((f->flags&SF_READ) && RDREADY(f)) - status[r] |= SF_READ; + if((f->flags&SFIO_READ) && RDREADY(f)) + status[r] |= SFIO_READ; - if((f->flags&SF_WRITE) && WRREADY(f)) - status[r] |= SF_WRITE; + if((f->flags&SFIO_WRITE) && WRREADY(f)) + status[r] |= SFIO_WRITE; - if((f->flags&SF_RDWR) == status[r]) + if((f->flags&SFIO_RDWR) == status[r]) continue; /* has discipline, ask its opinion */ if(f->disc && f->disc->exceptf) - { if((m = (*f->disc->exceptf)(f,SF_DPOLL,&tm,f->disc)) < 0) + { if((m = (*f->disc->exceptf)(f,SFIO_DPOLL,&tm,f->disc)) < 0) continue; else if(m > 0) - { status[r] = m&SF_RDWR; + { status[r] = m&SFIO_RDWR; continue; } } @@ -84,13 +84,13 @@ int sfpoll(Sfio_t** fa, /* array of streams to poll */ if(f->extent < 0) /* unseekable stream, must poll/select */ check[c++] = r; else /* seekable streams are always ready */ - { if(f->flags&SF_READ) - status[r] |= SF_READ; - if(f->flags&SF_WRITE) - status[r] |= SF_WRITE; + { if(f->flags&SFIO_READ) + status[r] |= SFIO_READ; + if(f->flags&SFIO_WRITE) + status[r] |= SFIO_WRITE; } } - /* terminate poll on interrupt only if all streams marked SF_IOINTR */ + /* terminate poll on interrupt only if all streams marked SFIO_IOINTR */ eintr = eintr == n ? -1 : EINTR; np = -1; @@ -113,12 +113,12 @@ int sfpoll(Sfio_t** fa, /* array of streams to poll */ fds[m].fd = f->file; fds[m].events = fds[m].revents = 0; - if((f->flags&SF_WRITE) && !WRREADY(f) ) + if((f->flags&SFIO_WRITE) && !WRREADY(f) ) fds[m].events |= POLLOUT; - if((f->flags&SF_READ) && !RDREADY(f) ) + if((f->flags&SFIO_READ) && !RDREADY(f) ) { /* a sfpopen situation with two file descriptors */ - if((f->mode&SF_WRITE) && HASAUXFD(f)) + if((f->mode&SFIO_WRITE) && HASAUXFD(f)) { m += 1; fds[m].fd = f->proc->file; fds[m].revents = 0; @@ -139,16 +139,16 @@ int sfpoll(Sfio_t** fa, /* array of streams to poll */ for(m = 0, r = 0; r < np; ++r, ++m) { f = fa[check[r]]; - if((f->flags&SF_WRITE) && !WRREADY(f) ) + if((f->flags&SFIO_WRITE) && !WRREADY(f) ) { if(fds[m].revents&(POLLOUT|POLLHUP|POLLERR)) - status[check[r]] |= SF_WRITE; + status[check[r]] |= SFIO_WRITE; } - if((f->flags&SF_READ) && !RDREADY(f)) - { if((f->mode&SF_WRITE) && HASAUXFD(f)) + if((f->flags&SFIO_READ) && !RDREADY(f)) + { if((f->mode&SFIO_WRITE) && HASAUXFD(f)) m += 1; if(fds[m].revents&(POLLIN|POLLHUP|POLLERR)) - status[check[r]] |= SF_READ; + status[check[r]] |= SFIO_READ; } } @@ -170,11 +170,11 @@ int sfpoll(Sfio_t** fa, /* array of streams to poll */ if(f->file > m) m = f->file; - if((f->flags&SF_WRITE) && !WRREADY(f)) + if((f->flags&SFIO_WRITE) && !WRREADY(f)) FD_SET(f->file,&wr); - if((f->flags&SF_READ) && !RDREADY(f)) - { if((f->mode&SF_WRITE) && HASAUXFD(f)) + if((f->flags&SFIO_READ) && !RDREADY(f)) + { if((f->mode&SFIO_WRITE) && HASAUXFD(f)) { if(f->proc->file > m) m = f->proc->file; FD_SET(f->proc->file, &rd); @@ -201,19 +201,19 @@ int sfpoll(Sfio_t** fa, /* array of streams to poll */ for(r = 0; r < np; ++r) { f = fa[check[r]]; - if((f->flags&SF_WRITE) && !WRREADY(f) ) + if((f->flags&SFIO_WRITE) && !WRREADY(f) ) { if(FD_ISSET(f->file,&wr) ) - status[check[r]] |= SF_WRITE; + status[check[r]] |= SFIO_WRITE; } - if((f->flags&SF_READ) && !RDREADY(f) ) - { if((f->mode&SF_WRITE) && HASAUXFD(f) ) + if((f->flags&SFIO_READ) && !RDREADY(f) ) + { if((f->mode&SFIO_WRITE) && HASAUXFD(f) ) { if(FD_ISSET(f->proc->file, &rd) ) - status[check[r]] |= SF_READ; + status[check[r]] |= SFIO_READ; } else { if(FD_ISSET(f->file,&rd) ) - status[check[r]] |= SF_READ; + status[check[r]] |= SFIO_READ; } } } @@ -230,7 +230,7 @@ int sfpoll(Sfio_t** fa, /* array of streams to poll */ /* announce status */ if(f->disc && f->disc->exceptf) - (*f->disc->exceptf)(f,SF_READY,(void*)(long)status[c],f->disc); + (*f->disc->exceptf)(f,SFIO_READY,(void*)(long)status[c],f->disc); if(c > r) /* move to front of list */ { fa[c] = fa[r]; diff --git a/src/lib/libast/sfio/sfpool.c b/src/lib/libast/sfio/sfpool.c index 74f82667d325..b08f463cf7c6 100644 --- a/src/lib/libast/sfio/sfpool.c +++ b/src/lib/libast/sfio/sfpool.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,7 +22,7 @@ /* Management of pools of streams. ** If pf is not nil, f is pooled with pf and f becomes current; ** otherwise, f is isolated from its pool. flag can be one of -** 0 or SF_SHARE. +** 0 or SFIO_SHARE. ** ** Written by Kiem-Phong Vo. */ @@ -37,7 +37,7 @@ static int delpool(Sfpool_t* p) if(p->s_sf && p->sf != p->array) free(p->sf); - p->mode = SF_AVAIL; + p->mode = SFIO_AVAIL; return 0; } @@ -48,7 +48,7 @@ static Sfpool_t* newpool(int mode) /* look to see if there is a free pool */ for(last = &_Sfpool, p = last->next; p; last = p, p = p->next) - { if(p->mode == SF_AVAIL ) + { if(p->mode == SFIO_AVAIL ) { p->mode = 0; break; } @@ -66,7 +66,7 @@ static Sfpool_t* newpool(int mode) } - p->mode = mode&SF_SHARE; + p->mode = mode&SFIO_SHARE; p->s_sf = sizeof(p->array)/sizeof(p->array[0]); p->sf = p->array; @@ -93,12 +93,12 @@ static int _sfphead(Sfpool_t* p, /* the pool */ SFLOCK(head,0); rv = -1; - if(!(p->mode&SF_SHARE) || (head->mode&SF_READ) || (f->mode&SF_READ) ) + if(!(p->mode&SFIO_SHARE) || (head->mode&SFIO_READ) || (f->mode&SFIO_READ) ) { if(SFSYNC(head) < 0) goto done; } else /* shared pool of write-streams, data can be moved among streams */ - { if(SFMODE(head,1) != SF_WRITE && _sfmode(head,SF_WRITE,1) < 0) + { if(SFMODE(head,1) != SFIO_WRITE && _sfmode(head,SFIO_WRITE,1) < 0) goto done; /**/ASSERT(f->next == f->data); @@ -124,8 +124,8 @@ static int _sfphead(Sfpool_t* p, /* the pool */ f->next = f->data+v; } - f->mode &= ~SF_POOL; - head->mode |= SF_POOL; + f->mode &= ~SFIO_POOL; + head->mode |= SFIO_POOL; head->next = head->endr = head->endw = head->data; /* clear write buffer */ p->sf[n] = head; @@ -133,7 +133,7 @@ static int _sfphead(Sfpool_t* p, /* the pool */ rv = 0; done: - head->mode &= ~SF_LOCK; /* partially unlock because it's no longer head */ + head->mode &= ~SFIO_LOCK; /* partially unlock because it's no longer head */ return rv; } @@ -149,7 +149,7 @@ static int _sfpdelete(Sfpool_t* p, /* the pool */ p->sf[n] = p->sf[n+1]; f->pool = NULL; - f->mode &= ~SF_POOL; + f->mode &= ~SFIO_POOL; if(p->n_sf == 0 || p == &_Sfpool) { if(p != &_Sfpool) @@ -167,9 +167,9 @@ static int _sfpdelete(Sfpool_t* p, /* the pool */ p->sf[0] = f; } - /* head stream has SF_POOL off */ + /* head stream has SFIO_POOL off */ f = p->sf[0]; - f->mode &= ~SF_POOL; + f->mode &= ~SFIO_POOL; if(!SFFROZEN(f)) _SFOPEN(f); @@ -221,13 +221,13 @@ Sfio_t* sfpool(Sfio_t* f, Sfio_t* pf, int mode) } if(f) /* check for permissions */ - { if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) + { if((f->mode&SFIO_RDWR) != f->mode && _sfmode(f,0,0) < 0) return NULL; if(f->disc == _Sfudisc) (void)sfclose((*_Sfstack)(f,NULL)); } if(pf) - { if((pf->mode&SF_RDWR) != pf->mode && _sfmode(pf,0,0) < 0) + { if((pf->mode&SFIO_RDWR) != pf->mode && _sfmode(pf,0,0) < 0) return NULL; if(pf->disc == _Sfudisc) (void)sfclose((*_Sfstack)(pf,NULL)); @@ -265,10 +265,10 @@ Sfio_t* sfpool(Sfio_t* f, Sfio_t* pf, int mode) if(pf->pool && pf->pool != &_Sfpool) /* always use current mode */ mode = pf->pool->mode; - if(mode&SF_SHARE) /* can only have write streams */ - { if(SFMODE(f,1) != SF_WRITE && _sfmode(f,SF_WRITE,1) < 0) + if(mode&SFIO_SHARE) /* can only have write streams */ + { if(SFMODE(f,1) != SFIO_WRITE && _sfmode(f,SFIO_WRITE,1) < 0) goto done; - if(SFMODE(pf,1) != SF_WRITE && _sfmode(pf,SF_WRITE,1) < 0) + if(SFMODE(pf,1) != SFIO_WRITE && _sfmode(pf,SFIO_WRITE,1) < 0) goto done; if(f->next > f->data && SFSYNC(f) < 0) /* start f clean */ goto done; diff --git a/src/lib/libast/sfio/sfpopen.c b/src/lib/libast/sfio/sfpopen.c index 177a05a94bf6..5e877dbebff8 100644 --- a/src/lib/libast/sfio/sfpopen.c +++ b/src/lib/libast/sfio/sfpopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -47,9 +47,9 @@ Sfio_t* sfpopen(Sfio_t* f, else pflags = 0; flags = 0; - if (sflags & SF_READ) + if (sflags & SFIO_READ) flags |= PROC_READ; - if (sflags & SF_WRITE) + if (sflags & SFIO_WRITE) flags |= PROC_WRITE; av[0] = "sh"; av[1] = "-c"; @@ -57,9 +57,9 @@ Sfio_t* sfpopen(Sfio_t* f, av[3] = 0; if (!(proc = procopen(0, av, 0, 0, flags))) return NULL; - if (!(f = sfnew(f, NULL, (size_t)SF_UNBOUND, - (sflags&SF_READ) ? proc->rfd : proc->wfd, sflags|((sflags&SF_RDWR)?0:SF_READ))) || - _sfpopen(f, (sflags&SF_READ) ? proc->wfd : -1, proc->pid, pflags) < 0) + if (!(f = sfnew(f, NULL, (size_t)SFIO_UNBOUND, + (sflags&SFIO_READ) ? proc->rfd : proc->wfd, sflags|((sflags&SFIO_RDWR)?0:SFIO_READ))) || + _sfpopen(f, (sflags&SFIO_READ) ? proc->wfd : -1, proc->pid, pflags) < 0) { if (f) sfclose(f); procclose(proc); diff --git a/src/lib/libast/sfio/sfprintf.c b/src/lib/libast/sfio/sfprintf.c index 949ef349d118..2fa6633b8b08 100644 --- a/src/lib/libast/sfio/sfprintf.c +++ b/src/lib/libast/sfio/sfprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -41,7 +41,7 @@ ssize_t sfvsprintf(char* s, size_t n, const char* form, va_list args) /* make a temp stream */ _Sfnotify = 0; - f = sfnew(NULL,NULL,(size_t)SF_UNBOUND, -1,SF_WRITE|SF_STRING); + f = sfnew(NULL,NULL,(size_t)SFIO_UNBOUND, -1,SFIO_WRITE|SFIO_STRING); _Sfnotify = notify; if(!f) return -1; diff --git a/src/lib/libast/sfio/sfprints.c b/src/lib/libast/sfio/sfprints.c index 7f1c5473113d..e4f6dade1bb9 100644 --- a/src/lib/libast/sfio/sfprints.c +++ b/src/lib/libast/sfio/sfprints.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -33,7 +33,7 @@ char* sfvprints(const char* form, va_list args) if(!f) /* make a string stream to write into */ { _Sfnotify = 0; - f = sfnew(NULL,NULL,(size_t)SF_UNBOUND, -1,SF_WRITE|SF_STRING); + f = sfnew(NULL,NULL,(size_t)SFIO_UNBOUND, -1,SFIO_WRITE|SFIO_STRING); _Sfnotify = notify; if(!f) return NULL; diff --git a/src/lib/libast/sfio/sfpurge.c b/src/lib/libast/sfio/sfpurge.c index 76e84b0b3107..c2e634fd7ec4 100644 --- a/src/lib/libast/sfio/sfpurge.c +++ b/src/lib/libast/sfio/sfpurge.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -28,24 +28,24 @@ int sfpurge(Sfio_t* f) { int mode; - if(!f || (mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode|SF_SYNCED,0) < 0) + if(!f || (mode = f->mode&SFIO_RDWR) != (int)f->mode && _sfmode(f,mode|SFIO_SYNCED,0) < 0) return -1; - if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf) - (void)(*f->disc->exceptf)(f,SF_PURGE,(void*)((int)1),f->disc); + if((f->flags&SFIO_IOCHECK) && f->disc && f->disc->exceptf) + (void)(*f->disc->exceptf)(f,SFIO_PURGE,(void*)((int)1),f->disc); if(f->disc == _Sfudisc) (void)sfclose((*_Sfstack)(f,NULL)); /* cannot purge read string streams */ - if((f->flags&SF_STRING) && (f->mode&SF_READ) ) + if((f->flags&SFIO_STRING) && (f->mode&SFIO_READ) ) goto done; SFLOCK(f,0); /* if memory map must be a read stream, pretend data is gone */ #ifdef MAP_TYPE - if(f->bits&SF_MMAP) + if(f->bits&SFIO_MMAP) { f->here -= f->endb - f->next; if(f->data) { SFMUNMAP(f,f->data,f->endb-f->data); @@ -56,20 +56,20 @@ int sfpurge(Sfio_t* f) } #endif - switch(f->mode&~SF_LOCK) + switch(f->mode&~SFIO_LOCK) { default : SFOPEN(f,0); return -1; - case SF_WRITE : + case SFIO_WRITE : f->next = f->data; - if(!f->proc || !(f->flags&SF_READ) || !(f->mode&SF_WRITE) ) + if(!f->proc || !(f->flags&SFIO_READ) || !(f->mode&SFIO_WRITE) ) break; /* 2-way pipe, must clear read buffer */ - (void)_sfmode(f,SF_READ,1); + (void)_sfmode(f,SFIO_READ,1); /* FALLTHROUGH */ - case SF_READ: + case SFIO_READ: if(f->extent >= 0 && f->endb > f->next) { f->here -= f->endb-f->next; (void)SFSK(f,f->here,SEEK_SET,f->disc); @@ -81,8 +81,8 @@ int sfpurge(Sfio_t* f) SFOPEN(f,0); done: - if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf) - (void)(*f->disc->exceptf)(f,SF_PURGE,(void*)((int)0),f->disc); + if((f->flags&SFIO_IOCHECK) && f->disc && f->disc->exceptf) + (void)(*f->disc->exceptf)(f,SFIO_PURGE,(void*)((int)0),f->disc); return 0; } diff --git a/src/lib/libast/sfio/sfputr.c b/src/lib/libast/sfio/sfputr.c index bf3383f4db57..6caf41a7fbad 100644 --- a/src/lib/libast/sfio/sfputr.c +++ b/src/lib/libast/sfio/sfputr.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -30,7 +30,7 @@ ssize_t sfputr(Sfio_t* f, /* write to this stream */ uchar *ps; char *ss; - if(!f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + if(!f || (f->mode != SFIO_WRITE && _sfmode(f,SFIO_WRITE,0) < 0)) return -1; SFLOCK(f,0); @@ -38,20 +38,20 @@ ssize_t sfputr(Sfio_t* f, /* write to this stream */ f->val = sn = -1; ss = (char*)s; for(w = 0; (*s || rc >= 0); ) { /* need to communicate string size to exception handler */ - if((f->flags&SF_STRING) && f->next >= f->endb ) + if((f->flags&SFIO_STRING) && f->next >= f->endb ) { sn = sn < 0 ? strlen(s) : (sn - (s-ss)); ss = (char*)s; /* save current checkpoint */ f->val = sn + (rc >= 0 ? 1 : 0); /* space requirement */ - f->bits |= SF_PUTR; /* tell sfflsbuf to use f->val */ + f->bits |= SFIO_PUTR; /* tell sfflsbuf to use f->val */ } SFWPEEK(f,ps,p); - f->bits &= ~SF_PUTR; /* remove any trace of this */ + f->bits &= ~SFIO_PUTR; /* remove any trace of this */ if(p < 0 ) /* something not right about buffering */ break; - if(p == 0 || (f->flags&SF_WHOLE) ) + if(p == 0 || (f->flags&SFIO_WHOLE) ) { n = sn < 0 ? strlen(s) : sn - (s-ss); if(p >= (n + (rc < 0 ? 0 : 1)) ) { /* buffer can hold everything */ @@ -108,11 +108,11 @@ ssize_t sfputr(Sfio_t* f, /* write to this stream */ } /* sync unseekable shared streams */ - if(f->extent < 0 && (f->flags&SF_SHARE) ) + if(f->extent < 0 && (f->flags&SFIO_SHARE) ) (void)SFFLSBUF(f,-1); /* check for line buffering */ - else if((f->flags&SF_LINE) && !(f->flags&SF_STRING) && (n = f->next-f->data) > 0) + else if((f->flags&SFIO_LINE) && !(f->flags&SFIO_STRING) && (n = f->next-f->data) > 0) { if(n > w) n = w; f->next -= n; diff --git a/src/lib/libast/sfio/sfraise.c b/src/lib/libast/sfio/sfraise.c index d534a8aacd9f..0fdfa32174a3 100644 --- a/src/lib/libast/sfio/sfraise.c +++ b/src/lib/libast/sfio/sfraise.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -58,15 +58,15 @@ int sfraise(Sfio_t* f, /* stream */ GETLOCAL(f,local); if(!SFKILLED(f) && !(local && - (type == SF_NEW || type == SF_CLOSING || - type == SF_FINAL || type == SF_ATEXIT)) && - SFMODE(f,local) != (f->mode&SF_RDWR) && _sfmode(f,0,local) < 0) + (type == SFIO_NEW || type == SFIO_CLOSING || + type == SFIO_FINAL || type == SFIO_ATEXIT)) && + SFMODE(f,local) != (f->mode&SFIO_RDWR) && _sfmode(f,0,local) < 0) return -1; SFLOCK(f,local); for(disc = f->disc; disc; ) { next = disc->disc; - if(type == SF_FINAL) + if(type == SFIO_FINAL) f->disc = next; if(disc->exceptf) diff --git a/src/lib/libast/sfio/sfrd.c b/src/lib/libast/sfio/sfrd.c index 491f3ea4d119..131d98c220cd 100644 --- a/src/lib/libast/sfio/sfrd.c +++ b/src/lib/libast/sfio/sfrd.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -37,7 +37,7 @@ static void _sfwrsync(void) continue; f = p->sf[0]; if(!SFFROZEN(f) && f->next > f->data && - (f->mode&SF_WRITE) && f->extent < 0 ) + (f->mode&SFIO_WRITE) && f->extent < 0 ) (void)_sfflsbuf(f,-1); } @@ -46,7 +46,7 @@ static void _sfwrsync(void) { f = _Sfpool.sf[n]; if(!SFFROZEN(f) && f->next > f->data && - (f->mode&SF_WRITE) && f->extent < 0 ) + (f->mode&SFIO_WRITE) && f->extent < 0 ) (void)_sfflsbuf(f,-1); } } @@ -61,25 +61,25 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) return -1; GETLOCAL(f,local); - if((rcrv = f->mode & (SF_RC|SF_RV)) ) - f->mode &= ~(SF_RC|SF_RV); - f->bits &= ~SF_JUSTSEEK; + if((rcrv = f->mode & (SFIO_RC|SFIO_RV)) ) + f->mode &= ~(SFIO_RC|SFIO_RV); + f->bits &= ~SFIO_JUSTSEEK; - if(f->mode&SF_PKRD) + if(f->mode&SFIO_PKRD) return -1; - if(!local && !(f->bits&SF_DCDOWN)) /* an external user's call */ - { if(f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) + if(!local && !(f->bits&SFIO_DCDOWN)) /* an external user's call */ + { if(f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0) return -1; if(f->next < f->endb) { if(SFSYNC(f) < 0) return -1; - if((f->mode&(SF_SYNCED|SF_READ)) == (SF_SYNCED|SF_READ) ) + if((f->mode&(SFIO_SYNCED|SFIO_READ)) == (SFIO_SYNCED|SFIO_READ) ) { f->endb = f->next = f->endr = f->data; - f->mode &= ~SF_SYNCED; + f->mode &= ~SFIO_SYNCED; } #ifdef MAP_TYPE - if((f->bits&SF_MMAP) && f->data) + if((f->bits&SFIO_MMAP) && f->data) { SFMUNMAP(f, f->data, f->endb-f->data); f->data = NULL; } @@ -90,13 +90,13 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) for(dosync = 0;;) { /* stream locked by sfsetfd() */ - if(!(f->flags&SF_STRING) && f->file < 0) + if(!(f->flags&SFIO_STRING) && f->file < 0) return 0; - f->flags &= ~(SF_EOF|SF_ERROR); + f->flags &= ~(SFIO_EOF|SFIO_ERROR); dc = disc; - if(f->flags&SF_STRING) + if(f->flags&SFIO_STRING) { if((r = (f->data+f->extent) - f->next) < 0) r = 0; if(r <= 0) @@ -106,20 +106,20 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) /* warn that a read is about to happen */ SFDISC(f,dc,readf); - if(dc && dc->exceptf && (f->flags&SF_IOCHECK) ) + if(dc && dc->exceptf && (f->flags&SFIO_IOCHECK) ) { int rv; if(local) SETLOCAL(f); - if((rv = _sfexcept(f,SF_READ,n,dc)) > 0) + if((rv = _sfexcept(f,SFIO_READ,n,dc)) > 0) n = rv; else if(rv < 0) - { f->flags |= SF_ERROR; + { f->flags |= SFIO_ERROR; return (ssize_t)rv; } } #ifdef MAP_TYPE - if(f->bits&SF_MMAP) + if(f->bits&SFIO_MMAP) { ssize_t a, round; struct stat st; @@ -130,13 +130,13 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) } /* actual seek location */ - if((f->flags&(SF_SHARE|SF_PUBLIC)) == (SF_SHARE|SF_PUBLIC) && + if((f->flags&(SFIO_SHARE|SFIO_PUBLIC)) == (SFIO_SHARE|SFIO_PUBLIC) && (r = SFSK(f,0,SEEK_CUR,dc)) != f->here) f->here = r; else f->here -= f->endb-f->next; /* before mapping, make sure we have data to map */ - if((f->flags&SF_SHARE) || (size_t)(r = f->extent-f->here) < n) + if((f->flags&SFIO_SHARE) || (size_t)(r = f->extent-f->here) < n) { if((r = fstat(f->file,&st)) < 0) goto do_except; if((r = (f->extent = st.st_size) - f->here) <= 0 ) @@ -167,14 +167,14 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) break; else { f->data = NULL; - if((r >>= 1) < (_Sfpage*SF_NMAP) || + if((r >>= 1) < (_Sfpage*SFIO_NMAP) || (errno != EAGAIN && errno != ENOMEM) ) break; } } if(f->data) - { if(f->bits&SF_SEQUENTIAL) + { if(f->bits&SFIO_SEQUENTIAL) SFMMSEQON(f,f->data,r); f->next = f->data+a; f->endr = f->endb = f->data+r; @@ -202,7 +202,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) (void)SFSK(f,f->here,SEEK_SET,dc); /* make a buffer */ - (void)SFSETBUF(f,f->tiny,(size_t)SF_UNBOUND); + (void)SFSETBUF(f,f->tiny,(size_t)SFIO_UNBOUND); if(!buf) { buf = f->data; @@ -219,8 +219,8 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) } /* make sure file pointer is right */ - if(f->extent >= 0 && (f->flags&SF_SHARE) ) - { if(!(f->flags&SF_PUBLIC) ) + if(f->extent >= 0 && (f->flags&SFIO_SHARE) ) + { if(!(f->flags&SFIO_PUBLIC) ) f->here = SFSK(f,f->here,SEEK_SET,dc); else f->here = SFSK(f,0,SEEK_CUR,dc); } @@ -229,12 +229,12 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) errno = 0; if(dc && dc->readf) - { int share = f->flags&SF_SHARE; + { int share = f->flags&SFIO_SHARE; if(rcrv) /* pass on rcrv for possible continuations */ f->mode |= rcrv; /* tell readf that no peeking necessary */ - else f->flags &= ~SF_SHARE; + else f->flags &= ~SFIO_SHARE; SFDCRD(f,buf,n,dc,r); @@ -245,15 +245,15 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) } else if(SFISNULL(f)) r = 0; - else if(f->extent < 0 && (f->flags&SF_SHARE) && rcrv) + else if(f->extent < 0 && (f->flags&SFIO_SHARE) && rcrv) { /* try peek read */ r = sfpkrd(f->file, (char*)buf, n, - (rcrv&SF_RC) ? (int)f->getr : -1, - -1L, (rcrv&SF_RV) ? 1 : 0); + (rcrv&SFIO_RC) ? (int)f->getr : -1, + -1L, (rcrv&SFIO_RV) ? 1 : 0); if(r > 0) - { if(rcrv&SF_RV) - f->mode |= SF_PKRD; - else f->mode |= SF_RC; + { if(rcrv&SFIO_RV) + f->mode |= SFIO_PKRD; + else f->mode |= SFIO_RC; } } else r = read(f->file,buf,n); @@ -262,8 +262,8 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) errno = oerrno; if(r > 0 ) - { if(!(f->bits&SF_DCDOWN) ) /* not a continuation call */ - { if(!(f->mode&SF_PKRD) ) + { if(!(f->bits&SFIO_DCDOWN) ) /* not a continuation call */ + { if(!(f->mode&SFIO_PKRD) ) { f->here += r; if(f->extent >= 0 && f->extent < f->here) f->extent = f->here; @@ -279,18 +279,18 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) do_except: if(local) SETLOCAL(f); - switch(_sfexcept(f,SF_READ,(ssize_t)r,dc)) + switch(_sfexcept(f,SFIO_READ,(ssize_t)r,dc)) { - case SF_ECONT : + case SFIO_ECONT : goto do_continue; - case SF_EDONE : + case SFIO_EDONE : n = local ? 0 : (ssize_t)r; return n; - case SF_EDISC : - if(!local && !(f->flags&SF_STRING)) + case SFIO_EDISC : + if(!local && !(f->flags&SFIO_STRING)) goto do_continue; /* FALLTHROUGH */ - case SF_ESTACK : + case SFIO_ESTACK : return -1; } diff --git a/src/lib/libast/sfio/sfread.c b/src/lib/libast/sfio/sfread.c index a3bc635bdefc..25143f4baa51 100644 --- a/src/lib/libast/sfio/sfread.c +++ b/src/lib/libast/sfio/sfread.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -35,30 +35,30 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */ return (ssize_t)(-1); GETLOCAL(f,local); - justseek = f->bits&SF_JUSTSEEK; f->bits &= ~SF_JUSTSEEK; + justseek = f->bits&SFIO_JUSTSEEK; f->bits &= ~SFIO_JUSTSEEK; if(!buf) return (ssize_t)(n == 0 ? 0 : -1) ; /* release peek lock */ - if(f->mode&SF_PEEK) - { if(!(f->mode&SF_READ) ) + if(f->mode&SFIO_PEEK) + { if(!(f->mode&SFIO_READ) ) return (ssize_t)(-1); - if(f->mode&SF_GETR) + if(f->mode&SFIO_GETR) { if(((uchar*)buf + f->val) != f->next && (!f->rsrv || f->rsrv->data != (uchar*)buf) ) return (ssize_t)(-1); - f->mode &= ~SF_PEEK; + f->mode &= ~SFIO_PEEK; return 0; } else { if((uchar*)buf != f->next) return (ssize_t)(-1); - f->mode &= ~SF_PEEK; - if(f->mode&SF_PKRD) + f->mode &= ~SFIO_PEEK; + if(f->mode&SFIO_PKRD) { /* actually read the data now */ - f->mode &= ~SF_PKRD; + f->mode &= ~SFIO_PKRD; if(n > 0) n = (r = read(f->file,f->data,n)) < 0 ? 0 : r; f->endb = f->data+n; @@ -71,9 +71,9 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */ } s = begs = (uchar*)buf; - for(;; f->mode &= ~SF_LOCK) + for(;; f->mode &= ~SFIO_LOCK) { /* check stream mode */ - if(SFMODE(f,local) != SF_READ && _sfmode(f,SF_READ,local) < 0) + if(SFMODE(f,local) != SFIO_READ && _sfmode(f,SFIO_READ,local) < 0) { n = s > begs ? s-begs : (size_t)(-1); return (ssize_t)n; } @@ -93,12 +93,12 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */ if(n <= 0) /* all done */ break; - if(!(f->flags&SF_STRING) && !(f->bits&SF_MMAP) ) + if(!(f->flags&SFIO_STRING) && !(f->bits&SFIO_MMAP) ) { f->next = f->endb = f->data; /* exact IO is desirable for these cases */ if(SFDIRECT(f,n) || - ((f->flags&SF_SHARE) && f->extent < 0) ) + ((f->flags&SFIO_SHARE) && f->extent < 0) ) r = (ssize_t)n; else if(justseek && n <= f->iosz && f->iosz <= f->size) r = f->iosz; /* limit buffering */ @@ -120,7 +120,7 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */ else { do_filbuf: if(justseek) - f->bits |= SF_JUSTSEEK; + f->bits |= SFIO_JUSTSEEK; if(SFFILBUF(f,-1) <= 0) break; } diff --git a/src/lib/libast/sfio/sfreserve.c b/src/lib/libast/sfio/sfreserve.c index 4a75baa32099..8eef92193096 100644 --- a/src/lib/libast/sfio/sfreserve.c +++ b/src/lib/libast/sfio/sfreserve.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -37,14 +37,14 @@ void* sfreserve(Sfio_t* f, /* file to peek */ sz = size < 0 ? -size : size; - /* see if we need to bias toward SF_WRITE instead of the default SF_READ */ + /* see if we need to bias toward SFIO_WRITE instead of the default SFIO_READ */ if(type < 0) mode = 0; - else if((mode = type&SF_WRITE) ) - type &= ~SF_WRITE; + else if((mode = type&SFIO_WRITE) ) + type &= ~SFIO_WRITE; /* return the last record */ - if(type == SF_LASTR ) + if(type == SFIO_LASTR ) { if((n = f->endb - f->next) > 0 && n == f->val ) { data = f->next; f->next += n; @@ -64,13 +64,13 @@ void* sfreserve(Sfio_t* f, /* file to peek */ if(type > 0) { if(type == 1 ) /* upward compatibility mode */ - type = SF_LOCKR; - else if(type != SF_LOCKR) + type = SFIO_LOCKR; + else if(type != SFIO_LOCKR) return NULL; } - if(size == 0 && (type < 0 || type == SF_LOCKR) ) - { if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) + if(size == 0 && (type < 0 || type == SFIO_LOCKR) ) + { if((f->mode&SFIO_RDWR) != f->mode && _sfmode(f,0,0) < 0) return NULL; SFLOCK(f,0); @@ -81,11 +81,11 @@ void* sfreserve(Sfio_t* f, /* file to peek */ } /* iterate until get to a stream that has data or buffer space */ - for(local = 0;; local = SF_LOCAL) + for(local = 0;; local = SFIO_LOCAL) { _Sfi = f->val = -1; - if(!mode && !(mode = f->flags&SF_READ) ) - mode = SF_WRITE; + if(!mode && !(mode = f->flags&SFIO_READ) ) + mode = SFIO_WRITE; if((int)f->mode != mode && _sfmode(f,mode,local) < 0) { SFOPEN(f,0); return NULL; @@ -99,7 +99,7 @@ void* sfreserve(Sfio_t* f, /* file to peek */ break; /* set amount to perform IO */ - if(size == 0 || (f->mode&SF_WRITE)) + if(size == 0 || (f->mode&SFIO_WRITE)) iosz = -1; else if(size < 0 && n == 0 && f->push) /* maybe stack-pop */ { if((iosz = f->push->endb - f->push->next) == 0) @@ -117,25 +117,25 @@ void* sfreserve(Sfio_t* f, /* file to peek */ /* do a buffer refill or flush */ now = n; - if(f->mode&SF_WRITE) + if(f->mode&SFIO_WRITE) (void)SFFLSBUF(f, iosz); - else if(type == SF_LOCKR && f->extent < 0 && (f->flags&SF_SHARE) ) + else if(type == SFIO_LOCKR && f->extent < 0 && (f->flags&SFIO_SHARE) ) { if(n == 0) /* peek-read only if there is no buffered data */ - { f->mode |= SF_RV; + { f->mode |= SFIO_RV; (void)SFFILBUF(f, iosz ); } if((n = f->endb - f->next) < sz) - { if(f->mode&SF_PKRD) + { if(f->mode&SFIO_PKRD) { f->endb = f->endr = f->next; - f->mode &= ~SF_PKRD; + f->mode &= ~SFIO_PKRD; } break; } } else - { /* sfreserve(f,0,0) == sfread(f, sfreserve(f,-1,SF_LOCKR), 0) */ + { /* sfreserve(f,0,0) == sfread(f, sfreserve(f,-1,SFIO_LOCKR), 0) */ if(size == 0 && type == 0) - f->mode |= SF_RV; + f->mode |= SFIO_RV; (void)SFFILBUF(f, iosz ); } @@ -150,7 +150,7 @@ void* sfreserve(Sfio_t* f, /* file to peek */ break; /* request was only to assess data availability */ - if(type == SF_LOCKR && size > 0 && n > 0 ) + if(type == SFIO_LOCKR && size > 0 && n > 0 ) break; } @@ -159,23 +159,23 @@ void* sfreserve(Sfio_t* f, /* file to peek */ if(size == 0 || n == 0) { if(n > 0) /* got data */ data = f->next; - else if(type == SF_LOCKR && size == 0 && (rsrv = _sfrsrv(f,0)) ) + else if(type == SFIO_LOCKR && size == 0 && (rsrv = _sfrsrv(f,0)) ) data = rsrv->data; } else if(n >= sz) /* got data */ data = f->next; - else if(f->flags&SF_STRING) /* try extending string buffer */ - { if((f->mode&SF_WRITE) && (f->flags&SF_MALLOC) ) + else if(f->flags&SFIO_STRING) /* try extending string buffer */ + { if((f->mode&SFIO_WRITE) && (f->flags&SFIO_MALLOC) ) { (void)SFWR(f,f->next,sz,f->disc); if((n = f->endb - f->next) >= sz ) data = f->next; } } - else if(f->mode&SF_WRITE) /* allocate side buffer */ - { if(type == SF_LOCKR && (rsrv = _sfrsrv(f, sz)) ) + else if(f->mode&SFIO_WRITE) /* allocate side buffer */ + { if(type == SFIO_LOCKR && (rsrv = _sfrsrv(f, sz)) ) data = rsrv->data; } - else if(type != SF_LOCKR && sz > f->size && (rsrv = _sfrsrv(f,sz)) ) + else if(type != SFIO_LOCKR && sz > f->size && (rsrv = _sfrsrv(f,sz)) ) { if((n = SFREAD(f,rsrv->data,sz)) >= sz) /* read side buffer */ data = rsrv->data; else rsrv->slen = -n; @@ -184,10 +184,10 @@ void* sfreserve(Sfio_t* f, /* file to peek */ SFOPEN(f,0); if(data) - { if(type == SF_LOCKR) - { f->mode |= SF_PEEK; - if((f->mode & SF_READ) && size == 0 && data != f->next) - f->mode |= SF_GETR; /* so sfread() will unlock */ + { if(type == SFIO_LOCKR) + { f->mode |= SFIO_PEEK; + if((f->mode & SFIO_READ) && size == 0 && data != f->next) + f->mode |= SFIO_GETR; /* so sfread() will unlock */ f->endr = f->endw = f->data; } else diff --git a/src/lib/libast/sfio/sfresize.c b/src/lib/libast/sfio/sfresize.c index 675ece5967ea..5ba081c923eb 100644 --- a/src/lib/libast/sfio/sfresize.c +++ b/src/lib/libast/sfio/sfresize.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -26,16 +26,16 @@ int sfresize(Sfio_t* f, Sfoff_t size) { if(size < 0 || f->extent < 0 || - !f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + !f || (f->mode != SFIO_WRITE && _sfmode(f,SFIO_WRITE,0) < 0)) return -1; SFLOCK(f,0); - if(f->flags&SF_STRING) + if(f->flags&SFIO_STRING) { SFSTRSIZE(f); if(f->extent >= size) - { if((f->flags&SF_MALLOC) && (f->next - f->data) <= size) + { if((f->flags&SFIO_MALLOC) && (f->next - f->data) <= size) { size_t s = (((size_t)size + 1023)/1024)*1024; void* d; if(s < f->size && (d = realloc(f->data, s)) ) diff --git a/src/lib/libast/sfio/sfscanf.c b/src/lib/libast/sfio/sfscanf.c index ee2367683e7c..633a8ef437a4 100644 --- a/src/lib/libast/sfio/sfscanf.c +++ b/src/lib/libast/sfio/sfscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -42,9 +42,9 @@ int sfvsscanf(const char* s, const char* form, va_list args) /* make a fake stream */ SFCLEAR(&f); - f.flags = SF_STRING|SF_READ; - f.bits = SF_PRIVATE; - f.mode = SF_READ; + f.flags = SFIO_STRING|SFIO_READ; + f.bits = SFIO_PRIVATE; + f.mode = SFIO_READ; f.size = strlen((char*)s); f.data = f.next = f.endw = (uchar*)s; f.endb = f.endr = f.data+f.size; diff --git a/src/lib/libast/sfio/sfseek.c b/src/lib/libast/sfio/sfseek.c index e2217c40f078..d4d41a44a78d 100644 --- a/src/lib/libast/sfio/sfseek.c +++ b/src/lib/libast/sfio/sfseek.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -27,13 +27,13 @@ static void newpos(Sfio_t* f, Sfoff_t p) { #ifdef MAP_TYPE - if((f->bits&SF_MMAP) && f->data) + if((f->bits&SFIO_MMAP) && f->data) { SFMUNMAP(f, f->data, f->endb-f->data); f->data = NULL; } #endif f->next = f->endr = f->endw = f->data; - f->endb = (f->mode&SF_WRITE) ? f->data+f->size : f->data; + f->endb = (f->mode&SFIO_WRITE) ? f->data+f->size : f->data; if((f->here = p) < 0) { f->extent = -1; f->here = 0; @@ -52,29 +52,29 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ GETLOCAL(f,local); - hardseek = (type|f->flags)&(SF_SHARE|SF_PUBLIC); + hardseek = (type|f->flags)&(SFIO_SHARE|SFIO_PUBLIC); - if(hardseek && f->mode == (SF_READ|SF_SYNCED) ) + if(hardseek && f->mode == (SFIO_READ|SFIO_SYNCED) ) { newpos(f,f->here); - f->mode = SF_READ; + f->mode = SFIO_READ; } /* set and initialize the stream to a definite mode */ - if((int)SFMODE(f,local) != (mode = f->mode&SF_RDWR)) + if((int)SFMODE(f,local) != (mode = f->mode&SFIO_RDWR)) { int flags = f->flags; - if(hardseek&SF_PUBLIC) /* seek ptr must follow file descriptor */ - f->flags |= SF_SHARE|SF_PUBLIC; + if(hardseek&SFIO_PUBLIC) /* seek ptr must follow file descriptor */ + f->flags |= SFIO_SHARE|SFIO_PUBLIC; mode = _sfmode(f,mode,local); - if(hardseek&SF_PUBLIC) + if(hardseek&SFIO_PUBLIC) f->flags = flags; if(mode < 0) return (Sfoff_t)(-1); } - mustsync = (type&SF_SHARE) && !(type&SF_PUBLIC) && - (f->mode&SF_READ) && !(f->flags&SF_STRING); + mustsync = (type&SFIO_SHARE) && !(type&SFIO_PUBLIC) && + (f->mode&SFIO_READ) && !(f->flags&SFIO_STRING); /* X/Open-compliant */ if((type &= (SEEK_SET|SEEK_CUR|SEEK_END)) != SEEK_SET && @@ -96,9 +96,9 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ SFLOCK(f,local); /* clear error and eof bits */ - f->flags &= ~(SF_EOF|SF_ERROR); + f->flags &= ~(SFIO_EOF|SFIO_ERROR); - while(f->flags&SF_STRING) + while(f->flags&SFIO_STRING) { SFSTRSIZE(f); if(type == SEEK_CUR) @@ -121,15 +121,15 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ { p = -1; goto done; } - else if(!(f->flags&SF_STRING)) + else if(!(f->flags&SFIO_STRING)) { p = r; goto done; } } - if(f->mode&SF_WRITE) + if(f->mode&SFIO_WRITE) { /* see if we can avoid flushing buffer */ - if(!hardseek && type < SEEK_END && !(f->flags&SF_APPENDWR) ) + if(!hardseek && type < SEEK_END && !(f->flags&SFIO_APPENDWR) ) { s = f->here + (f->next - f->data); r = p + (type == SEEK_SET ? 0 : s); if(r == s) @@ -144,8 +144,8 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ } } - if(type == SEEK_END || (f->mode&SF_WRITE) ) - { if((hardseek&SF_PUBLIC) || type == SEEK_END) + if(type == SEEK_END || (f->mode&SFIO_WRITE) ) + { if((hardseek&SFIO_PUBLIC) || type == SEEK_END) p = SFSK(f, p, type, f->disc); else { r = p + (type == SEEK_CUR ? f->here : 0); @@ -163,7 +163,7 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ if(r <= f->here && r >= (f->here - (f->endb-f->data)) ) { if((hardseek || (type == SEEK_CUR && p == 0)) ) { if((s = SFSK(f, 0, SEEK_CUR, f->disc)) == f->here || - (s >= 0 && !(hardseek&SF_PUBLIC) && + (s >= 0 && !(hardseek&SFIO_PUBLIC) && (s = SFSK(f, f->here, SEEK_SET, f->disc)) == f->here) ) goto near_done; else if(s < 0) @@ -188,11 +188,11 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ goto done; #ifdef MAP_TYPE - if(f->bits&SF_MMAP) + if(f->bits&SFIO_MMAP) { /* if mmap is not great, stop mmapping if moving around too much */ #if _mmap_worthy < 2 if((f->next - f->data) < ((f->endb - f->data)/4) ) - { SFSETBUF(f,f->tiny,(size_t)SF_UNBOUND); + { SFSETBUF(f,f->tiny,(size_t)SFIO_UNBOUND); hardseek = 1; /* this forces a hard seek below */ } else @@ -229,7 +229,7 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ /* seeking around and wasting data, be conservative */ if(f->iosz > 0 && (p > f->lpos || p < f->lpos-f->size) ) - f->bits |= SF_JUSTSEEK; + f->bits |= SFIO_JUSTSEEK; } if((hardseek || r != f->here) && (f->here = SFSK(f,r,SEEK_SET,f->disc)) != r) diff --git a/src/lib/libast/sfio/sfset.c b/src/lib/libast/sfio/sfset.c index 10071f9768f0..04217a584252 100644 --- a/src/lib/libast/sfio/sfset.c +++ b/src/lib/libast/sfio/sfset.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -34,10 +34,10 @@ int sfset(Sfio_t* f, int flags, int set) if(flags == 0 && set == 0) return f->flags&SFIO_FLAGS; - if((oflags = (f->mode&SF_RDWR)) != (int)f->mode) - { /* avoid sfsetbuf() isatty() call if user sets (SF_LINE|SF_WCWIDTH) */ - if(set && (flags & (SF_LINE|SF_WCWIDTH)) && !(f->flags & (SF_LINE|SF_WCWIDTH))) - { tflags = (SF_LINE|SF_WCWIDTH); + if((oflags = (f->mode&SFIO_RDWR)) != (int)f->mode) + { /* avoid sfsetbuf() isatty() call if user sets (SFIO_LINE|SFIO_WCWIDTH) */ + if(set && (flags & (SFIO_LINE|SFIO_WCWIDTH)) && !(f->flags & (SFIO_LINE|SFIO_WCWIDTH))) + { tflags = (SFIO_LINE|SFIO_WCWIDTH); f->flags |= tflags; } else tflags = 0; @@ -54,36 +54,36 @@ int sfset(Sfio_t* f, int flags, int set) /* preserve at least one rd/wr flag */ oflags = f->flags; - if(!(f->bits&SF_BOTH) || (flags&SF_RDWR) == SF_RDWR ) - flags &= ~SF_RDWR; + if(!(f->bits&SFIO_BOTH) || (flags&SFIO_RDWR) == SFIO_RDWR ) + flags &= ~SFIO_RDWR; /* set the flag */ if(set) - f->flags |= (flags&SF_SETS); - else f->flags &= ~(flags&SF_SETS); + f->flags |= (flags&SFIO_SETS); + else f->flags &= ~(flags&SFIO_SETS); /* must have at least one of read/write */ - if(!(f->flags&SF_RDWR)) - f->flags |= (oflags&SF_RDWR); + if(!(f->flags&SFIO_RDWR)) + f->flags |= (oflags&SFIO_RDWR); if(f->extent < 0) - f->flags &= ~SF_APPENDWR; + f->flags &= ~SFIO_APPENDWR; /* turn to appropriate mode as necessary */ - if((flags &= SF_RDWR) ) + if((flags &= SFIO_RDWR) ) { if(!set) - { if(flags == SF_READ) - flags = SF_WRITE; - else flags = SF_READ; + { if(flags == SFIO_READ) + flags = SFIO_WRITE; + else flags = SFIO_READ; } - if((flags == SF_WRITE && !(f->mode&SF_WRITE)) || - (flags == SF_READ && !(f->mode&(SF_READ|SF_SYNCED))) ) + if((flags == SFIO_WRITE && !(f->mode&SFIO_WRITE)) || + (flags == SFIO_READ && !(f->mode&(SFIO_READ|SFIO_SYNCED))) ) (void)_sfmode(f,flags,1); } /* if not shared or unseekable, public means nothing */ - if(!(f->flags&SF_SHARE) || f->extent < 0) - f->flags &= ~SF_PUBLIC; + if(!(f->flags&SFIO_SHARE) || f->extent < 0) + f->flags &= ~SFIO_PUBLIC; SFOPEN(f,0); return oflags&SFIO_FLAGS; diff --git a/src/lib/libast/sfio/sfsetbuf.c b/src/lib/libast/sfio/sfsetbuf.c index 10b53ebf68fb..edf27210315b 100644 --- a/src/lib/libast/sfio/sfsetbuf.c +++ b/src/lib/libast/sfio/sfsetbuf.c @@ -55,9 +55,9 @@ static int sfsetlinemode(void) char* endw; static int modes = -1; - static const char sf_line[] = "SF_LINE"; - static const char sf_maxr[] = "SF_MAXR="; - static const char sf_wcwidth[] = "SF_WCWIDTH"; + static const char sf_line[] = "SFIO_LINE"; + static const char sf_maxr[] = "SFIO_MAXR="; + static const char sf_wcwidth[] = "SFIO_WCWIDTH"; #define ISSEPAR(c) ((c) == ',' || (c) == ' ' || (c) == '\t') if (modes < 0) @@ -70,13 +70,13 @@ static int sfsetlinemode(void) ; if((endw-astsfio) > (sizeof(sf_line)-1) && strncmp(astsfio,sf_line,sizeof(sf_line)-1) == 0) - modes |= SF_LINE; + modes |= SFIO_LINE; else if((endw-astsfio) > (sizeof(sf_maxr)-1) && strncmp(astsfio,sf_maxr,sizeof(sf_maxr)-1) == 0) _Sfmaxr = (ssize_t)strtonll(astsfio+sizeof(sf_maxr)-1,NULL,NULL,0); else if((endw-astsfio) > (sizeof(sf_wcwidth)-1) && strncmp(astsfio,sf_wcwidth,sizeof(sf_wcwidth)-1) == 0) - modes |= SF_WCWIDTH; + modes |= SFIO_WCWIDTH; } } } @@ -106,31 +106,31 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ if(size == 0 && buf) { /* special case to get buffer info */ - _Sfi = f->val = (f->bits&SF_MMAP) ? (f->endb-f->data) : f->size; + _Sfi = f->val = (f->bits&SFIO_MMAP) ? (f->endb-f->data) : f->size; return f->data; } /* cleanup actions already done, don't allow write buffering any more */ - if(_Sfexiting && !(f->flags&SF_STRING) && (f->mode&SF_WRITE)) + if(_Sfexiting && !(f->flags&SFIO_STRING) && (f->mode&SFIO_WRITE)) { buf = NULL; size = 0; } - if((init = f->mode&SF_INIT) ) + if((init = f->mode&SFIO_INIT) ) { if(!f->pool && _sfsetpool(f) < 0) return NULL; } - else if((f->mode&SF_RDWR) != SFMODE(f,local) && _sfmode(f,0,local) < 0) + else if((f->mode&SFIO_RDWR) != SFMODE(f,local) && _sfmode(f,0,local) < 0) return NULL; if(init) - f->mode = (f->mode&SF_RDWR)|SF_LOCK; + f->mode = (f->mode&SFIO_RDWR)|SFIO_LOCK; else { int rv; /* make sure there is no hidden read data */ - if(f->proc && (f->flags&SF_READ) && (f->mode&SF_WRITE) && - _sfmode(f,SF_READ,local) < 0) + if(f->proc && (f->flags&SFIO_READ) && (f->mode&SFIO_WRITE) && + _sfmode(f,SFIO_READ,local) < 0) return NULL; /* synchronize first */ @@ -138,8 +138,8 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ if(rv < 0) return NULL; - /* turn off the SF_SYNCED bit because buffer is changing */ - f->mode &= ~SF_SYNCED; + /* turn off the SFIO_SYNCED bit because buffer is changing */ + f->mode &= ~SFIO_SYNCED; } SFLOCK(f,local); @@ -156,7 +156,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ } else /* initialize stream as if in the default case */ { buf = NULL; - size = (size_t)SF_UNBOUND; + size = (size_t)SFIO_UNBOUND; } } @@ -164,11 +164,11 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ oflags = f->flags; #ifdef MAP_TYPE - /* see if memory mapping is possible (see sfwrite for SF_BOTH) */ - okmmap = (buf || (f->flags&SF_STRING) || (f->flags&SF_RDWR) == SF_RDWR) ? 0 : 1; + /* see if memory mapping is possible (see sfwrite for SFIO_BOTH) */ + okmmap = (buf || (f->flags&SFIO_STRING) || (f->flags&SFIO_RDWR) == SFIO_RDWR) ? 0 : 1; /* save old buffer info */ - if(f->bits&SF_MMAP) + if(f->bits&SFIO_MMAP) { if(f->data) { SFMUNMAP(f,f->data,f->endb-f->data); f->data = NULL; @@ -182,12 +182,12 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ obuf = f->data; osize = f->size; - f->flags &= ~SF_MALLOC; - f->bits &= ~SF_MMAP; + f->flags &= ~SFIO_MALLOC; + f->bits &= ~SFIO_MMAP; /* pure read/string streams must have a valid string */ - if((f->flags&(SF_RDWR|SF_STRING)) == SF_RDSTR && - (size == (size_t)SF_UNBOUND || !buf)) + if((f->flags&(SFIO_RDWR|SFIO_STRING)) == SFIO_RDSTR && + (size == (size_t)SFIO_UNBOUND || !buf)) size = 0; /* set disc to the first discipline with a seekf */ @@ -195,7 +195,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ if(disc->seekf) break; - if((init || local) && !(f->flags&SF_STRING)) + if((init || local) && !(f->flags&SFIO_STRING)) { /* ASSERT(f->file >= 0) */ st.st_mode = 0; @@ -222,7 +222,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ #endif bufsize = 64 * 1024; #ifdef MAP_TYPE - if(S_ISDIR(st.st_mode) || (Sfoff_t)st.st_size < (Sfoff_t)SF_GRAIN) + if(S_ISDIR(st.st_mode) || (Sfoff_t)st.st_size < (Sfoff_t)SFIO_GRAIN) okmmap = 0; #endif if(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) @@ -244,7 +244,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ #if _lib_getpagesize if((_Sfpage = (size_t)getpagesize()) <= 0) #endif - _Sfpage = SF_PAGE; + _Sfpage = SFIO_PAGE; } #if SFSETLINEMODE @@ -257,7 +257,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ /* seekable std-devices are share-public by default */ if(f == sfstdin || f == sfstdout || f == sfstderr) - f->flags |= SF_SHARE|SF_PUBLIC; + f->flags |= SFIO_SHARE|SFIO_PUBLIC; } else { @@ -269,11 +269,11 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ { if(S_ISCHR(st.st_mode) ) { int oerrno = errno; - bufsize = SF_GRAIN; + bufsize = SFIO_GRAIN; /* set line mode for terminals */ - if(!(f->flags&(SF_LINE|SF_WCWIDTH)) && isatty(f->file)) - f->flags |= SF_LINE|SF_WCWIDTH; + if(!(f->flags&(SFIO_LINE|SFIO_WCWIDTH)) && isatty(f->file)) + f->flags |= SFIO_LINE|SFIO_WCWIDTH; #if _sys_stat else /* special case /dev/null */ { int dev, ino; @@ -297,25 +297,25 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ } /* initialize side buffer for r+w unseekable streams */ - if(!f->proc && (f->bits&SF_BOTH) ) + if(!f->proc && (f->bits&SFIO_BOTH) ) (void)_sfpopen(f,-1,-1,1); } } } #ifdef MAP_TYPE - if(okmmap && size && (f->mode&SF_READ) && f->extent >= 0 ) + if(okmmap && size && (f->mode&SFIO_READ) && f->extent >= 0 ) { /* see if we can try memory mapping */ if(!disc) for(disc = f->disc; disc; disc = disc->disc) if(disc->readf) break; if(!disc) - { f->bits |= SF_MMAP; - if(size == (size_t)SF_UNBOUND) + { f->bits |= SFIO_MMAP; + if(size == (size_t)SFIO_UNBOUND) { if(bufsize > _Sfpage) - size = bufsize * SF_NMAP; - else size = _Sfpage * SF_NMAP; + size = bufsize * SFIO_NMAP; + else size = _Sfpage * SFIO_NMAP; if(size > 256*1024) size = 256*1024; } @@ -325,17 +325,17 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ /* get buffer space */ setbuf: - if(size == (size_t)SF_UNBOUND) + if(size == (size_t)SFIO_UNBOUND) { /* define a default size suitable for block transfer */ if(init && osize > 0) size = osize; - else if(f == sfstderr && (f->mode&SF_WRITE)) + else if(f == sfstderr && (f->mode&SFIO_WRITE)) size = 0; - else if(f->flags&SF_STRING ) - size = SF_GRAIN; - else if((f->flags&SF_READ) && !(f->bits&SF_BOTH) && + else if(f->flags&SFIO_STRING ) + size = SFIO_GRAIN; + else if((f->flags&SFIO_READ) && !(f->bits&SFIO_BOTH) && f->extent > 0 && f->extent < (Sfoff_t)_Sfpage ) - size = (((size_t)f->extent + SF_GRAIN-1)/SF_GRAIN)*SF_GRAIN; + size = (((size_t)f->extent + SFIO_GRAIN-1)/SFIO_GRAIN)*SFIO_GRAIN; else if((ssize_t)(size = _Sfpage) < bufsize) size = bufsize; @@ -343,12 +343,12 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ } sf_malloc = 0; - if(size > 0 && !buf && !(f->bits&SF_MMAP)) + if(size > 0 && !buf && !(f->bits&SFIO_MMAP)) { /* try to allocate a buffer */ if(obuf && size == (size_t)osize && init) { buf = obuf; obuf = NULL; - sf_malloc = (oflags&SF_MALLOC); + sf_malloc = (oflags&SFIO_MALLOC); } if(!buf) { /* do allocation */ @@ -358,11 +358,11 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ else size /= 2; } if(size > 0) - sf_malloc = SF_MALLOC; + sf_malloc = SFIO_MALLOC; } } - if(size == 0 && !(f->flags&SF_STRING) && !(f->bits&SF_MMAP) && (f->mode&SF_READ)) + if(size == 0 && !(f->flags&SFIO_STRING) && !(f->bits&SFIO_MMAP) && (f->mode&SFIO_READ)) { /* use the internal buffer */ size = sizeof(f->tiny); buf = f->tiny; @@ -371,21 +371,21 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ /* set up new buffer */ f->size = size; f->next = f->data = f->endr = f->endw = (uchar*)buf; - f->endb = (f->mode&SF_READ) ? f->data : f->data+size; - if(f->flags&SF_STRING) + f->endb = (f->mode&SFIO_READ) ? f->data : f->data+size; + if(f->flags&SFIO_STRING) { /* these fields are used to test actual size - see sfseek() */ f->extent = (!sf_malloc && - ((f->flags&SF_READ) || (f->bits&SF_BOTH)) ) ? size : 0; + ((f->flags&SFIO_READ) || (f->bits&SFIO_BOTH)) ) ? size : 0; f->here = 0; /* read+string stream should have all data available */ - if((f->mode&SF_READ) && !sf_malloc) + if((f->mode&SFIO_READ) && !sf_malloc) f->endb = f->data+size; } - f->flags = (f->flags & ~SF_MALLOC)|sf_malloc; + f->flags = (f->flags & ~SFIO_MALLOC)|sf_malloc; - if(obuf && obuf != f->data && osize > 0 && (oflags&SF_MALLOC)) + if(obuf && obuf != f->data && osize > 0 && (oflags&SFIO_MALLOC)) { free(obuf); obuf = NULL; } @@ -399,7 +399,7 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ ** blksz should also be a power-of-2 for optimal disk seeks. */ if(blksz <= 0 || (blksz & (blksz-1)) != 0 ) - blksz = SF_GRAIN; + blksz = SFIO_GRAIN; while(blksz > f->size/2) blksz /= 2; f->blksz = blksz; diff --git a/src/lib/libast/sfio/sfsetfd.c b/src/lib/libast/sfio/sfsetfd.c index 5a9e918b9990..3f24d81c2474 100644 --- a/src/lib/libast/sfio/sfsetfd.c +++ b/src/lib/libast/sfio/sfsetfd.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -53,17 +53,17 @@ int sfsetfd(Sfio_t* f, int newfd) if(!f) return -1; - if(f->flags&SF_STRING) + if(f->flags&SFIO_STRING) return -1; - if((f->mode&SF_INIT) && f->file < 0) + if((f->mode&SFIO_INIT) && f->file < 0) { /* restoring file descriptor after a previous freeze */ if(newfd < 0) return -1; } else { /* change file descriptor */ - if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) + if((f->mode&SFIO_RDWR) != f->mode && _sfmode(f,0,0) < 0) return -1; SFLOCK(f,0); @@ -78,23 +78,23 @@ int sfsetfd(Sfio_t* f, int newfd) } else { /* sync stream if necessary */ - if(((f->mode&SF_WRITE) && f->next > f->data) || - (f->mode&SF_READ) || f->disc == _Sfudisc) + if(((f->mode&SFIO_WRITE) && f->next > f->data) || + (f->mode&SFIO_READ) || f->disc == _Sfudisc) { if(SFSYNC(f) < 0) { SFOPEN(f,0); return -1; } } - if(((f->mode&SF_WRITE) && f->next > f->data) || - ((f->mode&SF_READ) && f->extent < 0 && + if(((f->mode&SFIO_WRITE) && f->next > f->data) || + ((f->mode&SFIO_READ) && f->extent < 0 && f->next < f->endb) ) { SFOPEN(f,0); return -1; } #ifdef MAP_TYPE - if((f->bits&SF_MMAP) && f->data) + if((f->bits&SFIO_MMAP) && f->data) { SFMUNMAP(f,f->data,f->endb-f->data); f->data = NULL; } @@ -103,8 +103,8 @@ int sfsetfd(Sfio_t* f, int newfd) /* make stream appears uninitialized */ f->endb = f->endr = f->endw = f->data; f->extent = f->here = 0; - f->mode = (f->mode&SF_RDWR)|SF_INIT; - f->bits &= ~SF_NULL; /* off /dev/null handling */ + f->mode = (f->mode&SFIO_RDWR)|SFIO_INIT; + f->bits &= ~SFIO_NULL; /* off /dev/null handling */ } } @@ -113,7 +113,7 @@ int sfsetfd(Sfio_t* f, int newfd) /* notify changes */ if(_Sfnotify) - (*_Sfnotify)(f, SF_SETFD, (void*)((long)newfd)); + (*_Sfnotify)(f, SFIO_SETFD, (void*)((long)newfd)); f->file = newfd; diff --git a/src/lib/libast/sfio/sfsize.c b/src/lib/libast/sfio/sfsize.c index a037abc01be6..0325657fdccc 100644 --- a/src/lib/libast/sfio/sfsize.c +++ b/src/lib/libast/sfio/sfsize.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -28,10 +28,10 @@ Sfoff_t sfsize(Sfio_t* f) int mode; Sfoff_t s; - if(!f || ((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0)) + if(!f || ((mode = f->mode&SFIO_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0)) return (Sfoff_t)(-1); - if(f->flags&SF_STRING) + if(f->flags&SFIO_STRING) { SFSTRSIZE(f); return f->extent; } @@ -41,7 +41,7 @@ Sfoff_t sfsize(Sfio_t* f) s = f->here; if(f->extent >= 0) - { if(f->flags&(SF_SHARE|SF_APPENDWR)) + { if(f->flags&(SFIO_SHARE|SFIO_APPENDWR)) { for(disc = f->disc; disc; disc = disc->disc) if(disc->seekf) break; @@ -63,14 +63,14 @@ Sfoff_t sfsize(Sfio_t* f) #endif } - if((f->flags&(SF_SHARE|SF_PUBLIC)) == (SF_SHARE|SF_PUBLIC)) + if((f->flags&(SFIO_SHARE|SFIO_PUBLIC)) == (SFIO_SHARE|SFIO_PUBLIC)) f->here = SFSK(f,0,SEEK_CUR,f->disc); } - if(f->here != s && (f->mode&SF_READ) ) + if(f->here != s && (f->mode&SFIO_READ) ) { /* buffered data is known to be invalid */ #ifdef MAP_TYPE - if((f->bits&SF_MMAP) && f->data) + if((f->bits&SFIO_MMAP) && f->data) { SFMUNMAP(f,f->data,f->endb-f->data); f->data = NULL; } @@ -84,9 +84,9 @@ Sfoff_t sfsize(Sfio_t* f) f->extent = f->here; if((s = f->extent) >= 0) - { if(f->flags&SF_APPENDWR) + { if(f->flags&SFIO_APPENDWR) s += (f->next - f->data); - else if(f->mode&SF_WRITE) + else if(f->mode&SFIO_WRITE) { s = f->here + (f->next - f->data); if(s < f->extent) s = f->extent; diff --git a/src/lib/libast/sfio/sfsk.c b/src/lib/libast/sfio/sfsk.c index 921908ec5165..fceb86e8b769 100644 --- a/src/lib/libast/sfio/sfsk.c +++ b/src/lib/libast/sfio/sfsk.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -33,13 +33,13 @@ Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) return (Sfoff_t)(-1); GETLOCAL(f,local); - if(!local && !(f->bits&SF_DCDOWN)) - { if((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0) + if(!local && !(f->bits&SFIO_DCDOWN)) + { if((mode = f->mode&SFIO_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0) return (Sfoff_t)(-1); if(SFSYNC(f) < 0) return (Sfoff_t)(-1); #ifdef MAP_TYPE - if(f->mode == SF_READ && (f->bits&SF_MMAP) && f->data) + if(f->mode == SFIO_READ && (f->bits&SFIO_MMAP) && f->data) { SFMUNMAP(f, f->data, f->endb-f->data); f->data = NULL; } @@ -52,7 +52,7 @@ Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) for(;;) { dc = disc; - if(f->flags&SF_STRING) + if(f->flags&SFIO_STRING) { SFSTRSIZE(f); if(type == SEEK_SET) s = (ssize_t)addr; @@ -75,11 +75,11 @@ Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) if(local) SETLOCAL(f); - switch(_sfexcept(f,SF_SEEK,s,dc)) + switch(_sfexcept(f,SFIO_SEEK,s,dc)) { - case SF_EDISC: - case SF_ECONT: - if(f->flags&SF_STRING) + case SFIO_EDISC: + case SFIO_ECONT: + if(f->flags&SFIO_STRING) return (Sfoff_t)s; goto do_continue; default: diff --git a/src/lib/libast/sfio/sfstack.c b/src/lib/libast/sfio/sfstack.c index eb94f8bcec65..64ba7fc2c16a 100644 --- a/src/lib/libast/sfio/sfstack.c +++ b/src/lib/libast/sfio/sfstack.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -31,9 +31,9 @@ Sfio_t* sfstack(Sfio_t* f1, /* base of stack */ Sfio_t* rf; Sfrsrv_t* rsrv; - if(f1 && (f1->mode&SF_RDWR) != f1->mode && _sfmode(f1,0,0) < 0) + if(f1 && (f1->mode&SFIO_RDWR) != f1->mode && _sfmode(f1,0,0) < 0) return NULL; - if(f2 && (f2->mode&SF_RDWR) != f2->mode && _sfmode(f2,0,0) < 0) + if(f2 && (f2->mode&SFIO_RDWR) != f2->mode && _sfmode(f2,0,0) < 0) return NULL; if(!f1) return f2; @@ -41,10 +41,10 @@ Sfio_t* sfstack(Sfio_t* f1, /* base of stack */ /* give access to other internal functions */ _Sfstack = sfstack; - if(f2 == SF_POPSTACK) + if(f2 == SFIO_POPSTACK) { if(!(f2 = f1->push)) return NULL; - f2->mode &= ~SF_PUSH; + f2->mode &= ~SFIO_PUSH; } else { if(f2->push) @@ -75,13 +75,13 @@ Sfio_t* sfstack(Sfio_t* f1, /* base of stack */ if(f2->push != f2) { /* freeze the pushed stream */ - f2->mode |= SF_PUSH; + f2->mode |= SFIO_PUSH; f1->push = f2; rf = f1; } else { /* unfreeze the just exposed stream */ - f1->mode &= ~SF_PUSH; + f1->mode &= ~SFIO_PUSH; f2->push = NULL; rf = f2; } diff --git a/src/lib/libast/sfio/sfswap.c b/src/lib/libast/sfio/sfswap.c index 95d9c4266266..416849f84361 100644 --- a/src/lib/libast/sfio/sfswap.c +++ b/src/lib/libast/sfio/sfswap.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,7 +22,7 @@ /* Swap two streams. If the second argument is NULL, ** a new stream will be created. Always return the second argument ** or the new stream. Note that this function will always work -** unless streams are locked by SF_PUSH. +** unless streams are locked by SFIO_PUSH. ** ** Written by Kiem-Phong Vo. */ @@ -33,27 +33,27 @@ Sfio_t* sfswap(Sfio_t* f1, Sfio_t* f2) int f1pool, f2pool, f1flags, f2flags; unsigned int f1mode, f2mode; - if(!f1 || (f1->mode&SF_AVAIL) || (SFFROZEN(f1) && (f1->mode&SF_PUSH)) ) + if(!f1 || (f1->mode&SFIO_AVAIL) || (SFFROZEN(f1) && (f1->mode&SFIO_PUSH)) ) return NULL; - if(f2 && SFFROZEN(f2) && (f2->mode&SF_PUSH) ) + if(f2 && SFFROZEN(f2) && (f2->mode&SFIO_PUSH) ) return NULL; if(f1 == f2) return f2; f1mode = f1->mode; SFLOCK(f1,0); - f1->mode |= SF_PUSH; /* make sure there is no recursion on f1 */ + f1->mode |= SFIO_PUSH; /* make sure there is no recursion on f1 */ if(f2) { f2mode = f2->mode; SFLOCK(f2,0); - f2->mode |= SF_PUSH; /* make sure there is no recursion on f2 */ + f2->mode |= SFIO_PUSH; /* make sure there is no recursion on f2 */ } else { f2 = f1->file == 0 ? sfstdin : f1->file == 1 ? sfstdout : f1->file == 2 ? sfstderr : NULL; - if((!f2 || !(f2->mode&SF_AVAIL)) ) + if((!f2 || !(f2->mode&SFIO_AVAIL)) ) { if(!(f2 = (Sfio_t*)malloc(sizeof(Sfio_t))) ) { f1->mode = f1mode; SFOPEN(f1,0); @@ -62,8 +62,8 @@ Sfio_t* sfswap(Sfio_t* f1, Sfio_t* f2) SFCLEAR(f2); } - f2->mode = SF_AVAIL|SF_LOCK; - f2mode = SF_AVAIL; + f2->mode = SFIO_AVAIL|SFIO_LOCK; + f2mode = SFIO_AVAIL; } if(!f1->pool) @@ -89,16 +89,16 @@ Sfio_t* sfswap(Sfio_t* f1, Sfio_t* f2) if(f1pool >= 0) f2->pool->sf[f1pool] = f2; - if(f2flags&SF_STATIC) - f2->flags |= SF_STATIC; - else f2->flags &= ~SF_STATIC; + if(f2flags&SFIO_STATIC) + f2->flags |= SFIO_STATIC; + else f2->flags &= ~SFIO_STATIC; - if(f1flags&SF_STATIC) - f1->flags |= SF_STATIC; - else f1->flags &= ~SF_STATIC; + if(f1flags&SFIO_STATIC) + f1->flags |= SFIO_STATIC; + else f1->flags &= ~SFIO_STATIC; - if(f2mode&SF_AVAIL) /* swapping to a closed stream */ - { if(!(f1->flags&SF_STATIC) ) + if(f2mode&SFIO_AVAIL) /* swapping to a closed stream */ + { if(!(f1->flags&SFIO_STATIC) ) free(f1); } else diff --git a/src/lib/libast/sfio/sfsync.c b/src/lib/libast/sfio/sfsync.c index fdb8aed2eb60..7f41f8e0b0fa 100644 --- a/src/lib/libast/sfio/sfsync.c +++ b/src/lib/libast/sfio/sfsync.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -46,16 +46,16 @@ static int _sfall(void) { count += 1; f = p->sf[n]; - if(f->flags&SF_STRING ) + if(f->flags&SFIO_STRING ) goto did_sync; if(SFFROZEN(f)) continue; - if((f->mode&SF_READ) && (f->mode&SF_SYNCED) ) + if((f->mode&SFIO_READ) && (f->mode&SFIO_SYNCED) ) goto did_sync; - if((f->mode&SF_READ) && !(f->bits&SF_MMAP) && + if((f->mode&SFIO_READ) && !(f->bits&SFIO_MMAP) && f->next == f->endb) goto did_sync; - if((f->mode&SF_WRITE) && !(f->bits&SF_HOLE) && + if((f->mode&SFIO_WRITE) && !(f->bits&SFIO_HOLE) && f->next == f->data) goto did_sync; @@ -90,11 +90,11 @@ int sfsync(Sfio_t* f) rv = 0; - lock = origf->mode&SF_LOCK; - if(origf->mode == (SF_SYNCED|SF_READ) ) /* already synced */ + lock = origf->mode&SFIO_LOCK; + if(origf->mode == (SFIO_SYNCED|SFIO_READ) ) /* already synced */ goto done; - if((origf->mode&SF_RDWR) != SFMODE(origf,local) && _sfmode(origf,0,local) < 0) + if((origf->mode&SFIO_RDWR) != SFMODE(origf,local) && _sfmode(origf,0,local) < 0) { rv = -1; goto done; } @@ -103,46 +103,46 @@ int sfsync(Sfio_t* f) { unsigned int mode; - if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf) - (void)(*f->disc->exceptf)(f,SF_SYNC,(void*)((int)1),f->disc); + if((f->flags&SFIO_IOCHECK) && f->disc && f->disc->exceptf) + (void)(*f->disc->exceptf)(f,SFIO_SYNC,(void*)((int)1),f->disc); SFLOCK(f,local); /* pretend that this stream is not on a stack */ - mode = f->mode&SF_PUSH; - f->mode &= ~SF_PUSH; + mode = f->mode&SFIO_PUSH; + f->mode &= ~SFIO_PUSH; /* these streams do not need synchronization */ - if((f->flags&SF_STRING) || (f->mode&SF_SYNCED)) + if((f->flags&SFIO_STRING) || (f->mode&SFIO_SYNCED)) goto next; - if((f->mode&SF_WRITE) && (f->next > f->data || (f->bits&SF_HOLE)) ) + if((f->mode&SFIO_WRITE) && (f->next > f->data || (f->bits&SFIO_HOLE)) ) { /* sync the buffer, make sure pool doesn't move */ - unsigned int pool = f->mode&SF_POOL; - f->mode &= ~SF_POOL; + unsigned int pool = f->mode&SFIO_POOL; + f->mode &= ~SFIO_POOL; if(f->next > f->data && (SFWRALL(f), SFFLSBUF(f,-1)) < 0) rv = -1; - if(!SFISNULL(f) && (f->bits&SF_HOLE) ) + if(!SFISNULL(f) && (f->bits&SFIO_HOLE) ) { /* realize a previously created hole of 0's */ if(SFSK(f,(Sfoff_t)(-1),SEEK_CUR,f->disc) >= 0) (void)SFWR(f,"",1,f->disc); - f->bits &= ~SF_HOLE; + f->bits &= ~SFIO_HOLE; } f->mode |= pool; } - if((f->mode&SF_READ) && f->extent >= 0 && - ((f->bits&SF_MMAP) || f->next < f->endb) ) + if((f->mode&SFIO_READ) && f->extent >= 0 && + ((f->bits&SFIO_MMAP) || f->next < f->endb) ) { /* make sure the file pointer is at the right place */ f->here -= (f->endb-f->next); f->endr = f->endw = f->data; - f->mode = SF_READ|SF_SYNCED|lock; + f->mode = SFIO_READ|SFIO_SYNCED|lock; (void)SFSK(f,f->here,SEEK_SET,f->disc); - if((f->flags&SF_SHARE) && !(f->flags&SF_PUBLIC) && - !(f->bits&SF_MMAP) ) + if((f->flags&SFIO_SHARE) && !(f->flags&SFIO_PUBLIC) && + !(f->bits&SFIO_MMAP) ) { f->endb = f->next = f->data; - f->mode &= ~SF_SYNCED; + f->mode &= ~SFIO_SYNCED; } } @@ -150,12 +150,12 @@ int sfsync(Sfio_t* f) f->mode |= mode; SFOPEN(f,local); - if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf) - (void)(*f->disc->exceptf)(f,SF_SYNC,(void*)((int)0),f->disc); + if((f->flags&SFIO_IOCHECK) && f->disc && f->disc->exceptf) + (void)(*f->disc->exceptf)(f,SFIO_SYNC,(void*)((int)0),f->disc); } done: - if(!local && f && (f->mode&SF_POOL) && f->pool && f != f->pool->sf[0]) + if(!local && f && (f->mode&SFIO_POOL) && f->pool && f != f->pool->sf[0]) SFSYNC(f->pool->sf[0]); return rv; diff --git a/src/lib/libast/sfio/sftable.c b/src/lib/libast/sfio/sftable.c index 2e5a507c874a..9447bc8664b1 100644 --- a/src/lib/libast/sfio/sftable.c +++ b/src/lib/libast/sfio/sftable.c @@ -482,9 +482,9 @@ static const unsigned char ldbl_inf[] = { _ast_ldbl_inf_init }; static int sfcvinit(void) { int d, l; - for(d = 0; d <= SF_MAXCHAR; ++d) - { _Sfcv36[d] = SF_RADIX; - _Sfcv64[d] = SF_RADIX; + for(d = 0; d <= SFIO_MAXCHAR; ++d) + { _Sfcv36[d] = SFIO_RADIX; + _Sfcv64[d] = SFIO_RADIX; } /* [0-9] */ @@ -506,7 +506,7 @@ static int sfcvinit(void) } /* remaining digits */ - for(; d < SF_RADIX; ++d) + for(; d < SFIO_RADIX; ++d) { _Sfcv36[(uchar)_Sfdigits[d]] = d; _Sfcv64[(uchar)_Sfdigits[d]] = d; } diff --git a/src/lib/libast/sfio/sftell.c b/src/lib/libast/sfio/sftell.c index f76a0f9fd507..9d56fe958787 100644 --- a/src/lib/libast/sfio/sftell.c +++ b/src/lib/libast/sfio/sftell.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -29,20 +29,20 @@ Sfoff_t sftell(Sfio_t* f) Sfoff_t p; /* set the stream to the right mode */ - if(!f || ((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0)) + if(!f || ((mode = f->mode&SFIO_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0)) return (Sfoff_t)(-1); /* throw away ungetc data */ if(f->disc == _Sfudisc) (void)sfclose((*_Sfstack)(f,NULL)); - if(f->flags&SF_STRING) + if(f->flags&SFIO_STRING) return (Sfoff_t)(f->next-f->data); /* let sfseek() handle the hard case */ - if(f->extent >= 0 && (f->flags&(SF_SHARE|SF_APPENDWR)) ) + if(f->extent >= 0 && (f->flags&(SFIO_SHARE|SFIO_APPENDWR)) ) p = sfseek(f,0,SEEK_CUR); - else p = f->here + ((f->mode&SF_WRITE) ? f->next-f->data : f->next-f->endb); + else p = f->here + ((f->mode&SFIO_WRITE) ? f->next-f->data : f->next-f->endb); return p; } diff --git a/src/lib/libast/sfio/sftmp.c b/src/lib/libast/sfio/sftmp.c index f2ee0b2f8418..a74ba03dd020 100644 --- a/src/lib/libast/sfio/sftmp.c +++ b/src/lib/libast/sfio/sftmp.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -62,10 +62,10 @@ static int _tmprmfile(Sfio_t* f, int type, void* val, Sfdisc_t* disc) NOT_USED(val); - if(type == SF_DPOP) /* don't allow this to pop */ + if(type == SFIO_DPOP) /* don't allow this to pop */ return -1; - if(type == SF_CLOSING) + if(type == SFIO_CLOSING) { for(last = NULL, ff = File; ff; last = ff, ff = ff->next) if(ff->f == f) @@ -76,7 +76,7 @@ static int _tmprmfile(Sfio_t* f, int type, void* val, Sfdisc_t* disc) else last->next = ff->next; if(_Sfnotify) - (*_Sfnotify)(f,SF_CLOSING,f->file); + (*_Sfnotify)(f,SFIO_CLOSING,f->file); CLOSE(f->file); f->file = -1; while(remove(ff->name) < 0 && errno == EINTR) @@ -94,7 +94,7 @@ static void _rmfiles(void) for(ff = File; ff; ff = next) { next = ff->next; - _tmprmfile(ff->f, SF_CLOSING, NULL, ff->f->disc); + _tmprmfile(ff->f, SFIO_CLOSING, NULL, ff->f->disc); } } @@ -165,14 +165,14 @@ static int _tmpexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc) NOT_USED(val); /* the discipline needs to change only under the following exceptions */ - if(type != SF_WRITE && type != SF_SEEK && - type != SF_DPUSH && type != SF_DPOP && type != SF_DBUFFER) + if(type != SFIO_WRITE && type != SFIO_SEEK && + type != SFIO_DPUSH && type != SFIO_DPOP && type != SFIO_DBUFFER) return 0; /* try to create the temp file */ SFCLEAR(&newf); - newf.flags = SF_STATIC; - newf.mode = SF_AVAIL; + newf.flags = SFIO_STATIC; + newf.mode = SFIO_AVAIL; if((fd = _tmpfd(f)) < 0 ) return -1; @@ -180,15 +180,15 @@ static int _tmpexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc) /* make sure that the notify function won't be called here since we are only interested in creating the file, not the stream */ _Sfnotify = 0; - sf = sfnew(&newf,NULL,(size_t)SF_UNBOUND,fd,SF_READ|SF_WRITE); + sf = sfnew(&newf,NULL,(size_t)SFIO_UNBOUND,fd,SFIO_READ|SFIO_WRITE); _Sfnotify = notify; if(!sf) return -1; /* make sure that new stream has the same mode */ - if((m = f->flags&(SF_READ|SF_WRITE)) != (SF_READ|SF_WRITE)) - sfset(sf, ((~m)&(SF_READ|SF_WRITE)), 0); - sfset(sf, (f->mode&(SF_READ|SF_WRITE)), 1); + if((m = f->flags&(SFIO_READ|SFIO_WRITE)) != (SFIO_READ|SFIO_WRITE)) + sfset(sf, ((~m)&(SFIO_READ|SFIO_WRITE)), 0); + sfset(sf, (f->mode&(SFIO_READ|SFIO_WRITE)), 1); /* now remake the old stream into the new image */ memcpy(&savf, f, sizeof(Sfio_t)); @@ -199,25 +199,25 @@ static int _tmpexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc) f->proc = savf.proc; f->stdio = savf.stdio; - /* remove the SF_STATIC bit if it was only set above in making newf */ - if(!(savf.flags&SF_STATIC) ) - f->flags &= ~SF_STATIC; + /* remove the SFIO_STATIC bit if it was only set above in making newf */ + if(!(savf.flags&SFIO_STATIC) ) + f->flags &= ~SFIO_STATIC; if(savf.data) { SFSTRSIZE(&savf); - if(!(savf.flags&SF_MALLOC) ) + if(!(savf.flags&SFIO_MALLOC) ) (void)sfsetbuf(f,savf.data,savf.size); if(savf.extent > 0) (void)sfwrite(f,savf.data,(size_t)savf.extent); (void)sfseek(f,(Sfoff_t)(savf.next - savf.data),SEEK_SET); - if((savf.flags&SF_MALLOC) ) + if((savf.flags&SFIO_MALLOC) ) free(savf.data); } /* announce change of status */ f->disc = NULL; if(_Sfnotify) - (*_Sfnotify)(f, SF_SETFD, (void*)((long)f->file)); + (*_Sfnotify)(f, SFIO_SETFD, (void*)((long)f->file)); /* erase all traces of newf */ newf.data = newf.endb = newf.endr = newf.endw = NULL; @@ -245,17 +245,17 @@ Sfio_t* sftmp(size_t s) /* start with a memory resident stream */ _Sfnotify = 0; /* local computation so no notification */ - f = sfnew(NULL,NULL,s,-1,SF_STRING|SF_READ|SF_WRITE); + f = sfnew(NULL,NULL,s,-1,SFIO_STRING|SFIO_READ|SFIO_WRITE); _Sfnotify = notify; if(!f) return NULL; - if(s != (size_t)SF_UNBOUND) /* set up a discipline for out-of-bound, etc. */ + if(s != (size_t)SFIO_UNBOUND) /* set up a discipline for out-of-bound, etc. */ f->disc = &Tmpdisc; if(s == 0) /* make the file now */ { _Sfnotify = 0; /* local computation so no notification */ - rv = _tmpexcept(f,SF_DPOP,NULL,f->disc); + rv = _tmpexcept(f,SFIO_DPOP,NULL,f->disc); _Sfnotify = notify; if(rv < 0) { sfclose(f); @@ -264,7 +264,7 @@ Sfio_t* sftmp(size_t s) } if(_Sfnotify) - (*_Sfnotify)(f, SF_NEW, (void*)((long)f->file)); + (*_Sfnotify)(f, SFIO_NEW, (void*)((long)f->file)); return f; } diff --git a/src/lib/libast/sfio/sfungetc.c b/src/lib/libast/sfio/sfungetc.c index 02db51d761f1..1829a87db417 100644 --- a/src/lib/libast/sfio/sfungetc.c +++ b/src/lib/libast/sfio/sfungetc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -19,7 +19,7 @@ ***********************************************************************/ #include "sfhdr.h" -/* Push back one byte to a given SF_READ stream +/* Push back one byte to a given SFIO_READ stream ** ** Written by Kiem-Phong Vo. */ @@ -32,7 +32,7 @@ static int _uexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc) return -1; /* close the unget stream */ - if(type != SF_CLOSING) + if(type != SFIO_CLOSING) (void)sfclose((*_Sfstack)(f,NULL)); return 1; @@ -43,7 +43,7 @@ int sfungetc(Sfio_t* f, /* push back one byte to this stream */ { Sfio_t* uf; - if(!f || c < 0 || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + if(!f || c < 0 || (f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0)) return -1; SFLOCK(f,0); @@ -55,8 +55,8 @@ int sfungetc(Sfio_t* f, /* push back one byte to this stream */ /* make a string stream for unget characters */ if(f->disc != _Sfudisc) - { if(!(uf = sfnew(NULL,NULL,(size_t)SF_UNBOUND, - -1,SF_STRING|SF_READ))) + { if(!(uf = sfnew(NULL,NULL,(size_t)SFIO_UNBOUND, + -1,SFIO_STRING|SFIO_READ))) { c = -1; goto done; } @@ -74,7 +74,7 @@ int sfungetc(Sfio_t* f, /* push back one byte to this stream */ { c = -1; goto done; } - f->flags |= SF_MALLOC; + f->flags |= SFIO_MALLOC; if(f->data) memcpy((char*)(data+16),(char*)f->data,f->size); f->size += 16; diff --git a/src/lib/libast/sfio/sfvprintf.c b/src/lib/libast/sfio/sfvprintf.c index 5bfae436e5bb..8080d84c79b0 100644 --- a/src/lib/libast/sfio/sfvprintf.c +++ b/src/lib/libast/sfio/sfvprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -102,7 +102,7 @@ int sfvprintf(Sfio_t* f, /* file to print to */ int xargs; /* highest (max) argv[] index see in an indexed format (%x$ *x$) */ #define SLACK 1024 - char buf[SF_MAXDIGITS+SLACK], tmp[SF_MAXDIGITS+1], data[SF_GRAIN]; + char buf[SFIO_MAXDIGITS+SLACK], tmp[SFIO_MAXDIGITS+1], data[SFIO_GRAIN]; int decimal = 0, thousand = 0; #if _has_multibyte @@ -154,12 +154,12 @@ int sfvprintf(Sfio_t* f, /* file to print to */ return -1; /* make sure stream is in write mode and buffer is not NULL */ - if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) + if(f->mode != SFIO_WRITE && _sfmode(f,SFIO_WRITE,0) < 0) return -1; SFLOCK(f,0); - if(!f->data && !(f->flags&SF_STRING)) + if(!f->data && !(f->flags&SFIO_STRING)) { f->data = f->next = (uchar*)data; f->endb = f->data+sizeof(data); } @@ -627,7 +627,7 @@ loop_fmt : goto pop_fmt; if(!argv.ft->form && ft ) /* change extension functions */ { if(ft->eventf && - (*ft->eventf)(f,SF_DPOP,(void*)form,ft) < 0) + (*ft->eventf)(f,SFIO_DPOP,(void*)form,ft) < 0) continue; fmstk->ft = ft = argv.ft; } @@ -965,7 +965,7 @@ loop_fmt : { flags &= ~SFFMT_ALTER; scale = 1000; } - if(base < 2 || base > SF_RADIX) + if(base < 2 || base > SFIO_RADIX) base = 10; if((base&(n_s = base-1)) == 0) { if(base < 8) @@ -1157,13 +1157,13 @@ loop_fmt : if(fmt == 'e' || fmt == 'E' && (v |= SFFMT_UPPER)) { v |= SFFMT_EFORMAT; n = (precis = precis < 0 ? FPRECIS : precis)+1; - ep = _sfcvt(valp,tmp+1,sizeof(tmp)-1, min(n,SF_FDIGITS), + ep = _sfcvt(valp,tmp+1,sizeof(tmp)-1, min(n,SFIO_FDIGITS), &decpt, &sign, &n_s, v); goto e_format; } else if(fmt == 'f' || fmt == 'F' && (v |= SFFMT_UPPER)) { precis = precis < 0 ? FPRECIS : precis; - ep = _sfcvt(valp,tmp+1,sizeof(tmp)-1, min(precis,SF_FDIGITS), + ep = _sfcvt(valp,tmp+1,sizeof(tmp)-1, min(precis,SFIO_FDIGITS), &decpt, &sign, &n_s, v); goto f_format; } @@ -1175,7 +1175,7 @@ loop_fmt : else precis = 2*(sizeof(double) - 2); } n = precis + 1; - ep = _sfcvt(valp,tmp+1,sizeof(tmp)-1, min(n,SF_FDIGITS), + ep = _sfcvt(valp,tmp+1,sizeof(tmp)-1, min(n,SFIO_FDIGITS), &decpt, &sign, &n_s, v); sp = endsp = buf+1; /* reserve space for sign */ @@ -1192,7 +1192,7 @@ loop_fmt : if(fmt == 'G') v |= SFFMT_UPPER; v |= SFFMT_EFORMAT; - ep = _sfcvt(valp,tmp+1,sizeof(tmp)-1, min(precis,SF_FDIGITS), + ep = _sfcvt(valp,tmp+1,sizeof(tmp)-1, min(precis,SFIO_FDIGITS), &decpt, &sign, &n_s, v); if(dval == 0.) decpt = 1; @@ -1382,8 +1382,8 @@ loop_fmt : while((fm = fmstk) ) /* pop the format stack and continue */ { if(fm->eventf) { if(!form || !form[0]) - (*fm->eventf)(f,SF_FINAL,NULL,ft); - else if((*fm->eventf)(f,SF_DPOP,(void*)form,ft) < 0) + (*fm->eventf)(f,SFIO_FINAL,NULL,ft); + else if((*fm->eventf)(f,SFIO_DPOP,(void*)form,ft) < 0) goto loop_fmt; } @@ -1407,7 +1407,7 @@ loop_fmt : free(fp); while((fm = fmstk) ) { if(fm->eventf) - (*fm->eventf)(f,SF_FINAL,NULL,fm->ft); + (*fm->eventf)(f,SFIO_FINAL,NULL,fm->ft); fmstk = fm->next; free(fm); } @@ -1419,8 +1419,8 @@ loop_fmt : f->endw = f->endr = f->endb = f->data = NULL; f->next = f->data; - if((((flags = f->flags)&SF_SHARE) && !(flags&SF_PUBLIC) ) || - (n > 0 && (sp == data || (flags&SF_LINE) ) ) ) + if((((flags = f->flags)&SFIO_SHARE) && !(flags&SFIO_PUBLIC) ) || + (n > 0 && (sp == data || (flags&SFIO_LINE) ) ) ) (void)SFWRITE(f,sp,n); else f->next += n; diff --git a/src/lib/libast/sfio/sfvscanf.c b/src/lib/libast/sfio/sfvscanf.c index 2a351591cc9f..7b14c60f2c33 100644 --- a/src/lib/libast/sfio/sfvscanf.c +++ b/src/lib/libast/sfio/sfvscanf.c @@ -37,9 +37,9 @@ static void _sfbuf(Sfio_t* f, int* peek) { if(f->next >= f->endb) { if(*peek) /* try peeking for a share stream if possible */ - { f->mode |= SF_RV; + { f->mode |= SFIO_RV; if(SFFILBUF(f,-1) > 0) - { f->mode |= SF_PEEK; + { f->mode |= SFIO_PEEK; return; } *peek = 0; /* can't peek, back to normal reads */ @@ -108,7 +108,7 @@ static int _scgetc(void* arg, int flag) /* structure to match characters in a character class */ typedef struct _accept_s -{ char ok[SF_MAXCHAR+1]; +{ char ok[SFIO_MAXCHAR+1]; int yes; char *form, *endf; #if _has_multibyte @@ -129,7 +129,7 @@ static char* _sfsetclass(const char* form, /* format string */ } else ac->yes = 1; - for(c = 0; c <= SF_MAXCHAR; ++c) + for(c = 0; c <= SFIO_MAXCHAR; ++c) ac->ok[c] = !ac->yes; if(*form == ']' || *form == '-') /* special first char */ @@ -304,7 +304,7 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ int peek; #define SFbuf(f) (_sfbuf(f,&peek), (data = d = f->next), (endd = f->endb) ) #define SFlen(f) (d - data) -#define SFinit(f) ((peek = f->extent < 0 && (f->flags&SF_SHARE)), SFbuf(f) ) +#define SFinit(f) ((peek = f->extent < 0 && (f->flags&SFIO_SHARE)), SFbuf(f) ) #define SFend(f) ((n_input += SFlen(f)), \ (peek ? SFREAD(f,data,SFlen(f)) : ((f->next = d),0)) ) #define SFgetc(f,c) ((c) = (d < endd || (SFend(f), SFbuf(f), d < endd)) ? \ @@ -314,7 +314,7 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ SFCVINIT(); /* initialize conversion tables */ - if(!f || !form || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + if(!f || !form || (f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0)) return -1; SFLOCK(f,0); @@ -337,7 +337,7 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ while((fmt = *form++)) { if(fmt != '%') { if(isspace(fmt)) - { if(fmt != '\n' || !(f->flags&SF_LINE)) + { if(fmt != '\n' || !(f->flags&SFIO_LINE)) fmt = -1; for(;;) { if(SFgetc(f,inp) < 0 || inp == fmt) @@ -674,7 +674,7 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ continue; if(!argv.ft->form && ft ) /* change extension functions */ { if(ft->eventf && - (*ft->eventf)(f,SF_DPOP,(void*)form,ft) < 0) + (*ft->eventf)(f,SFIO_DPOP,(void*)form,ft) < 0) continue; fmstk->ft = ft = argv.ft; } @@ -846,7 +846,7 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ if(fmt == 'i' && inp == '#' && !(flags&SFFMT_ALTER) ) { base = (int)argv.lu; - if(base < 2 || base > SF_RADIX) + if(base < 2 || base > SFIO_RADIX) goto pop_fmt; argv.lu = 0; sp = (char*)(base <= 36 ? _Sfcv36 : _Sfcv64); @@ -858,7 +858,7 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ else { /* other bases */ sp = (char*)(base <= 36 ? _Sfcv36 : _Sfcv64); - if(base < 2 || base > SF_RADIX || sp[inp] >= base) + if(base < 2 || base > SFIO_RADIX || sp[inp] >= base) { SFungetc(f,inp); goto pop_fmt; } @@ -1018,8 +1018,8 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ while((fm = fmstk) ) /* pop the format stack and continue */ { if(fm->eventf) { if(!form || !form[0]) - (*fm->eventf)(f,SF_FINAL,NULL,ft); - else if((*fm->eventf)(f,SF_DPOP,(void*)form,ft) < 0) + (*fm->eventf)(f,SFIO_FINAL,NULL,ft); + else if((*fm->eventf)(f,SFIO_DPOP,(void*)form,ft) < 0) goto loop_fmt; } @@ -1043,7 +1043,7 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ free(fp); while((fm = fmstk) ) { if(fm->eventf) - (*fm->eventf)(f,SF_FINAL,NULL,fm->ft); + (*fm->eventf)(f,SFIO_FINAL,NULL,fm->ft); fmstk = fm->next; free(fm); } diff --git a/src/lib/libast/sfio/sfwalk.c b/src/lib/libast/sfio/sfwalk.c index 1aafb8ac6b1f..a93774525df4 100644 --- a/src/lib/libast/sfio/sfwalk.c +++ b/src/lib/libast/sfio/sfwalk.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,12 +32,12 @@ int sfwalk(Sfwalk_f walkf, /* return <0: stop, >=0: continue */ int n, rv; /* truly initializing std-streams before walking */ - if(sfstdin->mode & SF_INIT) - _sfmode(sfstdin, (sfstdin->mode & SF_RDWR), 0); - if(sfstdout->mode & SF_INIT) - _sfmode(sfstdout, (sfstdout->mode & SF_RDWR), 0); - if(sfstderr->mode & SF_INIT) - _sfmode(sfstderr, (sfstderr->mode & SF_RDWR), 0); + if(sfstdin->mode & SFIO_INIT) + _sfmode(sfstdin, (sfstdin->mode & SFIO_RDWR), 0); + if(sfstdout->mode & SFIO_INIT) + _sfmode(sfstdout, (sfstdout->mode & SFIO_RDWR), 0); + if(sfstderr->mode & SFIO_INIT) + _sfmode(sfstderr, (sfstderr->mode & SFIO_RDWR), 0); for(rv = 0, p = &_Sfpool; p; p = p->next) { for(n = 0; n < p->n_sf; ) diff --git a/src/lib/libast/sfio/sfwr.c b/src/lib/libast/sfio/sfwr.c index 13b48e05f1e4..a4fb80e3a817 100644 --- a/src/lib/libast/sfio/sfwr.c +++ b/src/lib/libast/sfio/sfwr.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -86,7 +86,7 @@ static ssize_t sfoutput(Sfio_t* f, char* buf, size_t n) } if((wr = write(f->file,wbuf,buf-wbuf)) > 0) { w += wr; - f->bits &= ~SF_HOLE; + f->bits &= ~SFIO_HOLE; } if(wr != (buf-wbuf)) break; @@ -101,7 +101,7 @@ static ssize_t sfoutput(Sfio_t* f, char* buf, size_t n) w += s; n -= s; wbuf = (buf += s); - f->bits |= SF_HOLE; + f->bits |= SFIO_HOLE; if(n > 0) { /* next page must be dirty */ @@ -125,8 +125,8 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) return (ssize_t)(-1); GETLOCAL(f,local); - if(!local && !(f->bits&SF_DCDOWN)) /* an external user's call */ - { if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0 ) + if(!local && !(f->bits&SFIO_DCDOWN)) /* an external user's call */ + { if(f->mode != SFIO_WRITE && _sfmode(f,SFIO_WRITE,0) < 0 ) return (ssize_t)(-1); if(f->next > f->data && SFSYNC(f) < 0 ) return (ssize_t)(-1); @@ -134,39 +134,39 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) for(;;) { /* stream locked by sfsetfd() */ - if(!(f->flags&SF_STRING) && f->file < 0) + if(!(f->flags&SFIO_STRING) && f->file < 0) return 0; /* clear current error states */ - f->flags &= ~(SF_EOF|SF_ERROR); + f->flags &= ~(SFIO_EOF|SFIO_ERROR); dc = disc; - if(f->flags&SF_STRING) /* just asking to extend buffer */ + if(f->flags&SFIO_STRING) /* just asking to extend buffer */ w = n + (f->next - f->data); else { /* warn that a write is about to happen */ SFDISC(f,dc,writef); - if(dc && dc->exceptf && (f->flags&SF_IOCHECK) ) + if(dc && dc->exceptf && (f->flags&SFIO_IOCHECK) ) { int rv; if(local) SETLOCAL(f); - if((rv = _sfexcept(f,SF_WRITE,n,dc)) > 0) + if((rv = _sfexcept(f,SFIO_WRITE,n,dc)) > 0) n = rv; else if(rv < 0) - { f->flags |= SF_ERROR; + { f->flags |= SFIO_ERROR; return rv; } } if(f->extent >= 0) { /* make sure we are at the right place to write */ - if(f->flags&SF_APPENDWR) - { if(f->here != f->extent || (f->flags&SF_SHARE)) + if(f->flags&SFIO_APPENDWR) + { if(f->here != f->extent || (f->flags&SFIO_SHARE)) { f->here = SFSK(f,0,SEEK_END,dc); f->extent = f->here; } } - else if((f->flags&SF_SHARE) && !(f->flags&SF_PUBLIC)) + else if((f->flags&SFIO_SHARE) && !(f->flags&SFIO_PUBLIC)) f->here = SFSK(f,f->here,SEEK_SET,dc); } @@ -178,10 +178,10 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) } else if(SFISNULL(f)) w = n; - else if(f->flags&SF_WHOLE) + else if(f->flags&SFIO_WHOLE) goto do_write; else if((ssize_t)n >= _Sfpage && - !(f->flags&(SF_SHARE|SF_APPENDWR)) && + !(f->flags&(SFIO_SHARE|SFIO_APPENDWR)) && f->here == f->extent && (f->here%_Sfpage) == 0) { if((w = sfoutput(f,(char*)buf,n)) <= 0) goto do_write; @@ -190,15 +190,15 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) { do_write: if((w = write(f->file,buf,n)) > 0) - f->bits &= ~SF_HOLE; + f->bits &= ~SFIO_HOLE; } if(errno == 0) errno = oerrno; if(w > 0) - { if(!(f->bits&SF_DCDOWN) ) - { if((f->flags&(SF_APPENDWR|SF_PUBLIC)) && f->extent >= 0 ) + { if(!(f->bits&SFIO_DCDOWN) ) + { if((f->flags&(SFIO_APPENDWR|SFIO_PUBLIC)) && f->extent >= 0 ) f->here = SFSK(f,0,SEEK_CUR,dc); else f->here += w; if(f->extent >= 0 && f->here > f->extent) @@ -211,18 +211,18 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) if(local) SETLOCAL(f); - switch(_sfexcept(f,SF_WRITE,w,dc)) + switch(_sfexcept(f,SFIO_WRITE,w,dc)) { - case SF_ECONT : + case SFIO_ECONT : goto do_continue; - case SF_EDONE : + case SFIO_EDONE : w = local ? 0 : w; return (ssize_t)w; - case SF_EDISC : - if(!local && !(f->flags&SF_STRING)) + case SFIO_EDISC : + if(!local && !(f->flags&SFIO_STRING)) goto do_continue; /* FALLTHROUGH */ - case SF_ESTACK : + case SFIO_ESTACK : return (ssize_t)(-1); } diff --git a/src/lib/libast/sfio/sfwrite.c b/src/lib/libast/sfio/sfwrite.c index 479d09b5c9ee..1bc061dc86fc 100644 --- a/src/lib/libast/sfio/sfwrite.c +++ b/src/lib/libast/sfio/sfwrite.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -40,17 +40,17 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */ return (ssize_t)(n == 0 ? 0 : -1) ; /* release peek lock */ - if(f->mode&SF_PEEK) - { if(!(f->mode&SF_WRITE) && (f->flags&SF_RDWR) != SF_RDWR) + if(f->mode&SFIO_PEEK) + { if(!(f->mode&SFIO_WRITE) && (f->flags&SFIO_RDWR) != SFIO_RDWR) return (ssize_t)(-1); if((uchar*)buf != f->next && (!f->rsrv || f->rsrv->data != (uchar*)buf) ) return (ssize_t)(-1); - f->mode &= ~SF_PEEK; + f->mode &= ~SFIO_PEEK; - if(f->mode&SF_PKRD) + if(f->mode&SFIO_PKRD) { /* read past peeked data */ char buf[16]; ssize_t r; @@ -65,19 +65,19 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */ else w -= r; } - f->mode &= ~SF_PKRD; + f->mode &= ~SFIO_PKRD; f->endb = f->data + n; f->here += n; } - if((f->mode&SF_READ) && f->proc) + if((f->mode&SFIO_READ) && f->proc) f->next += n; } s = begs = (uchar*)buf; - for(;; f->mode &= ~SF_LOCK) + for(;; f->mode &= ~SFIO_LOCK) { /* check stream mode */ - if(SFMODE(f,local) != SF_WRITE && _sfmode(f,SF_WRITE,local) < 0 ) + if(SFMODE(f,local) != SFIO_WRITE && _sfmode(f,SFIO_WRITE,local) < 0 ) { w = s > begs ? s-begs : -1; return w; } @@ -95,11 +95,11 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */ } /* attempt to create space in buffer */ - if(w == 0 || ((f->flags&SF_WHOLE) && w < (ssize_t)n) ) - { if(f->flags&SF_STRING) /* extend buffer */ + if(w == 0 || ((f->flags&SFIO_WHOLE) && w < (ssize_t)n) ) + { if(f->flags&SFIO_STRING) /* extend buffer */ { (void)SFWR(f, s, n-w, f->disc); if((w = f->endb - f->next) < (ssize_t)n) - { if(!(f->flags&SF_STRING)) /* maybe sftmp */ + { if(!(f->flags&SFIO_STRING)) /* maybe sftmp */ { if(f->next > f->data) goto fls_buf; } @@ -111,13 +111,13 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */ { fls_buf: (void)SFFLSBUF(f, -1); if((w = f->endb - f->next) < (ssize_t)n && - (f->flags&SF_WHOLE) && f->next > f->data ) + (f->flags&SFIO_WHOLE) && f->next > f->data ) break; } } - if(!(f->flags&SF_STRING) && f->next == f->data && - (((f->flags&SF_WHOLE) && w <= n) || SFDIRECT(f,n)) ) + if(!(f->flags&SFIO_STRING) && f->next == f->data && + (((f->flags&SFIO_WHOLE) && w <= n) || SFDIRECT(f,n)) ) { /* bypass buffering */ if((w = SFWR(f,s,n,f->disc)) <= 0 ) break; @@ -137,11 +137,11 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */ } /* always flush buffer for share streams */ - if(f->extent < 0 && (f->flags&SF_SHARE) && !(f->flags&SF_PUBLIC) ) + if(f->extent < 0 && (f->flags&SFIO_SHARE) && !(f->flags&SFIO_PUBLIC) ) (void)SFFLSBUF(f,-1); /* check to see if buffer should be flushed */ - else if(n == 0 && (f->flags&SF_LINE) && !(f->flags&SF_STRING)) + else if(n == 0 && (f->flags&SFIO_LINE) && !(f->flags&SFIO_STRING)) { if((ssize_t)(n = f->next-f->data) > (w = s-begs)) n = w; if(n > 0 && n < HIFORLINE) diff --git a/src/lib/libast/stdio/_stdsprnt.c b/src/lib/libast/stdio/_stdsprnt.c index 7c2f7b12a639..a74585793601 100644 --- a/src/lib/libast/stdio/_stdsprnt.c +++ b/src/lib/libast/stdio/_stdsprnt.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -28,7 +28,7 @@ _stdsprintf(char* s, const char* fmt, ...) int v; va_start(args, fmt); - v = s ? sfvsprintf(s, SF_BUFSIZE, fmt, args) : -1; + v = s ? sfvsprintf(s, SFIO_BUFSIZE, fmt, args) : -1; va_end(args); return v; } diff --git a/src/lib/libast/stdio/fdopen.c b/src/lib/libast/stdio/fdopen.c index f44374e7cf0a..085996a00707 100644 --- a/src/lib/libast/stdio/fdopen.c +++ b/src/lib/libast/stdio/fdopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -26,5 +26,5 @@ fdopen(int fd, const char* mode) if (fd < 0 || !(flags = _sftype(mode, NULL, NULL))) return NULL; - return sfnew(NULL, NULL, (size_t)SF_UNBOUND, fd, flags); + return sfnew(NULL, NULL, (size_t)SFIO_UNBOUND, fd, flags); } diff --git a/src/lib/libast/stdio/fflush.c b/src/lib/libast/stdio/fflush.c index 9d2efefd2a27..7bd8b68624ec 100644 --- a/src/lib/libast/stdio/fflush.c +++ b/src/lib/libast/stdio/fflush.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -30,6 +30,6 @@ fflush(Sfio_t* f) return fcloseall(); if (f->extent > 0) - sfseek(f, 0, SEEK_CUR|SF_PUBLIC); + sfseek(f, 0, SEEK_CUR|SFIO_PUBLIC); return (sfsync(f) < 0 || sfpurge(f) < 0) ? -1 : 0; } diff --git a/src/lib/libast/stdio/fgets.c b/src/lib/libast/stdio/fgets.c index 8d0ef6972612..17ce4e33e2b4 100644 --- a/src/lib/libast/stdio/fgets.c +++ b/src/lib/libast/stdio/fgets.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -26,7 +26,7 @@ _stdgets(Sfio_t* f, char* us, int n, int isgets) unsigned char* is; unsigned char* ps; - if(n <= 0 || !us || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + if(n <= 0 || !us || (f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0)) return NULL; SFLOCK(f,0); @@ -38,7 +38,7 @@ _stdgets(Sfio_t* f, char* us, int n, int isgets) { /* peek the read buffer for data */ if((p = f->endb - (ps = f->next)) <= 0 ) { f->getr = '\n'; - f->mode |= SF_RC; + f->mode |= SFIO_RC; if(SFRPEEK(f,ps,p) <= 0) break; } @@ -52,7 +52,7 @@ _stdgets(Sfio_t* f, char* us, int n, int isgets) is += p; ps = f->next+p; #else - if(!(f->flags&(SF_BOTH|SF_MALLOC))) + if(!(f->flags&(SFIO_BOTH|SFIO_MALLOC))) { while(p-- && (*is++ = *ps++) != '\n') ; p = ps-f->next; diff --git a/src/lib/libast/stdio/fmemopen.c b/src/lib/libast/stdio/fmemopen.c index 45840f874845..2d07e5aea138 100644 --- a/src/lib/libast/stdio/fmemopen.c +++ b/src/lib/libast/stdio/fmemopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,5 +22,5 @@ Sfio_t* fmemopen(void* buf, size_t size, const char* mode) { - return sfnew(NULL, buf, size, -1, SF_STRING|_sftype(mode, NULL, NULL)); + return sfnew(NULL, buf, size, -1, SFIO_STRING|_sftype(mode, NULL, NULL)); } diff --git a/src/lib/libast/stdio/fseek.c b/src/lib/libast/stdio/fseek.c index b63bf1257cd1..4cc72f65208e 100644 --- a/src/lib/libast/stdio/fseek.c +++ b/src/lib/libast/stdio/fseek.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,5 +22,5 @@ int fseek(Sfio_t* f, long off, int op) { - return sfseek(f, (Sfoff_t)off, op|SF_SHARE) >= 0 ? 0 : -1; + return sfseek(f, (Sfoff_t)off, op|SFIO_SHARE) >= 0 ? 0 : -1; } diff --git a/src/lib/libast/stdio/fseeko.c b/src/lib/libast/stdio/fseeko.c index b89144050e86..7e13868932f5 100644 --- a/src/lib/libast/stdio/fseeko.c +++ b/src/lib/libast/stdio/fseeko.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,5 +22,5 @@ int fseeko(Sfio_t* f, off_t off, int op) { - return sfseek(f, (Sfoff_t)off, op|SF_SHARE) >= 0 ? 0 : -1; + return sfseek(f, (Sfoff_t)off, op|SFIO_SHARE) >= 0 ? 0 : -1; } diff --git a/src/lib/libast/stdio/fsetpos.c b/src/lib/libast/stdio/fsetpos.c index b3727ab2ae52..8cf0a1cd9d22 100644 --- a/src/lib/libast/stdio/fsetpos.c +++ b/src/lib/libast/stdio/fsetpos.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,5 +22,5 @@ int fsetpos(Sfio_t* f, const fpos_t* pos) { - return sfseek(f, (Sfoff_t)pos->_sf_offset, SF_PUBLIC) == (Sfoff_t)pos->_sf_offset ? 0 : -1; + return sfseek(f, (Sfoff_t)pos->_sf_offset, SFIO_PUBLIC) == (Sfoff_t)pos->_sf_offset ? 0 : -1; } diff --git a/src/lib/libast/stdio/fwide.c b/src/lib/libast/stdio/fwide.c index 34eb11355825..36c362010e83 100644 --- a/src/lib/libast/stdio/fwide.c +++ b/src/lib/libast/stdio/fwide.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -30,21 +30,21 @@ fwide(Sfio_t* f, int mode) { if (mode > 0) { - f->bits &= ~SF_MB; - f->bits |= SF_WC; + f->bits &= ~SFIO_MB; + f->bits |= SFIO_WC; } else if (mode < 0) { - f->bits &= ~SF_WC; - f->bits |= SF_MB; + f->bits &= ~SFIO_WC; + f->bits |= SFIO_MB; } - if (f->bits & SF_MB) + if (f->bits & SFIO_MB) return -1; - if (f->bits & SF_WC) + if (f->bits & SFIO_WC) return 1; - if ((f->flags & SF_SYNCED) || f->next > f->data) + if ((f->flags & SFIO_SYNCED) || f->next > f->data) { - f->bits |= SF_MB; + f->bits |= SFIO_MB; return -1; } return 0; diff --git a/src/lib/libast/stdio/getdelim.c b/src/lib/libast/stdio/getdelim.c index 0bfdf2f2632a..850dfae3d5da 100644 --- a/src/lib/libast/stdio/getdelim.c +++ b/src/lib/libast/stdio/getdelim.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -32,7 +32,7 @@ getdelim(char** sp, size_t* np, int delim, Sfio_t* f) if(delim < 0 || delim > 255 || !sp || !np) /* bad parameters */ return -1; - if(!f || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + if(!f || (f->mode != SFIO_READ && _sfmode(f,SFIO_READ,0) < 0)) return -1; SFLOCK(f,0); @@ -43,7 +43,7 @@ getdelim(char** sp, size_t* np, int delim, Sfio_t* f) { /* read new data */ if((p = f->endb - (ps = f->next)) <= 0 ) { f->getr = delim; - f->mode |= SF_RC; + f->mode |= SFIO_RC; if(SFRPEEK(f,ps,p) <= 0) { m = -1; break; diff --git a/src/lib/libast/stdio/putchar.c b/src/lib/libast/stdio/putchar.c deleted file mode 100644 index 44b3e98d4cfe..000000000000 --- a/src/lib/libast/stdio/putchar.c +++ /dev/null @@ -1,22 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ - -#include "stdhdr.h" - -NoN(putchar) diff --git a/src/lib/libast/stdio/rewind.c b/src/lib/libast/stdio/rewind.c index 5af6ea2a147f..467831f2378d 100644 --- a/src/lib/libast/stdio/rewind.c +++ b/src/lib/libast/stdio/rewind.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,6 +22,6 @@ void rewind(Sfio_t* f) { - sfseek(f, 0, SEEK_SET|SF_PUBLIC); + sfseek(f, 0, SEEK_SET|SFIO_PUBLIC); sfclrlock(f); } diff --git a/src/lib/libast/stdio/setlinebuf.c b/src/lib/libast/stdio/setlinebuf.c index fa9e51b2afe2..3690f744e5c8 100644 --- a/src/lib/libast/stdio/setlinebuf.c +++ b/src/lib/libast/stdio/setlinebuf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,6 +22,6 @@ int setlinebuf(Sfio_t* f) { - sfset(f, SF_LINE, 1); + sfset(f, SFIO_LINE, 1); return 0; } diff --git a/src/lib/libast/stdio/setvbuf.c b/src/lib/libast/stdio/setvbuf.c index 3f21cd362f15..4bc3cc44782b 100644 --- a/src/lib/libast/stdio/setvbuf.c +++ b/src/lib/libast/stdio/setvbuf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -23,8 +23,8 @@ int setvbuf(Sfio_t* f, char* buf, int type, size_t size) { if (type == _IOLBF) - sfset(f, SF_LINE, 1); - else if (f->flags & SF_STRING) + sfset(f, SFIO_LINE, 1); + else if (f->flags & SFIO_STRING) return -1; else if (type == _IONBF) { @@ -34,7 +34,7 @@ setvbuf(Sfio_t* f, char* buf, int type, size_t size) else if (type == _IOFBF) { if (size == 0) - size = SF_BUFSIZE; + size = SFIO_BUFSIZE; sfsync(f); sfsetbuf(f, buf, size); } diff --git a/src/lib/libast/stdio/stdhdr.h b/src/lib/libast/stdio/stdhdr.h index 20fe4164f2d3..7c0d8e4ac55b 100644 --- a/src/lib/libast/stdio/stdhdr.h +++ b/src/lib/libast/stdio/stdhdr.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -30,15 +30,15 @@ #include "stdio.h" -#define SF_MB 010000 -#define SF_WC 020000 +#define SFIO_MB 010000 +#define SFIO_WC 020000 #define FWIDE(f,r) \ do \ { \ if (fwide(f, 0) < 0) \ return r; \ - f->bits |= SF_WC; \ + f->bits |= SFIO_WC; \ } while (0) extern int sfdcwide(Sfio_t*); diff --git a/src/lib/libast/stdio/vfwscanf.c b/src/lib/libast/stdio/vfwscanf.c index 453f52971b69..1fe06bb16d91 100644 --- a/src/lib/libast/stdio/vfwscanf.c +++ b/src/lib/libast/stdio/vfwscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -45,13 +45,13 @@ wideexcept(Sfio_t* f, int op, void* val, Sfdisc_t* dp) return -1; switch (op) { - case SF_ATEXIT: - sfdisc(f, SF_POPDISC); + case SFIO_ATEXIT: + sfdisc(f, SFIO_POPDISC); break; - case SF_CLOSING: - case SF_DPOP: - case SF_FINAL: - if (op != SF_CLOSING) + case SFIO_CLOSING: + case SFIO_DPOP: + case SFIO_FINAL: + if (op != SFIO_CLOSING) free(dp); break; } @@ -92,7 +92,7 @@ vfwscanf(Sfio_t* f, const wchar_t* fmt, va_list args) n = wcstombs(NULL, fmt, 0); if (w = newof(0, Wide_t, 1, n)) { - if (t = sfnew(NULL, buf, sizeof(buf), (int)astconf_long(CONF_OPEN_MAX)+1, SF_READ)) + if (t = sfnew(NULL, buf, sizeof(buf), (int)astconf_long(CONF_OPEN_MAX)+1, SFIO_READ)) { w->sfdisc.exceptf = wideexcept; w->sfdisc.readf = wideread; diff --git a/src/lib/libast/stdio/vsnprintf.c b/src/lib/libast/stdio/vsnprintf.c index 42068e83b659..6d3e99e10306 100644 --- a/src/lib/libast/stdio/vsnprintf.c +++ b/src/lib/libast/stdio/vsnprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -26,8 +26,8 @@ vsnprintf(char* s, int n, const char* form, va_list args) ssize_t rv; /* make a temp stream */ - if(!(f = sfnew(NULL,NULL,(size_t)SF_UNBOUND, - -1,SF_WRITE|SF_STRING)) ) + if(!(f = sfnew(NULL,NULL,(size_t)SFIO_UNBOUND, + -1,SFIO_WRITE|SFIO_STRING)) ) return -1; if((rv = sfvprintf(f,form,args)) >= 0 ) diff --git a/src/lib/libast/stdio/vsprintf.c b/src/lib/libast/stdio/vsprintf.c index 460f53510b4c..e58dbbd64c15 100644 --- a/src/lib/libast/stdio/vsprintf.c +++ b/src/lib/libast/stdio/vsprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,5 +22,5 @@ int vsprintf(char* s, const char* fmt, va_list args) { - return vsnprintf(s, 4 * SF_BUFSIZE, fmt, args); + return vsnprintf(s, 4 * SFIO_BUFSIZE, fmt, args); } diff --git a/src/lib/libast/stdio/vswprintf.c b/src/lib/libast/stdio/vswprintf.c index a866a10b4768..d336e2fc0794 100644 --- a/src/lib/libast/stdio/vswprintf.c +++ b/src/lib/libast/stdio/vswprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -39,9 +39,9 @@ vswprintf(wchar_t* s, size_t n, const wchar_t* fmt, va_list args) */ SFCLEAR(&f); - f.flags = SF_STRING|SF_WRITE; - f.bits = SF_PRIVATE; - f.mode = SF_WRITE; + f.flags = SFIO_STRING|SFIO_WRITE; + f.bits = SFIO_PRIVATE; + f.mode = SFIO_WRITE; f.size = n - 1; f.data = f.next = f.endr = (uchar*)s; f.endb = f.endw = f.data + f.size; diff --git a/src/lib/libast/stdio/vswscanf.c b/src/lib/libast/stdio/vswscanf.c index 4688acba8697..c9d8f2cf0107 100644 --- a/src/lib/libast/stdio/vswscanf.c +++ b/src/lib/libast/stdio/vswscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -38,9 +38,9 @@ vswscanf(const wchar_t* s, const wchar_t* fmt, va_list args) */ SFCLEAR(&f); - f.flags = SF_STRING|SF_READ; - f.bits = SF_PRIVATE; - f.mode = SF_READ; + f.flags = SFIO_STRING|SFIO_READ; + f.bits = SFIO_PRIVATE; + f.mode = SFIO_READ; f.size = wcslen(s) * sizeof(wchar_t); f.data = f.next = f.endw = (uchar*)s; f.endb = f.endr = f.data + f.size; diff --git a/src/lib/libast/string/strtoi.h b/src/lib/libast/string/strtoi.h index 4603b9e036e8..68f5730ea5bd 100644 --- a/src/lib/libast/string/strtoi.h +++ b/src/lib/libast/string/strtoi.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -222,7 +222,7 @@ S2I_function(const char* a, char** e, int base) #if S2I_multiplier base = basep ? *((unsigned char*)basep) : 0; #else - if (base > 36 && base <= SF_RADIX) + if (base > 36 && base <= SFIO_RADIX) { static int conformance = -1; @@ -232,7 +232,7 @@ S2I_function(const char* a, char** e, int base) base = 1; } #endif - if (base && (base < 2 || base > SF_RADIX)) + if (base && (base < 2 || base > SFIO_RADIX)) { errno = EINVAL; return 0; @@ -280,7 +280,7 @@ S2I_function(const char* a, char** e, int base) } if (!base) base = 10; - else if (base < 2 || base > SF_RADIX) + else if (base < 2 || base > SFIO_RADIX) { errno = EINVAL; return 0; diff --git a/src/lib/libast/string/tokline.c b/src/lib/libast/string/tokline.c index 03511c10e078..ba7d4094379a 100644 --- a/src/lib/libast/string/tokline.c +++ b/src/lib/libast/string/tokline.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -66,13 +66,13 @@ spliceline(Sfio_t* s, int op, void* val, Sfdisc_t* ad) NoP(val); switch (op) { - case SF_CLOSING: + case SFIO_CLOSING: sfclose(d->sp); return 0; - case SF_DPOP: + case SFIO_DPOP: free(d); return 0; - case SF_READ: + case SFIO_READ: do { if (!(buf = sfgetr(d->sp, '\n', 0)) && !(buf = sfgetr(d->sp, '\n', -1))) @@ -125,7 +125,7 @@ spliceline(Sfio_t* s, int op, void* val, Sfdisc_t* ad) } if (n > 0) { - if (!j && buf[n - 1] != '\n' && (s->_flags & SF_STRING)) + if (!j && buf[n - 1] != '\n' && (s->_flags & SFIO_STRING)) buf[n++] = '\n'; if (q && buf[n - 1] == '\n') buf[n - 1] = '\r'; @@ -144,8 +144,8 @@ spliceline(Sfio_t* s, int op, void* val, Sfdisc_t* ad) * open a stream to parse lines * * flags: 0 arg: open Sfio_t* - * flags: SF_READ arg: file name - * flags: SF_STRING arg: null-terminated char* + * flags: SFIO_READ arg: file name + * flags: SFIO_STRING arg: null-terminated char* * * if line!=0 then it points to a line count that starts at 0 * and is incremented for each input line @@ -169,9 +169,9 @@ tokline(const char* arg, int flags, int* line) free(d); return NULL; } - if (!(flags & (SF_STRING|SF_READ))) + if (!(flags & (SFIO_STRING|SFIO_READ))) f = (Sfio_t*)arg; - else if (!(f = sfopen(NULL, arg, (flags & SF_STRING) ? "s" : "r"))) + else if (!(f = sfopen(NULL, arg, (flags & SFIO_STRING) ? "s" : "r"))) { free(d); sfclose(s); diff --git a/src/lib/libast/tm/tmlocale.c b/src/lib/libast/tm/tmlocale.c index cff5dd1193ba..fbe1d1984a04 100644 --- a/src/lib/libast/tm/tmlocale.c +++ b/src/lib/libast/tm/tmlocale.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -580,7 +580,7 @@ load(Lc_info_t* li) if (tp = sfstropen()) { sfread(sp, u, 3); - n = iconv_move(cvt, sp, tp, SF_UNBOUND, NULL); + n = iconv_move(cvt, sp, tp, SFIO_UNBOUND, NULL); } iconv_close(cvt); } diff --git a/src/lib/libast/vec/vecargs.c b/src/lib/libast/vec/vecargs.c deleted file mode 100644 index bc075d970dd7..000000000000 --- a/src/lib/libast/vec/vecargs.c +++ /dev/null @@ -1,72 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ -/* - * Glenn Fowler - * AT&T Bell Laboratories - * - * string vector argv insertion - */ - -#include -#include -#include - -/* - * insert the string vector vec between - * (*argvp)[0] and (*argvp)[1], sliding (*argvp)[1] ... over - * null and blank args are deleted - * - * vecfree always called - * - * -1 returned if insertion failed - */ - -int -vecargs(char** vec, int* argcp, char*** argvp) -{ - char** argv; - char** oargv; - char** ovec; - char* s; - int num; - - if (!vec) return -1; - if ((num = (char**)(*(vec - 1)) - vec) > 0) - { - if (!(argv = newof(0, char*, num + *argcp + 1, 0))) - { - vecfree(vec, 0); - return -1; - } - oargv = *argvp; - *argvp = argv; - *argv++ = *oargv++; - ovec = vec; - while (s = *argv = *vec++) - { - while (isspace(*s)) s++; - if (*s) argv++; - } - vecfree(ovec, 1); - while (*argv = *oargv++) argv++; - *argcp = argv - *argvp; - } - else vecfree(vec, 0); - return 0; -} diff --git a/src/lib/libast/vec/vecfile.c b/src/lib/libast/vec/vecfile.c deleted file mode 100644 index 3a420d4657c4..000000000000 --- a/src/lib/libast/vec/vecfile.c +++ /dev/null @@ -1,58 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ -/* - * Glenn Fowler - * AT&T Research - * - * string vector load support - */ - -#include -#include -#include - -/* - * load a string vector from lines in file - */ - -char** -vecfile(const char* file) -{ - int n; - char* buf; - char** vec; - int fd; - struct stat st; - - vec = 0; - if ((fd = open(file, O_RDONLY|O_cloexec)) >= 0) - { - if (!fstat(fd, &st) && S_ISREG(st.st_mode) && (n = st.st_size) > 0 && (buf = newof(0, char, n + 1, 0))) - { - if (read(fd, buf, n) == n) - { - buf[n] = 0; - vec = vecload(buf); - } - if (!vec) free(buf); - } - close(fd); - } - return vec; -} diff --git a/src/lib/libast/vec/vecfree.c b/src/lib/libast/vec/vecfree.c deleted file mode 100644 index b56b5cf43394..000000000000 --- a/src/lib/libast/vec/vecfree.c +++ /dev/null @@ -1,44 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ -/* - * Glenn Fowler - * AT&T Bell Laboratories - * - * file to string vector support - */ - -#include -#include - -/* - * free a string vector generated by vecload() - * - * retain!=0 frees the string pointers but retains the string data - * in this case the data is permanently allocated - */ - -void -vecfree(char** vec, int retain) -{ - if (vec) - { - if (*(vec -= 2) && !retain) free(*vec); - free(vec); - } -} diff --git a/src/lib/libast/vec/vecload.c b/src/lib/libast/vec/vecload.c deleted file mode 100644 index d76e30d247c3..000000000000 --- a/src/lib/libast/vec/vecload.c +++ /dev/null @@ -1,92 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ -/* - * Glenn Fowler - * AT&T Bell Laboratories - * - * string vector load support - */ - -#include -#include - -/* - * load a string vector from lines in buf - * buf may be modified on return - * - * each line in buf is treated as a new vector element - * lines with # as first char are comments - * \ as the last char joins consecutive lines - * - * the vector ends with a 0 sentinel - * - * the string array pointer is returned - */ - -char** -vecload(char* buf) -{ - char* s; - int n; - char** p; - char** vec; - - vec = 0; - n = (*buf == '#') ? -1 : 0; - for (s = buf;; s++) - { - if (*s == '\n') - { - if (s > buf && *(s - 1) == '\\') *(s - 1) = *s = ' '; - else - { - *s = 0; - if (*(s + 1) != '#') - { - n++; - if (!*(s + 1)) break; - } - } - } - else if (!*s) - { - n++; - break; - } - } - if (n < 0) n = 0; - if (p = newof(0, char*, n + 3, 0)) - { - *p++ = s = buf; - vec = ++p; - if (n > 0) for (;;) - { - if (*s != '#') - { - *p++ = s; - if (--n <= 0) break; - } - while (*s) s++; - s++; - } - *p = 0; - *(vec - 1) = (char*)p; - } - return vec; -} diff --git a/src/lib/libast/vec/vecstring.c b/src/lib/libast/vec/vecstring.c deleted file mode 100644 index fdddfdfb8a5d..000000000000 --- a/src/lib/libast/vec/vecstring.c +++ /dev/null @@ -1,42 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ -/* - * Glenn Fowler - * AT&T Bell Laboratories - * - * string vector load support - */ - -#include -#include - -/* - * load a string vector from lines in str - */ - -char** -vecstring(const char* str) -{ - char* buf; - char** vec; - - if (!str || !*str || !(buf = strdup(str))) vec = 0; - else if (!(vec = vecload(buf))) free(buf); - return vec; -} diff --git a/src/lib/libcmd/Mamfile b/src/lib/libcmd/Mamfile index 21f702dcfc4d..05db9042e46e 100644 --- a/src/lib/libcmd/Mamfile +++ b/src/lib/libcmd/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 setv INSTALLROOT ../../.. setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast setv CC cc @@ -37,14 +37,16 @@ make install virtual make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit prev ${PACKAGE_ast_INCLUDE}/endian.h make ${PACKAGE_ast_INCLUDE}/wchar.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h + note * TODO * circular depencency + note # prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h done done done make ${PACKAGE_ast_INCLUDE}/stdio.h implicit make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_std.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_std.h done done prev ${PACKAGE_ast_INCLUDE}/ast_common.h @@ -426,7 +428,6 @@ make install virtual prev tty.c prev uname.c prev uniq.c - prev vmstate.c prev wc.c prev revlib.c prev wclib.c @@ -448,6 +449,14 @@ make install virtual exec - ${^} | exec - sort -u exec - } > cmdext.h + prev vmstate.c + exec - { + exec - cat <> cmdext.h prev ${PACKAGE_ast_INCLUDE}/shcmd.h done @@ -463,6 +472,7 @@ make install virtual done done make sumlib.o + bind -lsum exec - set -- ${mam_libsum} exec - ${AR} x "$1" sumlib.o done @@ -543,7 +553,6 @@ make install virtual prev tty.c prev uname.c prev uniq.c - prev vmstate.c prev wc.c prev revlib.c prev wclib.c @@ -563,6 +572,14 @@ make install virtual exec - ${^} | exec - sort -u exec - } > ${@} + prev vmstate.c + exec - { + exec - cat <> ${@} done cmdlist.h exec - cp -f ${<} ${@} done ${PACKAGE_ast_INCLUDE}/cmdlist.h diff --git a/src/lib/libcmd/cat.c b/src/lib/libcmd/cat.c index 0ad71d09c3df..ea4ec16f3084 100644 --- a/src/lib/libcmd/cat.c +++ b/src/lib/libcmd/cat.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -184,7 +184,7 @@ vcat(char* states, Sfio_t* ip, Sfio_t* op, Reserve_f reserve, int flags) else { memcpy(tmp, pp, c); - if (!(nxt = (unsigned char*)(*reserve)(ip, SF_UNBOUND, 0))) + if (!(nxt = (unsigned char*)(*reserve)(ip, SFIO_UNBOUND, 0))) { states[0] = sfvalue(ip) ? T_ERROR : T_EOF; *(cp = end = tmp + sizeof(tmp) - 1) = 0; @@ -268,7 +268,7 @@ vcat(char* states, Sfio_t* ip, Sfio_t* op, Reserve_f reserve, int flags) goto flush; } c = last; - if (!(nxt = (unsigned char*)(*reserve)(ip, SF_UNBOUND, 0))) + if (!(nxt = (unsigned char*)(*reserve)(ip, SFIO_UNBOUND, 0))) { *(cp = end = tmp + sizeof(tmp) - 1) = 0; states[0] = (m = sfvalue(ip)) ? T_ERROR : T_EOF; @@ -345,7 +345,7 @@ vcat(char* states, Sfio_t* ip, Sfio_t* op, Reserve_f reserve, int flags) { if (cp < end || last != '\n') break; - if (!(nxt = (unsigned char*)(*reserve)(ip, SF_UNBOUND, 0))) + if (!(nxt = (unsigned char*)(*reserve)(ip, SFIO_UNBOUND, 0))) { states[0] = sfvalue(ip) ? T_ERROR : T_EOF; cp = end = tmp; @@ -533,7 +533,7 @@ b_cat(int argc, char** argv, Shbltin_t* context) sfsetbuf(fp, fp, -1); if (dovcat) n = vcat(states, fp, sfstdout, reserve, flags); - else if (sfmove(fp, sfstdout, SF_UNBOUND, -1) >= 0 && sfeof(fp)) + else if (sfmove(fp, sfstdout, SFIO_UNBOUND, -1) >= 0 && sfeof(fp)) n = 0; else n = -1; diff --git a/src/lib/libcmd/chgrp.c b/src/lib/libcmd/chgrp.c index e751194c42da..3c7708da5909 100644 --- a/src/lib/libcmd/chgrp.c +++ b/src/lib/libcmd/chgrp.c @@ -367,7 +367,7 @@ b_chgrp(int argc, char** argv, Shbltin_t* context) getids(s, &t, &key, options); if (!(m = (Map_t*)dtmatch(map, &key))) { - if (!(m = (Map_t*)stkalloc(stkstd, sizeof(Map_t)))) + if (!(m = stkalloc(stkstd, sizeof(Map_t)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory [id dictionary]"); UNREACHABLE(); diff --git a/src/lib/libcmd/cksum.c b/src/lib/libcmd/cksum.c index 549a0871507f..5a419ddf6c6a 100644 --- a/src/lib/libcmd/cksum.c +++ b/src/lib/libcmd/cksum.c @@ -194,7 +194,7 @@ pr(State_t* state, Sfio_t* op, Sfio_t* ip, char* file, int perm, struct stat* st if (state->text) { peek = 0; - while (p = sfreserve(ip, SF_UNBOUND, 0)) + while (p = sfreserve(ip, SFIO_UNBOUND, 0)) { e = p + sfvalue(ip); if (peek) @@ -220,7 +220,7 @@ pr(State_t* state, Sfio_t* op, Sfio_t* ip, char* file, int perm, struct stat* st sumblock(state->sum, "\r", 1); } else - while (p = sfreserve(ip, SF_UNBOUND, 0)) + while (p = sfreserve(ip, SFIO_UNBOUND, 0)) sumblock(state->sum, p, sfvalue(ip)); if (sfvalue(ip)) error(ERROR_SYSTEM|2, "%s: read error", file); diff --git a/src/lib/libcmd/cmp.c b/src/lib/libcmd/cmp.c index e3ab705c7993..670f9210d4c5 100644 --- a/src/lib/libcmd/cmp.c +++ b/src/lib/libcmd/cmp.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -159,14 +159,14 @@ cmp(const char* file1, Sfio_t* f1, const char* file2, Sfio_t* f2, int flags, Sfo { if (count > 0 && !(count -= n1)) return ret; - if (!(p1 = (unsigned char*)sfreserve(f1, SF_UNBOUND, 0)) || (c1 = sfvalue(f1)) <= 0) + if (!(p1 = (unsigned char*)sfreserve(f1, SFIO_UNBOUND, 0)) || (c1 = sfvalue(f1)) <= 0) { if (sferror(f1)) { error(ERROR_exit(2), "read error on %s", file1); UNREACHABLE(); } - if ((e2 - p2) > 0 || sfreserve(f2, SF_UNBOUND, 0) && sfvalue(f2) > 0) + if ((e2 - p2) > 0 || sfreserve(f2, SFIO_UNBOUND, 0) && sfvalue(f2) > 0) { ret = 1; if (!(flags & CMP_SILENT)) @@ -189,7 +189,7 @@ cmp(const char* file1, Sfio_t* f1, const char* file2, Sfio_t* f2, int flags, Sfo } if ((c2 = e2 - p2) <= 0) { - if (!(p2 = (unsigned char*)sfreserve(f2, SF_UNBOUND, 0)) || (c2 = sfvalue(f2)) <= 0) + if (!(p2 = (unsigned char*)sfreserve(f2, SFIO_UNBOUND, 0)) || (c2 = sfvalue(f2)) <= 0) { if (sferror(f2)) { diff --git a/src/lib/libcmd/cp.c b/src/lib/libcmd/cp.c index f3cf2974cb8f..cd75de414c25 100644 --- a/src/lib/libcmd/cp.c +++ b/src/lib/libcmd/cp.c @@ -589,14 +589,14 @@ visit(State_t* state, FTSENT* ent) } else if (ent->fts_statp->st_size > 0) { - if (!(ip = sfnew(NULL, NULL, SF_UNBOUND, rfd, SF_READ))) + if (!(ip = sfnew(NULL, NULL, SFIO_UNBOUND, rfd, SFIO_READ))) { error(ERROR_SYSTEM|2, "%s: %s read stream error", ent->fts_path, state->path); close(rfd); close(wfd); return 0; } - if (!(op = sfnew(NULL, NULL, SF_UNBOUND, wfd, SF_WRITE))) + if (!(op = sfnew(NULL, NULL, SFIO_UNBOUND, wfd, SFIO_WRITE))) { error(ERROR_SYSTEM|2, "%s: %s write stream error", ent->fts_path, state->path); close(wfd); @@ -604,7 +604,7 @@ visit(State_t* state, FTSENT* ent) return 0; } n = 0; - if (sfmove(ip, op, (Sfoff_t)SF_UNBOUND, -1) < 0) + if (sfmove(ip, op, (Sfoff_t)SFIO_UNBOUND, -1) < 0) n |= 3; if (!sfeof(ip)) n |= 1; @@ -872,7 +872,7 @@ b_cp(int argc, char** argv, Shbltin_t* context) argc--; argv++; } - if (!(v = (char**)stkalloc(stkstd, (argc + 2) * sizeof(char*)))) + if (!(v = stkalloc(stkstd, (argc + 2) * sizeof(char*)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory"); UNREACHABLE(); diff --git a/src/lib/libcmd/cut.c b/src/lib/libcmd/cut.c index ceb6e2556427..90c0cec4a6d0 100644 --- a/src/lib/libcmd/cut.c +++ b/src/lib/libcmd/cut.c @@ -134,7 +134,7 @@ cutinit(int mode, char* str, Delim_t* wdelim, Delim_t* ldelim, size_t reclen) char* cp = str; Cut_t* cut; - if (!(cut = (Cut_t*)stkalloc(stkstd, sizeof(Cut_t) + strlen(cp) * sizeof(int)))) + if (!(cut = stkalloc(stkstd, sizeof(Cut_t) + strlen(cp) * sizeof(int)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory"); UNREACHABLE(); @@ -275,7 +275,7 @@ cutcols(Cut_t* cut, Sfio_t* fdin, Sfio_t* fdout) bp = sfreserve(fdin, len, -1); else bp = sfgetr(fdin, '\n', 0); - if (!bp && !(bp = sfgetr(fdin, 0, SF_LASTR))) + if (!bp && !(bp = sfgetr(fdin, 0, SFIO_LASTR))) break; len = sfvalue(fdin); xx = 0; @@ -387,7 +387,7 @@ cutfields(Cut_t* cut, Sfio_t* fdin, Sfio_t* fdout) long offset = 0; unsigned char mb[8]; /* process each buffer */ - while ((bp = (unsigned char*)sfreserve(fdin, SF_UNBOUND, -1)) && (c = sfvalue(fdin)) > 0) + while ((bp = (unsigned char*)sfreserve(fdin, SFIO_UNBOUND, -1)) && (c = sfvalue(fdin)) > 0) { cp = bp; ep = cp + --c; @@ -444,7 +444,7 @@ cutfields(Cut_t* cut, Sfio_t* fdin, Sfio_t* fdout) } for (i = 0; i <= (ep - cp); i++) mb[i] = cp[i]; - if (!(bp = (unsigned char*)sfreserve(fdin, SF_UNBOUND, -1)) || (c = sfvalue(fdin)) <= 0) + if (!(bp = (unsigned char*)sfreserve(fdin, SFIO_UNBOUND, -1)) || (c = sfvalue(fdin)) <= 0) goto failed; cp = bp; ep = cp + --c; diff --git a/src/lib/libcmd/fds.c b/src/lib/libcmd/fds.c index 79d1914b8c95..c5346af3d503 100644 --- a/src/lib/libcmd/fds.c +++ b/src/lib/libcmd/fds.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -217,7 +217,7 @@ b_fds(int argc, char** argv, Shbltin_t* context) } if (unit == 1) sp = sfstdout; - else if (fstat(unit, &st) || !(sp = sfnew(NULL, NULL, SF_UNBOUND, unit, SF_WRITE))) + else if (fstat(unit, &st) || !(sp = sfnew(NULL, NULL, SFIO_UNBOUND, unit, SFIO_WRITE))) { error(ERROR_SYSTEM|3, "%d: cannot write to file descriptor"); UNREACHABLE(); diff --git a/src/lib/libcmd/fmt.c b/src/lib/libcmd/fmt.c index 9b1ef4c9d1ce..7210096f93af 100644 --- a/src/lib/libcmd/fmt.c +++ b/src/lib/libcmd/fmt.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -239,7 +239,7 @@ dofmt(Fmt_t* fp) char buf[8192]; cp = 0; - while (cp || (cp = sfgetr(fp->in, '\n', 0)) && !(splice = 0) && (lp = cp + sfvalue(fp->in) - 1) || (cp = sfgetr(fp->in, '\n', SF_LASTR)) && (splice = 1) && (lp = cp + sfvalue(fp->in))) + while (cp || (cp = sfgetr(fp->in, '\n', 0)) && !(splice = 0) && (lp = cp + sfvalue(fp->in) - 1) || (cp = sfgetr(fp->in, '\n', SFIO_LASTR)) && (splice = 1) && (lp = cp + sfvalue(fp->in))) { if (isoption(fp, 'o')) { diff --git a/src/lib/libcmd/head.c b/src/lib/libcmd/head.c index 8b252a5fae7d..73231ca3d61b 100644 --- a/src/lib/libcmd/head.c +++ b/src/lib/libcmd/head.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2013 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -131,7 +131,7 @@ b_head(int argc, char** argv, Shbltin_t* context) { cp = "/dev/stdin"; fp = sfstdin; - sfset(fp, SF_SHARE, 1); + sfset(fp, SFIO_SHARE, 1); } else if (!(fp = sfopen(NULL, cp, "r"))) { @@ -149,7 +149,7 @@ b_head(int argc, char** argv, Shbltin_t* context) goto next; } if ((moved = sfmove(fp, sfstdout, keep, delim)) < 0 && !ERROR_PIPE(errno) && errno != EINTR || - delim >= 0 && moved < keep && sfmove(fp, sfstdout, SF_UNBOUND, -1) < 0 && !ERROR_PIPE(errno) && errno != EINTR) + delim >= 0 && moved < keep && sfmove(fp, sfstdout, SFIO_UNBOUND, -1) < 0 && !ERROR_PIPE(errno) && errno != EINTR) error(ERROR_system(0), "%s: read error", cp); next: if (fp != sfstdin) diff --git a/src/lib/libcmd/join.c b/src/lib/libcmd/join.c index 6f71009e50d9..ec8653a959ab 100644 --- a/src/lib/libcmd/join.c +++ b/src/lib/libcmd/join.c @@ -970,8 +970,8 @@ b_join(int argc, char** argv, Shbltin_t* context) } if (jp->buffered) { - sfsetbuf(jp->file[0].iop, jp->file[0].iop, SF_UNBOUND); - sfsetbuf(jp->file[1].iop, jp->file[1].iop, SF_UNBOUND); + sfsetbuf(jp->file[0].iop, jp->file[0].iop, SFIO_UNBOUND); + sfsetbuf(jp->file[1].iop, jp->file[1].iop, SFIO_UNBOUND); } jp->outfile = sfstdout; if (!jp->outlist) diff --git a/src/lib/libcmd/paste.c b/src/lib/libcmd/paste.c index a5102cd374d6..1259c9dc7339 100644 --- a/src/lib/libcmd/paste.c +++ b/src/lib/libcmd/paste.c @@ -257,7 +257,7 @@ b_paste(int argc, char** argv, Shbltin_t* context) n = 1; if(!sflag) { - if (!(streams = (Sfio_t**)stkalloc(stkstd,n*sizeof(Sfio_t*)))) + if (!(streams = stkalloc(stkstd,n*sizeof(Sfio_t*)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory"); UNREACHABLE(); diff --git a/src/lib/libcmd/revlib.c b/src/lib/libcmd/revlib.c index 248dd9cf1abc..e79a5c4e24e9 100644 --- a/src/lib/libcmd/revlib.c +++ b/src/lib/libcmd/revlib.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,7 +22,7 @@ #include #include -#define BUFSIZE SF_BUFSIZE +#define BUFSIZE SFIO_BUFSIZE #define rounddown(n,size) (((n)-1)&~((size)-1)) /* @@ -37,12 +37,12 @@ int rev_line(Sfio_t *in, Sfio_t *out, off_t start) off_t offset; if(sfseek(in,0,SEEK_CUR) < 0) { - Sfio_t *tmp = sftmp(4*SF_BUFSIZE); + Sfio_t *tmp = sftmp(4*SFIO_BUFSIZE); if(!tmp) return -1; if(start>0 && sfmove(in, NULL, start, -1) != start) return -1; - if(sfmove(in, tmp, SF_UNBOUND, -1) < 0 || !sfeof(in) || sferror(tmp)) + if(sfmove(in, tmp, SFIO_UNBOUND, -1) < 0 || !sfeof(in) || sferror(tmp)) return -1; in = tmp; start=0; diff --git a/src/lib/libcmd/rm.c b/src/lib/libcmd/rm.c index 8184af92cd55..7db4111f4d51 100644 --- a/src/lib/libcmd/rm.c +++ b/src/lib/libcmd/rm.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2013 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -87,7 +87,7 @@ typedef struct State_s /* program state */ int unconditional; /* enable dir rwx on preorder */ int verbose; /* display each file */ #if _lib_fsync - char buf[SF_BUFSIZE];/* clobber buffer */ + char buf[SFIO_BUFSIZE];/* clobber buffer */ #endif } State_t; diff --git a/src/lib/libcmd/stty.c b/src/lib/libcmd/stty.c index f94490af4b75..e112377ad2dc 100644 --- a/src/lib/libcmd/stty.c +++ b/src/lib/libcmd/stty.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -928,15 +928,6 @@ static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp) return 1; } -#ifndef _lib_tcgetpgrp -# ifdef TIOCGPGRP - static int _i_; -# define tcgetpgrp(a) (ioctl(a, TIOCGPGRP, &_i_)>=0?_i_:-1) -# else -# define tcgetpgrp(a) (-1) -# endif /* TIOCGPGRP */ -#endif /* _lib_tcgetpgrp */ - int b_stty(int argc, char** argv, Shbltin_t* context) { diff --git a/src/lib/libcmd/tail.c b/src/lib/libcmd/tail.c index 2021dd5632a0..bc842b294fe8 100644 --- a/src/lib/libcmd/tail.c +++ b/src/lib/libcmd/tail.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2013 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -176,11 +176,11 @@ tailpos(Sfio_t* fp, Sfoff_t number, int delim) incomplete = 1; for (;;) { - if ((offset = last - SF_BUFSIZE) < first) + if ((offset = last - SFIO_BUFSIZE) < first) offset = first; sfseek(fp, offset, SEEK_SET); n = last - offset; - if (!(s = sfreserve(fp, n, SF_LOCKR))) + if (!(s = sfreserve(fp, n, SFIO_LOCKR))) return -1; t = s + n; if (incomplete) @@ -216,7 +216,7 @@ pipetail(Sfio_t* infile, Sfio_t* outfile, Sfoff_t number, int delim) Sfio_t* out; Sfoff_t n; Sfoff_t nleft = number; - size_t a = 2 * SF_BUFSIZE; + size_t a = 2 * SFIO_BUFSIZE; int fno = 0; Sfoff_t offset[2]; Sfio_t* tmp[2]; @@ -292,12 +292,12 @@ init(Tail_t* tp, Sfoff_t number, int delim, int flags, const char** format) error(ERROR_system(0), "%s: cannot open", tp->name); return -1; } - sfset(tp->sp, SF_SHARE, 0); + sfset(tp->sp, SFIO_SHARE, 0); if (offset) { if (number < 0 || !number && (flags & POSITIVE)) { - sfset(tp->sp, SF_SHARE, !(flags & FOLLOW)); + sfset(tp->sp, SFIO_SHARE, !(flags & FOLLOW)); if (number < -1) { sfmove(tp->sp, NULL, -number - 1, delim); @@ -326,7 +326,7 @@ init(Tail_t* tp, Sfoff_t number, int delim, int flags, const char** format) sfprintf(sfstdout, *format, tp->name); *format = header_fmt; } - op = (flags & REVERSE) ? sftmp(4*SF_BUFSIZE) : sfstdout; + op = (flags & REVERSE) ? sftmp(4*SFIO_BUFSIZE) : sfstdout; pipetail(tp->sp ? tp->sp : sfstdin, op, number, delim); if (flags & REVERSE) { @@ -629,7 +629,7 @@ b_tail(int argc, char** argv, Shbltin_t* context) } if (flags & FOLLOW) { - if (!(fp = (Tail_t*)stkalloc(stkstd, argc * sizeof(Tail_t)))) + if (!(fp = stkalloc(stkstd, argc * sizeof(Tail_t)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory"); UNREACHABLE(); @@ -677,9 +677,9 @@ b_tail(int argc, char** argv, Shbltin_t* context) n = 1; if (timeout) fp->expire = NOW + timeout; - z = fp->fifo ? SF_UNBOUND : st.st_size - fp->cur; + z = fp->fifo ? SFIO_UNBOUND : st.st_size - fp->cur; i = 0; - if ((s = sfreserve(fp->sp, z, SF_LOCKR)) || (z = sfvalue(fp->sp)) && (s = sfreserve(fp->sp, z, SF_LOCKR)) && (i = 1)) + if ((s = sfreserve(fp->sp, z, SFIO_LOCKR)) || (z = sfvalue(fp->sp)) && (s = sfreserve(fp->sp, z, SFIO_LOCKR)) && (i = 1)) { z = sfvalue(fp->sp); for (r = s + z; r > s && *(r - 1) != '\n'; r--); @@ -773,17 +773,17 @@ b_tail(int argc, char** argv, Shbltin_t* context) } if (number < 0 || !number && (flags & POSITIVE)) { - sfset(ip, SF_SHARE, 1); + sfset(ip, SFIO_SHARE, 1); if (number < -1 && (moved = sfmove(ip, NULL, -(number + 1), delim)) >= 0 && delim >= 0 && moved < -(number + 1)) - (void)sfgetr(ip, delim, SF_LASTR); + (void)sfgetr(ip, delim, SFIO_LASTR); if (flags & REVERSE) rev_line(ip, sfstdout, sfseek(ip, 0, SEEK_CUR)); else - sfmove(ip, sfstdout, SF_UNBOUND, -1); + sfmove(ip, sfstdout, SFIO_UNBOUND, -1); } else { - sfset(ip, SF_SHARE, 0); + sfset(ip, SFIO_SHARE, 0); if ((offset = tailpos(ip, number, delim)) >= 0) { if (flags & REVERSE) @@ -791,12 +791,12 @@ b_tail(int argc, char** argv, Shbltin_t* context) else { sfseek(ip, offset, SEEK_SET); - sfmove(ip, sfstdout, SF_UNBOUND, -1); + sfmove(ip, sfstdout, SFIO_UNBOUND, -1); } } else { - op = (flags & REVERSE) ? sftmp(4*SF_BUFSIZE) : sfstdout; + op = (flags & REVERSE) ? sftmp(4*SFIO_BUFSIZE) : sfstdout; pipetail(ip, op, number, delim); if (flags & REVERSE) { diff --git a/src/lib/libcmd/tee.c b/src/lib/libcmd/tee.c index 6399e71f73e1..6eaedc677f11 100644 --- a/src/lib/libcmd/tee.c +++ b/src/lib/libcmd/tee.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -97,7 +97,7 @@ tee_cleanup(Tee_t* tp) { sfdisc(sfstdout, NULL); if (tp->line >= 0) - sfset(sfstdout, SF_LINE, tp->line); + sfset(sfstdout, SFIO_LINE, tp->line); for (hp = tp->fd; (n = *hp) >= 0; hp++) close(n); } @@ -135,11 +135,11 @@ b_tee(int argc, char** argv, Shbltin_t* context) signal(SIGINT, SIG_IGN); continue; case 'l': - line = sfset(sfstdout, 0, 0) & SF_LINE; + line = sfset(sfstdout, 0, 0) & SFIO_LINE; if ((line == 0) == (opt_info.num == 0)) line = -1; else - sfset(sfstdout, SF_LINE, !!opt_info.num); + sfset(sfstdout, SFIO_LINE, !!opt_info.num); continue; case ':': error(2, "%s", opt_info.arg); @@ -167,7 +167,7 @@ b_tee(int argc, char** argv, Shbltin_t* context) #endif if (argc > 0) { - if (tp = (Tee_t*)stkalloc(stkstd, sizeof(Tee_t) + argc * sizeof(int))) + if (tp = stkalloc(stkstd, sizeof(Tee_t) + argc * sizeof(int))) { memset(&tp->disc, 0, sizeof(tp->disc)); tp->disc.writef = tee_write; @@ -198,7 +198,7 @@ b_tee(int argc, char** argv, Shbltin_t* context) UNREACHABLE(); } } - if ((sfmove(sfstdin, sfstdout, SF_UNBOUND, -1) < 0 || !sfeof(sfstdin)) && !ERROR_PIPE(errno) && errno != EINTR) + if ((sfmove(sfstdin, sfstdout, SFIO_UNBOUND, -1) < 0 || !sfeof(sfstdin)) && !ERROR_PIPE(errno) && errno != EINTR) error(ERROR_system(0), "read error"); if (sfsync(sfstdout)) error(ERROR_system(0), "write error"); diff --git a/src/lib/libcmd/uname.c b/src/lib/libcmd/uname.c index 880100d5eeb4..a64917f43f60 100644 --- a/src/lib/libcmd/uname.c +++ b/src/lib/libcmd/uname.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -142,7 +142,7 @@ uname(struct utsname* ut) sys = 0; } #endif -#ifdef _lib_gethostname +#if _lib_gethostname if (gethostname(ut->nodename, sizeof(ut->nodename) - 1)) return -1; #else @@ -297,7 +297,7 @@ b_uname(int argc, char** argv, Shbltin_t* context) continue; case ':': { - char **new_argv = (char **)stkalloc(stkstd, (argc + 3) * sizeof(char*)); + char **new_argv = stkalloc(stkstd, (argc + 3) * sizeof(char*)); new_argv[0] = "command"; new_argv[1] = "-px"; for (n = 0; n <= argc; n++) diff --git a/src/lib/libcmd/uniq.c b/src/lib/libcmd/uniq.c index 47db36d48e22..af4e993b2d24 100644 --- a/src/lib/libcmd/uniq.c +++ b/src/lib/libcmd/uniq.c @@ -91,7 +91,7 @@ static int uniq(Sfio_t *fdin, Sfio_t *fdout, int fields, int chars, int width, i { if(bufp = sfgetr(fdin,'\n',0)) n = sfvalue(fdin); - else if(bufp = sfgetr(fdin,'\n',SF_LASTR)) + else if(bufp = sfgetr(fdin,'\n',SFIO_LASTR)) { n = sfvalue(fdin); bufp = memcpy(fmtbuf(n + 1), bufp, n); diff --git a/src/lib/libcmd/wclib.c b/src/lib/libcmd/wclib.c index 0a4850d23b96..2848afb67fcf 100644 --- a/src/lib/libcmd/wclib.c +++ b/src/lib/libcmd/wclib.c @@ -56,7 +56,7 @@ Wc_t* wc_init(int mode) int w; Wc_t* wp; - if (!(wp = (Wc_t*)stkalloc(stkstd,sizeof(Wc_t)))) + if (!(wp = stkalloc(stkstd,sizeof(Wc_t)))) return NULL; if (!mbwide()) wp->mb = 0; @@ -175,7 +175,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) wchar_t x; unsigned char side[32]; - sfset(fd,SF_WRITE,1); + sfset(fd,SFIO_WRITE,1); nlines = nwords = nchars = nbytes = 0; wp->longest = 0; if (wp->mb < 0 && (wp->mode & (WC_MBYTE|WC_WORDS))) @@ -196,7 +196,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) else o = 0; cp = side + o; - if (!(buff = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) || (n = sfvalue(fd)) <= 0) + if (!(buff = (unsigned char*)sfreserve(fd, SFIO_UNBOUND, 0)) || (n = sfvalue(fd)) <= 0) { if ((nchars - longest) > wp->longest) wp->longest = nchars - longest; @@ -252,7 +252,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) { if (!(wp->mode & (WC_MBYTE|WC_WORDS|WC_LONGEST))) { - while ((cp = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) && (c = sfvalue(fd)) > 0) + while ((cp = (unsigned char*)sfreserve(fd, SFIO_UNBOUND, 0)) && (c = sfvalue(fd)) > 0) { nchars += c; endbuff = cp + c; @@ -271,7 +271,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) } else { - while ((cp = buff = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) && (c = sfvalue(fd)) > 0) + while ((cp = buff = (unsigned char*)sfreserve(fd, SFIO_UNBOUND, 0)) && (c = sfvalue(fd)) > 0) { nchars += c; /* check to see whether first character terminates word */ @@ -342,7 +342,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) lastchar = 0; start = (endbuff = side) + 1; xspace = iswspace(0xa0) || iswspace(0x85); - while ((cp = buff = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) && (c = sfvalue(fd)) > 0) + while ((cp = buff = (unsigned char*)sfreserve(fd, SFIO_UNBOUND, 0)) && (c = sfvalue(fd)) > 0) { nbytes += c; nchars += c; diff --git a/src/lib/libdll/Mamfile b/src/lib/libdll/Mamfile index e2717f021d04..e636748baa2f 100644 --- a/src/lib/libdll/Mamfile +++ b/src/lib/libdll/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 setv INSTALLROOT ../../.. setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast setv CC cc @@ -28,7 +28,8 @@ make install virtual prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit make ${PACKAGE_ast_INCLUDE}/endian.h implicit make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_common.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_common.h done done done @@ -40,14 +41,16 @@ make install virtual make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit prev ${PACKAGE_ast_INCLUDE}/endian.h make ${PACKAGE_ast_INCLUDE}/wchar.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h done done done make ${PACKAGE_ast_INCLUDE}/stdio.h implicit make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_std.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_std.h done done prev ${PACKAGE_ast_INCLUDE}/ast_common.h diff --git a/src/lib/libsum/Mamfile b/src/lib/libsum/Mamfile index 662957ffc060..7ad675087aad 100644 --- a/src/lib/libsum/Mamfile +++ b/src/lib/libsum/Mamfile @@ -3,7 +3,7 @@ note * This build script is in an extended Make Abstract Machine (MAM) note * language. Documentation is at: src/cmd/INIT/README-mamake.md note * -setv MAMAKE_STRICT 2 +setv MAMAKE_STRICT 3 setv INSTALLROOT ../../.. setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast setv CC cc @@ -23,7 +23,6 @@ make install virtual make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit make ${PACKAGE_ast_INCLUDE}/ast_common.h implicit prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit - prev ${PACKAGE_ast_INCLUDE}/endian.h done done done @@ -45,14 +44,16 @@ make install virtual make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit prev ${PACKAGE_ast_INCLUDE}/endian.h make ${PACKAGE_ast_INCLUDE}/wchar.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h done done done make ${PACKAGE_ast_INCLUDE}/stdio.h implicit make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit - prev ${PACKAGE_ast_INCLUDE}/ast_std.h + note * TODO * circular dependency + note # prev ${PACKAGE_ast_INCLUDE}/ast_std.h done done prev ${PACKAGE_ast_INCLUDE}/ast_common.h @@ -143,7 +144,6 @@ make install virtual note * pre-install note * - prev libsum.a loop DIR ${INSTALLROOT}/lib/lib ${PACKAGE_ast_INCLUDE} make ${DIR} exec - mkdir -p ${@}