run GNU protoize

protect header files
nuke some dead code
regenerate configure script
let silly code die
This commit is contained in:
tg 2004-10-28 11:53:44 +00:00
parent dc7da8ddbf
commit b2de14e57c
46 changed files with 1024 additions and 1991 deletions

20
aclocal.m4 vendored
View File

@ -1,4 +1,4 @@
dnl $MirBSD: aclocal.m4,v 1.9 2004/05/24 19:55:54 tg Stab $ dnl $MirBSD: aclocal.m4,v 1.10 2004/10/28 11:53:39 tg Exp $
dnl dnl
dnl Copyright (c) 2004 Thorsten Glaser dnl Copyright (c) 2004 Thorsten Glaser
dnl Copyright (C) 1996, Memorial University of Newfoundland. dnl Copyright (C) 1996, Memorial University of Newfoundland.
@ -346,24 +346,6 @@ AC_DEFUN(KSH_C_VOLATILE,
dnl dnl
dnl dnl
dnl dnl
dnl Check if function prototypes work (including stdc vararg prototypes)
AC_DEFUN(KSH_C_PROTOTYPES,
[AC_CACHE_CHECK(if compiler understands prototypes, ksh_cv_c_prototypes,
[AC_TRY_COMPILE([
#include <stdarg.h>
void foo(char *fmt, ...);
int bar(int a, char b, char *c);
int bar(a, b, c) int a; char b; char *c;
{ foo("%d%c%s\n", a, b, c); return a + b + *c; }
void foo(char *fmt, ...) { va_list a; va_start(a, fmt); va_end(a); }
], , ksh_cv_c_prototypes=yes, ksh_cv_c_prototypes=no)])
if test $ksh_cv_c_prototypes = yes; then
AC_DEFINE(HAVE_PROTOTYPES)
fi
])dnl
dnl
dnl
dnl
dnl Check if C compiler understands gcc's __attribute((...)). dnl Check if C compiler understands gcc's __attribute((...)).
dnl checks for noreturn, const, and format(type,fmt,param), also checks dnl checks for noreturn, const, and format(type,fmt,param), also checks
dnl that the compiler doesn't die when it sees an unknown attribute (this dnl that the compiler doesn't die when it sees an unknown attribute (this

55
c_ksh.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: c_ksh.c,v 1.8 2004/10/28 11:11:16 tg Exp $ */ /** $MirBSD: c_ksh.c,v 1.9 2004/10/28 11:53:39 tg Exp $ */
/* $OpenBSD: c_ksh.c,v 1.18 2004/02/10 13:03:36 jmc Exp $ */ /* $OpenBSD: c_ksh.c,v 1.18 2004/02/10 13:03:36 jmc Exp $ */
/* /*
@ -13,11 +13,10 @@
#include <sys/cygwin.h> #include <sys/cygwin.h>
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
__RCSID("$MirBSD: c_ksh.c,v 1.8 2004/10/28 11:11:16 tg Exp $"); __RCSID("$MirBSD: c_ksh.c,v 1.9 2004/10/28 11:53:39 tg Exp $");
int int
c_cd(wp) c_cd(char **wp)
char **wp;
{ {
int optc; int optc;
int physical = Flag(FPHYSICAL); int physical = Flag(FPHYSICAL);
@ -178,8 +177,7 @@ c_cd(wp)
} }
int int
c_pwd(wp) c_pwd(char **wp)
char **wp;
{ {
int optc; int optc;
int physical = Flag(FPHYSICAL); int physical = Flag(FPHYSICAL);
@ -223,8 +221,7 @@ c_pwd(wp)
} }
int int
c_print(wp) c_print(char **wp)
char **wp;
{ {
#define PO_NL BIT(0) /* print newline */ #define PO_NL BIT(0) /* print newline */
#define PO_EXPAND BIT(1) /* expand backslash sequences */ #define PO_EXPAND BIT(1) /* expand backslash sequences */
@ -447,8 +444,7 @@ c_print(wp)
} }
int int
c_whence(wp) c_whence(char **wp)
char **wp;
{ {
struct tbl *tp; struct tbl *tp;
char *id; char *id;
@ -570,8 +566,7 @@ c_whence(wp)
/* Deal with command -vV - command -p dealt with in comexec() */ /* Deal with command -vV - command -p dealt with in comexec() */
int int
c_command(wp) c_command(char **wp)
char **wp;
{ {
/* Let c_whence do the work. Note that c_command() must be /* Let c_whence do the work. Note that c_command() must be
* a distinct function from c_whence() (tested in comexec()). * a distinct function from c_whence() (tested in comexec()).
@ -581,8 +576,7 @@ c_command(wp)
/* typeset, export, and readonly */ /* typeset, export, and readonly */
int int
c_typeset(wp) c_typeset(char **wp)
char **wp;
{ {
struct block *l = e->loc; struct block *l = e->loc;
struct tbl *vp, **p; struct tbl *vp, **p;
@ -878,8 +872,7 @@ c_typeset(wp)
} }
int int
c_alias(wp) c_alias(char **wp)
char **wp;
{ {
struct table *t = &aliases; struct table *t = &aliases;
int rv = 0, rflag = 0, tflag, Uflag = 0, pflag = 0; int rv = 0, rflag = 0, tflag, Uflag = 0, pflag = 0;
@ -1015,8 +1008,7 @@ c_alias(wp)
} }
int int
c_unalias(wp) c_unalias(char **wp)
char **wp;
{ {
struct table *t = &aliases; struct table *t = &aliases;
struct tbl *ap; struct tbl *ap;
@ -1069,8 +1061,7 @@ c_unalias(wp)
#ifdef KSH #ifdef KSH
int int
c_let(wp) c_let(char **wp)
char **wp;
{ {
int rv = 1; int rv = 1;
long val; long val;
@ -1089,8 +1080,7 @@ c_let(wp)
#endif /* KSH */ #endif /* KSH */
int int
c_jobs(wp) c_jobs(char **wp)
char **wp;
{ {
int optc; int optc;
int flag = 0; int flag = 0;
@ -1128,8 +1118,7 @@ c_jobs(wp)
#ifdef JOBS #ifdef JOBS
int int
c_fgbg(wp) c_fgbg(char **wp)
char **wp;
{ {
int bg = strcmp(*wp, "bg") == 0; int bg = strcmp(*wp, "bg") == 0;
int UNINITIALIZED(rv); int UNINITIALIZED(rv);
@ -1161,11 +1150,7 @@ static char *kill_fmt_entry(void *arg, int i, char *buf, int buflen);
/* format a single kill item */ /* format a single kill item */
static char * static char *
kill_fmt_entry(arg, i, buf, buflen) kill_fmt_entry(void *arg, int i, char *buf, int buflen)
void *arg;
int i;
char *buf;
int buflen;
{ {
struct kill_info *ki = (struct kill_info *) arg; struct kill_info *ki = (struct kill_info *) arg;
@ -1185,8 +1170,7 @@ kill_fmt_entry(arg, i, buf, buflen)
int int
c_kill(wp) c_kill(char **wp)
char **wp;
{ {
Trap *t = (Trap *) 0; Trap *t = (Trap *) 0;
char *p; char *p;
@ -1295,8 +1279,7 @@ c_kill(wp)
} }
void void
getopts_reset(val) getopts_reset(int val)
int val;
{ {
if (val >= 1) { if (val >= 1) {
ksh_getopt_reset(&user_opt, ksh_getopt_reset(&user_opt,
@ -1306,8 +1289,7 @@ getopts_reset(val)
} }
int int
c_getopts(wp) c_getopts(char **wp)
char **wp;
{ {
int argc; int argc;
const char *options; const char *options;
@ -1406,8 +1388,7 @@ c_getopts(wp)
#ifdef EMACS #ifdef EMACS
int int
c_bind(wp) c_bind(char **wp)
char **wp;
{ {
int rv = 0, macro = 0, list = 0; int rv = 0, macro = 0, list = 0;
char *cp; char *cp;

63
c_sh.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: c_sh.c,v 1.6 2004/10/28 11:11:17 tg Exp $ */ /** $MirBSD: c_sh.c,v 1.7 2004/10/28 11:53:39 tg Exp $ */
/* $OpenBSD: c_sh.c,v 1.17 2003/03/13 09:03:07 deraadt Exp $ */ /* $OpenBSD: c_sh.c,v 1.17 2003/03/13 09:03:07 deraadt Exp $ */
/* /*
@ -10,22 +10,20 @@
#include "ksh_time.h" #include "ksh_time.h"
#include "ksh_times.h" #include "ksh_times.h"
__RCSID("$MirBSD: c_sh.c,v 1.6 2004/10/28 11:11:17 tg Exp $"); __RCSID("$MirBSD: c_sh.c,v 1.7 2004/10/28 11:53:39 tg Exp $");
static char *clocktos(clock_t t); static char *clocktos(clock_t t);
/* :, false and true */ /* :, false and true */
int int
c_label(wp) c_label(char **wp)
char **wp;
{ {
return wp[0][0] == 'f' ? 1 : 0; return wp[0][0] == 'f' ? 1 : 0;
} }
int int
c_shift(wp) c_shift(char **wp)
char **wp;
{ {
struct block *l = e->loc; struct block *l = e->loc;
int n; int n;
@ -56,8 +54,7 @@ c_shift(wp)
} }
int int
c_umask(wp) c_umask(char **wp)
char **wp;
{ {
int i; int i;
char *cp; char *cp;
@ -176,8 +173,7 @@ c_umask(wp)
} }
int int
c_dot(wp) c_dot(char **wp)
char **wp;
{ {
char *file, *cp; char *file, *cp;
char **argv; char **argv;
@ -215,8 +211,7 @@ c_dot(wp)
} }
int int
c_wait(wp) c_wait(char **wp)
char **wp;
{ {
int UNINITIALIZED(rv); int UNINITIALIZED(rv);
int sig; int sig;
@ -238,8 +233,7 @@ c_wait(wp)
} }
int int
c_read(wp) c_read(char **wp)
char **wp;
{ {
int c = 0; int c = 0;
int expand = 1, history = 0; int expand = 1, history = 0;
@ -424,8 +418,7 @@ c_read(wp)
} }
int int
c_eval(wp) c_eval(char **wp)
char **wp;
{ {
struct source *s; struct source *s;
@ -465,8 +458,7 @@ c_eval(wp)
} }
int int
c_trap(wp) c_trap(char **wp)
char **wp;
{ {
int i; int i;
char *s; char *s;
@ -488,18 +480,6 @@ c_trap(wp)
shprintf(" %s\n", p->name); shprintf(" %s\n", p->name);
} }
} }
#if 0 /* this is ugly and not clear POSIX needs it */
/* POSIX may need this so output of trap can be saved and
* used to restore trap conditions
*/
if (anydfl) {
shprintf("trap -- -");
for (p = sigtraps, i = SIGNALS+1; --i >= 0; p++)
if (p->trap == NULL && p->name)
shprintf(" %s", p->name);
shprintf(newline);
}
#endif
return 0; return 0;
} }
@ -525,8 +505,7 @@ c_trap(wp)
} }
int int
c_exitreturn(wp) c_exitreturn(char **wp)
char **wp;
{ {
int how = LEXIT; int how = LEXIT;
int n; int n;
@ -568,8 +547,7 @@ c_exitreturn(wp)
} }
int int
c_brkcont(wp) c_brkcont(char **wp)
char **wp;
{ {
int n, quit; int n, quit;
struct env *ep, *last_ep = (struct env *) 0; struct env *ep, *last_ep = (struct env *) 0;
@ -622,8 +600,7 @@ c_brkcont(wp)
} }
int int
c_set(wp) c_set(char **wp)
char **wp;
{ {
int argi, setargs; int argi, setargs;
struct block *l = e->loc; struct block *l = e->loc;
@ -658,8 +635,7 @@ c_set(wp)
} }
int int
c_unset(wp) c_unset(char **wp)
char **wp;
{ {
char *id; char *id;
int optc, unset_var = 1; int optc, unset_var = 1;
@ -713,9 +689,7 @@ c_times(char **wp GCC_FUNC_ATTR(unused))
* time pipeline (really a statement, not a built-in command) * time pipeline (really a statement, not a built-in command)
*/ */
int int
timex(t, f) timex(struct op *t, int f)
struct op *t;
int f;
{ {
#define TF_NOARGS BIT(0) #define TF_NOARGS BIT(0)
#define TF_NOREAL BIT(1) /* don't report real time */ #define TF_NOREAL BIT(1) /* don't report real time */
@ -770,9 +744,7 @@ timex(t, f)
} }
void void
timex_hook(t, app) timex_hook(struct op *t, char **volatile *app)
struct op *t;
char ** volatile *app;
{ {
char **wp = *app; char **wp = *app;
int optc; int optc;
@ -805,8 +777,7 @@ timex_hook(t, app)
} }
static char * static char *
clocktos(t) clocktos(clock_t t)
clock_t t;
{ {
static char temp[22]; /* enough for 64 bit clock_t */ static char temp[22]; /* enough for 64 bit clock_t */
int i; int i;

View File

@ -1,4 +1,4 @@
/** $MirBSD: c_test.c,v 1.6 2004/10/28 11:11:17 tg Exp $ */ /** $MirBSD: c_test.c,v 1.7 2004/10/28 11:53:39 tg Exp $ */
/* $OpenBSD: c_test.c,v 1.10 2003/10/10 19:09:07 millert Exp $ */ /* $OpenBSD: c_test.c,v 1.10 2003/10/10 19:09:07 millert Exp $ */
/* /*
@ -14,7 +14,7 @@
#include "ksh_stat.h" #include "ksh_stat.h"
#include "c_test.h" #include "c_test.h"
__RCSID("$MirBSD: c_test.c,v 1.6 2004/10/28 11:11:17 tg Exp $"); __RCSID("$MirBSD: c_test.c,v 1.7 2004/10/28 11:53:39 tg Exp $");
/* test(1) accepts the following grammar: /* test(1) accepts the following grammar:
oexpr ::= aexpr | aexpr "-o" oexpr ; oexpr ::= aexpr | aexpr "-o" oexpr ;
@ -103,8 +103,7 @@ static int ptest_eval(Test_env *te, Test_op op, const char *opnd1,
static void ptest_error(Test_env *te, int offset, const char *msg); static void ptest_error(Test_env *te, int offset, const char *msg);
int int
c_test(wp) c_test(char **wp)
char **wp;
{ {
int argc; int argc;
int res; int res;
@ -188,10 +187,7 @@ c_test(wp)
*/ */
Test_op Test_op
test_isop(te, meta, s) test_isop(Test_env *te, Test_meta meta, const char *s)
Test_env *te;
Test_meta meta;
const char *s;
{ {
char sc1; char sc1;
const struct t_op *otab; const struct t_op *otab;
@ -211,12 +207,7 @@ test_isop(te, meta, s)
} }
int int
test_eval(te, op, opnd1, opnd2, do_eval) test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, int do_eval)
Test_env *te;
Test_op op;
const char *opnd1;
const char *opnd2;
int do_eval;
{ {
int res; int res;
int not; int not;
@ -421,9 +412,7 @@ test_eval(te, op, opnd1, opnd2, do_eval)
/* Nasty kludge to handle Korn's bizarre /dev/fd hack */ /* Nasty kludge to handle Korn's bizarre /dev/fd hack */
static int static int
test_stat(path, statb) test_stat(const char *path, struct stat *statb)
const char *path;
struct stat *statb;
{ {
#if !defined(HAVE_DEV_FD) #if !defined(HAVE_DEV_FD)
int fd; int fd;
@ -439,9 +428,7 @@ test_stat(path, statb)
* non-directories when running as root. * non-directories when running as root.
*/ */
static int static int
test_eaccess(path, mode) test_eaccess(const char *path, int mode)
const char *path;
int mode;
{ {
int res; int res;
@ -482,8 +469,7 @@ test_eaccess(path, mode)
} }
int int
test_parse(te) test_parse(Test_env *te)
Test_env *te;
{ {
int res; int res;
@ -496,9 +482,7 @@ test_parse(te)
} }
static int static int
test_oexpr(te, do_eval) test_oexpr(Test_env *te, int do_eval)
Test_env *te;
int do_eval;
{ {
int res; int res;
@ -511,9 +495,7 @@ test_oexpr(te, do_eval)
} }
static int static int
test_aexpr(te, do_eval) test_aexpr(Test_env *te, int do_eval)
Test_env *te;
int do_eval;
{ {
int res; int res;
@ -526,9 +508,7 @@ test_aexpr(te, do_eval)
} }
static int static int
test_nexpr(te, do_eval) test_nexpr(Test_env *te, int do_eval)
Test_env *te;
int do_eval;
{ {
if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_NOT)) if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_NOT))
return !test_nexpr(te, do_eval); return !test_nexpr(te, do_eval);
@ -536,9 +516,7 @@ test_nexpr(te, do_eval)
} }
static int static int
test_primary(te, do_eval) test_primary(Test_env *te, int do_eval)
Test_env *te;
int do_eval;
{ {
const char *opnd1, *opnd2; const char *opnd1, *opnd2;
int res; int res;
@ -597,9 +575,7 @@ test_primary(te, do_eval)
* TM_UNOP and TM_BINOP, the returned value is a Test_op). * TM_UNOP and TM_BINOP, the returned value is a Test_op).
*/ */
static int static int
ptest_isa(te, meta) ptest_isa(Test_env *te, Test_meta meta)
Test_env *te;
Test_meta meta;
{ {
/* Order important - indexed by Test_meta values */ /* Order important - indexed by Test_meta values */
static const char *const tokens[] = { static const char *const tokens[] = {
@ -633,21 +609,13 @@ ptest_getopnd(Test_env *te, Test_op op, int do_eval GCC_FUNC_ATTR(unused))
} }
static int static int
ptest_eval(te, op, opnd1, opnd2, do_eval) ptest_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, int do_eval)
Test_env *te;
Test_op op;
const char *opnd1;
const char *opnd2;
int do_eval;
{ {
return test_eval(te, op, opnd1, opnd2, do_eval); return test_eval(te, op, opnd1, opnd2, do_eval);
} }
static void static void
ptest_error(te, offset, msg) ptest_error(Test_env *te, int offset, const char *msg)
Test_env *te;
int offset;
const char *msg;
{ {
const char *op = te->pos.wp + offset >= te->wp_end ? const char *op = te->pos.wp + offset >= te->wp_end ?
(const char *) 0 : te->pos.wp[offset]; (const char *) 0 : te->pos.wp[offset];

View File

@ -1,6 +1,9 @@
/** $MirBSD: c_test.h,v 1.4 2004/10/28 11:11:17 tg Exp $ */ /** $MirBSD: c_test.h,v 1.5 2004/10/28 11:53:40 tg Exp $ */
/* $OpenBSD: c_test.h,v 1.2 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: c_test.h,v 1.2 2003/10/22 07:40:38 jmc Exp $ */
#ifndef C_TEST_H
#define C_TEST_H
/* Various types of operations. Keeping things grouped nicely /* Various types of operations. Keeping things grouped nicely
* (unary,binary) makes switch() statements more efficient. * (unary,binary) makes switch() statements more efficient.
*/ */
@ -54,3 +57,5 @@ 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, int test_eval(Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval); const char *opnd2, int do_eval);
int test_parse(Test_env *te); int test_parse(Test_env *te);
#endif /* ndef C_TEST_H */

View File

@ -1,4 +1,4 @@
/** $MirBSD: c_ulimit.c,v 1.7 2004/10/28 11:03:22 tg Exp $ */ /** $MirBSD: c_ulimit.c,v 1.8 2004/10/28 11:53:40 tg Exp $ */
/* $OpenBSD: c_ulimit.c,v 1.10 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: c_ulimit.c,v 1.10 2003/10/22 07:40:38 jmc Exp $ */
/* /*
@ -32,7 +32,7 @@ extern long ulimit();
# endif /* HAVE_ULIMIT */ # endif /* HAVE_ULIMIT */
#endif /* HAVE_ULIMIT_H */ #endif /* HAVE_ULIMIT_H */
__RCSID("$MirBSD: c_ulimit.c,v 1.7 2004/10/28 11:03:22 tg Exp $"); __RCSID("$MirBSD: c_ulimit.c,v 1.8 2004/10/28 11:53:40 tg Exp $");
#define SOFT 0x1 #define SOFT 0x1
#define HARD 0x2 #define HARD 0x2
@ -44,8 +44,7 @@ __RCSID("$MirBSD: c_ulimit.c,v 1.7 2004/10/28 11:03:22 tg Exp $");
#endif /* RLIM_INFINITY */ #endif /* RLIM_INFINITY */
int int
c_ulimit(wp) c_ulimit(char **wp)
char **wp;
{ {
static const struct limits { static const struct limits {
const char *name; const char *name;

View File

@ -1,6 +1,9 @@
/** $MirBSD: conf-end.h,v 1.7 2004/09/21 11:57:07 tg Exp $ */ /** $MirBSD: conf-end.h,v 1.8 2004/10/28 11:53:40 tg Exp $ */
/* $OpenBSD: conf-end.h,v 1.2 1996/08/25 12:37:58 downsj Exp $ */ /* $OpenBSD: conf-end.h,v 1.2 1996/08/25 12:37:58 downsj Exp $ */
#ifndef CONF_END_H
#define CONF_END_H
/* Include ksh features? */ /* Include ksh features? */
/* #define KSH 1 */ /* #define KSH 1 */
@ -23,17 +26,11 @@
#define COMPLEX_HISTORY #define COMPLEX_HISTORY
/* Strict POSIX behaviour? */ /* Strict POSIX behaviour? */
/* #undef POSIXLY_CORRECT */ #undef POSIXLY_CORRECT
/* Specify default $ENV? */ /* Specify default $ENV? */
/* #undef DEFAULT_ENV */ /* #undef DEFAULT_ENV */
/* Include shl(1) support? */
/* #undef SWTCH */
/* Include game-of-life? */
/* #undef SILLY */
/* /*
* The above are defined for mirbsdksh via external * The above are defined for mirbsdksh via external
* means, such as this header ;-) * means, such as this header ;-)
@ -58,11 +55,6 @@
# define HISTORY # define HISTORY
#endif /* EDIT */ #endif /* EDIT */
/* It's there, use it */
#if defined(KSH) && defined(EDIT)
# define SILLY
#endif
/* /*
* if you don't have mmap() you can't use Peter Collinson's history * if you don't have mmap() you can't use Peter Collinson's history
* mechanism. If that is the case, then define EASY_HISTORY * mechanism. If that is the case, then define EASY_HISTORY
@ -113,3 +105,5 @@
# define GCC_FUNC_ATTR(x) # define GCC_FUNC_ATTR(x)
# define GCC_FUNC_ATTR2(x,y) # define GCC_FUNC_ATTR2(x,y)
#endif /* HAVE_GCC_FUNC_ATTR */ #endif /* HAVE_GCC_FUNC_ATTR */
#endif /* ndef CONF_END_H */

View File

@ -1,4 +1,4 @@
/** $MirBSD: config.h,v 1.12 2004/09/21 11:57:08 tg Exp $ */ /** $MirBSD: config.h,v 1.13 2004/10/28 11:53:40 tg Exp $ */
/* $OpenBSD: config.h,v 1.9 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: config.h,v 1.9 2003/10/22 07:40:38 jmc Exp $ */
/* /*
@ -118,9 +118,6 @@
/* Define to nothing if compiler doesn't like the volatile keyword */ /* Define to nothing if compiler doesn't like the volatile keyword */
/* #undef volatile */ /* #undef volatile */
/* Define if C compiler groks function prototypes */
#define HAVE_PROTOTYPES 1
/* Define if C compiler groks __attribute__((...)) (const, noreturn, format) */ /* Define if C compiler groks __attribute__((...)) (const, noreturn, format) */
#define HAVE_GCC_FUNC_ATTR 1 #define HAVE_GCC_FUNC_ATTR 1

770
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
dnl $MirBSD: configure.in,v 1.7 2004/05/24 19:08:52 tg Stab $ dnl $MirBSD: configure.in,v 1.8 2004/10/28 11:53:41 tg Exp $
dnl dnl
dnl Process this file with autoconf to produce a configure script dnl Process this file with autoconf to produce a configure script
dnl dnl
@ -91,7 +91,6 @@ dnl
AC_C_CONST AC_C_CONST
KSH_C_VOID KSH_C_VOID
KSH_C_VOLATILE KSH_C_VOLATILE
KSH_C_PROTOTYPES
KSH_C_FUNC_ATTR KSH_C_FUNC_ATTR
dnl dnl
dnl System services dnl System services

136
edit.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: edit.c,v 1.9 2004/10/28 11:11:17 tg Exp $ */ /** $MirBSD: edit.c,v 1.10 2004/10/28 11:53:41 tg Exp $ */
/* $OpenBSD: edit.c,v 1.18 2003/08/22 18:17:10 fgsch Exp $ */ /* $OpenBSD: edit.c,v 1.18 2003/08/22 18:17:10 fgsch Exp $ */
/* /*
@ -22,7 +22,7 @@
#include <ctype.h> #include <ctype.h>
#include "ksh_stat.h" #include "ksh_stat.h"
__RCSID("$MirBSD: edit.c,v 1.9 2004/10/28 11:11:17 tg Exp $"); __RCSID("$MirBSD: edit.c,v 1.10 2004/10/28 11:53:41 tg Exp $");
#if defined(TIOCGWINSZ) #if defined(TIOCGWINSZ)
static RETSIGTYPE x_sigwinch(int sig); static RETSIGTYPE x_sigwinch(int sig);
@ -42,7 +42,7 @@ static char vdisable_c;
/* Called from main */ /* Called from main */
void void
x_init() x_init(void)
{ {
/* set to -2 to force initial binding */ /* set to -2 to force initial binding */
edchars.erase = edchars.kill = edchars.intr = edchars.quit edchars.erase = edchars.kill = edchars.intr = edchars.quit
@ -124,9 +124,7 @@ check_sigwinch(void)
* read an edited command line * read an edited command line
*/ */
int int
x_read(buf, len) x_read(char *buf, size_t len)
char *buf;
size_t len;
{ {
int i; int i;
@ -154,7 +152,7 @@ x_read(buf, len)
/* tty I/O */ /* tty I/O */
int int
x_getc() x_getc(void)
{ {
#ifdef OS2 #ifdef OS2
unsigned char c = _read_kbd(0, 1, 0); unsigned char c = _read_kbd(0, 1, 0);
@ -176,29 +174,26 @@ x_getc()
} }
void void
x_flush() x_flush(void)
{ {
shf_flush(shl_out); shf_flush(shl_out);
} }
void void
x_putc(c) x_putc(int c)
int c;
{ {
shf_putc(c, shl_out); shf_putc(c, shl_out);
} }
void void
x_puts(s) x_puts(const char *s)
const char *s;
{ {
while (*s != 0) while (*s != 0)
shf_putc(*s++, shl_out); shf_putc(*s++, shl_out);
} }
bool_t bool_t
x_mode(onoff) x_mode(bool_t onoff)
bool_t onoff;
{ {
static bool_t x_cur_mode; static bool_t x_cur_mode;
bool_t prev; bool_t prev;
@ -232,14 +227,7 @@ x_mode(onoff)
# ifdef _BSD_SYSV /* need to force CBREAK instead of RAW (need CRMOD on output) */ # ifdef _BSD_SYSV /* need to force CBREAK instead of RAW (need CRMOD on output) */
cb.c_lflag &= ~(ICANON|ECHO); cb.c_lflag &= ~(ICANON|ECHO);
# else # 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); cb.c_lflag &= ~(ISIG|ICANON|ECHO);
# endif
# endif # endif
# ifdef VLNEXT # ifdef VLNEXT
/* osf/1 processes lnext when ~icanon */ /* osf/1 processes lnext when ~icanon */
@ -331,9 +319,7 @@ x_mode(onoff)
* length * length
*/ */
int int
promptlen(cp, spp) promptlen(const char *cp, const char **spp)
const char *cp;
const char **spp;
{ {
int count = 0; int count = 0;
const char *sp = cp; const char *sp = cp;
@ -373,8 +359,7 @@ promptlen(cp, spp)
} }
void void
set_editmode(ed) set_editmode(const char *ed)
const char *ed;
{ {
static const enum sh_flag edit_flags[] = { static const enum sh_flag edit_flags[] = {
#ifdef EMACS #ifdef EMACS
@ -408,10 +393,7 @@ set_editmode(ed)
* moved to the start of the line after (un)commenting. * moved to the start of the line after (un)commenting.
*/ */
int int
x_do_comment(buf, bsize, lenp) x_do_comment(char *buf, int bsize, int *lenp)
char *buf;
int bsize;
int *lenp;
{ {
int i, j; int i, j;
int len = *lenp; int len = *lenp;
@ -460,41 +442,8 @@ static void glob_table(const char *pat, XPtrV *wp, struct table *tp);
static void glob_path(int flags, const char *pat, XPtrV *wp, static void glob_path(int flags, const char *pat, XPtrV *wp,
const char *path); const char *path);
#if 0 /* not used... */
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;
int slen;
int is_command;
int *nwordsp;
char **ret;
{
int nwords;
int prefix_len;
char **words;
nwords = (is_command ? x_command_glob : x_file_glob)(XCF_FULLPATH,
str, slen, &words);
*nwordsp = nwords;
if (nwords == 0) {
*ret = (char *) 0;
return -1;
}
prefix_len = x_longest_prefix(nwords, words);
*ret = str_nsave(words[0], prefix_len, ATEMP);
x_free_words(nwords, words);
return prefix_len;
}
#endif /* 0 */
void void
x_print_expansions(nwords, words, is_command) x_print_expansions(int nwords, char *const *words, int is_command)
int nwords;
char *const *words;
int is_command;
{ {
int use_copy = 0; int use_copy = 0;
int prefix_len; int prefix_len;
@ -632,9 +581,7 @@ static int path_order_cmp(const void *aa, const void *bb);
/* Compare routine used in x_command_glob() */ /* Compare routine used in x_command_glob() */
static int static int
path_order_cmp(aa, bb) path_order_cmp(const void *aa, const void *bb)
const void *aa;
const void *bb;
{ {
const struct path_order_info *a = (const struct path_order_info *) aa; const struct path_order_info *a = (const struct path_order_info *) aa;
const struct path_order_info *b = (const struct path_order_info *) bb; const struct path_order_info *b = (const struct path_order_info *) bb;
@ -645,11 +592,7 @@ path_order_cmp(aa, bb)
} }
static int static int
x_command_glob(flags, str, slen, wordsp) x_command_glob(int flags, const char *str, int slen, char ***wordsp)
int flags;
const char *str;
int slen;
char ***wordsp;
{ {
char *toglob; char *toglob;
char *pat; char *pat;
@ -743,12 +686,7 @@ x_command_glob(flags, str, slen, wordsp)
|| (c) == '`' || (c) == '=' || (c) == ':' ) || (c) == '`' || (c) == '=' || (c) == ':' )
static int static int
x_locate_word(buf, buflen, pos, startp, is_commandp) x_locate_word(const char *buf, int buflen, int pos, int *startp, int *is_commandp)
const char *buf;
int buflen;
int pos;
int *startp;
int *is_commandp;
{ {
int p; int p;
int start, end; int start, end;
@ -800,15 +738,7 @@ x_locate_word(buf, buflen, pos, startp, is_commandp)
} }
int int
x_cf_glob(flags, buf, buflen, pos, startp, endp, wordsp, is_commandp) x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp, int *endp, char ***wordsp, int *is_commandp)
int flags;
const char *buf;
int buflen;
int pos;
int *startp;
int *endp;
char ***wordsp;
int *is_commandp;
{ {
int len; int len;
int nwords; int nwords;
@ -844,9 +774,7 @@ x_cf_glob(flags, buf, buflen, pos, startp, endp, wordsp, is_commandp)
* new string is returned. * new string is returned.
*/ */
static char * static char *
add_glob(str, slen) add_glob(const char *str, int slen)
const char *str;
int slen;
{ {
char *toglob; char *toglob;
char *s; char *s;
@ -885,9 +813,7 @@ add_glob(str, slen)
* Find longest common prefix * Find longest common prefix
*/ */
int int
x_longest_prefix(nwords, words) x_longest_prefix(int nwords, char *const *words)
int nwords;
char *const *words;
{ {
int i, j; int i, j;
int prefix_len; int prefix_len;
@ -907,9 +833,7 @@ x_longest_prefix(nwords, words)
} }
void void
x_free_words(nwords, words) x_free_words(int nwords, char **words)
int nwords;
char **words;
{ {
int i; int i;
@ -932,9 +856,7 @@ x_free_words(nwords, words)
* 0 * 0
*/ */
int int
x_basename(s, se) x_basename(const char *s, const char *se)
const char *s;
const char *se;
{ {
const char *p; const char *p;
@ -959,10 +881,7 @@ x_basename(s, se)
* are added to wp. * are added to wp.
*/ */
static void static void
glob_table(pat, wp, tp) glob_table(const char *pat, XPtrV *wp, struct table *tp)
const char *pat;
XPtrV *wp;
struct table *tp;
{ {
struct tstate ts; struct tstate ts;
struct tbl *te; struct tbl *te;
@ -974,11 +893,7 @@ glob_table(pat, wp, tp)
} }
static void static void
glob_path(flags, pat, wp, path) glob_path(int flags, const char *pat, XPtrV *wp, const char *path)
int flags;
const char *pat;
XPtrV *wp;
const char *path;
{ {
const char *sp, *p; const char *sp, *p;
char *xp; char *xp;
@ -1048,10 +963,7 @@ glob_path(flags, pat, wp, path)
* keybinding-specific function * keybinding-specific function
*/ */
int int
x_escape(s, len, putbuf_func) x_escape(const char *s, size_t len, int (*putbuf_func) (const char *, size_t))
const char *s;
size_t len;
int putbuf_func(const char *s, size_t len);
{ {
size_t add, wlen; size_t add, wlen;
const char *ifs = str_val(local("IFS", 0)); const char *ifs = str_val(local("IFS", 0));

13
edit.h
View File

@ -1,7 +1,10 @@
/** $MirBSD: edit.h,v 1.4 2004/10/28 11:11:17 tg Exp $ */ /** $MirBSD: edit.h,v 1.5 2004/10/28 11:53:41 tg Exp $ */
/* $OpenBSD: edit.h,v 1.3 1999/11/14 22:04:02 d Exp $ */ /* $OpenBSD: edit.h,v 1.3 1999/11/14 22:04:02 d Exp $ */
/* $From: edit.h,v 1.2 1994/05/19 18:32:40 michael Exp michael $ */ /* $From: edit.h,v 1.2 1994/05/19 18:32:40 michael Exp michael $ */
#ifndef EDIT_H
#define EDIT_H
/* some useful #defines */ /* some useful #defines */
#ifdef EXTERN #ifdef EXTERN
# define I__(i) = i # define I__(i) = i
@ -67,9 +70,5 @@ int x_vi(char *buf, size_t len);
# undef EXTERN # undef EXTERN
#endif #endif
#undef I__ #undef I__
/*
* Local Variables: #endif /* ndef EDIT_H */
* version-control:t
* comment-column:40
* End:
*/

162
emacs.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: emacs.c,v 1.11 2004/10/28 11:11:17 tg Exp $ */ /** $MirBSD: emacs.c,v 1.12 2004/10/28 11:53:41 tg Exp $ */
/* $OpenBSD: emacs.c,v 1.28 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: emacs.c,v 1.28 2003/10/22 07:40:38 jmc Exp $ */
/* /*
@ -19,7 +19,7 @@
#include <locale.h> #include <locale.h>
#include "edit.h" #include "edit.h"
__RCSID("$MirBSD: emacs.c,v 1.11 2004/10/28 11:11:17 tg Exp $"); __RCSID("$MirBSD: emacs.c,v 1.12 2004/10/28 11:53:41 tg Exp $");
static Area aedit; static Area aedit;
#define AEDIT &aedit /* area for kill ring and macro defns */ #define AEDIT &aedit /* area for kill ring and macro defns */
@ -220,11 +220,6 @@ static const struct x_ftab x_ftab[] = {
{ x_fold_upper, "upcase-word", XF_ARG }, { x_fold_upper, "upcase-word", XF_ARG },
{ x_set_arg, "set-arg", XF_NOBIND }, { x_set_arg, "set-arg", XF_NOBIND },
{ x_comment, "comment", 0 }, { x_comment, "comment", 0 },
#ifdef SILLY
{ x_game_of_life, "play-game-of-life", 0 },
#else
{ 0, 0, 0 },
#endif
#ifdef DEBUG #ifdef DEBUG
{ x_debug_info, "debug-info", 0 }, { x_debug_info, "debug-info", 0 },
#else #else
@ -332,9 +327,7 @@ static struct x_defbindings const x_defbindings[] = {
}; };
int int
x_emacs(buf, len) x_emacs(char *buf, size_t len)
char *buf;
size_t len;
{ {
int c; int c;
const char *p; const char *p;
@ -441,9 +434,7 @@ x_ins_string(int c GCC_FUNC_ATTR(unused))
static int x_do_ins(const char *cp, int len); static int x_do_ins(const char *cp, int len);
static int static int
x_do_ins(cp, len) x_do_ins(const char *cp, int len)
const char *cp;
int len;
{ {
if (xep+len >= xend) { if (xep+len >= xend) {
x_e_putc(BEL); x_e_putc(BEL);
@ -458,8 +449,7 @@ x_do_ins(cp, len)
} }
static int static int
x_ins(s) x_ins(char *s)
char *s;
{ {
char *cp = xcp; char *cp = xcp;
int adj = x_adj_done; int adj = x_adj_done;
@ -489,9 +479,7 @@ x_ins(s)
* this is used for x_escape() in do_complete() * this is used for x_escape() in do_complete()
*/ */
static int static int
x_emacs_putbuf(s, len) x_emacs_putbuf(const char *s, size_t len)
const char *s;
size_t len;
{ {
int rval; int rval;
@ -533,9 +521,7 @@ x_del_char(int c GCC_FUNC_ATTR(unused))
/* Delete nc chars to the right of the cursor (including cursor position) */ /* Delete nc chars to the right of the cursor (including cursor position) */
static void static void
x_delete(nc, push) x_delete(int nc, int push)
int nc;
int push;
{ {
int i,j; int i,j;
char *cp; char *cp;
@ -618,7 +604,7 @@ x_del_fword(int c GCC_FUNC_ATTR(unused))
} }
static int static int
x_bword() x_bword(void)
{ {
int nc = 0; int nc = 0;
char *cp = xcp; char *cp = xcp;
@ -645,7 +631,7 @@ x_bword()
} }
static int static int
x_fword() x_fword(void)
{ {
int nc = 0; int nc = 0;
char *cp = xcp; char *cp = xcp;
@ -671,8 +657,7 @@ x_fword()
} }
static void static void
x_goto(cp) x_goto(char *cp)
char *cp;
{ {
if (cp < xbp || cp >= (xbp + x_displen)) if (cp < xbp || cp >= (xbp + x_displen))
{ {
@ -708,8 +693,7 @@ x_bs(int c GCC_FUNC_ATTR(unused))
} }
static int static int
x_size_str(cp) x_size_str(char *cp)
char *cp;
{ {
int size = 0; int size = 0;
while (*cp) while (*cp)
@ -728,8 +712,7 @@ x_size(int c GCC_FUNC_ATTR(unused))
} }
static void static void
x_zots(str) x_zots(char *str)
char *str;
{ {
int adj = x_adj_done; int adj = x_adj_done;
@ -881,8 +864,7 @@ x_goto_hist(int c GCC_FUNC_ATTR(unused))
} }
static void static void
x_load_hist(hp) x_load_hist(char **hp)
char **hp;
{ {
int oldsize; int oldsize;
@ -903,16 +885,14 @@ x_load_hist(hp)
} }
static int static int
x_nl_next_com(c) x_nl_next_com(int c)
int c;
{ {
x_nextcmd = source->line - (histptr - x_histp) + 1; x_nextcmd = source->line - (histptr - x_histp) + 1;
return (x_newline(c)); return (x_newline(c));
} }
static int static int
x_eot_del(c) x_eot_del(int c)
int c;
{ {
if (xep == xbuf && x_arg_defaulted) if (xep == xbuf && x_arg_defaulted)
return (x_end_of_text(c)); return (x_end_of_text(c));
@ -984,10 +964,7 @@ x_search_hist(int c GCC_FUNC_ATTR(unused))
/* search backward from current line */ /* search backward from current line */
static int static int
x_search(pat, sameline, offset) x_search(char *pat, int sameline, int offset)
char *pat;
int sameline;
int offset;
{ {
char **hp; char **hp;
int i; int i;
@ -1009,8 +986,7 @@ x_search(pat, sameline, offset)
/* return position of first match of pattern in string, else -1 */ /* return position of first match of pattern in string, else -1 */
static int static int
x_match(str, pat) x_match(char *str, char *pat)
char *str, *pat;
{ {
if (*pat == '^') { if (*pat == '^') {
return (strncmp(str, pat+1, strlen(pat+1)) == 0) ? 0 : -1; return (strncmp(str, pat+1, strlen(pat+1)) == 0) ? 0 : -1;
@ -1065,8 +1041,7 @@ x_draw_line(int c GCC_FUNC_ATTR(unused))
* redrawing. * redrawing.
*/ */
static void static void
x_redraw(limit) x_redraw(int limit)
int limit;
{ {
int i, j; int i, j;
char *cp; char *cp;
@ -1223,8 +1198,7 @@ x_kill(int c GCC_FUNC_ATTR(unused))
} }
static void static void
x_push(nchars) x_push(int nchars)
int nchars;
{ {
char *cp = str_nsave(xcp, nchars, AEDIT); char *cp = str_nsave(xcp, nchars, AEDIT);
if (killstack[killsp]) if (killstack[killsp])
@ -1311,7 +1285,7 @@ x_stuffreset(int c GCC_FUNC_ATTR(unused))
static int static int
x_stuff(int c GCC_FUNC_ATTR(unused)) x_stuff(int c GCC_FUNC_ATTR(unused))
{ {
#if 0 || defined TIOCSTI #if defined(TIOCSTI)
char ch = c; char ch = c;
bool_t savmode = x_mode(FALSE); bool_t savmode = x_mode(FALSE);
@ -1323,8 +1297,7 @@ x_stuff(int c GCC_FUNC_ATTR(unused))
} }
static char * static char *
x_mapin(cp) x_mapin(const char *cp)
const char *cp;
{ {
char *new, *op; char *new, *op;
@ -1375,8 +1348,7 @@ x_mapout(int c GCC_FUNC_ATTR(unused))
} }
static void static void
x_print(prefix, key) x_print(int prefix, int key)
int prefix, key;
{ {
if (prefix == 1) if (prefix == 1)
shprintf("%s", x_mapout(x_prefix1)); shprintf("%s", x_mapout(x_prefix1));
@ -1394,10 +1366,10 @@ x_print(prefix, key)
} }
int int
x_bind(a1, a2, macro, list) x_bind(const char *a1, const char *a2, int macro, int list)
const char *a1, *a2;
int macro; /* bind -m */ /* bind -m */
int list; /* bind -l */ /* bind -l */
{ {
Findex f; Findex f;
int prefix, key; int prefix, key;
@ -1462,12 +1434,6 @@ x_bind(a1, a2, macro, list)
bi_errorf("%s: no such function", a2); bi_errorf("%s: no such function", a2);
return 1; return 1;
} }
#if 0 /* This breaks the bind commands that map arrow keys */
if (f == XFUNC_meta1)
x_prefix1 = key;
if (f == XFUNC_meta2)
x_prefix2 = key;
#endif /* 0 */
} else { } else {
f = XFUNC_ins_string; f = XFUNC_ins_string;
m2 = x_mapin(a2); m2 = x_mapin(a2);
@ -1491,7 +1457,7 @@ x_bind(a1, a2, macro, list)
} }
void void
x_init_emacs() x_init_emacs(void)
{ {
unsigned i; unsigned i;
int j; int j;
@ -1527,9 +1493,7 @@ x_init_emacs()
static void bind_if_not_bound(int p, int k, int func); static void bind_if_not_bound(int p, int k, int func);
static void static void
bind_if_not_bound(p, k, func) bind_if_not_bound(int p, int k, int func)
int p, k;
int func;
{ {
/* Has user already bound this key? If so, don't override it */ /* Has user already bound this key? If so, don't override it */
if (x_bound[((p) * X_TABSZ + (k)) / 8] if (x_bound[((p) * X_TABSZ + (k)) / 8]
@ -1540,8 +1504,7 @@ bind_if_not_bound(p, k, func)
} }
void void
x_emacs_keys(ec) x_emacs_keys(X_chars *ec)
X_chars *ec;
{ {
if (ec->erase >= 0) { if (ec->erase >= 0) {
bind_if_not_bound(0, ec->erase, XFUNC_del_back); bind_if_not_bound(0, ec->erase, XFUNC_del_back);
@ -1637,58 +1600,6 @@ x_noop(int c GCC_FUNC_ATTR(unused))
return KSTD; return KSTD;
} }
#ifdef SILLY
static int
x_game_of_life(int c GCC_FUNC_ATTR(unused))
{
char newbuf [256+1];
char *ip, *op;
int i, len;
i = xep - xbuf;
*xep = 0;
len = x_size_str(xbuf);
xcp = xbp = xbuf;
memmove(newbuf+1, xbuf, i);
newbuf[0] = 'A';
newbuf[i] = 'A';
for (ip = newbuf+1, op = xbuf; --i >= 0; ip++, op++) {
/* Empty space */
if (*ip < '@' || *ip == '_' || *ip == 0x7F) {
/* Two adults, make whoopee */
if (ip[-1] < '_' && ip[1] < '_') {
/* Make kid look like parents. */
*op = '`' + ((ip[-1] + ip[1])/2)%32;
if (*op == 0x7F) /* Birth defect */
*op = '`';
}
else
*op = ' '; /* nothing happens */
continue;
}
/* Child */
if (*ip > '`') {
/* All alone, dies */
if (ip[-1] == ' ' && ip[1] == ' ')
*op = ' ';
else /* Gets older */
*op = *ip-'`'+'@';
continue;
}
/* Adult */
/* Overcrowded, dies */
if (ip[-1] >= '@' && ip[1] >= '@') {
*op = ' ';
continue;
}
*op = *ip;
}
*op = 0;
x_redraw(len);
return KSTD;
}
#endif
/* /*
* File/command name completion routines * File/command name completion routines
*/ */
@ -1771,9 +1682,9 @@ x_expand(int c GCC_FUNC_ATTR(unused))
/* type == 0 for list, 1 for complete and 2 for complete-list */ /* type == 0 for list, 1 for complete and 2 for complete-list */
static void static void
do_complete(flags, type) do_complete(int flags, Comp_type type)
int flags; /* XCF_{COMMAND,FILE,COMMAND_FILE} */ /* XCF_{COMMAND,FILE,COMMAND_FILE} */
Comp_type type;
{ {
char **words; char **words;
int nwords; int nwords;
@ -1838,7 +1749,7 @@ do_complete(flags, type)
*/ */
static void static void
x_adjust() x_adjust(void)
{ {
x_adj_done++; /* flag the fact that we were called. */ x_adj_done++; /* flag the fact that we were called. */
/* /*
@ -1860,7 +1771,7 @@ x_e_ungetc(int c GCC_FUNC_ATTR(unused))
} }
static int static int
x_e_getc() x_e_getc(void)
{ {
int c; int c;
@ -1927,8 +1838,7 @@ x_debug_info(int c GCC_FUNC_ATTR(unused))
#endif #endif
static void static void
x_e_puts(s) x_e_puts(const char *s)
const char *s;
{ {
int adj = x_adj_done; int adj = x_adj_done;
@ -2153,7 +2063,7 @@ x_fold_case(int c GCC_FUNC_ATTR(unused))
*/ */
static char * static char *
x_lastcp() x_lastcp(void)
{ {
char *rcp; char *rcp;
int i; int i;

138
eval.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: eval.c,v 1.5 2004/10/28 11:11:17 tg Exp $ */ /** $MirBSD: eval.c,v 1.6 2004/10/28 11:53:41 tg Exp $ */
/* $OpenBSD: eval.c,v 1.14 2003/11/10 21:26:39 millert Exp $ */ /* $OpenBSD: eval.c,v 1.14 2003/11/10 21:26:39 millert Exp $ */
/* /*
@ -10,7 +10,7 @@
#include "ksh_dir.h" #include "ksh_dir.h"
#include "ksh_stat.h" #include "ksh_stat.h"
__RCSID("$MirBSD: eval.c,v 1.5 2004/10/28 11:11:17 tg Exp $"); __RCSID("$MirBSD: eval.c,v 1.6 2004/10/28 11:53:41 tg Exp $");
/* /*
* string expansion * string expansion
@ -60,9 +60,7 @@ static void alt_expand(XPtrV *wp, char *start, char *exp_start,
/* compile and expand word */ /* compile and expand word */
char * char *
substitute(cp, f) substitute(const char *cp, int f)
const char *cp;
int f;
{ {
struct source *s, *sold; struct source *s, *sold;
@ -81,9 +79,7 @@ substitute(cp, f)
* expand arg-list * expand arg-list
*/ */
char ** char **
eval(ap, f) eval(char **ap, int f)
char **ap;
int f;
{ {
XPtrV w; XPtrV w;
@ -108,9 +104,7 @@ eval(ap, f)
* expand string * expand string
*/ */
char * char *
evalstr(cp, f) evalstr(char *cp, int f)
char *cp;
int f;
{ {
XPtrV w; XPtrV w;
@ -126,9 +120,7 @@ evalstr(cp, f)
* used from iosetup to expand redirection files * used from iosetup to expand redirection files
*/ */
char * char *
evalonestr(cp, f) evalonestr(char *cp, int f)
char *cp;
int f;
{ {
XPtrV w; XPtrV w;
@ -161,10 +153,10 @@ typedef struct SubType {
} SubType; } SubType;
void void
expand(cp, wp, f) expand(char *cp, XPtrV *wp, int f)
char *cp; /* input word */ /* input word */
XPtrV *wp; /* output words */ /* output words */
int f; /* DO* flags */ /* DO* flags */
{ {
int UNINITIALIZED(c); int UNINITIALIZED(c);
int type; /* expansion type */ int type; /* expansion type */
@ -691,12 +683,12 @@ expand(cp, wp, f)
* Prepare to generate the string returned by ${} substitution. * Prepare to generate the string returned by ${} substitution.
*/ */
static int static int
varsub(xp, sp, word, stypep, slenp) varsub(Expand *xp, char *sp, char *word, int *stypep, int *slenp)
Expand *xp;
char *sp;
char *word;
int *stypep; /* becomes qualifier type */ /* becomes qualifier type */
int *slenp; /* " " len (=, :=, etc.) valid iff *stypep != 0 */ /* " " len (=, :=, etc.) valid iff *stypep != 0 */
{ {
int c; int c;
int state; /* next state: XBASE, XARG, XSUB, XNULLSUB */ int state; /* next state: XBASE, XARG, XSUB, XNULLSUB */
@ -842,9 +834,7 @@ varsub(xp, sp, word, stypep, slenp)
* Run the command in $(...) and read its output. * Run the command in $(...) and read its output.
*/ */
static int static int
comsub(xp, cp) comsub(Expand *xp, char *cp)
Expand *xp;
char *cp;
{ {
Source *s, *sold; Source *s, *sold;
struct op *t; struct op *t;
@ -896,10 +886,7 @@ comsub(xp, cp)
*/ */
static char * static char *
trimsub(str, pat, how) trimsub(char *str, char *pat, int how)
char *str;
char *pat;
int how;
{ {
char *end = strchr(str, 0); char *end = strchr(str, 0);
char *p, c; char *p, c;
@ -949,10 +936,7 @@ trimsub(str, pat, how)
/* XXX cp not const 'cause slashes are temporarily replaced with nulls... */ /* XXX cp not const 'cause slashes are temporarily replaced with nulls... */
static void static void
glob(cp, wp, markdirs) glob(char *cp, XPtrV *wp, int markdirs)
char *cp;
XPtrV *wp;
int markdirs;
{ {
int oldsize = XPsize(*wp); int oldsize = XPsize(*wp);
@ -972,10 +956,7 @@ glob(cp, wp, markdirs)
* the number of matches found. * the number of matches found.
*/ */
int int
glob_str(cp, wp, markdirs) glob_str(char *cp, XPtrV *wp, int markdirs)
char *cp;
XPtrV *wp;
int markdirs;
{ {
int oldsize = XPsize(*wp); int oldsize = XPsize(*wp);
XString xs; XString xs;
@ -989,12 +970,12 @@ glob_str(cp, wp, markdirs)
} }
static void static void
globit(xs, xpp, sp, wp, check) globit(XString *xs, char **xpp, char *sp, XPtrV *wp, int check)
XString *xs; /* dest string */ /* dest string */
char **xpp; /* ptr to dest end */ /* ptr to dest end */
char *sp; /* source path */ /* source path */
XPtrV *wp; /* output list */ /* output list */
int check; /* GF_* flags */ /* GF_* flags */
{ {
char *np; /* next source component */ char *np; /* next source component */
char *xp = *xpp; char *xp = *xpp;
@ -1135,56 +1116,9 @@ globit(xs, xpp, sp, wp, check)
*--np = odirsep; *--np = odirsep;
} }
#if 0
/* 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(XString *xs, char **xpp, char *p);
static int
copy_non_glob(xs, xpp, p)
XString *xs;
char **xpp;
char *p;
{
char *xp;
int len = strlen(p);
XcheckN(*xs, *xpp, len);
xp = *xpp;
for (; *p; p++) {
if (ISMAGIC(*p)) {
int c = *++p;
if (c == '*' || c == '?')
return 0;
if (*p == '[') {
char *q = p + 1;
if (ISMAGIC(*q) && q[1] == NOT)
q += 2;
if (ISMAGIC(*q) && q[1] == ']')
q += 2;
for (; *q; q++)
if (ISMAGIC(*q) && *++q == ']')
return 0;
/* pass a literal [ through */
}
/* must be a MAGIC-MAGIC, or MAGIC-!, MAGIC--, etc. */
}
*xp++ = *p;
}
*xp = '\0';
*xpp = xp;
return 1;
}
#endif /* 0 */
/* remove MAGIC from string */ /* remove MAGIC from string */
char * char *
debunk(dp, sp, dlen) debunk(char *dp, const char *sp, size_t dlen)
char *dp;
const char *sp;
size_t dlen;
{ {
char *d, *s; char *d, *s;
@ -1214,11 +1148,7 @@ debunk(dp, sp, dlen)
* past the name, otherwise returns 0. * past the name, otherwise returns 0.
*/ */
static char * static char *
maybe_expand_tilde(p, dsp, dpp, isassign) maybe_expand_tilde(char *p, XString *dsp, char **dpp, int isassign)
char *p;
XString *dsp;
char **dpp;
int isassign;
{ {
XString ts; XString ts;
char *dp = *dpp; char *dp = *dpp;
@ -1256,8 +1186,7 @@ maybe_expand_tilde(p, dsp, dpp, isassign)
*/ */
static char * static char *
tilde(cp) tilde(char *cp)
char *cp;
{ {
char *dp; char *dp;
@ -1283,8 +1212,7 @@ tilde(cp)
*/ */
static char * static char *
homedir(name) homedir(char *name)
char *name;
{ {
struct tbl *ap; struct tbl *ap;
@ -1308,11 +1236,7 @@ homedir(name)
#ifdef BRACE_EXPAND #ifdef BRACE_EXPAND
static void static void
alt_expand(wp, start, exp_start, end, fdo) alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
XPtrV *wp;
char *start, *exp_start;
char *end;
int fdo;
{ {
int UNINITIALIZED(count); int UNINITIALIZED(count);
char *brace_start, *brace_end, *UNINITIALIZED(comma); char *brace_start, *brace_end, *UNINITIALIZED(comma);

122
exec.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: exec.c,v 1.5 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: exec.c,v 1.6 2004/10/28 11:53:41 tg Exp $ */
/* $OpenBSD: exec.c,v 1.31 2003/12/15 05:25:52 otto Exp $ */ /* $OpenBSD: exec.c,v 1.31 2003/12/15 05:25:52 otto Exp $ */
/* /*
@ -10,7 +10,7 @@
#include <ctype.h> #include <ctype.h>
#include "ksh_stat.h" #include "ksh_stat.h"
__RCSID("$MirBSD: exec.c,v 1.5 2004/10/28 11:11:18 tg Exp $"); __RCSID("$MirBSD: exec.c,v 1.6 2004/10/28 11:53:41 tg Exp $");
/* Does ps4 get parameter substitutions done? */ /* Does ps4 get parameter substitutions done? */
#ifdef KSH #ifdef KSH
@ -56,8 +56,7 @@ static char clexec_tab[MAXFD+1];
* we now use this function always. * we now use this function always.
*/ */
int int
fd_clexec(fd) fd_clexec(int fd)
int fd;
{ {
#ifndef F_SETFD #ifndef F_SETFD
if (fd >= 0 && fd < sizeof(clexec_tab)) { if (fd >= 0 && fd < sizeof(clexec_tab)) {
@ -75,9 +74,9 @@ fd_clexec(fd)
* execute command tree * execute command tree
*/ */
int int
execute(t, flags) execute(struct op *volatile t, volatile int flags)
struct op * volatile t;
volatile int flags; /* if XEXEC don't fork */ /* if XEXEC don't fork */
{ {
int i; int i;
volatile int rv = 0; volatile int rv = 0;
@ -448,11 +447,7 @@ execute(t, flags)
*/ */
static int static int
comexec(t, tp, ap, flags) comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
struct op *t;
struct tbl *volatile tp;
char **ap;
int volatile flags;
{ {
int i; int i;
volatile int rv = 0; volatile int rv = 0;
@ -754,9 +749,7 @@ comexec(t, tp, ap, flags)
} }
static void static void
scriptexec(tp, ap) scriptexec(struct op *tp, char **ap)
struct op *tp;
char **ap;
{ {
char *shell; char *shell;
@ -868,8 +861,7 @@ scriptexec(tp, ap)
} }
int int
shcomexec(wp) shcomexec(char **wp)
char **wp;
{ {
struct tbl *tp; struct tbl *tp;
@ -884,10 +876,7 @@ shcomexec(wp)
* is created if none is found. * is created if none is found.
*/ */
struct tbl * struct tbl *
findfunc(name, h, create) findfunc(const char *name, unsigned int h, int create)
const char *name;
unsigned int h;
int create;
{ {
struct block *l; struct block *l;
struct tbl *tp = (struct tbl *) 0; struct tbl *tp = (struct tbl *) 0;
@ -912,9 +901,7 @@ findfunc(name, h, create)
* function did not exist, returns 0 otherwise. * function did not exist, returns 0 otherwise.
*/ */
int int
define(name, t) define(const char *name, struct op *t)
const char *name;
struct op *t;
{ {
struct tbl *tp; struct tbl *tp;
int was_set = 0; int was_set = 0;
@ -957,9 +944,7 @@ define(name, t)
* add builtin * add builtin
*/ */
void void
builtin(name, func) builtin(const char *name, int (*func) (char **))
const char *name;
int (*func)(char **);
{ {
struct tbl *tp; struct tbl *tp;
Tflag flag; Tflag flag;
@ -987,9 +972,9 @@ builtin(name, func)
* either function, hashed command, or built-in (in that order) * either function, hashed command, or built-in (in that order)
*/ */
struct tbl * struct tbl *
findcom(name, flags) findcom(const char *name, int flags)
const char *name;
int flags; /* FC_* */ /* FC_* */
{ {
static struct tbl temp; static struct tbl temp;
unsigned int h = hash(name); unsigned int h = hash(name);
@ -1086,8 +1071,8 @@ findcom(name, flags)
* flush executable commands with relative paths * flush executable commands with relative paths
*/ */
void void
flushcom(all) flushcom(int all)
int all; /* just relative or all */ /* just relative or all */
{ {
struct tbl *tp; struct tbl *tp;
struct tstate ts; struct tstate ts;
@ -1104,10 +1089,10 @@ flushcom(all)
/* Check if path is something we want to find. Returns -1 for failure. */ /* Check if path is something we want to find. Returns -1 for failure. */
int int
search_access(path, mode, errnop) search_access(const char *path, int mode, int *errnop)
const char *path;
int mode;
int *errnop; /* set if candidate found, but not suitable */ /* set if candidate found, but not suitable */
{ {
#ifndef OS2 #ifndef OS2
int ret, err = 0; int ret, err = 0;
@ -1201,11 +1186,11 @@ search_access1(path, mode, errnop)
* search for command with PATH * search for command with PATH
*/ */
char * char *
search(name, path, mode, errnop) search(const char *name, const char *path, int mode, int *errnop)
const char *name;
const char *path;
int mode; /* R_OK or X_OK */ /* R_OK or X_OK */
int *errnop; /* set if candidate found, but not suitable */ /* set if candidate found, but not suitable */
{ {
const char *sp, *p; const char *sp, *p;
char *xp; char *xp;
@ -1271,9 +1256,7 @@ search(name, path, mode, errnop)
} }
static int static int
call_builtin(tp, wp) call_builtin(struct tbl *tp, char **wp)
struct tbl *tp;
char **wp;
{ {
int rv; int rv;
@ -1294,9 +1277,7 @@ call_builtin(tp, wp)
* set up redirection, saving old fd's in e->savefd * set up redirection, saving old fd's in e->savefd
*/ */
static int static int
iosetup(iop, tp) iosetup(struct ioword *iop, struct tbl *tp)
struct ioword *iop;
struct tbl *tp;
{ {
int u = -1; int u = -1;
char *cp = iop->name; char *cp = iop->name;
@ -1440,9 +1421,7 @@ iosetup(iop, tp)
* if unquoted here, expand here temp file into second temp file. * if unquoted here, expand here temp file into second temp file.
*/ */
static int static int
herein(content, sub) herein(const char *content, int sub)
const char *content;
int sub;
{ {
volatile int fd = -1; volatile int fd = -1;
struct source *s, *volatile osource; struct source *s, *volatile osource;
@ -1509,9 +1488,7 @@ herein(content, sub)
* print the args in column form - assuming that we can * print the args in column form - assuming that we can
*/ */
static char * static char *
do_selectargs(ap, print_menu) do_selectargs(char **ap, bool_t print_menu)
char **ap;
bool_t print_menu;
{ {
static const char *const read_args[] = { static const char *const read_args[] = {
"read", "-r", "REPLY", (char *) 0 "read", "-r", "REPLY", (char *) 0
@ -1551,11 +1528,7 @@ static char *select_fmt_entry(void *arg, int i, char *buf, int buflen);
/* format a single select menu item */ /* format a single select menu item */
static char * static char *
select_fmt_entry(arg, i, buf, buflen) select_fmt_entry(void *arg, int i, char *buf, int buflen)
void *arg;
int i;
char *buf;
int buflen;
{ {
struct select_menu_info *smi = (struct select_menu_info *) arg; struct select_menu_info *smi = (struct select_menu_info *) arg;
@ -1568,8 +1541,7 @@ select_fmt_entry(arg, i, buf, buflen)
* print a select style menu * print a select style menu
*/ */
int int
pr_menu(ap) pr_menu(char *const *ap)
char *const *ap;
{ {
struct select_menu_info smi; struct select_menu_info smi;
char *const *pp; char *const *pp;
@ -1612,19 +1584,14 @@ pr_menu(ap)
static char *plain_fmt_entry(void *arg, int i, char *buf, int buflen); static char *plain_fmt_entry(void *arg, int i, char *buf, int buflen);
static char * static char *
plain_fmt_entry(arg, i, buf, buflen) plain_fmt_entry(void *arg, int i, char *buf, int buflen)
void *arg;
int i;
char *buf;
int buflen;
{ {
shf_snprintf(buf, buflen, "%s", ((char *const *)arg)[i]); shf_snprintf(buf, buflen, "%s", ((char *const *)arg)[i]);
return buf; return buf;
} }
int int
pr_list(ap) pr_list(char *const *ap)
char *const *ap;
{ {
char *const *pp; char *const *pp;
int nwidth; int nwidth;
@ -1653,9 +1620,7 @@ extern const char db_close[];
* TM_UNOP and TM_BINOP, the returned value is a Test_op). * TM_UNOP and TM_BINOP, the returned value is a Test_op).
*/ */
static int static int
dbteste_isa(te, meta) dbteste_isa(Test_env *te, Test_meta meta)
Test_env *te;
Test_meta meta;
{ {
int ret = 0; int ret = 0;
int uqword; int uqword;
@ -1694,10 +1659,7 @@ dbteste_isa(te, meta)
} }
static const char * static const char *
dbteste_getopnd(te, op, do_eval) dbteste_getopnd(Test_env *te, Test_op op, int do_eval)
Test_env *te;
Test_op op;
int do_eval;
{ {
char *s = *te->pos.wp; char *s = *te->pos.wp;
@ -1718,21 +1680,13 @@ dbteste_getopnd(te, op, do_eval)
} }
static int static int
dbteste_eval(te, op, opnd1, opnd2, do_eval) dbteste_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, int do_eval)
Test_env *te;
Test_op op;
const char *opnd1;
const char *opnd2;
int do_eval;
{ {
return test_eval(te, op, opnd1, opnd2, do_eval); return test_eval(te, op, opnd1, opnd2, do_eval);
} }
static void static void
dbteste_error(te, offset, msg) dbteste_error(Test_env *te, int offset, const char *msg)
Test_env *te;
int offset;
const char *msg;
{ {
te->flags |= TEF_ERROR; te->flags |= TEF_ERROR;
internal_errorf(0, "dbteste_error: %s (offset %d)", msg, offset); internal_errorf(0, "dbteste_error: %s (offset %d)", msg, offset);

View File

@ -1,6 +1,9 @@
/** $MirBSD: expand.h,v 1.5 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: expand.h,v 1.6 2004/10/28 11:53:41 tg Exp $ */
/* $OpenBSD: expand.h,v 1.3 2001/03/26 16:19:45 todd Exp $ */ /* $OpenBSD: expand.h,v 1.3 2001/03/26 16:19:45 todd Exp $ */
#ifndef EXPAND_H
#define EXPAND_H
/* /*
* Expanding strings * Expanding strings
*/ */
@ -106,3 +109,5 @@ typedef struct XPtrV {
sizeofN(void*, XPsize(x)), ATEMP) sizeofN(void*, XPsize(x)), ATEMP)
#define XPfree(x) afree((void*) (x).beg, ATEMP) #define XPfree(x) afree((void*) (x).beg, ATEMP)
#endif /* ndef EXPAND_H */

45
expr.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: expr.c,v 1.6 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: expr.c,v 1.7 2004/10/28 11:53:41 tg Exp $ */
/* $OpenBSD: expr.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: expr.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */
/* /*
@ -8,7 +8,7 @@
#include "sh.h" #include "sh.h"
#include <ctype.h> #include <ctype.h>
__RCSID("$MirBSD: expr.c,v 1.6 2004/10/28 11:11:18 tg Exp $"); __RCSID("$MirBSD: expr.c,v 1.7 2004/10/28 11:53:41 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */ /* The order of these enums is constrained by the order of opinfo[] */
enum token { enum token {
@ -142,10 +142,7 @@ static struct tbl *intvar(Expr_state *es, struct tbl *vp);
* parse and evaluate expression * parse and evaluate expression
*/ */
int int
evaluate(expr, rval, error_ok) evaluate(const char *expr, long int *rval, int error_ok)
const char *expr;
long *rval;
int error_ok;
{ {
struct tbl v; struct tbl v;
int ret; int ret;
@ -161,10 +158,7 @@ evaluate(expr, rval, error_ok)
* parse and evaluate expression, storing result in vp. * parse and evaluate expression, storing result in vp.
*/ */
int int
v_evaluate(vp, expr, error_ok) v_evaluate(struct tbl *vp, const char *expr, volatile int error_ok)
struct tbl *vp;
const char *expr;
volatile int error_ok;
{ {
struct tbl *v; struct tbl *v;
Expr_state curstate; Expr_state curstate;
@ -193,12 +187,10 @@ v_evaluate(vp, expr, error_ok)
} }
token(es); token(es);
#if 1 /* ifdef-out to disallow empty expressions to be treated as 0 */
if (es->tok == END) { if (es->tok == END) {
es->tok = LIT; es->tok = LIT;
es->val = tempvar(); es->val = tempvar();
} }
#endif /* 0 */
v = intvar(es, evalexpr(es, MAX_PREC)); v = intvar(es, evalexpr(es, MAX_PREC));
if (es->tok != END) if (es->tok != END)
@ -216,10 +208,7 @@ v_evaluate(vp, expr, error_ok)
} }
static void static void
evalerr(es, type, str) evalerr(Expr_state *es, enum error_type type, const char *str)
Expr_state *es;
enum error_type type;
const char *str;
{ {
char tbuf[2]; char tbuf[2];
const char *s; const char *s;
@ -275,9 +264,7 @@ evalerr(es, type, str)
} }
static struct tbl * static struct tbl *
evalexpr(es, prec) evalexpr(Expr_state *es, enum prec prec)
Expr_state *es;
enum prec prec;
{ {
struct tbl *vl, UNINITIALIZED(*vr), *vasn; struct tbl *vl, UNINITIALIZED(*vr), *vasn;
enum token op; enum token op;
@ -456,8 +443,7 @@ evalexpr(es, prec)
} }
static void static void
token(es) token(Expr_state *es)
Expr_state *es;
{ {
const char *cp; const char *cp;
int c; int c;
@ -530,11 +516,7 @@ token(es)
/* Do a ++ or -- operation */ /* Do a ++ or -- operation */
static struct tbl * static struct tbl *
do_ppmm(es, op, vasn, is_prefix) do_ppmm(Expr_state *es, enum token op, struct tbl *vasn, bool_t is_prefix)
Expr_state *es;
enum token op;
struct tbl *vasn;
bool_t is_prefix;
{ {
struct tbl *vl; struct tbl *vl;
int oval; int oval;
@ -554,10 +536,7 @@ do_ppmm(es, op, vasn, is_prefix)
} }
static void static void
assign_check(es, op, vasn) assign_check(Expr_state *es, enum token op, struct tbl *vasn)
Expr_state *es;
enum token op;
struct tbl *vasn;
{ {
if (vasn->name[0] == '\0' && !(vasn->flag & EXPRLVALUE)) if (vasn->name[0] == '\0' && !(vasn->flag & EXPRLVALUE))
evalerr(es, ET_LVALUE, opinfo[(int) op].name); evalerr(es, ET_LVALUE, opinfo[(int) op].name);
@ -566,7 +545,7 @@ assign_check(es, op, vasn)
} }
static struct tbl * static struct tbl *
tempvar() tempvar(void)
{ {
struct tbl *vp; struct tbl *vp;
@ -581,9 +560,7 @@ tempvar()
/* cast (string) variable to temporary integer variable */ /* cast (string) variable to temporary integer variable */
static struct tbl * static struct tbl *
intvar(es, vp) intvar(Expr_state *es, struct tbl *vp)
Expr_state *es;
struct tbl *vp;
{ {
struct tbl *vq; struct tbl *vq;

117
history.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: history.c,v 1.13 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: history.c,v 1.14 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: history.c,v 1.24 2004/08/03 12:44:59 danh Exp $ */ /* $OpenBSD: history.c,v 1.24 2004/08/03 12:44:59 danh Exp $ */
/* /*
@ -21,7 +21,7 @@
#include "sh.h" #include "sh.h"
#include "ksh_stat.h" #include "ksh_stat.h"
__RCSID("$MirBSD: history.c,v 1.13 2004/10/28 11:11:18 tg Exp $"); __RCSID("$MirBSD: history.c,v 1.14 2004/10/28 11:53:42 tg Exp $");
#ifdef HISTORY #ifdef HISTORY
# ifdef EASY_HISTORY # ifdef EASY_HISTORY
@ -78,8 +78,7 @@ static Source *hist_source;
int int
c_fc(wp) c_fc(char **wp)
char **wp;
{ {
struct shf *shf; struct shf *shf;
struct temp UNINITIALIZED(*tf); struct temp UNINITIALIZED(*tf);
@ -296,8 +295,7 @@ c_fc(wp)
/* Save cmd in history, execute cmd (cmd gets trashed) */ /* Save cmd in history, execute cmd (cmd gets trashed) */
static int static int
hist_execute(cmd) hist_execute(char *cmd)
char *cmd;
{ {
Source *sold; Source *sold;
int ret; int ret;
@ -337,11 +335,7 @@ hist_execute(cmd)
} }
static int static int
hist_replace(hp, pat, rep, global) hist_replace(char **hp, const char *pat, const char *rep, int global)
char **hp;
const char *pat;
const char *rep;
int global;
{ {
char *line; char *line;
@ -386,10 +380,7 @@ hist_replace(hp, pat, rep, global)
* pattern is a number or string * pattern is a number or string
*/ */
static char ** static char **
hist_get(str, approx, allow_cur) hist_get(const char *str, int approx, int allow_cur)
const char *str;
int approx;
int allow_cur;
{ {
char **hp = (char **) 0; char **hp = (char **) 0;
int n; int n;
@ -430,8 +421,7 @@ hist_get(str, approx, allow_cur)
/* Return a pointer to the newest command in the history */ /* Return a pointer to the newest command in the history */
static char ** static char **
hist_get_newest(allow_cur) hist_get_newest(int allow_cur)
int allow_cur;
{ {
if (histptr < history || (!allow_cur && histptr == history)) { if (histptr < history || (!allow_cur && histptr == history)) {
bi_errorf("no history (yet)"); bi_errorf("no history (yet)");
@ -444,7 +434,7 @@ hist_get_newest(allow_cur)
/* Return a pointer to the newest command in the history */ /* Return a pointer to the newest command in the history */
static char ** static char **
hist_get_oldest() hist_get_oldest(void)
{ {
if (histptr <= history) { if (histptr <= history) {
bi_errorf("no history (yet)"); bi_errorf("no history (yet)");
@ -457,7 +447,7 @@ hist_get_oldest()
/* Back up over last histsave */ /* Back up over last histsave */
/******************************/ /******************************/
static void static void
histbackup() histbackup(void)
{ {
static int last_line = -1; static int last_line = -1;
@ -473,20 +463,19 @@ histbackup()
* Return the current position. * Return the current position.
*/ */
char ** char **
histpos() histpos(void)
{ {
return current; return current;
} }
int int
histN() histN(void)
{ {
return curpos; return curpos;
} }
int int
histnum(n) histnum(int n)
int n;
{ {
int last = histptr - history; int last = histptr - history;
@ -507,11 +496,7 @@ histnum(n)
* direction. * direction.
*/ */
int int
findhist(start, fwd, str, anchored) findhist(int start, int fwd, const char *str, int anchored)
int start;
int fwd;
const char *str;
int anchored;
{ {
char **hp; char **hp;
int maxhist = histptr - history; int maxhist = histptr - history;
@ -535,8 +520,7 @@ findhist(start, fwd, str, anchored)
* this means reallocating the dataspace * this means reallocating the dataspace
*/ */
void void
sethistsize(n) sethistsize(int n)
int n;
{ {
if (n > 0 && n != histsize) { if (n > 0 && n != histsize) {
int cursize = histptr - history; int cursize = histptr - history;
@ -560,8 +544,7 @@ sethistsize(n)
* maintenance * maintenance
*/ */
void void
sethistfile(name) sethistfile(const char *name)
const char *name;
{ {
/* if not started then nothing to do */ /* if not started then nothing to do */
if (hstarted == 0) if (hstarted == 0)
@ -600,7 +583,7 @@ sethistfile(name)
* initialise the history vector * initialise the history vector
*/ */
void void
init_histvec() init_histvec(void)
{ {
if (history == (char **)NULL) { if (history == (char **)NULL) {
histsize = HISTORYSIZE; histsize = HISTORYSIZE;
@ -614,10 +597,10 @@ init_histvec()
* save command in history * save command in history
*/ */
void void
histsave(lno, cmd, dowrite) histsave(int lno, const char *cmd, int dowrite)
int lno; /* ignored (compatibility with COMPLEX_HISTORY) */ /* ignored (compatibility with COMPLEX_HISTORY) */
const char *cmd;
int dowrite; /* ignored (compatibility with COMPLEX_HISTORY) */ /* ignored (compatibility with COMPLEX_HISTORY) */
{ {
char **hp = histptr; char **hp = histptr;
char *cp; char *cp;
@ -641,9 +624,7 @@ histsave(lno, cmd, dowrite)
* commands * commands
*/ */
void void
histappend(cmd, nl_separate) histappend(const char *cmd, int nl_separate)
const char *cmd;
int nl_separate;
{ {
int hlen, clen; int hlen, clen;
char *p; char *p;
@ -669,8 +650,7 @@ histappend(cmd, nl_separate)
* to save its history. * to save its history.
*/ */
void void
hist_init(s) hist_init(Source *s)
Source *s;
{ {
char *f; char *f;
FILE *fh; FILE *fh;
@ -683,19 +663,8 @@ hist_init(s)
hist_source = s; hist_source = s;
if ((f = str_val(global("HISTFILE"))) == NULL || *f == '\0') { if ((f = str_val(global("HISTFILE"))) == NULL || *f == '\0') {
# if 1 /* Don't use history file unless the user asks for it */
hname = NULL; hname = NULL;
return; 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 } else
hname = str_save(f, APERM); hname = str_save(f, APERM);
@ -735,7 +704,7 @@ hist_init(s)
*/ */
void void
hist_finish() hist_finish(void)
{ {
static int once; static int once;
FILE *fh; FILE *fh;
@ -773,10 +742,7 @@ hist_finish()
* save command in history * save command in history
*/ */
void void
histsave(lno, cmd, dowrite) histsave(int lno, const char *cmd, int dowrite)
int lno;
const char *cmd;
int dowrite;
{ {
char **hp; char **hp;
char *c, *cp; char *c, *cp;
@ -824,8 +790,7 @@ histsave(lno, cmd, dowrite)
# define COMMAND 0xff # define COMMAND 0xff
void void
hist_init(s) hist_init(Source *s)
Source *s;
{ {
unsigned char *base; unsigned char *base;
int lines; int lines;
@ -902,9 +867,7 @@ typedef enum state {
} State; } State;
static int static int
hist_count_lines(base, bytes) hist_count_lines(unsigned char *base, int bytes)
unsigned char *base;
int bytes;
{ {
State state = shdr; State state = shdr;
int lines = 0; int lines = 0;
@ -937,9 +900,7 @@ hist_count_lines(base, bytes)
* Shrink the history file to histsize lines * Shrink the history file to histsize lines
*/ */
static int static int
hist_shrink(oldbase, oldbytes) hist_shrink(unsigned char *oldbase, int oldbytes)
unsigned char *oldbase;
int oldbytes;
{ {
int fd; int fd;
char nfile[PATH_MAX]; char nfile[PATH_MAX];
@ -991,10 +952,7 @@ hist_shrink(oldbase, oldbytes)
* return the pointer and the number of bytes left * return the pointer and the number of bytes left
*/ */
static unsigned char * static unsigned char *
hist_skip_back(base, bytes, no) hist_skip_back(unsigned char *base, int *bytes, int no)
unsigned char *base;
int *bytes;
int no;
{ {
int lines = 0; int lines = 0;
unsigned char *ep; unsigned char *ep;
@ -1020,10 +978,7 @@ hist_skip_back(base, bytes, no)
* load the history structure from the stored data * load the history structure from the stored data
*/ */
static void static void
histload(s, base, bytes) histload(Source *s, unsigned char *base, int bytes)
Source *s;
unsigned char *base;
int bytes;
{ {
State state; State state;
int lno = 0; int lno = 0;
@ -1073,10 +1028,7 @@ histload(s, base, bytes)
* Insert a line into the history at a specified number * Insert a line into the history at a specified number
*/ */
static void static void
histinsert(s, lno, line) histinsert(Source *s, int lno, unsigned char *line)
Source *s;
int lno;
unsigned char *line;
{ {
char **hp; char **hp;
@ -1096,9 +1048,7 @@ histinsert(s, lno, line)
* and we should read those commands to update our history * and we should read those commands to update our history
*/ */
static void static void
writehistfile(lno, cmd) writehistfile(int lno, char *cmd)
int lno;
char *cmd;
{ {
int sizenow; int sizenow;
unsigned char *base; unsigned char *base;
@ -1154,7 +1104,7 @@ bad:
} }
void void
hist_finish() hist_finish(void)
{ {
(void) flock(histfd, LOCK_UN); (void) flock(histfd, LOCK_UN);
(void) close(histfd); (void) close(histfd);
@ -1165,8 +1115,7 @@ hist_finish()
* add magic to the history file * add magic to the history file
*/ */
static int static int
sprinkle(fd) sprinkle(int fd)
int fd;
{ {
static unsigned char mag[] = { HMAGIC1, HMAGIC2 }; static unsigned char mag[] = { HMAGIC1, HMAGIC2 };

100
io.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: io.c,v 1.6 2004/10/28 11:03:23 tg Exp $ */ /** $MirBSD: io.c,v 1.7 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: io.c,v 1.13 2003/11/10 21:26:39 millert Exp $ */ /* $OpenBSD: io.c,v 1.13 2003/11/10 21:26:39 millert Exp $ */
/* /*
@ -18,13 +18,7 @@ static int initio_done;
/* A shell error occurred (eg, syntax error, etc.) */ /* A shell error occurred (eg, syntax error, etc.) */
void void
#ifdef HAVE_PROTOTYPES
errorf(const char *fmt, ...) errorf(const char *fmt, ...)
#else
errorf(fmt, va_alist)
const char *fmt;
va_dcl
#endif
{ {
va_list va; va_list va;
@ -43,14 +37,7 @@ errorf(fmt, va_alist)
/* like errorf(), but no unwind is done */ /* like errorf(), but no unwind is done */
void void
#ifdef HAVE_PROTOTYPES
warningf(int fileline, const char *fmt, ...) warningf(int fileline, const char *fmt, ...)
#else
warningf(fileline, fmt, va_alist)
int fileline;
const char *fmt;
va_dcl
#endif
{ {
va_list va; va_list va;
@ -66,13 +53,7 @@ warningf(fileline, fmt, va_alist)
* (also unwinds environments for special builtins). * (also unwinds environments for special builtins).
*/ */
void void
#ifdef HAVE_PROTOTYPES
bi_errorf(const char *fmt, ...) bi_errorf(const char *fmt, ...)
#else
bi_errorf(fmt, va_alist)
const char *fmt;
va_dcl
#endif
{ {
va_list va; va_list va;
@ -103,14 +84,7 @@ bi_errorf(fmt, va_alist)
/* Called when something that shouldn't happen does */ /* Called when something that shouldn't happen does */
void void
#ifdef HAVE_PROTOTYPES
internal_errorf(int jump, const char *fmt, ...) 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; va_list va;
@ -127,8 +101,7 @@ internal_errorf(jump, fmt, va_alist)
/* used by error reporting functions to print "ksh: .kshrc[25]: " */ /* used by error reporting functions to print "ksh: .kshrc[25]: " */
void void
error_prefix(fileline) error_prefix(int fileline)
int fileline;
{ {
/* Avoid foo: foo[2]: ... */ /* Avoid foo: foo[2]: ... */
if (!fileline || !source || !source->file if (!fileline || !source || !source->file
@ -143,13 +116,7 @@ error_prefix(fileline)
/* printf to shl_out (stderr) with flush */ /* printf to shl_out (stderr) with flush */
void void
#ifdef HAVE_PROTOTYPES
shellf(const char *fmt, ...) shellf(const char *fmt, ...)
#else
shellf(fmt, va_alist)
const char *fmt;
va_dcl
#endif
{ {
va_list va; va_list va;
@ -163,13 +130,7 @@ shellf(fmt, va_alist)
/* printf to shl_stdout (stdout) */ /* printf to shl_stdout (stdout) */
void void
#ifdef HAVE_PROTOTYPES
shprintf(const char *fmt, ...) shprintf(const char *fmt, ...)
#else
shprintf(fmt, va_alist)
const char *fmt;
va_dcl
#endif
{ {
va_list va; va_list va;
@ -199,13 +160,7 @@ kshdebug_init_()
/* print to debugging log */ /* print to debugging log */
void void
# ifdef HAVE_PROTOTYPES
kshdebug_printf_(const char *fmt, ...) kshdebug_printf_(const char *fmt, ...)
# else
kshdebug_printf_(fmt, va_alist)
const char *fmt;
va_dcl
# endif
{ {
va_list va; va_list va;
@ -245,8 +200,7 @@ kshdebug_dump_(str, mem, nbytes)
/* test if we can seek backwards fd (returns 0 or SHF_UNBUF) */ /* test if we can seek backwards fd (returns 0 or SHF_UNBUF) */
int int
can_seek(fd) can_seek(int fd)
int fd;
{ {
struct stat statb; struct stat statb;
@ -257,7 +211,7 @@ can_seek(fd)
struct shf shf_iob[3]; struct shf shf_iob[3];
void void
initio() initio(void)
{ {
shf_fdopen(1, SHF_WR, shl_stdout); /* force buffer allocation */ shf_fdopen(1, SHF_WR, shl_stdout); /* force buffer allocation */
shf_fdopen(2, SHF_WR, shl_out); shf_fdopen(2, SHF_WR, shl_out);
@ -268,10 +222,7 @@ initio()
/* A dup2() with error checking */ /* A dup2() with error checking */
int int
ksh_dup2(ofd, nfd, errok) ksh_dup2(int ofd, int nfd, int errok)
int ofd;
int nfd;
int errok;
{ {
int ret = dup2(ofd, nfd); int ret = dup2(ofd, nfd);
@ -292,9 +243,7 @@ ksh_dup2(ofd, nfd, errok)
* set close-on-exec flag. * set close-on-exec flag.
*/ */
int int
savefd(fd, noclose) savefd(int fd, int noclose)
int fd;
int noclose;
{ {
int nfd; int nfd;
@ -315,8 +264,7 @@ savefd(fd, noclose)
} }
void void
restfd(fd, ofd) restfd(int fd, int ofd)
int fd, ofd;
{ {
if (fd == 2) if (fd == 2)
shf_flush(&shf_iob[fd]); shf_flush(&shf_iob[fd]);
@ -329,8 +277,7 @@ restfd(fd, ofd)
} }
void void
openpipe(pv) openpipe(int *pv)
int *pv;
{ {
if (pipe(pv) < 0) if (pipe(pv) < 0)
errorf("can't create pipe - try again"); errorf("can't create pipe - try again");
@ -339,8 +286,7 @@ openpipe(pv)
} }
void void
closepipe(pv) closepipe(int *pv)
int *pv;
{ {
close(pv[0]); close(pv[0]);
close(pv[1]); close(pv[1]);
@ -350,10 +296,7 @@ closepipe(pv)
* a string (the X in 2>&X, read -uX, print -uX) into a file descriptor. * a string (the X in 2>&X, read -uX, print -uX) into a file descriptor.
*/ */
int int
check_fd(name, mode, emsgp) check_fd(char *name, int mode, const char **emsgp)
char *name;
int mode;
const char **emsgp;
{ {
int fd, fl; int fd, fl;
@ -408,7 +351,7 @@ check_fd(name, mode, emsgp)
#ifdef KSH #ifdef KSH
/* Called once from main */ /* Called once from main */
void void
coproc_init() coproc_init(void)
{ {
coproc.read = coproc.readw = coproc.write = -1; coproc.read = coproc.readw = coproc.write = -1;
coproc.njobs = 0; coproc.njobs = 0;
@ -417,8 +360,7 @@ coproc_init()
/* Called by c_read() when eof is read - close fd if it is the co-process fd */ /* Called by c_read() when eof is read - close fd if it is the co-process fd */
void void
coproc_read_close(fd) coproc_read_close(int fd)
int fd;
{ {
if (coproc.read >= 0 && fd == coproc.read) { if (coproc.read >= 0 && fd == coproc.read) {
coproc_readw_close(fd); coproc_readw_close(fd);
@ -431,8 +373,7 @@ coproc_read_close(fd)
* read pipe, so reads will actually terminate. * read pipe, so reads will actually terminate.
*/ */
void void
coproc_readw_close(fd) coproc_readw_close(int fd)
int fd;
{ {
if (coproc.readw >= 0 && coproc.read >= 0 && fd == coproc.read) { if (coproc.readw >= 0 && coproc.read >= 0 && fd == coproc.read) {
close(coproc.readw); close(coproc.readw);
@ -444,8 +385,7 @@ coproc_readw_close(fd)
* when co-process input is dup'd * when co-process input is dup'd
*/ */
void void
coproc_write_close(fd) coproc_write_close(int fd)
int fd;
{ {
if (coproc.write >= 0 && fd == coproc.write) { if (coproc.write >= 0 && fd == coproc.write) {
close(coproc.write); close(coproc.write);
@ -457,9 +397,7 @@ coproc_write_close(fd)
* (Used by check_fd() and by c_read/c_print to deal with -p option). * (Used by check_fd() and by c_read/c_print to deal with -p option).
*/ */
int int
coproc_getfd(mode, emsgp) coproc_getfd(int mode, const char **emsgp)
int mode;
const char **emsgp;
{ {
int fd = (mode & R_OK) ? coproc.read : coproc.write; int fd = (mode & R_OK) ? coproc.read : coproc.write;
@ -474,8 +412,7 @@ coproc_getfd(mode, emsgp)
* Should be called with SIGCHLD blocked. * Should be called with SIGCHLD blocked.
*/ */
void void
coproc_cleanup(reuse) coproc_cleanup(int reuse)
int reuse;
{ {
/* This to allow co-processes to share output pipe */ /* This to allow co-processes to share output pipe */
if (!reuse || coproc.readw < 0 || coproc.read < 0) { if (!reuse || coproc.readw < 0 || coproc.read < 0) {
@ -501,10 +438,7 @@ coproc_cleanup(reuse)
*/ */
struct temp * struct temp *
maketemp(ap, type, tlist) maketemp(Area *ap, Temp_type type, struct temp **tlist)
Area *ap;
Temp_type type;
struct temp **tlist;
{ {
#ifndef HAVE_MKSTEMP #ifndef HAVE_MKSTEMP
static unsigned int inc; static unsigned int inc;

98
jobs.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: jobs.c,v 1.7 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: jobs.c,v 1.8 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: jobs.c,v 1.21 2003/11/10 21:26:39 millert Exp $ */ /* $OpenBSD: jobs.c,v 1.21 2003/11/10 21:26:39 millert Exp $ */
/* /*
@ -31,7 +31,7 @@
#include "ksh_times.h" #include "ksh_times.h"
#include "tty.h" #include "tty.h"
__RCSID("$MirBSD: jobs.c,v 1.7 2004/10/28 11:11:18 tg Exp $"); __RCSID("$MirBSD: jobs.c,v 1.8 2004/10/28 11:53:42 tg Exp $");
/* Start of system configuration stuff */ /* Start of system configuration stuff */
@ -63,16 +63,13 @@ int tcsetpgrp(int fd, pid_t grp);
int tcgetpgrp(int fd); int tcgetpgrp(int fd);
int int
tcsetpgrp(fd, grp) tcsetpgrp(int fd, pid_t grp)
int fd;
pid_t grp;
{ {
return ioctl(fd, TIOCSPGRP, &grp); return ioctl(fd, TIOCSPGRP, &grp);
} }
int int
tcgetpgrp(fd) tcgetpgrp(int fd)
int fd;
{ {
int r, grp; int r, grp;
@ -228,8 +225,7 @@ static int kill_job(Job *j, int sig);
/* initialize job control */ /* initialize job control */
void void
j_init(mflagset) j_init(int mflagset)
int mflagset;
{ {
child_max = CHILD_MAX; /* so syscon() isn't always being called */ child_max = CHILD_MAX; /* so syscon() isn't always being called */
@ -283,7 +279,7 @@ j_init(mflagset)
/* job cleanup before shell exit */ /* job cleanup before shell exit */
void void
j_exit() j_exit(void)
{ {
/* kill stopped, and possibly running, jobs */ /* kill stopped, and possibly running, jobs */
Job *j; Job *j;
@ -340,7 +336,7 @@ j_exit()
#ifdef JOBS #ifdef JOBS
/* turn job control on or off according to Flag(FMONITOR) */ /* turn job control on or off according to Flag(FMONITOR) */
void void
j_change() j_change(void)
{ {
int i; int i;
@ -435,10 +431,10 @@ j_change()
/* execute tree in child subprocess */ /* execute tree in child subprocess */
int int
exchild(t, flags, close_fd) exchild(struct op *t, int flags, int close_fd)
struct op *t;
int flags;
int close_fd; /* used if XPCLOSE or XCCLOSE */ /* used if XPCLOSE or XCCLOSE */
{ {
static Proc *last_proc; /* for pipelines */ static Proc *last_proc; /* for pipelines */
@ -697,7 +693,7 @@ exchild(t, flags, close_fd)
/* start the last job: only used for `command` jobs */ /* start the last job: only used for `command` jobs */
void void
startlast() startlast(void)
{ {
#ifdef JOB_SIGS #ifdef JOB_SIGS
sigset_t omask; sigset_t omask;
@ -717,7 +713,7 @@ startlast()
/* wait for last job: only used for `command` jobs */ /* wait for last job: only used for `command` jobs */
int int
waitlast() waitlast(void)
{ {
int rv; int rv;
Job *j; Job *j;
@ -750,9 +746,7 @@ waitlast()
/* wait for child, interruptable. */ /* wait for child, interruptable. */
int int
waitfor(cp, sigp) waitfor(const char *cp, int *sigp)
const char *cp;
int *sigp;
{ {
int rv; int rv;
Job *j; Job *j;
@ -813,9 +807,7 @@ waitfor(cp, sigp)
/* kill (built-in) a job */ /* kill (built-in) a job */
int int
j_kill(cp, sig) j_kill(const char *cp, int sig)
const char *cp;
int sig;
{ {
Job *j; Job *j;
int rv = 0; int rv = 0;
@ -860,9 +852,7 @@ j_kill(cp, sig)
#ifdef JOBS #ifdef JOBS
/* fg and bg built-ins: called only if Flag(FMONITOR) set */ /* fg and bg built-ins: called only if Flag(FMONITOR) set */
int int
j_resume(cp, bg) j_resume(const char *cp, int bg)
const char *cp;
int bg;
{ {
Job *j; Job *j;
Proc *p; Proc *p;
@ -968,7 +958,7 @@ j_resume(cp, bg)
/* are there any running or stopped jobs ? */ /* are there any running or stopped jobs ? */
int int
j_stopped_running() j_stopped_running(void)
{ {
Job *j; Job *j;
int which = 0; int which = 0;
@ -995,10 +985,10 @@ j_stopped_running()
/* list jobs for jobs built-in */ /* list jobs for jobs built-in */
int int
j_jobs(cp, slp, nflag) j_jobs(const char *cp, int slp, int nflag)
const char *cp;
int slp; /* 0: short, 1: long, 2: pgrp */ /* 0: short, 1: long, 2: pgrp */
int nflag;
{ {
Job *j, *tmp; Job *j, *tmp;
int how; int how;
@ -1051,7 +1041,7 @@ j_jobs(cp, slp, nflag)
/* list jobs for top-level notification */ /* list jobs for top-level notification */
void void
j_notify() j_notify(void)
{ {
Job *j, *tmp; Job *j, *tmp;
#ifdef JOB_SIGS #ifdef JOB_SIGS
@ -1083,7 +1073,7 @@ j_notify()
/* Return pid of last process in last asynchronous job */ /* Return pid of last process in last asynchronous job */
pid_t pid_t
j_async() j_async(void)
{ {
#ifdef JOB_SIGS #ifdef JOB_SIGS
sigset_t omask; sigset_t omask;
@ -1106,8 +1096,7 @@ j_async()
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static void static void
j_set_async(j) j_set_async(Job *j)
Job *j;
{ {
Job *jl, *oldest; Job *jl, *oldest;
@ -1142,8 +1131,7 @@ j_set_async(j)
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static void static void
j_startjob(j) j_startjob(Job *j)
Job *j;
{ {
Proc *p; Proc *p;
@ -1173,10 +1161,10 @@ j_startjob(j)
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static int static int
j_waitj(j, flags, where) j_waitj(Job *j, int flags, const char *where)
Job *j;
int flags; /* see JW_* */ /* see JW_* */
const char *where;
{ {
int rv; int rv;
@ -1397,8 +1385,7 @@ found:
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static void static void
check_job(j) check_job(Job *j)
Job *j;
{ {
int jstate; int jstate;
Proc *p; Proc *p;
@ -1506,10 +1493,7 @@ check_job(j)
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static void static void
j_print(j, how, shf) j_print(Job *j, int how, struct shf *shf)
Job *j;
int how;
struct shf *shf;
{ {
Proc *p; Proc *p;
int state; int state;
@ -1618,9 +1602,7 @@ j_print(j, how, shf)
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static Job * static Job *
j_lookup(cp, ecodep) j_lookup(const char *cp, int *ecodep)
const char *cp;
int *ecodep;
{ {
Job *j, *last_match; Job *j, *last_match;
Proc *p; Proc *p;
@ -1713,7 +1695,7 @@ static Proc *free_procs;
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static Job * static Job *
new_job() new_job(void)
{ {
int i; int i;
Job *newj, *j; Job *newj, *j;
@ -1741,7 +1723,7 @@ new_job()
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static Proc * static Proc *
new_proc() new_proc(void)
{ {
Proc *p; Proc *p;
@ -1760,9 +1742,7 @@ new_proc()
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static void static void
remove_job(j, where) remove_job(Job *j, const char *where)
Job *j;
const char *where;
{ {
Proc *p, *tmp; Proc *p, *tmp;
Job **prev, *curr; Job **prev, *curr;
@ -1802,9 +1782,7 @@ remove_job(j, where)
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static void static void
put_job(j, where) put_job(Job *j, int where)
Job *j;
int where;
{ {
Job **prev, *curr; Job **prev, *curr;
@ -1839,9 +1817,7 @@ put_job(j, where)
* If jobs are compiled in then this routine expects sigchld to be blocked. * If jobs are compiled in then this routine expects sigchld to be blocked.
*/ */
static int static int
kill_job(j, sig) kill_job(Job *j, int sig)
Job *j;
int sig;
{ {
Proc *p; Proc *p;
int rval = 0; int rval = 0;

View File

@ -1,6 +1,9 @@
/** $MirBSD: ksh_dir.h,v 1.4 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: ksh_dir.h,v 1.5 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: ksh_dir.h,v 1.1.1.1 1996/08/14 06:19:11 downsj Exp $ */ /* $OpenBSD: ksh_dir.h,v 1.1.1.1 1996/08/14 06:19:11 downsj Exp $ */
#ifndef KSH_DIR_H
#define KSH_DIR_H
/* Wrapper around the ugly dir includes/ifdefs */ /* Wrapper around the ugly dir includes/ifdefs */
#if defined(HAVE_DIRENT_H) #if defined(HAVE_DIRENT_H)
@ -25,3 +28,5 @@ extern DIR *ksh_opendir(const char *d);
#else /* OPENDIR_DOES_NONDIR */ #else /* OPENDIR_DOES_NONDIR */
# define ksh_opendir(d) opendir(d) # define ksh_opendir(d) opendir(d)
#endif /* OPENDIR_DOES_NONDIR */ #endif /* OPENDIR_DOES_NONDIR */
#endif /* ndef KSH_DIR_H */

View File

@ -1,6 +1,9 @@
/** $MirBSD: ksh_limval.h,v 1.3 2004/09/21 11:57:10 tg Exp $ */ /** $MirBSD: ksh_limval.h,v 1.4 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: ksh_limval.h,v 1.1.1.1 1996/08/14 06:19:11 downsj Exp $ */ /* $OpenBSD: ksh_limval.h,v 1.1.1.1 1996/08/14 06:19:11 downsj Exp $ */
#ifndef KSH_LIMVAL_H
#define KSH_LIMVAL_H
/* Wrapper around the values.h/limits.h includes/ifdefs */ /* Wrapper around the values.h/limits.h includes/ifdefs */
#ifdef HAVE_VALUES_H #ifdef HAVE_VALUES_H
@ -23,3 +26,5 @@
#ifndef BITS #ifndef BITS
# define BITS(t) (BITSPERBYTE * sizeof(t)) # define BITS(t) (BITSPERBYTE * sizeof(t))
#endif #endif
#endif /* ndef KSH_LIMVAL_H */

View File

@ -1,6 +1,9 @@
/** $MirBSD: ksh_stat.h,v 1.4 2004/09/21 11:57:11 tg Exp $ */ /** $MirBSD: ksh_stat.h,v 1.5 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: ksh_stat.h,v 1.3 1996/10/01 02:05:39 downsj Exp $ */ /* $OpenBSD: ksh_stat.h,v 1.3 1996/10/01 02:05:39 downsj Exp $ */
#ifndef KSH_STAT_H
#define KSH_STAT_H
/* Wrapper around the ugly sys/stat includes/ifdefs */ /* Wrapper around the ugly sys/stat includes/ifdefs */
/* assumes <sys/types.h> already included */ /* assumes <sys/types.h> already included */
@ -64,3 +67,5 @@
#ifndef S_IXOTH #ifndef S_IXOTH
# define S_IXOTH 00001 /* user execute bit */ # define S_IXOTH 00001 /* user execute bit */
#endif /* S_IXOTH */ #endif /* S_IXOTH */
#endif /* ndef KSH_STAT_H */

View File

@ -1,8 +1,8 @@
/** $MirBSD: ksh_time.h,v 1.4 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: ksh_time.h,v 1.5 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: ksh_time.h,v 1.2 1996/10/01 02:05:40 downsj Exp $ */ /* $OpenBSD: ksh_time.h,v 1.2 1996/10/01 02:05:40 downsj Exp $ */
#ifndef KSH_TIME_H #ifndef KSH_TIME_H
# define KSH_TIME_H #define KSH_TIME_H
/* Wrapper around the ugly time.h,sys/time.h includes/ifdefs */ /* Wrapper around the ugly time.h,sys/time.h includes/ifdefs */
@ -24,4 +24,5 @@ extern time_t time(time_t *);
#ifndef CLK_TCK #ifndef CLK_TCK
# define CLK_TCK 60 /* 60HZ */ # define CLK_TCK 60 /* 60HZ */
#endif #endif
#endif /* KSH_TIME_H */ #endif /* KSH_TIME_H */

View File

@ -1,8 +1,8 @@
/** $MirBSD: ksh_times.h,v 1.4 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: ksh_times.h,v 1.5 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: ksh_times.h,v 1.2 1996/10/01 02:05:41 downsj Exp $ */ /* $OpenBSD: ksh_times.h,v 1.2 1996/10/01 02:05:41 downsj Exp $ */
#ifndef KSH_TIMES_H #ifndef KSH_TIMES_H
# define KSH_TIMES_H #define KSH_TIMES_H
/* Needed for clock_t on some systems (ie, NeXT in non-posix mode) */ /* Needed for clock_t on some systems (ie, NeXT in non-posix mode) */
#include "ksh_time.h" #include "ksh_time.h"
@ -18,4 +18,5 @@ extern clock_t ksh_times(struct tms *);
#ifdef HAVE_TIMES #ifdef HAVE_TIMES
extern clock_t times(struct tms *); extern clock_t times(struct tms *);
#endif /* HAVE_TIMES */ #endif /* HAVE_TIMES */
#endif /* KSH_TIMES_H */ #endif /* KSH_TIMES_H */

View File

@ -1,6 +1,9 @@
/** $MirBSD: ksh_wait.h,v 1.3 2004/09/21 11:57:12 tg Exp $ */ /** $MirBSD: ksh_wait.h,v 1.4 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: ksh_wait.h,v 1.3 1997/06/19 13:58:43 kstailey Exp $ */ /* $OpenBSD: ksh_wait.h,v 1.3 1997/06/19 13:58:43 kstailey Exp $ */
#ifndef KSH_WAIT_H
#define KSH_WAIT_H
/* Wrapper around the ugly sys/wait includes/ifdefs */ /* Wrapper around the ugly sys/wait includes/ifdefs */
#ifdef HAVE_SYS_WAIT_H #ifdef HAVE_SYS_WAIT_H
@ -50,3 +53,5 @@ typedef int WAIT_T;
#else /* !HAVE_WAITPID && HAVE_WAIT3 */ #else /* !HAVE_WAITPID && HAVE_WAIT3 */
# define ksh_waitpid(p, s, o) waitpid((p), (s), (o)) # define ksh_waitpid(p, s, o) waitpid((p), (s), (o))
#endif /* !HAVE_WAITPID && HAVE_WAIT3 */ #endif /* !HAVE_WAITPID && HAVE_WAIT3 */
#endif /* ndef KSH_WAIT_H */

87
lex.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: lex.c,v 1.6 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: lex.c,v 1.7 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: lex.c,v 1.18 2003/08/06 21:08:05 millert Exp $ */ /* $OpenBSD: lex.c,v 1.18 2003/08/06 21:08:05 millert Exp $ */
/* /*
@ -8,7 +8,7 @@
#include "sh.h" #include "sh.h"
#include <ctype.h> #include <ctype.h>
__RCSID("$MirBSD: lex.c,v 1.6 2004/10/28 11:11:18 tg Exp $"); __RCSID("$MirBSD: lex.c,v 1.7 2004/10/28 11:53:42 tg Exp $");
/* Structure to keep track of the lexing state and the various pieces of info /* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state. * needed for each particular state.
@ -99,8 +99,7 @@ static int ignore_backslash_newline;
*/ */
int int
yylex(cf) yylex(int cf)
int cf;
{ {
Lex_state states[STATE_BSIZE], *statep; Lex_state states[STATE_BSIZE], *statep;
State_info state_info; State_info state_info;
@ -771,7 +770,7 @@ Done:
} }
static void static void
gethere() gethere(void)
{ {
struct ioword **p; struct ioword **p;
@ -785,8 +784,7 @@ gethere()
*/ */
static void static void
readhere(iop) readhere(struct ioword *iop)
struct ioword *iop;
{ {
int c; int c;
char *volatile eof; char *volatile eof;
@ -844,13 +842,7 @@ readhere(iop)
} }
void void
#ifdef HAVE_PROTOTYPES
yyerror(const char *fmt, ...) yyerror(const char *fmt, ...)
#else
yyerror(fmt, va_alist)
const char *fmt;
va_dcl
#endif
{ {
va_list va; va_list va;
@ -871,9 +863,7 @@ yyerror(fmt, va_alist)
*/ */
Source * Source *
pushs(type, areap) pushs(int type, Area *areap)
int type;
Area *areap;
{ {
Source *s; Source *s;
@ -896,7 +886,7 @@ pushs(type, areap)
} }
static int static int
getsc__() getsc__(void)
{ {
Source *s = source; Source *s = source;
int c; int c;
@ -997,8 +987,7 @@ getsc__()
} }
static void static void
getsc_line(s) getsc_line(Source *s)
Source *s;
{ {
char *xp = Xstring(s->xs, xp); char *xp = Xstring(s->xs, xp);
int interactive = Flag(FTALKING) && s->type == SSTDIN; int interactive = Flag(FTALKING) && s->type == SSTDIN;
@ -1110,9 +1099,7 @@ getsc_line(s)
} }
void void
set_prompt(to, s) set_prompt(int to, Source *s)
int to;
Source *s;
{ {
cur_prompt = to; cur_prompt = to;
@ -1168,44 +1155,8 @@ set_prompt(to, s)
/* See also related routine, promptlen() in edit.c */ /* See also related routine, promptlen() in edit.c */
void void
pprompt(cp, ntruncate) pprompt(const char *cp, int ntruncate)
const char *cp;
int ntruncate;
{ {
#if 0
char nbuf[32];
int c;
while (*cp != 0) {
if (*cp != '!')
c = *cp++;
else if (*++cp == '!')
c = *cp++;
else {
int len;
char *p;
shf_snprintf(p = nbuf, sizeof(nbuf), "%d",
source->line + 1);
len = strlen(nbuf);
if (ntruncate) {
if (ntruncate >= len) {
ntruncate -= len;
continue;
}
p += ntruncate;
len -= ntruncate;
ntruncate = 0;
}
shf_write(p, len, shl_out);
continue;
}
if (ntruncate)
--ntruncate;
else
shf_putc(c, shl_out);
}
#endif /* 0 */
shf_puts(cp + ntruncate, shl_out); shf_puts(cp + ntruncate, shl_out);
shf_flush(shl_out); shf_flush(shl_out);
} }
@ -1214,9 +1165,7 @@ pprompt(cp, ntruncate)
* the :[-+?=#%] or close-brace. * the :[-+?=#%] or close-brace.
*/ */
static char * static char *
get_brace_var(wsp, wp) get_brace_var(XString *wsp, char *wp)
XString *wsp;
char *wp;
{ {
enum parse_state { enum parse_state {
PS_INITIAL, PS_SAW_HASH, PS_IDENT, PS_INITIAL, PS_SAW_HASH, PS_IDENT,
@ -1291,8 +1240,7 @@ get_brace_var(wsp, wp)
* (Returned string double null terminated) * (Returned string double null terminated)
*/ */
static int static int
arraysub(strp) arraysub(char **strp)
char **strp;
{ {
XString ws; XString ws;
char *wp; char *wp;
@ -1319,8 +1267,7 @@ arraysub(strp)
/* Unget a char: handles case when we are already at the start of the buffer */ /* Unget a char: handles case when we are already at the start of the buffer */
static const char * static const char *
ungetsc(c) ungetsc(int c)
int c;
{ {
if (backslash_skip) if (backslash_skip)
backslash_skip--; backslash_skip--;
@ -1372,9 +1319,7 @@ getsc_bn(void)
} }
static Lex_state * static Lex_state *
push_state_(si, old_end) push_state_(State_info *si, Lex_state *old_end)
State_info *si;
Lex_state *old_end;
{ {
Lex_state *new = alloc(sizeof(Lex_state) * STATE_BSIZE, ATEMP); Lex_state *new = alloc(sizeof(Lex_state) * STATE_BSIZE, ATEMP);
@ -1385,9 +1330,7 @@ push_state_(si, old_end)
} }
static Lex_state * static Lex_state *
pop_state_(si, old_end) pop_state_(State_info *si, Lex_state *old_end)
State_info *si;
Lex_state *old_end;
{ {
Lex_state *old_base = si->base; Lex_state *old_base = si->base;

7
lex.h
View File

@ -1,7 +1,10 @@
/** $MirBSD: lex.h,v 1.3 2004/09/21 11:57:13 tg Exp $ */ /** $MirBSD: lex.h,v 1.4 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: lex.h,v 1.7 2003/02/28 09:45:09 jmc Exp $ */ /* $OpenBSD: lex.h,v 1.7 2003/02/28 09:45:09 jmc Exp $ */
/* $From: lex.h,v 1.4 1994/05/31 13:34:34 michael Exp $ */ /* $From: lex.h,v 1.4 1994/05/31 13:34:34 michael Exp $ */
#ifndef LEX_H
#define LEX_H
/* /*
* Source input, lexer and parser * Source input, lexer and parser
*/ */
@ -130,3 +133,5 @@ EXTERN char **history; /* saved commands */
EXTERN char **histptr; /* last history item */ EXTERN char **histptr; /* last history item */
EXTERN int histsize; /* history size */ EXTERN int histsize; /* history size */
#endif /* HISTORY */ #endif /* HISTORY */
#endif /* ndef LEX_H */

27
mail.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: mail.c,v 1.5 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: mail.c,v 1.6 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: mail.c,v 1.9 1999/06/15 01:18:35 millert Exp $ */ /* $OpenBSD: mail.c,v 1.9 1999/06/15 01:18:35 millert Exp $ */
/* /*
@ -13,7 +13,7 @@
#include "ksh_stat.h" #include "ksh_stat.h"
#include "ksh_time.h" #include "ksh_time.h"
__RCSID("$MirBSD: mail.c,v 1.5 2004/10/28 11:11:18 tg Exp $"); __RCSID("$MirBSD: mail.c,v 1.6 2004/10/28 11:53:42 tg Exp $");
#define MBMESSAGE "you have mail in $_" #define MBMESSAGE "you have mail in $_"
@ -40,14 +40,14 @@ static mbox_t * mballoc(char *p, char *m); /* allocate a new mbox */
static void mprintit(mbox_t *mbp); static void mprintit(mbox_t *mbp);
void void
mcheck() mcheck(void)
{ {
mbox_t *mbp; mbox_t *mbp;
time_t now; time_t now;
struct tbl *vp; struct tbl *vp;
struct stat stbuf; struct stat stbuf;
now = time((time_t *) 0); now = time(NULL);
if (mlastchkd == 0) if (mlastchkd == 0)
mlastchkd = now; mlastchkd = now;
if (now - mlastchkd >= mailcheck_interval) { if (now - mlastchkd >= mailcheck_interval) {
@ -84,15 +84,13 @@ mcheck()
} }
void void
mcset(interval) mcset(long int interval)
long interval;
{ {
mailcheck_interval = interval; mailcheck_interval = interval;
} }
void void
mbset(p) mbset(char *p)
char *p;
{ {
struct stat stbuf; struct stat stbuf;
@ -110,8 +108,7 @@ mbset(p)
} }
void void
mpset(mptoparse) mpset(char *mptoparse)
char *mptoparse;
{ {
mbox_t *mbp; mbox_t *mbp;
char *mpath, *mmsg, *mval; char *mpath, *mmsg, *mval;
@ -150,8 +147,7 @@ mpset(mptoparse)
} }
static void static void
munset(mlist) munset(mbox_t *mlist)
mbox_t *mlist;
{ {
mbox_t *mbp; mbox_t *mbp;
@ -165,9 +161,7 @@ mbox_t *mlist;
} }
static mbox_t * static mbox_t *
mballoc(p, m) mballoc(char *p, char *m)
char *p;
char *m;
{ {
struct stat stbuf; struct stat stbuf;
mbox_t *mbp; mbox_t *mbp;
@ -184,8 +178,7 @@ mballoc(p, m)
} }
static void static void
mprintit( mbp ) mprintit(mbox_t *mbp)
mbox_t *mbp;
{ {
struct tbl *vp; struct tbl *vp;

42
main.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: main.c,v 1.11 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: main.c,v 1.12 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: main.c,v 1.28 2004/08/23 14:56:32 millert Exp $ */ /* $OpenBSD: main.c,v 1.28 2004/08/23 14:56:32 millert Exp $ */
/* /*
@ -11,7 +11,7 @@
#include "ksh_stat.h" #include "ksh_stat.h"
#include "ksh_time.h" #include "ksh_time.h"
__RCSID("$MirBSD: main.c,v 1.11 2004/10/28 11:11:18 tg Exp $"); __RCSID("$MirBSD: main.c,v 1.12 2004/10/28 11:53:42 tg Exp $");
extern char **environ; extern char **environ;
@ -69,9 +69,6 @@ static const char *const initcoms [] = {
#ifdef KSH #ifdef KSH
/* Aliases that are builtin commands in at&t */ /* Aliases that are builtin commands in at&t */
"login=exec login", "login=exec login",
#ifndef __OpenBSD__
"newgrp=exec newgrp",
#endif /* __OpenBSD__ */
#endif /* KSH */ #endif /* KSH */
NULL, NULL,
/* this is what at&t ksh seems to track, with the addition of emacs */ /* this is what at&t ksh seems to track, with the addition of emacs */
@ -454,11 +451,7 @@ main(int argc, char *argv[])
} }
int int
include(name, argc, argv, intr_ok) include(const char *name, int argc, char **argv, int intr_ok)
const char *name;
int argc;
char **argv;
int intr_ok;
{ {
Source *volatile s = NULL; Source *volatile s = NULL;
struct shf *shf; struct shf *shf;
@ -526,8 +519,7 @@ include(name, argc, argv, intr_ok)
} }
int int
command(comm) command(const char *comm)
const char *comm;
{ {
Source *s; Source *s;
@ -540,9 +532,9 @@ command(comm)
* run the commands from the input source, returning status. * run the commands from the input source, returning status.
*/ */
int int
shell(s, toplevel) shell(Source *volatile s, volatile int toplevel)
Source *volatile s; /* input source */ /* input source */
int volatile toplevel;
{ {
struct op *t; struct op *t;
volatile int wastty = s->flags & SF_TTY; volatile int wastty = s->flags & SF_TTY;
@ -651,8 +643,7 @@ shell(s, toplevel)
/* return to closest error handler or shell(), exit if none found */ /* return to closest error handler or shell(), exit if none found */
void void
unwind(i) unwind(int i)
int i;
{ {
/* ordering for EXIT vs ERR is a bit odd (this is what at&t ksh does) */ /* ordering for EXIT vs ERR is a bit odd (this is what at&t ksh does) */
if (i == LEXIT || (Flag(FERREXIT) && (i == LERROR || i == LINTR) if (i == LEXIT || (Flag(FERREXIT) && (i == LERROR || i == LINTR)
@ -686,8 +677,7 @@ unwind(i)
} }
void void
newenv(type) newenv(int type)
int type;
{ {
struct env *ep; struct env *ep;
@ -703,7 +693,7 @@ newenv(type)
} }
void void
quitenv() quitenv(void)
{ {
struct env *ep = e; struct env *ep = e;
int fd; int fd;
@ -756,7 +746,7 @@ quitenv()
/* Called after a fork to cleanup stuff left over from parents environment */ /* Called after a fork to cleanup stuff left over from parents environment */
void void
cleanup_parents_env() cleanup_parents_env(void)
{ {
struct env *ep; struct env *ep;
int fd; int fd;
@ -781,7 +771,7 @@ cleanup_parents_env()
/* Called just before an execve cleanup stuff temporary files */ /* Called just before an execve cleanup stuff temporary files */
void void
cleanup_proc_env() cleanup_proc_env(void)
{ {
struct env *ep; struct env *ep;
@ -791,7 +781,7 @@ cleanup_proc_env()
/* remove temp files and free ATEMP Area */ /* remove temp files and free ATEMP Area */
static void static void
reclaim() reclaim(void)
{ {
remove_temps(e->temps); remove_temps(e->temps);
e->temps = NULL; e->temps = NULL;
@ -799,8 +789,7 @@ reclaim()
} }
static void static void
remove_temps(tp) remove_temps(struct temp *tp)
struct temp *tp;
{ {
#ifdef OS2 #ifdef OS2
static struct temp *delayed_remove; static struct temp *delayed_remove;
@ -845,8 +834,7 @@ remove_temps(tp)
/* Returns true if name refers to a restricted shell */ /* Returns true if name refers to a restricted shell */
static int static int
is_restricted(name) is_restricted(char *name)
char *name;
{ {
char *p; char *p;

143
misc.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: misc.c,v 1.11 2004/10/28 11:11:18 tg Exp $ */ /** $MirBSD: misc.c,v 1.12 2004/10/28 11:53:42 tg Exp $ */
/* $OpenBSD: misc.c,v 1.20 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: misc.c,v 1.20 2003/10/22 07:40:38 jmc Exp $ */
/* /*
@ -11,7 +11,7 @@
# include <limits.h> # include <limits.h>
#endif #endif
__RCSID("$MirBSD: misc.c,v 1.11 2004/10/28 11:11:18 tg Exp $"); __RCSID("$MirBSD: misc.c,v 1.12 2004/10/28 11:53:42 tg Exp $");
#ifndef UCHAR_MAX #ifndef UCHAR_MAX
# define UCHAR_MAX 0xFF # define UCHAR_MAX 0xFF
@ -28,9 +28,7 @@ static const unsigned char *cclass(const unsigned char *p, int sub);
* Fast character classes * Fast character classes
*/ */
void void
setctypes(s, t) setctypes(const char *s, int t)
const char *s;
int t;
{ {
unsigned i; unsigned i;
@ -44,7 +42,7 @@ setctypes(s, t)
} }
void void
initctypes() initctypes(void)
{ {
int c; int c;
@ -65,9 +63,7 @@ initctypes()
/* convert unsigned long to base N string */ /* convert unsigned long to base N string */
char * char *
ulton(n, base) ulton(long unsigned int n, int base)
unsigned long n;
int base;
{ {
char *p; char *p;
static char buf [20]; static char buf [20];
@ -82,9 +78,7 @@ ulton(n, base)
} }
char * char *
str_save(s, ap) str_save(const char *s, Area *ap)
const char *s;
Area *ap;
{ {
size_t len; size_t len;
char *p; char *p;
@ -102,10 +96,7 @@ str_save(s, ap)
* (unless n < 0). * (unless n < 0).
*/ */
char * char *
str_nsave(s, n, ap) str_nsave(const char *s, int n, Area *ap)
const char *s;
int n;
Area *ap;
{ {
char *ns; char *ns;
@ -118,10 +109,7 @@ str_nsave(s, n, ap)
/* called from expand.h:XcheckN() to grow buffer */ /* called from expand.h:XcheckN() to grow buffer */
char * char *
Xcheck_grow_(xsp, xp, more) Xcheck_grow_(XString *xsp, char *xp, size_t more)
XString *xsp;
char *xp;
size_t more;
{ {
char *old_beg = xsp->beg; char *old_beg = xsp->beg;
@ -195,8 +183,7 @@ const struct option options[] = {
* translate -o option into F* constant (also used for test -o option) * translate -o option into F* constant (also used for test -o option)
*/ */
int int
option(n) option(const char *n)
const char *n;
{ {
unsigned i; unsigned i;
@ -220,11 +207,7 @@ static void printoptions(int verbose);
/* format a single select menu item */ /* format a single select menu item */
static char * static char *
options_fmt_entry(arg, i, buf, buflen) options_fmt_entry(void *arg, int i, char *buf, int buflen)
void *arg;
int i;
char *buf;
int buflen;
{ {
struct options_info *oi = (struct options_info *) arg; struct options_info *oi = (struct options_info *) arg;
@ -235,8 +218,7 @@ options_fmt_entry(arg, i, buf, buflen)
} }
static void static void
printoptions(verbose) printoptions(int verbose)
int verbose;
{ {
unsigned i; unsigned i;
@ -268,7 +250,7 @@ printoptions(verbose)
} }
char * char *
getoptions() getoptions(void)
{ {
unsigned i; unsigned i;
char m[(int) FNFLAGS + 1]; char m[(int) FNFLAGS + 1];
@ -283,10 +265,10 @@ getoptions()
/* change a Flag(*) value; takes care of special actions */ /* change a Flag(*) value; takes care of special actions */
void void
change_flag(f, what, newval) change_flag(enum sh_flag f, int what, int newval)
enum sh_flag f; /* flag to change */ /* flag to change */
int what; /* what is changing the flag (command line vs set) */ /* what is changing the flag (command line vs set) */
int newval;
{ {
int oldval; int oldval;
@ -346,10 +328,10 @@ change_flag(f, what, newval)
* non-option arguments, -1 if there is an error. * non-option arguments, -1 if there is an error.
*/ */
int int
parse_args(argv, what, setargsp) parse_args(char **argv, int what, int *setargsp)
char **argv;
int what; /* OF_CMDLINE or OF_SET */ /* OF_CMDLINE or OF_SET */
int *setargsp;
{ {
static char cmd_opts[NELEM(options) + 3]; /* o:\0 */ static char cmd_opts[NELEM(options) + 3]; /* o:\0 */
static char set_opts[NELEM(options) + 5]; /* Ao;s\0 */ static char set_opts[NELEM(options) + 5]; /* Ao;s\0 */
@ -487,9 +469,7 @@ parse_args(argv, what, setargsp)
/* parse a decimal number: returns 0 if string isn't a number, 1 otherwise */ /* parse a decimal number: returns 0 if string isn't a number, 1 otherwise */
int int
getn(as, ai) getn(const char *as, int *ai)
const char *as;
int *ai;
{ {
char *p; char *p;
long n; long n;
@ -505,9 +485,7 @@ getn(as, ai)
/* getn() that prints error */ /* getn() that prints error */
int int
bi_getn(as, ai) bi_getn(const char *as, int *ai)
const char *as;
int *ai;
{ {
int rv = getn(as, ai); int rv = getn(as, ai);
@ -527,9 +505,7 @@ bi_getn(as, ai)
*/ */
int int
gmatch(s, p, isfile) gmatch(const char *s, const char *p, int isfile)
const char *s, *p;
int isfile;
{ {
const char *se, *pe; const char *se, *pe;
@ -570,8 +546,7 @@ gmatch(s, p, isfile)
- return ? - return ?
*/ */
int int
has_globbing(xp, xpe) has_globbing(const char *xp, const char *xpe)
const char *xp, *xpe;
{ {
const unsigned char *p = (const unsigned char *) xp; const unsigned char *p = (const unsigned char *) xp;
const unsigned char *pe = (const unsigned char *) xpe; const unsigned char *pe = (const unsigned char *) xpe;
@ -625,10 +600,7 @@ has_globbing(xp, xpe)
/* Function must return either 0 or 1 (assumed by code for 0x80|'!') */ /* Function must return either 0 or 1 (assumed by code for 0x80|'!') */
static int static int
do_gmatch(s, se, p, pe, isfile) do_gmatch(const unsigned char *s, const unsigned char *se, const unsigned char *p, const unsigned char *pe, int isfile)
const unsigned char *s, *p;
const unsigned char *se, *pe;
int isfile;
{ {
int sc, pc; int sc, pc;
const unsigned char *prest, *psub, *pnext; const unsigned char *prest, *psub, *pnext;
@ -760,9 +732,7 @@ do_gmatch(s, se, p, pe, isfile)
} }
static const unsigned char * static const unsigned char *
cclass(p, sub) cclass(const unsigned char *p, int sub)
const unsigned char *p;
int sub;
{ {
int c, d, not, found = 0; int c, d, not, found = 0;
const unsigned char *orig_p = p; const unsigned char *orig_p = p;
@ -807,10 +777,7 @@ cclass(p, sub)
/* Look for next ) or | (if match_sep) in *(foo|bar) pattern */ /* Look for next ) or | (if match_sep) in *(foo|bar) pattern */
const unsigned char * const unsigned char *
pat_scan(p, pe, match_sep) pat_scan(const unsigned char *p, const unsigned char *pe, int match_sep)
const unsigned char *p;
const unsigned char *pe;
int match_sep;
{ {
int nest = 0; int nest = 0;
@ -835,10 +802,10 @@ pat_scan(p, pe, match_sep)
static void qsort1(void **base, void **lim, int (*f)(void *, void *)); static void qsort1(void **base, void **lim, int (*f)(void *, void *));
void void
qsortp(base, n, f) qsortp(void **base, size_t n, int (*f) (void *, void *))
void **base; /* base address */ /* base address */
size_t n; /* elements */ /* elements */
int (*f)(void *, void *); /* compare function */ /* compare function */
{ {
qsort1(base, base + n, f); qsort1(base, base + n, f);
} }
@ -851,9 +818,7 @@ qsortp(base, n, f)
} }
static void static void
qsort1(base, lim, f) qsort1(void **base, void **lim, int (*f) (void *, void *))
void **base, **lim;
int (*f)(void *, void *);
{ {
void **i, **j; void **i, **j;
void **lptr, **hptr; void **lptr, **hptr;
@ -922,17 +887,14 @@ qsort1(base, lim, f)
} }
int int
xstrcmp(p1, p2) xstrcmp(void *p1, void *p2)
void *p1, *p2;
{ {
return (strcmp((char *)p1, (char *)p2)); return (strcmp((char *)p1, (char *)p2));
} }
/* Initialize a Getopt structure */ /* Initialize a Getopt structure */
void void
ksh_getopt_reset(go, flags) ksh_getopt_reset(Getopt *go, int flags)
Getopt *go;
int flags;
{ {
go->optind = 1; go->optind = 1;
go->optarg = (char *) 0; go->optarg = (char *) 0;
@ -968,10 +930,7 @@ ksh_getopt_reset(go, flags)
* in go->info. * in go->info.
*/ */
int int
ksh_getopt(argv, go, options) ksh_getopt(char **argv, Getopt *go, const char *options)
char **argv;
Getopt *go;
const char *options;
{ {
char c; char c;
char *o; char *o;
@ -1071,8 +1030,7 @@ ksh_getopt(argv, go, options)
* No trailing newline is printed. * No trailing newline is printed.
*/ */
void void
print_value_quoted(s) print_value_quoted(const char *s)
const char *s;
{ {
const char *p; const char *p;
int inquote = 0; int inquote = 0;
@ -1105,13 +1063,7 @@ print_value_quoted(s)
* element * element
*/ */
void void
print_columns(shf, n, func, arg, max_width, prefcol) print_columns(struct shf *shf, int n, char *(*func) (void *, int, char *, int), void *arg, int max_width, int prefcol)
struct shf *shf;
int n;
char *(*func)(void *, int, char *, int);
void *arg;
int max_width;
int prefcol;
{ {
char *str = (char *) alloc(max_width + 1, ATEMP); char *str = (char *) alloc(max_width + 1, ATEMP);
int i; int i;
@ -1157,9 +1109,7 @@ print_columns(shf, n, func, arg, max_width, prefcol)
/* Strip any nul bytes from buf - returns new length (nbytes - # of nuls) */ /* Strip any nul bytes from buf - returns new length (nbytes - # of nuls) */
int int
strip_nuls(buf, nbytes) strip_nuls(char *buf, int nbytes)
char *buf;
int nbytes;
{ {
char *dst; char *dst;
@ -1190,10 +1140,7 @@ strip_nuls(buf, nbytes)
* Returns dst. * Returns dst.
*/ */
char * char *
str_zcpy(dst, src, dsize) str_zcpy(char *dst, const char *src, int dsize)
char *dst;
const char *src;
int dsize;
{ {
if (dsize > 0) { if (dsize > 0) {
int len = strlen(src); int len = strlen(src);
@ -1210,10 +1157,7 @@ str_zcpy(dst, src, dsize)
* and restarts read. * and restarts read.
*/ */
int int
blocking_read(fd, buf, nbytes) blocking_read(int fd, char *buf, int nbytes)
int fd;
char *buf;
int nbytes;
{ {
int ret; int ret;
int tried_reset = 0; int tried_reset = 0;
@ -1242,8 +1186,7 @@ blocking_read(fd, buf, nbytes)
* 1 if it was. * 1 if it was.
*/ */
int int
reset_nonblock(fd) reset_nonblock(int fd)
int fd;
{ {
int flags; int flags;
int blocking_flags; int blocking_flags;
@ -1296,9 +1239,7 @@ reset_nonblock(fd)
/* Like getcwd(), except bsize is ignored if buf is 0 (MAXPATHLEN is used) */ /* Like getcwd(), except bsize is ignored if buf is 0 (MAXPATHLEN is used) */
char * char *
ksh_get_wd(buf, bsize) ksh_get_wd(char *buf, int bsize)
char *buf;
int bsize;
{ {
#ifdef HAVE_GETCWD #ifdef HAVE_GETCWD
char *b; char *b;

30
path.c
View File

@ -1,10 +1,10 @@
/** $MirBSD: path.c,v 1.6 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: path.c,v 1.7 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: path.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: path.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */
#include "sh.h" #include "sh.h"
#include "ksh_stat.h" #include "ksh_stat.h"
__RCSID("$MirBSD: path.c,v 1.6 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: path.c,v 1.7 2004/10/28 11:53:43 tg Exp $");
/* /*
* Contains a routine to search a : separated list of * Contains a routine to search a : separated list of
@ -35,12 +35,12 @@ static char *do_phys_path(XString *xsp, char *xp, const char *path);
* was appended to result. * was appended to result.
*/ */
int int
make_path(cwd, file, cdpathp, xsp, phys_pathp) make_path(const char *cwd, const char *file, char **cdpathp, XString *xsp, int *phys_pathp)
const char *cwd;
const char *file;
char **cdpathp; /* & of : separated list */ /* & of : separated list */
XString *xsp;
int *phys_pathp;
{ {
int rval = 0; int rval = 0;
int use_cdpath = 1; int use_cdpath = 1;
@ -113,8 +113,7 @@ make_path(cwd, file, cdpathp, xsp, phys_pathp)
* ie, simplify_path("/a/b/c/./../d/..") returns "/a/b" * ie, simplify_path("/a/b/c/./../d/..") returns "/a/b"
*/ */
void void
simplify_path(path) simplify_path(char *path)
char *path;
{ {
char *cur; char *cur;
char *t; char *t;
@ -196,8 +195,7 @@ simplify_path(path)
void void
set_current_wd(path) set_current_wd(char *path)
char *path;
{ {
int len; int len;
char *p = path; char *p = path;
@ -216,8 +214,7 @@ set_current_wd(path)
#ifdef S_ISLNK #ifdef S_ISLNK
char * char *
get_phys_path(path) get_phys_path(const char *path)
const char *path;
{ {
XString xs; XString xs;
char *xp; char *xp;
@ -237,10 +234,7 @@ get_phys_path(path)
} }
static char * static char *
do_phys_path(xsp, xp, path) do_phys_path(XString *xsp, char *xp, const char *path)
XString *xsp;
char *xp;
const char *path;
{ {
const char *p, *q; const char *p, *q;
size_t len; size_t len;

View File

@ -1,7 +1,10 @@
/** $MirBSD: proto.h,v 1.7 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: proto.h,v 1.8 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: proto.h,v 1.11 2003/05/16 19:58:57 jsyn Exp $ */ /* $OpenBSD: proto.h,v 1.11 2003/05/16 19:58:57 jsyn Exp $ */
/* $From: proto.h,v 1.3 1994/05/19 18:32:40 michael Exp michael $ */ /* $From: proto.h,v 1.3 1994/05/19 18:32:40 michael Exp michael $ */
#ifndef PROTO_H
#define PROTO_H
/* /*
* prototypes for PD-KSH * prototypes for PD-KSH
* originally generated using "cproto.c 3.5 92/04/11 19:28:01 cthuang" * originally generated using "cproto.c 3.5 92/04/11 19:28:01 cthuang"
@ -305,3 +308,5 @@ extern int gettimeofday( /* struct timeval *tv, struct timezone *tz */ );
extern int setrlimit( /* int resource, struct rlimit *rlp */ ); extern int setrlimit( /* int resource, struct rlimit *rlp */ );
extern int lstat( /* const char *path, struct stat *buf */ ); extern int lstat( /* const char *path, struct stat *buf */ );
#endif #endif
#endif /* ndef PROTO_H */

12
sh.h
View File

@ -1,6 +1,9 @@
/** $MirBSD: sh.h,v 1.14 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: sh.h,v 1.15 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: sh.h,v 1.18 2004/05/31 10:36:35 otto Exp $ */ /* $OpenBSD: sh.h,v 1.18 2004/05/31 10:36:35 otto Exp $ */
#ifndef SH_H
#define SH_H
/* /*
* mirbsdksh - MirOS Project Korn-Shell * mirbsdksh - MirOS Project Korn-Shell
* from: Public Domain Bourne/Korn shell * from: Public Domain Bourne/Korn shell
@ -102,13 +105,8 @@ void *memmove(void *d, const void *s, size_t n);
# endif # endif
#endif /* HAVE_MEMMOVE */ #endif /* HAVE_MEMMOVE */
#ifdef HAVE_PROTOTYPES
# include <stdarg.h> # include <stdarg.h>
# define SH_VA_START(va, argn) va_start(va, argn) # 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 <errno.h> #include <errno.h>
@ -722,3 +720,5 @@ EXTERN int x_cols I__(80); /* tty columns */
# undef EXTERN # undef EXTERN
#endif #endif
#undef I__ #undef I__
#endif /* ndef SH_H */

109
shf.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: shf.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: shf.c,v 1.6 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: shf.c,v 1.8 2003/02/28 09:45:09 jmc Exp $ */ /* $OpenBSD: shf.c,v 1.8 2003/02/28 09:45:09 jmc Exp $ */
/* /*
@ -9,7 +9,7 @@
#include "ksh_stat.h" #include "ksh_stat.h"
#include "ksh_limval.h" #include "ksh_limval.h"
__RCSID("$MirBSD: shf.c,v 1.5 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: shf.c,v 1.6 2004/10/28 11:53:43 tg Exp $");
/* flags to shf_emptybuf() */ /* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */ #define EB_READSW 0x01 /* about to switch to reading */
@ -29,11 +29,7 @@ static int shf_emptybuf(struct shf *shf, int flags);
* fails. * fails.
*/ */
struct shf * struct shf *
shf_open(name, oflags, mode, sflags) shf_open(const char *name, int oflags, int mode, int sflags)
const char *name;
int oflags;
int mode;
int sflags;
{ {
struct shf *shf; struct shf *shf;
int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE; int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE;
@ -73,10 +69,7 @@ shf_open(name, oflags, mode, sflags)
/* Set up the shf structure for a file descriptor. Doesn't fail. */ /* Set up the shf structure for a file descriptor. Doesn't fail. */
struct shf * struct shf *
shf_fdopen(fd, sflags, shf) shf_fdopen(int fd, int sflags, struct shf *shf)
int fd;
int sflags;
struct shf *shf;
{ {
int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE; int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE;
@ -126,10 +119,7 @@ shf_fdopen(fd, sflags, shf)
/* Set up an existing shf (and buffer) to use the given fd */ /* Set up an existing shf (and buffer) to use the given fd */
struct shf * struct shf *
shf_reopen(fd, sflags, shf) shf_reopen(int fd, int sflags, struct shf *shf)
int fd;
int sflags;
struct shf *shf;
{ {
int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE; int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE;
@ -176,11 +166,7 @@ shf_reopen(fd, sflags, shf)
* When writing, a byte is reserved for a trailing null - see shf_sclose(). * When writing, a byte is reserved for a trailing null - see shf_sclose().
*/ */
struct shf * struct shf *
shf_sopen(buf, bsize, sflags, shf) shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
char *buf;
int bsize;
int sflags;
struct shf *shf;
{ {
/* can't have a read+write string */ /* can't have a read+write string */
if (!(sflags & (SHF_RD | SHF_WR)) if (!(sflags & (SHF_RD | SHF_WR))
@ -213,8 +199,7 @@ shf_sopen(buf, bsize, sflags, shf)
/* Flush and close file descriptor, free the shf structure */ /* Flush and close file descriptor, free the shf structure */
int int
shf_close(shf) shf_close(struct shf *shf)
struct shf *shf;
{ {
int ret = 0; int ret = 0;
@ -233,8 +218,7 @@ shf_close(shf)
/* Flush and close file descriptor, don't free file structure */ /* Flush and close file descriptor, don't free file structure */
int int
shf_fdclose(shf) shf_fdclose(struct shf *shf)
struct shf *shf;
{ {
int ret = 0; int ret = 0;
@ -256,8 +240,7 @@ shf_fdclose(shf)
* (does not free string if it was allocated). * (does not free string if it was allocated).
*/ */
char * char *
shf_sclose(shf) shf_sclose(struct shf *shf)
struct shf *shf;
{ {
unsigned char *s = shf->buf; unsigned char *s = shf->buf;
@ -273,8 +256,7 @@ shf_sclose(shf)
/* Flush and free file structure, don't close file descriptor */ /* Flush and free file structure, don't close file descriptor */
int int
shf_finish(shf) shf_finish(struct shf *shf)
struct shf *shf;
{ {
int ret = 0; int ret = 0;
@ -292,8 +274,7 @@ shf_finish(shf)
* buffered. Returns 0 for success, EOF for (write) error. * buffered. Returns 0 for success, EOF for (write) error.
*/ */
int int
shf_flush(shf) shf_flush(struct shf *shf)
struct shf *shf;
{ {
if (shf->flags & SHF_STRING) if (shf->flags & SHF_STRING)
return (shf->flags & SHF_WR) ? EOF : 0; return (shf->flags & SHF_WR) ? EOF : 0;
@ -324,9 +305,7 @@ shf_flush(shf)
* buffer. Returns 0 for success, EOF for (write) error. * buffer. Returns 0 for success, EOF for (write) error.
*/ */
static int static int
shf_emptybuf(shf, flags) shf_emptybuf(struct shf *shf, int flags)
struct shf *shf;
int flags;
{ {
int ret = 0; int ret = 0;
@ -406,8 +385,7 @@ shf_emptybuf(shf, flags)
/* Fill up a read buffer. Returns EOF for a read error, 0 otherwise. */ /* Fill up a read buffer. Returns EOF for a read error, 0 otherwise. */
static int static int
shf_fillbuf(shf) shf_fillbuf(struct shf *shf)
struct shf *shf;
{ {
if (shf->flags & SHF_STRING) if (shf->flags & SHF_STRING)
return 0; return 0;
@ -453,10 +431,7 @@ shf_fillbuf(shf)
* buffer. Returns 0 for success, EOF otherwise. * buffer. Returns 0 for success, EOF otherwise.
*/ */
int int
shf_seek(shf, where, from) shf_seek(struct shf *shf, off_t where, int from)
struct shf *shf;
off_t where;
int from;
{ {
if (shf->fd < 0) { if (shf->fd < 0) {
errno = EINVAL; errno = EINVAL;
@ -501,10 +476,7 @@ shf_seek(shf, where, from)
* a read error occurred. * a read error occurred.
*/ */
int int
shf_read(buf, bsize, shf) shf_read(char *buf, int bsize, struct shf *shf)
char *buf;
int bsize;
struct shf *shf;
{ {
int orig_bsize = bsize; int orig_bsize = bsize;
int ncopy; int ncopy;
@ -538,10 +510,7 @@ shf_read(buf, bsize, shf)
* end of file, returns a pointer to the null byte in buf otherwise. * end of file, returns a pointer to the null byte in buf otherwise.
*/ */
char * char *
shf_getse(buf, bsize, shf) shf_getse(char *buf, int bsize, struct shf *shf)
char *buf;
int bsize;
struct shf *shf;
{ {
unsigned char *end; unsigned char *end;
int ncopy; int ncopy;
@ -588,8 +557,7 @@ shf_getse(buf, bsize, shf)
/* Returns the char read. Returns EOF for error and end of file. */ /* Returns the char read. Returns EOF for error and end of file. */
int int
shf_getchar(shf) shf_getchar(struct shf *shf)
struct shf *shf;
{ {
if (!(shf->flags & SHF_RD)) if (!(shf->flags & SHF_RD))
internal_errorf(1, "shf_getchar: flags %x", shf->flags); internal_errorf(1, "shf_getchar: flags %x", shf->flags);
@ -604,9 +572,7 @@ shf_getchar(shf)
* successful, EOF if there is no room. * successful, EOF if there is no room.
*/ */
int int
shf_ungetc(c, shf) shf_ungetc(int c, struct shf *shf)
int c;
struct shf *shf;
{ {
if (!(shf->flags & SHF_RD)) if (!(shf->flags & SHF_RD))
internal_errorf(1, "shf_ungetc: flags %x", shf->flags); internal_errorf(1, "shf_ungetc: flags %x", shf->flags);
@ -641,9 +607,7 @@ shf_ungetc(c, shf)
* the char could not be written. * the char could not be written.
*/ */
int int
shf_putchar(c, shf) shf_putchar(int c, struct shf *shf)
int c;
struct shf *shf;
{ {
if (!(shf->flags & SHF_WR)) if (!(shf->flags & SHF_WR))
internal_errorf(1, "shf_putchar: flags %x", shf->flags); internal_errorf(1, "shf_putchar: flags %x", shf->flags);
@ -685,9 +649,7 @@ shf_putchar(c, shf)
* the string could not be written. * the string could not be written.
*/ */
int int
shf_puts(s, shf) shf_puts(const char *s, struct shf *shf)
const char *s;
struct shf *shf;
{ {
if (!s) if (!s)
return EOF; return EOF;
@ -697,10 +659,7 @@ shf_puts(s, shf)
/* Write a buffer. Returns nbytes if successful, EOF if there is an error. */ /* Write a buffer. Returns nbytes if successful, EOF if there is an error. */
int int
shf_write(buf, nbytes, shf) shf_write(const char *buf, int nbytes, struct shf *shf)
const char *buf;
int nbytes;
struct shf *shf;
{ {
int orig_nbytes = nbytes; int orig_nbytes = nbytes;
int n; int n;
@ -761,14 +720,7 @@ shf_write(buf, nbytes, shf)
} }
int int
#ifdef HAVE_PROTOTYPES
shf_fprintf(struct shf *shf, const char *fmt, ...) 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; va_list args;
int n; int n;
@ -781,15 +733,7 @@ shf_fprintf(shf, fmt, va_alist)
} }
int int
#ifdef HAVE_PROTOTYPES
shf_snprintf(char *buf, int bsize, const char *fmt, ...) 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; struct shf shf;
va_list args; va_list args;
@ -808,13 +752,7 @@ shf_snprintf(buf, bsize, fmt, va_alist)
} }
char * char *
#ifdef HAVE_PROTOTYPES
shf_smprintf(const char *fmt, ...) shf_smprintf(const char *fmt, ...)
#else
shf_smprintf(fmt, va_alist)
char *fmt;
va_dcl
#endif
{ {
struct shf shf; struct shf shf;
va_list args; va_list args;
@ -884,10 +822,7 @@ my_ceil(d)
#endif /* FP */ #endif /* FP */
int int
shf_vfprintf(shf, fmt, args) shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
struct shf *shf;
const char *fmt;
va_list args;
{ {
char c, *s; char c, *s;
int UNINITIALIZED(tmp); int UNINITIALIZED(tmp);

4
shf.h
View File

@ -1,8 +1,8 @@
/** $MirBSD: shf.h,v 1.4 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: shf.h,v 1.5 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: shf.h,v 1.2 1999/01/08 20:25:02 millert Exp $ */ /* $OpenBSD: shf.h,v 1.2 1999/01/08 20:25:02 millert Exp $ */
#ifndef SHF_H #ifndef SHF_H
# define SHF_H #define SHF_H
/* /*
* Shell file I/O routines * Shell file I/O routines

83
syn.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: syn.c,v 1.6 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: syn.c,v 1.7 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: syn.c,v 1.14 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: syn.c,v 1.14 2003/10/22 07:40:38 jmc Exp $ */
/* /*
@ -8,7 +8,7 @@
#include "sh.h" #include "sh.h"
#include "c_test.h" #include "c_test.h"
__RCSID("$MirBSD: syn.c,v 1.6 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: syn.c,v 1.7 2004/10/28 11:53:43 tg Exp $");
struct nesting_state { struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */ int start_token; /* token than began nesting (eg, FOR) */
@ -63,7 +63,7 @@ static int symbol; /* yylex value */
((reject) ? (symbol) : (REJECT, symbol = yylex(cf))) ((reject) ? (symbol) : (REJECT, symbol = yylex(cf)))
static void static void
yyparse() yyparse(void)
{ {
int c; int c;
@ -78,8 +78,7 @@ yyparse()
} }
static struct op * static struct op *
pipeline(cf) pipeline(int cf)
int cf;
{ {
struct op *t, *p, *tl = NULL; struct op *t, *p, *tl = NULL;
@ -99,7 +98,7 @@ pipeline(cf)
} }
static struct op * static struct op *
andor() andor(void)
{ {
struct op *t, *p; struct op *t, *p;
int c; int c;
@ -117,8 +116,7 @@ andor()
} }
static struct op * static struct op *
c_list(multi) c_list(int multi)
int multi;
{ {
struct op *t = NULL, *p, *tl = NULL; struct op *t = NULL, *p, *tl = NULL;
int c; int c;
@ -155,8 +153,7 @@ c_list(multi)
} }
static struct ioword * static struct ioword *
synio(cf) synio(int cf)
int cf;
{ {
struct ioword *iop; struct ioword *iop;
int ishere; int ishere;
@ -180,16 +177,14 @@ synio(cf)
} }
static void static void
musthave(c, cf) musthave(int c, int cf)
int c, cf;
{ {
if ((token(cf)) != c) if ((token(cf)) != c)
syntaxerr((char *) 0); syntaxerr((char *) 0);
} }
static struct op * static struct op *
nested(type, smark, emark) nested(int type, int smark, int emark)
int type, smark, emark;
{ {
struct op *t; struct op *t;
struct nesting_state old_nesting; struct nesting_state old_nesting;
@ -202,8 +197,7 @@ nested(type, smark, emark)
} }
static struct op * static struct op *
get_command(cf) get_command(int cf)
int cf;
{ {
struct op *t; struct op *t;
int c, iopn = 0, syniocf; int c, iopn = 0, syniocf;
@ -419,7 +413,7 @@ get_command(cf)
} }
static struct op * static struct op *
dogroup() dogroup(void)
{ {
int c; int c;
struct op *list; struct op *list;
@ -442,7 +436,7 @@ dogroup()
} }
static struct op * static struct op *
thenpart() thenpart(void)
{ {
struct op *t; struct op *t;
@ -456,7 +450,7 @@ thenpart()
} }
static struct op * static struct op *
elsepart() elsepart(void)
{ {
struct op *t; struct op *t;
@ -479,7 +473,7 @@ elsepart()
} }
static struct op * static struct op *
caselist() caselist(void)
{ {
struct op *t, *tl; struct op *t, *tl;
int c; int c;
@ -505,8 +499,7 @@ caselist()
} }
static struct op * static struct op *
casepart(endtok) casepart(int endtok)
int endtok;
{ {
struct op *t; struct op *t;
int c; int c;
@ -534,9 +527,9 @@ casepart(endtok)
} }
static struct op * static struct op *
function_body(name, ksh_func) function_body(char *name, int ksh_func)
char *name;
int ksh_func; /* function foo { ... } vs foo() { .. } */ /* function foo { ... } vs foo() { .. } */
{ {
char *sname, *p; char *sname, *p;
struct op *t; struct op *t;
@ -595,7 +588,7 @@ function_body(name, ksh_func)
} }
static char ** static char **
wordlist() wordlist(void)
{ {
int c; int c;
XPtrV args; XPtrV args;
@ -625,10 +618,7 @@ wordlist()
*/ */
static struct op * static struct op *
block(type, t1, t2, wp) block(int type, struct op *t1, struct op *t2, char **wp)
int type;
struct op *t1, *t2;
char **wp;
{ {
struct op *t; struct op *t;
@ -683,7 +673,7 @@ const struct tokeninfo {
}; };
void void
initkeywords() initkeywords(void)
{ {
struct tokeninfo const *tt; struct tokeninfo const *tt;
struct tbl *p; struct tbl *p;
@ -700,8 +690,7 @@ initkeywords()
} }
static void static void
syntaxerr(what) syntaxerr(const char *what)
const char *what;
{ {
char redir[6]; /* 2<<- is the longest redirection, I think */ char redir[6]; /* 2<<- is the longest redirection, I think */
const char *s; const char *s;
@ -753,9 +742,7 @@ syntaxerr(what)
} }
static void static void
nesting_push(save, tok) nesting_push(struct nesting_state *save, int tok)
struct nesting_state *save;
int tok;
{ {
*save = nesting; *save = nesting;
nesting.start_token = tok; nesting.start_token = tok;
@ -763,15 +750,13 @@ nesting_push(save, tok)
} }
static void static void
nesting_pop(saved) nesting_pop(struct nesting_state *saved)
struct nesting_state *saved;
{ {
nesting = *saved; nesting = *saved;
} }
static struct op * static struct op *
newtp(type) newtp(int type)
int type;
{ {
struct op *t; struct op *t;
@ -786,8 +771,7 @@ newtp(type)
} }
struct op * struct op *
compile(s) compile(Source *s)
Source *s;
{ {
nesting.start_token = 0; nesting.start_token = 0;
nesting.start_line = 0; nesting.start_line = 0;
@ -808,8 +792,7 @@ compile(s)
* $ * $
*/ */
static int static int
assign_command(s) assign_command(char *s)
char *s;
{ {
char c = *s; char c = *s;
@ -823,8 +806,7 @@ assign_command(s)
/* Check if we are in the middle of reading an alias */ /* Check if we are in the middle of reading an alias */
static int static int
inalias(s) inalias(struct source *s)
struct source *s;
{ {
for (; s && s->type == SALIAS; s = s->next) for (; s && s->type == SALIAS; s = s->next)
if (!(s->flags & SF_ALIASEND)) if (!(s->flags & SF_ALIASEND))
@ -857,9 +839,7 @@ const char db_gthan[] = { CHAR, '>', EOS };
* TM_UNOP and TM_BINOP, the returned value is a Test_op). * TM_UNOP and TM_BINOP, the returned value is a Test_op).
*/ */
static int static int
dbtestp_isa(te, meta) dbtestp_isa(Test_env *te, Test_meta meta)
Test_env *te;
Test_meta meta;
{ {
int c = tpeek(ARRAYVAR | (meta == TM_BINOP ? 0 : CONTIN)); int c = tpeek(ARRAYVAR | (meta == TM_BINOP ? 0 : CONTIN));
int uqword = 0; int uqword = 0;
@ -928,10 +908,7 @@ dbtestp_eval(Test_env *te GCC_FUNC_ATTR(unused),
} }
static void static void
dbtestp_error(te, offset, msg) dbtestp_error(Test_env *te, int offset, const char *msg)
Test_env *te;
int offset;
const char *msg;
{ {
te->flags |= TEF_ERROR; te->flags |= TEF_ERROR;

48
table.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: table.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: table.c,v 1.6 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: table.c,v 1.5 1999/01/10 17:55:03 millert Exp $ */ /* $OpenBSD: table.c,v 1.5 1999/01/10 17:55:03 millert Exp $ */
/* /*
@ -7,7 +7,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirBSD: table.c,v 1.5 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: table.c,v 1.6 2004/10/28 11:53:43 tg Exp $");
#define INIT_TBLS 8 /* initial table size (power of 2) */ #define INIT_TBLS 8 /* initial table size (power of 2) */
@ -16,8 +16,7 @@ static int tnamecmp(void *p1, void *p2);
unsigned int unsigned int
hash(n) hash(const char *n)
const char * n;
{ {
unsigned int h = 0; unsigned int h = 0;
@ -27,10 +26,7 @@ hash(n)
} }
void void
tinit(tp, ap, tsize) tinit(struct table *tp, Area *ap, int tsize)
struct table *tp;
Area *ap;
int tsize;
{ {
tp->areap = ap; tp->areap = ap;
tp->tbls = NULL; tp->tbls = NULL;
@ -40,9 +36,7 @@ tinit(tp, ap, tsize)
} }
static void static void
texpand(tp, nsize) texpand(struct table *tp, int nsize)
struct table *tp;
int nsize;
{ {
int i; int i;
struct tbl *tblp, **p; struct tbl *tblp, **p;
@ -75,10 +69,10 @@ texpand(tp, nsize)
} }
struct tbl * struct tbl *
tsearch(tp, n, h) tsearch(struct table *tp, const char *n, unsigned int h)
struct table *tp; /* table */ /* table */
const char *n; /* name to enter */ /* name to enter */
unsigned int h; /* hash(n) */ /* hash(n) */
{ {
struct tbl **pp, *p; struct tbl **pp, *p;
@ -98,10 +92,10 @@ tsearch(tp, n, h)
} }
struct tbl * struct tbl *
tenter(tp, n, h) tenter(struct table *tp, const char *n, unsigned int h)
struct table *tp; /* table */ /* table */
const char *n; /* name to enter */ /* name to enter */
unsigned int h; /* hash(n) */ /* hash(n) */
{ {
struct tbl **pp, *p; struct tbl **pp, *p;
int len; int len;
@ -140,24 +134,20 @@ tenter(tp, n, h)
} }
void void
tdelete(p) tdelete(struct tbl *p)
struct tbl *p;
{ {
p->flag = 0; p->flag = 0;
} }
void void
twalk(ts, tp) twalk(struct tstate *ts, struct table *tp)
struct tstate *ts;
struct table *tp;
{ {
ts->left = tp->size; ts->left = tp->size;
ts->next = tp->tbls; ts->next = tp->tbls;
} }
struct tbl * struct tbl *
tnext(ts) tnext(struct tstate *ts)
struct tstate *ts;
{ {
while (--ts->left >= 0) { while (--ts->left >= 0) {
struct tbl *p = *ts->next++; struct tbl *p = *ts->next++;
@ -168,15 +158,13 @@ tnext(ts)
} }
static int static int
tnamecmp(p1, p2) tnamecmp(void *p1, void *p2)
void *p1, *p2;
{ {
return strcmp(((struct tbl *)p1)->name, ((struct tbl *)p2)->name); return strcmp(((struct tbl *)p1)->name, ((struct tbl *)p2)->name);
} }
struct tbl ** struct tbl **
tsort(tp) tsort(struct table *tp)
struct table *tp;
{ {
int i; int i;
struct tbl **p, **sp, **dp; struct tbl **p, **sp, **dp;

11
table.h
View File

@ -1,7 +1,10 @@
/** $MirBSD: table.h,v 1.4 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: table.h,v 1.5 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: table.h,v 1.5 1999/06/15 01:18:36 millert Exp $ */ /* $OpenBSD: table.h,v 1.5 1999/06/15 01:18:36 millert Exp $ */
/* $From: table.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */ /* $From: table.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */
#ifndef TABLE_H
#define TABLE_H
/* /*
* generic hashed associative table for commands and variables. * generic hashed associative table for commands and variables.
*/ */
@ -116,12 +119,8 @@ struct block {
struct table vars; /* local variables */ struct table vars; /* local variables */
struct table funs; /* local functions */ struct table funs; /* local functions */
Getopt getopts_state; Getopt getopts_state;
#if 1
char * error; /* error handler */ char * error; /* error handler */
char * exit; /* exit handler */ char * exit; /* exit handler */
#else
Trap error, exit;
#endif
struct block *next; /* enclosing block */ struct block *next; /* enclosing block */
}; };
@ -181,3 +180,5 @@ EXTERN char *tmpdir; /* TMPDIR value */
EXTERN const char *prompt; EXTERN const char *prompt;
EXTERN int cur_prompt; /* PS1 or PS2 */ EXTERN int cur_prompt; /* PS1 or PS2 */
EXTERN int current_lineno; /* LINENO value */ EXTERN int current_lineno; /* LINENO value */
#endif /* ndef TABLE_H */

49
trap.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: trap.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: trap.c,v 1.6 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: trap.c,v 1.13 2003/02/28 09:45:09 jmc Exp $ */ /* $OpenBSD: trap.c,v 1.13 2003/02/28 09:45:09 jmc Exp $ */
/* /*
@ -9,7 +9,7 @@
#define FROM_TRAP_C #define FROM_TRAP_C
#include "sh.h" #include "sh.h"
__RCSID("$MirBSD: trap.c,v 1.5 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: trap.c,v 1.6 2004/10/28 11:53:43 tg Exp $");
/* Table is indexed by signal number /* Table is indexed by signal number
* *
@ -25,7 +25,7 @@ Trap sigtraps[SIGNALS+1] = {
static struct sigaction Sigact_ign, Sigact_trap; static struct sigaction Sigact_ign, Sigact_trap;
void void
inittraps() inittraps(void)
{ {
#ifdef HAVE_SYS_SIGLIST #ifdef HAVE_SYS_SIGLIST
# ifndef SYS_SIGLIST_DECLARED # ifndef SYS_SIGLIST_DECLARED
@ -62,7 +62,7 @@ inittraps()
static RETSIGTYPE alarm_catcher(int sig); static RETSIGTYPE alarm_catcher(int sig);
void void
alarm_init() alarm_init(void)
{ {
sigtraps[SIGALRM].flags |= TF_SHELL_USES; sigtraps[SIGALRM].flags |= TF_SHELL_USES;
setsig(&sigtraps[SIGALRM], alarm_catcher, setsig(&sigtraps[SIGALRM], alarm_catcher,
@ -89,9 +89,7 @@ alarm_catcher(int sig GCC_FUNC_ATTR(unused))
#endif /* KSH */ #endif /* KSH */
Trap * Trap *
gettrap(name, igncase) gettrap(const char *name, int igncase)
const char *name;
int igncase;
{ {
int i; int i;
Trap *p; Trap *p;
@ -125,8 +123,7 @@ gettrap(name, igncase)
* trap signal handler * trap signal handler
*/ */
RETSIGTYPE RETSIGTYPE
trapsig(i) trapsig(int i)
int i;
{ {
Trap *p = &sigtraps[i]; Trap *p = &sigtraps[i];
int errno_ = errno; int errno_ = errno;
@ -152,7 +149,7 @@ trapsig(i)
* work if user has trapped SIGINT. * work if user has trapped SIGINT.
*/ */
void void
intrcheck() intrcheck(void)
{ {
if (intrsig) if (intrsig)
runtraps(TF_DFL_INTR|TF_FATAL); runtraps(TF_DFL_INTR|TF_FATAL);
@ -162,7 +159,7 @@ intrcheck()
* termination has been received. * termination has been received.
*/ */
int int
fatal_trap_check() fatal_trap_check(void)
{ {
int i; int i;
Trap *p; Trap *p;
@ -180,7 +177,7 @@ fatal_trap_check()
* is set. * is set.
*/ */
int int
trap_pending() trap_pending(void)
{ {
int i; int i;
Trap *p; Trap *p;
@ -198,8 +195,7 @@ trap_pending()
* can interrupt commands. * can interrupt commands.
*/ */
void void
runtraps(flag) runtraps(int flag)
int flag;
{ {
int i; int i;
Trap *p; Trap *p;
@ -228,8 +224,7 @@ runtraps(flag)
} }
void void
runtrap(p) runtrap(Trap *p)
Trap *p;
{ {
int i = p->signal; int i = p->signal;
char *trapstr = p->trap; char *trapstr = p->trap;
@ -275,7 +270,7 @@ runtrap(p)
/* clear pending traps and reset user's trap handlers; used after fork(2) */ /* clear pending traps and reset user's trap handlers; used after fork(2) */
void void
cleartraps() cleartraps(void)
{ {
int i; int i;
Trap *p; Trap *p;
@ -292,7 +287,7 @@ cleartraps()
/* restore signals just before an exec(2) */ /* restore signals just before an exec(2) */
void void
restoresigs() restoresigs(void)
{ {
int i; int i;
Trap *p; Trap *p;
@ -304,9 +299,7 @@ restoresigs()
} }
void void
settrap(p, s) settrap(Trap *p, char *s)
Trap *p;
char *s;
{ {
handler_t f; handler_t f;
@ -342,7 +335,7 @@ settrap(p, s)
* kill shell (unless user catches it and exits) * kill shell (unless user catches it and exits)
*/ */
int int
block_pipe() block_pipe(void)
{ {
int restore_dfl = 0; int restore_dfl = 0;
Trap *p = &sigtraps[SIGPIPE]; Trap *p = &sigtraps[SIGPIPE];
@ -360,8 +353,7 @@ block_pipe()
/* Called by c_print() to undo whatever block_pipe() did */ /* Called by c_print() to undo whatever block_pipe() did */
void void
restore_pipe(restore_dfl) restore_pipe(int restore_dfl)
int restore_dfl;
{ {
if (restore_dfl) if (restore_dfl)
setsig(&sigtraps[SIGPIPE], SIG_DFL, SS_RESTORE_CURR); setsig(&sigtraps[SIGPIPE], SIG_DFL, SS_RESTORE_CURR);
@ -372,10 +364,7 @@ restore_pipe(restore_dfl)
* FTALKING. * FTALKING.
*/ */
int int
setsig(p, f, flags) setsig(Trap *p, handler_t f, int flags)
Trap *p;
handler_t f;
int flags;
{ {
struct sigaction sigact; struct sigaction sigact;
@ -426,9 +415,7 @@ setsig(p, f, flags)
/* control what signal is set to before an exec() */ /* control what signal is set to before an exec() */
void void
setexecsig(p, restore) setexecsig(Trap *p, int restore)
Trap *p;
int restore;
{ {
/* XXX debugging */ /* XXX debugging */
if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL))) if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL)))

88
tree.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: tree.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: tree.c,v 1.6 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: tree.c,v 1.10 2002/02/27 19:37:09 dhartmei Exp $ */ /* $OpenBSD: tree.c,v 1.10 2002/02/27 19:37:09 dhartmei Exp $ */
/* /*
@ -7,7 +7,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirBSD: tree.c,v 1.5 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: tree.c,v 1.6 2004/10/28 11:53:43 tg Exp $");
#define INDENT 4 #define INDENT 4
@ -25,10 +25,7 @@ static void iofree(struct ioword **iow, Area *ap);
*/ */
static void static void
ptree(t, indent, shf) ptree(struct op *t, int indent, struct shf *shf)
struct op *t;
int indent;
struct shf *shf;
{ {
char **w; char **w;
struct ioword **ioact; struct ioword **ioact;
@ -51,25 +48,8 @@ ptree(t, indent, shf)
fptreef(shf, indent, "#no-args# "); fptreef(shf, indent, "#no-args# ");
break; break;
case TEXEC: case TEXEC:
#if 0 /* ?not useful - can't be called? */
/* Print original vars */
if (t->left->vars)
for (w = t->left->vars; *w != NULL; )
fptreef(shf, indent, "%S ", *w++);
else
fptreef(shf, indent, "#no-vars# ");
/* Print expanded vars */
if (t->args)
for (w = t->args; *w != NULL; )
fptreef(shf, indent, "%s ", *w++);
else
fptreef(shf, indent, "#no-args# ");
/* Print original io */
t = t->left;
#else
t = t->left; t = t->left;
goto Chain; goto Chain;
#endif
case TPAREN: case TPAREN:
fptreef(shf, indent + 2, "( %T) ", t->left); fptreef(shf, indent + 2, "( %T) ", t->left);
break; break;
@ -212,10 +192,7 @@ ptree(t, indent, shf)
} }
static void static void
pioact(shf, indent, iop) pioact(struct shf *shf, int indent, struct ioword *iop)
struct shf *shf;
int indent;
struct ioword *iop;
{ {
int flag = iop->flag; int flag = iop->flag;
int type = flag & IOTYPE; int type = flag & IOTYPE;
@ -273,9 +250,7 @@ pioact(shf, indent, iop)
*/ */
static void static void
tputC(c, shf) tputC(int c, struct shf *shf)
int c;
struct shf *shf;
{ {
if ((c&0x60) == 0) { /* C0|C1 */ if ((c&0x60) == 0) { /* C0|C1 */
tputc((c&0x80) ? '$' : '^', shf); tputc((c&0x80) ? '$' : '^', shf);
@ -288,9 +263,7 @@ tputC(c, shf)
} }
static void static void
tputS(wp, shf) tputS(char *wp, struct shf *shf)
char *wp;
struct shf *shf;
{ {
int c, quoted=0; int c, quoted=0;
@ -372,15 +345,7 @@ tputS(wp, shf)
*/ */
/* VARARGS */ /* VARARGS */
int int
#ifdef HAVE_PROTOTYPES
fptreef(struct shf *shf, int indent, const char *fmt, ...) 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; va_list va;
@ -393,15 +358,7 @@ fptreef(shf, indent, fmt, va_alist)
/* VARARGS */ /* VARARGS */
char * char *
#ifdef HAVE_PROTOTYPES
snptreef(char *s, int n, const char *fmt, ...) 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; va_list va;
struct shf shf; struct shf shf;
@ -416,11 +373,7 @@ snptreef(s, n, fmt, va_alist)
} }
static void static void
vfptreef(shf, indent, fmt, va) vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
struct shf *shf;
int indent;
const char *fmt;
va_list va;
{ {
int c; int c;
@ -488,9 +441,7 @@ vfptreef(shf, indent, fmt, va)
*/ */
struct op * struct op *
tcopy(t, ap) tcopy(struct op *t, Area *ap)
struct op *t;
Area *ap;
{ {
struct op *r; struct op *r;
char **tw, **rw; char **tw, **rw;
@ -539,9 +490,7 @@ tcopy(t, ap)
} }
char * char *
wdcopy(wp, ap) wdcopy(const char *wp, Area *ap)
const char *wp;
Area *ap;
{ {
size_t len = wdscan(wp, EOS) - wp; size_t len = wdscan(wp, EOS) - wp;
return memcpy(alloc(len, ap), wp, len); return memcpy(alloc(len, ap), wp, len);
@ -549,9 +498,7 @@ wdcopy(wp, ap)
/* return the position of prefix c in wp plus 1 */ /* return the position of prefix c in wp plus 1 */
char * char *
wdscan(wp, c) wdscan(const char *wp, int c)
const char *wp;
int c;
{ {
int nest = 0; int nest = 0;
@ -607,8 +554,7 @@ wdscan(wp, c)
* (string is allocated from ATEMP) * (string is allocated from ATEMP)
*/ */
char * char *
wdstrip(wp) wdstrip(const char *wp)
const char *wp;
{ {
struct shf shf; struct shf shf;
int c; int c;
@ -675,9 +621,7 @@ wdstrip(wp)
} }
static struct ioword ** static struct ioword **
iocopy(iow, ap) iocopy(struct ioword **iow, Area *ap)
struct ioword **iow;
Area *ap;
{ {
struct ioword **ior; struct ioword **ior;
int i; int i;
@ -710,9 +654,7 @@ iocopy(iow, ap)
*/ */
void void
tfree(t, ap) tfree(struct op *t, Area *ap)
struct op *t;
Area *ap;
{ {
char **w; char **w;
@ -744,9 +686,7 @@ tfree(t, ap)
} }
static void static void
iofree(iow, ap) iofree(struct ioword **iow, Area *ap)
struct ioword **iow;
Area *ap;
{ {
struct ioword **iop; struct ioword **iop;
struct ioword *p; struct ioword *p;

7
tree.h
View File

@ -1,7 +1,10 @@
/** $MirBSD: tree.h,v 1.3 2004/09/21 11:57:16 tg Exp $ */ /** $MirBSD: tree.h,v 1.4 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: tree.h,v 1.8 2003/10/22 07:40:38 jmc Exp $ */ /* $OpenBSD: tree.h,v 1.8 2003/10/22 07:40:38 jmc Exp $ */
/* $From: tree.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */ /* $From: tree.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */
#ifndef TREE_H
#define TREE_H
/* /*
* command trees for compile/execute * command trees for compile/execute
*/ */
@ -140,3 +143,5 @@ struct ioword {
#define DB_AND 3 /* && -> -a conversion */ #define DB_AND 3 /* && -> -a conversion */
#define DB_BE 4 /* an inserted -BE */ #define DB_BE 4 /* an inserted -BE */
#define DB_PAT 5 /* a pattern argument */ #define DB_PAT 5 /* a pattern argument */
#endif /* ndef TREE_H */

13
tty.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: tty.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: tty.c,v 1.6 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: tty.c,v 1.2 1996/10/01 02:05:51 downsj Exp $ */ /* $OpenBSD: tty.c,v 1.2 1996/10/01 02:05:51 downsj Exp $ */
#include "sh.h" #include "sh.h"
@ -7,12 +7,10 @@
#include "tty.h" #include "tty.h"
#undef EXTERN #undef EXTERN
__RCSID("$MirBSD: tty.c,v 1.5 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: tty.c,v 1.6 2004/10/28 11:53:43 tg Exp $");
int int
get_tty(fd, ts) get_tty(int fd, TTY_state *ts)
int fd;
TTY_state *ts;
{ {
int ret; int ret;
@ -99,8 +97,7 @@ set_tty(int fd, TTY_state *ts, int flags GCC_FUNC_ATTR(unused))
* foreground job completion and for setting up tty process group. * foreground job completion and for setting up tty process group.
*/ */
void void
tty_init(init_ttystate) tty_init(int init_ttystate)
int init_ttystate;
{ {
int do_close = 1; int do_close = 1;
int tfd; int tfd;
@ -170,7 +167,7 @@ tty_init(init_ttystate)
} }
void void
tty_close() tty_close(void)
{ {
if (tty_fd >= 0) { if (tty_fd >= 0) {
close(tty_fd); close(tty_fd);

7
tty.h
View File

@ -1,6 +1,9 @@
/** $MirBSD: tty.h,v 1.4 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: tty.h,v 1.5 2004/10/28 11:53:43 tg Exp $ */
/* $OpenBSD: tty.h,v 1.2 1996/11/21 07:59:36 downsj Exp $ */ /* $OpenBSD: tty.h,v 1.2 1996/11/21 07:59:36 downsj Exp $ */
#ifndef TTY_H
#define TTY_H
/* /*
tty.h -- centralized definitions for a variety of terminal interfaces tty.h -- centralized definitions for a variety of terminal interfaces
@ -108,3 +111,5 @@ extern void tty_close(void);
# undef EXTERN # undef EXTERN
#endif #endif
#undef I__ #undef I__
#endif /* ndef TTY_H */

112
var.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: var.c,v 1.10 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: var.c,v 1.11 2004/10/28 11:53:44 tg Exp $ */
/* $OpenBSD: var.c,v 1.17 2004/05/08 19:42:35 deraadt Exp $ */ /* $OpenBSD: var.c,v 1.17 2004/05/08 19:42:35 deraadt Exp $ */
#include "sh.h" #include "sh.h"
@ -7,7 +7,7 @@
#include "ksh_stat.h" #include "ksh_stat.h"
#include <ctype.h> #include <ctype.h>
__RCSID("$MirBSD: var.c,v 1.10 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: var.c,v 1.11 2004/10/28 11:53:44 tg Exp $");
/* /*
* Variables * Variables
@ -34,7 +34,7 @@ static struct tbl *arraysearch(struct tbl *, int);
* assume caller has allocated and set up e->loc * assume caller has allocated and set up e->loc
*/ */
void void
newblock() newblock(void)
{ {
struct block *l; struct block *l;
static char *const empty[] = {null}; static char *const empty[] = {null};
@ -60,7 +60,7 @@ newblock()
* pop a block handling special variables * pop a block handling special variables
*/ */
void void
popblock() popblock(void)
{ {
struct block *l = e->loc; struct block *l = e->loc;
struct tbl *vp, **vpp = l->vars.tbls, *vq; struct tbl *vp, **vpp = l->vars.tbls, *vq;
@ -82,7 +82,7 @@ popblock()
/* called by main() to initialize variable data structures */ /* called by main() to initialize variable data structures */
void void
initvar() initvar(void)
{ {
static const struct { static const struct {
const char *name; const char *name;
@ -131,10 +131,7 @@ initvar()
const char *array_index_calc(const char *n, bool_t *arrayp, int *valp); const char *array_index_calc(const char *n, bool_t *arrayp, int *valp);
const char * const char *
array_index_calc(n, arrayp, valp) array_index_calc(const char *n, bool_t *arrayp, int *valp)
const char *n;
bool_t *arrayp;
int *valp;
{ {
const char *p; const char *p;
int len; int len;
@ -164,8 +161,7 @@ array_index_calc(n, arrayp, valp)
* Search for variable, if not found create globally. * Search for variable, if not found create globally.
*/ */
struct tbl * struct tbl *
global(n) global(const char *n)
const char *n;
{ {
struct block *l = e->loc; struct block *l = e->loc;
struct tbl *vp; struct tbl *vp;
@ -247,9 +243,7 @@ global(n)
* Search for local variable, if not found create locally. * Search for local variable, if not found create locally.
*/ */
struct tbl * struct tbl *
local(n, copy) local(const char *n, bool_t copy)
const char *n;
bool_t copy;
{ {
struct block *l = e->loc; struct block *l = e->loc;
struct tbl *vp; struct tbl *vp;
@ -293,8 +287,7 @@ local(n, copy)
/* get variable string value */ /* get variable string value */
char * char *
str_val(vp) str_val(struct tbl *vp)
struct tbl *vp;
{ {
char *s; char *s;
@ -342,8 +335,7 @@ str_val(vp)
/* get variable integer value, with error checking */ /* get variable integer value, with error checking */
long long
intval(vp) intval(struct tbl *vp)
struct tbl *vp;
{ {
long num; long num;
int base; int base;
@ -357,10 +349,7 @@ intval(vp)
/* set variable to string value */ /* set variable to string value */
int int
setstr(vq, s, error_ok) setstr(struct tbl *vq, const char *s, int error_ok)
struct tbl *vq;
const char *s;
int error_ok;
{ {
int no_ro_check = error_ok & 0x4; int no_ro_check = error_ok & 0x4;
error_ok &= ~0x4; error_ok &= ~0x4;
@ -401,9 +390,7 @@ setstr(vq, s, error_ok)
/* set variable to integer */ /* set variable to integer */
void void
setint(vq, n) setint(struct tbl *vq, long int n)
struct tbl *vq;
long n;
{ {
if (!(vq->flag&INTEGER)) { if (!(vq->flag&INTEGER)) {
struct tbl *vp = &vtemp; struct tbl *vp = &vtemp;
@ -421,9 +408,7 @@ setint(vq, n)
} }
int int
getint(vp, nump) getint(struct tbl *vp, long int *nump)
struct tbl *vp;
long *nump;
{ {
char *s; char *s;
int c; int c;
@ -480,8 +465,7 @@ getint(vp, nump)
* (vq and vp may be the same) * (vq and vp may be the same)
*/ */
struct tbl * struct tbl *
setint_v(vq, vp) setint_v(struct tbl *vq, struct tbl *vp)
struct tbl *vq, *vp;
{ {
int base; int base;
long num; long num;
@ -502,9 +486,7 @@ setint_v(vq, vp)
} }
static char * static char *
formatstr(vp, s) formatstr(struct tbl *vp, const char *s)
struct tbl *vp;
const char *s;
{ {
int olen, nlen; int olen, nlen;
char *p, *q; char *p, *q;
@ -566,9 +548,7 @@ formatstr(vp, s)
* make vp->val.s be "name=value" for quick exporting. * make vp->val.s be "name=value" for quick exporting.
*/ */
static void static void
export(vp, val) export(struct tbl *vp, const char *val)
struct tbl *vp;
const char *val;
{ {
char *xp; char *xp;
char *op = (vp->flag&ALLOC) ? vp->val.s : NULL; char *op = (vp->flag&ALLOC) ? vp->val.s : NULL;
@ -592,10 +572,7 @@ export(vp, val)
* LCASEV, UCASEV_AL), and optionally set its value if an assignment. * LCASEV, UCASEV_AL), and optionally set its value if an assignment.
*/ */
struct tbl * struct tbl *
typeset(var, set, clr, field, base) typeset(const char *var, Tflag set, Tflag clr, int field, int base)
const char *var;
Tflag clr, set;
int field, base;
{ {
struct tbl *vp; struct tbl *vp;
struct tbl *vpbase, *t; struct tbl *vpbase, *t;
@ -746,9 +723,7 @@ typeset(var, set, clr, field, base)
* the name lookup (eg, x[2]). * the name lookup (eg, x[2]).
*/ */
void void
unset(vp, array_ref) unset(struct tbl *vp, int array_ref)
struct tbl *vp;
int array_ref;
{ {
if (vp->flag & ALLOC) if (vp->flag & ALLOC)
afree((void*)vp->val.s, vp->areap); afree((void*)vp->val.s, vp->areap);
@ -776,9 +751,7 @@ unset(vp, array_ref)
* null if whole string is legal). * null if whole string is legal).
*/ */
char * char *
skip_varname(s, aok) skip_varname(const char *s, int aok)
const char *s;
int aok;
{ {
int alen; int alen;
@ -793,9 +766,9 @@ skip_varname(s, aok)
/* Return a pointer to the first character past any legal variable name. */ /* Return a pointer to the first character past any legal variable name. */
char * char *
skip_wdvarname(s, aok) skip_wdvarname(const char *s, int aok)
const char *s;
int aok; /* skip array de-reference? */ /* skip array de-reference? */
{ {
if (s[0] == CHAR && letter(s[1])) { if (s[0] == CHAR && letter(s[1])) {
do do
@ -826,9 +799,7 @@ skip_wdvarname(s, aok)
/* Check if coded string s is a variable name */ /* Check if coded string s is a variable name */
int int
is_wdvarname(s, aok) is_wdvarname(const char *s, int aok)
const char *s;
int aok;
{ {
char *p = skip_wdvarname(s, aok); char *p = skip_wdvarname(s, aok);
@ -837,8 +808,7 @@ is_wdvarname(s, aok)
/* Check if coded string s is a variable assignment */ /* Check if coded string s is a variable assignment */
int int
is_wdvarassign(s) is_wdvarassign(const char *s)
const char *s;
{ {
char *p = skip_wdvarname(s, TRUE); char *p = skip_wdvarname(s, TRUE);
@ -849,7 +819,7 @@ is_wdvarassign(s)
* Make the exported environment from the exported names in the dictionary. * Make the exported environment from the exported names in the dictionary.
*/ */
char ** char **
makenv() makenv(void)
{ {
struct block *l = e->loc; struct block *l = e->loc;
XPtrV env; XPtrV env;
@ -889,7 +859,7 @@ makenv()
* Called after a fork in parent to bump the random number generator. * Called after a fork in parent to bump the random number generator.
*/ */
void void
change_random() change_random(void)
{ {
rnd_seed(time(NULL) * getpid()); rnd_seed(time(NULL) * getpid());
} }
@ -900,8 +870,7 @@ change_random()
/* Test if name is a special parameter */ /* Test if name is a special parameter */
static int static int
special(name) special(const char *name)
const char * name;
{ {
struct tbl *tp; struct tbl *tp;
@ -911,8 +880,7 @@ special(name)
/* Make a variable non-special */ /* Make a variable non-special */
static void static void
unspecial(name) unspecial(const char *name)
const char * name;
{ {
struct tbl *tp; struct tbl *tp;
@ -927,8 +895,7 @@ static time_t seconds; /* time SECONDS last set */
static int user_lineno; /* what user set $LINENO to */ static int user_lineno; /* what user set $LINENO to */
static void static void
getspec(vp) getspec(struct tbl *vp)
struct tbl *vp;
{ {
switch (special(vp->name)) { switch (special(vp->name)) {
#ifdef KSH #ifdef KSH
@ -969,8 +936,7 @@ getspec(vp)
} }
static void static void
setspec(vp) setspec(struct tbl *vp)
struct tbl *vp;
{ {
char *s; char *s;
@ -1070,8 +1036,7 @@ setspec(vp)
} }
static void static void
unsetspec(vp) unsetspec(struct tbl *vp)
struct tbl *vp;
{ {
switch (special(vp->name)) { switch (special(vp->name)) {
case V_PATH: case V_PATH:
@ -1129,9 +1094,7 @@ unsetspec(vp)
* vp, indexed by val. * vp, indexed by val.
*/ */
static struct tbl * static struct tbl *
arraysearch(vp, val) arraysearch(struct tbl *vp, int val)
struct tbl *vp;
int val;
{ {
struct tbl *prev, *curr, *new; struct tbl *prev, *curr, *new;
size_t namelen = strlen(vp->name) + 1; size_t namelen = strlen(vp->name) + 1;
@ -1175,8 +1138,7 @@ arraysearch(vp, val)
* bracket. * bracket.
*/ */
int int
array_ref_len(cp) array_ref_len(const char *cp)
const char *cp;
{ {
const char *s = cp; const char *s = cp;
int c; int c;
@ -1194,8 +1156,7 @@ array_ref_len(cp)
* Make a copy of the base of an array name * Make a copy of the base of an array name
*/ */
char * char *
arrayname(str) arrayname(const char *str)
const char *str;
{ {
const char *p; const char *p;
@ -1209,10 +1170,7 @@ arrayname(str)
/* Set (or overwrite, if !reset) the array variable var to the values in vals. /* Set (or overwrite, if !reset) the array variable var to the values in vals.
*/ */
void void
set_array(var, reset, vals) set_array(const char *var, int reset, char **vals)
const char *var;
int reset;
char **vals;
{ {
struct tbl *vp, *vq; struct tbl *vp, *vq;
int i; int i;

141
vi.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: vi.c,v 1.9 2004/10/28 11:11:19 tg Exp $ */ /** $MirBSD: vi.c,v 1.10 2004/10/28 11:53:44 tg Exp $ */
/* $OpenBSD: vi.c,v 1.13 2004/05/10 16:28:47 pvalchev Exp $ */ /* $OpenBSD: vi.c,v 1.13 2004/05/10 16:28:47 pvalchev Exp $ */
/* /*
@ -15,7 +15,7 @@
#include "ksh_stat.h" /* completion */ #include "ksh_stat.h" /* completion */
#include "edit.h" #include "edit.h"
__RCSID("$MirBSD: vi.c,v 1.9 2004/10/28 11:11:19 tg Exp $"); __RCSID("$MirBSD: vi.c,v 1.10 2004/10/28 11:53:44 tg Exp $");
#define Ctrl(c) (c&0x1f) #define Ctrl(c) (c&0x1f)
#define is_wordch(c) (letnum(c)) #define is_wordch(c) (letnum(c))
@ -190,9 +190,7 @@ enum expand_mode { NONE, EXPAND, COMPLETE, PRINT };
static enum expand_mode expanded = NONE;/* last input was expanded */ static enum expand_mode expanded = NONE;/* last input was expanded */
int int
x_vi(buf, len) x_vi(char *buf, size_t len)
char *buf;
size_t len;
{ {
int c; int c;
@ -252,8 +250,7 @@ x_vi(buf, len)
} }
static int static int
vi_hook(ch) vi_hook(int ch)
int ch;
{ {
static char curcmd[MAXVICMD]; static char curcmd[MAXVICMD];
static char locpat[SRCHLEN]; static char locpat[SRCHLEN];
@ -550,9 +547,7 @@ vi_hook(ch)
} }
static void static void
vi_reset(buf, len) vi_reset(char *buf, size_t len)
char *buf;
size_t len;
{ {
state = VNORMAL; state = VNORMAL;
ohnum = hnum = hlast = histnum(-1) + 1; ohnum = hnum = hlast = histnum(-1) + 1;
@ -566,8 +561,7 @@ vi_reset(buf, len)
} }
static int static int
nextstate(ch) nextstate(int ch)
int ch;
{ {
if (is_extend(ch)) if (is_extend(ch))
return VEXTCMD; return VEXTCMD;
@ -586,8 +580,7 @@ nextstate(ch)
} }
static int static int
vi_insert(ch) vi_insert(int ch)
int ch;
{ {
int tcursor; int tcursor;
@ -719,9 +712,7 @@ vi_insert(ch)
} }
static int static int
vi_cmd(argcnt, cmd) vi_cmd(int argcnt, const char *cmd)
int argcnt;
const char *cmd;
{ {
int ncursor; int ncursor;
int cur, c1, c2, c3 = 0; int cur, c1, c2, c3 = 0;
@ -1172,10 +1163,7 @@ vi_cmd(argcnt, cmd)
} }
static int static int
domove(argcnt, cmd, sub) domove(int argcnt, const char *cmd, int sub)
int argcnt;
const char *cmd;
int sub;
{ {
int bcount, UNINITIALIZED(i), t; int bcount, UNINITIALIZED(i), t;
int UNINITIALIZED(ncursor); int UNINITIALIZED(ncursor);
@ -1322,8 +1310,7 @@ domove(argcnt, cmd, sub)
} }
static int static int
redo_insert(count) redo_insert(int count)
int count;
{ {
while (count-- > 0) while (count-- > 0)
if (putbuf(ibuf, inslen, insert==REPLACE) != 0) if (putbuf(ibuf, inslen, insert==REPLACE) != 0)
@ -1335,8 +1322,7 @@ redo_insert(count)
} }
static void static void
yank_range(a, b) yank_range(int a, int b)
int a, b;
{ {
yanklen = b - a; yanklen = b - a;
if (yanklen != 0) if (yanklen != 0)
@ -1344,8 +1330,7 @@ yank_range(a, b)
} }
static int static int
bracktype(ch) bracktype(int ch)
int ch;
{ {
switch (ch) { switch (ch) {
@ -1390,7 +1375,7 @@ static char holdbuf[LINE]; /* place to hold last edit buffer */
static int holdlen; /* length of holdbuf */ static int holdlen; /* length of holdbuf */
static void static void
save_cbuf() save_cbuf(void)
{ {
memmove(holdbuf, es->cbuf, es->linelen); memmove(holdbuf, es->cbuf, es->linelen);
holdlen = es->linelen; holdlen = es->linelen;
@ -1398,7 +1383,7 @@ save_cbuf()
} }
static void static void
restore_cbuf() restore_cbuf(void)
{ {
es->cursor = 0; es->cursor = 0;
es->linelen = holdlen; es->linelen = holdlen;
@ -1407,8 +1392,7 @@ restore_cbuf()
/* return a new edstate */ /* return a new edstate */
static struct edstate * static struct edstate *
save_edstate(old) save_edstate(struct edstate *old)
struct edstate *old;
{ {
struct edstate *new; struct edstate *new;
@ -1423,8 +1407,7 @@ save_edstate(old)
} }
static void static void
restore_edstate(new, old) restore_edstate(struct edstate *new, struct edstate *old)
struct edstate *old, *new;
{ {
memcpy(new->cbuf, old->cbuf, old->linelen); memcpy(new->cbuf, old->cbuf, old->linelen);
new->linelen = old->linelen; new->linelen = old->linelen;
@ -1434,8 +1417,7 @@ restore_edstate(new, old)
} }
static void static void
free_edstate(old) free_edstate(struct edstate *old)
struct edstate *old;
{ {
afree(old->cbuf, APERM); afree(old->cbuf, APERM);
afree((char *)old, APERM); afree((char *)old, APERM);
@ -1444,9 +1426,7 @@ free_edstate(old)
static void static void
edit_reset(buf, len) edit_reset(char *buf, size_t len)
char *buf;
size_t len;
{ {
const char *p; const char *p;
@ -1486,18 +1466,13 @@ edit_reset(buf, len)
* this is used for calling x_escape() in complete_word() * this is used for calling x_escape() in complete_word()
*/ */
static int static int
x_vi_putbuf(s, len) x_vi_putbuf(const char *s, size_t len)
const char *s;
size_t len;
{ {
return putbuf(s, len, 0); return putbuf(s, len, 0);
} }
static int static int
putbuf(buf, len, repl) putbuf(const char *buf, int len, int repl)
const char *buf;
int len;
int repl;
{ {
if (len == 0) if (len == 0)
return 0; return 0;
@ -1519,8 +1494,7 @@ putbuf(buf, len, repl)
} }
static void static void
del_range(a, b) del_range(int a, int b)
int a, b;
{ {
if (es->linelen != b) if (es->linelen != b)
memmove(&es->cbuf[a], &es->cbuf[b], es->linelen - b); memmove(&es->cbuf[a], &es->cbuf[b], es->linelen - b);
@ -1528,11 +1502,7 @@ del_range(a, b)
} }
static int static int
findch(ch, cnt, forw, incl) findch(int ch, int cnt, int forw, int incl)
int ch;
int cnt;
int forw;
int incl;
{ {
int ncursor; int ncursor;
@ -1560,8 +1530,7 @@ findch(ch, cnt, forw, incl)
} }
static int static int
forwword(argcnt) forwword(int argcnt)
int argcnt;
{ {
int ncursor; int ncursor;
@ -1583,8 +1552,7 @@ forwword(argcnt)
} }
static int static int
backword(argcnt) backword(int argcnt)
int argcnt;
{ {
int ncursor; int ncursor;
@ -1609,8 +1577,7 @@ backword(argcnt)
} }
static int static int
endword(argcnt) endword(int argcnt)
int argcnt;
{ {
int ncursor; int ncursor;
@ -1636,8 +1603,7 @@ endword(argcnt)
} }
static int static int
Forwword(argcnt) Forwword(int argcnt)
int argcnt;
{ {
int ncursor; int ncursor;
@ -1652,8 +1618,7 @@ Forwword(argcnt)
} }
static int static int
Backword(argcnt) Backword(int argcnt)
int argcnt;
{ {
int ncursor; int ncursor;
@ -1669,8 +1634,7 @@ Backword(argcnt)
} }
static int static int
Endword(argcnt) Endword(int argcnt)
int argcnt;
{ {
int ncursor; int ncursor;
@ -1690,9 +1654,7 @@ Endword(argcnt)
} }
static int static int
grabhist(save, n) grabhist(int save, int n)
int save;
int n;
{ {
char *hptr; char *hptr;
@ -1719,9 +1681,7 @@ grabhist(save, n)
} }
static int static int
grabsearch(save, start, fwd, pat) grabsearch(int save, int start, int fwd, char *pat)
int save, start, fwd;
char *pat;
{ {
char *hptr; char *hptr;
int hist; int hist;
@ -1755,8 +1715,7 @@ grabsearch(save, start, fwd, pat)
} }
static void static void
redraw_line(newline) redraw_line(int newline)
int newline;
{ {
(void) memset(wbuf[win], ' ', wbuf_len); (void) memset(wbuf[win], ' ', wbuf_len);
if (newline) { if (newline) {
@ -1769,8 +1728,7 @@ redraw_line(newline)
} }
static void static void
refresh(leftside) refresh(int leftside)
int leftside;
{ {
if (leftside < 0) if (leftside < 0)
leftside = lastref; leftside = lastref;
@ -1783,7 +1741,7 @@ refresh(leftside)
} }
static int static int
outofwin() outofwin(void)
{ {
int cur, col; int cur, col;
@ -1799,7 +1757,7 @@ outofwin()
} }
static void static void
rewindow() rewindow(void)
{ {
int tcur, tcol; int tcur, tcol;
int holdcur1, holdcol1; int holdcur1, holdcol1;
@ -1823,8 +1781,7 @@ rewindow()
} }
static int static int
newcol(ch, col) newcol(int ch, int col)
int ch, col;
{ {
if (ch == '\t') if (ch == '\t')
return (col | 7) + 1; return (col | 7) + 1;
@ -1832,9 +1789,7 @@ newcol(ch, col)
} }
static void static void
display(wb1, wb2, leftside) display(char *wb1, char *wb2, int leftside)
char *wb1, *wb2;
int leftside;
{ {
unsigned char ch; unsigned char ch;
char *twb1, *twb2, mc; char *twb1, *twb2, mc;
@ -1927,9 +1882,7 @@ display(wb1, wb2, leftside)
} }
static void static void
ed_mov_opt(col, wb) ed_mov_opt(int col, char *wb)
int col;
char *wb;
{ {
if (col < cur_col) { if (col < cur_col) {
if (col + 1 < cur_col - col) { if (col + 1 < cur_col - col) {
@ -1953,8 +1906,7 @@ ed_mov_opt(col, wb)
/* replace word with all expansions (ie, expand word*) */ /* replace word with all expansions (ie, expand word*) */
static int static int
expand_word(command) expand_word(int command)
int command;
{ {
static struct edstate *buf; static struct edstate *buf;
int rval = 0; int rval = 0;
@ -2008,9 +1960,7 @@ expand_word(command)
} }
static int static int
complete_word(command, count) complete_word(int command, int count)
int command;
int count;
{ {
static struct edstate *buf; static struct edstate *buf;
int rval = 0; int rval = 0;
@ -2139,8 +2089,7 @@ print_expansions(struct edstate *e, int command GCC_FUNC_ATTR(unused))
/* How long is char when displayed (not counting tabs) */ /* How long is char when displayed (not counting tabs) */
static int static int
char_len(c) char_len(int c)
int c;
{ {
int len = 1; int len = 1;
@ -2155,8 +2104,7 @@ char_len(c)
/* Similar to x_zotc(emacs.c), but no tab weirdness */ /* Similar to x_zotc(emacs.c), but no tab weirdness */
static void static void
x_vi_zotc(c) x_vi_zotc(int c)
int c;
{ {
if (Flag(FVISHOW8) && (c & 0x80)) { if (Flag(FVISHOW8) && (c & 0x80)) {
x_puts("M-"); x_puts("M-");
@ -2170,14 +2118,13 @@ x_vi_zotc(c)
} }
static void static void
vi_pprompt(full) vi_pprompt(int full)
int full;
{ {
pprompt(prompt + (full ? 0 : prompt_skip), prompt_trunc); pprompt(prompt + (full ? 0 : prompt_skip), prompt_trunc);
} }
static void static void
vi_error() vi_error(void)
{ {
/* Beem out of any macros as soon as an error occurs */ /* Beem out of any macros as soon as an error occurs */
vi_macro_reset(); vi_macro_reset();
@ -2186,7 +2133,7 @@ vi_error()
} }
static void static void
vi_macro_reset() vi_macro_reset(void)
{ {
if (macro.p) { if (macro.p) {
afree(macro.buf, APERM); afree(macro.buf, APERM);