diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-12-18 20:55:53 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-12-18 20:55:53 +0000 |
commit | 62c19679be069ef2770e79fb05fdbc3a9749c612 (patch) | |
tree | bbdc0d9152836bab35763618d41fe24d089c34d0 /bin/ksh | |
parent | 220f5907de5bdc773b687af762aa5d835e26025c (diff) |
Remove unused OS dependent #ifdef blocks, #defines and macro abstraction.
First step in making the ksh code easier to read. From Matthias Kilian
Diffstat (limited to 'bin/ksh')
47 files changed, 855 insertions, 3614 deletions
diff --git a/bin/ksh/Makefile b/bin/ksh/Makefile index f94a05d85b6..7faaf9c467d 100644 --- a/bin/ksh/Makefile +++ b/bin/ksh/Makefile @@ -1,12 +1,12 @@ -# $OpenBSD: Makefile,v 1.18 2004/02/16 19:07:19 deraadt Exp $ +# $OpenBSD: Makefile,v 1.19 2004/12/18 20:55:52 millert Exp $ PROG= ksh SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c \ eval.c exec.c expr.c history.c io.c jobs.c lex.c mail.c \ - main.c misc.c missing.c path.c shf.c syn.c table.c trap.c \ + main.c misc.c path.c shf.c syn.c table.c trap.c \ tree.c tty.c var.c version.c vi.c -DEFS= -DHAVE_CONFIG_H -Wall -Wno-unused +DEFS= -Wall -Wno-unused CFLAGS+=${DEFS} -I. -I${.CURDIR} -DKSH MAN= ksh.1 sh.1 diff --git a/bin/ksh/PROJECTS b/bin/ksh/PROJECTS index 07813a4c98b..6ae931c9030 100644 --- a/bin/ksh/PROJECTS +++ b/bin/ksh/PROJECTS @@ -1,4 +1,4 @@ -$OpenBSD: PROJECTS,v 1.5 1999/07/14 13:37:23 millert Exp $ +$OpenBSD: PROJECTS,v 1.6 2004/12/18 20:55:52 millert Exp $ Things to be done in pdksh (see also the NOTES file): @@ -109,3 +109,6 @@ Things to be done in pdksh (see also the NOTES file): * teach shf_vfprintf() about long long's (%lld); also make %p use long longs if appropriate. + + * decide wether to keep currently disabled FP stuff in shf.c; if + not, eliminate ksh_limval.h (moving BITS to var.c). diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c index 137b6621a20..f1071f0afe6 100644 --- a/bin/ksh/c_ksh.c +++ b/bin/ksh/c_ksh.c @@ -1,16 +1,13 @@ -/* $OpenBSD: c_ksh.c,v 1.18 2004/02/10 13:03:36 jmc Exp $ */ +/* $OpenBSD: c_ksh.c,v 1.19 2004/12/18 20:55:52 millert Exp $ */ /* * built-in Korn commands: c_* */ #include "sh.h" -#include "ksh_stat.h" +#include <sys/stat.h> #include <ctype.h> -#ifdef __CYGWIN__ -#include <sys/cygwin.h> -#endif /* __CYGWIN__ */ int c_cd(wp) @@ -107,11 +104,9 @@ c_cd(wp) cdpath = str_val(global("CDPATH")); do { cdnode = make_path(current_wd, dir, &cdpath, &xs, &phys_path); -#ifdef S_ISLNK if (physical) rval = chdir(try = Xstring(xs, xp) + phys_path); else -#endif /* S_ISLNK */ { simplify_path(Xstring(xs, xp)); rval = chdir(try = Xstring(xs, xp)); @@ -136,30 +131,15 @@ c_cd(wp) /* Ignore failure (happens if readonly or integer) */ setstr(oldpwd_s, current_wd, KSH_RETURN_ERROR); - if (!ISABSPATH(Xstring(xs, xp))) { -#ifdef OS2 - /* simplify_path() doesn't know about os/2's drive contexts, - * so it can't set current_wd when changing to a:foo. - * Handle this by calling getcwd()... - */ - pwd = ksh_get_wd((char *) 0, 0); -#else /* OS2 */ + if (Xstring(xs, xp)[0] != '/') { pwd = (char *) 0; -#endif /* OS2 */ } else -#ifdef S_ISLNK if (!physical || !(pwd = get_phys_path(Xstring(xs, xp)))) -#endif /* S_ISLNK */ pwd = Xstring(xs, xp); /* Set PWD */ if (pwd) { -#ifdef __CYGWIN__ - char ptmp[PATH]; /* larger than MAX_PATH */ - cygwin_conv_to_full_posix_path(pwd, ptmp); -#else /* __CYGWIN__ */ char *ptmp = pwd; -#endif /* __CYGWIN__ */ set_current_wd(ptmp); /* Ignore failure (happens if readonly or integer) */ setstr(pwd_s, ptmp, KSH_RETURN_ERROR); @@ -199,13 +179,9 @@ c_pwd(wp) bi_errorf("too many arguments"); return 1; } -#ifdef S_ISLNK p = current_wd[0] ? (physical ? get_phys_path(current_wd) : current_wd) : (char *) 0; -#else /* S_ISLNK */ - p = current_wd[0] ? current_wd : (char *) 0; -#endif /* S_ISLNK */ - if (p && eaccess(p, R_OK) < 0) + if (p && access(p, R_OK) < 0) p = (char *) 0; if (!p) { p = ksh_get_wd((char *) 0, 0); @@ -228,7 +204,6 @@ c_print(wp) #define PO_PMINUSMINUS BIT(2) /* print a -- argument */ #define PO_HIST BIT(3) /* print to history instead of stdout */ #define PO_COPROC BIT(4) /* printing to coprocess: block SIGPIPE */ -#define PO_FSLASH BIT(5) /* swap slash for backslash (for os2 ) */ int fd = 1; int flags = PO_EXPAND|PO_NL; char *s; @@ -269,11 +244,7 @@ c_print(wp) } } else { int optc; -#if OS2 - const char *options = "Rnpfrsu,"; /* added f flag */ -#else const char *options = "Rnprsu,"; -#endif while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF) switch (optc) { case 'R': /* fake BSD echo command */ @@ -284,11 +255,6 @@ c_print(wp) case 'e': flags |= PO_EXPAND; break; -#ifdef OS2 - case 'f': - flags |= PO_FSLASH; - break; -#endif case 'n': flags &= ~PO_NL; break; @@ -334,13 +300,6 @@ c_print(wp) s = *wp; while ((c = *s++) != '\0') { Xcheck(xs, xp); -#ifdef OS2 - if ((flags & PO_FSLASH) && c == '\\') - if (*s == '\\') - *s++; - else - c = '/'; -#endif /* OS2 */ if ((flags & PO_EXPAND) && c == '\\') { int i; @@ -392,7 +351,7 @@ c_print(wp) Xfree(xs, xp); } else { int n, len = Xlength(xs, xp); - int UNINITIALIZED(opipe); + int opipe = 0; #ifdef KSH /* Ensure we aren't killed by a SIGPIPE while writing to @@ -1129,7 +1088,7 @@ c_fgbg(wp) char **wp; { int bg = strcmp(*wp, "bg") == 0; - int UNINITIALIZED(rv); + int rv = 0; if (!Flag(FMONITOR)) { bi_errorf("job control not enabled"); @@ -1154,7 +1113,7 @@ struct kill_info { int num_width; int name_width; }; -static char *kill_fmt_entry ARGS((void *arg, int i, char *buf, int buflen)); +static char *kill_fmt_entry(void *arg, int i, char *buf, int buflen); /* format a single kill item */ static char * @@ -1231,16 +1190,16 @@ c_kill(wp) for (; wp[i]; i++) { if (!bi_getn(wp[i], &n)) return 1; - if (n > 128 && n < 128 + SIGNALS) + if (n > 128 && n < 128 + NSIG) n -= 128; - if (n > 0 && n < SIGNALS && sigtraps[n].name) + if (n > 0 && n < NSIG && sigtraps[n].name) shprintf("%s\n", sigtraps[n].name); else shprintf("%d\n", n); } } else if (Flag(FPOSIX)) { p = null; - for (i = 1; i < SIGNALS; i++, p = space) + for (i = 1; i < NSIG; i++, p = space) if (sigtraps[i].name) shprintf("%s%s", p, sigtraps[i].name); shprintf(newline); @@ -1249,10 +1208,10 @@ c_kill(wp) int mess_width; struct kill_info ki; - for (i = SIGNALS, ki.num_width = 1; i >= 10; i /= 10) + for (i = NSIG, ki.num_width = 1; i >= 10; i /= 10) ki.num_width++; ki.name_width = mess_width = 0; - for (i = 0; i < SIGNALS; i++) { + for (i = 0; i < NSIG; i++) { w = sigtraps[i].name ? strlen(sigtraps[i].name) : ki.num_width; if (w > ki.name_width) @@ -1262,7 +1221,7 @@ c_kill(wp) mess_width = w; } - print_columns(shl_stdout, SIGNALS - 1, + print_columns(shl_stdout, NSIG - 1, kill_fmt_entry, (void *) &ki, ki.num_width + ki.name_width + mess_width + 3, 1); } diff --git a/bin/ksh/c_sh.c b/bin/ksh/c_sh.c index 50f9d9c5144..a2c5fb14d6d 100644 --- a/bin/ksh/c_sh.c +++ b/bin/ksh/c_sh.c @@ -1,15 +1,14 @@ -/* $OpenBSD: c_sh.c,v 1.17 2003/03/13 09:03:07 deraadt Exp $ */ +/* $OpenBSD: c_sh.c,v 1.18 2004/12/18 20:55:52 millert Exp $ */ /* * built-in Bourne commands */ #include "sh.h" -#include "ksh_stat.h" /* umask() */ -#include "ksh_time.h" -#include "ksh_times.h" +#include <sys/stat.h> /* umask() */ +#include <sys/times.h> -static char *clocktos ARGS((clock_t t)); +static char *clocktos(clock_t t); /* :, false and true */ @@ -215,7 +214,7 @@ int c_wait(wp) char **wp; { - int UNINITIALIZED(rv); + int rv = 0; int sig; if (ksh_getopt(wp, &builtin_opt, null) == '?') @@ -249,7 +248,7 @@ c_read(wp) const char *emsg; XString cs, xs; struct tbl *vp; - char UNINITIALIZED(*xp); + char *xp = NULL; while ((optc = ksh_getopt(wp, &builtin_opt, "prsu,")) != EOF) switch (optc) { @@ -323,11 +322,7 @@ c_read(wp) break; while (1) { c = shf_getc(shf); - if (c == '\0' -#ifdef OS2 - || c == '\r' -#endif /* OS2 */ - ) + if (c == '\0') continue; if (c == EOF && shf_error(shf) && shf_errno(shf) == EINTR) @@ -476,7 +471,7 @@ c_trap(wp) if (*wp == NULL) { int anydfl = 0; - for (p = sigtraps, i = SIGNALS+1; --i >= 0; p++) { + for (p = sigtraps, i = NSIG+1; --i >= 0; p++) { if (p->trap == NULL) anydfl = 1; else { @@ -491,7 +486,7 @@ c_trap(wp) */ if (anydfl) { shprintf("trap -- -"); - for (p = sigtraps, i = SIGNALS+1; --i >= 0; p++) + for (p = sigtraps, i = NSIG+1; --i >= 0; p++) if (p->trap == NULL && p->name) shprintf(" %s", p->name); shprintf(newline); @@ -698,7 +693,7 @@ c_times(wp) { struct tms all; - (void) ksh_times(&all); + (void) times(&all); shprintf("Shell: %8ss user ", clocktos(all.tms_utime)); shprintf("%8ss system\n", clocktos(all.tms_stime)); shprintf("Kids: %8ss user ", clocktos(all.tms_cutime)); @@ -725,7 +720,7 @@ timex(t, f) extern clock_t j_usrtime, j_systime; /* computed by j_wait */ char opts[1]; - t0t = ksh_times(&t0); + t0t = times(&t0); if (t->left) { /* * Two ways of getting cpu usage of a command: just use t0 @@ -741,7 +736,7 @@ timex(t, f) opts[0] = 0; rv = execute(t->left, f | XTIME); tf |= opts[0]; - t1t = ksh_times(&t1); + t1t = times(&t1); } else tf = TF_NOARGS; @@ -863,8 +858,8 @@ c_builtin(wp) return 0; } -extern int c_test ARGS((char **wp)); /* in c_test.c */ -extern int c_ulimit ARGS((char **wp)); /* in c_ulimit.c */ +extern int c_test(char **wp); /* in c_test.c */ +extern int c_ulimit(char **wp); /* in c_ulimit.c */ /* A leading = means assignments before command are kept; * a leading * means a POSIX special builtin; @@ -894,13 +889,5 @@ const struct builtin shbuiltins [] = { {"ulimit", c_ulimit}, {"+umask", c_umask}, {"*=unset", c_unset}, -#ifdef OS2 - /* In OS2, the first line of a file can be "extproc name", which - * tells the command interpreter (cmd.exe) to use name to execute - * the file. For this to be useful, ksh must ignore commands - * starting with extproc and this does the trick... - */ - {"extproc", c_label}, -#endif /* OS2 */ {NULL, NULL} }; diff --git a/bin/ksh/c_test.c b/bin/ksh/c_test.c index 3e57eebc4a2..e95652f68f4 100644 --- a/bin/ksh/c_test.c +++ b/bin/ksh/c_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_test.c,v 1.10 2003/10/10 19:09:07 millert Exp $ */ +/* $OpenBSD: c_test.c,v 1.11 2004/12/18 20:55:52 millert Exp $ */ /* * test(1); version 7-like -- author Erik Baalbergen @@ -10,7 +10,7 @@ */ #include "sh.h" -#include "ksh_stat.h" +#include <sys/stat.h> #include "c_test.h" /* test(1) accepts the following grammar: @@ -87,17 +87,17 @@ static const struct t_op b_ops [] = { {"", TO_NONOP } }; -static int test_stat ARGS((const char *path, struct stat *statb)); -static int test_eaccess ARGS((const char *path, int mode)); -static int test_oexpr ARGS((Test_env *te, int do_eval)); -static int test_aexpr ARGS((Test_env *te, int do_eval)); -static int test_nexpr ARGS((Test_env *te, int do_eval)); -static int test_primary ARGS((Test_env *te, int do_eval)); -static int ptest_isa ARGS((Test_env *te, Test_meta meta)); -static const char *ptest_getopnd ARGS((Test_env *te, Test_op op, int do_eval)); -static int ptest_eval ARGS((Test_env *te, Test_op op, const char *opnd1, - const char *opnd2, int do_eval)); -static void ptest_error ARGS((Test_env *te, int offset, const char *msg)); +static int test_stat(const char *path, struct stat *statb); +static int test_eaccess(const char *path, int mode); +static int test_oexpr(Test_env *te, int do_eval); +static int test_aexpr(Test_env *te, int do_eval); +static int test_nexpr(Test_env *te, int do_eval); +static int test_primary(Test_env *te, int do_eval); +static int ptest_isa(Test_env *te, Test_meta meta); +static const char *ptest_getopnd(Test_env *te, Test_op op, int do_eval); +static int ptest_eval(Test_env *te, Test_op op, const char *opnd1, + const char *opnd2, int do_eval); +static void ptest_error(Test_env *te, int offset, const char *msg); int c_test(wp) @@ -259,70 +259,23 @@ test_eval(te, op, opnd1, opnd2, do_eval) case TO_FILID: /* -d */ return test_stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode); case TO_FILCDEV: /* -c */ -#ifdef S_ISCHR return test_stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode); -#else - return 0; -#endif case TO_FILBDEV: /* -b */ -#ifdef S_ISBLK return test_stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode); -#else - return 0; -#endif case TO_FILFIFO: /* -p */ -#ifdef S_ISFIFO return test_stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode); -#else - return 0; -#endif case TO_FILSYM: /* -h -L */ -#ifdef S_ISLNK return lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode); -#else - return 0; -#endif case TO_FILSOCK: /* -S */ -#ifdef S_ISSOCK return test_stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode); -#else - return 0; -#endif case TO_FILCDF:/* -H HP context dependent files (directories) */ -#ifdef S_ISCDF - { - /* Append a + to filename and check to see if result is a - * setuid directory. CDF stuff in general is hookey, since - * it breaks for the following sequence: echo hi > foo+; - * mkdir foo; echo bye > foo/default; chmod u+s foo - * (foo+ refers to the file with hi in it, there is no way - * to get at the file with bye in it - please correct me if - * I'm wrong about this). - */ - int len = strlen(opnd1); - char *p = str_nsave(opnd1, len + 1, ATEMP); - - p[len++] = '+'; - p[len] = '\0'; - return stat(p, &b1) == 0 && S_ISCDF(b1.st_mode); - } -#else return 0; -#endif case TO_FILSETU: /* -u */ -#ifdef S_ISUID return test_stat(opnd1, &b1) == 0 && (b1.st_mode & S_ISUID) == S_ISUID; -#else - return 0; -#endif case TO_FILSETG: /* -g */ -#ifdef S_ISGID return test_stat(opnd1, &b1) == 0 && (b1.st_mode & S_ISGID) == S_ISGID; -#else - return 0; -#endif case TO_FILSTCK: /* -k */ return test_stat(opnd1, &b1) == 0 && (b1.st_mode & S_ISVTX) == S_ISVTX; @@ -422,13 +375,6 @@ test_stat(path, statb) const char *path; struct stat *statb; { -#if !defined(HAVE_DEV_FD) - int fd; - - if (strncmp(path, "/dev/fd/", 8) == 0 && getn(path + 8, &fd)) - return fstat(fd, statb); -#endif /* !HAVE_DEV_FD */ - return stat(path, statb); } @@ -442,23 +388,7 @@ test_eaccess(path, mode) { int res; -#if !defined(HAVE_DEV_FD) - int fd; - - /* Note: doesn't handle //dev/fd, etc.. (this is ok) */ - if (strncmp(path, "/dev/fd/", 8) == 0 && getn(path + 8, &fd)) { - int flags; - - if ((flags = fcntl(fd, F_GETFL, 0)) < 0 - || (mode & X_OK) - || ((mode & W_OK) && (flags & O_ACCMODE) == O_RDONLY) - || ((mode & R_OK) && (flags & O_ACCMODE) == O_WRONLY)) - return -1; - return 0; - } -#endif /* !HAVE_DEV_FD */ - - res = eaccess(path, mode); + res = access(path, mode); /* * On most (all?) unixes, access() says everything is executable for * root - avoid this on files by using stat(). diff --git a/bin/ksh/c_test.h b/bin/ksh/c_test.h index dd0a43e2946..33df5721a8e 100644 --- a/bin/ksh/c_test.h +++ b/bin/ksh/c_test.h @@ -1,4 +1,4 @@ -/* $OpenBSD: c_test.h,v 1.2 2003/10/22 07:40:38 jmc Exp $ */ +/* $OpenBSD: c_test.h,v 1.3 2004/12/18 20:55:52 millert Exp $ */ /* Various types of operations. Keeping things grouped nicely * (unary,binary) makes switch() statements more efficient. @@ -42,14 +42,14 @@ struct test_env { XPtrV *av; /* used by dbtestp_* */ } pos; char **wp_end; /* used by ptest_* */ - int (*isa) ARGS((Test_env *te, Test_meta meta)); - const char *(*getopnd) ARGS((Test_env *te, Test_op op, int do_eval)); - int (*eval) ARGS((Test_env *te, Test_op op, const char *opnd1, - const char *opnd2, int do_eval)); - void (*error) ARGS((Test_env *te, int offset, const char *msg)); + int (*isa)(Test_env *te, Test_meta meta); + const char *(*getopnd) (Test_env *te, Test_op op, int do_eval); + int (*eval)(Test_env *te, Test_op op, const char *opnd1, + const char *opnd2, int do_eval); + void (*error)(Test_env *te, int offset, const char *msg); }; -Test_op test_isop ARGS((Test_env *te, Test_meta meta, const char *s)); -int test_eval ARGS((Test_env *te, Test_op op, const char *opnd1, - const char *opnd2, int do_eval)); -int test_parse ARGS((Test_env *te)); +Test_op test_isop(Test_env *te, Test_meta meta, const char *s); +int test_eval(Test_env *te, Test_op op, const char *opnd1, + const char *opnd2, int do_eval); +int test_parse(Test_env *te); diff --git a/bin/ksh/c_ulimit.c b/bin/ksh/c_ulimit.c index 17c8162b3e2..43b9cb8c1d4 100644 --- a/bin/ksh/c_ulimit.c +++ b/bin/ksh/c_ulimit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_ulimit.c,v 1.10 2003/10/22 07:40:38 jmc Exp $ */ +/* $OpenBSD: c_ulimit.c,v 1.11 2004/12/18 20:55:52 millert Exp $ */ /* ulimit -- handle "ulimit" builtin @@ -19,27 +19,11 @@ */ #include "sh.h" -#include "ksh_time.h" -#ifdef HAVE_SYS_RESOURCE_H -# include <sys/resource.h> -#endif /* HAVE_SYS_RESOURCE_H */ -#ifdef HAVE_ULIMIT_H -# include <ulimit.h> -#else /* HAVE_ULIMIT_H */ -# ifdef HAVE_ULIMIT -extern long ulimit(); -# endif /* HAVE_ULIMIT */ -#endif /* HAVE_ULIMIT_H */ +#include <sys/resource.h> #define SOFT 0x1 #define HARD 0x2 -#ifdef RLIM_INFINITY -# define KSH_RLIM_INFINITY RLIM_INFINITY -#else -# define KSH_RLIM_INFINITY ((rlim_t) 1 << (sizeof(rlim_t) * 8 - 1) - 1) -#endif /* RLIM_INFINITY */ - int c_ulimit(wp) char **wp; @@ -53,77 +37,27 @@ c_ulimit(wp) char option; } limits[] = { /* Do not use options -H, -S or -a */ -#ifdef RLIMIT_CPU { "time(cpu-seconds)", RLIMIT, RLIMIT_CPU, RLIMIT_CPU, 1, 't' }, -#endif -#ifdef RLIMIT_FSIZE { "file(blocks)", RLIMIT, RLIMIT_FSIZE, RLIMIT_FSIZE, 512, 'f' }, -#else /* RLIMIT_FSIZE */ -# ifdef UL_GETFSIZE /* x/open */ - { "file(blocks)", ULIMIT, UL_GETFSIZE, UL_SETFSIZE, 1, 'f' }, -# else /* UL_GETFSIZE */ -# ifdef UL_GFILLIM /* svr4/xenix */ - { "file(blocks)", ULIMIT, UL_GFILLIM, UL_SFILLIM, 1, 'f' }, -# else /* UL_GFILLIM */ - { "file(blocks)", ULIMIT, 1, 2, 1, 'f' }, -# endif /* UL_GFILLIM */ -# endif /* UL_GETFSIZE */ -#endif /* RLIMIT_FSIZE */ -#ifdef RLIMIT_CORE { "coredump(blocks)", RLIMIT, RLIMIT_CORE, RLIMIT_CORE, 512, 'c' }, -#endif -#ifdef RLIMIT_DATA { "data(kbytes)", RLIMIT, RLIMIT_DATA, RLIMIT_DATA, 1024, 'd' }, -#endif -#ifdef RLIMIT_STACK { "stack(kbytes)", RLIMIT, RLIMIT_STACK, RLIMIT_STACK, 1024, 's' }, -#endif -#ifdef RLIMIT_MEMLOCK { "lockedmem(kbytes)", RLIMIT, RLIMIT_MEMLOCK, RLIMIT_MEMLOCK, 1024, 'l' }, -#endif -#ifdef RLIMIT_RSS { "memory(kbytes)", RLIMIT, RLIMIT_RSS, RLIMIT_RSS, 1024, 'm' }, -#endif -#ifdef RLIMIT_NOFILE { "nofiles(descriptors)", RLIMIT, RLIMIT_NOFILE, RLIMIT_NOFILE, 1, 'n' }, -#else /* RLIMIT_NOFILE */ -# ifdef UL_GDESLIM /* svr4/xenix */ - { "nofiles(descriptors)", ULIMIT, UL_GDESLIM, -1, 1, 'n' }, -# endif /* UL_GDESLIM */ -#endif /* RLIMIT_NOFILE */ -#ifdef RLIMIT_NPROC { "processes", RLIMIT, RLIMIT_NPROC, RLIMIT_NPROC, 1, 'p' }, -#endif #ifdef RLIMIT_VMEM { "vmemory(kbytes)", RLIMIT, RLIMIT_VMEM, RLIMIT_VMEM, 1024, 'v' }, -#else /* RLIMIT_VMEM */ - /* These are not quite right - really should subtract etext or something */ -# ifdef UL_GMEMLIM /* svr4/xenix */ - { "vmemory(maxaddr)", ULIMIT, UL_GMEMLIM, -1, 1, 'v' }, -# else /* UL_GMEMLIM */ -# ifdef UL_GETBREAK /* osf/1 */ - { "vmemory(maxaddr)", ULIMIT, UL_GETBREAK, -1, 1, 'v' }, -# else /* UL_GETBREAK */ -# ifdef UL_GETMAXBRK /* hpux */ - { "vmemory(maxaddr)", ULIMIT, UL_GETMAXBRK, -1, 1, 'v' }, -# endif /* UL_GETMAXBRK */ -# endif /* UL_GETBREAK */ -# endif /* UL_GMEMLIM */ #endif /* RLIMIT_VMEM */ -#ifdef RLIMIT_SWAP - { "swap(kbytes)", RLIMIT_SWAP, RLIMIT_SWAP, 1024, 'w' }, -#endif { (char *) 0 } }; static char options[3 + NELEM(limits)]; - rlim_t UNINITIALIZED(val); + rlim_t val = 0; int how = SOFT | HARD; const struct limits *l; int set, all = 0; int optc, what; -#ifdef HAVE_SETRLIMIT struct rlimit limit; -#endif /* HAVE_SETRLIMIT */ if (!options[0]) { /* build options string on first call - yuck */ @@ -167,7 +101,7 @@ c_ulimit(wp) return 1; } if (strcmp(wp[0], "unlimited") == 0) - val = KSH_RLIM_INFINITY; + val = RLIM_INFINITY; else { long rval; @@ -189,28 +123,17 @@ c_ulimit(wp) } if (all) { for (l = limits; l->name; l++) { -#ifdef HAVE_SETRLIMIT if (l->which == RLIMIT) { getrlimit(l->gcmd, &limit); if (how & SOFT) val = limit.rlim_cur; else if (how & HARD) val = limit.rlim_max; - } else -#endif /* HAVE_SETRLIMIT */ -#ifdef HAVE_ULIMIT - { - val = ulimit(l->gcmd, (rlim_t) 0); } -#else /* HAVE_ULIMIT */ - ; -#endif /* HAVE_ULIMIT */ shprintf("%-20s ", l->name); -#ifdef RLIM_INFINITY if (val == RLIM_INFINITY) shprintf("unlimited\n"); else -#endif /* RLIM_INFINITY */ { val /= l->factor; shprintf("%ld\n", (long) val); @@ -218,7 +141,6 @@ c_ulimit(wp) } return 0; } -#ifdef HAVE_SETRLIMIT if (l->which == RLIMIT) { getrlimit(l->gcmd, &limit); if (set) { @@ -240,30 +162,11 @@ c_ulimit(wp) else if (how & HARD) val = limit.rlim_max; } - } else -#endif /* HAVE_SETRLIMIT */ -#ifdef HAVE_ULIMIT - { - if (set) { - if (l->scmd == -1) { - bi_errorf("can't change limit"); - return 1; - } else if (ulimit(l->scmd, val) < 0) { - bi_errorf("bad limit: %s", strerror(errno)); - return 1; - } - } else - val = ulimit(l->gcmd, (rlim_t) 0); } -#else /* HAVE_ULIMIT */ - ; -#endif /* HAVE_ULIMIT */ if (!set) { -#ifdef RLIM_INFINITY if (val == RLIM_INFINITY) shprintf("unlimited\n"); else -#endif /* RLIM_INFINITY */ { val /= l->factor; shprintf("%ld\n", (long) val); diff --git a/bin/ksh/conf-end.h b/bin/ksh/conf-end.h deleted file mode 100644 index 8b65cb7d1df..00000000000 --- a/bin/ksh/conf-end.h +++ /dev/null @@ -1,62 +0,0 @@ -/* $OpenBSD: conf-end.h,v 1.2 1996/08/25 12:37:58 downsj Exp $ */ - -/* - * End of configuration stuff for PD ksh. - */ - -#if defined(EMACS) || defined(VI) -# define EDIT -#else -# undef EDIT -#endif - -/* Super small configuration-- no editing. */ -#if defined(EDIT) && defined(NOEDIT) -# undef EDIT -# undef EMACS -# undef VI -#endif - -/* Editing implies history */ -#if defined(EDIT) && !defined(HISTORY) -# define HISTORY -#endif /* EDIT */ - -/* - * if you don't have mmap() you can't use Peter Collinson's history - * mechanism. If that is the case, then define EASY_HISTORY - */ -#if defined(HISTORY) && (!defined(COMPLEX_HISTORY) || !defined(HAVE_MMAP) || !defined(HAVE_FLOCK)) -# undef COMPLEX_HISTORY -# define EASY_HISTORY /* sjg's trivial history file */ -#endif - -/* Can we safely catch sigchld and wait for processes? */ -#if (defined(HAVE_WAITPID) || defined(HAVE_WAIT3)) \ - && (defined(POSIX_SIGNALS) || defined(BSD42_SIGNALS)) -# define JOB_SIGS -#endif - -#if !defined(JOB_SIGS) || !(defined(POSIX_PGRP) || defined(BSD_PGRP)) -# undef JOBS /* if no JOB_SIGS, no job control support */ -#endif - -/* pdksh assumes system calls return EINTR if a signal happened (this so - * the signal handler doesn't have to longjmp()). I don't know if this - * happens (or can be made to happen) with sigset() et. al. (the bsd41 signal - * routines), so, the autoconf stuff checks what they do and defines - * SIGNALS_DONT_INTERRUPT if signals don't interrupt read(). - * If SIGNALS_DONT_INTERRUPT isn't defined and your compiler chokes on this, - * delete the hash in front of the error (and file a bug report). - */ -#ifdef SIGNALS_DONT_INTERRUPT - # error pdksh needs interruptable system calls. -#endif /* SIGNALS_DONT_INTERRUPT */ - -#ifdef HAVE_GCC_FUNC_ATTR -# define GCC_FUNC_ATTR(x) __attribute__((x)) -# define GCC_FUNC_ATTR2(x,y) __attribute__((x,y)) -#else -# define GCC_FUNC_ATTR(x) -# define GCC_FUNC_ATTR2(x,y) -#endif /* HAVE_GCC_FUNC_ATTR */ diff --git a/bin/ksh/config.h b/bin/ksh/config.h index 8a8ef7227e7..7c6d96ece92 100644 --- a/bin/ksh/config.h +++ b/bin/ksh/config.h @@ -1,9 +1,9 @@ -/* $OpenBSD: config.h,v 1.10 2004/02/08 19:18:15 deraadt Exp $ */ +/* $OpenBSD: config.h,v 1.11 2004/12/18 20:55:52 millert Exp $ */ /* config.h. NOT generated automatically. */ /* - * This file, acconfig.h, which is a part of pdksh (the public domain ksh), + * This file, config.h, which is a part of pdksh (the public domain ksh), * is placed in the public domain. It comes with no licence, warranty * or guarantee of any kind (i.e., at your own risk). */ @@ -11,194 +11,12 @@ #ifndef CONFIG_H #define CONFIG_H -/* Define if on AIX 3. - System headers sometimes define this. - We just want to avoid a redefinition error message. */ -#ifndef _ALL_SOURCE -/* #undef _ALL_SOURCE */ -#endif - -/* Define if the closedir function returns void instead of int. */ -/* #undef CLOSEDIR_VOID */ - -/* Define to empty if the keyword does not work. */ -/* #undef const */ - -/* Define to `int' if <sys/types.h> doesn't define. */ -/* #undef gid_t */ - -/* Define if you have a working `mmap' system call. */ -#define HAVE_MMAP 1 - -/* Define if your struct stat has st_rdev. */ -#define HAVE_ST_RDEV 1 - -/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define if you have <unistd.h>. */ -#define HAVE_UNISTD_H 1 - -/* Define if on MINIX. */ -/* #undef _MINIX */ - -/* Define to `int' if <sys/types.h> doesn't define. */ -/* #undef mode_t */ - -/* Define to `long' if <sys/types.h> doesn't define. */ -/* #undef off_t */ - -/* Define to `int' if <sys/types.h> doesn't define. */ -/* #undef pid_t */ - -/* Define if the system does not provide POSIX.1 features except - with this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define if you need to in order for stat and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* Define as the return type of signal handlers (int or void). */ -#define RETSIGTYPE void - -/* Define if the `S_IS*' macros in <sys/stat.h> do not work properly. */ -/* #undef STAT_MACROS_BROKEN */ - -/* Define if `sys_siglist' is declared by <signal.h>. */ -#define SYS_SIGLIST_DECLARED 1 - -/* Define if you can safely include both <sys/time.h> and <time.h>. */ -#define TIME_WITH_SYS_TIME 1 - -/* Define to `int' if <sys/types.h> doesn't define. */ -/* #undef uid_t */ - -/* Define if the closedir function returns void instead of int. */ -/* #undef VOID_CLOSEDIR */ - -/* Define if your kernel doesn't handle scripts starting with #! */ -/* #undef SHARPBANG */ - -/* Define if dup2() preserves the close-on-exec flag (ultrix does this) */ -/* #undef DUP2_BROKEN */ - -/* Define as the return value of signal handlers (0 or ). */ -#define RETSIGVAL - -/* Define if you have posix signal routines (sigaction(), et. al.) */ -#define POSIX_SIGNALS 1 - -/* Define if you have BSD4.2 signal routines (sigsetmask(), et. al.) */ -/* #undef BSD42_SIGNALS */ -/* Define if you have BSD4.1 signal routines (sigset(), et. al.) */ -/* #undef BSD41_SIGNALS */ -/* Define if you have v7 signal routines (signal(), signal reset on delivery) */ -/* #undef V7_SIGNALS */ - -/* Define to use the fake posix signal routines (sigact.[ch]) */ -/* #undef USE_FAKE_SIGACT */ - -/* Define if signals don't interrupt read() */ -/* #undef SIGNALS_DONT_INTERRUPT */ - -/* Define if you have bsd versions of the setpgrp() and getpgrp() routines */ -/* #undef BSD_PGRP */ - -/* Define if you have POSIX versions of the setpgid() and getpgrp() routines */ -#define POSIX_PGRP 1 - -/* Define if you have sysV versions of the setpgrp() and getpgrp() routines */ -/* #undef SYSV_PGRP */ - -/* Define if you don't have setpgrp(), setpgid() or getpgrp() routines */ -/* #undef NO_PGRP */ - -/* Define to char if your compiler doesn't like the void keyword */ -/* #undef void */ - -/* Define to nothing if compiler doesn't like the volatile keyword */ -/* #undef volatile */ - -/* Define if C compiler groks function prototypes */ -#define HAVE_PROTOTYPES 1 /* Define if C compiler groks __attribute__((...)) (const, noreturn, format) */ #define HAVE_GCC_FUNC_ATTR 1 -/* Define to 32-bit signed integer type if <sys/types.h> doesn't define */ -/* #undef clock_t */ - -/* Define to the type of struct rlimit fields if the rlim_t type is missing */ -/* #undef rlim_t */ - -/* Define if time() is declared in <time.h> */ -#define TIME_DECLARED 1 - -/* Define to `unsigned' if <signal.h> doesn't define */ -/* #undef sigset_t */ - -/* Define if sys_errlist[] and sys_nerr are in the C library */ -#define HAVE_SYS_ERRLIST 1 - -/* Define if sys_errlist[] and sys_nerr are defined in <errno.h> */ -#define SYS_ERRLIST_DECLARED 1 - -/* Define if sys_siglist[] is in the C library */ -#define HAVE_SYS_SIGLIST 1 - -/* Define if you have a sane <termios.h> header file */ -#define HAVE_TERMIOS_H 1 - -/* Define if you have a memset() function in your C library */ -#define HAVE_MEMSET 1 - -/* Define if you have a memmove() function in your C library */ -#define HAVE_MEMMOVE 1 - -/* Define if you have a bcopy() function in your C library */ -/* #undef HAVE_BCOPY */ - -/* Define if you have a lstat() function in your C library */ -#define HAVE_LSTAT 1 - -/* Define if you have a sane <termio.h> header file */ -/* #undef HAVE_TERMIO_H */ - -/* Define if you don't have times() or if it always returns 0 */ -/* #undef TIMES_BROKEN */ - -/* Define if opendir() will open non-directory files */ -/* #undef OPENDIR_DOES_NONDIR */ - -/* Define if you have a dup2() function in your C library */ -#define HAVE_DUP2 1 - -/* Define if the pgrp of setpgrp() can't be the pid of a zombie process */ -/* #undef NEED_PGRP_SYNC */ - -/* Define if you arg running SCO unix */ -/* #undef OS_SCO */ - -/* Define if you arg running ISC unix */ -/* #undef OS_ISC */ - -/* Define if you arg running OS2 with the EMX library */ -/* #undef OS2 */ - -/* Define if you have a POSIX.1 compatible <sys/wait.h> */ -#define POSIX_SYS_WAIT 1 - -/* Define if your OS maps references to /dev/fd/n to file descriptor n */ -#define HAVE_DEV_FD 1 - -/* Default PATH */ -#define DEFAULT_PATH "/bin:/usr/bin:/sbin:/usr/sbin" - -/* Define if your C library's getwd/getcwd function dumps core in unreadable - * directories. */ -/* #undef HPUX_GETWD_BUG */ /* Include ksh features? */ /* #define KSH 1 */ @@ -218,141 +36,46 @@ /* Include any history? */ #define HISTORY 1 -/* Include complex history? */ -#define COMPLEX_HISTORY - /* Strict POSIX behaviour? */ /* #undef POSIXLY_CORRECT */ /* Specify default $ENV? */ /* #undef DEFAULT_ENV */ -/* Include shl(1) support? */ -/* #undef SWTCH */ - /* Include game-of-life? */ /* #undef SILLY */ /* The number of bytes in a int. */ #define SIZEOF_INT 4 -/* Define if you have the _setjmp function. */ -/* #undef HAVE__SETJMP */ - -/* Define if you have the confstr function. */ -#define HAVE_CONFSTR 1 - -/* Define if you have the flock function. */ -#define HAVE_FLOCK 1 - -/* Define if you have the getcwd function. */ -#define HAVE_GETCWD 1 - -/* Define if you have the getgroups function. */ -/* #undef HAVE_GETGROUPS */ - -/* Define if you have the getpagesize function. */ -#define HAVE_GETPAGESIZE 1 - -/* Define if you have the getrusage function. */ -/* #undef HAVE_GETRUSAGE */ - -/* Define if you have the getwd function. */ -#define HAVE_GETWD 1 - -/* Define if you have the killpg function. */ -#define HAVE_KILLPG 1 - -/* Define if you have the nice function. */ -#define HAVE_NICE 1 - -/* Define if you have the setrlimit function. */ -#define HAVE_SETRLIMIT 1 - -/* Define if you have the sigsetjmp function. */ -#define HAVE_SIGSETJMP 1 - -/* Define if you have the strcasecmp function. */ -#define HAVE_STRCASECMP 1 - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strstr function. */ -#define HAVE_STRSTR 1 - -/* Define if you have the sysconf function. */ -#define HAVE_SYSCONF 1 - -/* Define if you have the tcsetpgrp function. */ -#define HAVE_TCSETPGRP 1 - -/* Define if you have the ulimit function. */ -/* #undef HAVE_ULIMIT */ - -/* Define if you have the valloc function. */ -#define HAVE_VALLOC 1 - -/* Define if you have the wait3 function. */ -#define HAVE_WAIT3 1 - -/* Define if you have the waitpid function. */ -#define HAVE_WAITPID 1 - -/* Define if you have the <dirent.h> header file. */ -#define HAVE_DIRENT_H 1 - -/* Define if you have the <fcntl.h> header file. */ -#define HAVE_FCNTL_H 1 - -/* Define if you have the <limits.h> header file. */ -#define HAVE_LIMITS_H 1 - -/* Define if you have the <memory.h> header file. */ -#define HAVE_MEMORY_H 1 - -/* Define if you have the <ndir.h> header file. */ -/* #undef HAVE_NDIR_H */ - -/* Define if you have the <paths.h> header file. */ -#define HAVE_PATHS_H 1 - -/* Define if you have the <stddef.h> header file. */ -#define HAVE_STDDEF_H 1 - -/* Define if you have the <stdlib.h> header file. */ -#define HAVE_STDLIB_H 1 - -/* Define if you have the <string.h> header file. */ -#define HAVE_STRING_H 1 - -/* Define if you have the <sys/dir.h> header file. */ -/* #undef HAVE_SYS_DIR_H */ - -/* Define if you have the <sys/ndir.h> header file. */ -/* #undef HAVE_SYS_NDIR_H */ - -/* Define if you have the <sys/param.h> header file. */ -#define HAVE_SYS_PARAM_H 1 - -/* Define if you have the <sys/resource.h> header file. */ -#define HAVE_SYS_RESOURCE_H 1 - -/* Define if you have the <sys/time.h> header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define if you have the <sys/wait.h> header file. */ -#define HAVE_SYS_WAIT_H 1 +/* + * End of configuration stuff for PD ksh. + */ -/* Define if you have the <ulimit.h> header file. */ -/* #undef HAVE_ULIMIT_H */ +#if defined(EMACS) || defined(VI) +# define EDIT +#else +# undef EDIT +#endif -/* Define if you have the <values.h> header file. */ -/* #undef HAVE_VALUES_H */ +/* Super small configuration-- no editing. */ +#if defined(EDIT) && defined(NOEDIT) +# undef EDIT +# undef EMACS +# undef VI +#endif -/* Need to use a separate file to keep the configure script from commenting - * out the undefs.... - */ -#include "conf-end.h" +/* Editing implies history */ +#if defined(EDIT) && !defined(HISTORY) +# define HISTORY +#endif /* EDIT */ + +#ifdef HAVE_GCC_FUNC_ATTR +# define GCC_FUNC_ATTR(x) __attribute__((x)) +# define GCC_FUNC_ATTR2(x,y) __attribute__((x,y)) +#else +# define GCC_FUNC_ATTR(x) +# define GCC_FUNC_ATTR2(x,y) +#endif /* HAVE_GCC_FUNC_ATTR */ #endif /* CONFIG_H */ diff --git a/bin/ksh/edit.c b/bin/ksh/edit.c index 4076ac2bf0a..a4e7f3feab2 100644 --- a/bin/ksh/edit.c +++ b/bin/ksh/edit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.19 2004/11/04 19:20:07 deraadt Exp $ */ +/* $OpenBSD: edit.c,v 1.20 2004/12/18 20:55:52 millert Exp $ */ /* * Command line editing - common code @@ -13,28 +13,22 @@ #define EXTERN #include "edit.h" #undef EXTERN -#ifdef OS_SCO /* SCO Unix 3.2v4.1 */ -# include <sys/stream.h> /* needed for <sys/ptem.h> */ -# include <sys/ptem.h> /* needed for struct winsize */ -#endif /* OS_SCO */ #include <sys/ioctl.h> #include <ctype.h> #include <libgen.h> -#include "ksh_stat.h" +#include <sys/stat.h> -#if defined(TIOCGWINSZ) -static RETSIGTYPE x_sigwinch ARGS((int sig)); +static void x_sigwinch(int sig); static int got_sigwinch; -static void check_sigwinch ARGS((void)); -#endif /* TIOCGWINSZ */ +static void check_sigwinch(void); -static int x_file_glob ARGS((int flags, const char *str, int slen, - char ***wordsp)); -static int x_command_glob ARGS((int flags, const char *str, int slen, - char ***wordsp)); -static int x_locate_word ARGS((const char *buf, int buflen, int pos, - int *startp, int *is_command)); +static int x_file_glob(int flags, const char *str, int slen, + char ***wordsp); +static int x_command_glob(int flags, const char *str, int slen, + char ***wordsp); +static int x_locate_word(const char *buf, int buflen, int pos, + int *startp, int *is_command); static char vdisable_c; @@ -49,48 +43,27 @@ x_init() /* default value for deficient systems */ edchars.werase = 027; /* ^W */ -#ifdef TIOCGWINSZ -# ifdef SIGWINCH if (setsig(&sigtraps[SIGWINCH], x_sigwinch, SS_RESTORE_ORIG|SS_SHTRAP)) sigtraps[SIGWINCH].flags |= TF_SHELL_USES; -# endif /* SIGWINCH */ got_sigwinch = 1; /* force initial check */ check_sigwinch(); -#endif /* TIOCGWINSZ */ #ifdef EMACS x_init_emacs(); #endif /* EMACS */ - /* Bizarreness to figure out how to disable - * a struct termios.c_cc[] char - */ -#ifdef _POSIX_VDISABLE - if (_POSIX_VDISABLE >= 0) - vdisable_c = (char) _POSIX_VDISABLE; - else - /* `feature not available' */ - vdisable_c = (char) 0377; -#else -# if defined(HAVE_PATHCONF) && defined(_PC_VDISABLE) - vdisable_c = fpathconf(tty_fd, _PC_VDISABLE); -# else - vdisable_c = (char) 0377; /* default to old BSD value */ -# endif -#endif /* _POSIX_VDISABLE */ + vdisable_c = (char) _POSIX_VDISABLE; } -#if defined(TIOCGWINSZ) -static RETSIGTYPE +static void x_sigwinch(sig) int sig; { got_sigwinch = 1; - return RETSIGVAL; } static void -check_sigwinch ARGS((void)) +check_sigwinch(void) { if (got_sigwinch) { struct winsize ws; @@ -118,7 +91,6 @@ check_sigwinch ARGS((void)) } } } -#endif /* TIOCGWINSZ */ /* * read an edited command line @@ -130,10 +102,8 @@ x_read(buf, len) { int i; -#if defined(TIOCGWINSZ) if (got_sigwinch) check_sigwinch(); -#endif /* TIOCGWINSZ */ x_mode(TRUE); #ifdef EMACS @@ -156,10 +126,6 @@ x_read(buf, len) int x_getc() { -#ifdef OS2 - unsigned char c = _read_kbd(0, 1, 0); - return c == 0 ? 0xE0 : c; -#else /* OS2 */ char c; int n; @@ -172,7 +138,6 @@ x_getc() if (n != 1) return -1; return (int) (unsigned char) c; -#endif /* OS2 */ } void @@ -215,84 +180,23 @@ x_mode(onoff) oldchars = edchars; cb = tty_state; -#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H) edchars.erase = cb.c_cc[VERASE]; edchars.kill = cb.c_cc[VKILL]; edchars.intr = cb.c_cc[VINTR]; edchars.quit = cb.c_cc[VQUIT]; edchars.eof = cb.c_cc[VEOF]; -# ifdef VWERASE edchars.werase = cb.c_cc[VWERASE]; -# endif -# ifdef _CRAY2 /* brain-damaged terminal handler */ - cb.c_lflag &= ~(ICANON|ECHO); - /* rely on print routine to map '\n' to CR,LF */ -# else cb.c_iflag &= ~(INLCR|ICRNL); -# ifdef _BSD_SYSV /* need to force CBREAK instead of RAW (need CRMOD on output) */ - cb.c_lflag &= ~(ICANON|ECHO); -# else -# ifdef SWTCH /* need CBREAK to handle swtch char */ - cb.c_lflag &= ~(ICANON|ECHO); - cb.c_lflag |= ISIG; - cb.c_cc[VINTR] = vdisable_c; - cb.c_cc[VQUIT] = vdisable_c; -# else cb.c_lflag &= ~(ISIG|ICANON|ECHO); -# endif -# endif -# ifdef VLNEXT /* osf/1 processes lnext when ~icanon */ cb.c_cc[VLNEXT] = vdisable_c; -# endif /* VLNEXT */ -# ifdef VDISCARD /* sunos 4.1.x & osf/1 processes discard(flush) when ~icanon */ cb.c_cc[VDISCARD] = vdisable_c; -# endif /* VDISCARD */ cb.c_cc[VTIME] = 0; cb.c_cc[VMIN] = 1; -# endif /* _CRAY2 */ -#else - /* Assume BSD tty stuff. */ - edchars.erase = cb.sgttyb.sg_erase; - edchars.kill = cb.sgttyb.sg_kill; - cb.sgttyb.sg_flags &= ~ECHO; - cb.sgttyb.sg_flags |= CBREAK; -# ifdef TIOCGATC - edchars.intr = cb.lchars.tc_intrc; - edchars.quit = cb.lchars.tc_quitc; - edchars.eof = cb.lchars.tc_eofc; - edchars.werase = cb.lchars.tc_werasc; - cb.lchars.tc_suspc = -1; - cb.lchars.tc_dsuspc = -1; - cb.lchars.tc_lnextc = -1; - cb.lchars.tc_statc = -1; - cb.lchars.tc_intrc = -1; - cb.lchars.tc_quitc = -1; - cb.lchars.tc_rprntc = -1; -# else - edchars.intr = cb.tchars.t_intrc; - edchars.quit = cb.tchars.t_quitc; - edchars.eof = cb.tchars.t_eofc; - cb.tchars.t_intrc = -1; - cb.tchars.t_quitc = -1; -# ifdef TIOCGLTC - edchars.werase = cb.ltchars.t_werasc; - cb.ltchars.t_suspc = -1; - cb.ltchars.t_dsuspc = -1; - cb.ltchars.t_lnextc = -1; - cb.ltchars.t_rprntc = -1; -# endif -# endif /* TIOCGATC */ -#endif /* HAVE_TERMIOS_H || HAVE_TERMIO_H */ set_tty(tty_fd, &cb, TF_WAIT); -#ifdef __CYGWIN__ - if (edchars.eof == '\0') - edchars.eof = '\4'; -#endif /* __CYGWIN__ */ - /* Convert unset values to internal `unset' value */ if (edchars.erase == vdisable_c) edchars.erase = -1; @@ -334,7 +238,7 @@ set_editmode(ed) char *rcp; int i; - if ((rcp = ksh_strrchr_dirsep(ed))) + if ((rcp = strrchr(ed, '/'))) ed = ++rcp; for (i = 0; i < NELEM(edit_flags); i++) if (strstr(ed, options[(int) edit_flags[i]].name)) { @@ -402,14 +306,14 @@ x_do_comment(buf, bsize, lenp) /* Common file/command completion code for vi/emacs */ -static char *add_glob ARGS((const char *str, int slen)); -static void glob_table ARGS((const char *pat, XPtrV *wp, struct table *tp)); -static void glob_path ARGS((int flags, const char *pat, XPtrV *wp, - const char *path)); +static char *add_glob(const char *str, int slen); +static void glob_table(const char *pat, XPtrV *wp, struct table *tp); +static void glob_path(int flags, const char *pat, XPtrV *wp, + const char *path); #if 0 /* not used... */ -int x_complete_word ARGS((const char *str, int slen, int is_command, - int *multiple, char **ret)); +int x_complete_word(const char *str, int slen, int is_command, + int *multiple, char **ret); int x_complete_word(str, slen, is_command, nwordsp, ret) const char *str; @@ -466,7 +370,7 @@ x_print_expansions(nwords, words, is_command) /* All in same directory? */ if (i == nwords) { while (prefix_len > 0 - && !ISDIRSEP(words[0][prefix_len - 1])) + && words[0][prefix_len - 1] != '/') prefix_len--; use_copy = 1; XPinit(l, nwords + 1); @@ -590,7 +494,7 @@ path_order_cmp(aa, bb) const struct path_order_info *b = (const struct path_order_info *) bb; int t; - t = FILECMP(a->word + a->base, b->word + b->base); + t = strcmp(a->word + a->base, b->word + b->base); return t ? t : a->path_order - b->path_order; } @@ -652,7 +556,7 @@ x_command_glob(flags, str, slen, wordsp) info[i].word = words[i]; info[i].base = x_basename(words[i], (char *) 0); if (!last_info || info[i].base != last_info->base - || FILENCMP(words[i], + || strncmp(words[i], last_info->word, info[i].base) != 0) { last_info = &info[i]; @@ -737,7 +641,7 @@ x_locate_word(buf, buflen, pos, startp, is_commandp) * like file globbing. */ for (p = start; p < end; p++) - if (ISDIRSEP(buf[p])) + if (buf[p] == '/') break; iscmd = p == end; } @@ -820,7 +724,7 @@ add_glob(str, slen) else if (*s == '*' || *s == '[' || *s == '?' || *s == '$' || (s[1] == '(' /*)*/ && strchr("*+?@!", *s))) break; - else if (ISDIRSEP(*s)) + else if (*s == '/') saw_slash = TRUE; } if (!*s && (*toglob != '~' || saw_slash)) { @@ -849,7 +753,7 @@ x_longest_prefix(nwords, words) prefix_len = strlen(words[0]); for (i = 1; i < nwords; i++) for (j = 0, p = words[i]; j < prefix_len; j++) - if (FILECHCONV(p[j]) != FILECHCONV(words[0][j])) { + if (p[j] != words[0][j]) { prefix_len = j; break; } @@ -894,11 +798,11 @@ x_basename(s, se) return 0; /* Skip trailing slashes */ - for (p = se - 1; p > s && ISDIRSEP(*p); p--) + for (p = se - 1; p > s && *p == '/'; p--) ; - for (; p > s && !ISDIRSEP(*p); p--) + for (; p > s && *p != '/'; p--) ; - if (ISDIRSEP(*p) && p + 1 < se) + if (*p == '/' && p + 1 < se) p++; return p - s; @@ -944,7 +848,7 @@ glob_path(flags, pat, wp, path) Xinit(xs, xp, patlen + 128, ATEMP); while (sp) { xp = Xstring(xs, xp); - if (!(p = strchr(sp, PATHSEP))) + if (!(p = strchr(sp, ':'))) p = sp + strlen(sp); pathlen = p - sp; if (pathlen) { @@ -959,7 +863,7 @@ glob_path(flags, pat, wp, path) *xp++ = MAGIC; *xp++ = *s++; } - *xp++ = DIRSEP; + *xp++ = '/'; pathlen++; } sp = p; @@ -1001,7 +905,7 @@ int x_escape(s, len, putbuf_func) const char *s; size_t len; - int putbuf_func ARGS((const char *s, size_t len)); + int putbuf_func(const char *s, size_t len); { size_t add, wlen; const char *ifs = str_val(local("IFS", 0)); diff --git a/bin/ksh/edit.h b/bin/ksh/edit.h index d8f3641d399..1928a0fb97b 100644 --- a/bin/ksh/edit.h +++ b/bin/ksh/edit.h @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.h,v 1.3 1999/11/14 22:04:02 d Exp $ */ +/* $OpenBSD: edit.h,v 1.4 2004/12/18 20:55:52 millert Exp $ */ /* NAME: * edit.h - globals for edit modes @@ -44,26 +44,26 @@ EXTERN X_chars edchars; #define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE) /* edit.c */ -int x_getc ARGS((void)); -void x_flush ARGS((void)); -void x_putc ARGS((int c)); -void x_puts ARGS((const char *s)); -bool_t x_mode ARGS((bool_t onoff)); -int promptlen ARGS((const char *cp, const char **spp)); -int x_do_comment ARGS((char *buf, int bsize, int *lenp)); -void x_print_expansions ARGS((int nwords, char *const *words, int is_command)); -int x_cf_glob ARGS((int flags, const char *buf, int buflen, int pos, int *startp, - int *endp, char ***wordsp, int *is_commandp)); -int x_longest_prefix ARGS((int nwords, char *const *words)); -int x_basename ARGS((const char *s, const char *se)); -void x_free_words ARGS((int nwords, char **words)); -int x_escape ARGS((const char *, size_t, int (*)(const char *s, size_t len))); +int x_getc(void); +void x_flush(void); +void x_putc(int c); +void x_puts(const char *s); +bool_t x_mode(bool_t onoff); +int promptlen(const char *cp, const char **spp); +int x_do_comment(char *buf, int bsize, int *lenp); +void x_print_expansions(int nwords, char *const *words, int is_command); +int x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp, + int *endp, char ***wordsp, int *is_commandp); +int x_longest_prefix(int nwords, char *const *words); +int x_basename(const char *s, const char *se); +void x_free_words(int nwords, char **words); +int x_escape(const char *, size_t, int (*)(const char *s, size_t len)); /* emacs.c */ -int x_emacs ARGS((char *buf, size_t len)); -void x_init_emacs ARGS((void)); -void x_emacs_keys ARGS((X_chars *ec)); +int x_emacs(char *buf, size_t len); +void x_init_emacs(void); +void x_emacs_keys(X_chars *ec); /* vi.c */ -int x_vi ARGS((char *buf, size_t len)); +int x_vi(char *buf, size_t len); #ifdef DEBUG diff --git a/bin/ksh/emacs-gen.sh b/bin/ksh/emacs-gen.sh index 97449de8fa4..34429d01b36 100644 --- a/bin/ksh/emacs-gen.sh +++ b/bin/ksh/emacs-gen.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: emacs-gen.sh,v 1.1 1996/08/14 06:19:10 downsj Exp $ +# $OpenBSD: emacs-gen.sh,v 1.2 2004/12/18 20:55:52 millert Exp $ case $# in 1) file=$1;; @@ -36,7 +36,7 @@ sed -e '1,/@START-FUNC-TAB@/d' -e '/@END-FUNC-TAB@/,$d' < $file | fname = substr(fname, 1, length(fname) - 1); if (fname != "0") { printf "#define XFUNC_%s %d\n", substr(fname, 3, length(fname) - 2), nfunc; - printf "static int %s ARGS((int c));\n", fname; + printf "static int %s (int c);\n", fname; nfunc++; } }' || exit 1 diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c index afa8a65975f..785217f2795 100644 --- a/bin/ksh/emacs.c +++ b/bin/ksh/emacs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emacs.c,v 1.28 2003/10/22 07:40:38 jmc Exp $ */ +/* $OpenBSD: emacs.c,v 1.29 2004/12/18 20:55:52 millert Exp $ */ /* * Emacs-like command line editing and history @@ -12,8 +12,7 @@ #ifdef EMACS #include "sh.h" -#include "ksh_stat.h" -#include "ksh_dir.h" +#include <sys/stat.h> #include <ctype.h> #include <locale.h> #include "edit.h" @@ -21,7 +20,6 @@ static Area aedit; #define AEDIT &aedit /* area for kill ring and macro defns */ -#undef CTRL /* _BSD brain damage */ #define CTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F) /* ASCII */ #define UNCTRL(x) ((x) == 0x7F ? '?' : (x) | 0x40) /* ASCII */ #define META(x) ((x) & 0x7f) @@ -34,7 +32,7 @@ static Area aedit; #define KINTR 2 /* ^G, ^C */ struct x_ftab { - int (*xf_func) ARGS((int c)); + int (*xf_func)(int c); const char *xf_name; short xf_flags; }; @@ -56,17 +54,8 @@ struct x_defbindings { #define is_cfs(c) (c == ' ' || c == '\t' || c == '"' || c == '\'') #define is_mfs(c) (!(isalnum(c) || c == '_' || c == '$')) /* Separator for motion */ -#ifdef OS2 - /* Deal with 8 bit chars & an extra prefix for function key (these two - * changes increase memory usage from 9,216 bytes to 24,416 bytes...) - */ -# define CHARMASK 0xFF /* 8-bit ASCII character mask */ -# define X_NTABS 4 /* normal, meta1, meta2, meta3 */ -static int x_prefix3 = 0xE0; -#else /* OS2 */ # define CHARMASK 0xFF /* 8-bit character mask */ # define X_NTABS 3 /* normal, meta1, meta2 */ -#endif /* OS2 */ #define X_TABSZ (CHARMASK+1) /* size of keydef tables etc */ /* Arguments for do_complete() @@ -120,34 +109,34 @@ static int x_curprefix; static char *macroptr; static int prompt_skip; -static int x_ins ARGS((char *cp)); -static void x_delete ARGS((int nc, int push)); -static int x_bword ARGS((void)); -static int x_fword ARGS((void)); -static void x_goto ARGS((char *cp)); -static void x_bs ARGS((int c)); -static int x_size_str ARGS((char *cp)); -static int x_size ARGS((int c)); -static void x_zots ARGS((char *str)); -static void x_zotc ARGS((int c)); -static void x_load_hist ARGS((char **hp)); -static int x_search ARGS((char *pat, int sameline, int offset)); -static int x_match ARGS((char *str, char *pat)); -static void x_redraw ARGS((int limit)); -static void x_push ARGS((int nchars)); -static char * x_mapin ARGS((const char *cp)); -static char * x_mapout ARGS((int c)); -static void x_print ARGS((int prefix, int key)); -static void x_adjust ARGS((void)); -static void x_e_ungetc ARGS((int c)); -static int x_e_getc ARGS((void)); -static void x_e_putc ARGS((int c)); -static void x_e_puts ARGS((const char *s)); -static int x_comment ARGS((int c)); -static int x_fold_case ARGS((int c)); -static char *x_lastcp ARGS((void)); -static void do_complete ARGS((int flags, Comp_type type)); -static int x_emacs_putbuf ARGS((const char *s, size_t len)); +static int x_ins(char *cp); +static void x_delete(int nc, int push); +static int x_bword(void); +static int x_fword(void); +static void x_goto(char *cp); +static void x_bs(int c); +static int x_size_str(char *cp); +static int x_size(int c); +static void x_zots(char *str); +static void x_zotc(int c); +static void x_load_hist(char **hp); +static int x_search(char *pat, int sameline, int offset); +static int x_match(char *str, char *pat); +static void x_redraw(int limit); +static void x_push(int nchars); +static char * x_mapin(const char *cp); +static char * x_mapout(int c); +static void x_print(int prefix, int key); +static void x_adjust(void); +static void x_e_ungetc(int c); +static int x_e_getc(void); +static void x_e_putc(int c); +static void x_e_puts(const char *s); +static int x_comment(int c); +static int x_fold_case(int c); +static char *x_lastcp(void); +static void do_complete(int flags, Comp_type type); +static int x_emacs_putbuf(const char *s, size_t len); /* The lines between START-FUNC-TAB .. END-FUNC-TAB are run through a @@ -227,11 +216,7 @@ static const struct x_ftab x_ftab[] = { #else { 0, 0, 0 }, #endif -#ifdef OS2 - { x_meta3, "prefix-3", XF_PREFIX }, -#else { 0, 0, 0 }, -#endif /* @END-FUNC-TAB@ */ }; @@ -270,7 +255,7 @@ static struct x_defbindings const x_defbindings[] = { { XFUNC_meta_yank, 1, 'y' }, { XFUNC_literal, 0, CTRL('^') }, { XFUNC_comment, 1, '#' }, -#if defined(BRL) && defined(TIOCSTI) +#if defined(TIOCSTI) { XFUNC_stuff, 0, CTRL('T') }, #else { XFUNC_transpose, 0, CTRL('T') }, @@ -309,13 +294,6 @@ static struct x_defbindings const x_defbindings[] = { { XFUNC_fold_lower, 1, 'l' }, { XFUNC_fold_capitalize, 1, 'C' }, { XFUNC_fold_capitalize, 1, 'c' }, -#ifdef OS2 - { XFUNC_meta3, 0, 0xE0 }, - { XFUNC_mv_back, 3, 'K' }, - { XFUNC_mv_forw, 3, 'M' }, - { XFUNC_next_com, 3, 'P' }, - { XFUNC_prev_com, 3, 'H' }, -#endif /* OS2 */ /* These for ansi arrow keys: arguablely shouldn't be here by * default, but its simpler/faster/smaller than using termcap * entries. @@ -1197,16 +1175,6 @@ x_meta2(c) return KSTD; } -#ifdef OS2 -static int -x_meta3(c) - int c; -{ - x_curprefix = 3; - return KSTD; -} -#endif /* OS2 */ - static int x_kill(c) int c; @@ -1323,7 +1291,7 @@ static int x_stuff(c) int c; { -#if 0 || defined TIOCSTI +#ifdef TIOCSTI char ch = c; bool_t savmode = x_mode(FALSE); @@ -1345,11 +1313,6 @@ x_mapin(cp) /* XXX -- should handle \^ escape? */ if (*cp == '^') { cp++; -#ifdef OS2 - if (*cp == '0') /* To define function keys */ - *op++ = 0xE0; - else -#endif /* OS2 */ if (*cp >= '?') /* includes '?'; ASCII */ *op++ = CTRL(*cp); else { @@ -1372,12 +1335,6 @@ x_mapout(c) static char buf[8]; register char *p = buf; -#ifdef OS2 - if (c == 0xE0) { - *p++ = '^'; - *p++ = '0'; - } else -#endif /* OS2 */ if (iscntrl(c)) { *p++ = '^'; *p++ = UNCTRL(c); @@ -1395,10 +1352,6 @@ x_print(prefix, key) shprintf("%s", x_mapout(x_prefix1)); if (prefix == 2) shprintf("%s", x_mapout(x_prefix2)); -#ifdef OS2 - if (prefix == 3) - shprintf("%s", x_mapout(x_prefix3)); -#endif /* OS2 */ shprintf("%s = ", x_mapout(key)); if (x_tab[prefix][key] != XFUNC_ins_string) shprintf("%s\n", x_ftab[x_tab[prefix][key]].xf_name); @@ -1451,10 +1404,6 @@ x_bind(a1, a2, macro, list) prefix = 1; else if (x_tab[prefix][key] == XFUNC_meta2) prefix = 2; -#ifdef OS2 - else if (x_tab[prefix][key] == XFUNC_meta3) - prefix = 3; -#endif /* OS2 */ else break; } @@ -1833,7 +1782,7 @@ do_complete(flags, type) completed = 1; } /* add space if single non-dir match */ - if ((nwords == 1) && (!ISDIRSEP(words[0][nlen - 1]))) { + if (nwords == 1 && words[0][nlen - 1] != '/') { x_ins(space); completed = 1; } diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c index f8ebe29371b..8195d7ffcc2 100644 --- a/bin/ksh/eval.c +++ b/bin/ksh/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.18 2004/12/13 16:37:06 millert Exp $ */ +/* $OpenBSD: eval.c,v 1.19 2004/12/18 20:55:52 millert Exp $ */ /* * Expansion - quoting, separation, substitution, globbing @@ -6,8 +6,8 @@ #include "sh.h" #include <pwd.h> -#include "ksh_dir.h" -#include "ksh_stat.h" +#include <dirent.h> +#include <sys/stat.h> /* * string expansion @@ -41,19 +41,19 @@ typedef struct Expand { #define IFS_WS 1 /* have seen IFS white-space */ #define IFS_NWS 2 /* have seen IFS non-white-space */ -static int varsub ARGS((Expand *xp, char *sp, char *word, int *stypep, int *slenp)); -static int comsub ARGS((Expand *xp, char *cp)); -static char *trimsub ARGS((char *str, char *pat, int how)); -static void glob ARGS((char *cp, XPtrV *wp, int markdirs)); -static void globit ARGS((XString *xs, char **xpp, char *sp, XPtrV *wp, - int check)); -static char *maybe_expand_tilde ARGS((char *p, XString *dsp, char **dpp, - int isassign)); -static char *tilde ARGS((char *acp)); -static char *homedir ARGS((char *name)); +static int varsub(Expand *xp, char *sp, char *word, int *stypep, int *slenp); +static int comsub(Expand *xp, char *cp); +static char *trimsub(char *str, char *pat, int how); +static void glob(char *cp, XPtrV *wp, int markdirs); +static void globit(XString *xs, char **xpp, char *sp, XPtrV *wp, + int check); +static char *maybe_expand_tilde(char *p, XString *dsp, char **dpp, + int isassign); +static char *tilde(char *acp); +static char *homedir(char *name); #ifdef BRACE_EXPAND -static void alt_expand ARGS((XPtrV *wp, char *start, char *exp_start, - char *end, int fdo)); +static void alt_expand(XPtrV *wp, char *start, char *exp_start, + char *end, int fdo); #endif /* compile and expand word */ @@ -89,17 +89,10 @@ eval(ap, f) return ap; XPinit(w, 32); XPput(w, NULL); /* space for shell name */ -#ifdef SHARPBANG - XPput(w, NULL); /* and space for one arg */ -#endif while (*ap != NULL) expand(*ap++, &w, f); XPput(w, NULL); -#ifdef SHARPBANG - return (char **) XPclose(w) + 2; -#else return (char **) XPclose(w) + 1; -#endif } /* @@ -164,7 +157,7 @@ expand(cp, wp, f) register XPtrV *wp; /* output words */ int f; /* DO* flags */ { - register int UNINITIALIZED(c); + register int c = 0; register int type; /* expansion type */ register int quote = 0; /* quoted */ XString ds; /* destination string */ @@ -173,7 +166,7 @@ expand(cp, wp, f) int doblank; /* field splitting of parameter/command subst */ Expand x; /* expansion variables */ SubType st_head, *st; - int UNINITIALIZED(newlines); /* For trailing newlines in COMSUB */ + int newlines = 0; /* For trailing newlines in COMSUB */ int saw_eq, tilde_ok; int make_magic; size_t len; @@ -651,7 +644,7 @@ expand(cp, wp, f) tilde_ok = 1; } break; - case PATHSEP: /* : */ + case ':': /* : */ /* Note unquoted : for ~ */ if (!(f & DOTEMP_) && (f & DOASNTILDE)) tilde_ok = 1; @@ -1040,12 +1033,10 @@ globit(xs, xpp, sp, wp, check) * SunOS 4.1.3 does this... */ if ((check & GF_EXCHECK) && xp > Xstring(*xs, xp) - && ISDIRSEP(xp[-1]) && !S_ISDIR(lstatb.st_mode) -#ifdef S_ISLNK + && xp[-1] == '/' && !S_ISDIR(lstatb.st_mode) && (!S_ISLNK(lstatb.st_mode) || stat_check() < 0 || !S_ISDIR(statb.st_mode)) -#endif /* S_ISLNK */ ) return; /* Possibly tack on a trailing / if there isn't already @@ -1053,43 +1044,31 @@ globit(xs, xpp, sp, wp, check) * directory */ if (((check & GF_MARKDIR) && (check & GF_GLOBBED)) - && xp > Xstring(*xs, xp) && !ISDIRSEP(xp[-1]) + && xp > Xstring(*xs, xp) && xp[-1] != '/' && (S_ISDIR(lstatb.st_mode) -#ifdef S_ISLNK || (S_ISLNK(lstatb.st_mode) && stat_check() > 0 && S_ISDIR(statb.st_mode)) -#endif /* S_ISLNK */ )) { - *xp++ = DIRSEP; + *xp++ = '/'; *xp = '\0'; } } -#ifdef OS2 /* Done this way to avoid bug in gcc 2.7.2... */ - /* Ugly kludge required for command - * completion - see how search_access() - * is implemented for OS/2... - */ -# define KLUDGE_VAL 4 -#else /* OS2 */ -# define KLUDGE_VAL 0 -#endif /* OS2 */ - XPput(*wp, str_nsave(Xstring(*xs, xp), Xlength(*xs, xp) - + KLUDGE_VAL, ATEMP)); + XPput(*wp, str_nsave(Xstring(*xs, xp), Xlength(*xs, xp), ATEMP)); return; } if (xp > Xstring(*xs, xp)) - *xp++ = DIRSEP; - while (ISDIRSEP(*sp)) { + *xp++ = '/'; + while (*sp == '/') { Xcheck(*xs, xp); *xp++ = *sp++; } - np = ksh_strchr_dirsep(sp); + np = strchr(sp, '/'); if (np != NULL) { se = np; - odirsep = *np; /* don't assume DIRSEP, can be multiple kinds */ + odirsep = *np; /* don't assume '/', can be multiple kinds */ *np++ = '\0'; } else { odirsep = '\0'; /* keep gcc quiet */ @@ -1119,7 +1098,7 @@ globit(xs, xpp, sp, wp, check) /* xp = *xpp; copy_non_glob() may have re-alloc'd xs */ *xp = '\0'; prefix_len = Xlength(*xs, xp); - dirp = ksh_opendir(prefix_len ? Xstring(*xs, xp) : "."); + dirp = opendir(prefix_len ? Xstring(*xs, xp) : "."); if (dirp == NULL) goto Nodir; while ((d = readdir(dirp)) != NULL) { @@ -1131,7 +1110,7 @@ globit(xs, xpp, sp, wp, check) || !gmatch(name, sp, TRUE)) continue; - len = NLENGTH(d) + 1; + len = strlen(d->d_name) + 1; XcheckN(*xs, xp, len); memcpy(xp, name, len); *xpp = xp + len - 1; @@ -1152,7 +1131,7 @@ globit(xs, xpp, sp, wp, check) /* Check if p contains something that needs globbing; if it does, 0 is * returned; if not, p is copied into xs/xp after stripping any MAGICs */ -static int copy_non_glob ARGS((XString *xs, char **xpp, char *p)); +static int copy_non_glob(XString *xs, char **xpp, char *p); static int copy_non_glob(xs, xpp, p) XString *xs; @@ -1239,8 +1218,7 @@ maybe_expand_tilde(p, dsp, dpp, isassign) Xinit(ts, tp, 16, ATEMP); /* : only for DOASNTILDE form */ - while (p[0] == CHAR && !ISDIRSEP(p[1]) - && (!isassign || p[1] != PATHSEP)) + while (p[0] == CHAR && p[1] != '/' && (!isassign || p[1] != ':')) { Xcheck(ts, tp); *tp++ = p[1]; @@ -1303,10 +1281,6 @@ homedir(name) ap = tenter(&homedirs, name, hash(name)); if (!(ap->flag & ISSET)) { -#ifdef OS2 - /* No usernames in OS2 - punt */ - return NULL; -#else /* OS2 */ struct passwd *pw; pw = getpwnam(name); @@ -1314,7 +1288,6 @@ homedir(name) return NULL; ap->val.s = str_save(pw->pw_dir, APERM); ap->flag |= DEFINED|ISSET|ALLOC; -#endif /* OS2 */ } return ap->val.s; } @@ -1327,8 +1300,8 @@ alt_expand(wp, start, exp_start, end, fdo) char *end; int fdo; { - int UNINITIALIZED(count); - char *brace_start, *brace_end, *UNINITIALIZED(comma); + int count = 0; + char *brace_start, *brace_end, *comma = NULL; char *field_start; char *p; diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c index 0989dc2b095..a210a960f9d 100644 --- a/bin/ksh/exec.c +++ b/bin/ksh/exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.c,v 1.31 2003/12/15 05:25:52 otto Exp $ */ +/* $OpenBSD: exec.c,v 1.32 2004/12/18 20:55:52 millert Exp $ */ /* * execute command tree @@ -7,7 +7,7 @@ #include "sh.h" #include "c_test.h" #include <ctype.h> -#include "ksh_stat.h" +#include <sys/stat.h> /* Does ps4 get parameter substitutions done? */ #ifdef KSH @@ -16,55 +16,33 @@ # define PS4_SUBSTITUTE(s) (s) #endif /* KSH */ -static int comexec ARGS((struct op *t, struct tbl *volatile tp, char **ap, - int volatile flags)); -static void scriptexec ARGS((struct op *tp, char **ap)); -static int call_builtin ARGS((struct tbl *tp, char **wp)); -static int iosetup ARGS((struct ioword *iop, struct tbl *tp)); -static int herein ARGS((const char *content, int sub)); +static int comexec(struct op *t, struct tbl *volatile tp, char **ap, + int volatile flags); +static void scriptexec(struct op *tp, char **ap); +static int call_builtin(struct tbl *tp, char **wp); +static int iosetup(struct ioword *iop, struct tbl *tp); +static int herein(const char *content, int sub); #ifdef KSH -static char *do_selectargs ARGS((char **ap, bool_t print_menu)); +static char *do_selectargs(char **ap, bool_t print_menu); #endif /* KSH */ #ifdef KSH -static int dbteste_isa ARGS((Test_env *te, Test_meta meta)); -static const char *dbteste_getopnd ARGS((Test_env *te, Test_op op, - int do_eval)); -static int dbteste_eval ARGS((Test_env *te, Test_op op, const char *opnd1, - const char *opnd2, int do_eval)); -static void dbteste_error ARGS((Test_env *te, int offset, const char *msg)); +static int dbteste_isa(Test_env *te, Test_meta meta); +static const char *dbteste_getopnd(Test_env *te, Test_op op, + int do_eval); +static int dbteste_eval(Test_env *te, Test_op op, const char *opnd1, + const char *opnd2, int do_eval); +static void dbteste_error(Test_env *te, int offset, const char *msg); #endif /* KSH */ -#ifdef OS2 -static int search_access1 ARGS((const char *path, int mode, int *errnop)); -#endif /* OS2 */ /* - * handle systems that don't have F_SETFD - */ -#ifndef F_SETFD -# ifndef MAXFD -# define MAXFD 64 -# endif -/* a bit field would be smaller, but this will work */ -static char clexec_tab[MAXFD+1]; -#endif - -/* * we now use this function always. */ int fd_clexec(fd) int fd; { -#ifndef F_SETFD - if (fd >= 0 && fd < sizeof(clexec_tab)) { - clexec_tab[fd] = 1; - return 0; - } - return -1; -#else return fcntl(fd, F_SETFD, 1); -#endif } @@ -200,24 +178,20 @@ execute(t, flags) #ifdef KSH case TCOPROC: { -# ifdef JOB_SIGS sigset_t omask; -# endif /* JOB_SIGS */ -# ifdef JOB_SIGS /* Block sigchild as we are using things changed in the * signal handler */ sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); e->type = E_ERRH; - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (i) { sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); quitenv(); unwind(i); /*NOTREACHED*/ } -# endif /* JOB_SIGS */ /* Already have a (live) co-process? */ if (coproc.job && coproc.write >= 0) errorf("coprocess already exists"); @@ -248,10 +222,8 @@ execute(t, flags) /* create new coprocess id */ ++coproc.id; } -# ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); e->type = E_EXEC; /* no more need for error handler */ -# endif /* JOB_SIGS */ /* exchild() closes coproc.* in child after fork, * will also increment coproc.njobs when the @@ -313,7 +285,7 @@ execute(t, flags) : e->loc->argv + 1; e->type = E_LOOP; while (1) { - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (!i) break; if ((e->flags&EF_BRKCONT_PASS) @@ -353,7 +325,7 @@ execute(t, flags) case TUNTIL: e->type = E_LOOP; while (1) { - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (!i) break; if ((e->flags&EF_BRKCONT_PASS) @@ -410,17 +382,9 @@ execute(t, flags) case TEXEC: /* an eval'd TCOM */ s = t->args[0]; ap = makenv(); -#ifndef F_SETFD - for (i = 0; i < sizeof(clexec_tab); i++) - if (clexec_tab[i]) { - close(i); - clexec_tab[i] = 0; - } -#endif restoresigs(); cleanup_proc_env(); - /* XINTACT bit is for OS2 */ - ksh_execve(t->str, t->args, ap, (flags & XINTACT) ? 1 : 0); + execve(t->str, t->args, ap); if (errno == ENOEXEC) scriptexec(t, ap); else @@ -577,7 +541,7 @@ comexec(t, tp, ap, flags) rv = subst_exstat; goto Leave; } else if (!tp) { - if (Flag(FRESTRICTED) && ksh_strchr_dirsep(cp)) { + if (Flag(FRESTRICTED) && strchr(cp, '/')) { warningf(TRUE, "%s: restricted", cp); rv = 1; goto Leave; @@ -659,7 +623,7 @@ comexec(t, tp, ap, flags) tp->flag |= FINUSE; e->type = E_FUNC; - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (i == 0) { /* seems odd to pass XERROK here, but at&t ksh does */ exstat = execute(tp->val.t, flags & XERROK); @@ -764,101 +728,9 @@ scriptexec(tp, ap) shell = EXECSHELL; *tp->args-- = tp->str; -#ifdef SHARPBANG - { - char buf[LINE]; - register char *cp; - register int fd, n; - - buf[0] = '\0'; - if ((fd = open(tp->str, O_RDONLY)) >= 0) { - if ((n = read(fd, buf, LINE - 1)) > 0) - buf[n] = '\0'; - (void) close(fd); - } - if ((buf[0] == '#' && buf[1] == '!' && (cp = &buf[2])) -# ifdef OS2 - || (strncmp(buf, "extproc", 7) == 0 && isspace(buf[7]) - && (cp = &buf[7])) -# endif /* OS2 */ - ) - { - while (*cp && (*cp == ' ' || *cp == '\t')) - cp++; - if (*cp && *cp != '\n') { - char *a0 = cp, *a1 = (char *) 0; -# ifdef OS2 - char *a2 = cp; -# endif /* OS2 */ - - while (*cp && *cp != '\n' && *cp != ' ' - && *cp != '\t') - { -# ifdef OS2 - /* Allow shell search without prepended path - * if shell with / in pathname cannot be found. - * Use / explicitly so \ can be used if explicit - * needs to be forced. - */ - if (*cp == '/') - a2 = cp + 1; -# endif /* OS2 */ - cp++; - } - if (*cp && *cp != '\n') { - *cp++ = '\0'; - while (*cp - && (*cp == ' ' || *cp == '\t')) - cp++; - if (*cp && *cp != '\n') { - a1 = cp; - /* all one argument */ - while (*cp && *cp != '\n') - cp++; - } - } - if (*cp == '\n') { - *cp = '\0'; - if (a1) - *tp->args-- = a1; -# ifdef OS2 - if (a0 != a2) { - char *tmp_a0 = str_nsave(a0, - strlen(a0) + 5, ATEMP); - if (search_access(tmp_a0, X_OK, - (int *) 0)) - a0 = a2; - afree(tmp_a0, ATEMP); - } -# endif /* OS2 */ - shell = a0; - } - } -# ifdef OS2 - } else { - /* Use ksh documented shell default if present - * else use OS2_SHELL which is assumed to need - * the /c option and '\' as dir separator. - */ - char *p = shell; - - shell = str_val(global("EXECSHELL")); - if (shell && *shell) - shell = search(shell, path, X_OK, (int *) 0); - if (!shell || !*shell) { - shell = p; - *tp->args-- = "/c"; - for (p = tp->str; *p; p++) - if (*p == '/') - *p = '\\'; - } -# endif /* OS2 */ - } - } -#endif /* SHARPBANG */ *tp->args = shell; - ksh_execve(tp->args[0], tp->args, ap, 0); + execve(tp->args[0], tp->args, ap); /* report both the program that was run and the bogus shell */ errorf("%s: %s: %s", tp->str, shell, strerror(errno)); @@ -956,7 +828,7 @@ define(name, t) void builtin(name, func) const char *name; - int (*func) ARGS((char **)); + int (*func)(char **); { register struct tbl *tp; Tflag flag; @@ -995,7 +867,7 @@ findcom(name, flags) char *fpath; /* for function autoloading */ char *npath; - if (ksh_strchr_dirsep(name) != NULL) { + if (strchr(name, '/') != NULL) { insert = 0; /* prevent FPATH search below */ flags &= ~FC_FUNC; @@ -1032,7 +904,7 @@ findcom(name, flags) tp = tbi; if (!tp && (flags & FC_PATH) && !(flags & FC_DEFPATH)) { tp = tsearch(&taliases, name, h); - if (tp && (tp->flag & ISSET) && eaccess(tp->val.s, X_OK) != 0) { + if (tp && (tp->flag & ISSET) && access(tp->val.s, X_OK) != 0) { if (tp->flag & ALLOC) { tp->flag &= ~ALLOC; afree(tp->val.s, APERM); @@ -1090,7 +962,7 @@ flushcom(all) struct tstate ts; for (twalk(&ts, &taliases); (tp = tnext(&ts)) != NULL; ) - if ((tp->flag&ISSET) && (all || !ISDIRSEP(tp->val.s[0]))) { + if ((tp->flag&ISSET) && (all || tp->val.s[0] != '/')) { if (tp->flag&ALLOC) { tp->flag &= ~(ALLOC|ISSET); afree(tp->val.s, APERM); @@ -1106,13 +978,12 @@ search_access(path, mode, errnop) int mode; int *errnop; /* set if candidate found, but not suitable */ { -#ifndef OS2 int ret, err = 0; struct stat statb; if (stat(path, &statb) < 0) return -1; - ret = eaccess(path, mode); + ret = access(path, mode); if (ret < 0) err = errno; /* File exists, but we can't access it */ else if (mode == X_OK @@ -1126,74 +997,8 @@ search_access(path, mode, errnop) if (err && errnop && !*errnop) *errnop = err; return ret; -#else /* !OS2 */ - /* - * NOTE: ASSUMES path can be modified and has enough room at the - * end of the string for a suffix (ie, 4 extra characters). - * Certain code knows this (eg, eval.c(globit()), - * exec.c(search())). - */ - static char *xsuffixes[] = { ".ksh", ".exe", ".", ".sh", ".cmd", - ".com", ".bat", (char *) 0 - }; - static char *rsuffixes[] = { ".ksh", ".", ".sh", ".cmd", ".bat", - (char *) 0 - }; - int i; - char *mpath = (char *) path; - char *tp = mpath + strlen(mpath); - char *p; - char **sfx; - - /* If a suffix has been specified, check if it is one of the - * suffixes that indicate the file is executable - if so, change - * the access test to R_OK... - * This code assumes OS/2 files can have only one suffix... - */ - if ((p = strrchr((p = ksh_strrchr_dirsep(mpath)) ? p : mpath, '.'))) { - if (mode == X_OK) - mode = R_OK; - return search_access1(mpath, mode, errnop); - } - /* Try appending the various suffixes. Different suffixes for - * read and execute 'cause we don't want to read an executable... - */ - sfx = mode == R_OK ? rsuffixes : xsuffixes; - for (i = 0; sfx[i]; i++) { - strcpy(tp, p = sfx[i]); - if (search_access1(mpath, R_OK, errnop) == 0) - return 0; - *tp = '\0'; - } - return -1; -#endif /* !OS2 */ } -#ifdef OS2 -static int -search_access1(path, mode, errnop) - const char *path; - int mode; - int *errnop; /* set if candidate found, but not suitable */ -{ - int ret, err = 0; - struct stat statb; - - if (stat(path, &statb) < 0) - return -1; - ret = eaccess(path, mode); - if (ret < 0) - err = errno; /* File exists, but we can't access it */ - else if (!S_ISREG(statb.st_mode)) { - ret = -1; - err = S_ISDIR(statb.st_mode) ? EISDIR : EACCES; - } - if (err && errnop && !*errnop) - *errnop = err; - return ret; -} -#endif /* OS2 */ - /* * search for command with PATH */ @@ -1211,26 +1016,7 @@ search(name, path, mode, errnop) if (errnop) *errnop = 0; -#ifdef OS2 - /* Xinit() allocates 8 additional bytes, so appended suffixes won't - * overflow the memory. - */ - namelen = strlen(name) + 1; - Xinit(xs, xp, namelen, ATEMP); - memcpy(Xstring(xs, xp), name, namelen); - - if (ksh_strchr_dirsep(name)) { - if (search_access(Xstring(xs, xp), mode, errnop) >= 0) - return Xstring(xs, xp); /* not Xclose() - see above */ - Xfree(xs, xp); - return NULL; - } - - /* Look in current context always. (os2 style) */ - if (search_access(Xstring(xs, xp), mode, errnop) == 0) - return Xstring(xs, xp); /* not Xclose() - xp may be wrong */ -#else /* OS2 */ - if (ksh_strchr_dirsep(name)) { + if (strchr(name, '/')) { if (search_access(name, mode, errnop) == 0) return (char *) name; return NULL; @@ -1238,28 +1024,23 @@ search(name, path, mode, errnop) namelen = strlen(name) + 1; Xinit(xs, xp, 128, ATEMP); -#endif /* OS2 */ sp = path; while (sp != NULL) { xp = Xstring(xs, xp); - if (!(p = strchr(sp, PATHSEP))) + if (!(p = strchr(sp, ':'))) p = sp + strlen(sp); if (p != sp) { XcheckN(xs, xp, p - sp); memcpy(xp, sp, p - sp); xp += p - sp; - *xp++ = DIRSEP; + *xp++ = '/'; } sp = p; XcheckN(xs, xp, namelen); memcpy(xp, name, namelen); if (search_access(Xstring(xs, xp), mode, errnop) == 0) -#ifdef OS2 - return Xstring(xs, xp); /* Not Xclose() - see above */ -#else /* OS2 */ return Xclose(xs, xp + namelen); -#endif /* OS2 */ if (*sp++ == '\0') sp = NULL; } @@ -1298,7 +1079,7 @@ iosetup(iop, tp) register int u = -1; char *cp = iop->name; int iotype = iop->flag & IOTYPE; - int do_open = 1, do_close = 0, UNINITIALIZED(flags); + int do_open = 1, do_close = 0, flags = 0; struct ioword iotmp; struct stat statb; @@ -1372,10 +1153,6 @@ iosetup(iop, tp) return -1; } u = open(cp, flags, 0666); -#ifdef OS2 - if (u < 0 && strcmp(cp, "/dev/null") == 0) - u = open("nul", flags, 0666); -#endif /* OS2 */ } if (u < 0) { /* herein() may already have printed message */ @@ -1468,7 +1245,7 @@ herein(content, sub) osource = source; newenv(E_ERRH); - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (i) { source = osource; quitenv(); @@ -1544,7 +1321,7 @@ struct select_menu_info { int num_width; } info; -static char *select_fmt_entry ARGS((void *arg, int i, char *buf, int buflen)); +static char *select_fmt_entry(void *arg, int i, char *buf, int buflen); /* format a single select menu item */ static char * @@ -1606,7 +1383,7 @@ pr_menu(ap) /* XXX: horrible kludge to fit within the framework */ -static char *plain_fmt_entry ARGS((void *arg, int i, char *buf, int buflen)); +static char *plain_fmt_entry(void *arg, int i, char *buf, int buflen); static char * plain_fmt_entry(arg, i, buf, buflen) diff --git a/bin/ksh/expand.h b/bin/ksh/expand.h index ed1aeb7dd4f..e41a0bdb3c1 100644 --- a/bin/ksh/expand.h +++ b/bin/ksh/expand.h @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.h,v 1.3 2001/03/26 16:19:45 todd Exp $ */ +/* $OpenBSD: expand.h,v 1.4 2004/12/18 20:55:52 millert Exp $ */ /* * Expanding strings @@ -69,7 +69,7 @@ typedef char * XStringP; #define Xsavepos(xs, xp) ((xp) - (xs).beg) #define Xrestpos(xs, xp, n) ((xs).beg + (n)) -char * Xcheck_grow_ ARGS((XString *xsp, char *xp, int more)); +char * Xcheck_grow_(XString *xsp, char *xp, int more); /* * expandable vector of generic pointers diff --git a/bin/ksh/expr.c b/bin/ksh/expr.c index e61372fb2e1..e04abfd24d0 100644 --- a/bin/ksh/expr.c +++ b/bin/ksh/expr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expr.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */ +/* $OpenBSD: expr.c,v 1.10 2004/12/18 20:55:52 millert Exp $ */ /* * Korn expression evaluation @@ -128,16 +128,16 @@ struct expr_state { enum error_type { ET_UNEXPECTED, ET_BADLIT, ET_RECURSIVE, ET_LVALUE, ET_RDONLY, ET_STR }; -static void evalerr ARGS((Expr_state *es, enum error_type type, - const char *str)) GCC_FUNC_ATTR(noreturn); -static struct tbl *evalexpr ARGS((Expr_state *es, enum prec prec)); -static void token ARGS((Expr_state *es)); -static struct tbl *do_ppmm ARGS((Expr_state *es, enum token op, - struct tbl *vasn, bool_t is_prefix)); -static void assign_check ARGS((Expr_state *es, enum token op, - struct tbl *vasn)); -static struct tbl *tempvar ARGS((void)); -static struct tbl *intvar ARGS((Expr_state *es, struct tbl *vp)); +static void evalerr(Expr_state *es, enum error_type type, + const char *str) GCC_FUNC_ATTR(noreturn); +static struct tbl *evalexpr(Expr_state *es, enum prec prec); +static void token(Expr_state *es); +static struct tbl *do_ppmm(Expr_state *es, enum token op, + struct tbl *vasn, bool_t is_prefix); +static void assign_check(Expr_state *es, enum token op, + struct tbl *vasn); +static struct tbl *tempvar(void); +static struct tbl *intvar(Expr_state *es, struct tbl *vp); /* * parse and evaluate expression @@ -178,7 +178,7 @@ v_evaluate(vp, expr, error_ok) curstate.evaling = (struct tbl *) 0; newenv(E_ERRH); - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (i) { /* Clear EXPRINEVAL in of any variables we were playing with */ if (curstate.evaling) @@ -280,9 +280,9 @@ evalexpr(es, prec) Expr_state *es; enum prec prec; { - struct tbl *vl, UNINITIALIZED(*vr), *vasn; + struct tbl *vl, *vr = NULL, *vasn; enum token op; - long UNINITIALIZED(res); + long res = 0; if (prec == P_PRIMARY) { op = es->tok; diff --git a/bin/ksh/history.c b/bin/ksh/history.c index 31c7c8345d7..519a92dda9d 100644 --- a/bin/ksh/history.c +++ b/bin/ksh/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.25 2004/12/12 06:53:13 deraadt Exp $ */ +/* $OpenBSD: history.c,v 1.26 2004/12/18 20:55:52 millert Exp $ */ /* * command history @@ -9,33 +9,18 @@ /* * This file contains * a) the original in-memory history mechanism - * b) a simple file saving history mechanism done by sjg@zen - * define EASY_HISTORY to get this - * c) a more complicated mechanism done by pc@hillside.co.uk + * b) a more complicated mechanism done by pc@hillside.co.uk * that more closely follows the real ksh way of doing * things. You need to have the mmap system call for this * to work on your system */ #include "sh.h" -#include "ksh_stat.h" +#include <sys/stat.h> #ifdef HISTORY -# ifdef EASY_HISTORY - -# ifndef HISTFILE -# ifdef OS2 -# define HISTFILE "history.ksh" -# else /* OS2 */ -# define HISTFILE ".pdksh_history" -# endif /* OS2 */ -# endif - -# else -/* Defines and includes for the complicated case */ - -# include <sys/file.h> -# include <sys/mman.h> +# include <sys/file.h> +# include <sys/mman.h> /* * variables for handling the data file @@ -43,28 +28,20 @@ static int histfd; static int hsize; -static int hist_count_lines ARGS((unsigned char *, int)); -static int hist_shrink ARGS((unsigned char *, int)); -static unsigned char *hist_skip_back ARGS((unsigned char *,int *,int)); -static void histload ARGS((Source *, unsigned char *, int)); -static void histinsert ARGS((Source *, int, unsigned char *)); -static void writehistfile ARGS((int, char *)); -static int sprinkle ARGS((int)); - -# ifdef MAP_FILE -# define MAP_FLAGS (MAP_FILE|MAP_PRIVATE) -# else -# define MAP_FLAGS MAP_PRIVATE -# endif - -# endif /* of EASY_HISTORY */ - -static int hist_execute ARGS((char *cmd)); -static int hist_replace ARGS((char **hp, const char *pat, const char *rep, - int global)); -static char **hist_get ARGS((const char *str, int approx, int allow_cur)); -static char **hist_get_oldest ARGS((void)); -static void histbackup ARGS((void)); +static int hist_count_lines(unsigned char *, int); +static int hist_shrink(unsigned char *, int); +static unsigned char *hist_skip_back(unsigned char *,int *,int); +static void histload(Source *, unsigned char *, int); +static void histinsert(Source *, int, unsigned char *); +static void writehistfile(int, char *); +static int sprinkle(int); + +static int hist_execute(char *cmd); +static int hist_replace(char **hp, const char *pat, const char *rep, + int global); +static char **hist_get(const char *str, int approx, int allow_cur); +static char **hist_get_oldest(void); +static void histbackup(void); static char **current; /* current position in history[] */ static int curpos; /* current index in history[] */ @@ -78,7 +55,7 @@ c_fc(wp) char **wp; { struct shf *shf; - struct temp UNINITIALIZED(*tf); + struct temp *tf = NULL; char *p, *editor = (char *) 0; int gflag = 0, lflag = 0, nflag = 0, sflag = 0, rflag = 0; int optc; @@ -307,12 +284,7 @@ hist_execute(cmd) if (!*q) /* ignore trailing newline */ q = (char *) 0; } -#ifdef EASY_HISTORY - if (p != cmd) - histappend(p, TRUE); - else -#endif /* EASY_HISTORY */ - histsave(++(hist_source->line), p, 1); + histsave(++(hist_source->line), p, 1); shellf("%s\n", p); /* POSIX doesn't say this is done... */ if ((p = q)) /* restore \n (trailing \n not restored) */ @@ -590,12 +562,6 @@ sethistfile(name) /* * its a new name - possibly */ -# ifdef EASY_HISTORY - if (hname) { - afree(hname, APERM); - hname = NULL; - } -# else if (histfd) { /* yes the file is open */ (void) close(histfd); @@ -607,7 +573,6 @@ sethistfile(name) histptr = history - 1; hist_source->line = 0; } -# endif hist_init(hist_source); } @@ -625,156 +590,6 @@ init_histvec() } } -# ifdef EASY_HISTORY -/* - * save command in history - */ -void -histsave(lno, cmd, dowrite) - int lno; /* ignored (compatibility with COMPLEX_HISTORY) */ - const char *cmd; - int dowrite; /* ignored (compatibility with COMPLEX_HISTORY) */ -{ - register char **hp = histptr; - char *cp; - - if (++hp >= history + histsize) { /* remove oldest command */ - afree((void*)history[0], APERM); - memmove(history, history + 1, - sizeof(history[0]) * (histsize - 1)); - hp = &history[histsize - 1]; - } - *hp = str_save(cmd, APERM); - /* trash trailing newline but allow imbedded newlines */ - cp = *hp + strlen(*hp); - if (cp > *hp && cp[-1] == '\n') - cp[-1] = '\0'; - histptr = hp; -} - -/* - * Append an entry to the last saved command. Used for multiline - * commands - */ -void -histappend(cmd, nl_separate) - const char *cmd; - int nl_separate; -{ - int hlen, clen; - char *p; - - hlen = strlen(*histptr); - clen = strlen(cmd); - if (clen > 0 && cmd[clen-1] == '\n') - clen--; - p = *histptr = (char *) aresize(*histptr, hlen + clen + 2, APERM); - p += hlen; - if (nl_separate) - *p++ = '\n'; - memcpy(p, cmd, clen); - p[clen] = '\0'; -} - -/* - * 92-04-25 <sjg@zen> - * A simple history file implementation. - * At present we only save the history when we exit. - * This can cause problems when there are multiple shells are - * running under the same user-id. The last shell to exit gets - * to save its history. - */ -void -hist_init(s) - Source *s; -{ - char *f; - FILE *fh; - - if (Flag(FTALKING) == 0) - return; - - hstarted = 1; - - hist_source = s; - - if ((f = str_val(global("HISTFILE"))) == NULL || *f == '\0') { -# if 1 /* Don't use history file unless the user asks for it */ - hname = NULL; - return; -# else - char *home = str_val(global("HOME")); - int len; - - if (home == NULL) - home = null; - f = HISTFILE; - hname = alloc(len = strlen(home) + strlen(f) + 2, APERM); - shf_snprintf(hname, len, "%s/%s", home, f); -# endif - } else - hname = str_save(f, APERM); - - if ((fh = fopen(hname, "r"))) { - int pos = 0, nread = 0; - int contin = 0; /* continuation of previous command */ - char *end; - char hline[LINE + 1]; - - while (1) { - if (pos >= nread) { - pos = 0; - nread = fread(hline, 1, LINE, fh); - if (nread <= 0) - break; - hline[nread] = '\0'; - } - end = strchr(hline + pos, 0); /* will always succeed */ - if (contin) - histappend(hline + pos, 0); - else { - hist_source->line++; - histsave(0, hline + pos, 0); - } - pos = end - hline + 1; - contin = end == &hline[nread]; - } - fclose(fh); - } -} - -/* - * save our history. - * We check that we do not have more than we are allowed. - * If the history file is read-only we do nothing. - * Handy for having all shells start with a useful history set. - */ - -void -hist_finish() -{ - static int once; - FILE *fh; - register int i; - register char **hp; - - if (once++) - return; - /* check how many we have */ - i = histptr - history; - if (i >= histsize) - hp = &histptr[-histsize]; - else - hp = history; - if (hname && (fh = fopen(hname, "w"))) - { - for (i = 0; hp + i <= histptr && hp[i]; i++) - fprintf(fh, "%s%c", hp[i], '\0'); - fclose(fh); - } -} - -# else /* EASY_HISTORY */ /* * Routines added by Peter Collinson BSDI(Europe)/Hillside Systems to @@ -835,9 +650,9 @@ histsave(lno, cmd, dowrite) * Each command is * <command byte><command number(4 bytes)><bytes><null> */ -# define HMAGIC1 0xab -# define HMAGIC2 0xcd -# define COMMAND 0xff +#define HMAGIC1 0xab +#define HMAGIC2 0xcd +#define COMMAND 0xff void hist_init(s) @@ -881,7 +696,7 @@ hist_init(s) /* * we have some data */ - base = (unsigned char *)mmap(0, hsize, PROT_READ, MAP_FLAGS, histfd, 0); + base = (unsigned char *)mmap(0, hsize, PROT_READ, MAP_FILE|MAP_PRIVATE, histfd, 0); /* * check on its validity */ @@ -1131,7 +946,7 @@ writehistfile(lno, cmd) if (sizenow > hsize) { /* someone has added some lines */ bytes = sizenow - hsize; - base = (unsigned char *)mmap(0, sizenow, PROT_READ, MAP_FLAGS, histfd, 0); + base = (unsigned char *)mmap(0, sizenow, PROT_READ, MAP_FILE|MAP_PRIVATE, histfd, 0); if (base == MAP_FAILED) goto bad; new = base + hsize; @@ -1189,7 +1004,6 @@ sprinkle(fd) return(write(fd, mag, 2) != 2); } -# endif #else /* HISTORY */ /* No history to be compiled in: dummy routines to avoid lots more ifdefs */ diff --git a/bin/ksh/io.c b/bin/ksh/io.c index a20ceed3d8b..1ab2882e216 100644 --- a/bin/ksh/io.c +++ b/bin/ksh/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.13 2003/11/10 21:26:39 millert Exp $ */ +/* $OpenBSD: io.c,v 1.14 2004/12/18 20:55:52 millert Exp $ */ /* * shell buffered IO and formatted output @@ -6,7 +6,7 @@ #include <ctype.h> #include "sh.h" -#include "ksh_stat.h" +#include <sys/stat.h> static int initio_done; @@ -17,13 +17,7 @@ static int initio_done; /* A shell error occurred (eg, syntax error, etc.) */ void -#ifdef HAVE_PROTOTYPES errorf(const char *fmt, ...) -#else -errorf(fmt, va_alist) - const char *fmt; - va_dcl -#endif { va_list va; @@ -31,7 +25,7 @@ errorf(fmt, va_alist) exstat = 1; if (*fmt) { error_prefix(TRUE); - SH_VA_START(va, fmt); + va_start(va, fmt); shf_vfprintf(shl_out, fmt, va); va_end(va); shf_putchar('\n', shl_out); @@ -42,19 +36,12 @@ errorf(fmt, va_alist) /* like errorf(), but no unwind is done */ void -#ifdef HAVE_PROTOTYPES warningf(int fileline, const char *fmt, ...) -#else -warningf(fileline, fmt, va_alist) - int fileline; - const char *fmt; - va_dcl -#endif { va_list va; error_prefix(fileline); - SH_VA_START(va, fmt); + va_start(va, fmt); shf_vfprintf(shl_out, fmt, va); va_end(va); shf_putchar('\n', shl_out); @@ -65,13 +52,7 @@ warningf(fileline, fmt, va_alist) * (also unwinds environments for special builtins). */ void -#ifdef HAVE_PROTOTYPES bi_errorf(const char *fmt, ...) -#else -bi_errorf(fmt, va_alist) - const char *fmt; - va_dcl -#endif { va_list va; @@ -82,7 +63,7 @@ bi_errorf(fmt, va_alist) /* not set when main() calls parse_args() */ if (builtin_argv0) shf_fprintf(shl_out, "%s: ", builtin_argv0); - SH_VA_START(va, fmt); + va_start(va, fmt); shf_vfprintf(shl_out, fmt, va); va_end(va); shf_putchar('\n', shl_out); @@ -102,20 +83,13 @@ bi_errorf(fmt, va_alist) /* Called when something that shouldn't happen does */ void -#ifdef HAVE_PROTOTYPES internal_errorf(int jump, const char *fmt, ...) -#else -internal_errorf(jump, fmt, va_alist) - int jump; - const char *fmt; - va_dcl -#endif { va_list va; error_prefix(TRUE); shf_fprintf(shl_out, "internal error: "); - SH_VA_START(va, fmt); + va_start(va, fmt); shf_vfprintf(shl_out, fmt, va); va_end(va); shf_putchar('\n', shl_out); @@ -142,19 +116,13 @@ error_prefix(fileline) /* printf to shl_out (stderr) with flush */ void -#ifdef HAVE_PROTOTYPES shellf(const char *fmt, ...) -#else -shellf(fmt, va_alist) - const char *fmt; - va_dcl -#endif { va_list va; if (!initio_done) /* shl_out may not be set up yet... */ return; - SH_VA_START(va, fmt); + va_start(va, fmt); shf_vfprintf(shl_out, fmt, va); va_end(va); shf_flush(shl_out); @@ -162,19 +130,13 @@ shellf(fmt, va_alist) /* printf to shl_stdout (stdout) */ void -#ifdef HAVE_PROTOTYPES shprintf(const char *fmt, ...) -#else -shprintf(fmt, va_alist) - const char *fmt; - va_dcl -#endif { va_list va; if (!shl_stdout_ok) internal_errorf(1, "shl_stdout not valid"); - SH_VA_START(va, fmt); + va_start(va, fmt); shf_vfprintf(shl_stdout, fmt, va); va_end(va); } @@ -198,19 +160,13 @@ kshdebug_init_() /* print to debugging log */ void -# ifdef HAVE_PROTOTYPES kshdebug_printf_(const char *fmt, ...) -# else -kshdebug_printf_(fmt, va_alist) - const char *fmt; - va_dcl -# endif { va_list va; if (!kshdebug_shf) return; - SH_VA_START(va, fmt); + va_start(va, fmt); shf_fprintf(kshdebug_shf, "[%d] ", getpid()); shf_vfprintf(kshdebug_shf, fmt, va); va_end(va); @@ -277,12 +233,6 @@ ksh_dup2(ofd, nfd, errok) if (ret < 0 && errno != EBADF && !errok) errorf("too many files open in shell"); -#ifdef DUP2_BROKEN - /* Ultrix systems like to preserve the close-on-exec flag */ - if (ret >= 0) - (void) fcntl(nfd, F_SETFD, 0); -#endif /* DUP2_BROKEN */ - return ret; } @@ -298,7 +248,7 @@ savefd(fd, noclose) int nfd; if (fd < FDBASE) { - nfd = ksh_dupbase(fd, FDBASE); + nfd = fcntl(fd, F_DUPFD, FDBASE); if (nfd < 0) { if (errno == EBADF) return -1; @@ -364,20 +314,6 @@ check_fd(name, mode, emsgp) return -1; } fl &= O_ACCMODE; -#ifdef OS2 - if (mode == W_OK ) { - if (setmode(fd, O_TEXT) == -1) { - if (emsgp) - *emsgp = "couldn't set write mode"; - return -1; - } - } else if (mode == R_OK) - if (setmode(fd, O_BINARY) == -1) { - if (emsgp) - *emsgp = "couldn't set read mode"; - return -1; - } -#else /* OS2 */ /* X_OK is a kludge to disable this check for dups (x<&1): * historical shells never did this check (XXX don't know what * posix has to say). @@ -392,7 +328,6 @@ check_fd(name, mode, emsgp) : "fd not open for writing"; return -1; } -#endif /* OS2 */ return fd; } #ifdef KSH @@ -519,38 +454,10 @@ maketemp(ap, type, tlist) tp->name = path = (char *) &tp[1]; tp->shf = (struct shf *) 0; tp->type = type; -#ifdef __OpenBSD__ shf_snprintf(path, len, "%s/shXXXXXXXX", dir); fd = mkstemp(path); if (fd >= 0) tp->shf = shf_fdopen(fd, SHF_WR, (struct shf *) 0); -#else - while (1) { - /* Note that temp files need to fit 8.3 DOS limits */ - shf_snprintf(path, len, "%s/sh%05u.%03x", - dir, (unsigned) procpid, inc++); - /* Mode 0600 to be paranoid, O_TRUNC in case O_EXCL isn't - * really there. - */ - fd = open(path, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, 0600); - if (fd >= 0) { - tp->shf = shf_fdopen(fd, SHF_WR, (struct shf *) 0); - break; - } - if (errno != EINTR -#ifdef EEXIST - && errno != EEXIST -#endif /* EEXIST */ -#ifdef EISDIR - && errno != EISDIR -#endif /* EISDIR */ - ) - /* Error must be printed by caller: don't know here if - * errorf() or bi_errorf() should be used. - */ - break; - } -#endif /* __OpenBSD__ */ tp->pid = procpid; tp->next = *tlist; diff --git a/bin/ksh/jobs.c b/bin/ksh/jobs.c index f87eaf52f8c..e83f32ed08a 100644 --- a/bin/ksh/jobs.c +++ b/bin/ksh/jobs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: jobs.c,v 1.22 2004/11/04 19:20:07 deraadt Exp $ */ +/* $OpenBSD: jobs.c,v 1.23 2004/12/18 20:55:52 millert Exp $ */ /* * Process and job control @@ -13,80 +13,14 @@ * to allow use of vfork() when available but that would be way too much * work :) * - * Notes regarding the copious ifdefs: - * - JOB_SIGS is independent of JOBS - it is defined if there are modern - * signal and wait routines available. This is preferred, even when - * JOBS is not defined, since the shell will not otherwise notice when - * background jobs die until the shell waits for a foreground process - * to die. - * - TTY_PGRP defined iff JOBS is defined - defined if there are tty - * process groups - * - NEED_PGRP_SYNC defined iff JOBS is defined - see comment below */ #include "sh.h" -#include "ksh_stat.h" -#include "ksh_wait.h" -#include "ksh_times.h" +#include <sys/stat.h> +#include <sys/wait.h> +#include <sys/times.h> #include "tty.h" -/* Start of system configuration stuff */ - -/* We keep CHILD_MAX zombie processes around (exact value isn't critical) */ -#ifndef CHILD_MAX -# if defined(HAVE_SYSCONF) && defined(_SC_CHILD_MAX) -# define CHILD_MAX sysconf(_SC_CHILD_MAX) -# else /* _SC_CHILD_MAX */ -# ifdef _POSIX_CHILD_MAX -# define CHILD_MAX ((_POSIX_CHILD_MAX) * 2) -# else /* _POSIX_CHILD_MAX */ -# define CHILD_MAX 20 -# endif /* _POSIX_CHILD_MAX */ -# endif /* _SC_CHILD_MAX */ -#endif /* !CHILD_MAX */ - -#ifdef JOBS -# if defined(HAVE_TCSETPGRP) || defined(TIOCSPGRP) -# define TTY_PGRP -# endif -# ifdef BSD_PGRP -# define setpgid setpgrp -# define getpgID() getpgrp(0) -# else -# define getpgID() getpgrp() -# endif -# if defined(TTY_PGRP) && !defined(HAVE_TCSETPGRP) -int tcsetpgrp ARGS((int fd, pid_t grp)); -int tcgetpgrp ARGS((int fd)); - -int -tcsetpgrp(fd, grp) - int fd; - pid_t grp; -{ - return ioctl(fd, TIOCSPGRP, &grp); -} - -int -tcgetpgrp(fd) - int fd; -{ - int r, grp; - - if ((r = ioctl(fd, TIOCGPGRP, &grp)) < 0) - return r; - return grp; -} -# endif /* !HAVE_TCSETPGRP && TIOCSPGRP */ -#else /* JOBS */ -/* These so we can use ifdef xxx instead of if defined(JOBS) && defined(xxx) */ -# undef TTY_PGRP -# undef NEED_PGRP_SYNC -#endif /* JOBS */ - -/* End of system configuration stuff */ - - /* Order important! */ #define PRUNNING 0 #define PEXITED 1 @@ -97,7 +31,7 @@ typedef struct proc Proc; struct proc { Proc *next; /* next process in pipeline (if any) */ int state; - WAIT_T status; /* wait status */ + int status; /* wait status */ pid_t pid; /* process id */ char command[48]; /* process command string */ }; @@ -144,10 +78,10 @@ struct job { #ifdef KSH Coproc_id coproc_id; /* 0 or id of coprocess output pipe */ #endif /* KSH */ -#ifdef TTY_PGRP +#ifdef JOBS TTY_state ttystate; /* saved tty state for stopped jobs */ pid_t saved_ttypgrp; /* saved tty process group for stopped jobs */ -#endif /* TTY_PGRP */ +#endif /* JOBS */ }; /* Flags for j_waitj() */ @@ -181,47 +115,29 @@ INT32 njobs; /* # of jobs started */ static int child_max; /* CHILD_MAX */ -#ifdef JOB_SIGS /* held_sigchld is set if sigchld occurs before a job is completely started */ static int held_sigchld; -#endif /* JOB_SIGS */ #ifdef JOBS static struct shf *shl_j; -#endif /* JOBS */ - -#ifdef NEED_PGRP_SYNC -/* On some systems, the kernel doesn't count zombie processes when checking - * if a process group is valid, which can cause problems in creating the - * pipeline "cmd1 | cmd2": if cmd1 can die (and go into the zombie state) - * before cmd2 is started, the kernel doesn't allow the setpgid() for cmd2 - * to succeed. Solution is to create a pipe between the parent and the first - * process; the first process doesn't do anything until the pipe is closed - * and the parent doesn't close the pipe until all the processes are started. - */ -static int j_sync_pipe[2]; -static int j_sync_open; -#endif /* NEED_PGRP_SYNC */ - -#ifdef TTY_PGRP static int ttypgrp_ok; /* set if can use tty pgrps */ static pid_t restore_ttypgrp = -1; static pid_t our_pgrp; static int const tt_sigs[] = { SIGTSTP, SIGTTIN, SIGTTOU }; -#endif /* TTY_PGRP */ - -static void j_set_async ARGS((Job *j)); -static void j_startjob ARGS((Job *j)); -static int j_waitj ARGS((Job *j, int flags, const char *where)); -static RETSIGTYPE j_sigchld ARGS((int sig)); -static void j_print ARGS((Job *j, int how, struct shf *shf)); -static Job *j_lookup ARGS((const char *cp, int *ecodep)); -static Job *new_job ARGS((void)); -static Proc *new_proc ARGS((void)); -static void check_job ARGS((Job *j)); -static void put_job ARGS((Job *j, int where)); -static void remove_job ARGS((Job *j, const char *where)); -static int kill_job ARGS((Job *j, int sig)); +#endif /* JOBS */ + +static void j_set_async(Job *j); +static void j_startjob(Job *j); +static int j_waitj(Job *j, int flags, const char *where); +static void j_sigchld(int sig); +static void j_print(Job *j, int how, struct shf *shf); +static Job *j_lookup(const char *cp, int *ecodep); +static Job *new_job(void); +static Proc *new_proc(void); +static void check_job(Job *j); +static void put_job(Job *j, int where); +static void remove_job(Job *j, const char *where); +static int kill_job(Job *j, int sig); /* initialize job control */ void @@ -230,7 +146,6 @@ j_init(mflagset) { child_max = CHILD_MAX; /* so syscon() isn't always being called */ -#ifdef JOB_SIGS sigemptyset(&sm_default); sigprocmask(SIG_SETMASK, &sm_default, (sigset_t *) 0); @@ -239,10 +154,6 @@ j_init(mflagset) setsig(&sigtraps[SIGCHLD], j_sigchld, SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP); -#else /* JOB_SIGS */ - /* Make sure SIGCHLD isn't ignored - can do odd things under SYSV */ - setsig(&sigtraps[SIGCHLD], SIG_DFL, SS_RESTORE_ORIG|SS_FORCE); -#endif /* JOB_SIGS */ #ifdef JOBS if (!mflagset && Flag(FTALKING)) @@ -253,7 +164,6 @@ j_init(mflagset) */ shl_j = shf_fdopen(2, SHF_WR, (struct shf *) 0); -# ifdef TTY_PGRP if (Flag(FMONITOR) || Flag(FTALKING)) { int i; @@ -267,7 +177,6 @@ j_init(mflagset) SS_RESTORE_IGN|SS_FORCE); } } -# endif /* TTY_PGRP */ /* j_change() calls tty_init() */ if (Flag(FMONITOR)) @@ -314,7 +223,6 @@ j_exit() j_notify(); #ifdef JOBS -# ifdef TTY_PGRP if (kshpid == procpid && restore_ttypgrp >= 0) { /* Need to restore the tty pgrp to what it was when the * shell started up, so that the process that started us @@ -326,7 +234,6 @@ j_exit() tcsetpgrp(tty_fd, restore_ttypgrp); setpgid(0, restore_ttypgrp); } -# endif /* TTY_PGRP */ if (Flag(FMONITOR)) { Flag(FMONITOR) = 0; j_change(); @@ -345,11 +252,10 @@ j_change() /* Don't call get_tty() 'til we own the tty process group */ tty_init(FALSE); -# ifdef TTY_PGRP /* no controlling tty, no SIGT* */ ttypgrp_ok = tty_fd >= 0 && tty_devtty; - if (ttypgrp_ok && (our_pgrp = getpgID()) < 0) { + if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) { warningf(FALSE, "j_init: getpgrp() failed: %s", strerror(errno)); ttypgrp_ok = 0; @@ -393,23 +299,11 @@ j_change() our_pgrp = kshpid; } } -# if defined(NTTYDISC) && defined(TIOCSETD) && !defined(HAVE_TERMIOS_H) && !defined(HAVE_TERMIO_H) - if (ttypgrp_ok) { - int ldisc = NTTYDISC; - - if (ioctl(tty_fd, TIOCSETD, &ldisc) < 0) - warningf(FALSE, - "j_init: can't set new line discipline: %s", - strerror(errno)); - } -# endif /* NTTYDISC && TIOCSETD */ if (!ttypgrp_ok) warningf(FALSE, "warning: won't have full job control"); -# endif /* TTY_PGRP */ if (tty_fd >= 0) get_tty(tty_fd, &tty_state); } else { -# ifdef TTY_PGRP ttypgrp_ok = 0; if (Flag(FTALKING)) for (i = NELEM(tt_sigs); --i >= 0; ) @@ -423,7 +317,6 @@ j_change() (sigtraps[tt_sigs[i]].flags & TF_ORIG_IGN) ? SIG_IGN : SIG_DFL, SS_RESTORE_ORIG|SS_FORCE); } -# endif /* TTY_PGRP */ if (!Flag(FTALKING)) tty_close(); } @@ -440,9 +333,7 @@ exchild(t, flags, close_fd) static Proc *last_proc; /* for pipelines */ int i; -#ifdef JOB_SIGS sigset_t omask; -#endif /* JOB_SIGS */ Proc *p; Job *j; int rv = 0; @@ -455,15 +346,13 @@ exchild(t, flags, close_fd) */ return execute(t, flags & (XEXEC | XERROK)); -#ifdef JOB_SIGS /* no SIGCHLD's while messing with job and process lists */ sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ p = new_proc(); p->next = (Proc *) 0; p->state = PRUNNING; - WSTATUS(p->status) = 0; + p->status = 0; p->pid = 0; /* link process into jobs list */ @@ -474,17 +363,6 @@ exchild(t, flags, close_fd) last_proc->next = p; last_proc = p; } else { -#ifdef NEED_PGRP_SYNC - if (j_sync_open) { /* should never happen */ - j_sync_open = 0; - closepipe(j_sync_pipe); - } - /* don't do the sync pipe business if there is no pipeline */ - if (flags & XPIPEO) { - openpipe(j_sync_pipe); - j_sync_open = 1; - } -#endif /* NEED_PGRP_SYNC */ j = new_job(); /* fills in j->job */ /* we don't consider XXCOM's foreground since they don't get * tty process group and we don't save or restore tty modes. @@ -518,15 +396,7 @@ exchild(t, flags, close_fd) if (i < 0) { kill_job(j, SIGKILL); remove_job(j, "fork failed"); -#ifdef NEED_PGRP_SYNC - if (j_sync_open) { - closepipe(j_sync_pipe); - j_sync_open = 0; - } -#endif /* NEED_PGRP_SYNC */ -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ errorf("cannot fork - try again"); } ischild = i == 0; @@ -539,29 +409,6 @@ exchild(t, flags, close_fd) /* job control set up */ if (Flag(FMONITOR) && !(flags&XXCOM)) { int dotty = 0; -# ifdef NEED_PGRP_SYNC - int first_child_sync = 0; -# endif /* NEED_PGRP_SYNC */ - -# ifdef NEED_PGRP_SYNC - if (j_sync_open) { - /* - * The Parent closes 0, keeps 1 open 'til the whole - * pipeline is started. The First child closes 1, - * keeps 0 open (reads from it). The remaining - * children just have to close 1 (parent has already - * closeed 0). - */ - if (j->pgrp == 0) { /* First process */ - close(j_sync_pipe[ischild]); - j_sync_pipe[ischild] = -1; - first_child_sync = ischild; - } else if (ischild) { - j_sync_open = 0; - closepipe(j_sync_pipe); - } - } -# endif /* NEED_PGRP_SYNC */ if (j->pgrp == 0) { /* First process */ j->pgrp = p->pid; dotty = 1; @@ -571,7 +418,6 @@ exchild(t, flags, close_fd) * condition */ setpgid(p->pid, j->pgrp); -# ifdef TTY_PGRP /* YYY: should this be if (ttypgrp_ok && ischild && !(flags&XBGND)) tcsetpgrp(tty_fd, j->pgrp); @@ -579,17 +425,6 @@ exchild(t, flags, close_fd) */ if (ttypgrp_ok && dotty && !(flags & XBGND)) tcsetpgrp(tty_fd, j->pgrp); -# endif /* TTY_PGRP */ -# ifdef NEED_PGRP_SYNC - if (first_child_sync) { - char c; - while (read(j_sync_pipe[0], &c, 1) == -1 - && errno == EINTR) - ; - close(j_sync_pipe[0]); - j_sync_open = 0; - } -# endif /* NEED_PGRP_SYNC */ } #endif /* JOBS */ @@ -603,11 +438,9 @@ exchild(t, flags, close_fd) if (flags & XCOPROC) coproc_cleanup(FALSE); #endif /* KSH */ -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ cleanup_parents_env(); -#ifdef TTY_PGRP +#ifdef JOBS /* If FMONITOR or FTALKING is set, these signals are ignored, * if neither FMONITOR nor FTALKING are set, the signals have * their inherited values. @@ -617,11 +450,9 @@ exchild(t, flags, close_fd) setsig(&sigtraps[tt_sigs[i]], SIG_DFL, SS_RESTORE_DFL|SS_FORCE); } -#endif /* TTY_PGRP */ -#ifdef HAVE_NICE +#endif /* JOBS */ if (Flag(FBGNICE) && (flags & XBGND)) nice(4); -#endif /* HAVE_NICE */ if ((flags & XBGND) && !Flag(FMONITOR)) { setsig(&sigtraps[SIGINT], SIG_IGN, SS_RESTORE_IGN|SS_FORCE); @@ -642,10 +473,6 @@ exchild(t, flags, close_fd) Flag(FMONITOR) = 0; #endif /* JOBS */ Flag(FTALKING) = 0; -#ifdef OS2 - if (tty_fd >= 0) - flags |= XINTACT; -#endif /* OS2 */ tty_close(); cleartraps(); execute(t, (flags & XERROK) | XEXEC); /* no return */ @@ -658,12 +485,12 @@ exchild(t, flags, close_fd) /* Ensure next child gets a (slightly) different $RANDOM sequence */ change_random(); if (!(flags & XPIPEO)) { /* last process in a job */ -#ifdef TTY_PGRP +#ifdef JOBS /* YYY: Is this needed? (see also YYY above) if (Flag(FMONITOR) && !(flags&(XXCOM|XBGND))) tcsetpgrp(tty_fd, j->pgrp); */ -#endif /* TTY_PGRP */ +#endif /* JOBS */ j_startjob(j); #ifdef KSH if (flags & XCOPROC) { @@ -685,9 +512,7 @@ exchild(t, flags, close_fd) rv = j_waitj(j, JW_NONE, "jw:last proc"); } -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return rv; } @@ -696,20 +521,16 @@ exchild(t, flags, close_fd) void startlast() { -#ifdef JOB_SIGS sigset_t omask; sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ if (last_job) { /* no need to report error - waitlast() will do it */ /* ensure it isn't removed by check_job() */ last_job->flags |= JF_WAITING; j_startjob(last_job); } -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ } /* wait for last job: only used for `command` jobs */ @@ -718,11 +539,9 @@ waitlast() { int rv; Job *j; -#ifdef JOB_SIGS sigset_t omask; sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ j = last_job; if (!j || !(j->flags & JF_STARTED)) { @@ -730,17 +549,13 @@ waitlast() warningf(TRUE, "waitlast: no last job"); else internal_errorf(0, "waitlast: not started"); -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return 125; /* not so arbitrary, non-zero value */ } rv = j_waitj(j, JW_NONE, "jw:waitlast"); -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return rv; } @@ -755,11 +570,9 @@ waitfor(cp, sigp) Job *j; int ecode; int flags = JW_INTERRUPT|JW_ASYNCNOTIFY; -#ifdef JOB_SIGS sigset_t omask; sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ *sigp = 0; @@ -772,24 +585,18 @@ waitfor(cp, sigp) if (j->ppid == procpid && j->state == PRUNNING) break; if (!j) { -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return -1; } } else if ((j = j_lookup(cp, &ecode))) { /* don't report normal job completion */ flags &= ~JW_ASYNCNOTIFY; if (j->ppid != procpid) { -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return -1; } } else { -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ if (ecode != JL_NOSUCH) bi_errorf("%s: %s", cp, lookup_msgs[ecode]); return -1; @@ -798,9 +605,7 @@ waitfor(cp, sigp) /* at&t ksh will wait for stopped jobs - we don't */ rv = j_waitj(j, flags, "jw:waitfor"); -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ if (rv < 0) /* we were interrupted */ *sigp = 128 + -rv; @@ -818,16 +623,12 @@ j_kill(cp, sig) Proc *p; int rv = 0; int ecode; -#ifdef JOB_SIGS sigset_t omask; sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ if ((j = j_lookup(cp, &ecode)) == (Job *) 0) { -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ bi_errorf("%s: %s", cp, lookup_msgs[ecode]); return 1; } @@ -848,9 +649,7 @@ j_kill(cp, sig) } } -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return rv; } @@ -890,7 +689,7 @@ j_resume(cp, bg) for (p = j->proc_list; p != (Proc *) 0; p = p->next) { if (p->state == PSTOPPED) { p->state = PRUNNING; - WSTATUS(p->status) = 0; + p->status = 0; running = 1; } shprintf("%s%s", p->command, p->next ? "| " : null); @@ -904,7 +703,7 @@ j_resume(cp, bg) if (bg) j_set_async(j); else { -# ifdef TTY_PGRP +# ifdef JOBS /* attach tty to job */ if (j->state == PRUNNING) { if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) { @@ -922,7 +721,7 @@ j_resume(cp, bg) return 1; } } -# endif /* TTY_PGRP */ +# endif /* JOBS */ j->flags |= JF_FG; j->flags &= ~JF_KNOWN; if (j == async_job) @@ -934,7 +733,7 @@ j_resume(cp, bg) if (!bg) { j->flags &= ~JF_FG; -# ifdef TTY_PGRP +# ifdef JOBS if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) { set_tty(tty_fd, &tty_state, TF_NONE); } @@ -944,7 +743,7 @@ j_resume(cp, bg) tty_fd, (int) our_pgrp, strerror(errno)); } -# endif /* TTY_PGRP */ +# endif /* JOBS */ } sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); bi_errorf("cannot continue job %s: %s", @@ -952,11 +751,11 @@ j_resume(cp, bg) return 1; } if (!bg) { -# ifdef TTY_PGRP +# ifdef JOBS if (ttypgrp_ok) { j->flags &= ~(JF_SAVEDTTY | JF_SAVEDTTYPGRP); } -# endif /* TTY_PGRP */ +# endif /* JOBS */ rv = j_waitj(j, JW_NONE, "jw:resume"); } sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); @@ -996,17 +795,13 @@ j_njobs(void) { Job *j; int nj = 0; -#ifdef JOB_SIGS sigset_t omask; sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ for (j = job_list; j; j = j->next) nj++; -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return nj; } @@ -1021,11 +816,9 @@ j_jobs(cp, slp, nflag) Job *j, *tmp; int how; int zflag = 0; -#ifdef JOB_SIGS sigset_t omask; sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ if (nflag < 0) { /* kludge: print zombies */ nflag = 0; @@ -1035,9 +828,7 @@ j_jobs(cp, slp, nflag) int ecode; if ((j = j_lookup(cp, &ecode)) == (Job *) 0) { -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ bi_errorf("%s: %s", cp, lookup_msgs[ecode]); return 1; } @@ -1061,9 +852,7 @@ j_jobs(cp, slp, nflag) if (j->flags & JF_REMOVE) remove_job(j, "jobs"); } -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return 0; } @@ -1072,11 +861,9 @@ void j_notify() { Job *j, *tmp; -#ifdef JOB_SIGS sigset_t omask; sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ for (j = job_list; j; j = j->next) { #ifdef JOBS if (Flag(FMONITOR) && (j->flags & JF_CHANGED)) @@ -1094,27 +881,21 @@ j_notify() remove_job(j, "notify"); } shf_flush(shl_out); -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ } /* Return pid of last process in last asynchronous job */ pid_t j_async() { -#ifdef JOB_SIGS sigset_t omask; sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); -#endif /* JOB_SIGS */ if (async_job) async_job->flags |= JF_KNOWN; -#ifdef JOB_SIGS sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); -#endif /* JOB_SIGS */ return async_pid; } @@ -1170,19 +951,11 @@ j_startjob(j) ; j->last_proc = p; -#ifdef NEED_PGRP_SYNC - if (j_sync_open) { - j_sync_open = 0; - closepipe(j_sync_pipe); - } -#endif /* NEED_PGRP_SYNC */ -#ifdef JOB_SIGS if (held_sigchld) { held_sigchld = 0; /* Don't call j_sigchld() as it may remove job... */ kill(procpid, SIGCHLD); } -#endif /* JOB_SIGS */ } /* @@ -1212,11 +985,7 @@ j_waitj(j, flags, where) || ((flags & JW_STOPPEDWAIT) && (volatile int) j->state == PSTOPPED)) { -#ifdef JOB_SIGS sigsuspend(&sm_default); -#else /* JOB_SIGS */ - j_sigchld(SIGCHLD); -#endif /* JOB_SIGS */ if (fatal_trap) { int oldf = j->flags & (JF_WAITING|JF_W_ASYNCNOTIFY); j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY); @@ -1231,10 +1000,10 @@ j_waitj(j, flags, where) j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY); if (j->flags & JF_FG) { - WAIT_T status; + int status; j->flags &= ~JF_FG; -#ifdef TTY_PGRP +#ifdef JOBS if (Flag(FMONITOR) && ttypgrp_ok && j->pgrp) { /* * Save the tty's current pgrp so it can be restored @@ -1261,7 +1030,7 @@ j_waitj(j, flags, where) get_tty(tty_fd, &j->ttystate); } } -#endif /* TTY_PGRP */ +#endif /* JOBS */ if (tty_fd >= 0) { /* Only restore tty settings if job was originally * started in the foreground. Problems can be @@ -1328,18 +1097,17 @@ j_waitj(j, flags, where) * * If jobs are compiled in then this routine expects sigchld to be blocked. */ -static RETSIGTYPE +static void j_sigchld(sig) int sig; { int errno_ = errno; Job *j; - Proc UNINITIALIZED(*p); + Proc *p = NULL; int pid; - WAIT_T status; + int status; struct tms t0, t1; -#ifdef JOB_SIGS /* Don't wait for any processes if a job is partially started. * This is so we don't do away with the process group leader * before all the processes in a pipe line are started (so the @@ -1348,22 +1116,17 @@ j_sigchld(sig) for (j = job_list; j; j = j->next) if (j->ppid == procpid && !(j->flags & JF_STARTED)) { held_sigchld = 1; - return RETSIGVAL; + return; } -#endif /* JOB_SIGS */ - ksh_times(&t0); + times(&t0); do { -#ifdef JOB_SIGS - pid = ksh_waitpid(-1, &status, (WNOHANG|WUNTRACED)); -#else /* JOB_SIGS */ - pid = wait(&status); -#endif /* JOB_SIGS */ + pid = waitpid(-1, &status, (WNOHANG|WUNTRACED)); if (pid <= 0) /* return if would block (0) ... */ break; /* ... or no children or interrupted (-1) */ - ksh_times(&t1); + times(&t1); /* find job and process structures for this pid */ for (j = job_list; j != (Job *) 0; j = j->next) @@ -1396,15 +1159,9 @@ found: check_job(j); /* check to see if entire job is done */ } -#ifdef JOB_SIGS while (1); -#else /* JOB_SIGS */ - while (0); -#endif /* JOB_SIGS */ errno = errno_; - - return RETSIGVAL; } /* @@ -1532,7 +1289,7 @@ j_print(j, how, shf) { Proc *p; int state; - WAIT_T status; + int status; int coredumped; char jobchar = ' '; char buf[64]; @@ -1575,7 +1332,7 @@ j_print(j, how, shf) WEXITSTATUS(p->status)); break; case PSIGNALLED: - if (WIFCORED(p->status)) + if (WCOREDUMP(p->status)) coredumped = 1; /* kludge for not reporting `normal termination signals' * (ie, SIGINT, SIGPIPE) @@ -1616,8 +1373,7 @@ j_print(j, how, shf) state = p->state; status = p->status; p = p->next; - while (p && p->state == state - && WSTATUS(p->status) == WSTATUS(status)) + while (p && p->state == state && p->status == status) { if (how == JP_LONG) shf_fprintf(shf, "%s%5d %-20s %s%s", filler, p->pid, diff --git a/bin/ksh/ksh_dir.h b/bin/ksh/ksh_dir.h deleted file mode 100644 index 34c981fedc1..00000000000 --- a/bin/ksh/ksh_dir.h +++ /dev/null @@ -1,26 +0,0 @@ -/* $OpenBSD: ksh_dir.h,v 1.1 1996/08/14 06:19:11 downsj Exp $ */ - -/* Wrapper around the ugly dir includes/ifdefs */ - -#if defined(HAVE_DIRENT_H) -# include <dirent.h> -# define NLENGTH(dirent) (strlen(dirent->d_name)) -#else -# define dirent direct -# define NLENGTH(dirent) (dirent->d_namlen) -# ifdef HAVE_SYS_NDIR_H -# include <sys/ndir.h> -# endif /* HAVE_SYS_NDIR_H */ -# ifdef HAVE_SYS_DIR_H -# include <sys/dir.h> -# endif /* HAVE_SYSDIR_H */ -# ifdef HAVE_NDIR_H -# include <ndir.h> -# endif /* HAVE_NDIR_H */ -#endif /* HAVE_DIRENT_H */ - -#ifdef OPENDIR_DOES_NONDIR -extern DIR *ksh_opendir ARGS((const char *d)); -#else /* OPENDIR_DOES_NONDIR */ -# define ksh_opendir(d) opendir(d) -#endif /* OPENDIR_DOES_NONDIR */ diff --git a/bin/ksh/ksh_limval.h b/bin/ksh/ksh_limval.h index 828c0f82577..d8ff7b5c266 100644 --- a/bin/ksh/ksh_limval.h +++ b/bin/ksh/ksh_limval.h @@ -1,24 +1,13 @@ -/* $OpenBSD: ksh_limval.h,v 1.1 1996/08/14 06:19:11 downsj Exp $ */ +/* $OpenBSD: ksh_limval.h,v 1.2 2004/12/18 20:55:52 millert Exp $ */ /* Wrapper around the values.h/limits.h includes/ifdefs */ -#ifdef HAVE_VALUES_H -# include <values.h> -#endif /* HAVE_VALUES_H */ /* limits.h is included in sh.h */ #ifndef DMAXEXP # define DMAXEXP 128 /* should be big enough */ #endif -#ifndef BITSPERBYTE -# ifdef CHAR_BIT -# define BITSPERBYTE CHAR_BIT -# else -# define BITSPERBYTE 8 /* probably true.. */ -# endif -#endif - #ifndef BITS -# define BITS(t) (BITSPERBYTE * sizeof(t)) +# define BITS(t) (CHAR_BIT * sizeof(t)) #endif diff --git a/bin/ksh/ksh_stat.h b/bin/ksh/ksh_stat.h deleted file mode 100644 index 1abcc7cb1fc..00000000000 --- a/bin/ksh/ksh_stat.h +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: ksh_stat.h,v 1.3 1996/10/01 02:05:39 downsj Exp $ */ - -/* Wrapper around the ugly sys/stat includes/ifdefs */ - -/* assumes <sys/types.h> already included */ -#include <sys/stat.h> - -#ifndef HAVE_LSTAT -# define lstat(path, buf) stat(path, buf) -#endif /* HAVE_LSTAT */ - -#ifdef STAT_MACROS_BROKEN -# undef S_ISREG -# undef S_ISDIR -# undef S_ISCHR -# undef S_ISBLK -# undef S_ISFIFO -# undef S_ISSOCK -# undef S_ISLNK -#endif /* STAT_MACROS_BROKEN */ - -#if !defined(S_ISREG) && defined(S_IFREG) -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif /* S_ISREG */ -#if !defined(S_ISDIR) && defined(S_IFDIR) -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif /* S_ISDIR */ -#if !defined(S_ISCHR) && defined(S_IFCHR) -# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -#endif /* S_ISCHR */ -#if !defined(S_ISBLK) && defined(S_IFBLK) -# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -#endif /* S_ISBLK */ -#if !defined(S_ISFIFO) && defined(S_IFIFO) -# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) -#endif /* S_ISFIFO */ -#if !defined(S_ISLNK) && defined(S_IFLNK) -# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#endif /* S_ISLNK */ -#if !defined(S_ISSOCK) && defined(S_IFSOCK) -# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) -#endif /* S_ISSOCK */ -#if !defined(S_ISCDF) && defined(S_CDF) -# define S_ISCDF(m) (S_ISDIR(m) && ((m) & S_CDF)) -#endif /* S_ISSOCK */ - -#ifndef S_ISVTX -# define S_ISVTX 01000 /* sticky bit */ -#endif /* S_ISVTX */ - -#ifndef S_IXUSR -# define S_IXUSR 00100 /* user execute bit */ -#endif /* S_IXUSR */ -#ifndef S_IXGRP -# define S_IXGRP 00010 /* user execute bit */ -#endif /* S_IXGRP */ -#ifndef S_IXOTH -# define S_IXOTH 00001 /* user execute bit */ -#endif /* S_IXOTH */ diff --git a/bin/ksh/ksh_time.h b/bin/ksh/ksh_time.h deleted file mode 100644 index ee8dc9b9128..00000000000 --- a/bin/ksh/ksh_time.h +++ /dev/null @@ -1,26 +0,0 @@ -/* $OpenBSD: ksh_time.h,v 1.2 1996/10/01 02:05:40 downsj Exp $ */ - -#ifndef KSH_TIME_H -# define KSH_TIME_H - -/* Wrapper around the ugly time.h,sys/time.h includes/ifdefs */ - -#ifdef TIME_WITH_SYS_TIME -# include <sys/time.h> -# include <time.h> -#else /* TIME_WITH_SYS_TIME */ -# ifdef HAVE_SYS_TIME_H -# include <sys/time.h> -# else -# include <time.h> -# endif -#endif /* TIME_WITH_SYS_TIME */ - -#ifndef TIME_DECLARED -extern time_t time ARGS((time_t *)); -#endif - -#ifndef CLK_TCK -# define CLK_TCK 60 /* 60HZ */ -#endif -#endif /* KSH_TIME_H */ diff --git a/bin/ksh/ksh_times.h b/bin/ksh/ksh_times.h deleted file mode 100644 index ec7b97eedf5..00000000000 --- a/bin/ksh/ksh_times.h +++ /dev/null @@ -1,20 +0,0 @@ -/* $OpenBSD: ksh_times.h,v 1.2 1996/10/01 02:05:41 downsj Exp $ */ - -#ifndef KSH_TIMES_H -# define KSH_TIMES_H - -/* Needed for clock_t on some systems (ie, NeXT in non-posix mode) */ -#include "ksh_time.h" - -#include <sys/times.h> - -#ifdef TIMES_BROKEN -extern clock_t ksh_times ARGS((struct tms *)); -#else /* TIMES_BROKEN */ -# define ksh_times times -#endif /* TIMES_BROKEN */ - -#ifdef HAVE_TIMES -extern clock_t times ARGS((struct tms *)); -#endif /* HAVE_TIMES */ -#endif /* KSH_TIMES_H */ diff --git a/bin/ksh/ksh_wait.h b/bin/ksh/ksh_wait.h deleted file mode 100644 index a077b90f16b..00000000000 --- a/bin/ksh/ksh_wait.h +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: ksh_wait.h,v 1.3 1997/06/19 13:58:43 kstailey Exp $ */ - -/* Wrapper around the ugly sys/wait includes/ifdefs */ - -#ifdef HAVE_SYS_WAIT_H -# include <sys/wait.h> -#endif - -#ifndef POSIX_SYS_WAIT -/* Get rid of system macros (which probably use union wait) */ -# undef WIFCORED -# undef WIFEXITED -# undef WEXITSTATUS -# undef WIFSIGNALED -# undef WTERMSIG -# undef WIFSTOPPED -# undef WSTOPSIG -#endif /* POSIX_SYS_WAIT */ - -typedef int WAIT_T; - -#ifndef WIFCORED -# define WIFCORED(s) ((s) & 0x80) -#endif -#define WSTATUS(s) (s) - -#ifndef WIFEXITED -# define WIFEXITED(s) (((s) & 0xff) == 0) -#endif -#ifndef WEXITSTATUS -# define WEXITSTATUS(s) (((s) >> 8) & 0xff) -#endif -#ifndef WIFSIGNALED -# define WIFSIGNALED(s) (((s) & 0xff) != 0 && ((s) & 0xff) != 0x7f) -#endif -#ifndef WTERMSIG -# define WTERMSIG(s) ((s) & 0x7f) -#endif -#ifndef WIFSTOPPED -# define WIFSTOPPED(s) (((s) & 0xff) == 0x7f) -#endif -#ifndef WSTOPSIG -# define WSTOPSIG(s) (((s) >> 8) & 0xff) -#endif - -#if !defined(HAVE_WAITPID) && defined(HAVE_WAIT3) - /* always used with p == -1 */ -# define ksh_waitpid(p, s, o) wait3((s), (o), (struct rusage *) 0) -#else /* !HAVE_WAITPID && HAVE_WAIT3 */ -# define ksh_waitpid(p, s, o) waitpid((p), (s), (o)) -#endif /* !HAVE_WAITPID && HAVE_WAIT3 */ diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c index a505b9cebc8..40e7821c66f 100644 --- a/bin/ksh/lex.c +++ b/bin/ksh/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.23 2004/12/12 06:53:13 deraadt Exp $ */ +/* $OpenBSD: lex.c,v 1.24 2004/12/18 20:55:52 millert Exp $ */ /* * lexical analysis and source input @@ -53,16 +53,16 @@ struct State_info { }; -static void readhere ARGS((struct ioword *iop)); -static int getsc__ ARGS((void)); -static void getsc_line ARGS((Source *s)); -static int getsc_bn ARGS((void)); -static char *get_brace_var ARGS((XString *wsp, char *wp)); -static int arraysub ARGS((char **strp)); -static const char *ungetsc ARGS((int c)); -static void gethere ARGS((void)); -static Lex_state *push_state_ ARGS((State_info *si, Lex_state *old_end)); -static Lex_state *pop_state_ ARGS((State_info *si, Lex_state *old_end)); +static void readhere(struct ioword *iop); +static int getsc__(void); +static void getsc_line(Source *s); +static int getsc_bn(void); +static char *get_brace_var(XString *wsp, char *wp); +static int arraysub(char **strp); +static const char *ungetsc(int c); +static void gethere(void); +static Lex_state *push_state_(State_info *si, Lex_state *old_end); +static Lex_state *pop_state_(State_info *si, Lex_state *old_end); static int backslash_skip; static int ignore_backslash_newline; @@ -275,12 +275,6 @@ yylex(cf) switch (c) { case '\\': c = getsc(); -#ifdef OS2 - if (isalnum(c)) { - *wp++ = CHAR, *wp++ = '\\'; - *wp++ = CHAR, *wp++ = c; - } else -#endif if (c) /* trailing \ is lost */ *wp++ = QCHAR, *wp++ = c; break; @@ -903,13 +897,7 @@ readhere(iop) } void -#ifdef HAVE_PROTOTYPES yyerror(const char *fmt, ...) -#else -yyerror(fmt, va_alist) - const char *fmt; - va_dcl -#endif { va_list va; @@ -919,7 +907,7 @@ yyerror(fmt, va_alist) source->str = null; /* zap pending input */ error_prefix(TRUE); - SH_VA_START(va, fmt); + va_start(va, fmt); shf_vfprintf(shl_out, fmt, va); va_end(va); errorf(null); @@ -1152,15 +1140,8 @@ getsc_line(s) while (*p && ctype(*p, C_IFS) && ctype(*p, C_IFSWS)) p++; if (*p) { -# ifdef EASY_HISTORY - if (cur_prompt == PS2) - histappend(Xstring(s->xs, xp), 1); - else -# endif /* EASY_HISTORY */ - { - s->line++; - histsave(s->line, s->str, 1); - } + s->line++; + histsave(s->line, s->str, 1); } #endif /* HISTORY */ } @@ -1191,7 +1172,7 @@ set_prompt(to, s) ps1 = shf_sclose(shf); saved_atemp = ATEMP; newenv(E_ERRH); - if (ksh_sigsetjmp(e->jbuf, 0)) { + if (sigsetjmp(e->jbuf, 0)) { prompt = safe_prompt; /* Don't print an error - assume it has already * been printed. Reason is we may have forked @@ -1632,7 +1613,7 @@ ungetsc(c) /* Called to get a char that isn't a \newline sequence. */ static int -getsc_bn ARGS((void)) +getsc_bn(void) { int c, c2; diff --git a/bin/ksh/mail.c b/bin/ksh/mail.c index c0f0b1fe17c..3429935ff02 100644 --- a/bin/ksh/mail.c +++ b/bin/ksh/mail.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mail.c,v 1.9 1999/06/15 01:18:35 millert Exp $ */ +/* $OpenBSD: mail.c,v 1.10 2004/12/18 20:55:52 millert Exp $ */ /* * Mailbox checking code by Robert J. Gibson, adapted for PD ksh by @@ -9,8 +9,8 @@ #ifdef KSH #include "sh.h" -#include "ksh_stat.h" -#include "ksh_time.h" +#include <sys/stat.h> +#include <time.h> #define MBMESSAGE "you have mail in $_" @@ -32,9 +32,9 @@ static mbox_t mbox; static time_t mlastchkd; /* when mail was last checked */ static time_t mailcheck_interval; -static void munset ARGS((mbox_t *mlist)); /* free mlist and mval */ -static mbox_t * mballoc ARGS((char *p, char *m)); /* allocate a new mbox */ -static void mprintit ARGS((mbox_t *mbp)); +static void munset(mbox_t *mlist); /* free mlist and mval */ +static mbox_t * mballoc(char *p, char *m); /* allocate a new mbox */ +static void mprintit(mbox_t *mbp); void mcheck() @@ -119,7 +119,7 @@ mpset(mptoparse) mval = str_save(mptoparse, APERM); while (mval) { mpath = mval; - if ((mval = strchr(mval, PATHSEP)) != NULL) { + if ((mval = strchr(mval, ':')) != NULL) { *mval = '\0', mval++; } /* POSIX/bourne-shell say file%message */ diff --git a/bin/ksh/main.c b/bin/ksh/main.c index 8c7b8b95469..361d40478c7 100644 --- a/bin/ksh/main.c +++ b/bin/ksh/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.28 2004/08/23 14:56:32 millert Exp $ */ +/* $OpenBSD: main.c,v 1.29 2004/12/18 20:55:52 millert Exp $ */ /* * startup, main loop, environments and error handling @@ -7,8 +7,7 @@ #define EXTERN /* define EXTERNs in sh.h */ #include "sh.h" -#include "ksh_stat.h" -#include "ksh_time.h" +#include <sys/stat.h> extern char **environ; @@ -16,9 +15,9 @@ extern char **environ; * global data */ -static void reclaim ARGS((void)); -static void remove_temps ARGS((struct temp *tp)); -static int is_restricted ARGS((char *name)); +static void reclaim(void); +static void remove_temps(struct temp *tp); +static int is_restricted(char *name); /* * shell initialization @@ -66,9 +65,6 @@ static const char *const initcoms [] = { #ifdef KSH /* Aliases that are builtin commands in at&t */ "login=exec login", -#ifndef __OpenBSD__ - "newgrp=exec newgrp", -#endif /* __OpenBSD__ */ #endif /* KSH */ NULL, /* this is what at&t ksh seems to track, with the addition of emacs */ @@ -76,9 +72,6 @@ static const char *const initcoms [] = { "cat", "cc", "chmod", "cp", "date", "ed", "emacs", "grep", "ls", "mail", "make", "mv", "pr", "rm", "sed", "sh", "vi", "who", NULL, -#ifdef EXTRA_INITCOMS - EXTRA_INITCOMS, NULL, -#endif /* EXTRA_INITCOMS */ NULL }; @@ -94,16 +87,6 @@ main(int argc, char *argv[]) struct env env; pid_t ppid; -#ifdef MEM_DEBUG - chmem_set_defaults("ct", 1); - /* chmem_push("+c", 1); */ -#endif /* MEM_DEBUG */ - -#ifdef OS2 - setmode (0, O_BINARY); - setmode (1, O_TEXT); -#endif - /* make sure argv[] is sane */ if (!*argv) { static const char *empty_argv[] = { @@ -154,8 +137,7 @@ main(int argc, char *argv[]) init_histvec(); - def_path = DEFAULT__PATH; -#if defined(HAVE_CONFSTR) && defined(_CS_PATH) + def_path = _PATH_DEFPATH; { size_t len = confstr(_CS_PATH, (char *) 0, 0); char *new; @@ -165,7 +147,6 @@ main(int argc, char *argv[]) def_path = new; } } -#endif /* HAVE_CONFSTR && _CS_PATH */ /* Set PATH to def_path (will set the path global variable). * (import of environment below will probably change this setting). @@ -237,7 +218,7 @@ main(int argc, char *argv[]) char *pwdx = pwd; /* Try to use existing $PWD if it is valid */ - if (!ISABSPATH(pwd) + if (pwd[0] != '/' || stat(pwd, &s_pwd) < 0 || stat(".", &s_dot) < 0 || s_pwd.st_dev != s_dot.st_dev || s_pwd.st_ino != s_dot.st_ino) @@ -254,9 +235,6 @@ main(int argc, char *argv[]) } ppid = getppid(); setint(global("PPID"), (long) ppid); -#if defined(KSH) && !defined(__OpenBSD__) - setint(global("RANDOM"), (long) (time((time_t *)0) * kshpid * ppid)); -#endif /* KSH */ /* setstr can't fail here */ setstr(global(version_param), ksh_version, KSH_RETURN_ERROR); @@ -299,18 +277,7 @@ main(int argc, char *argv[]) kshname = argv[argi++]; } else if (argi < argc && !Flag(FSTDIN)) { s = pushs(SFILE, ATEMP); -#ifdef OS2 - /* a bug in os2 extproc shell processing doesn't - * pass full pathnames so we have to search for it. - * This changes the behavior of 'ksh arg' to search - * the users search path but it can't be helped. - */ - s->file = search(argv[argi++], path, R_OK, (int *) 0); - if (!s->file || !*s->file) - s->file = argv[argi - 1]; -#else s->file = argv[argi++]; -#endif /* OS2 */ s->u.shf = shf_open(s->file, O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC); if (s->u.shf == NULL) { exstat = 127; /* POSIX */ @@ -370,27 +337,10 @@ main(int argc, char *argv[]) warningf(FALSE, "Cannot determine current working directory"); if (Flag(FLOGIN)) { -#ifdef OS2 - char *profile; - - /* Try to find a profile - first see if $INIT has a value, - * then try /etc/profile.ksh, then c:/usr/etc/profile.ksh. - */ - if (!Flag(FPRIVILEGED) - && strcmp(profile = substitute("$INIT/profile.ksh", 0), - "/profile.ksh")) - include(profile, 0, (char **) 0, 1); - else if (include("/etc/profile.ksh", 0, (char **) 0, 1) < 0) - include("c:/usr/etc/profile.ksh", 0, (char **) 0, 1); - if (!Flag(FPRIVILEGED)) - include(substitute("$HOME/profile.ksh", 0), 0, - (char **) 0, 1); -#else /* OS2 */ include(KSH_SYSTEM_PROFILE, 0, (char **) 0, 1); if (!Flag(FPRIVILEGED)) include(substitute("$HOME/.profile", 0), 0, (char **) 0, 1); -#endif /* OS2 */ } if (Flag(FPRIVILEGED)) @@ -414,11 +364,6 @@ main(int argc, char *argv[]) env_file = substitute(env_file, DOTILDE); if (*env_file != '\0') include(env_file, 0, (char **) 0, 1); -#ifdef OS2 - else if (Flag(FTALKING)) - include(substitute("$HOME/kshrc.ksh", 0), 0, - (char **) 0, 1); -#endif /* OS2 */ } if (is_restricted(argv[0]) || is_restricted(str_val(global("SHELL")))) @@ -473,7 +418,7 @@ include(name, argc, argv, intr_ok) old_argc = 0; } newenv(E_INCL); - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (i) { if (s) /* Do this before quitenv(), which frees the memory */ shf_close(s->u.shf); @@ -549,7 +494,7 @@ shell(s, toplevel) newenv(E_PARSE); if (interactive) really_exit = 0; - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (i) { switch (i) { case LINTR: /* we get here if SIGINT not caught or ignored */ @@ -666,7 +611,7 @@ unwind(i) case E_INCL: case E_LOOP: case E_ERRH: - ksh_siglongjmp(e->jbuf, i); + siglongjmp(e->jbuf, i); /*NOTREACHED*/ case E_NONE: @@ -738,9 +683,6 @@ quitenv() kill(0, sig); } } -#ifdef MEM_DEBUG - chmem_allfree(); -#endif /* MEM_DEBUG */ } exit(exstat); } @@ -797,44 +739,10 @@ static void remove_temps(tp) struct temp *tp; { -#ifdef OS2 - static struct temp *delayed_remove; - struct temp *t, **tprev; - - if (delayed_remove) { - for (tprev = &delayed_remove, t = delayed_remove; t; t = *tprev) - /* No need to check t->pid here... */ - if (unlink(t->name) >= 0 || errno == ENOENT) { - *tprev = t->next; - afree(t, APERM); - } else - tprev = &t->next; - } -#endif /* OS2 */ for (; tp != NULL; tp = tp->next) if (tp->pid == procpid) { -#ifdef OS2 - /* OS/2 (and dos) do not allow files that are currently - * open to be removed, so we cache it away for future - * removal. - * XXX should only do this if errno - * is Efile-still-open-can't-remove - * (but I don't know what that is...) - */ - if (unlink(tp->name) < 0 && errno != ENOENT) { - t = (struct temp *) alloc( - sizeof(struct temp) + strlen(tp->name) + 1, - APERM); - memset(t, 0, sizeof(struct temp)); - t->name = (char *) &t[1]; - strlcpy(t->name, tp->name, strlen(tp->name) + 1); - t->next = delayed_remove; - delayed_remove = t; - } -#else /* OS2 */ unlink(tp->name); -#endif /* OS2 */ } } @@ -845,7 +753,7 @@ is_restricted(name) { char *p; - if ((p = ksh_strrchr_dirsep(name))) + if ((p = strrchr(name, '/'))) name = p; /* accepts rsh, rksh, rpdksh, pdrksh, etc. */ return (p = strchr(name, 'r')) && strstr(p, "sh"); diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c index 157b81bede2..8cb2d17be7e 100644 --- a/bin/ksh/misc.c +++ b/bin/ksh/misc.c @@ -1,25 +1,18 @@ -/* $OpenBSD: misc.c,v 1.21 2004/12/12 06:53:13 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.22 2004/12/18 20:55:52 millert Exp $ */ /* * Miscellaneous functions */ #include "sh.h" -#include <ctype.h> /* for FILECHCONV */ -#ifdef HAVE_LIMITS_H -# include <limits.h> -#endif - -#ifndef UCHAR_MAX -# define UCHAR_MAX 0xFF -#endif +#include <ctype.h> /* ??? Removing this changes generated code! */ +#include <sys/param.h> /* for MAXPATHLEN */ short ctypes [UCHAR_MAX+1]; /* type bits for unsigned char */ -static int do_gmatch ARGS((const unsigned char *s, const unsigned char *p, - const unsigned char *se, const unsigned char *pe, - int isfile)); -static const unsigned char *cclass ARGS((const unsigned char *p, int sub)); +static int do_gmatch(const unsigned char *s, const unsigned char *p, + const unsigned char *se, const unsigned char *pe); +static const unsigned char *cclass(const unsigned char *p, int sub); /* * Fast character classes @@ -213,8 +206,8 @@ struct options_info { } opts[NELEM(options)]; }; -static char *options_fmt_entry ARGS((void *arg, int i, char *buf, int buflen)); -static void printoptions ARGS((int verbose)); +static char *options_fmt_entry(void *arg, int i, char *buf, int buflen); +static void printoptions(int verbose); /* format a single select menu item */ static char * @@ -319,14 +312,10 @@ change_flag(f, what, newval) #endif /* EDIT */ /* Turning off -p? */ if (f == FPRIVILEGED && oldval && !newval) { -#ifdef OS2 - ; -#else /* OS2 */ seteuid(ksheuid = getuid()); setuid(ksheuid); setegid(getgid()); setgid(getgid()); -#endif /* OS2 */ } else if (f == FPOSIX && newval) { #ifdef BRACE_EXPAND Flag(FBRACEEXPAND) = 0 @@ -384,7 +373,7 @@ parse_args(argv, what, setargsp) * flag using +l. */ Flag(FLOGIN) = (argv[0][0] == '-' - || ((p = ksh_strrchr_dirsep(argv[0])) + || ((p = strrchr(argv[0], '/')) && *++p == '-')); opts = cmd_opts; } else @@ -546,8 +535,7 @@ gmatch(s, p, isfile) return !strcmp(t, s); } return do_gmatch((const unsigned char *) s, (const unsigned char *) se, - (const unsigned char *) p, (const unsigned char *) pe, - isfile); + (const unsigned char *) p, (const unsigned char *) pe); } /* Returns if p is a syntacticly correct globbing pattern, false @@ -622,10 +610,9 @@ has_globbing(xp, xpe) /* Function must return either 0 or 1 (assumed by code for 0x80|'!') */ static int -do_gmatch(s, se, p, pe, isfile) +do_gmatch(s, se, p, pe) const unsigned char *s, *p; const unsigned char *se, *pe; - int isfile; { register int sc, pc; const unsigned char *prest, *psub, *pnext; @@ -637,10 +624,6 @@ do_gmatch(s, se, p, pe, isfile) pc = *p++; sc = s < se ? *s : '\0'; s++; - if (isfile) { - sc = FILECHCONV(sc); - pc = FILECHCONV(pc); - } if (!ISMAGIC(pc)) { if (sc != pc) return 0; @@ -662,7 +645,7 @@ do_gmatch(s, se, p, pe, isfile) return 1; s--; do { - if (do_gmatch(s, se, p, pe, isfile)) + if (do_gmatch(s, se, p, pe)) return 1; } while (s++ < se); return 0; @@ -679,18 +662,18 @@ do_gmatch(s, se, p, pe, isfile) s--; /* take care of zero matches */ if (p[-1] == (0x80 | '*') - && do_gmatch(s, se, prest, pe, isfile)) + && do_gmatch(s, se, prest, pe)) return 1; for (psub = p; ; psub = pnext) { pnext = pat_scan(psub, pe, 1); for (srest = s; srest <= se; srest++) { if (do_gmatch(s, srest, - psub, pnext - 2, isfile) + psub, pnext - 2) && (do_gmatch(srest, se, - prest, pe, isfile) + prest, pe) || (s != srest && do_gmatch(srest, se, - p - 2, pe, isfile)))) + p - 2, pe)))) return 1; } if (pnext == prest) @@ -706,16 +689,16 @@ do_gmatch(s, se, p, pe, isfile) s--; /* Take care of zero matches */ if (p[-1] == (0x80 | '?') - && do_gmatch(s, se, prest, pe, isfile)) + && do_gmatch(s, se, prest, pe)) return 1; for (psub = p; ; psub = pnext) { pnext = pat_scan(psub, pe, 1); srest = prest == pe ? se : s; for (; srest <= se; srest++) { if (do_gmatch(s, srest, - psub, pnext - 2, isfile) + psub, pnext - 2) && do_gmatch(srest, se, - prest, pe, isfile)) + prest, pe)) return 1; } if (pnext == prest) @@ -733,7 +716,7 @@ do_gmatch(s, se, p, pe, isfile) for (psub = p; ; psub = pnext) { pnext = pat_scan(psub, pe, 1); if (do_gmatch(s, srest, - psub, pnext - 2, isfile)) + psub, pnext - 2)) { matched = 1; break; @@ -742,7 +725,7 @@ do_gmatch(s, se, p, pe, isfile) break; } if (!matched && do_gmatch(srest, se, - prest, pe, isfile)) + prest, pe)) return 1; } return 0; @@ -829,13 +812,13 @@ pat_scan(p, pe, match_sep) /* * quick sort of array of generic pointers to objects. */ -static void qsort1 ARGS((void **base, void **lim, int (*f)(void *, void *))); +static void qsort1(void **base, void **lim, int (*f)(void *, void *)); void qsortp(base, n, f) void **base; /* base address */ size_t n; /* elements */ - int (*f) ARGS((void *, void *)); /* compare function */ + int (*f)(void *, void *); /* compare function */ { qsort1(base, base + n, f); } @@ -850,7 +833,7 @@ qsortp(base, n, f) static void qsort1(base, lim, f) void **base, **lim; - int (*f) ARGS((void *, void *)); + int (*f)(void *, void *); { register void **i, **j; register void **lptr, **hptr; @@ -1105,7 +1088,7 @@ void print_columns(shf, n, func, arg, max_width, prefcol) struct shf *shf; int n; - char *(*func) ARGS((void *, int, char *, int)); + char *(*func)(void *, int, char *, int); void *arg; int max_width; int prefcol; @@ -1216,12 +1199,7 @@ blocking_read(fd, buf, nbytes) int tried_reset = 0; while ((ret = read(fd, buf, nbytes)) < 0) { - if (!tried_reset && (errno == EAGAIN -#ifdef EWOULDBLOCK - || errno == EWOULDBLOCK -#endif /* EWOULDBLOCK */ - )) - { + if (!tried_reset && errno == EAGAIN) { int oerrno = errno; if (reset_nonblock(fd) > 0) { tried_reset = 1; @@ -1243,70 +1221,29 @@ reset_nonblock(fd) int fd; { int flags; - int blocking_flags; if ((flags = fcntl(fd, F_GETFL, 0)) < 0) return -1; - /* With luck, the C compiler will reduce this to a constant */ - blocking_flags = 0; -#ifdef O_NONBLOCK - blocking_flags |= O_NONBLOCK; -#endif /* O_NONBLOCK */ -#ifdef O_NDELAY - blocking_flags |= O_NDELAY; -#else /* O_NDELAY */ -# ifndef O_NONBLOCK - blocking_flags |= FNDELAY; /* hope this exists... */ -# endif /* O_NONBLOCK */ -#endif /* O_NDELAY */ - if (!(flags & blocking_flags)) + if (!(flags & O_NONBLOCK)) return 0; - flags &= ~blocking_flags; + flags &= ~O_NONBLOCK; if (fcntl(fd, F_SETFL, flags) < 0) return -1; return 1; } -#ifdef HAVE_SYS_PARAM_H -# include <sys/param.h> -#endif /* HAVE_SYS_PARAM_H */ -#ifndef MAXPATHLEN -# define MAXPATHLEN PATH -#endif /* MAXPATHLEN */ - -#ifdef HPUX_GETWD_BUG -# include "ksh_dir.h" - -/* - * Work around bug in hpux 10.x C library - getwd/getcwd dump core - * if current directory is not readable. Done in macro 'cause code - * is needed in GETWD and GETCWD cases. - */ -# define HPUX_GETWD_BUG_CODE \ - { \ - DIR *d = ksh_opendir("."); \ - if (!d) \ - return (char *) 0; \ - closedir(d); \ - } -#else /* HPUX_GETWD_BUG */ -# define HPUX_GETWD_BUG_CODE -#endif /* HPUX_GETWD_BUG */ - /* Like getcwd(), except bsize is ignored if buf is 0 (MAXPATHLEN is used) */ char * ksh_get_wd(buf, bsize) char *buf; int bsize; { -#ifdef HAVE_GETCWD char *b; char *ret; - /* Before memory allocated */ - HPUX_GETWD_BUG_CODE - + /* Note: we could just use plain getcwd(), but then we'd had to + * inject possibly allocated space into the ATEMP area. */ /* Assume getcwd() available */ if (!buf) { bsize = MAXPATHLEN; @@ -1324,37 +1261,4 @@ ksh_get_wd(buf, bsize) } return ret; -#else /* HAVE_GETCWD */ - extern char *getwd ARGS((char *)); - char *b; - int len; - - /* Before memory allocated */ - HPUX_GETWD_BUG_CODE - - if (buf && bsize > MAXPATHLEN) - b = buf; - else - b = alloc(MAXPATHLEN + 1, ATEMP); - if (!getwd(b)) { - errno = EACCES; - if (b != buf) - afree(b, ATEMP); - return (char *) 0; - } - len = strlen(b) + 1; - if (!buf) - b = aresize(b, len, ATEMP); - else if (buf != b) { - if (len > bsize) { - errno = ERANGE; - return (char *) 0; - } - memcpy(buf, b, len); - afree(b, ATEMP); - b = buf; - } - - return b; -#endif /* HAVE_GETCWD */ } diff --git a/bin/ksh/missing.c b/bin/ksh/missing.c deleted file mode 100644 index f785bb311f7..00000000000 --- a/bin/ksh/missing.c +++ /dev/null @@ -1,290 +0,0 @@ -/* $OpenBSD: missing.c,v 1.5 2003/05/16 18:49:46 jsyn Exp $ */ - -/* - * Routines which may be missing on some machines - */ - -#include "sh.h" -#include "ksh_stat.h" -#include "ksh_dir.h" - -#ifndef HAVE_MEMSET -void * -memset(d, c, n) - void *d; - int c; - size_t n; -{ - unsigned char *p = (unsigned char *) d; - - /* Not amazingly fast.. */ - for (; n > 0; --n) - *p++ = c; - return d; -} -#endif /* !HAVE_MEMSET */ - -#if !defined(HAVE_MEMMOVE) && !defined(HAVE_BCOPY) -void * -memmove(d, s, n) - void *d; - const void *s; - size_t n; -{ - char *dp = (char *) d, *sp = (char *) s; - - if (n <= 0) - ; - else if (dp < sp) - do - *dp++ = *sp++; - while (--n > 0); - else if (dp > sp) { - dp += n; - sp += n; - do - *--dp = *--sp; - while (--n > 0); - } - return d; -} -#endif /* !HAVE_MEMMOVE && !HAVE_BCOPY */ - -#ifndef HAVE_STRCASECMP -/* - * Case insensitive string compare routines, same semantics as str[n]cmp() - * (assumes ASCII..). - */ -static const char ichars[256] = { - 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, - 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff - }; - -int -strcasecmp(s1, s2) - const char *s1; - const char *s2; -{ - const unsigned char *us1 = (const unsigned char *) s1; - const unsigned char *us2 = (const unsigned char *) s2; - - while (ichars[*us1] == ichars[*us2++]) - if (!*us1++) - return 0; - - return ichars[*us1] - ichars[*--us2]; -} - -int -strncasecmp(s1, s2, n) - const char *s1; - const char *s2; - int n; -{ - const unsigned char *us1 = (const unsigned char *) s1; - const unsigned char *us2 = (const unsigned char *) s2; - - while (--n >= 0 && ichars[*us1] == ichars[*us2++]) - if (!*us1++) - return 0; - - return n < 0 ? 0 : ichars[*us1] - ichars[*--us2]; -} -#endif /* HAVE_STRCASECMP */ - -#ifndef HAVE_STRSTR -char * -strstr(s, p) - const char *s; - const char *p; -{ - int len; - - if (s && p) - for (len = strlen(p); *s; s++) - if (*s == *p && strncmp(s, p, len) == 0) - return (char *) s; - - return 0; -} -#endif /* !HAVE_STRSTR */ - -#ifndef HAVE_STRERROR -char * -strerror(err) - int err; -{ - static char buf[64]; -# ifdef HAVE_SYS_ERRLIST -# ifndef SYS_ERRLIST_DECLARED - extern int sys_nerr; - extern char *sys_errlist[]; -# endif - char *p; - - if (err < 0 || err >= sys_nerr) - shf_snprintf(p = buf, sizeof(buf), "Unknown system error %d", - err); - else - p = sys_errlist[err]; - return p; -# else /* HAVE_SYS_ERRLIST */ - switch (err) { - case EINVAL: - return "Invalid argument"; - case EACCES: - return "Permission denied"; - case ESRCH: - return "No such process"; - case EPERM: - return "Not owner"; - case ENOENT: - return "No such file or directory"; - case ENOTDIR: - return "Not a directory"; - case ENOEXEC: - return "Exec format error"; - case ENOMEM: - return "Not enough memory"; - case E2BIG: - return "Argument list too long"; - default: - shf_snprintf(buf, sizeof(buf), "Unknown system error %d", err); - return buf; - } -# endif /* HAVE_SYS_ERRLIST */ -} -#endif /* !HAVE_STRERROR */ - -#ifdef TIMES_BROKEN -# include "ksh_time.h" -# include "ksh_times.h" -# ifdef HAVE_GETRUSAGE -# include <sys/resource.h> -# else /* HAVE_GETRUSAGE */ -# include <sys/timeb.h> -# endif /* HAVE_GETRUSAGE */ - -clock_t -ksh_times(tms) - struct tms *tms; -{ - static clock_t base_sec; - clock_t rv; - -# ifdef HAVE_GETRUSAGE - { - struct timeval tv; - struct rusage ru; - - getrusage(RUSAGE_SELF, &ru); - tms->tms_utime = ru.ru_utime.tv_sec * CLK_TCK - + ru.ru_utime.tv_usec * CLK_TCK / 1000000; - tms->tms_stime = ru.ru_stime.tv_sec * CLK_TCK - + ru.ru_stime.tv_usec * CLK_TCK / 1000000; - - getrusage(RUSAGE_CHILDREN, &ru); - tms->tms_cutime = ru.ru_utime.tv_sec * CLK_TCK - + ru.ru_utime.tv_usec * CLK_TCK / 1000000; - tms->tms_cstime = ru.ru_stime.tv_sec * CLK_TCK - + ru.ru_stime.tv_usec * CLK_TCK / 1000000; - - gettimeofday(&tv, (struct timezone *) 0); - if (base_sec == 0) - base_sec = tv.tv_sec; - rv = (tv.tv_sec - base_sec) * CLK_TCK; - rv += tv.tv_usec * CLK_TCK / 1000000; - } -# else /* HAVE_GETRUSAGE */ - /* Assume times() available, but always returns 0 - * (also assumes ftime() available) - */ - { - struct timeb tb; - - if (times(tms) == (clock_t) -1) - return (clock_t) -1; - ftime(&tb); - if (base_sec == 0) - base_sec = tb.time; - rv = (tb.time - base_sec) * CLK_TCK; - rv += tb.millitm * CLK_TCK / 1000; - } -# endif /* HAVE_GETRUSAGE */ - return rv; -} -#endif /* TIMES_BROKEN */ - -#ifdef OPENDIR_DOES_NONDIR -/* Prevent opendir() from attempting to open non-directories. Such - * behavior can cause problems if it attempts to open special devices... - */ -DIR * -ksh_opendir(d) - const char *d; -{ - struct stat statb; - - if (stat(d, &statb) != 0) - return (DIR *) 0; - if (!S_ISDIR(statb.st_mode)) { - errno = ENOTDIR; - return (DIR *) 0; - } - return opendir(d); -} -#endif /* OPENDIR_DOES_NONDIR */ - -#ifndef HAVE_DUP2 -int -dup2(oldd, newd) - int oldd; - int newd; -{ - int old_errno; - - if (fcntl(oldd, F_GETFL, 0) == -1) - return -1; /* errno == EBADF */ - - if (oldd == newd) - return newd; - - old_errno = errno; - - close(newd); /* in case its open */ - - errno = old_errno; - - return fcntl(oldd, F_DUPFD, newd); -} -#endif /* !HAVE_DUP2 */ diff --git a/bin/ksh/path.c b/bin/ksh/path.c index c955f89615e..dc21bf866ac 100644 --- a/bin/ksh/path.c +++ b/bin/ksh/path.c @@ -1,7 +1,7 @@ -/* $OpenBSD: path.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */ +/* $OpenBSD: path.c,v 1.10 2004/12/18 20:55:52 millert Exp $ */ #include "sh.h" -#include "ksh_stat.h" +#include <sys/stat.h> /* * Contains a routine to search a : separated list of @@ -12,9 +12,7 @@ * Larry Bouzane (larry@cs.mun.ca) */ -#ifdef S_ISLNK -static char *do_phys_path ARGS((XString *xsp, char *xp, const char *path)); -#endif /* S_ISLNK */ +static char *do_phys_path(XString *xsp, char *xp, const char *path); /* * Makes a filename into result using the following algorithm. @@ -49,7 +47,7 @@ make_path(cwd, file, cdpathp, xsp, phys_pathp) if (!file) file = null; - if (!ISRELPATH(file)) { + if (file[0] == '/') { *phys_pathp = 0; use_cdpath = 0; } else { @@ -58,7 +56,7 @@ make_path(cwd, file, cdpathp, xsp, phys_pathp) if (c == '.') c = file[2]; - if (ISDIRSEP(c) || c == '\0') + if (c == '/' || c == '\0') use_cdpath = 0; } @@ -68,29 +66,29 @@ make_path(cwd, file, cdpathp, xsp, phys_pathp) else if (use_cdpath) { char *pend; - for (pend = plist; *pend && *pend != PATHSEP; pend++) + for (pend = plist; *pend && *pend != ':'; pend++) ; plen = pend - plist; *cdpathp = *pend ? ++pend : (char *) 0; } - if ((use_cdpath == 0 || !plen || ISRELPATH(plist)) + if ((use_cdpath == 0 || !plen || plist[0] != '/') && (cwd && *cwd)) { len = strlen(cwd); XcheckN(*xsp, xp, len); memcpy(xp, cwd, len); xp += len; - if (!ISDIRSEP(cwd[len - 1])) - Xput(*xsp, xp, DIRSEP); + if (cwd[len - 1] != '/') + Xput(*xsp, xp, '/'); } *phys_pathp = Xlength(*xsp, xp); if (use_cdpath && plen) { XcheckN(*xsp, xp, plen); memcpy(xp, plist, plen); xp += plen; - if (!ISDIRSEP(plist[plen - 1])) - Xput(*xsp, xp, DIRSEP); + if (plist[plen - 1] != '/') + Xput(*xsp, xp, '/'); rval = 1; } } @@ -122,12 +120,8 @@ simplify_path(path) if (!*path) return; - if ((isrooted = ISROOTEDPATH(path))) + if ((isrooted = path[0] == '/')) very_start++; -#if defined (OS2) || defined (__CYGWIN__) - if (path[0] && path[1] == ':') /* skip a: */ - very_start += 2; -#endif /* OS2 || __CYGWIN__ */ /* Before After * /foo/ /foo @@ -137,22 +131,11 @@ simplify_path(path) * .. .. * ./foo foo * foo/../../../bar ../../bar - * OS2 and CYGWIN: - * a:/foo/../.. a:/ - * a:. a: - * a:.. a:.. - * a:foo/../../blah a:../blah */ -#ifdef __CYGWIN__ - /* preserve leading double-slash on pathnames (for UNC paths) */ - if (path[0] && ISDIRSEP(path[0]) && path[1] && ISDIRSEP(path[1])) - very_start++; -#endif /* __CYGWIN__ */ - for (cur = t = start = very_start; ; ) { /* treat multiple '/'s as one '/' */ - while (ISDIRSEP(*t)) + while (*t == '/') t++; if (*t == '\0') { @@ -164,18 +147,18 @@ simplify_path(path) } if (t[0] == '.') { - if (!t[1] || ISDIRSEP(t[1])) { + if (!t[1] || t[1] == '/') { t += 1; continue; - } else if (t[1] == '.' && (!t[2] || ISDIRSEP(t[2]))) { + } else if (t[1] == '.' && (!t[2] || t[2] == '/')) { if (!isrooted && cur == start) { if (cur != very_start) - *cur++ = DIRSEP; + *cur++ = '/'; *cur++ = '.'; *cur++ = '.'; start = cur; } else if (cur != start) - while (--cur > start && !ISDIRSEP(*cur)) + while (--cur > start && *cur != '/') ; t += 2; continue; @@ -183,10 +166,10 @@ simplify_path(path) } if (cur != very_start) - *cur++ = DIRSEP; + *cur++ = '/'; /* find/copy next component of pathname */ - while (*t && !ISDIRSEP(*t)) + while (*t && *t != '/') *cur++ = *t++; } } @@ -211,7 +194,6 @@ set_current_wd(path) afree(p, ATEMP); } -#ifdef S_ISLNK char * get_phys_path(path) const char *path; @@ -227,7 +209,7 @@ get_phys_path(path) return (char *) 0; if (Xlength(xs, xp) == 0) - Xput(xs, xp, DIRSEP); + Xput(xs, xp, '/'); Xput(xs, xp, '\0'); return Xclose(xs, xp); @@ -246,24 +228,24 @@ do_phys_path(xsp, xp, path) Xcheck(*xsp, xp); for (p = path; p; p = q) { - while (ISDIRSEP(*p)) + while (*p == '/') p++; if (!*p) break; - len = (q = ksh_strchr_dirsep(p)) ? q - p : strlen(p); + len = (q = strchr(p, '/')) ? q - p : strlen(p); if (len == 1 && p[0] == '.') continue; if (len == 2 && p[0] == '.' && p[1] == '.') { while (xp > Xstring(*xsp, xp)) { xp--; - if (ISDIRSEP(*xp)) + if (*xp == '/') break; } continue; } savepos = Xsavepos(*xsp, xp); - Xput(*xsp, xp, DIRSEP); + Xput(*xsp, xp, '/'); XcheckN(*xsp, xp, len + 1); memcpy(xp, p, len); xp += len; @@ -279,14 +261,13 @@ do_phys_path(xsp, xp, path) lbuf[llen] = '\0'; /* If absolute path, start from scratch.. */ - xp = ISABSPATH(lbuf) ? Xstring(*xsp, xp) - : Xrestpos(*xsp, xp, savepos); + xp = lbuf[0] == '/' ? Xstring(*xsp, xp) + : Xrestpos(*xsp, xp, savepos); if (!(xp = do_phys_path(xsp, xp, lbuf))) return (char *) 0; } return xp; } -#endif /* S_ISLNK */ #ifdef TEST diff --git a/bin/ksh/proto.h b/bin/ksh/proto.h index ddd8e7bff17..712bb685a35 100644 --- a/bin/ksh/proto.h +++ b/bin/ksh/proto.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proto.h,v 1.13 2004/12/12 06:53:13 deraadt Exp $ */ +/* $OpenBSD: proto.h,v 1.14 2004/12/18 20:55:52 millert Exp $ */ /* * prototypes for PD-KSH @@ -7,300 +7,270 @@ */ /* alloc.c */ -Area * ainit ARGS((Area *ap)); -void afreeall ARGS((Area *ap)); -void * alloc ARGS((size_t size, Area *ap)); -void * aresize ARGS((void *ptr, size_t size, Area *ap)); -void afree ARGS((void *ptr, Area *ap)); +Area * ainit(Area *ap); +void afreeall(Area *ap); +void * alloc(size_t size, Area *ap); +void * aresize(void *ptr, size_t size, Area *ap); +void afree(void *ptr, Area *ap); /* c_ksh.c */ -int c_hash ARGS((char **wp)); -int c_cd ARGS((char **wp)); -int c_pwd ARGS((char **wp)); -int c_print ARGS((char **wp)); -int c_whence ARGS((char **wp)); -int c_command ARGS((char **wp)); -int c_typeset ARGS((char **wp)); -int c_alias ARGS((char **wp)); -int c_unalias ARGS((char **wp)); -int c_let ARGS((char **wp)); -int c_jobs ARGS((char **wp)); -int c_fgbg ARGS((char **wp)); -int c_kill ARGS((char **wp)); -void getopts_reset ARGS((int val)); -int c_getopts ARGS((char **wp)); -int c_bind ARGS((char **wp)); +int c_hash(char **wp); +int c_cd(char **wp); +int c_pwd(char **wp); +int c_print(char **wp); +int c_whence(char **wp); +int c_command(char **wp); +int c_typeset(char **wp); +int c_alias(char **wp); +int c_unalias(char **wp); +int c_let(char **wp); +int c_jobs(char **wp); +int c_fgbg(char **wp); +int c_kill(char **wp); +void getopts_reset(int val); +int c_getopts(char **wp); +int c_bind(char **wp); /* c_sh.c */ -int c_label ARGS((char **wp)); -int c_shift ARGS((char **wp)); -int c_umask ARGS((char **wp)); -int c_dot ARGS((char **wp)); -int c_wait ARGS((char **wp)); -int c_read ARGS((char **wp)); -int c_eval ARGS((char **wp)); -int c_trap ARGS((char **wp)); -int c_brkcont ARGS((char **wp)); -int c_exitreturn ARGS((char **wp)); -int c_set ARGS((char **wp)); -int c_unset ARGS((char **wp)); -int c_ulimit ARGS((char **wp)); -int c_times ARGS((char **wp)); -int timex ARGS((struct op *t, int f)); -void timex_hook ARGS((struct op *t, char ** volatile *app)); -int c_exec ARGS((char **wp)); -int c_builtin ARGS((char **wp)); +int c_label(char **wp); +int c_shift(char **wp); +int c_umask(char **wp); +int c_dot(char **wp); +int c_wait(char **wp); +int c_read(char **wp); +int c_eval(char **wp); +int c_trap(char **wp); +int c_brkcont(char **wp); +int c_exitreturn(char **wp); +int c_set(char **wp); +int c_unset(char **wp); +int c_ulimit(char **wp); +int c_times(char **wp); +int timex(struct op *t, int f); +void timex_hook(struct op *t, char ** volatile *app); +int c_exec(char **wp); +int c_builtin(char **wp); /* c_test.c */ -int c_test ARGS((char **wp)); +int c_test(char **wp); /* edit.c: most prototypes in edit.h */ -void x_init ARGS((void)); -int x_read ARGS((char *buf, size_t len)); -void set_editmode ARGS((const char *ed)); +void x_init(void); +int x_read(char *buf, size_t len); +void set_editmode(const char *ed); /* emacs.c: most prototypes in edit.h */ -int x_bind ARGS((const char *a1, const char *a2, int macro, - int list)); +int x_bind(const char *a1, const char *a2, int macro, int list); /* eval.c */ -char * substitute ARGS((const char *cp, int f)); -char ** eval ARGS((char **ap, int f)); -char * evalstr ARGS((char *cp, int f)); -char * evalonestr ARGS((char *cp, int f)); -char *debunk ARGS((char *dp, const char *sp, size_t dlen)); -void expand ARGS((char *cp, XPtrV *wp, int f)); -int glob_str ARGS((char *cp, XPtrV *wp, int markdirs)); +char * substitute(const char *cp, int f); +char ** eval(char **ap, int f); +char * evalstr(char *cp, int f); +char * evalonestr(char *cp, int f); +char *debunk(char *dp, const char *sp, size_t dlen); +void expand(char *cp, XPtrV *wp, int f); +int glob_str(char *cp, XPtrV *wp, int markdirs); /* exec.c */ -int fd_clexec ARGS((int fd)); -int execute ARGS((struct op * volatile t, volatile int flags)); -int shcomexec ARGS((char **wp)); -struct tbl * findfunc ARGS((const char *name, unsigned int h, int create)); -int define ARGS((const char *name, struct op *t)); -void builtin ARGS((const char *name, int (*func)(char **))); -struct tbl * findcom ARGS((const char *name, int flags)); -void flushcom ARGS((int all)); -char * search ARGS((const char *name, const char *path, int mode, - int *errnop)); -int search_access ARGS((const char *path, int mode, int *errnop)); -int pr_menu ARGS((char *const *ap)); -int pr_list ARGS((char *const *ap)); +int fd_clexec(int fd); +int execute(struct op * volatile t, volatile int flags); +int shcomexec(char **wp); +struct tbl * findfunc(const char *name, unsigned int h, int create); +int define(const char *name, struct op *t); +void builtin(const char *name, int (*func)(char **)); +struct tbl * findcom(const char *name, int flags); +void flushcom(int all); +char * search(const char *name, const char *path, int mode, int *errnop); +int search_access(const char *path, int mode, int *errnop); +int pr_menu(char *const *ap); +int pr_list(char *const *ap); /* expr.c */ -int evaluate ARGS((const char *expr, long *rval, int error_ok)); -int v_evaluate ARGS((struct tbl *vp, const char *expr, volatile int error_ok)); +int evaluate(const char *expr, long *rval, int error_ok); +int v_evaluate(struct tbl *vp, const char *expr, volatile int error_ok); /* history.c */ -void init_histvec ARGS((void)); -void hist_init ARGS((Source *s)); -void hist_finish ARGS((void)); -void histsave ARGS((int lno, const char *cmd, int dowrite)); +void init_histvec(void); +void hist_init(Source *s); +void hist_finish(void); +void histsave(int lno, const char *cmd, int dowrite); #ifdef HISTORY -int c_fc ARGS((register char **wp)); -void sethistsize ARGS((int n)); -void sethistfile ARGS((const char *name)); -# ifdef EASY_HISTORY -void histappend ARGS((const char *cmd, int nl_separate)); -# endif -char ** histpos ARGS((void)); -int histN ARGS((void)); -int histnum ARGS((int n)); -int findhist ARGS((int start, int fwd, const char *str, - int anchored)); -int findhistrel ARGS((const char *str)); -char **hist_get_newest ARGS((int allow_cur)); +int c_fc(register char **wp); +void sethistsize(int n); +void sethistfile(const char *name); +char ** histpos(void); +int histN(void); +int histnum(int n); +int findhist(int start, int fwd, const char *str, int anchored); +int findhistrel(const char *str); +char **hist_get_newest(int allow_cur); #endif /* HISTORY */ /* io.c */ -void errorf ARGS((const char *fmt, ...)) - GCC_FUNC_ATTR2(noreturn, format(printf, 1, 2)); -void warningf ARGS((int fileline, const char *fmt, ...)) - GCC_FUNC_ATTR(format(printf, 2, 3)); -void bi_errorf ARGS((const char *fmt, ...)) - GCC_FUNC_ATTR(format(printf, 1, 2)); -void internal_errorf ARGS((int jump, const char *fmt, ...)) - GCC_FUNC_ATTR(format(printf, 2, 3)); -void error_prefix ARGS((int fileline)); -void shellf ARGS((const char *fmt, ...)) - GCC_FUNC_ATTR(format(printf, 1, 2)); -void shprintf ARGS((const char *fmt, ...)) - GCC_FUNC_ATTR(format(printf, 1, 2)); +void errorf(const char *fmt, ...) + GCC_FUNC_ATTR2(noreturn, format(printf, 1, 2)); +void warningf(int fileline, const char *fmt, ...) + GCC_FUNC_ATTR(format(printf, 2, 3)); +void bi_errorf(const char *fmt, ...) + GCC_FUNC_ATTR(format(printf, 1, 2)); +void internal_errorf(int jump, const char *fmt, ...) + GCC_FUNC_ATTR(format(printf, 2, 3)); +void error_prefix(int fileline); +void shellf(const char *fmt, ...) + GCC_FUNC_ATTR(format(printf, 1, 2)); +void shprintf(const char *fmt, ...) + GCC_FUNC_ATTR(format(printf, 1, 2)); #ifdef KSH_DEBUG -void kshdebug_init_ ARGS((void)); -void kshdebug_printf_ ARGS((const char *fmt, ...)) - GCC_FUNC_ATTR(format(printf, 1, 2)); -void kshdebug_dump_ ARGS((const char *str, const void *mem, int nbytes)); +void kshdebug_init_(void); +void kshdebug_printf_(const char *fmt, ...) + GCC_FUNC_ATTR(format(printf, 1, 2)); +void kshdebug_dump_(const char *str, const void *mem, int nbytes); #endif /* KSH_DEBUG */ -int can_seek ARGS((int fd)); -void initio ARGS((void)); -int ksh_dup2 ARGS((int ofd, int nfd, int errok)); -int savefd ARGS((int fd, int noclose)); -void restfd ARGS((int fd, int ofd)); -void openpipe ARGS((int *pv)); -void closepipe ARGS((int *pv)); -int check_fd ARGS((char *name, int mode, const char **emsgp)); +int can_seek(int fd); +void initio(void); +int ksh_dup2(int ofd, int nfd, int errok); +int savefd(int fd, int noclose); +void restfd(int fd, int ofd); +void openpipe(int *pv); +void closepipe(int *pv); +int check_fd(char *name, int mode, const char **emsgp); #ifdef KSH -void coproc_init ARGS((void)); -void coproc_read_close ARGS((int fd)); -void coproc_readw_close ARGS((int fd)); -void coproc_write_close ARGS((int fd)); -int coproc_getfd ARGS((int mode, const char **emsgp)); -void coproc_cleanup ARGS((int reuse)); +void coproc_init(void); +void coproc_read_close(int fd); +void coproc_readw_close(int fd); +void coproc_write_close(int fd); +int coproc_getfd(int mode, const char **emsgp); +void coproc_cleanup(int reuse); #endif /* KSH */ -struct temp *maketemp ARGS((Area *ap, Temp_type type, struct temp **tlist)); +struct temp *maketemp(Area *ap, Temp_type type, struct temp **tlist); /* jobs.c */ -void j_init ARGS((int mflagset)); -void j_exit ARGS((void)); -void j_change ARGS((void)); -int exchild ARGS((struct op *t, int flags, int close_fd)); -void startlast ARGS((void)); -int waitlast ARGS((void)); -int waitfor ARGS((const char *cp, int *sigp)); -int j_kill ARGS((const char *cp, int sig)); -int j_resume ARGS((const char *cp, int bg)); -int j_jobs ARGS((const char *cp, int slp, int nflag)); -int j_njobs ARGS((void)); -void j_notify ARGS((void)); -pid_t j_async ARGS((void)); -int j_stopped_running ARGS((void)); +void j_init(int mflagset); +void j_exit(void); +void j_change(void); +int exchild(struct op *t, int flags, int close_fd); +void startlast(void); +int waitlast(void); +int waitfor(const char *cp, int *sigp); +int j_kill(const char *cp, int sig); +int j_resume(const char *cp, int bg); +int j_jobs(const char *cp, int slp, int nflag); +int j_njobs(void); +void j_notify(void); +pid_t j_async(void); +int j_stopped_running(void); /* lex.c */ -int yylex ARGS((int cf)); -void yyerror ARGS((const char *fmt, ...)) - GCC_FUNC_ATTR2(noreturn, format(printf, 1, 2)); -Source * pushs ARGS((int type, Area *areap)); -void set_prompt ARGS((int to, Source *s)); -void pprompt ARGS((const char *cp, int ntruncate)); +int yylex(int cf); +void yyerror(const char *fmt, ...) + GCC_FUNC_ATTR2(noreturn, format(printf, 1, 2)); +Source * pushs(int type, Area *areap); +void set_prompt(int to, Source *s); +void pprompt(const char *cp, int ntruncate); /* mail.c */ #ifdef KSH -void mcheck ARGS((void)); -void mcset ARGS((long interval)); -void mbset ARGS((char *p)); -void mpset ARGS((char *mptoparse)); +void mcheck(void); +void mcset(long interval); +void mbset(char *p); +void mpset(char *mptoparse); #endif /* KSH */ /* main.c */ -int include ARGS((const char *name, int argc, char **argv, - int intr_ok)); -int command ARGS((const char *comm)); -int shell ARGS((Source *volatile s, int volatile toplevel)); -void unwind ARGS((int i)) GCC_FUNC_ATTR(noreturn); -void newenv ARGS((int type)); -void quitenv ARGS((void)); -void cleanup_parents_env ARGS((void)); -void cleanup_proc_env ARGS((void)); -void aerror ARGS((Area *ap, const char *msg)) - GCC_FUNC_ATTR(noreturn); +int include(const char *name, int argc, char **argv, int intr_ok); +int command(const char *comm); +int shell(Source *volatile s, int volatile toplevel); +void unwind(int i) GCC_FUNC_ATTR(noreturn); +void newenv(int type); +void quitenv(void); +void cleanup_parents_env(void); +void cleanup_proc_env(void); +void aerror(Area *ap, const char *msg) + GCC_FUNC_ATTR(noreturn); /* misc.c */ -void setctypes ARGS((const char *s, int t)); -void initctypes ARGS((void)); -char * ulton ARGS((unsigned long n, int base)); -char * str_save ARGS((const char *s, Area *ap)); -char * str_nsave ARGS((const char *s, int n, Area *ap)); -int option ARGS((const char *n)); -char * getoptions ARGS((void)); -void change_flag ARGS((enum sh_flag f, int what, int newval)); -int parse_args ARGS((char **argv, int what, int *setargsp)); -int getn ARGS((const char *as, int *ai)); -int bi_getn ARGS((const char *as, int *ai)); -int gmatch ARGS((const char *s, const char *p, int isfile)); -int has_globbing ARGS((const char *xp, const char *xpe)); -const unsigned char *pat_scan ARGS((const unsigned char *p, - const unsigned char *pe, int match_sep)); -void qsortp ARGS((void **base, size_t n, int (*f)(void *, void *))); -int xstrcmp ARGS((void *p1, void *p2)); -void ksh_getopt_reset ARGS((Getopt *go, int)); -int ksh_getopt ARGS((char **argv, Getopt *go, const char *options)); -void print_value_quoted ARGS((const char *s)); -void print_columns ARGS((struct shf *shf, int n, - char *(*func)(void *, int, char *, int), - void *arg, int max_width, int prefcol)); -int strip_nuls ARGS((char *buf, int nbytes)); -char *str_zcpy ARGS((char *dst, const char *src, int dsize)); -int blocking_read ARGS((int fd, char *buf, int nbytes)); -int reset_nonblock ARGS((int fd)); -char *ksh_get_wd ARGS((char *buf, int bsize)); +void setctypes(const char *s, int t); +void initctypes(void); +char * ulton(unsigned long n, int base); +char * str_save(const char *s, Area *ap); +char * str_nsave(const char *s, int n, Area *ap); +int option(const char *n); +char * getoptions(void); +void change_flag(enum sh_flag f, int what, int newval); +int parse_args(char **argv, int what, int *setargsp); +int getn(const char *as, int *ai); +int bi_getn(const char *as, int *ai); +int gmatch(const char *s, const char *p, int isfile); +int has_globbing(const char *xp, const char *xpe); +const unsigned char *pat_scan(const unsigned char *p, + const unsigned char *pe, int match_sep); +void qsortp(void **base, size_t n, int (*f)(void *, void *)); +int xstrcmp(void *p1, void *p2); +void ksh_getopt_reset(Getopt *go, int); +int ksh_getopt(char **argv, Getopt *go, const char *options); +void print_value_quoted(const char *s); +void print_columns(struct shf *shf, int n, + char *(*func)(void *, int, char *, int), + void *arg, int max_width, int prefcol); +int strip_nuls(char *buf, int nbytes); +char *str_zcpy(char *dst, const char *src, int dsize); +int blocking_read(int fd, char *buf, int nbytes); +int reset_nonblock(int fd); +char *ksh_get_wd(char *buf, int bsize); /* path.c */ -int make_path ARGS((const char *cwd, const char *file, - char **pathlist, XString *xsp, int *phys_pathp)); -void simplify_path ARGS((char *path)); -char *get_phys_path ARGS((const char *path)); -void set_current_wd ARGS((char *path)); +int make_path(const char *cwd, const char *file, + char **pathlist, XString *xsp, int *phys_pathp); +void simplify_path(char *path); +char *get_phys_path(const char *path); +void set_current_wd(char *path); /* syn.c */ -void initkeywords ARGS((void)); -struct op * compile ARGS((Source *s)); +void initkeywords(void); +struct op * compile(Source *s); /* table.c */ -unsigned int hash ARGS((const char *n)); -void tinit ARGS((struct table *tp, Area *ap, int tsize)); -struct tbl * tsearch ARGS((struct table *tp, const char *n, unsigned int h)); -struct tbl * tenter ARGS((struct table *tp, const char *n, unsigned int h)); -void tdelete ARGS((struct tbl *p)); -void twalk ARGS((struct tstate *ts, struct table *tp)); -struct tbl * tnext ARGS((struct tstate *ts)); -struct tbl ** tsort ARGS((struct table *tp)); +unsigned int hash(const char *n); +void tinit(struct table *tp, Area *ap, int tsize); +struct tbl * tsearch(struct table *tp, const char *n, unsigned int h); +struct tbl * tenter(struct table *tp, const char *n, unsigned int h); +void tdelete(struct tbl *p); +void twalk(struct tstate *ts, struct table *tp); +struct tbl * tnext(struct tstate *ts); +struct tbl ** tsort(struct table *tp); /* trace.c */ /* trap.c */ -void inittraps ARGS((void)); +void inittraps(void); #ifdef KSH -void alarm_init ARGS((void)); +void alarm_init(void); #endif /* KSH */ -Trap * gettrap ARGS((const char *name, int igncase)); -RETSIGTYPE trapsig ARGS((int i)); -void intrcheck ARGS((void)); -int fatal_trap_check ARGS((void)); -int trap_pending ARGS((void)); -void runtraps ARGS((int intr)); -void runtrap ARGS((Trap *p)); -void cleartraps ARGS((void)); -void restoresigs ARGS((void)); -void settrap ARGS((Trap *p, char *s)); -int block_pipe ARGS((void)); -void restore_pipe ARGS((int restore_dfl)); -int setsig ARGS((Trap *p, handler_t f, int flags)); -void setexecsig ARGS((Trap *p, int restore)); +Trap * gettrap(const char *name, int igncase); +void trapsig(int i); +void intrcheck(void); +int fatal_trap_check(void); +int trap_pending(void); +void runtraps(int intr); +void runtrap(Trap *p); +void cleartraps(void); +void restoresigs(void); +void settrap(Trap *p, char *s); +int block_pipe(void); +void restore_pipe(int restore_dfl); +int setsig(Trap *p, handler_t f, int flags); +void setexecsig(Trap *p, int restore); /* tree.c */ -int fptreef ARGS((struct shf *f, int indent, const char *fmt, ...)); -char * snptreef ARGS((char *s, int n, const char *fmt, ...)); -struct op * tcopy ARGS((struct op *t, Area *ap)); -char * wdcopy ARGS((const char *wp, Area *ap)); -char * wdscan ARGS((const char *wp, int c)); -char * wdstrip ARGS((const char *wp)); -void tfree ARGS((struct op *t, Area *ap)); +int fptreef(struct shf *f, int indent, const char *fmt, ...); +char * snptreef(char *s, int n, const char *fmt, ...); +struct op * tcopy(struct op *t, Area *ap); +char * wdcopy(const char *wp, Area *ap); +char * wdscan(const char *wp, int c); +char * wdstrip(const char *wp); +void tfree(struct op *t, Area *ap); /* var.c */ -void newblock ARGS((void)); -void popblock ARGS((void)); -void initvar ARGS((void)); -struct tbl * global ARGS((const char *n)); -struct tbl * local ARGS((const char *n, bool_t copy)); -char * str_val ARGS((struct tbl *vp)); -long intval ARGS((struct tbl *vp)); -int setstr ARGS((struct tbl *vq, const char *s, int error_ok)); -struct tbl *setint_v ARGS((struct tbl *vq, struct tbl *vp)); -void setint ARGS((struct tbl *vq, long n)); -int getint ARGS((struct tbl *vp, long *nump)); -struct tbl * typeset ARGS((const char *var, Tflag set, Tflag clr, int field, int base)); -void unset ARGS((struct tbl *vp, int array_ref)); -char * skip_varname ARGS((const char *s, int aok)); -char *skip_wdvarname ARGS((const char *s, int aok)); -int is_wdvarname ARGS((const char *s, int aok)); -int is_wdvarassign ARGS((const char *s)); -char ** makenv ARGS((void)); -void change_random ARGS((void)); -int array_ref_len ARGS((const char *cp)); -char * arrayname ARGS((const char *str)); -void set_array ARGS((const char *var, int reset, char **vals)); +void newblock(void); +void popblock(void); +void initvar(void); +struct tbl * global(const char *n); +struct tbl * local(const char *n, bool_t copy); +char * str_val(struct tbl *vp); +long intval(struct tbl *vp); +int setstr(struct tbl *vq, const char *s, int error_ok); +struct tbl *setint_v(struct tbl *vq, struct tbl *vp); +void setint(struct tbl *vq, long n); +int getint(struct tbl *vp, long *nump); +struct tbl * typeset(const char *var, Tflag set, Tflag clr, int field, int base); +void unset(struct tbl *vp, int array_ref); +char * skip_varname(const char *s, int aok); +char *skip_wdvarname(const char *s, int aok); +int is_wdvarname(const char *s, int aok); +int is_wdvarassign(const char *s); +char ** makenv(void); +void change_random(void); +int array_ref_len(const char *cp); +char * arrayname(const char *str); +void set_array(const char *var, int reset, char **vals); /* version.c */ /* vi.c: see edit.h */ - - -/* Hack to avoid billions of compile warnings on SunOS 4.1.x */ -#if defined(MUN) && defined(sun) && !defined(__svr4__) -extern void bcopy ARGS((const void *src, void *dst, size_t size)); -extern int fclose ARGS((FILE *fp)); -extern int fprintf ARGS((FILE *fp, const char *fmt, ...)); -extern int fread ARGS((void *buf, int size, int num, FILE *fp)); -extern int ioctl ARGS((int fd, int request, void *arg)); -extern int killpg ARGS((int pgrp, int sig)); -extern int nice ARGS((int n)); -extern int readlink ARGS((const char *path, char *buf, int bufsize)); -extern int setpgrp ARGS((int pid, int pgrp)); -extern int strcasecmp ARGS((const char *s1, const char *s2)); -extern int tolower ARGS((int)); -extern int toupper ARGS((int)); -/* Include files aren't included yet */ -extern int getrlimit ARGS(( /* int resource, struct rlimit *rpl */ )); -extern int getrusage ARGS(( /* int who, struct rusage *rusage */ )); -extern int gettimeofday ARGS(( /* struct timeval *tv, struct timezone *tz */ )); -extern int setrlimit ARGS(( /* int resource, struct rlimit *rlp */ )); -extern int lstat ARGS(( /* const char *path, struct stat *buf */ )); -#endif diff --git a/bin/ksh/sh.h b/bin/ksh/sh.h index 1eb3ddd50dd..920bdbdff20 100644 --- a/bin/ksh/sh.h +++ b/bin/ksh/sh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sh.h,v 1.19 2004/12/12 06:53:13 deraadt Exp $ */ +/* $OpenBSD: sh.h,v 1.20 2004/12/18 20:55:52 millert Exp $ */ /* * Public Domain Bourne/Korn shell @@ -8,238 +8,31 @@ #include "config.h" /* system and option configuration info */ -#ifdef HAVE_PROTOTYPES -# define ARGS(args) args /* prototype declaration */ -#else -# define ARGS(args) () /* K&R declaration */ -#endif - /* Start of common headers */ #include <stdio.h> #include <sys/types.h> #include <setjmp.h> -#ifdef HAVE_STDDEF_H -# include <stddef.h> -#endif - -#ifdef HAVE_STDLIB_H -# include <stdlib.h> -#else -/* just a useful subset of what stdlib.h would have */ -extern char * getenv ARGS((const char *)); -extern void * malloc ARGS((size_t)); -extern void * realloc ARGS((void *, size_t)); -extern int free ARGS((void *)); -extern int exit ARGS((int)); -extern int rand ARGS((void)); -extern void srand ARGS((unsigned int)); -extern int atoi ARGS((const char *)); -#endif /* HAVE_STDLIB_H */ - -#ifdef HAVE_UNISTD_H -# include <unistd.h> -#else -/* just a useful subset of what unistd.h would have */ -extern int access ARGS((const char *, int)); -extern int open ARGS((const char *, int, ...)); -extern int creat ARGS((const char *, mode_t)); -extern int read ARGS((int, char *, unsigned)); -extern int write ARGS((int, const char *, unsigned)); -extern off_t lseek ARGS((int, off_t, int)); -extern int close ARGS((int)); -extern int pipe ARGS((int [])); -extern int dup2 ARGS((int, int)); -extern int unlink ARGS((const char *)); -extern int fork ARGS((void)); -extern int execve ARGS((const char *, char * const[], char * const[])); -extern int chdir ARGS((const char *)); -extern int kill ARGS((pid_t, int)); -extern char *getcwd(); /* no ARGS here - differs on different machines */ -extern int geteuid ARGS((void)); -extern int readlink ARGS((const char *, char *, int)); -extern int getegid ARGS((void)); -extern int getpid ARGS((void)); -extern int getppid ARGS((void)); -extern unsigned int sleep ARGS((unsigned int)); -extern int isatty ARGS((int)); -# ifdef POSIX_PGRP -extern int getpgrp ARGS((void)); -extern int setpgid ARGS((pid_t, pid_t)); -# endif /* POSIX_PGRP */ -# ifdef BSD_PGRP -extern int getpgrp ARGS((pid_t)); -extern int setpgrp ARGS((pid_t, pid_t)); -# endif /* BSD_PGRP */ -# ifdef SYSV_PGRP -extern int getpgrp ARGS((void)); -extern int setpgrp ARGS((void)); -# endif /* SYSV_PGRP */ -#endif /* HAVE_UNISTD_H */ - -#ifdef HAVE_STRING_H -# include <string.h> -#else -# include <strings.h> -# define strchr index -# define strrchr rindex -#endif /* HAVE_STRING_H */ -#ifndef HAVE_STRSTR -char *strstr ARGS((const char *s, const char *p)); -#endif /* HAVE_STRSTR */ -#ifndef HAVE_STRCASECMP -int strcasecmp ARGS((const char *s1, const char *s2)); -int strncasecmp ARGS((const char *s1, const char *s2, int n)); -#endif /* HAVE_STRCASECMP */ - -#ifdef HAVE_MEMORY_H -# include <memory.h> -#endif -#ifndef HAVE_MEMSET -# define memcpy(d, s, n) bcopy(s, d, n) -# define memcmp(s1, s2, n) bcmp(s1, s2, n) -void *memset ARGS((void *d, int c, size_t n)); -#endif /* HAVE_MEMSET */ -#ifndef HAVE_MEMMOVE -# ifdef HAVE_BCOPY -# define memmove(d, s, n) bcopy(s, d, n) -# else -void *memmove ARGS((void *d, const void *s, size_t n)); -# endif -#endif /* HAVE_MEMMOVE */ - -#ifdef HAVE_PROTOTYPES -# include <stdarg.h> -# define SH_VA_START(va, argn) va_start(va, argn) -#else -# include <varargs.h> -# define SH_VA_START(va, argn) va_start(va) -#endif /* HAVE_PROTOTYPES */ +#include <stddef.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <stdarg.h> #include <errno.h> - -#ifdef HAVE_FCNTL_H -# include <fcntl.h> -#else -# include <sys/file.h> -#endif /* HAVE_FCNTL_H */ -#ifndef O_ACCMODE -# define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) -#endif /* !O_ACCMODE */ - -#ifndef F_OK /* access() arguments */ -# define F_OK 0 -# define X_OK 1 -# define W_OK 2 -# define R_OK 4 -#endif /* !F_OK */ - -#ifndef SEEK_SET -# ifdef L_SET -# define SEEK_SET L_SET -# define SEEK_CUR L_INCR -# define SEEK_END L_XTND -# else /* L_SET */ -# define SEEK_SET 0 -# define SEEK_CUR 1 -# define SEEK_END 2 -# endif /* L_SET */ -#endif /* !SEEK_SET */ - -/* Some machines (eg, FreeBSD 1.1.5) define CLK_TCK in limits.h - * (ksh_limval.h assumes limits has been included, if available) - */ -#ifdef HAVE_LIMITS_H -# include <limits.h> -#endif /* HAVE_LIMITS_H */ +#include <fcntl.h> +#include <limits.h> #include <signal.h> -#ifdef NSIG -# define SIGNALS NSIG -#else -# ifdef _MINIX -# define SIGNALS (_NSIG+1) /* _NSIG is # of signals used, excluding 0. */ -# else -# ifdef _SIGMAX /* QNX */ -# define SIGNALS _SIGMAX -# else /* _SIGMAX */ -# define SIGNALS 32 -# endif /* _SIGMAX */ -# endif /* _MINIX */ -#endif /* NSIG */ -#ifndef SIGCHLD -# define SIGCHLD SIGCLD -#endif + /* struct sigaction.sa_flags is set to KSH_SA_FLAGS. Used to ensure * system calls are interrupted */ -#ifdef SA_INTERRUPT -# define KSH_SA_FLAGS SA_INTERRUPT -#else /* SA_INTERRUPT */ -# define KSH_SA_FLAGS 0 -#endif /* SA_INTERRUPT */ +#define KSH_SA_FLAGS 0 -typedef RETSIGTYPE (*handler_t) ARGS((int)); /* signal handler */ +typedef void (*handler_t)(int); /* signal handler */ -#ifdef USE_FAKE_SIGACT -# include "sigact.h" /* use sjg's fake sigaction() */ -#endif - -#ifdef HAVE_PATHS_H -# include <paths.h> -#endif /* HAVE_PATHS_H */ -#ifdef _PATH_DEFPATH -# define DEFAULT__PATH _PATH_DEFPATH -#else /* _PATH_DEFPATH */ -# define DEFAULT__PATH DEFAULT_PATH -#endif /* _PATH_DEFPATH */ - -#ifndef offsetof -# define offsetof(type,id) ((size_t)&((type*)NULL)->id) -#endif - -#ifndef HAVE_KILLPG -# define killpg(p, s) kill(-(p), (s)) -#endif /* !HAVE_KILLPG */ - -/* Special cases for execve(2) */ -#ifdef OS2 -extern int ksh_execve(char *cmd, char **args, char **env, int flags); -#else /* OS2 */ -# if defined(OS_ISC) && defined(_POSIX_SOURCE) -/* Kludge for ISC 3.2 (and other versions?) so programs will run correctly. */ -# define ksh_execve(p, av, ev, flags) \ - do { \ - __setostype(0); \ - execve(p, av, ev); \ - __setostype(1); \ - } while (0) -# else /* OS_ISC && _POSIX */ -# define ksh_execve(p, av, ev, flags) execve(p, av, ev) -# endif /* OS_ISC && _POSIX */ -#endif /* OS2 */ - -/* this is a hang-over from older versions of the os2 port */ -#define ksh_dupbase(fd, base) fcntl(fd, F_DUPFD, base) - -#ifdef HAVE_SIGSETJMP -# define ksh_sigsetjmp(env,sm) sigsetjmp((env), (sm)) -# define ksh_siglongjmp(env,v) siglongjmp((env), (v)) -# define ksh_jmp_buf sigjmp_buf -#else /* HAVE_SIGSETJMP */ -# ifdef HAVE__SETJMP -# define ksh_sigsetjmp(env,sm) _setjmp(env) -# define ksh_siglongjmp(env,v) _longjmp((env), (v)) -# else /* HAVE__SETJMP */ -# define ksh_sigsetjmp(env,sm) setjmp(env) -# define ksh_siglongjmp(env,v) longjmp((env), (v)) -# endif /* HAVE__SETJMP */ -# define ksh_jmp_buf jmp_buf -#endif /* HAVE_SIGSETJMP */ - -#ifndef HAVE_DUP2 -extern int dup2 ARGS((int, int)); -#endif /* !HAVE_DUP2 */ +#include <paths.h> /* Find a integer type that is at least 32 bits (or die) - SIZEOF_* defined * by autoconf (assumes an 8 bit byte, but I'm not concerned). @@ -249,13 +42,6 @@ extern int dup2 ARGS((int, int)); /* end of common headers */ -/* Stop gcc and lint from complaining about possibly uninitialized variables */ -#if defined(__GNUC__) || defined(lint) -# define UNINITIALIZED(var) var = 0 -#else -# define UNINITIALIZED(var) var -#endif /* GNUC || lint */ - /* some useful #defines */ #ifdef EXTERN # define I__(i) = i @@ -265,71 +51,8 @@ extern int dup2 ARGS((int, int)); # define EXTERN_DEFINED #endif -#ifdef OS2 -# define inDOS() (!(_emx_env & 0x200)) -#endif - -#ifndef EXECSHELL -/* shell to exec scripts (see also $SHELL initialization in main.c) */ -# ifdef OS2 -# define EXECSHELL (inDOS() ? "c:\\command.com" : "c:\\os2\\cmd.exe") -# define EXECSHELL_STR (inDOS() ? "COMSPEC" : "OS2_SHELL") -# else /* OS2 */ -# define EXECSHELL "/bin/sh" -# define EXECSHELL_STR "EXECSHELL" -# endif /* OS2 */ -#endif - -/* ISABSPATH() means path is fully and completely specified, - * ISROOTEDPATH() means a .. as the first component is a no-op, - * ISRELPATH() means $PWD can be tacked on to get an absolute path. - * - * OS Path ISABSPATH ISROOTEDPATH ISRELPATH - * unix /foo yes yes no - * unix foo no no yes - * unix ../foo no no yes - * os2+cyg a:/foo yes yes no - * os2+cyg a:foo no no no - * os2+cyg /foo no yes no - * os2+cyg foo no no yes - * os2+cyg ../foo no no yes - * cyg //foo yes yes no - */ -#ifdef OS2 -# define PATHSEP ';' -# define DIRSEP '/' /* even though \ is native */ -# define DIRSEPSTR "\\" -# define ISDIRSEP(c) ((c) == '\\' || (c) == '/') -# define ISABSPATH(s) (((s)[0] && (s)[1] == ':' && ISDIRSEP((s)[2]))) -# define ISROOTEDPATH(s) (ISDIRSEP((s)[0]) || ISABSPATH(s)) -# define ISRELPATH(s) (!(s)[0] || ((s)[1] != ':' && !ISDIRSEP((s)[0]))) -# define FILECHCONV(c) (isascii(c) && isupper(c) ? tolower(c) : c) -# define FILECMP(s1, s2) stricmp(s1, s2) -# define FILENCMP(s1, s2, n) strnicmp(s1, s2, n) -extern char *ksh_strchr_dirsep(const char *path); -extern char *ksh_strrchr_dirsep(const char *path); -# define chdir _chdir2 -# define getcwd _getcwd2 -#else -# define PATHSEP ':' -# define DIRSEP '/' -# define DIRSEPSTR "/" -# define ISDIRSEP(c) ((c) == '/') -#ifdef __CYGWIN__ -# define ISABSPATH(s) \ - (((s)[0] && (s)[1] == ':' && ISDIRSEP((s)[2])) || ISDIRSEP((s)[0])) -# define ISRELPATH(s) (!(s)[0] || ((s)[1] != ':' && !ISDIRSEP((s)[0]))) -#else /* __CYGWIN__ */ -# define ISABSPATH(s) ISDIRSEP((s)[0]) -# define ISRELPATH(s) (!ISABSPATH(s)) -#endif /* __CYGWIN__ */ -# define ISROOTEDPATH(s) ISABSPATH(s) -# define FILECHCONV(c) c -# define FILECMP(s1, s2) strcmp(s1, s2) -# define FILENCMP(s1, s2, n) strncmp(s1, s2, n) -# define ksh_strchr_dirsep(p) strchr(p, DIRSEP) -# define ksh_strrchr_dirsep(p) strrchr(p, DIRSEP) -#endif +#define EXECSHELL "/bin/sh" +#define EXECSHELL_STR "EXECSHELL" typedef int bool_t; #define FALSE 0 @@ -345,9 +68,6 @@ typedef INT32 Tflag; #define NUFILE 32 /* Number of user-accessible files */ #define FDBASE 10 /* First file usable by Shell */ -/* you're not going to run setuid shell scripts, are you? */ -#define eaccess(path, mode) access(path, mode) - /* Make MAGIC a char that might be printed to make bugs more obvious, but * not a char that is used often. Also, can't use the high bit as it causes * portability problems (calling strchr(x, 0x80|'x') is error prone). @@ -379,10 +99,6 @@ EXTERN Area aperm; /* permanent object space */ #define APERM &aperm #define ATEMP &e->area -#ifdef MEM_DEBUG -# include "chmem.h" /* a debugging front end for malloc et. al. */ -#endif /* MEM_DEBUG */ - #ifdef KSH_DEBUG # define kshdebug_init() kshdebug_init_() # define kshdebug_printf(a) kshdebug_printf_ a @@ -403,7 +119,7 @@ EXTERN struct env { struct block *loc; /* local variables and functions */ short *savefd; /* original redirected fd's */ struct env *oenv; /* link to previous environment */ - ksh_jmp_buf jbuf; /* long jump back to env creator */ + sigjmp_buf jbuf; /* long jump back to env creator */ struct temp *temps; /* temp files */ } *e; @@ -428,7 +144,7 @@ EXTERN struct env { /* Do returns stop at env type e? */ #define STOP_RETURN(t) ((t) == E_FUNC || (t) == E_INCL) -/* values for ksh_siglongjmp(e->jbuf, 0) */ +/* values for siglongjmp(e->jbuf, 0) */ #define LRETURN 1 /* return statement */ #define LEXIT 2 /* exit statement */ #define LERROR 3 /* errorf() called */ @@ -576,15 +292,12 @@ typedef struct trap { #define SS_SHTRAP BIT(5) /* trap for internal use (CHLD,ALRM,WINCH) */ #define SIGEXIT_ 0 /* for trap EXIT */ -#define SIGERR_ SIGNALS /* for trap ERR */ +#define SIGERR_ NSIG /* for trap ERR */ EXTERN int volatile trap; /* traps pending? */ EXTERN int volatile intrsig; /* pending trap interrupts executing command */ EXTERN int volatile fatal_trap;/* received a fatal signal */ -#ifndef FROM_TRAP_C -/* Kludge to avoid bogus re-declaration of sigtraps[] error on AIX 3.2.5 */ -extern Trap sigtraps[SIGNALS+1]; -#endif /* !FROM_TRAP_C */ +extern Trap sigtraps[NSIG+1]; #ifdef KSH /* @@ -666,9 +379,7 @@ EXTERN struct coproc coproc; #endif /* KSH */ /* Used in jobs.c and by coprocess stuff in exec.c */ -#ifdef JOB_SIGS EXTERN sigset_t sm_default, sm_sigchld; -#endif /* JOB_SIGS */ extern const char ksh_version[]; @@ -702,13 +413,7 @@ EXTERN int x_cols I__(80); /* tty columns */ #define CBRACE '}' /* Determine the location of the system (common) profile */ -#ifndef KSH_SYSTEM_PROFILE -# ifdef __NeXT -# define KSH_SYSTEM_PROFILE "/etc/profile.std" -# else /* __NeXT */ -# define KSH_SYSTEM_PROFILE "/etc/profile" -# endif /* __NeXT */ -#endif /* KSH_SYSTEM_PROFILE */ +#define KSH_SYSTEM_PROFILE "/etc/profile" /* Used by v_evaluate() and setstr() to control action when error occurs */ #define KSH_UNWIND_ERROR 0 /* unwind the stack (longjmp) */ diff --git a/bin/ksh/shf.c b/bin/ksh/shf.c index 2947858fbca..2faebbc25b9 100644 --- a/bin/ksh/shf.c +++ b/bin/ksh/shf.c @@ -1,11 +1,11 @@ -/* $OpenBSD: shf.c,v 1.8 2003/02/28 09:45:09 jmc Exp $ */ +/* $OpenBSD: shf.c,v 1.9 2004/12/18 20:55:52 millert Exp $ */ /* * Shell file I/O routines */ #include "sh.h" -#include "ksh_stat.h" +#include <sys/stat.h> #include "ksh_limval.h" @@ -19,8 +19,8 @@ * file descriptors. */ -static int shf_fillbuf ARGS((struct shf *shf)); -static int shf_emptybuf ARGS((struct shf *shf, int flags)); +static int shf_fillbuf(struct shf *shf); +static int shf_emptybuf(struct shf *shf, int flags); /* Open a file. First three args are for open(), last arg is flags for * this package. Returns NULL if file could not be opened, or if a dup @@ -53,7 +53,7 @@ shf_open(name, oflags, mode, sflags) if ((sflags & SHF_MAPHI) && fd < FDBASE) { int nfd; - nfd = ksh_dupbase(fd, FDBASE); + nfd = fcntl(fd, F_DUPFD, FDBASE); close(fd); if (nfd < 0) { afree(shf, shf->areap); @@ -571,14 +571,6 @@ shf_getse(buf, bsize, shf) shf->rnleft -= ncopy; buf += ncopy; bsize -= ncopy; -#ifdef OS2 - if (end && buf > orig_buf + 1 && buf[-2] == '\r') { - buf--; - bsize++; - buf[-1] = '\n'; - } -#endif - } while (!end && bsize); *buf = '\0'; return buf; @@ -759,19 +751,12 @@ shf_write(buf, nbytes, shf) } int -#ifdef HAVE_PROTOTYPES shf_fprintf(struct shf *shf, const char *fmt, ...) -#else -shf_fprintf(shf, fmt, va_alist) - struct shf *shf; - const char *fmt; - va_dcl -#endif { va_list args; int n; - SH_VA_START(args, fmt); + va_start(args, fmt); n = shf_vfprintf(shf, fmt, args); va_end(args); @@ -779,15 +764,7 @@ shf_fprintf(shf, fmt, va_alist) } int -#ifdef HAVE_PROTOTYPES shf_snprintf(char *buf, int bsize, const char *fmt, ...) -#else -shf_snprintf(buf, bsize, fmt, va_alist) - char *buf; - int bsize; - const char *fmt; - va_dcl -#endif { struct shf shf; va_list args; @@ -798,7 +775,7 @@ shf_snprintf(buf, bsize, fmt, va_alist) (long) buf, bsize); shf_sopen(buf, bsize, SHF_WR, &shf); - SH_VA_START(args, fmt); + va_start(args, fmt); n = shf_vfprintf(&shf, fmt, args); va_end(args); shf_sclose(&shf); /* null terminates */ @@ -806,19 +783,13 @@ shf_snprintf(buf, bsize, fmt, va_alist) } char * -#ifdef HAVE_PROTOTYPES shf_smprintf(const char *fmt, ...) -#else -shf_smprintf(fmt, va_alist) - char *fmt; - va_dcl -#endif { struct shf shf; va_list args; shf_sopen((char *) 0, 0, SHF_WR|SHF_DYNAMIC, &shf); - SH_VA_START(args, fmt); + va_start(args, fmt); shf_vfprintf(&shf, fmt, args); va_end(args); return shf_sclose(&shf); /* null terminates */ @@ -888,7 +859,7 @@ shf_vfprintf(shf, fmt, args) va_list args; { char c, *s; - int UNINITIALIZED(tmp); + int tmp = 0; int field, precision; int len; int flags; diff --git a/bin/ksh/shf.h b/bin/ksh/shf.h index b4be5a73d67..8d94434fd52 100644 --- a/bin/ksh/shf.h +++ b/bin/ksh/shf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: shf.h,v 1.2 1999/01/08 20:25:02 millert Exp $ */ +/* $OpenBSD: shf.h,v 1.3 2004/12/18 20:55:52 millert Exp $ */ #ifndef SHF_H # define SHF_H @@ -59,28 +59,26 @@ struct shf { extern struct shf shf_iob[]; -struct shf *shf_open ARGS((const char *name, int oflags, int mode, - int sflags)); -struct shf *shf_fdopen ARGS((int fd, int sflags, struct shf *shf)); -struct shf *shf_reopen ARGS((int fd, int sflags, struct shf *shf)); -struct shf *shf_sopen ARGS((char *buf, int bsize, int sflags, - struct shf *shf)); -int shf_close ARGS((struct shf *shf)); -int shf_fdclose ARGS((struct shf *shf)); -char *shf_sclose ARGS((struct shf *shf)); -int shf_finish ARGS((struct shf *shf)); -int shf_flush ARGS((struct shf *shf)); -int shf_seek ARGS((struct shf *shf, off_t where, int from)); -int shf_read ARGS((char *buf, int bsize, struct shf *shf)); -char *shf_getse ARGS((char *buf, int bsize, struct shf *shf)); -int shf_getchar ARGS((struct shf *shf)); -int shf_ungetc ARGS((int c, struct shf *shf)); -int shf_putchar ARGS((int c, struct shf *shf)); -int shf_puts ARGS((const char *s, struct shf *shf)); -int shf_write ARGS((const char *buf, int nbytes, struct shf *shf)); -int shf_fprintf ARGS((struct shf *shf, const char *fmt, ...)); -int shf_snprintf ARGS((char *buf, int bsize, const char *fmt, ...)); -char *shf_smprintf ARGS((const char *fmt, ...)); -int shf_vfprintf ARGS((struct shf *, const char *fmt, va_list args)); +struct shf *shf_open(const char *name, int oflags, int mode, int sflags); +struct shf *shf_fdopen(int fd, int sflags, struct shf *shf); +struct shf *shf_reopen(int fd, int sflags, struct shf *shf); +struct shf *shf_sopen(char *buf, int bsize, int sflags, struct shf *shf); +int shf_close(struct shf *shf); +int shf_fdclose(struct shf *shf); +char *shf_sclose(struct shf *shf); +int shf_finish(struct shf *shf); +int shf_flush(struct shf *shf); +int shf_seek(struct shf *shf, off_t where, int from); +int shf_read(char *buf, int bsize, struct shf *shf); +char *shf_getse(char *buf, int bsize, struct shf *shf); +int shf_getchar(struct shf *shf); +int shf_ungetc(int c, struct shf *shf); +int shf_putchar(int c, struct shf *shf); +int shf_puts(const char *s, struct shf *shf); +int shf_write(const char *buf, int nbytes, struct shf *shf); +int shf_fprintf(struct shf *shf, const char *fmt, ...); +int shf_snprintf(char *buf, int bsize, const char *fmt, ...); +char *shf_smprintf(const char *fmt, ...); +int shf_vfprintf(struct shf *, const char *fmt, va_list args); #endif /* SHF_H */ diff --git a/bin/ksh/siglist.sh b/bin/ksh/siglist.sh index 123b190140c..7e58272a850 100644 --- a/bin/ksh/siglist.sh +++ b/bin/ksh/siglist.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: siglist.sh,v 1.4 1997/06/19 13:58:47 kstailey Exp $ +# $OpenBSD: siglist.sh,v 1.5 2004/12/18 20:55:52 millert Exp $ # # Script to generate a sorted, complete list of signals, suitable @@ -19,7 +19,7 @@ CPP="${1-cc -E}" # The trap here to make up for a bug in bash (1.14.3(1)) that calls the trap (trap $trapsigs; echo '#include "sh.h"'; - echo ' { QwErTy SIGNALS , "DUMMY" , "hook for number of signals" },'; + echo ' { QwErTy NSIG , "DUMMY" , "hook for number of signals" },'; sed -e '/^[ ]*#/d' -e 's/^[ ]*\([^ ][^ ]*\)[ ][ ]*\(.*[^ ]\)[ ]*$/#ifdef SIG\1\ { QwErTy SIG\1 , "\1", "\2" },\ #endif/') > $in diff --git a/bin/ksh/syn.c b/bin/ksh/syn.c index 5cb68318c5c..607484ecdff 100644 --- a/bin/ksh/syn.c +++ b/bin/ksh/syn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syn.c,v 1.14 2003/10/22 07:40:38 jmc Exp $ */ +/* $OpenBSD: syn.c,v 1.15 2004/12/18 20:55:52 millert Exp $ */ /* * shell parser (C version) @@ -12,37 +12,36 @@ struct nesting_state { int start_line; /* line nesting began on */ }; -static void yyparse ARGS((void)); -static struct op *pipeline ARGS((int cf)); -static struct op *andor ARGS((void)); -static struct op *c_list ARGS((int multi)); -static struct ioword *synio ARGS((int cf)); -static void musthave ARGS((int c, int cf)); -static struct op *nested ARGS((int type, int smark, int emark)); -static struct op *get_command ARGS((int cf)); -static struct op *dogroup ARGS((void)); -static struct op *thenpart ARGS((void)); -static struct op *elsepart ARGS((void)); -static struct op *caselist ARGS((void)); -static struct op *casepart ARGS((int endtok)); -static struct op *function_body ARGS((char *name, int ksh_func)); -static char ** wordlist ARGS((void)); -static struct op *block ARGS((int type, struct op *t1, struct op *t2, - char **wp)); -static struct op *newtp ARGS((int type)); -static void syntaxerr ARGS((const char *what)) +static void yyparse(void); +static struct op *pipeline(int cf); +static struct op *andor(void); +static struct op *c_list(int multi); +static struct ioword *synio(int cf); +static void musthave(int c, int cf); +static struct op *nested(int type, int smark, int emark); +static struct op *get_command(int cf); +static struct op *dogroup(void); +static struct op *thenpart(void); +static struct op *elsepart(void); +static struct op *caselist(void); +static struct op *casepart(int endtok); +static struct op *function_body(char *name, int ksh_func); +static char ** wordlist(void); +static struct op *block(int type, struct op *t1, struct op *t2, + char **wp); +static struct op *newtp(int type); +static void syntaxerr(const char *what) GCC_FUNC_ATTR(noreturn); -static void nesting_push ARGS((struct nesting_state *save, int tok)); -static void nesting_pop ARGS((struct nesting_state *saved)); -static int assign_command ARGS((char *s)); -static int inalias ARGS((struct source *s)); +static void nesting_push(struct nesting_state *save, int tok); +static void nesting_pop(struct nesting_state *saved); +static int assign_command(char *s); +static int inalias(struct source *s); #ifdef KSH -static int dbtestp_isa ARGS((Test_env *te, Test_meta meta)); -static const char *dbtestp_getopnd ARGS((Test_env *te, Test_op op, - int do_eval)); -static int dbtestp_eval ARGS((Test_env *te, Test_op op, const char *opnd1, - const char *opnd2, int do_eval)); -static void dbtestp_error ARGS((Test_env *te, int offset, const char *msg)); +static int dbtestp_isa(Test_env *te, Test_meta meta); +static const char *dbtestp_getopnd(Test_env *te, Test_op op, int do_eval); +static int dbtestp_eval(Test_env *te, Test_op op, const char *opnd1, + const char *opnd2, int do_eval); +static void dbtestp_error(Test_env *te, int offset, const char *msg); #endif /* KSH */ static struct op *outtree; /* yyparse output */ diff --git a/bin/ksh/table.c b/bin/ksh/table.c index 91b33bc96c5..4f198df474b 100644 --- a/bin/ksh/table.c +++ b/bin/ksh/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.5 1999/01/10 17:55:03 millert Exp $ */ +/* $OpenBSD: table.c,v 1.6 2004/12/18 20:55:52 millert Exp $ */ /* * dynamic hashed associative table for commands and variables @@ -8,8 +8,8 @@ #define INIT_TBLS 8 /* initial table size (power of 2) */ -static void texpand ARGS((struct table *tp, int nsize)); -static int tnamecmp ARGS((void *p1, void *p2)); +static void texpand(struct table *tp, int nsize); +static int tnamecmp(void *p1, void *p2); unsigned int @@ -193,7 +193,7 @@ tsort(tp) #ifdef PERF_DEBUG /* performance debugging */ -void tprintinfo ARGS((struct table *tp)); +void tprintinfo(struct table *tp); void tprintinfo(tp) diff --git a/bin/ksh/table.h b/bin/ksh/table.h index f88c178b272..af46f0fd921 100644 --- a/bin/ksh/table.h +++ b/bin/ksh/table.h @@ -1,4 +1,4 @@ -/* $OpenBSD: table.h,v 1.5 1999/06/15 01:18:36 millert Exp $ */ +/* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */ /* $From: table.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */ @@ -20,7 +20,7 @@ struct tbl { /* table item */ union { char *s; /* string */ long i; /* integer */ - int (*f) ARGS((char **)); /* int function */ + int (*f)(char **); /* int function */ struct op *t; /* "function" tree */ } val; /* value */ int index; /* index for an array */ @@ -145,7 +145,7 @@ EXTERN struct table homedirs; /* homedir() cache */ struct builtin { const char *name; - int (*func) ARGS((char **)); + int (*func)(char **); }; /* these really are externs! Look in table.c for them */ diff --git a/bin/ksh/trap.c b/bin/ksh/trap.c index 010e79e98f2..25244ac2c5b 100644 --- a/bin/ksh/trap.c +++ b/bin/ksh/trap.c @@ -1,11 +1,9 @@ -/* $OpenBSD: trap.c,v 1.13 2003/02/28 09:45:09 jmc Exp $ */ +/* $OpenBSD: trap.c,v 1.14 2004/12/18 20:55:52 millert Exp $ */ /* * signal handling */ -/* Kludge to avoid bogus re-declaration of sigtraps[] error on AIX 3.2.5 */ -#define FROM_TRAP_C #include "sh.h" /* Table is indexed by signal number @@ -13,7 +11,7 @@ * The script siglist.sh generates siglist.out, which is a sorted, complete * list of signals */ -Trap sigtraps[SIGNALS+1] = { +Trap sigtraps[NSIG+1] = { { SIGEXIT_, "EXIT", "Signal 0" }, #include "siglist.out" /* generated by siglist.sh */ { SIGERR_, "ERR", "Error handler" }, @@ -24,17 +22,12 @@ static struct sigaction Sigact_ign, Sigact_trap; void inittraps() { -#ifdef HAVE_SYS_SIGLIST -# ifndef SYS_SIGLIST_DECLARED - extern char *sys_siglist[]; -# endif int i; /* Use system description, if available, for unknown signals... */ for (i = 0; i < NSIG; i++) if (!sigtraps[i].name && sys_siglist[i] && sys_siglist[i][0]) sigtraps[i].mess = sys_siglist[i]; -#endif /* HAVE_SYS_SIGLIST */ sigemptyset(&Sigact_ign.sa_mask); Sigact_ign.sa_flags = KSH_SA_FLAGS; @@ -56,7 +49,7 @@ inittraps() } #ifdef KSH -static RETSIGTYPE alarm_catcher ARGS((int sig)); +static void alarm_catcher(int sig); void alarm_init() @@ -66,7 +59,7 @@ alarm_init() SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP); } -static RETSIGTYPE +static void alarm_catcher(sig) int sig; { @@ -82,7 +75,6 @@ alarm_catcher(sig) alarm(left); } errno = errno_; - return RETSIGVAL; } #endif /* KSH */ @@ -97,11 +89,11 @@ gettrap(name, igncase) if (digit(*name)) { int n; - if (getn(name, &n) && 0 <= n && n < SIGNALS) + if (getn(name, &n) && 0 <= n && n < NSIG) return &sigtraps[n]; return NULL; } - for (p = sigtraps, i = SIGNALS+1; --i >= 0; p++) + for (p = sigtraps, i = NSIG+1; --i >= 0; p++) if (p->name) { if (igncase) { if (p->name && (!strcasecmp(p->name, name) || @@ -122,7 +114,7 @@ gettrap(name, igncase) /* * trap signal handler */ -RETSIGTYPE +void trapsig(i) int i; { @@ -138,12 +130,7 @@ trapsig(i) } if (p->shtrap) (*p->shtrap)(i); -#ifdef V7_SIGNALS - if (sigtraps[i].cursig == trapsig) /* this for SIGCHLD,SIGALRM */ - sigaction(i, &Sigact_trap, (struct sigaction *) 0); -#endif /* V7_SIGNALS */ errno = errno_; - return RETSIGVAL; } /* called when we want to allow the user to ^C out of something - won't @@ -166,7 +153,7 @@ fatal_trap_check() Trap *p; /* todo: should check if signal is fatal, not the TF_DFL_INTR flag */ - for (p = sigtraps, i = SIGNALS+1; --i >= 0; p++) + for (p = sigtraps, i = NSIG+1; --i >= 0; p++) if (p->set && (p->flags & (TF_DFL_INTR|TF_FATAL))) /* return value is used as an exit code */ return 128 + p->signal; @@ -183,7 +170,7 @@ trap_pending() int i; Trap *p; - for (p = sigtraps, i = SIGNALS+1; --i >= 0; p++) + for (p = sigtraps, i = NSIG+1; --i >= 0; p++) if (p->set && ((p->trap && p->trap[0]) || ((p->flags & (TF_DFL_INTR|TF_FATAL)) && !p->trap))) @@ -219,7 +206,7 @@ runtraps(flag) intrsig = 0; if (flag & TF_FATAL) fatal_trap = 0; - for (p = sigtraps, i = SIGNALS+1; --i >= 0; p++) + for (p = sigtraps, i = NSIG+1; --i >= 0; p++) if (p->set && (!flag || ((p->flags & flag) && p->trap == (char *) 0))) runtrap(p); @@ -232,7 +219,7 @@ runtrap(p) int i = p->signal; char *trapstr = p->trap; int oexstat; - int UNINITIALIZED(old_changed); + int old_changed = 0; p->set = 0; if (trapstr == (char *) 0) { /* SIG_DFL */ @@ -281,7 +268,7 @@ cleartraps() trap = 0; intrsig = 0; fatal_trap = 0; - for (i = SIGNALS+1, p = sigtraps; --i >= 0; p++) { + for (i = NSIG+1, p = sigtraps; --i >= 0; p++) { p->set = 0; if ((p->flags & TF_USER_SET) && (p->trap && p->trap[0])) settrap(p, (char *) 0); @@ -295,7 +282,7 @@ restoresigs() int i; Trap *p; - for (i = SIGNALS+1, p = sigtraps; --i >= 0; p++) + for (i = NSIG+1, p = sigtraps; --i >= 0; p++) if (p->flags & (TF_EXEC_IGN|TF_EXEC_DFL)) setsig(p, (p->flags & TF_EXEC_IGN) ? SIG_IGN : SIG_DFL, SS_RESTORE_CURR|SS_FORCE); diff --git a/bin/ksh/tree.c b/bin/ksh/tree.c index e412790b7f7..99f8ef386c1 100644 --- a/bin/ksh/tree.c +++ b/bin/ksh/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.10 2002/02/27 19:37:09 dhartmei Exp $ */ +/* $OpenBSD: tree.c,v 1.11 2004/12/18 20:55:52 millert Exp $ */ /* * command tree climbing @@ -9,13 +9,13 @@ #define INDENT 4 #define tputc(c, shf) shf_putchar(c, shf); -static void ptree ARGS((struct op *t, int indent, struct shf *f)); -static void pioact ARGS((struct shf *f, int indent, struct ioword *iop)); -static void tputC ARGS((int c, struct shf *shf)); -static void tputS ARGS((char *wp, struct shf *shf)); -static void vfptreef ARGS((struct shf *shf, int indent, const char *fmt, va_list va)); -static struct ioword **iocopy ARGS((struct ioword **iow, Area *ap)); -static void iofree ARGS((struct ioword **iow, Area *ap)); +static void ptree(struct op *t, int indent, struct shf *f); +static void pioact(struct shf *f, int indent, struct ioword *iop); +static void tputC(int c, struct shf *shf); +static void tputS(char *wp, struct shf *shf); +static void vfptreef(struct shf *shf, int indent, const char *fmt, va_list va); +static struct ioword **iocopy(struct ioword **iow, Area *ap); +static void iofree(struct ioword **iow, Area *ap); /* * print a command tree @@ -369,19 +369,11 @@ tputS(wp, shf) */ /* VARARGS */ int -#ifdef HAVE_PROTOTYPES fptreef(struct shf *shf, int indent, const char *fmt, ...) -#else -fptreef(shf, indent, fmt, va_alist) - struct shf *shf; - int indent; - const char *fmt; - va_dcl -#endif { va_list va; - SH_VA_START(va, fmt); + va_start(va, fmt); vfptreef(shf, indent, fmt, va); va_end(va); @@ -390,22 +382,14 @@ fptreef(shf, indent, fmt, va_alist) /* VARARGS */ char * -#ifdef HAVE_PROTOTYPES snptreef(char *s, int n, const char *fmt, ...) -#else -snptreef(s, n, fmt, va_alist) - char *s; - int n; - const char *fmt; - va_dcl -#endif { va_list va; struct shf shf; shf_sopen(s, n, SHF_WR | (s ? 0 : SHF_DYNAMIC), &shf); - SH_VA_START(va, fmt); + va_start(va, fmt); vfptreef(&shf, 0, fmt, va); va_end(va); diff --git a/bin/ksh/tree.h b/bin/ksh/tree.h index 3d15955fc2a..e89d5308f59 100644 --- a/bin/ksh/tree.h +++ b/bin/ksh/tree.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.h,v 1.8 2003/10/22 07:40:38 jmc Exp $ */ +/* $OpenBSD: tree.h,v 1.9 2004/12/18 20:55:52 millert Exp $ */ /* * command trees for compile/execute @@ -110,7 +110,6 @@ struct ioword { #define XERROK BIT(8) /* non-zero exit ok (for set -e) */ #define XCOPROC BIT(9) /* starting a co-process */ #define XTIME BIT(10) /* timing TCOM command */ -#define XINTACT BIT(11) /* OS2: proc started from interactive session */ /* * flags to control expansion of words (assumed by t->evalflags to fit diff --git a/bin/ksh/tty.c b/bin/ksh/tty.c index 00a94cd3ae6..3808563dc26 100644 --- a/bin/ksh/tty.c +++ b/bin/ksh/tty.c @@ -1,7 +1,7 @@ -/* $OpenBSD: tty.c,v 1.2 1996/10/01 02:05:51 downsj Exp $ */ +/* $OpenBSD: tty.c,v 1.3 2004/12/18 20:55:52 millert Exp $ */ #include "sh.h" -#include "ksh_stat.h" +#include <sys/stat.h> #define EXTERN #include "tty.h" #undef EXTERN @@ -11,29 +11,7 @@ get_tty(fd, ts) int fd; TTY_state *ts; { - int ret; - -# ifdef HAVE_TERMIOS_H - ret = tcgetattr(fd, ts); -# else /* HAVE_TERIOS_H */ -# ifdef HAVE_TERMIO_H - ret = ioctl(fd, TCGETA, ts); -# else /* HAVE_TERMIO_H */ - ret = ioctl(fd, TIOCGETP, &ts->sgttyb); -# ifdef TIOCGATC - if (ioctl(fd, TIOCGATC, &ts->lchars) < 0) - ret = -1; -# else - if (ioctl(fd, TIOCGETC, &ts->tchars) < 0) - ret = -1; -# ifdef TIOCGLTC - if (ioctl(fd, TIOCGLTC, &ts->ltchars) < 0) - ret = -1; -# endif /* TIOCGLTC */ -# endif /* TIOCGATC */ -# endif /* HAVE_TERMIO_H */ -# endif /* HAVE_TERIOS_H */ - return ret; + return tcgetattr(fd, ts); } int @@ -42,56 +20,7 @@ set_tty(fd, ts, flags) TTY_state *ts; int flags; { - int ret = 0; - -# ifdef HAVE_TERMIOS_H - ret = tcsetattr(fd, TCSADRAIN, ts); -# else /* HAVE_TERIOS_H */ -# ifdef HAVE_TERMIO_H -# ifndef TCSETAW /* e.g. Cray-2 */ - /* first wait for output to drain */ -# ifdef TCSBRK - if (ioctl(tty_fd, TCSBRK, 1) < 0) - ret = -1; -# else /* the following kludge is minimally intrusive, but sometimes fails */ - if (flags & TF_WAIT) - sleep((unsigned)1); /* fake it */ -# endif -# endif /* !TCSETAW */ -# if defined(_BSD_SYSV) || !defined(TCSETAW) -/* _BSD_SYSV must force TIOCSETN instead of TIOCSETP (preserve type-ahead) */ - if (ioctl(tty_fd, TCSETA, ts) < 0) - ret = -1; -# else - if (ioctl(tty_fd, TCSETAW, ts) < 0) - ret = -1; -# endif -# else /* HAVE_TERMIO_H */ -# if defined(__mips) && (defined(_SYSTYPE_BSD43) || defined(__SYSTYPE_BSD43)) - /* Under RISC/os 5.00, bsd43 environment, after a tty driver - * generated interrupt (eg, INTR, TSTP), all output to tty is - * lost until a SETP is done (there must be a better way of - * doing this...). - */ - if (flags & TF_MIPSKLUDGE) - ret = ioctl(fd, TIOCSETP, &ts->sgttyb); - else -# endif /* _SYSTYPE_BSD43 */ - ret = ioctl(fd, TIOCSETN, &ts->sgttyb); -# ifdef TIOCGATC - if (ioctl(fd, TIOCSATC, &ts->lchars) < 0) - ret = -1; -# else - if (ioctl(fd, TIOCSETC, &ts->tchars) < 0) - ret = -1; -# ifdef TIOCGLTC - if (ioctl(fd, TIOCSLTC, &ts->ltchars) < 0) - ret = -1; -# endif /* TIOCGLTC */ -# endif /* TIOCGATC */ -# endif /* HAVE_TERMIO_H */ -# endif /* HAVE_TERIOS_H */ - return ret; + return tcsetattr(fd, TCSADRAIN, ts); } @@ -111,38 +40,15 @@ tty_init(init_ttystate) } tty_devtty = 1; - /* SCO can't job control on /dev/tty, so don't try... */ -#if !defined(__SCO__) if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) { -#ifdef __NeXT - /* rlogin on NeXT boxes does not set up the controlling tty, - * so force it to be done here... - */ - { - extern char *ttyname ARGS((int)); - char *s = ttyname(isatty(2) ? 2 : 0); - int fd; - - if (s && (fd = open(s, O_RDWR, 0)) >= 0) { - close(fd); - tfd = open("/dev/tty", O_RDWR, 0); - } - } -#endif /* __NeXT */ -/* X11R5 xterm on mips doesn't set controlling tty properly - temporary hack */ -# if !defined(__mips) || !(defined(_SYSTYPE_BSD43) || defined(__SYSTYPE_BSD43)) if (tfd < 0) { tty_devtty = 0; warningf(FALSE, "No controlling tty (open /dev/tty: %s)", strerror(errno)); } -# endif /* __mips */ } -#else /* !__SCO__ */ - tfd = -1; -#endif /* __SCO__ */ if (tfd < 0) { do_close = 0; @@ -155,7 +61,7 @@ tty_init(init_ttystate) return; } } - if ((tty_fd = ksh_dupbase(tfd, FDBASE)) < 0) { + if ((tty_fd = fcntl(tfd, F_DUPFD, FDBASE)) < 0) { warningf(FALSE, "j_ttyinit: dup of tty fd failed: %s", strerror(errno)); } else if (fd_clexec(tty_fd) < 0) { diff --git a/bin/ksh/tty.h b/bin/ksh/tty.h index a6cd2dae1e9..f51ee9a6235 100644 --- a/bin/ksh/tty.h +++ b/bin/ksh/tty.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.h,v 1.2 1996/11/21 07:59:36 downsj Exp $ */ +/* $OpenBSD: tty.h,v 1.3 2004/12/18 20:55:52 millert Exp $ */ /* tty.h -- centralized definitions for a variety of terminal interfaces @@ -20,72 +20,8 @@ # define EXTERN_DEFINED #endif -/* Don't know of a system on which including sys/ioctl.h with termios.h - * causes problems. If there is one, these lines need to be deleted and - * aclocal.m4 needs to have stuff un-commented. - */ -#ifdef SYS_IOCTL_WITH_TERMIOS -# define SYS_IOCTL_WITH_TERMIOS -#endif /* SYS_IOCTL_WITH_TERMIOS */ -#ifdef SYS_IOCTL_WITH_TERMIO -# define SYS_IOCTL_WITH_TERMIO -#endif /* SYS_IOCTL_WITH_TERMIO */ - -#ifdef HAVE_TERMIOS_H -# include <termios.h> -# ifdef SYS_IOCTL_WITH_TERMIOS -# if !(defined(sun) && !defined(__svr4__)) /* too many warnings on sunos */ - /* Need to include sys/ioctl.h on some systems to get the TIOCGWINSZ - * stuff (eg, digital unix). - */ -# include <sys/ioctl.h> -# endif /* !(sun && !__svr4__) */ -# endif /* SYS_IOCTL_WITH_TERMIOS */ +#include <termios.h> typedef struct termios TTY_state; -#else -# ifdef HAVE_TERMIO_H -# include <termio.h> -# ifdef SYS_IOCTL_WITH_TERMIO -# include <sys/ioctl.h> /* see comment above in termios stuff */ -# endif /* SYS_IOCTL_WITH_TERMIO */ -# if _BSD_SYSV /* BRL UNIX System V emulation */ -# ifndef NTTYDISC -# define TIOCGETD _IOR( 't', 0, int ) -# define TIOCSETD _IOW( 't', 1, int ) -# define NTTYDISC 2 -# endif -# ifndef TIOCSTI -# define TIOCSTI _IOW( 't', 114, char ) -# endif -# ifndef TIOCSPGRP -# define TIOCSPGRP _IOW( 't', 118, int ) -# endif -# endif /* _BSD_SYSV */ -typedef struct termio TTY_state; -# else /* HAVE_TERMIO_H */ -/* Assume BSD tty stuff. Uses TIOCGETP, TIOCSETN; uses TIOCGATC/TIOCSATC if - * available, otherwise it uses TIOCGETC/TIOCSETC (also uses TIOCGLTC/TIOCSLTC - * if available) - */ -# ifdef _MINIX -# include <sgtty.h> -# define TIOCSETN TIOCSETP -# else -# include <sys/ioctl.h> -# endif -typedef struct { - struct sgttyb sgttyb; -# ifdef TIOCGATC - struct lchars lchars; -# else /* TIOCGATC */ - struct tchars tchars; -# ifdef TIOCGLTC - struct ltchars ltchars; -# endif /* TIOCGLTC */ -# endif /* TIOCGATC */ -} TTY_state; -# endif /* HAVE_TERMIO_H */ -#endif /* HAVE_TERMIOS_H */ /* Flags for set_tty() */ #define TF_NONE 0x00 @@ -96,10 +32,10 @@ EXTERN int tty_fd I__(-1); /* dup'd tty file descriptor */ EXTERN int tty_devtty; /* true if tty_fd is from /dev/tty */ EXTERN TTY_state tty_state; /* saved tty state */ -extern int get_tty ARGS((int fd, TTY_state *ts)); -extern int set_tty ARGS((int fd, TTY_state *ts, int flags)); -extern void tty_init ARGS((int init_ttystate)); -extern void tty_close ARGS((void)); +extern int get_tty(int fd, TTY_state *ts); +extern int set_tty(int fd, TTY_state *ts, int flags); +extern void tty_init(int init_ttystate); +extern void tty_close(void); /* be sure not to interfere with anyone else's idea about EXTERN */ #ifdef EXTERN_DEFINED diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 989542aa044..688d9630b70 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,9 +1,9 @@ -/* $OpenBSD: var.c,v 1.17 2004/05/08 19:42:35 deraadt Exp $ */ +/* $OpenBSD: var.c,v 1.18 2004/12/18 20:55:52 millert Exp $ */ #include "sh.h" -#include "ksh_time.h" +#include <time.h> #include "ksh_limval.h" -#include "ksh_stat.h" +#include <sys/stat.h> #include <ctype.h> /* @@ -17,14 +17,14 @@ */ static struct tbl vtemp; static struct table specials; -static char *formatstr ARGS((struct tbl *vp, const char *s)); -static void export ARGS((struct tbl *vp, const char *val)); -static int special ARGS((const char *name)); -static void unspecial ARGS((const char *name)); -static void getspec ARGS((struct tbl *vp)); -static void setspec ARGS((struct tbl *vp)); -static void unsetspec ARGS((struct tbl *vp)); -static struct tbl *arraysearch ARGS((struct tbl *, int)); +static char *formatstr(struct tbl *vp, const char *s); +static void export(struct tbl *vp, const char *val); +static int special(const char *name); +static void unspecial(const char *name); +static void getspec(struct tbl *vp); +static void setspec(struct tbl *vp); +static void unsetspec(struct tbl *vp); +static struct tbl *arraysearch(struct tbl *, int); /* * create a new block for function calls and simple commands @@ -664,8 +664,8 @@ typeset(var, set, clr, field, base) */ for (t = vpbase; t; t = t->u.array) { int fake_assign; - char UNINITIALIZED(*s); - char UNINITIALIZED(*free_me); + char *s = NULL; + char *free_me = NULL; fake_assign = (t->flag & ISSET) && (!val || t != vp) && ((set & (UCASEV_AL|LCASEV|LJUST|RJUST|ZEROFIL)) @@ -1013,7 +1013,7 @@ setspec(vp) { struct stat statb; s = str_val(vp); - if (ISABSPATH(s) && eaccess(s, W_OK|X_OK) == 0 + if (s[0] == '/' && access(s, W_OK|X_OK) == 0 && stat(s, &statb) == 0 && S_ISDIR(statb.st_mode)) tmpdir = str_save(s, APERM); } diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c index b9c1b93efa6..235b4e5db3b 100644 --- a/bin/ksh/vi.c +++ b/bin/ksh/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.13 2004/05/10 16:28:47 pvalchev Exp $ */ +/* $OpenBSD: vi.c,v 1.14 2004/12/18 20:55:52 millert Exp $ */ /* * vi command editing @@ -11,7 +11,7 @@ #include "sh.h" #include <ctype.h> -#include "ksh_stat.h" /* completion */ +#include <sys/stat.h> /* completion */ #include "edit.h" #define CMDLEN 2048 @@ -27,45 +27,45 @@ struct edstate { }; -static int vi_hook ARGS((int ch)); -static void vi_reset ARGS((char *buf, size_t len)); -static int nextstate ARGS((int ch)); -static int vi_insert ARGS((int ch)); -static int vi_cmd ARGS((int argcnt, const char *cmd)); -static int domove ARGS((int argcnt, const char *cmd, int sub)); -static int redo_insert ARGS((int count)); -static void yank_range ARGS((int a, int b)); -static int bracktype ARGS((int ch)); -static void save_cbuf ARGS((void)); -static void restore_cbuf ARGS((void)); -static void edit_reset ARGS((char *buf, size_t len)); -static int putbuf ARGS((const char *buf, int len, int repl)); -static void del_range ARGS((int a, int b)); -static int findch ARGS((int ch, int cnt, int forw, int incl)); -static int forwword ARGS((int argcnt)); -static int backword ARGS((int argcnt)); -static int endword ARGS((int argcnt)); -static int Forwword ARGS((int argcnt)); -static int Backword ARGS((int argcnt)); -static int Endword ARGS((int argcnt)); -static int grabhist ARGS((int save, int n)); -static int grabsearch ARGS((int save, int start, int fwd, char *pat)); -static void redraw_line ARGS((int newline)); -static void refresh ARGS((int leftside)); -static int outofwin ARGS((void)); -static void rewindow ARGS((void)); -static int newcol ARGS((int ch, int col)); -static void display ARGS((char *wb1, char *wb2, int leftside)); -static void ed_mov_opt ARGS((int col, char *wb)); -static int expand_word ARGS((int command)); -static int complete_word ARGS((int command, int count)); -static int print_expansions ARGS((struct edstate *e, int command)); -static int char_len ARGS((int c)); -static void x_vi_zotc ARGS((int c)); -static void vi_pprompt ARGS((int full)); -static void vi_error ARGS((void)); -static void vi_macro_reset ARGS((void)); -static int x_vi_putbuf ARGS((const char *s, size_t len)); +static int vi_hook(int ch); +static void vi_reset(char *buf, size_t len); +static int nextstate(int ch); +static int vi_insert(int ch); +static int vi_cmd(int argcnt, const char *cmd); +static int domove(int argcnt, const char *cmd, int sub); +static int redo_insert(int count); +static void yank_range(int a, int b); +static int bracktype(int ch); +static void save_cbuf(void); +static void restore_cbuf(void); +static void edit_reset(char *buf, size_t len); +static int putbuf(const char *buf, int len, int repl); +static void del_range(int a, int b); +static int findch(int ch, int cnt, int forw, int incl); +static int forwword(int argcnt); +static int backword(int argcnt); +static int endword(int argcnt); +static int Forwword(int argcnt); +static int Backword(int argcnt); +static int Endword(int argcnt); +static int grabhist(int save, int n); +static int grabsearch(int save, int start, int fwd, char *pat); +static void redraw_line(int newline); +static void refresh(int leftside); +static int outofwin(void); +static void rewindow(void); +static int newcol(int ch, int col); +static void display(char *wb1, char *wb2, int leftside); +static void ed_mov_opt(int col, char *wb); +static int expand_word(int command); +static int complete_word(int command, int count); +static int print_expansions(struct edstate *e, int command); +static int char_len(int c); +static void x_vi_zotc(int c); +static void vi_pprompt(int full); +static void vi_error(void); +static void vi_macro_reset(void); +static int x_vi_putbuf(const char *s, size_t len); #define C_ 0x1 /* a valid command that isn't a M_, E_, U_ */ #define M_ 0x2 /* movement command (h, l, etc.) */ @@ -141,9 +141,9 @@ const unsigned char classify[128] = { static char undocbuf[CMDLEN]; -static struct edstate *save_edstate ARGS((struct edstate *old)); -static void restore_edstate ARGS((struct edstate *old, struct edstate *new)); -static void free_edstate ARGS((struct edstate *old)); +static struct edstate *save_edstate(struct edstate *old); +static void restore_edstate(struct edstate *old, struct edstate *new); +static void free_edstate(struct edstate *old); static struct edstate ebuf; static struct edstate undobuf = { 0, undocbuf, CMDLEN, 0, 0 }; @@ -268,32 +268,8 @@ vi_hook(ch) } switch (vi_insert(ch)) { case -1: -#ifdef OS2 - /* Arrow keys generate 0xe0X, where X is H.. */ - state = VCMD; - argc1 = 1; - switch (x_getc()) { - case 'H': - *curcmd='k'; - break; - case 'K': - *curcmd='h'; - break; - case 'P': - *curcmd='j'; - break; - case 'M': - *curcmd='l'; - break; - default: - vi_error(); - state = VNORMAL; - } - break; -#else /* OS2 */ vi_error(); state = VNORMAL; -#endif /* OS2 */ break; case 0: if (state == VLIT) { @@ -650,10 +626,6 @@ vi_insert(ch) if (first_insert && ch != Ctrl('[')) saved_inslen = 0; switch (ch) { - -#ifdef OS2 - case 224: /* function key prefix */ -#endif /* OS2 */ case '\0': return -1; @@ -1175,8 +1147,8 @@ domove(argcnt, cmd, sub) const char *cmd; int sub; { - int bcount, UNINITIALIZED(i), t; - int UNINITIALIZED(ncursor); + int bcount, i = 0, t; + int ncursor = 0; switch (*cmd) { @@ -1734,8 +1706,8 @@ grabsearch(save, start, fwd, pat) anchored = *pat == '^' ? (++pat, 1) : 0; if ((hist = findhist(start, fwd, pat, anchored)) < 0) { /* if (start != 0 && fwd && match(holdbuf, pat) >= 0) { */ - /* XXX should FILECMP be strncmp? */ - if (start != 0 && fwd && FILECMP(holdbuf, pat) >= 0) { + /* XXX should strcmp be strncmp? */ + if (start != 0 && fwd && strcmp(holdbuf, pat) >= 0) { restore_cbuf(); return 0; } else @@ -1837,7 +1809,7 @@ display(wb1, wb2, leftside) unsigned char ch; char *twb1, *twb2, mc; int cur, col, cnt; - int UNINITIALIZED(ncol); + int ncol = 0; int moreright; col = 0; @@ -2067,7 +2039,7 @@ complete_word(command, count) /* If more than one possible match, use full path */ for (i = 0; i < nwords; i++) if (i != count && - FILECMP(words[i] + strcmp(words[i] + x_basename(words[i], (char *) 0), match) == 0) { @@ -2101,7 +2073,7 @@ complete_word(command, count) expanded = NONE; /* If not a directory, add a space to the end... */ - if (match_len > 0 && !ISDIRSEP(match[match_len - 1])) + if (match_len > 0 && match[match_len - 1] != '/') rval = putbuf(space, 1, 0); } x_free_words(nwords, words); |