de-register, de-inline, de-__P

This commit is contained in:
tg 2004-10-28 11:11:19 +00:00
parent 7ad780aa98
commit 75e25d6e50
36 changed files with 660 additions and 656 deletions

5
README
View File

@ -1,4 +1,4 @@
$MirBSD: README,v 1.3 2004/05/24 19:55:53 tg Stab $
$MirBSD: README,v 1.4 2004/10/28 11:11:16 tg Exp $
This is the README for mirbsdksh, developed as part of the MirBSD
operating system at The MirOS Project, and produced portably.
@ -143,8 +143,7 @@ Compiling/Installing:
in __start (perhaps our system doesn't have the full svr4
environ?). Try compiling in the bsd43 environ instead (still not
perfect - see BUG-REPORTS file), using gcc - cc has problems with
macro expansions in the argument of a macro (in this case, the ARGS
macro).
macro expansions in the argument of a macro.
* On TitanOS (Stardent/Titan), use 'CC="cc -43" configure ...'.
When configure finishes, edit config.h, undef HAVE_DIRENT_H and
define HAVE_SYS_DIR_H (the dirent.h header file is broken).

View File

@ -1,4 +1,4 @@
/** $MirBSD: c_ksh.c,v 1.7 2004/10/28 11:03:21 tg Exp $ */
/** $MirBSD: c_ksh.c,v 1.8 2004/10/28 11:11:16 tg Exp $ */
/* $OpenBSD: c_ksh.c,v 1.18 2004/02/10 13:03:36 jmc Exp $ */
/*
@ -13,7 +13,7 @@
#include <sys/cygwin.h>
#endif /* __CYGWIN__ */
__RCSID("$MirBSD: c_ksh.c,v 1.7 2004/10/28 11:03:21 tg Exp $");
__RCSID("$MirBSD: c_ksh.c,v 1.8 2004/10/28 11:11:16 tg Exp $");
int
c_cd(wp)
@ -1157,7 +1157,7 @@ struct kill_info {
size_t num_width;
size_t name_width;
};
static char *kill_fmt_entry ARGS((void *arg, int i, char *buf, int buflen));
static char *kill_fmt_entry(void *arg, int i, char *buf, int buflen);
/* format a single kill item */
static char *

10
c_sh.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: c_sh.c,v 1.5 2004/10/28 11:03:22 tg Exp $ */
/** $MirBSD: c_sh.c,v 1.6 2004/10/28 11:11:17 tg Exp $ */
/* $OpenBSD: c_sh.c,v 1.17 2003/03/13 09:03:07 deraadt Exp $ */
/*
@ -10,9 +10,9 @@
#include "ksh_time.h"
#include "ksh_times.h"
__RCSID("$MirBSD: c_sh.c,v 1.5 2004/10/28 11:03:22 tg Exp $");
__RCSID("$MirBSD: c_sh.c,v 1.6 2004/10/28 11:11:17 tg Exp $");
static char *clocktos ARGS((clock_t t));
static char *clocktos(clock_t t);
/* :, false and true */
@ -863,8 +863,8 @@ c_builtin(char **wp GCC_FUNC_ATTR(unused))
return 0;
}
extern int c_test ARGS((char **wp)); /* in c_test.c */
extern int c_ulimit ARGS((char **wp)); /* in c_ulimit.c */
extern int c_test(char **wp); /* in c_test.c */
extern int c_ulimit(char **wp); /* in c_ulimit.c */
/* A leading = means assignments before command are kept;
* a leading * means a POSIX special builtin;

View File

@ -1,4 +1,4 @@
/** $MirBSD: c_test.c,v 1.5 2004/10/28 11:03:22 tg Exp $ */
/** $MirBSD: c_test.c,v 1.6 2004/10/28 11:11:17 tg 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 "c_test.h"
__RCSID("$MirBSD: c_test.c,v 1.5 2004/10/28 11:03:22 tg Exp $");
__RCSID("$MirBSD: c_test.c,v 1.6 2004/10/28 11:11:17 tg Exp $");
/* test(1) accepts the following grammar:
oexpr ::= aexpr | aexpr "-o" oexpr ;
@ -90,17 +90,17 @@ static const struct t_op b_ops [] = {
{"", TO_NONOP }
};
static int test_stat ARGS((const char *path, struct stat *statb));
static int test_eaccess ARGS((const char *path, int mode));
static int test_oexpr ARGS((Test_env *te, int do_eval));
static int test_aexpr ARGS((Test_env *te, int do_eval));
static int test_nexpr ARGS((Test_env *te, int do_eval));
static int test_primary ARGS((Test_env *te, int do_eval));
static int ptest_isa ARGS((Test_env *te, Test_meta meta));
static const char *ptest_getopnd ARGS((Test_env *te, Test_op op, int do_eval));
static int ptest_eval ARGS((Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval));
static void ptest_error ARGS((Test_env *te, int offset, const char *msg));
static int test_stat(const char *path, struct stat *statb);
static int test_eaccess(const char *path, int mode);
static int test_oexpr(Test_env *te, int do_eval);
static int test_aexpr(Test_env *te, int do_eval);
static int test_nexpr(Test_env *te, int do_eval);
static int test_primary(Test_env *te, int do_eval);
static int ptest_isa(Test_env *te, Test_meta meta);
static const char *ptest_getopnd(Test_env *te, Test_op op, int do_eval);
static int ptest_eval(Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval);
static void ptest_error(Test_env *te, int offset, const char *msg);
int
c_test(wp)

View File

@ -1,4 +1,4 @@
/** $MirBSD: c_test.h,v 1.3 2004/09/21 11:57:07 tg Exp $ */
/** $MirBSD: c_test.h,v 1.4 2004/10/28 11:11:17 tg Exp $ */
/* $OpenBSD: c_test.h,v 1.2 2003/10/22 07:40:38 jmc Exp $ */
/* Various types of operations. Keeping things grouped nicely
@ -43,14 +43,14 @@ struct test_env {
XPtrV *av; /* used by dbtestp_* */
} pos;
char **wp_end; /* used by ptest_* */
int (*isa) ARGS((Test_env *te, Test_meta meta));
const char *(*getopnd) ARGS((Test_env *te, Test_op op, int do_eval));
int (*eval) ARGS((Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval));
void (*error) ARGS((Test_env *te, int offset, const char *msg));
int (*isa)(Test_env *te, Test_meta meta);
const char *(*getopnd)(Test_env *te, Test_op op, int do_eval);
int (*eval)(Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval);
void (*error)(Test_env *te, int offset, const char *msg);
};
Test_op test_isop ARGS((Test_env *te, Test_meta meta, const char *s));
int test_eval ARGS((Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval));
int test_parse ARGS((Test_env *te));
Test_op test_isop(Test_env *te, Test_meta meta, const char *s);
int test_eval(Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval);
int test_parse(Test_env *te);

36
edit.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: edit.c,v 1.8 2004/10/28 11:03:22 tg Exp $ */
/** $MirBSD: edit.c,v 1.9 2004/10/28 11:11:17 tg Exp $ */
/* $OpenBSD: edit.c,v 1.18 2003/08/22 18:17:10 fgsch Exp $ */
/*
@ -22,20 +22,20 @@
#include <ctype.h>
#include "ksh_stat.h"
__RCSID("$MirBSD: edit.c,v 1.8 2004/10/28 11:03:22 tg Exp $");
__RCSID("$MirBSD: edit.c,v 1.9 2004/10/28 11:11:17 tg Exp $");
#if defined(TIOCGWINSZ)
static RETSIGTYPE x_sigwinch ARGS((int sig));
static RETSIGTYPE x_sigwinch(int sig);
static int got_sigwinch;
static void check_sigwinch ARGS((void));
static void check_sigwinch(void);
#endif /* TIOCGWINSZ */
static int x_file_glob ARGS((int flags, const char *str, int slen,
char ***wordsp));
static int x_command_glob ARGS((int flags, const char *str, int slen,
char ***wordsp));
static int x_locate_word ARGS((const char *buf, int buflen, int pos,
int *startp, int *is_command));
static int x_file_glob(int flags, const char *str, int slen,
char ***wordsp);
static int x_command_glob(int flags, const char *str, int slen,
char ***wordsp);
static int x_locate_word(const char *buf, int buflen, int pos,
int *startp, int *is_command);
static char vdisable_c;
@ -90,7 +90,7 @@ x_sigwinch(int sig GCC_FUNC_ATTR(unused))
}
static void
check_sigwinch ARGS((void))
check_sigwinch(void)
{
if (got_sigwinch) {
struct winsize ws;
@ -455,14 +455,14 @@ x_do_comment(buf, bsize, lenp)
/* Common file/command completion code for vi/emacs */
static char *add_glob ARGS((const char *str, int slen));
static void glob_table ARGS((const char *pat, XPtrV *wp, struct table *tp));
static void glob_path ARGS((int flags, const char *pat, XPtrV *wp,
const char *path));
static char *add_glob(const char *str, int slen);
static void glob_table(const char *pat, XPtrV *wp, struct table *tp);
static void glob_path(int flags, const char *pat, XPtrV *wp,
const char *path);
#if 0 /* not used... */
int x_complete_word ARGS((const char *str, int slen, int is_command,
int *multiple, char **ret));
int x_complete_word(const char *str, int slen, int is_command,
int *multiple, char **ret);
int
x_complete_word(str, slen, is_command, nwordsp, ret)
const char *str;
@ -1051,7 +1051,7 @@ int
x_escape(s, len, putbuf_func)
const char *s;
size_t len;
int putbuf_func ARGS((const char *s, size_t len));
int putbuf_func(const char *s, size_t len);
{
size_t add, wlen;
const char *ifs = str_val(local("IFS", 0));

38
edit.h
View File

@ -1,4 +1,4 @@
/** $MirBSD: edit.h,v 1.3 2004/09/21 11:57:08 tg Exp $ */
/** $MirBSD: edit.h,v 1.4 2004/10/28 11:11:17 tg 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 $ */
@ -32,26 +32,26 @@ EXTERN X_chars edchars;
#define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE)
/* edit.c */
int x_getc ARGS((void));
void x_flush ARGS((void));
void x_putc ARGS((int c));
void x_puts ARGS((const char *s));
bool_t x_mode ARGS((bool_t onoff));
int promptlen ARGS((const char *cp, const char **spp));
int x_do_comment ARGS((char *buf, int bsize, int *lenp));
void x_print_expansions ARGS((int nwords, char *const *words, int is_command));
int x_cf_glob ARGS((int flags, const char *buf, int buflen, int pos, int *startp,
int *endp, char ***wordsp, int *is_commandp));
int x_longest_prefix ARGS((int nwords, char *const *words));
int x_basename ARGS((const char *s, const char *se));
void x_free_words ARGS((int nwords, char **words));
int x_escape ARGS((const char *, size_t, int (*)(const char *s, size_t len)));
int x_getc(void);
void x_flush(void);
void x_putc(int c);
void x_puts(const char *s);
bool_t x_mode(bool_t onoff);
int promptlen(const char *cp, const char **spp);
int x_do_comment(char *buf, int bsize, int *lenp);
void x_print_expansions(int nwords, char *const *words, int is_command);
int x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp,
int *endp, char ***wordsp, int *is_commandp);
int x_longest_prefix(int nwords, char *const *words);
int x_basename(const char *s, const char *se);
void x_free_words(int nwords, char **words);
int x_escape(const char *, size_t, int (*)(const char *s, size_t len));
/* emacs.c */
int x_emacs ARGS((char *buf, size_t len));
void x_init_emacs ARGS((void));
void x_emacs_keys ARGS((X_chars *ec));
int x_emacs(char *buf, size_t len);
void x_init_emacs(void);
void x_emacs_keys(X_chars *ec);
/* vi.c */
int x_vi ARGS((char *buf, size_t len));
int x_vi(char *buf, size_t len);
#ifdef DEBUG

View File

@ -1,5 +1,5 @@
#!/bin/sh
# $MirBSD: emacs-gen.sh,v 1.2 2004/05/24 19:56:05 tg Stab $
# $MirBSD: emacs-gen.sh,v 1.3 2004/10/28 11:11:17 tg Exp $
# $OpenBSD: emacs-gen.sh,v 1.1.1.1 1996/08/14 06:19:10 downsj Exp $
case $# in
@ -37,7 +37,7 @@ sed -e '1,/@START-FUNC-TAB@/d' -e '/@END-FUNC-TAB@/,$d' < $file |
fname = substr(fname, 1, length(fname) - 1);
if (fname != "0") {
printf "#define XFUNC_%s %d\n", substr(fname, 3, length(fname) - 2), nfunc;
printf "static int %s ARGS((int c));\n", fname;
printf "static int %s(int c);\n", fname;
nfunc++;
}
}' || exit 1

63
emacs.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: emacs.c,v 1.10 2004/10/28 11:03:22 tg Exp $ */
/** $MirBSD: emacs.c,v 1.11 2004/10/28 11:11:17 tg Exp $ */
/* $OpenBSD: emacs.c,v 1.28 2003/10/22 07:40:38 jmc Exp $ */
/*
@ -19,7 +19,7 @@
#include <locale.h>
#include "edit.h"
__RCSID("$MirBSD: emacs.c,v 1.10 2004/10/28 11:03:22 tg Exp $");
__RCSID("$MirBSD: emacs.c,v 1.11 2004/10/28 11:11:17 tg Exp $");
static Area aedit;
#define AEDIT &aedit /* area for kill ring and macro defns */
@ -37,7 +37,7 @@ static Area aedit;
#define KINTR 2 /* ^G, ^C */
struct x_ftab {
int (*xf_func) ARGS((int c));
int (*xf_func)(int c);
const char *xf_name;
short xf_flags;
};
@ -123,34 +123,34 @@ static int x_curprefix;
static char *macroptr;
static int prompt_skip;
static int x_ins ARGS((char *cp));
static void x_delete ARGS((int nc, int push));
static int x_bword ARGS((void));
static int x_fword ARGS((void));
static void x_goto ARGS((char *cp));
static void x_bs ARGS((int c));
static int x_size_str ARGS((char *cp));
static int x_size ARGS((int c));
static void x_zots ARGS((char *str));
static void x_zotc ARGS((int c));
static void x_load_hist ARGS((char **hp));
static int x_search ARGS((char *pat, int sameline, int offset));
static int x_match ARGS((char *str, char *pat));
static void x_redraw ARGS((int limit));
static void x_push ARGS((int nchars));
static char * x_mapin ARGS((const char *cp));
static char * x_mapout ARGS((int c));
static void x_print ARGS((int prefix, int key));
static void x_adjust ARGS((void));
static void x_e_ungetc ARGS((int c));
static int x_e_getc ARGS((void));
static void x_e_putc ARGS((int c));
static void x_e_puts ARGS((const char *s));
static int x_comment ARGS((int c));
static int x_fold_case ARGS((int c));
static char *x_lastcp ARGS((void));
static void do_complete ARGS((int flags, Comp_type type));
static int x_emacs_putbuf ARGS((const char *s, size_t len));
static int x_ins(char *cp);
static void x_delete(int nc, int push);
static int x_bword(void);
static int x_fword(void);
static void x_goto(char *cp);
static void x_bs(int c);
static int x_size_str(char *cp);
static int x_size(int c);
static void x_zots(char *str);
static void x_zotc(int c);
static void x_load_hist(char **hp);
static int x_search(char *pat, int sameline, int offset);
static int x_match(char *str, char *pat);
static void x_redraw(int limit);
static void x_push(int nchars);
static char * x_mapin(const char *cp);
static char * x_mapout(int c);
static void x_print(int prefix, int key);
static void x_adjust(void);
static void x_e_ungetc(int c);
static int x_e_getc(void);
static void x_e_putc(int c);
static void x_e_puts(const char *s);
static int x_comment(int c);
static int x_fold_case(int c);
static char *x_lastcp(void);
static void do_complete(int flags, Comp_type type);
static int x_emacs_putbuf(const char *s, size_t len);
/* The lines between START-FUNC-TAB .. END-FUNC-TAB are run through a
@ -2167,5 +2167,4 @@ x_lastcp()
xlp_valid = TRUE;
return (xlp);
}
#endif /* EDIT */

30
eval.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: eval.c,v 1.4 2004/10/28 11:03:22 tg Exp $ */
/** $MirBSD: eval.c,v 1.5 2004/10/28 11:11:17 tg 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_stat.h"
__RCSID("$MirBSD: eval.c,v 1.4 2004/10/28 11:03:22 tg Exp $");
__RCSID("$MirBSD: eval.c,v 1.5 2004/10/28 11:11:17 tg Exp $");
/*
* string expansion
@ -43,19 +43,19 @@ typedef struct Expand {
#define IFS_WS 1 /* have seen IFS white-space */
#define IFS_NWS 2 /* have seen IFS non-white-space */
static int varsub ARGS((Expand *xp, char *sp, char *word, int *stypep, int *slenp));
static int comsub ARGS((Expand *xp, char *cp));
static char *trimsub ARGS((char *str, char *pat, int how));
static void glob ARGS((char *cp, XPtrV *wp, int markdirs));
static void globit ARGS((XString *xs, char **xpp, char *sp, XPtrV *wp,
int check));
static char *maybe_expand_tilde ARGS((char *p, XString *dsp, char **dpp,
int isassign));
static char *tilde ARGS((char *acp));
static char *homedir ARGS((char *name));
static int varsub(Expand *xp, char *sp, char *word, int *stypep, int *slenp);
static int comsub(Expand *xp, char *cp);
static char *trimsub(char *str, char *pat, int how);
static void glob(char *cp, XPtrV *wp, int markdirs);
static void globit(XString *xs, char **xpp, char *sp, XPtrV *wp,
int check);
static char *maybe_expand_tilde(char *p, XString *dsp, char **dpp,
int isassign);
static char *tilde(char *acp);
static char *homedir(char *name);
#ifdef BRACE_EXPAND
static void alt_expand ARGS((XPtrV *wp, char *start, char *exp_start,
char *end, int fdo));
static void alt_expand(XPtrV *wp, char *start, char *exp_start,
char *end, int fdo);
#endif
/* compile and expand word */
@ -1139,7 +1139,7 @@ globit(xs, xpp, sp, wp, check)
/* Check if p contains something that needs globbing; if it does, 0 is
* returned; if not, p is copied into xs/xp after stripping any MAGICs
*/
static int copy_non_glob ARGS((XString *xs, char **xpp, char *p));
static int copy_non_glob(XString *xs, char **xpp, char *p);
static int
copy_non_glob(xs, xpp, p)
XString *xs;

38
exec.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: exec.c,v 1.4 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: exec.c,v 1.5 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: exec.c,v 1.31 2003/12/15 05:25:52 otto Exp $ */
/*
@ -10,6 +10,8 @@
#include <ctype.h>
#include "ksh_stat.h"
__RCSID("$MirBSD: exec.c,v 1.5 2004/10/28 11:11:18 tg Exp $");
/* Does ps4 get parameter substitutions done? */
#ifdef KSH
# define PS4_SUBSTITUTE(s) substitute((s), 0)
@ -17,25 +19,25 @@
# define PS4_SUBSTITUTE(s) (s)
#endif /* KSH */
static int comexec ARGS((struct op *t, struct tbl *volatile tp, char **ap,
int volatile flags));
static void scriptexec ARGS((struct op *tp, char **ap));
static int call_builtin ARGS((struct tbl *tp, char **wp));
static int iosetup ARGS((struct ioword *iop, struct tbl *tp));
static int herein ARGS((const char *content, int sub));
static int comexec(struct op *t, struct tbl *volatile tp, char **ap,
int volatile flags);
static void scriptexec(struct op *tp, char **ap);
static int call_builtin(struct tbl *tp, char **wp);
static int iosetup(struct ioword *iop, struct tbl *tp);
static int herein(const char *content, int sub);
#ifdef KSH
static char *do_selectargs ARGS((char **ap, bool_t print_menu));
static char *do_selectargs(char **ap, bool_t print_menu);
#endif /* KSH */
#ifdef KSH
static int dbteste_isa ARGS((Test_env *te, Test_meta meta));
static const char *dbteste_getopnd ARGS((Test_env *te, Test_op op,
int do_eval));
static int dbteste_eval ARGS((Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval));
static void dbteste_error ARGS((Test_env *te, int offset, const char *msg));
static int dbteste_isa(Test_env *te, Test_meta meta);
static const char *dbteste_getopnd(Test_env *te, Test_op op,
int do_eval);
static int dbteste_eval(Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval);
static void dbteste_error(Test_env *te, int offset, const char *msg);
#endif /* KSH */
#ifdef OS2
static int search_access1 ARGS((const char *path, int mode, int *errnop));
static int search_access1(const char *path, int mode, int *errnop);
#endif /* OS2 */
@ -957,7 +959,7 @@ define(name, t)
void
builtin(name, func)
const char *name;
int (*func) ARGS((char **));
int (*func)(char **);
{
struct tbl *tp;
Tflag flag;
@ -1545,7 +1547,7 @@ struct select_menu_info {
int num_width;
} info;
static char *select_fmt_entry ARGS((void *arg, int i, char *buf, int buflen));
static char *select_fmt_entry(void *arg, int i, char *buf, int buflen);
/* format a single select menu item */
static char *
@ -1607,7 +1609,7 @@ pr_menu(ap)
/* XXX: horrible kludge to fit within the framework */
static char *plain_fmt_entry ARGS((void *arg, int i, char *buf, int buflen));
static char *plain_fmt_entry(void *arg, int i, char *buf, int buflen);
static char *
plain_fmt_entry(arg, i, buf, buflen)

View File

@ -1,4 +1,4 @@
/** $MirBSD: expand.h,v 1.4 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: expand.h,v 1.5 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: expand.h,v 1.3 2001/03/26 16:19:45 todd Exp $ */
/*
@ -70,7 +70,7 @@ typedef char * XStringP;
#define Xsavepos(xs, xp) ((xp) - (xs).beg)
#define Xrestpos(xs, xp, n) ((xs).beg + (n))
char * Xcheck_grow_ ARGS((XString *xsp, char *xp, size_t more));
char * Xcheck_grow_(XString *xsp, char *xp, size_t more);
/*
* expandable vector of generic pointers

23
expr.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: expr.c,v 1.5 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: expr.c,v 1.6 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: expr.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */
/*
@ -8,6 +8,7 @@
#include "sh.h"
#include <ctype.h>
__RCSID("$MirBSD: expr.c,v 1.6 2004/10/28 11:11:18 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */
enum token {
@ -126,16 +127,16 @@ struct expr_state {
enum error_type { ET_UNEXPECTED, ET_BADLIT, ET_RECURSIVE,
ET_LVALUE, ET_RDONLY, ET_STR };
static void evalerr ARGS((Expr_state *es, enum error_type type,
const char *str)) GCC_FUNC_ATTR(noreturn);
static struct tbl *evalexpr ARGS((Expr_state *es, enum prec prec));
static void token ARGS((Expr_state *es));
static struct tbl *do_ppmm ARGS((Expr_state *es, enum token op,
struct tbl *vasn, bool_t is_prefix));
static void assign_check ARGS((Expr_state *es, enum token op,
struct tbl *vasn));
static struct tbl *tempvar ARGS((void));
static struct tbl *intvar ARGS((Expr_state *es, struct tbl *vp));
static void evalerr(Expr_state *es, enum error_type type,
const char *str) GCC_FUNC_ATTR(noreturn);
static struct tbl *evalexpr(Expr_state *es, enum prec prec);
static void token(Expr_state *es);
static struct tbl *do_ppmm(Expr_state *es, enum token op,
struct tbl *vasn, bool_t is_prefix);
static void assign_check(Expr_state *es, enum token op,
struct tbl *vasn);
static struct tbl *tempvar(void);
static struct tbl *intvar(Expr_state *es, struct tbl *vp);
/*
* parse and evaluate expression

View File

@ -1,4 +1,4 @@
/** $MirBSD: history.c,v 1.12 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: history.c,v 1.13 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: history.c,v 1.24 2004/08/03 12:44:59 danh Exp $ */
/*
@ -21,6 +21,8 @@
#include "sh.h"
#include "ksh_stat.h"
__RCSID("$MirBSD: history.c,v 1.13 2004/10/28 11:11:18 tg Exp $");
#ifdef HISTORY
# ifdef EASY_HISTORY
@ -44,13 +46,13 @@
static int histfd;
static int hsize;
static int hist_count_lines ARGS((unsigned char *, int));
static int hist_shrink ARGS((unsigned char *, int));
static unsigned char *hist_skip_back ARGS((unsigned char *,int *,int));
static void histload ARGS((Source *, unsigned char *, int));
static void histinsert ARGS((Source *, int, unsigned char *));
static void writehistfile ARGS((int, char *));
static int sprinkle ARGS((int));
static int hist_count_lines(unsigned char *, int);
static int hist_shrink(unsigned char *, int);
static unsigned char *hist_skip_back(unsigned char *,int *,int);
static void histload(Source *, unsigned char *, int);
static void histinsert(Source *, int, unsigned char *);
static void writehistfile(int, char *);
static int sprinkle(int);
# ifdef MAP_FILE
# define MAP_FLAGS (MAP_FILE|MAP_PRIVATE)
@ -60,13 +62,13 @@ static int sprinkle ARGS((int));
# endif /* of EASY_HISTORY */
static int hist_execute ARGS((char *cmd));
static int hist_replace ARGS((char **hp, const char *pat, const char *rep,
int global));
static char **hist_get ARGS((const char *str, int approx, int allow_cur));
static char **hist_get_newest ARGS((int allow_cur));
static char **hist_get_oldest ARGS((void));
static void histbackup ARGS((void));
static int hist_execute(char *cmd);
static int hist_replace(char **hp, const char *pat, const char *rep,
int global);
static char **hist_get(const char *str, int approx, int allow_cur);
static char **hist_get_newest(int allow_cur);
static char **hist_get_oldest(void);
static void histbackup(void);
static char **current; /* current position in history[] */
static int curpos; /* current index in history[] */

32
jobs.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: jobs.c,v 1.6 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: jobs.c,v 1.7 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: jobs.c,v 1.21 2003/11/10 21:26:39 millert Exp $ */
/*
@ -31,7 +31,7 @@
#include "ksh_times.h"
#include "tty.h"
__RCSID("$MirBSD: jobs.c,v 1.6 2004/10/28 11:03:23 tg Exp $");
__RCSID("$MirBSD: jobs.c,v 1.7 2004/10/28 11:11:18 tg Exp $");
/* Start of system configuration stuff */
@ -59,8 +59,8 @@ __RCSID("$MirBSD: jobs.c,v 1.6 2004/10/28 11:03:23 tg Exp $");
# define getpgID() getpgrp()
# endif
# if defined(TTY_PGRP) && !defined(HAVE_TCSETPGRP)
int tcsetpgrp ARGS((int fd, pid_t grp));
int tcgetpgrp ARGS((int fd));
int tcsetpgrp(int fd, pid_t grp);
int tcgetpgrp(int fd);
int
tcsetpgrp(fd, grp)
@ -213,18 +213,18 @@ static pid_t our_pgrp;
static int const tt_sigs[] = { SIGTSTP, SIGTTIN, SIGTTOU };
#endif /* TTY_PGRP */
static void j_set_async ARGS((Job *j));
static void j_startjob ARGS((Job *j));
static int j_waitj ARGS((Job *j, int flags, const char *where));
static RETSIGTYPE j_sigchld ARGS((int sig));
static void j_print ARGS((Job *j, int how, struct shf *shf));
static Job *j_lookup ARGS((const char *cp, int *ecodep));
static Job *new_job ARGS((void));
static Proc *new_proc ARGS((void));
static void check_job ARGS((Job *j));
static void put_job ARGS((Job *j, int where));
static void remove_job ARGS((Job *j, const char *where));
static int kill_job ARGS((Job *j, int sig));
static void j_set_async(Job *j);
static void j_startjob(Job *j);
static int j_waitj(Job *j, int flags, const char *where);
static RETSIGTYPE j_sigchld(int sig);
static void j_print(Job *j, int how, struct shf *shf);
static Job *j_lookup(const char *cp, int *ecodep);
static Job *new_job(void);
static Proc *new_proc(void);
static void check_job(Job *j);
static void put_job(Job *j, int where);
static void remove_job(Job *j, const char *where);
static int kill_job(Job *j, int sig);
/* initialize job control */
void

View File

@ -1,4 +1,4 @@
/** $MirBSD: ksh_dir.h,v 1.3 2004/09/21 11:57:10 tg Exp $ */
/** $MirBSD: ksh_dir.h,v 1.4 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: ksh_dir.h,v 1.1.1.1 1996/08/14 06:19:11 downsj Exp $ */
/* Wrapper around the ugly dir includes/ifdefs */
@ -21,7 +21,7 @@
#endif /* HAVE_DIRENT_H */
#ifdef OPENDIR_DOES_NONDIR
extern DIR *ksh_opendir ARGS((const char *d));
extern DIR *ksh_opendir(const char *d);
#else /* OPENDIR_DOES_NONDIR */
# define ksh_opendir(d) opendir(d)
#endif /* OPENDIR_DOES_NONDIR */

View File

@ -1,4 +1,4 @@
/** $MirBSD: ksh_time.h,v 1.3 2004/09/21 11:57:11 tg Exp $ */
/** $MirBSD: ksh_time.h,v 1.4 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: ksh_time.h,v 1.2 1996/10/01 02:05:40 downsj Exp $ */
#ifndef KSH_TIME_H
@ -18,7 +18,7 @@
#endif /* TIME_WITH_SYS_TIME */
#ifndef TIME_DECLARED
extern time_t time ARGS((time_t *));
extern time_t time(time_t *);
#endif
#ifndef CLK_TCK

View File

@ -1,4 +1,4 @@
/** $MirBSD: ksh_times.h,v 1.3 2004/09/21 11:57:12 tg Exp $ */
/** $MirBSD: ksh_times.h,v 1.4 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: ksh_times.h,v 1.2 1996/10/01 02:05:41 downsj Exp $ */
#ifndef KSH_TIMES_H
@ -10,12 +10,12 @@
#include <sys/times.h>
#ifdef TIMES_BROKEN
extern clock_t ksh_times ARGS((struct tms *));
extern clock_t ksh_times(struct tms *);
#else /* TIMES_BROKEN */
# define ksh_times times
#endif /* TIMES_BROKEN */
#ifdef HAVE_TIMES
extern clock_t times ARGS((struct tms *));
extern clock_t times(struct tms *);
#endif /* HAVE_TIMES */
#endif /* KSH_TIMES_H */

25
lex.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: lex.c,v 1.5 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: lex.c,v 1.6 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: lex.c,v 1.18 2003/08/06 21:08:05 millert Exp $ */
/*
@ -8,6 +8,7 @@
#include "sh.h"
#include <ctype.h>
__RCSID("$MirBSD: lex.c,v 1.6 2004/10/28 11:11:18 tg Exp $");
/* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state.
@ -53,16 +54,16 @@ struct State_info {
};
static void readhere ARGS((struct ioword *iop));
static int getsc__ ARGS((void));
static void getsc_line ARGS((Source *s));
static int getsc_bn ARGS((void));
static char *get_brace_var ARGS((XString *wsp, char *wp));
static int arraysub ARGS((char **strp));
static const char *ungetsc ARGS((int c));
static void gethere ARGS((void));
static Lex_state *push_state_ ARGS((State_info *si, Lex_state *old_end));
static Lex_state *pop_state_ ARGS((State_info *si, Lex_state *old_end));
static void readhere(struct ioword *iop);
static int getsc__(void);
static void getsc_line(Source *s);
static int getsc_bn(void);
static char *get_brace_var(XString *wsp, char *wp);
static int arraysub(char **strp);
static const char *ungetsc(int c);
static void gethere(void);
static Lex_state *push_state_(State_info *si, Lex_state *old_end);
static Lex_state *pop_state_(State_info *si, Lex_state *old_end);
static int backslash_skip;
static int ignore_backslash_newline;
@ -1343,7 +1344,7 @@ ungetsc(c)
/* Called to get a char that isn't a \newline sequence. */
static int
getsc_bn ARGS((void))
getsc_bn(void)
{
int c, c2;

10
mail.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: mail.c,v 1.4 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: mail.c,v 1.5 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: mail.c,v 1.9 1999/06/15 01:18:35 millert Exp $ */
/*
@ -13,6 +13,8 @@
#include "ksh_stat.h"
#include "ksh_time.h"
__RCSID("$MirBSD: mail.c,v 1.5 2004/10/28 11:11:18 tg Exp $");
#define MBMESSAGE "you have mail in $_"
typedef struct mbox {
@ -33,9 +35,9 @@ static mbox_t mbox;
static time_t mlastchkd; /* when mail was last checked */
static time_t mailcheck_interval;
static void munset ARGS((mbox_t *mlist)); /* free mlist and mval */
static mbox_t * mballoc ARGS((char *p, char *m)); /* allocate a new mbox */
static void mprintit ARGS((mbox_t *mbp));
static void munset(mbox_t *mlist); /* free mlist and mval */
static mbox_t * mballoc(char *p, char *m); /* allocate a new mbox */
static void mprintit(mbox_t *mbp);
void
mcheck()

10
main.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: main.c,v 1.10 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: main.c,v 1.11 2004/10/28 11:11:18 tg 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_time.h"
__RCSID("$MirBSD: main.c,v 1.10 2004/10/28 11:03:23 tg Exp $");
__RCSID("$MirBSD: main.c,v 1.11 2004/10/28 11:11:18 tg Exp $");
extern char **environ;
@ -19,9 +19,9 @@ extern char **environ;
* global data
*/
static void reclaim ARGS((void));
static void remove_temps ARGS((struct temp *tp));
static int is_restricted ARGS((char *name));
static void reclaim(void);
static void remove_temps(struct temp *tp);
static int is_restricted(char *name);
/*
* shell initialization

24
misc.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: misc.c,v 1.10 2004/10/28 11:03:23 tg Exp $ */
/** $MirBSD: misc.c,v 1.11 2004/10/28 11:11:18 tg Exp $ */
/* $OpenBSD: misc.c,v 1.20 2003/10/22 07:40:38 jmc Exp $ */
/*
@ -11,7 +11,7 @@
# include <limits.h>
#endif
__RCSID("$MirBSD: misc.c,v 1.10 2004/10/28 11:03:23 tg Exp $");
__RCSID("$MirBSD: misc.c,v 1.11 2004/10/28 11:11:18 tg Exp $");
#ifndef UCHAR_MAX
# define UCHAR_MAX 0xFF
@ -19,10 +19,10 @@ __RCSID("$MirBSD: misc.c,v 1.10 2004/10/28 11:03:23 tg Exp $");
short ctypes [UCHAR_MAX+1]; /* type bits for unsigned char */
static int do_gmatch ARGS((const unsigned char *s, const unsigned char *p,
static int do_gmatch(const unsigned char *s, const unsigned char *p,
const unsigned char *se, const unsigned char *pe,
int isfile));
static const unsigned char *cclass ARGS((const unsigned char *p, int sub));
int isfile);
static const unsigned char *cclass(const unsigned char *p, int sub);
/*
* Fast character classes
@ -215,8 +215,8 @@ struct options_info {
} opts[NELEM(options)];
};
static char *options_fmt_entry ARGS((void *arg, int i, char *buf, int buflen));
static void printoptions ARGS((int verbose));
static char *options_fmt_entry(void *arg, int i, char *buf, int buflen);
static void printoptions(int verbose);
/* format a single select menu item */
static char *
@ -832,13 +832,13 @@ pat_scan(p, pe, match_sep)
/*
* quick sort of array of generic pointers to objects.
*/
static void qsort1 ARGS((void **base, void **lim, int (*f)(void *, void *)));
static void qsort1(void **base, void **lim, int (*f)(void *, void *));
void
qsortp(base, n, f)
void **base; /* base address */
size_t n; /* elements */
int (*f) ARGS((void *, void *)); /* compare function */
int (*f)(void *, void *); /* compare function */
{
qsort1(base, base + n, f);
}
@ -853,7 +853,7 @@ qsortp(base, n, f)
static void
qsort1(base, lim, f)
void **base, **lim;
int (*f) ARGS((void *, void *));
int (*f)(void *, void *);
{
void **i, **j;
void **lptr, **hptr;
@ -1108,7 +1108,7 @@ void
print_columns(shf, n, func, arg, max_width, prefcol)
struct shf *shf;
int n;
char *(*func) ARGS((void *, int, char *, int));
char *(*func)(void *, int, char *, int);
void *arg;
int max_width;
int prefcol;
@ -1325,7 +1325,7 @@ ksh_get_wd(buf, bsize)
return ret;
#else /* HAVE_GETCWD */
extern char *getwd ARGS((char *));
extern char *getwd(char *);
char *b;
int len;

6
path.c
View File

@ -1,10 +1,10 @@
/** $MirBSD: path.c,v 1.5 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: path.c,v 1.6 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: path.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */
#include "sh.h"
#include "ksh_stat.h"
__RCSID("$MirBSD: path.c,v 1.5 2004/10/28 11:03:24 tg Exp $");
__RCSID("$MirBSD: path.c,v 1.6 2004/10/28 11:11:19 tg Exp $");
/*
* Contains a routine to search a : separated list of
@ -16,7 +16,7 @@ __RCSID("$MirBSD: path.c,v 1.5 2004/10/28 11:03:24 tg Exp $");
*/
#ifdef S_ISLNK
static char *do_phys_path ARGS((XString *xsp, char *xp, const char *path));
static char *do_phys_path(XString *xsp, char *xp, const char *path);
#endif /* S_ISLNK */
/*

490
proto.h
View File

@ -1,4 +1,4 @@
/** $MirBSD: proto.h,v 1.6 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: proto.h,v 1.7 2004/10/28 11:11:19 tg 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 $ */
@ -8,300 +8,300 @@
*/
/* alloc.c */
Area * ainit ARGS((Area *ap));
void afreeall ARGS((Area *ap));
void * alloc ARGS((size_t size, Area *ap));
void * aresize ARGS((void *ptr, size_t size, Area *ap));
void afree ARGS((void *ptr, Area *ap));
Area * ainit(Area *ap);
void afreeall(Area *ap);
void * alloc(size_t size, Area *ap);
void * aresize(void *ptr, size_t size, Area *ap);
void afree(void *ptr, Area *ap);
/* c_ksh.c */
int c_hash ARGS((char **wp));
int c_cd ARGS((char **wp));
int c_pwd ARGS((char **wp));
int c_print ARGS((char **wp));
int c_whence ARGS((char **wp));
int c_command ARGS((char **wp));
int c_typeset ARGS((char **wp));
int c_alias ARGS((char **wp));
int c_unalias ARGS((char **wp));
int c_let ARGS((char **wp));
int c_jobs ARGS((char **wp));
int c_fgbg ARGS((char **wp));
int c_kill ARGS((char **wp));
void getopts_reset ARGS((int val));
int c_getopts ARGS((char **wp));
int c_bind ARGS((char **wp));
int c_hash(char **wp);
int c_cd(char **wp);
int c_pwd(char **wp);
int c_print(char **wp);
int c_whence(char **wp);
int c_command(char **wp);
int c_typeset(char **wp);
int c_alias(char **wp);
int c_unalias(char **wp);
int c_let(char **wp);
int c_jobs(char **wp);
int c_fgbg(char **wp);
int c_kill(char **wp);
void getopts_reset(int val);
int c_getopts(char **wp);
int c_bind(char **wp);
/* c_sh.c */
int c_label ARGS((char **wp));
int c_shift ARGS((char **wp));
int c_umask ARGS((char **wp));
int c_dot ARGS((char **wp));
int c_wait ARGS((char **wp));
int c_read ARGS((char **wp));
int c_eval ARGS((char **wp));
int c_trap ARGS((char **wp));
int c_brkcont ARGS((char **wp));
int c_exitreturn ARGS((char **wp));
int c_set ARGS((char **wp));
int c_unset ARGS((char **wp));
int c_ulimit ARGS((char **wp));
int c_times ARGS((char **wp));
int timex ARGS((struct op *t, int f));
void timex_hook ARGS((struct op *t, char ** volatile *app));
int c_exec ARGS((char **wp));
int c_builtin ARGS((char **wp));
int c_label(char **wp);
int c_shift(char **wp);
int c_umask(char **wp);
int c_dot(char **wp);
int c_wait(char **wp);
int c_read(char **wp);
int c_eval(char **wp);
int c_trap(char **wp);
int c_brkcont(char **wp);
int c_exitreturn(char **wp);
int c_set(char **wp);
int c_unset(char **wp);
int c_ulimit(char **wp);
int c_times(char **wp);
int timex(struct op *t, int f);
void timex_hook(struct op *t, char ** volatile *app);
int c_exec(char **wp);
int c_builtin(char **wp);
/* c_test.c */
int c_test ARGS((char **wp));
int c_test(char **wp);
/* edit.c: most prototypes in edit.h */
void x_init ARGS((void));
int x_read ARGS((char *buf, size_t len));
void set_editmode ARGS((const char *ed));
void x_init(void);
int x_read(char *buf, size_t len);
void set_editmode(const char *ed);
/* emacs.c: most prototypes in edit.h */
int x_bind ARGS((const char *a1, const char *a2, int macro,
int list));
int x_bind(const char *a1, const char *a2, int macro,
int list);
/* eval.c */
char * substitute ARGS((const char *cp, int f));
char ** eval ARGS((char **ap, int f));
char * evalstr ARGS((char *cp, int f));
char * evalonestr ARGS((char *cp, int f));
char *debunk ARGS((char *dp, const char *sp, size_t dlen));
void expand ARGS((char *cp, XPtrV *wp, int f));
int glob_str ARGS((char *cp, XPtrV *wp, int markdirs));
char * substitute(const char *cp, int f);
char ** eval(char **ap, int f);
char * evalstr(char *cp, int f);
char * evalonestr(char *cp, int f);
char *debunk(char *dp, const char *sp, size_t dlen);
void expand(char *cp, XPtrV *wp, int f);
int glob_str(char *cp, XPtrV *wp, int markdirs);
/* exec.c */
int fd_clexec ARGS((int fd));
int execute ARGS((struct op * volatile t, volatile int flags));
int shcomexec ARGS((char **wp));
struct tbl * findfunc ARGS((const char *name, unsigned int h, int create));
int define ARGS((const char *name, struct op *t));
void builtin ARGS((const char *name, int (*func)(char **)));
struct tbl * findcom ARGS((const char *name, int flags));
void flushcom ARGS((int all));
char * search ARGS((const char *name, const char *path, int mode,
int *errnop));
int search_access ARGS((const char *path, int mode, int *errnop));
int pr_menu ARGS((char *const *ap));
int pr_list ARGS((char *const *ap));
int fd_clexec(int fd);
int execute(struct op * volatile t, volatile int flags);
int shcomexec(char **wp);
struct tbl * findfunc(const char *name, unsigned int h, int create);
int define(const char *name, struct op *t);
void builtin(const char *name, int (*func)(char **));
struct tbl * findcom(const char *name, int flags);
void flushcom(int all);
char * search(const char *name, const char *path, int mode,
int *errnop);
int search_access(const char *path, int mode, int *errnop);
int pr_menu(char *const *ap);
int pr_list(char *const *ap);
/* expr.c */
int evaluate ARGS((const char *expr, long *rval, int error_ok));
int v_evaluate ARGS((struct tbl *vp, const char *expr, volatile int error_ok));
int evaluate(const char *expr, long *rval, int error_ok);
int v_evaluate(struct tbl *vp, const char *expr, volatile int error_ok);
/* history.c */
void init_histvec ARGS((void));
void hist_init ARGS((Source *s));
void hist_finish ARGS((void));
void histsave ARGS((int lno, const char *cmd, int dowrite));
void init_histvec(void);
void hist_init(Source *s);
void hist_finish(void);
void histsave(int lno, const char *cmd, int dowrite);
#ifdef HISTORY
int c_fc ARGS((char **wp));
void sethistsize ARGS((int n));
void sethistfile ARGS((const char *name));
int c_fc(char **wp);
void sethistsize(int n);
void sethistfile(const char *name);
# ifdef EASY_HISTORY
void histappend ARGS((const char *cmd, int nl_separate));
void histappend(const char *cmd, int nl_separate);
# endif
char ** histpos ARGS((void));
int histN ARGS((void));
int histnum ARGS((int n));
int findhist ARGS((int start, int fwd, const char *str,
int anchored));
char ** histpos(void);
int histN(void);
int histnum(int n);
int findhist(int start, int fwd, const char *str,
int anchored);
#endif /* HISTORY */
/* io.c */
void errorf ARGS((const char *fmt, ...))
void errorf(const char *fmt, ...)
GCC_FUNC_ATTR2(noreturn, format(printf, 1, 2));
void warningf ARGS((int fileline, const char *fmt, ...))
void warningf(int fileline, const char *fmt, ...)
GCC_FUNC_ATTR(format(printf, 2, 3));
void bi_errorf ARGS((const char *fmt, ...))
void bi_errorf(const char *fmt, ...)
GCC_FUNC_ATTR(format(printf, 1, 2));
void internal_errorf ARGS((int jump, const char *fmt, ...))
void internal_errorf(int jump, const char *fmt, ...)
GCC_FUNC_ATTR(format(printf, 2, 3));
void error_prefix ARGS((int fileline));
void shellf ARGS((const char *fmt, ...))
void error_prefix(int fileline);
void shellf(const char *fmt, ...)
GCC_FUNC_ATTR(format(printf, 1, 2));
void shprintf ARGS((const char *fmt, ...))
void shprintf(const char *fmt, ...)
GCC_FUNC_ATTR(format(printf, 1, 2));
#ifdef KSH_DEBUG
void kshdebug_init_ ARGS((void));
void kshdebug_printf_ ARGS((const char *fmt, ...))
void kshdebug_init_(void);
void kshdebug_printf_(const char *fmt, ...)
GCC_FUNC_ATTR(format(printf, 1, 2));
void kshdebug_dump_ ARGS((const char *str, const void *mem, int nbytes));
void kshdebug_dump_(const char *str, const void *mem, int nbytes);
#endif /* KSH_DEBUG */
int can_seek ARGS((int fd));
void initio ARGS((void));
int ksh_dup2 ARGS((int ofd, int nfd, int errok));
int savefd ARGS((int fd, int noclose));
void restfd ARGS((int fd, int ofd));
void openpipe ARGS((int *pv));
void closepipe ARGS((int *pv));
int check_fd ARGS((char *name, int mode, const char **emsgp));
int can_seek(int fd);
void initio(void);
int ksh_dup2(int ofd, int nfd, int errok);
int savefd(int fd, int noclose);
void restfd(int fd, int ofd);
void openpipe(int *pv);
void closepipe(int *pv);
int check_fd(char *name, int mode, const char **emsgp);
#ifdef KSH
void coproc_init ARGS((void));
void coproc_read_close ARGS((int fd));
void coproc_readw_close ARGS((int fd));
void coproc_write_close ARGS((int fd));
int coproc_getfd ARGS((int mode, const char **emsgp));
void coproc_cleanup ARGS((int reuse));
void coproc_init(void);
void coproc_read_close(int fd);
void coproc_readw_close(int fd);
void coproc_write_close(int fd);
int coproc_getfd(int mode, const char **emsgp);
void coproc_cleanup(int reuse);
#endif /* KSH */
struct temp *maketemp ARGS((Area *ap, Temp_type type, struct temp **tlist));
struct temp *maketemp(Area *ap, Temp_type type, struct temp **tlist);
/* jobs.c */
void j_init ARGS((int mflagset));
void j_exit ARGS((void));
void j_change ARGS((void));
int exchild ARGS((struct op *t, int flags, int close_fd));
void startlast ARGS((void));
int waitlast ARGS((void));
int waitfor ARGS((const char *cp, int *sigp));
int j_kill ARGS((const char *cp, int sig));
int j_resume ARGS((const char *cp, int bg));
int j_jobs ARGS((const char *cp, int slp, int nflag));
void j_notify ARGS((void));
pid_t j_async ARGS((void));
int j_stopped_running ARGS((void));
void j_init(int mflagset);
void j_exit(void);
void j_change(void);
int exchild(struct op *t, int flags, int close_fd);
void startlast(void);
int waitlast(void);
int waitfor(const char *cp, int *sigp);
int j_kill(const char *cp, int sig);
int j_resume(const char *cp, int bg);
int j_jobs(const char *cp, int slp, int nflag);
void j_notify(void);
pid_t j_async(void);
int j_stopped_running(void);
/* lex.c */
int yylex ARGS((int cf));
void yyerror ARGS((const char *fmt, ...))
int yylex(int cf);
void yyerror(const char *fmt, ...)
GCC_FUNC_ATTR2(noreturn, format(printf, 1, 2));
Source * pushs ARGS((int type, Area *areap));
void set_prompt ARGS((int to, Source *s));
void pprompt ARGS((const char *cp, int ntruncate));
Source * pushs(int type, Area *areap);
void set_prompt(int to, Source *s);
void pprompt(const char *cp, int ntruncate);
/* mail.c */
#ifdef KSH
void mcheck ARGS((void));
void mcset ARGS((long interval));
void mbset ARGS((char *p));
void mpset ARGS((char *mptoparse));
void mcheck(void);
void mcset(long interval);
void mbset(char *p);
void mpset(char *mptoparse);
#endif /* KSH */
/* main.c */
int include ARGS((const char *name, int argc, char **argv,
int intr_ok));
int command ARGS((const char *comm));
int shell ARGS((Source *volatile s, int volatile toplevel));
void unwind ARGS((int i)) GCC_FUNC_ATTR(noreturn);
void newenv ARGS((int type));
void quitenv ARGS((void));
void cleanup_parents_env ARGS((void));
void cleanup_proc_env ARGS((void));
void aerror ARGS((Area *ap, const char *msg))
int include(const char *name, int argc, char **argv,
int intr_ok);
int command(const char *comm);
int shell(Source *volatile s, int volatile toplevel);
void unwind(int i) GCC_FUNC_ATTR(noreturn);
void newenv(int type);
void quitenv(void);
void cleanup_parents_env(void);
void cleanup_proc_env(void);
void aerror(Area *ap, const char *msg)
GCC_FUNC_ATTR(noreturn);
/* misc.c */
void setctypes ARGS((const char *s, int t));
void initctypes ARGS((void));
char * ulton ARGS((unsigned long n, int base));
char * str_save ARGS((const char *s, Area *ap));
char * str_nsave ARGS((const char *s, int n, Area *ap));
int option ARGS((const char *n));
char * getoptions ARGS((void));
void change_flag ARGS((enum sh_flag f, int what, int newval));
int parse_args ARGS((char **argv, int what, int *setargsp));
int getn ARGS((const char *as, int *ai));
int bi_getn ARGS((const char *as, int *ai));
int gmatch ARGS((const char *s, const char *p, int isfile));
int has_globbing ARGS((const char *xp, const char *xpe));
const unsigned char *pat_scan ARGS((const unsigned char *p,
const unsigned char *pe, int match_sep));
void qsortp ARGS((void **base, size_t n, int (*f)(void *, void *)));
int xstrcmp ARGS((void *p1, void *p2));
void ksh_getopt_reset ARGS((Getopt *go, int));
int ksh_getopt ARGS((char **argv, Getopt *go, const char *options));
void print_value_quoted ARGS((const char *s));
void print_columns ARGS((struct shf *shf, int n,
void setctypes(const char *s, int t);
void initctypes(void);
char * ulton(unsigned long n, int base);
char * str_save(const char *s, Area *ap);
char * str_nsave(const char *s, int n, Area *ap);
int option(const char *n);
char * getoptions(void);
void change_flag(enum sh_flag f, int what, int newval);
int parse_args(char **argv, int what, int *setargsp);
int getn(const char *as, int *ai);
int bi_getn(const char *as, int *ai);
int gmatch(const char *s, const char *p, int isfile);
int has_globbing(const char *xp, const char *xpe);
const unsigned char *pat_scan(const unsigned char *p,
const unsigned char *pe, int match_sep);
void qsortp(void **base, size_t n, int (*f)(void *, void *));
int xstrcmp(void *p1, void *p2);
void ksh_getopt_reset(Getopt *go, int);
int ksh_getopt(char **argv, Getopt *go, const char *options);
void print_value_quoted(const char *s);
void print_columns(struct shf *shf, int n,
char *(*func)(void *, int, char *, int),
void *arg, int max_width, int prefcol));
int strip_nuls ARGS((char *buf, int nbytes));
char *str_zcpy ARGS((char *dst, const char *src, int dsize));
int blocking_read ARGS((int fd, char *buf, int nbytes));
int reset_nonblock ARGS((int fd));
char *ksh_get_wd ARGS((char *buf, int bsize));
void *arg, int max_width, int prefcol);
int strip_nuls(char *buf, int nbytes);
char *str_zcpy(char *dst, const char *src, int dsize);
int blocking_read(int fd, char *buf, int nbytes);
int reset_nonblock(int fd);
char *ksh_get_wd(char *buf, int bsize);
/* path.c */
int make_path ARGS((const char *cwd, const char *file,
char **pathlist, XString *xsp, int *phys_pathp));
void simplify_path ARGS((char *path));
char *get_phys_path ARGS((const char *path));
void set_current_wd ARGS((char *path));
int make_path(const char *cwd, const char *file,
char **pathlist, XString *xsp, int *phys_pathp);
void simplify_path(char *path);
char *get_phys_path(const char *path);
void set_current_wd(char *path);
/* rnd.c */
long rnd_get ARGS((void));
void rnd_put ARGS((long));
void rnd_seed ARGS((long));
long rnd_get(void);
void rnd_put(long);
void rnd_seed(long);
/* syn.c */
void initkeywords ARGS((void));
struct op * compile ARGS((Source *s));
void initkeywords(void);
struct op * compile(Source *s);
/* table.c */
unsigned int hash ARGS((const char *n));
void tinit ARGS((struct table *tp, Area *ap, int tsize));
struct tbl * tsearch ARGS((struct table *tp, const char *n, unsigned int h));
struct tbl * tenter ARGS((struct table *tp, const char *n, unsigned int h));
void tdelete ARGS((struct tbl *p));
void twalk ARGS((struct tstate *ts, struct table *tp));
struct tbl * tnext ARGS((struct tstate *ts));
struct tbl ** tsort ARGS((struct table *tp));
unsigned int hash(const char *n);
void tinit(struct table *tp, Area *ap, int tsize);
struct tbl * tsearch(struct table *tp, const char *n, unsigned int h);
struct tbl * tenter(struct table *tp, const char *n, unsigned int h);
void tdelete(struct tbl *p);
void twalk(struct tstate *ts, struct table *tp);
struct tbl * tnext(struct tstate *ts);
struct tbl ** tsort(struct table *tp);
/* trace.c */
/* trap.c */
void inittraps ARGS((void));
void inittraps(void);
#ifdef KSH
void alarm_init ARGS((void));
void alarm_init(void);
#endif /* KSH */
Trap * gettrap ARGS((const char *name, int igncase));
RETSIGTYPE trapsig ARGS((int i));
void intrcheck ARGS((void));
int fatal_trap_check ARGS((void));
int trap_pending ARGS((void));
void runtraps ARGS((int intr));
void runtrap ARGS((Trap *p));
void cleartraps ARGS((void));
void restoresigs ARGS((void));
void settrap ARGS((Trap *p, char *s));
int block_pipe ARGS((void));
void restore_pipe ARGS((int restore_dfl));
int setsig ARGS((Trap *p, handler_t f, int flags));
void setexecsig ARGS((Trap *p, int restore));
Trap * gettrap(const char *name, int igncase);
RETSIGTYPE trapsig(int i);
void intrcheck(void);
int fatal_trap_check(void);
int trap_pending(void);
void runtraps(int intr);
void runtrap(Trap *p);
void cleartraps(void);
void restoresigs(void);
void settrap(Trap *p, char *s);
int block_pipe(void);
void restore_pipe(int restore_dfl);
int setsig(Trap *p, handler_t f, int flags);
void setexecsig(Trap *p, int restore);
/* tree.c */
int fptreef ARGS((struct shf *f, int indent, const char *fmt, ...));
char * snptreef ARGS((char *s, int n, const char *fmt, ...));
struct op * tcopy ARGS((struct op *t, Area *ap));
char * wdcopy ARGS((const char *wp, Area *ap));
char * wdscan ARGS((const char *wp, int c));
char * wdstrip ARGS((const char *wp));
void tfree ARGS((struct op *t, Area *ap));
int fptreef(struct shf *f, int indent, const char *fmt, ...);
char * snptreef(char *s, int n, const char *fmt, ...);
struct op * tcopy(struct op *t, Area *ap);
char * wdcopy(const char *wp, Area *ap);
char * wdscan(const char *wp, int c);
char * wdstrip(const char *wp);
void tfree(struct op *t, Area *ap);
/* var.c */
void newblock ARGS((void));
void popblock ARGS((void));
void initvar ARGS((void));
struct tbl * global ARGS((const char *n));
struct tbl * local ARGS((const char *n, bool_t copy));
char * str_val ARGS((struct tbl *vp));
long intval ARGS((struct tbl *vp));
int setstr ARGS((struct tbl *vq, const char *s, int error_ok));
struct tbl *setint_v ARGS((struct tbl *vq, struct tbl *vp));
void setint ARGS((struct tbl *vq, long n));
int getint ARGS((struct tbl *vp, long *nump));
struct tbl * typeset ARGS((const char *var, Tflag set, Tflag clr, int field, int base));
void unset ARGS((struct tbl *vp, int array_ref));
char * skip_varname ARGS((const char *s, int aok));
char *skip_wdvarname ARGS((const char *s, int aok));
int is_wdvarname ARGS((const char *s, int aok));
int is_wdvarassign ARGS((const char *s));
char ** makenv ARGS((void));
void change_random ARGS((void));
int array_ref_len ARGS((const char *cp));
char * arrayname ARGS((const char *str));
void set_array ARGS((const char *var, int reset, char **vals));
void newblock(void);
void popblock(void);
void initvar(void);
struct tbl * global(const char *n);
struct tbl * local(const char *n, bool_t copy);
char * str_val(struct tbl *vp);
long intval(struct tbl *vp);
int setstr(struct tbl *vq, const char *s, int error_ok);
struct tbl *setint_v(struct tbl *vq, struct tbl *vp);
void setint(struct tbl *vq, long n);
int getint(struct tbl *vp, long *nump);
struct tbl * typeset(const char *var, Tflag set, Tflag clr, int field, int base);
void unset(struct tbl *vp, int array_ref);
char * skip_varname(const char *s, int aok);
char *skip_wdvarname(const char *s, int aok);
int is_wdvarname(const char *s, int aok);
int is_wdvarassign(const char *s);
char ** makenv(void);
void change_random(void);
int array_ref_len(const char *cp);
char * arrayname(const char *str);
void set_array(const char *var, int reset, char **vals);
/* version.c */
/* vi.c: see edit.h */
/* Hack to avoid billions of compile warnings on SunOS 4.1.x */
#if defined(MUN) && defined(sun) && !defined(__svr4__)
extern void bcopy ARGS((const void *src, void *dst, size_t size));
extern int fclose ARGS((FILE *fp));
extern int fprintf ARGS((FILE *fp, const char *fmt, ...));
extern int fread ARGS((void *buf, int size, int num, FILE *fp));
extern int ioctl ARGS((int fd, int request, void *arg));
extern int killpg ARGS((int pgrp, int sig));
extern int nice ARGS((int n));
extern int readlink ARGS((const char *path, char *buf, int bufsize));
extern int setpgrp ARGS((int pid, int pgrp));
extern int strcasecmp ARGS((const char *s1, const char *s2));
extern int tolower ARGS((int));
extern int toupper ARGS((int));
extern void bcopy(const void *src, void *dst, size_t size);
extern int fclose(FILE *fp);
extern int fprintf(FILE *fp, const char *fmt, ...);
extern int fread(void *buf, int size, int num, FILE *fp);
extern int ioctl(int fd, int request, void *arg);
extern int killpg(int pgrp, int sig);
extern int nice(int n);
extern int readlink(const char *path, char *buf, int bufsize);
extern int setpgrp(int pid, int pgrp);
extern int strcasecmp(const char *s1, const char *s2);
extern int tolower(int);
extern int toupper(int);
/* Include files aren't included yet */
extern int getrlimit ARGS(( /* int resource, struct rlimit *rpl */ ));
extern int getrusage ARGS(( /* int who, struct rusage *rusage */ ));
extern int gettimeofday ARGS(( /* struct timeval *tv, struct timezone *tz */ ));
extern int setrlimit ARGS(( /* int resource, struct rlimit *rlp */ ));
extern int lstat ARGS(( /* const char *path, struct stat *buf */ ));
extern int getrlimit( /* int resource, struct rlimit *rpl */ );
extern int getrusage( /* int who, struct rusage *rusage */ );
extern int gettimeofday( /* struct timeval *tv, struct timezone *tz */ );
extern int setrlimit( /* int resource, struct rlimit *rlp */ );
extern int lstat( /* const char *path, struct stat *buf */ );
#endif

88
sh.h
View File

@ -1,4 +1,4 @@
/** $MirBSD: sh.h,v 1.13 2004/09/21 11:57:13 tg Exp $ */
/** $MirBSD: sh.h,v 1.14 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: sh.h,v 1.18 2004/05/31 10:36:35 otto Exp $ */
/*
@ -10,12 +10,6 @@
#include "config.h" /* system and option configuration info */
#ifdef HAVE_PROTOTYPES
# define ARGS(args) args /* prototype declaration */
#else
# define ARGS(args) () /* K&R declaration */
#endif
/* Start of common headers */
#include <stdio.h>
@ -29,51 +23,51 @@
# include <stdlib.h>
#else
/* just a useful subset of what stdlib.h would have */
extern char * getenv ARGS((const char *));
extern void * malloc ARGS((size_t));
extern void * realloc ARGS((void *, size_t));
extern int free ARGS((void *));
extern int exit ARGS((int));
extern int atoi ARGS((const char *));
extern char * getenv(const char *);
extern void * malloc(size_t);
extern void * realloc(void *, size_t);
extern int free(void *);
extern int exit(int);
extern int atoi(const char *);
#endif /* HAVE_STDLIB_H */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#else
/* just a useful subset of what unistd.h would have */
extern int access ARGS((const char *, int));
extern int open ARGS((const char *, int, ...));
extern int creat ARGS((const char *, mode_t));
extern int read ARGS((int, char *, unsigned));
extern int write ARGS((int, const char *, unsigned));
extern off_t lseek ARGS((int, off_t, int));
extern int close ARGS((int));
extern int pipe ARGS((int []));
extern int dup2 ARGS((int, int));
extern int unlink ARGS((const char *));
extern int fork ARGS((void));
extern int execve ARGS((const char *, char * const[], char * const[]));
extern int chdir ARGS((const char *));
extern int kill ARGS((pid_t, int));
extern int access(const char *, int);
extern int open(const char *, int, ...);
extern int creat(const char *, mode_t);
extern int read(int, char *, unsigned);
extern int write(int, const char *, unsigned);
extern off_t lseek(int, off_t, int);
extern int close(int);
extern int pipe(int []);
extern int dup2(int, int);
extern int unlink(const char *);
extern int fork(void);
extern int execve(const char *, char * const[], char * const[]);
extern int chdir(const char *);
extern int kill(pid_t, int);
extern char *getcwd(); /* no ARGS here - differs on different machines */
extern int geteuid ARGS((void));
extern int readlink ARGS((const char *, char *, int));
extern int getegid ARGS((void));
extern int getpid ARGS((void));
extern int getppid ARGS((void));
extern unsigned int sleep ARGS((unsigned int));
extern int isatty ARGS((int));
extern int geteuid(void);
extern int readlink(const char *, char *, int);
extern int getegid(void);
extern int getpid(void);
extern int getppid(void);
extern unsigned int sleep(unsigned int);
extern int isatty(int);
# ifdef POSIX_PGRP
extern int getpgrp ARGS((void));
extern int setpgid ARGS((pid_t, pid_t));
extern int getpgrp(void);
extern int setpgid(pid_t, pid_t);
# endif /* POSIX_PGRP */
# ifdef BSD_PGRP
extern int getpgrp ARGS((pid_t));
extern int setpgrp ARGS((pid_t, pid_t));
extern int getpgrp(pid_t);
extern int setpgrp(pid_t, pid_t);
# endif /* BSD_PGRP */
# ifdef SYSV_PGRP
extern int getpgrp ARGS((void));
extern int setpgrp ARGS((void));
extern int getpgrp(void);
extern int setpgrp(void);
# endif /* SYSV_PGRP */
#endif /* HAVE_UNISTD_H */
@ -85,11 +79,11 @@ extern int setpgrp ARGS((void));
# define strrchr rindex
#endif /* HAVE_STRING_H */
#ifndef HAVE_STRSTR
char *strstr ARGS((const char *s, const char *p));
char *strstr(const char *s, const char *p);
#endif /* HAVE_STRSTR */
#ifndef HAVE_STRCASECMP
int strcasecmp ARGS((const char *s1, const char *s2));
int strncasecmp ARGS((const char *s1, const char *s2, int n));
int strcasecmp(const char *s1, const char *s2);
int strncasecmp(const char *s1, const char *s2, int n);
#endif /* HAVE_STRCASECMP */
#ifdef HAVE_MEMORY_H
@ -98,13 +92,13 @@ int strncasecmp ARGS((const char *s1, const char *s2, int n));
#ifndef HAVE_MEMSET
# define memcpy(d, s, n) bcopy(s, d, n)
# define memcmp(s1, s2, n) bcmp(s1, s2, n)
void *memset ARGS((void *d, int c, size_t n));
void *memset(void *d, int c, size_t n);
#endif /* HAVE_MEMSET */
#ifndef HAVE_MEMMOVE
# ifdef HAVE_BCOPY
# define memmove(d, s, n) bcopy(s, d, n)
# else
void *memmove ARGS((void *d, const void *s, size_t n));
void *memmove(void *d, const void *s, size_t n);
# endif
#endif /* HAVE_MEMMOVE */
@ -179,7 +173,7 @@ void *memmove ARGS((void *d, const void *s, size_t n));
# define KSH_SA_FLAGS 0
#endif /* SA_INTERRUPT */
typedef RETSIGTYPE (*handler_t) ARGS((int)); /* signal handler */
typedef RETSIGTYPE (*handler_t)(int); /* signal handler */
#ifdef USE_FAKE_SIGACT
# include "sigact.h" /* use sjg's fake sigaction() */
@ -238,7 +232,7 @@ extern int ksh_execve(char *cmd, char **args, char **env, int flags);
#endif /* HAVE_SIGSETJMP */
#ifndef HAVE_DUP2
extern int dup2 ARGS((int, int));
extern int dup2(int, int);
#endif /* !HAVE_DUP2 */
/* Find a integer type that is at least 32 bits (or die) - SIZEOF_* defined

7
shf.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: shf.c,v 1.4 2004/09/21 11:57:14 tg Exp $ */
/** $MirBSD: shf.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: shf.c,v 1.8 2003/02/28 09:45:09 jmc Exp $ */
/*
@ -9,6 +9,7 @@
#include "ksh_stat.h"
#include "ksh_limval.h"
__RCSID("$MirBSD: shf.c,v 1.5 2004/10/28 11:11:19 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -20,8 +21,8 @@
* file descriptors.
*/
static int shf_fillbuf ARGS((struct shf *shf));
static int shf_emptybuf ARGS((struct shf *shf, int flags));
static int shf_fillbuf(struct shf *shf);
static int shf_emptybuf(struct shf *shf, int flags);
/* Open a file. First three args are for open(), last arg is flags for
* this package. Returns NULL if file could not be opened, or if a dup

48
shf.h
View File

@ -1,4 +1,4 @@
/** $MirBSD: shf.h,v 1.3 2004/09/21 11:57:14 tg Exp $ */
/** $MirBSD: shf.h,v 1.4 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: shf.h,v 1.2 1999/01/08 20:25:02 millert Exp $ */
#ifndef SHF_H
@ -60,28 +60,28 @@ struct shf {
extern struct shf shf_iob[];
struct shf *shf_open ARGS((const char *name, int oflags, int mode,
int sflags));
struct shf *shf_fdopen ARGS((int fd, int sflags, struct shf *shf));
struct shf *shf_reopen ARGS((int fd, int sflags, struct shf *shf));
struct shf *shf_sopen ARGS((char *buf, int bsize, int sflags,
struct shf *shf));
int shf_close ARGS((struct shf *shf));
int shf_fdclose ARGS((struct shf *shf));
char *shf_sclose ARGS((struct shf *shf));
int shf_finish ARGS((struct shf *shf));
int shf_flush ARGS((struct shf *shf));
int shf_seek ARGS((struct shf *shf, off_t where, int from));
int shf_read ARGS((char *buf, int bsize, struct shf *shf));
char *shf_getse ARGS((char *buf, int bsize, struct shf *shf));
int shf_getchar ARGS((struct shf *shf));
int shf_ungetc ARGS((int c, struct shf *shf));
int shf_putchar ARGS((int c, struct shf *shf));
int shf_puts ARGS((const char *s, struct shf *shf));
int shf_write ARGS((const char *buf, int nbytes, struct shf *shf));
int shf_fprintf ARGS((struct shf *shf, const char *fmt, ...));
int shf_snprintf ARGS((char *buf, int bsize, const char *fmt, ...));
char *shf_smprintf ARGS((const char *fmt, ...));
int shf_vfprintf ARGS((struct shf *, const char *fmt, va_list args));
struct shf *shf_open(const char *name, int oflags, int mode,
int sflags);
struct shf *shf_fdopen(int fd, int sflags, struct shf *shf);
struct shf *shf_reopen(int fd, int sflags, struct shf *shf);
struct shf *shf_sopen(char *buf, int bsize, int sflags,
struct shf *shf);
int shf_close(struct shf *shf);
int shf_fdclose(struct shf *shf);
char *shf_sclose(struct shf *shf);
int shf_finish(struct shf *shf);
int shf_flush(struct shf *shf);
int shf_seek(struct shf *shf, off_t where, int from);
int shf_read(char *buf, int bsize, struct shf *shf);
char *shf_getse(char *buf, int bsize, struct shf *shf);
int shf_getchar(struct shf *shf);
int shf_ungetc(int c, struct shf *shf);
int shf_putchar(int c, struct shf *shf);
int shf_puts(const char *s, struct shf *shf);
int shf_write(const char *buf, int nbytes, struct shf *shf);
int shf_fprintf(struct shf *shf, const char *fmt, ...);
int shf_snprintf(char *buf, int bsize, const char *fmt, ...);
char *shf_smprintf(const char *fmt, ...);
int shf_vfprintf(struct shf *, const char *fmt, va_list args);
#endif /* SHF_H */

62
syn.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: syn.c,v 1.5 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: syn.c,v 1.6 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: syn.c,v 1.14 2003/10/22 07:40:38 jmc Exp $ */
/*
@ -8,44 +8,44 @@
#include "sh.h"
#include "c_test.h"
__RCSID("$MirBSD: syn.c,v 1.5 2004/10/28 11:03:24 tg Exp $");
__RCSID("$MirBSD: syn.c,v 1.6 2004/10/28 11:11:19 tg Exp $");
struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */
int start_line; /* line nesting began on */
};
static void yyparse ARGS((void));
static struct op *pipeline ARGS((int cf));
static struct op *andor ARGS((void));
static struct op *c_list ARGS((int multi));
static struct ioword *synio ARGS((int cf));
static void musthave ARGS((int c, int cf));
static struct op *nested ARGS((int type, int smark, int emark));
static struct op *get_command ARGS((int cf));
static struct op *dogroup ARGS((void));
static struct op *thenpart ARGS((void));
static struct op *elsepart ARGS((void));
static struct op *caselist ARGS((void));
static struct op *casepart ARGS((int endtok));
static struct op *function_body ARGS((char *name, int ksh_func));
static char ** wordlist ARGS((void));
static struct op *block ARGS((int type, struct op *t1, struct op *t2,
char **wp));
static struct op *newtp ARGS((int type));
static void syntaxerr ARGS((const char *what))
static void yyparse(void);
static struct op *pipeline(int cf);
static struct op *andor(void);
static struct op *c_list(int multi);
static struct ioword *synio(int cf);
static void musthave(int c, int cf);
static struct op *nested(int type, int smark, int emark);
static struct op *get_command(int cf);
static struct op *dogroup(void);
static struct op *thenpart(void);
static struct op *elsepart(void);
static struct op *caselist(void);
static struct op *casepart(int endtok);
static struct op *function_body(char *name, int ksh_func);
static char ** wordlist(void);
static struct op *block(int type, struct op *t1, struct op *t2,
char **wp);
static struct op *newtp(int type);
static void syntaxerr(const char *what)
GCC_FUNC_ATTR(noreturn);
static void nesting_push ARGS((struct nesting_state *save, int tok));
static void nesting_pop ARGS((struct nesting_state *saved));
static int assign_command ARGS((char *s));
static int inalias ARGS((struct source *s));
static void nesting_push(struct nesting_state *save, int tok);
static void nesting_pop(struct nesting_state *saved);
static int assign_command(char *s);
static int inalias(struct source *s);
#ifdef KSH
static int dbtestp_isa ARGS((Test_env *te, Test_meta meta));
static const char *dbtestp_getopnd ARGS((Test_env *te, Test_op op,
int do_eval));
static int dbtestp_eval ARGS((Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval));
static void dbtestp_error ARGS((Test_env *te, int offset, const char *msg));
static int dbtestp_isa(Test_env *te, Test_meta meta);
static const char *dbtestp_getopnd(Test_env *te, Test_op op,
int do_eval);
static int dbtestp_eval(Test_env *te, Test_op op, const char *opnd1,
const char *opnd2, int do_eval);
static void dbtestp_error(Test_env *te, int offset, const char *msg);
#endif /* KSH */
static struct op *outtree; /* yyparse output */

10
table.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: table.c,v 1.4 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: table.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: table.c,v 1.5 1999/01/10 17:55:03 millert Exp $ */
/*
@ -7,10 +7,12 @@
#include "sh.h"
__RCSID("$MirBSD: table.c,v 1.5 2004/10/28 11:11:19 tg Exp $");
#define INIT_TBLS 8 /* initial table size (power of 2) */
static void texpand ARGS((struct table *tp, int nsize));
static int tnamecmp ARGS((void *p1, void *p2));
static void texpand(struct table *tp, int nsize);
static int tnamecmp(void *p1, void *p2);
unsigned int
@ -194,7 +196,7 @@ tsort(tp)
#ifdef PERF_DEBUG /* performance debugging */
void tprintinfo ARGS((struct table *tp));
void tprintinfo(struct table *tp);
void
tprintinfo(tp)

View File

@ -1,4 +1,4 @@
/** $MirBSD: table.h,v 1.3 2004/09/21 11:57:16 tg Exp $ */
/** $MirBSD: table.h,v 1.4 2004/10/28 11:11:19 tg 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 $ */
@ -20,7 +20,7 @@ struct tbl { /* table item */
union {
char *s; /* string */
long i; /* integer */
int (*f) ARGS((char **)); /* int function */
int (*f)(char **); /* int function */
struct op *t; /* "function" tree */
} val; /* value */
int index; /* index for an array */
@ -145,7 +145,7 @@ EXTERN struct table homedirs; /* homedir() cache */
struct builtin {
const char *name;
int (*func) ARGS((char **));
int (*func)(char **);
};
/* these really are externs! Look in table.c for them */

6
trap.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: trap.c,v 1.4 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: trap.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: trap.c,v 1.13 2003/02/28 09:45:09 jmc Exp $ */
/*
@ -9,7 +9,7 @@
#define FROM_TRAP_C
#include "sh.h"
__RCSID("$MirBSD: trap.c,v 1.4 2004/10/28 11:03:24 tg Exp $");
__RCSID("$MirBSD: trap.c,v 1.5 2004/10/28 11:11:19 tg Exp $");
/* Table is indexed by signal number
*
@ -59,7 +59,7 @@ inittraps()
}
#ifdef KSH
static RETSIGTYPE alarm_catcher ARGS((int sig));
static RETSIGTYPE alarm_catcher(int sig);
void
alarm_init()

18
tree.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: tree.c,v 1.4 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: tree.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: tree.c,v 1.10 2002/02/27 19:37:09 dhartmei Exp $ */
/*
@ -7,18 +7,18 @@
#include "sh.h"
__RCSID("$MirBSD: tree.c,v 1.4 2004/10/28 11:03:24 tg Exp $");
__RCSID("$MirBSD: tree.c,v 1.5 2004/10/28 11:11:19 tg Exp $");
#define INDENT 4
#define tputc(c, shf) shf_putchar(c, shf);
static void ptree ARGS((struct op *t, int indent, struct shf *f));
static void pioact ARGS((struct shf *f, int indent, struct ioword *iop));
static void tputC ARGS((int c, struct shf *shf));
static void tputS ARGS((char *wp, struct shf *shf));
static void vfptreef ARGS((struct shf *shf, int indent, const char *fmt, va_list va));
static struct ioword **iocopy ARGS((struct ioword **iow, Area *ap));
static void iofree ARGS((struct ioword **iow, Area *ap));
static void ptree(struct op *t, int indent, struct shf *f);
static void pioact(struct shf *f, int indent, struct ioword *iop);
static void tputC(int c, struct shf *shf);
static void tputS(char *wp, struct shf *shf);
static void vfptreef(struct shf *shf, int indent, const char *fmt, va_list va);
static struct ioword **iocopy(struct ioword **iow, Area *ap);
static void iofree(struct ioword **iow, Area *ap);
/*
* print a command tree

6
tty.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: tty.c,v 1.4 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: tty.c,v 1.5 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: tty.c,v 1.2 1996/10/01 02:05:51 downsj Exp $ */
#include "sh.h"
@ -7,7 +7,7 @@
#include "tty.h"
#undef EXTERN
__RCSID("$MirBSD: tty.c,v 1.4 2004/10/28 11:03:24 tg Exp $");
__RCSID("$MirBSD: tty.c,v 1.5 2004/10/28 11:11:19 tg Exp $");
int
get_tty(fd, ts)
@ -119,7 +119,7 @@ tty_init(init_ttystate)
* so force it to be done here...
*/
{
extern char *ttyname ARGS((int));
extern char *ttyname(int);
char *s = ttyname(isatty(2) ? 2 : 0);
int fd;

10
tty.h
View File

@ -1,4 +1,4 @@
/** $MirBSD: tty.h,v 1.3 2004/09/21 11:57:16 tg Exp $ */
/** $MirBSD: tty.h,v 1.4 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: tty.h,v 1.2 1996/11/21 07:59:36 downsj Exp $ */
/*
@ -97,10 +97,10 @@ EXTERN int tty_fd I__(-1); /* dup'd tty file descriptor */
EXTERN int tty_devtty; /* true if tty_fd is from /dev/tty */
EXTERN TTY_state tty_state; /* saved tty state */
extern int get_tty ARGS((int fd, TTY_state *ts));
extern int set_tty ARGS((int fd, TTY_state *ts, int flags));
extern void tty_init ARGS((int init_ttystate));
extern void tty_close ARGS((void));
extern int get_tty(int fd, TTY_state *ts);
extern int set_tty(int fd, TTY_state *ts, int flags);
extern void tty_init(int init_ttystate);
extern void tty_close(void);
/* be sure not to interfere with anyone else's idea about EXTERN */
#ifdef EXTERN_DEFINED

20
var.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: var.c,v 1.9 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: var.c,v 1.10 2004/10/28 11:11:19 tg Exp $ */
/* $OpenBSD: var.c,v 1.17 2004/05/08 19:42:35 deraadt Exp $ */
#include "sh.h"
@ -7,6 +7,8 @@
#include "ksh_stat.h"
#include <ctype.h>
__RCSID("$MirBSD: var.c,v 1.10 2004/10/28 11:11:19 tg Exp $");
/*
* Variables
*
@ -18,14 +20,14 @@
*/
static struct tbl vtemp;
static struct table specials;
static char *formatstr ARGS((struct tbl *vp, const char *s));
static void export ARGS((struct tbl *vp, const char *val));
static int special ARGS((const char *name));
static void unspecial ARGS((const char *name));
static void getspec ARGS((struct tbl *vp));
static void setspec ARGS((struct tbl *vp));
static void unsetspec ARGS((struct tbl *vp));
static struct tbl *arraysearch ARGS((struct tbl *, int));
static char *formatstr(struct tbl *vp, const char *s);
static void export(struct tbl *vp, const char *val);
static int special(const char *name);
static void unspecial(const char *name);
static void getspec(struct tbl *vp);
static void setspec(struct tbl *vp);
static void unsetspec(struct tbl *vp);
static struct tbl *arraysearch(struct tbl *, int);
/*
* create a new block for function calls and simple commands

89
vi.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: vi.c,v 1.8 2004/10/28 11:03:24 tg Exp $ */
/** $MirBSD: vi.c,v 1.9 2004/10/28 11:11:19 tg 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 "edit.h"
__RCSID("$MirBSD: vi.c,v 1.8 2004/10/28 11:03:24 tg Exp $");
__RCSID("$MirBSD: vi.c,v 1.9 2004/10/28 11:11:19 tg Exp $");
#define Ctrl(c) (c&0x1f)
#define is_wordch(c) (letnum(c))
@ -29,45 +29,45 @@ struct edstate {
};
static int vi_hook ARGS((int ch));
static void vi_reset ARGS((char *buf, size_t len));
static int nextstate ARGS((int ch));
static int vi_insert ARGS((int ch));
static int vi_cmd ARGS((int argcnt, const char *cmd));
static int domove ARGS((int argcnt, const char *cmd, int sub));
static int redo_insert ARGS((int count));
static void yank_range ARGS((int a, int b));
static int bracktype ARGS((int ch));
static void save_cbuf ARGS((void));
static void restore_cbuf ARGS((void));
static void edit_reset ARGS((char *buf, size_t len));
static int putbuf ARGS((const char *buf, int len, int repl));
static void del_range ARGS((int a, int b));
static int findch ARGS((int ch, int cnt, int forw, int incl));
static int forwword ARGS((int argcnt));
static int backword ARGS((int argcnt));
static int endword ARGS((int argcnt));
static int Forwword ARGS((int argcnt));
static int Backword ARGS((int argcnt));
static int Endword ARGS((int argcnt));
static int grabhist ARGS((int save, int n));
static int grabsearch ARGS((int save, int start, int fwd, char *pat));
static void redraw_line ARGS((int newline));
static void refresh ARGS((int leftside));
static int outofwin ARGS((void));
static void rewindow ARGS((void));
static int newcol ARGS((int ch, int col));
static void display ARGS((char *wb1, char *wb2, int leftside));
static void ed_mov_opt ARGS((int col, char *wb));
static int expand_word ARGS((int command));
static int complete_word ARGS((int command, int count));
static int print_expansions ARGS((struct edstate *e, int command));
static int char_len ARGS((int c));
static void x_vi_zotc ARGS((int c));
static void vi_pprompt ARGS((int full));
static void vi_error ARGS((void));
static void vi_macro_reset ARGS((void));
static int x_vi_putbuf ARGS((const char *s, size_t len));
static int vi_hook(int ch);
static void vi_reset(char *buf, size_t len);
static int nextstate(int ch);
static int vi_insert(int ch);
static int vi_cmd(int argcnt, const char *cmd);
static int domove(int argcnt, const char *cmd, int sub);
static int redo_insert(int count);
static void yank_range(int a, int b);
static int bracktype(int ch);
static void save_cbuf(void);
static void restore_cbuf(void);
static void edit_reset(char *buf, size_t len);
static int putbuf(const char *buf, int len, int repl);
static void del_range(int a, int b);
static int findch(int ch, int cnt, int forw, int incl);
static int forwword(int argcnt);
static int backword(int argcnt);
static int endword(int argcnt);
static int Forwword(int argcnt);
static int Backword(int argcnt);
static int Endword(int argcnt);
static int grabhist(int save, int n);
static int grabsearch(int save, int start, int fwd, char *pat);
static void redraw_line(int newline);
static void refresh(int leftside);
static int outofwin(void);
static void rewindow(void);
static int newcol(int ch, int col);
static void display(char *wb1, char *wb2, int leftside);
static void ed_mov_opt(int col, char *wb);
static int expand_word(int command);
static int complete_word(int command, int count);
static int print_expansions(struct edstate *e, int command);
static int char_len(int c);
static void x_vi_zotc(int c);
static void vi_pprompt(int full);
static void vi_error(void);
static void vi_macro_reset(void);
static int x_vi_putbuf(const char *s, size_t len);
#define C_ 0x1 /* a valid command that isn't a M_, E_, U_ */
#define M_ 0x2 /* movement command (h, l, etc.) */
@ -143,9 +143,9 @@ const unsigned char classify[128] = {
static char undocbuf[LINE];
static struct edstate *save_edstate ARGS((struct edstate *old));
static void restore_edstate ARGS((struct edstate *old, struct edstate *new));
static void free_edstate ARGS((struct edstate *old));
static struct edstate *save_edstate(struct edstate *old);
static void restore_edstate(struct edstate *old, struct edstate *new);
static void free_edstate(struct edstate *old);
static struct edstate ebuf;
static struct edstate undobuf = { 0, undocbuf, LINE, 0, 0 };
@ -2193,5 +2193,4 @@ vi_macro_reset()
memset((char *) &macro, 0, sizeof(macro));
}
}
#endif /* VI */