sync with OpenBSD: remove unused code and vars; name clash with libc

compiles under MirBSD
This commit is contained in:
tg 2006-01-29 20:04:54 +00:00
parent 7ca34b3b12
commit 94ee3b388a
12 changed files with 96 additions and 169 deletions

10
edit.c
View File

@ -1,11 +1,11 @@
/* $OpenBSD: edit.c,v 1.30 2005/09/11 18:08:47 otto Exp $ */ /* $OpenBSD: edit.c,v 1.31 2005/12/11 20:31:21 otto Exp $ */
/* $OpenBSD: edit.h,v 1.8 2005/03/28 21:28:22 deraadt Exp $ */ /* $OpenBSD: edit.h,v 1.8 2005/03/28 21:28:22 deraadt Exp $ */
/* $OpenBSD: emacs.c,v 1.39 2005/09/26 19:25:22 otto Exp $ */ /* $OpenBSD: emacs.c,v 1.39 2005/09/26 19:25:22 otto Exp $ */
/* $OpenBSD: vi.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: vi.c,v 1.22 2005/12/11 20:31:21 otto Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.17 2005/11/22 18:40:41 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.18 2006/01/29 20:04:49 tg Exp $");
/* tty driver characters we are interested in */ /* tty driver characters we are interested in */
typedef struct { typedef struct {
@ -760,7 +760,7 @@ glob_table(const char *pat, XPtrV *wp, struct table *tp)
struct tstate ts; struct tstate ts;
struct tbl *te; struct tbl *te;
for (twalk(&ts, tp); (te = tnext(&ts)); ) { for (ktwalk(&ts, tp); (te = ktnext(&ts)); ) {
if (gmatchx(te->name, pat, false)) if (gmatchx(te->name, pat, false))
XPput(*wp, str_save(te->name, ATEMP)); XPput(*wp, str_save(te->name, ATEMP));
} }
@ -3568,7 +3568,7 @@ vi_cmd(int argcnt, const char *cmd)
/* lookup letter in alias list... */ /* lookup letter in alias list... */
alias[1] = cmd[1]; alias[1] = cmd[1];
ap = tsearch(&aliases, alias, hash(alias)); ap = ktsearch(&aliases, alias, hash(alias));
if (!cmd[1] || !ap || !(ap->flag & ISSET)) if (!cmd[1] || !ap || !(ap->flag & ISSET))
return -1; return -1;
/* check if this is a recursive call... */ /* check if this is a recursive call... */

6
eval.c
View File

@ -1,8 +1,8 @@
/* $OpenBSD: eval.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: eval.c,v 1.28 2005/12/11 20:31:21 otto Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.9 2005/11/22 18:40:41 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.10 2006/01/29 20:04:50 tg Exp $");
/* /*
* string expansion * string expansion
@ -1181,7 +1181,7 @@ homedir(char *name)
{ {
struct tbl *ap; struct tbl *ap;
ap = tenter(&homedirs, name, hash(name)); ap = ktenter(&homedirs, name, hash(name));
if (!(ap->flag & ISSET)) { if (!(ap->flag & ISSET)) {
struct passwd *pw; struct passwd *pw;

24
exec.c
View File

@ -1,8 +1,8 @@
/* $OpenBSD: exec.c,v 1.42 2005/09/11 18:02:27 otto Exp $ */ /* $OpenBSD: exec.c,v 1.44 2005/12/11 20:31:21 otto Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.12 2005/11/22 18:40:41 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.13 2006/01/29 20:04:51 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, char **, static int comexec(struct op *, struct tbl *volatile, char **,
int volatile); int volatile);
@ -688,7 +688,7 @@ shcomexec(char **wp)
{ {
struct tbl *tp; struct tbl *tp;
tp = tsearch(&builtins, *wp, hash(*wp)); tp = ktsearch(&builtins, *wp, hash(*wp));
if (tp == NULL) if (tp == NULL)
internal_errorf(1, "shcomexec: %s", *wp); internal_errorf(1, "shcomexec: %s", *wp);
return call_builtin(tp, wp); return call_builtin(tp, wp);
@ -705,11 +705,11 @@ findfunc(const char *name, unsigned int h, int create)
struct tbl *tp = NULL; struct tbl *tp = NULL;
for (l = e->loc; l; l = l->next) { for (l = e->loc; l; l = l->next) {
tp = tsearch(&l->funs, name, h); tp = ktsearch(&l->funs, name, h);
if (tp) if (tp)
break; break;
if (!l->next && create) { if (!l->next && create) {
tp = tenter(&l->funs, name, h); tp = ktenter(&l->funs, name, h);
tp->flag = DEFINED; tp->flag = DEFINED;
tp->type = CFUNC; tp->type = CFUNC;
tp->val.t = NULL; tp->val.t = NULL;
@ -751,7 +751,7 @@ define(const char *name, struct op *t)
} }
if (t == NULL) { /* undefine */ if (t == NULL) { /* undefine */
tdelete(tp); ktdelete(tp);
return was_set ? 0 : 1; return was_set ? 0 : 1;
} }
@ -784,7 +784,7 @@ builtin(const char *name, int (*func) (char **))
break; break;
} }
tp = tenter(&builtins, name, hash(name)); tp = ktenter(&builtins, name, hash(name));
tp->flag = DEFINED | flag; tp->flag = DEFINED | flag;
tp->type = CSHELL; tp->type = CSHELL;
tp->val.f = func; tp->val.f = func;
@ -810,7 +810,7 @@ findcom(const char *name, int flags)
flags &= ~FC_FUNC; flags &= ~FC_FUNC;
goto Search; goto Search;
} }
tbi = (flags & FC_BI) ? tsearch(&builtins, name, h) : NULL; tbi = (flags & FC_BI) ? ktsearch(&builtins, name, h) : NULL;
/* POSIX says special builtins first, then functions, then /* POSIX says special builtins first, then functions, then
* POSIX regular builtins, then search path... * POSIX regular builtins, then search path...
*/ */
@ -832,7 +832,7 @@ findcom(const char *name, int flags)
if (!tp && (flags & FC_UNREGBI) && tbi) if (!tp && (flags & FC_UNREGBI) && tbi)
tp = tbi; tp = tbi;
if (!tp && (flags & FC_PATH) && !(flags & FC_DEFPATH)) { if (!tp && (flags & FC_PATH) && !(flags & FC_DEFPATH)) {
tp = tsearch(&taliases, name, h); tp = ktsearch(&taliases, name, h);
if (tp && (tp->flag & ISSET) && eaccess(tp->val.s, X_OK) != 0) { if (tp && (tp->flag & ISSET) && eaccess(tp->val.s, X_OK) != 0) {
if (tp->flag & ALLOC) { if (tp->flag & ALLOC) {
tp->flag &= ~ALLOC; tp->flag &= ~ALLOC;
@ -847,7 +847,7 @@ findcom(const char *name, int flags)
(flags & FC_PATH)) { (flags & FC_PATH)) {
if (!tp) { if (!tp) {
if (insert && !(flags & FC_DEFPATH)) { if (insert && !(flags & FC_DEFPATH)) {
tp = tenter(&taliases, name, h); tp = ktenter(&taliases, name, h);
tp->type = CTALIAS; tp->type = CTALIAS;
} else { } else {
tp = &temp; tp = &temp;
@ -887,7 +887,7 @@ flushcom(int all) /* just relative or all */
struct tbl *tp; struct tbl *tp;
struct tstate ts; struct tstate ts;
for (twalk(&ts, &taliases); (tp = tnext(&ts)) != NULL; ) for (ktwalk(&ts, &taliases); (tp = ktnext(&ts)) != NULL; )
if ((tp->flag&ISSET) && (all || tp->val.s[0] != '/')) { if ((tp->flag&ISSET) && (all || tp->val.s[0] != '/')) {
if (tp->flag&ALLOC) { if (tp->flag&ALLOC) {
tp->flag &= ~(ALLOC|ISSET); tp->flag &= ~(ALLOC|ISSET);
@ -1227,7 +1227,7 @@ struct select_menu_info {
char *const *args; char *const *args;
int arg_width; int arg_width;
int num_width; int num_width;
} info; };
static char *select_fmt_entry(void *arg, int i, char *buf, int buflen); static char *select_fmt_entry(void *arg, int i, char *buf, int buflen);

22
funcs.c
View File

@ -1,11 +1,11 @@
/* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_ksh.c,v 1.28 2005/12/11 20:31:21 otto Exp $ */
/* $OpenBSD: c_sh.c,v 1.31 2005/10/08 18:07:31 otto Exp $ */ /* $OpenBSD: c_sh.c,v 1.31 2005/10/08 18:07:31 otto Exp $ */
/* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: c_ulimit.c,v 1.14 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_ulimit.c,v 1.14 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.24 2005/11/22 18:40:42 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.25 2006/01/29 20:04:51 tg Exp $");
int int
c_cd(char **wp) c_cd(char **wp)
@ -424,9 +424,9 @@ c_whence(char **wp)
while ((vflag || ret == 0) && (id = *wp++) != NULL) { while ((vflag || ret == 0) && (id = *wp++) != NULL) {
tp = NULL; tp = NULL;
if ((iam_whence || vflag) && !pflag) if ((iam_whence || vflag) && !pflag)
tp = tsearch(&keywords, id, hash(id)); tp = ktsearch(&keywords, id, hash(id));
if (!tp && !pflag) { if (!tp && !pflag) {
tp = tsearch(&aliases, id, hash(id)); tp = ktsearch(&aliases, id, hash(id));
if (tp && !(tp->flag & ISSET)) if (tp && !(tp->flag & ISSET))
tp = NULL; tp = NULL;
} }
@ -692,7 +692,7 @@ c_typeset(char **wp)
flag = fset | fclr; /* no difference at this point.. */ flag = fset | fclr; /* no difference at this point.. */
if (func) { if (func) {
for (l = e->loc; l; l = l->next) { for (l = e->loc; l; l = l->next) {
for (p = tsort(&l->funs); (vp = *p++); ) { for (p = ktsort(&l->funs); (vp = *p++); ) {
if (flag && (vp->flag & flag) == 0) if (flag && (vp->flag & flag) == 0)
continue; continue;
if (thing == '-') if (thing == '-')
@ -705,7 +705,7 @@ c_typeset(char **wp)
} }
} else { } else {
for (l = e->loc; l; l = l->next) { for (l = e->loc; l; l = l->next) {
for (p = tsort(&l->vars); (vp = *p++); ) { for (p = ktsort(&l->vars); (vp = *p++); ) {
struct tbl *tvp; struct tbl *tvp;
int any_set = 0; int any_set = 0;
/* /*
@ -874,7 +874,7 @@ c_alias(char **wp)
if (*wp == NULL) { if (*wp == NULL) {
struct tbl *ap, **p; struct tbl *ap, **p;
for (p = tsort(t); (ap = *p++) != NULL; ) for (p = ktsort(t); (ap = *p++) != NULL; )
if ((ap->flag & (ISSET|xflag)) == (ISSET|xflag)) { if ((ap->flag & (ISSET|xflag)) == (ISSET|xflag)) {
if (pflag) if (pflag)
shf_puts("alias ", shl_stdout); shf_puts("alias ", shl_stdout);
@ -898,7 +898,7 @@ c_alias(char **wp)
alias = str_nsave(alias, val++ - alias, ATEMP); alias = str_nsave(alias, val++ - alias, ATEMP);
h = hash(alias); h = hash(alias);
if (val == NULL && !tflag && !xflag) { if (val == NULL && !tflag && !xflag) {
ap = tsearch(t, alias, h); ap = ktsearch(t, alias, h);
if (ap != NULL && (ap->flag&ISSET)) { if (ap != NULL && (ap->flag&ISSET)) {
if (pflag) if (pflag)
shf_puts("alias ", shl_stdout); shf_puts("alias ", shl_stdout);
@ -914,7 +914,7 @@ c_alias(char **wp)
} }
continue; continue;
} }
ap = tenter(t, alias, h); ap = ktenter(t, alias, h);
ap->type = tflag ? CTALIAS : CALIAS; ap->type = tflag ? CTALIAS : CALIAS;
/* Are we setting the value or just some flags? */ /* Are we setting the value or just some flags? */
if ((val && !tflag) || (!val && tflag && !Uflag)) { if ((val && !tflag) || (!val && tflag && !Uflag)) {
@ -968,7 +968,7 @@ c_unalias(char **wp)
wp += builtin_opt.optind; wp += builtin_opt.optind;
for (; *wp != NULL; wp++) { for (; *wp != NULL; wp++) {
ap = tsearch(t, *wp, hash(*wp)); ap = ktsearch(t, *wp, hash(*wp));
if (ap == NULL) { if (ap == NULL) {
rv = 1; /* POSIX */ rv = 1; /* POSIX */
continue; continue;
@ -983,7 +983,7 @@ c_unalias(char **wp)
if (all) { if (all) {
struct tstate ts; struct tstate ts;
for (twalk(&ts, t); (ap = tnext(&ts)); ) { for (ktwalk(&ts, t); (ap = ktnext(&ts)); ) {
if (ap->flag&ALLOC) { if (ap->flag&ALLOC) {
ap->flag &= ~(ALLOC|ISSET); ap->flag &= ~(ALLOC|ISSET);
afree((void*)ap->val.s, APERM); afree((void*)ap->val.s, APERM);

View File

@ -1,9 +1,9 @@
/* $OpenBSD: history.c,v 1.31 2005/07/31 16:12:52 espie Exp $ */ /* $OpenBSD: history.c,v 1.32 2005/12/11 18:53:51 deraadt Exp $ */
/* $OpenBSD: trap.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: trap.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.13 2005/11/22 18:40:42 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.14 2006/01/29 20:04:51 tg Exp $");
static int histfd; static int histfd;
static int hsize; static int hsize;
@ -25,7 +25,6 @@ static char **hist_get_oldest(void);
static void histbackup(void); static void histbackup(void);
static char **current; /* current position in history[] */ static char **current; /* current position in history[] */
static int curpos; /* current index in history[] */
static char *hname; /* current name of history file */ static char *hname; /* current name of history file */
static int hstarted; /* set after hist_init() called */ static int hstarted; /* set after hist_init() called */
static Source *hist_source; static Source *hist_source;
@ -432,12 +431,6 @@ histpos(void)
return current; return current;
} }
int
histN(void)
{
return curpos;
}
int int
histnum(int n) histnum(int n)
{ {
@ -445,11 +438,9 @@ histnum(int n)
if (n < 0 || n >= last) { if (n < 0 || n >= last) {
current = histptr; current = histptr;
curpos = last;
return last; return last;
} else { } else {
current = &history[n]; current = &history[n];
curpos = n;
return n; return n;
} }
} }

8
lex.c
View File

@ -1,8 +1,8 @@
/* $OpenBSD: lex.c,v 1.37 2005/09/11 18:02:27 otto Exp $ */ /* $OpenBSD: lex.c,v 1.38 2005/12/11 20:31:21 otto Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.10 2005/11/22 18:40:43 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.11 2006/01/29 20:04:52 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. */
@ -710,12 +710,12 @@ Done:
int h = hash(ident); int h = hash(ident);
/* { */ /* { */
if ((cf & KEYWORD) && (p = tsearch(&keywords, ident, h)) && if ((cf & KEYWORD) && (p = ktsearch(&keywords, ident, h)) &&
(!(cf & ESACONLY) || p->val.i == ESAC || p->val.i == '}')) { (!(cf & ESACONLY) || p->val.i == ESAC || p->val.i == '}')) {
afree(yylval.cp, ATEMP); afree(yylval.cp, ATEMP);
return p->val.i; return p->val.i;
} }
if ((cf & ALIAS) && (p = tsearch(&aliases, ident, h)) && if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
(p->flag & ISSET)) { (p->flag & ISSET)) {
Source *s; Source *s;

36
main.c
View File

@ -1,12 +1,12 @@
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: main.c,v 1.40 2005/12/11 20:31:21 otto Exp $ */
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: table.c,v 1.11 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: table.c,v 1.12 2005/12/11 20:31:21 otto Exp $ */
#define EXTERN /* define EXTERNs in sh.h */ #define EXTERN /* define EXTERNs in sh.h */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.31 2005/11/22 18:40:43 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.32 2006/01/29 20:04:52 tg Exp $");
#define MKSH_VERSION "@(#)MIRBSD KSH R26 2005/11/22" #define MKSH_VERSION "@(#)MIRBSD KSH R26 2005/11/22"
@ -99,15 +99,15 @@ main(int argc, char *argv[])
coproc_init(); coproc_init();
/* set up variable and command dictionaries */ /* set up variable and command dictionaries */
tinit(&taliases, APERM, 0); ktinit(&taliases, APERM, 0);
tinit(&aliases, APERM, 0); ktinit(&aliases, APERM, 0);
tinit(&homedirs, APERM, 0); ktinit(&homedirs, APERM, 0);
/* define shell keywords */ /* define shell keywords */
initkeywords(); initkeywords();
/* define built-in commands */ /* define built-in commands */
tinit(&builtins, APERM, 64); /* must be 2^n (currently 40 builtins) */ ktinit(&builtins, APERM, 64); /* must be 2^n (currently 40 builtins) */
for (i = 0; shbuiltins[i].name != NULL; i++) for (i = 0; shbuiltins[i].name != NULL; i++)
builtin(shbuiltins[i].name, shbuiltins[i].func); builtin(shbuiltins[i].name, shbuiltins[i].func);
for (i = 0; kshbuiltins[i].name != NULL; i++) for (i = 0; kshbuiltins[i].name != NULL; i++)
@ -659,14 +659,6 @@ remove_temps(struct temp *tp)
} }
} }
void
aerror(Area *ap __attribute__((unused)), const char *msg)
{
internal_errorf(1, "alloc: %s", msg);
errorf(null); /* this is never executed - keeps gcc quiet */
/*NOTREACHED*/
}
/* Initialize tty_fd. Used for saving/reseting tty modes upon /* Initialize tty_fd. Used for saving/reseting tty modes upon
* foreground job completion and for setting up tty process group. * foreground job completion and for setting up tty process group.
*/ */
@ -1094,7 +1086,7 @@ hash(const char *n)
} }
void void
tinit(struct table *tp, Area *ap, int tsize) ktinit(struct table *tp, Area *ap, int tsize)
{ {
tp->areap = ap; tp->areap = ap;
tp->tbls = NULL; tp->tbls = NULL;
@ -1139,7 +1131,7 @@ texpand(struct table *tp, int nsize)
/* name to enter */ /* name to enter */
/* hash(n) */ /* hash(n) */
struct tbl * struct tbl *
tsearch(struct table *tp, const char *n, unsigned int h) ktsearch(struct table *tp, const char *n, unsigned int h)
{ {
struct tbl **pp, *p; struct tbl **pp, *p;
@ -1162,7 +1154,7 @@ tsearch(struct table *tp, const char *n, unsigned int h)
/* name to enter */ /* name to enter */
/* hash(n) */ /* hash(n) */
struct tbl * struct tbl *
tenter(struct table *tp, const char *n, unsigned int h) ktenter(struct table *tp, const char *n, unsigned int h)
{ {
struct tbl **pp, *p; struct tbl **pp, *p;
int len; int len;
@ -1200,20 +1192,20 @@ Search:
} }
void void
tdelete(struct tbl *p) ktdelete(struct tbl *p)
{ {
p->flag = 0; p->flag = 0;
} }
void void
twalk(struct tstate *ts, struct table *tp) ktwalk(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(struct tstate *ts) ktnext(struct tstate *ts)
{ {
while (--ts->left >= 0) { while (--ts->left >= 0) {
struct tbl *p = *ts->next++; struct tbl *p = *ts->next++;
@ -1230,7 +1222,7 @@ tnamecmp(void *p1, void *p2)
} }
struct tbl ** struct tbl **
tsort(struct table *tp) ktsort(struct table *tp)
{ {
int i; int i;
struct tbl **p, **sp, **dp; struct tbl **p, **sp, **dp;

15
mksh.1
View File

@ -1,5 +1,5 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.27 2006/01/27 10:59:30 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.28 2006/01/29 20:04:52 tg Exp $
.\" $OpenBSD: ksh.1,v 1.107 2005/11/16 12:49:21 jmc Exp $ .\" $OpenBSD: ksh.1,v 1.109 2005/12/06 20:40:02 jmc Exp $
.\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $ .\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $
.\" .\"
.Dd May 22, 2005 .Dd May 22, 2005
@ -1468,11 +1468,20 @@ If you don't have any non-printing characters, you're out of luck.
By the way, don't blame me for By the way, don't blame me for
this hack; it's in the original this hack; it's in the original
.Xr ksh88 1 . .Xr ksh88 1 .
The default is The default prompt is
.Sq $\ \& .Sq $\ \&
for non-root users, for non-root users,
.Sq #\ \& .Sq #\ \&
for root. for root.
If
.Nm
is invoked by root and
.Ev PS1
does not contain a
.Sq #
character, the default value will be used even if
.Ev PS1
already exists in the environment.
.Pp .Pp
Since Backslashes and other special characters may be Since Backslashes and other special characters may be
interpreted by the shell, to set interpreted by the shell, to set

31
sh.h
View File

@ -1,14 +1,14 @@
/* $OpenBSD: sh.h,v 1.28 2005/10/04 20:35:11 otto Exp $ */ /* $OpenBSD: sh.h,v 1.29 2005/12/11 18:53:51 deraadt Exp $ */
/* $OpenBSD: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: shf.h,v 1.6 2005/12/11 18:53:51 deraadt Exp $ */
/* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */ /* $OpenBSD: table.h,v 1.7 2005/12/11 20:31:21 otto Exp $ */
/* $OpenBSD: tree.h,v 1.10 2005/03/28 21:28:22 deraadt Exp $ */ /* $OpenBSD: tree.h,v 1.10 2005/03/28 21:28:22 deraadt Exp $ */
/* $OpenBSD: expand.h,v 1.6 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: expand.h,v 1.6 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: lex.h,v 1.10 2005/09/11 18:02:27 otto Exp $ */ /* $OpenBSD: lex.h,v 1.10 2005/09/11 18:02:27 otto Exp $ */
/* $OpenBSD: proto.h,v 1.27 2005/10/06 06:39:36 otto Exp $ */ /* $OpenBSD: proto.h,v 1.29 2005/12/11 20:31:21 otto Exp $ */
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.23 2005/11/22 18:40:43 tg Exp $" #define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.24 2006/01/29 20:04:53 tg Exp $"
#if defined(__INTERIX) && !defined(_ALL_SOURCE) #if defined(__INTERIX) && !defined(_ALL_SOURCE)
#define _ALL_SOURCE #define _ALL_SOURCE
@ -227,7 +227,6 @@ EXTERN char shell_flags [FNFLAGS];
EXTERN char null [] I__(""); /* null value for variable */ EXTERN char null [] I__(""); /* null value for variable */
EXTERN char space [] I__(" "); EXTERN char space [] I__(" ");
EXTERN char newline [] I__("\n"); EXTERN char newline [] I__("\n");
EXTERN char slash [] I__("/");
enum temp_type { enum temp_type {
TT_HEREDOC_EXP, /* expanded heredoc */ TT_HEREDOC_EXP, /* expanded heredoc */
@ -585,7 +584,7 @@ struct block {
#define BF_DOGETOPTS BIT(0) /* save/restore getopts state */ #define BF_DOGETOPTS BIT(0) /* save/restore getopts state */
/* /*
* Used by twalk() and tnext() routines. * Used by ktwalk() and ktnext() routines.
*/ */
struct tstate { struct tstate {
int left; int left;
@ -1048,7 +1047,6 @@ int c_fc(char **);
void sethistsize(int); void sethistsize(int);
void sethistfile(const char *); void sethistfile(const char *);
char ** histpos(void); char ** histpos(void);
int histN(void);
int histnum(int); int histnum(int);
int findhist(int, int, const char *, int); int findhist(int, int, const char *, int);
int findhistrel(const char *); int findhistrel(const char *);
@ -1100,7 +1098,6 @@ void newenv(int);
void quitenv(struct shf *); void quitenv(struct shf *);
void cleanup_parents_env(void); void cleanup_parents_env(void);
void cleanup_proc_env(void); void cleanup_proc_env(void);
void aerror(Area *, const char *) __attribute__((__noreturn__));
void errorf(const char *, ...) void errorf(const char *, ...)
__attribute__((__noreturn__, __format__ (printf, 1, 2))); __attribute__((__noreturn__, __format__ (printf, 1, 2)));
void warningf(int, const char *, ...) void warningf(int, const char *, ...)
@ -1130,13 +1127,13 @@ int coproc_getfd(int, const char **);
void coproc_cleanup(int); void coproc_cleanup(int);
struct temp *maketemp(Area *, Temp_type, struct temp **); struct temp *maketemp(Area *, Temp_type, struct temp **);
unsigned int hash(const char *); unsigned int hash(const char *);
void tinit(struct table *, Area *, int); void ktinit(struct table *, Area *, int);
struct tbl * tsearch(struct table *, const char *, unsigned int); struct tbl * ktsearch(struct table *, const char *, unsigned int);
struct tbl * tenter(struct table *, const char *, unsigned int); struct tbl * ktenter(struct table *, const char *, unsigned int);
void tdelete(struct tbl *); void ktdelete(struct tbl *);
void twalk(struct tstate *, struct table *); void ktwalk(struct tstate *, struct table *);
struct tbl * tnext(struct tstate *); struct tbl * ktnext(struct tstate *);
struct tbl ** tsort(struct table *); struct tbl ** ktsort(struct table *);
/* misc.c */ /* misc.c */
void setctypes(const char *, int); void setctypes(const char *, int);
void initctypes(void); void initctypes(void);
@ -1176,9 +1173,7 @@ struct shf *shf_sopen(char *, int, int, struct shf *);
int shf_close(struct shf *); int shf_close(struct shf *);
int shf_fdclose(struct shf *); int shf_fdclose(struct shf *);
char * shf_sclose(struct shf *); char * shf_sclose(struct shf *);
int shf_finish(struct shf *);
int shf_flush(struct shf *); int shf_flush(struct shf *);
int shf_seek(struct shf *, off_t, int);
int shf_read(char *, int, struct shf *); int shf_read(char *, int, struct shf *);
char * shf_getse(char *, int, struct shf *); char * shf_getse(char *, int, struct shf *);
int shf_getchar(struct shf *s); int shf_getchar(struct shf *s);

64
shf.c
View File

@ -1,8 +1,8 @@
/* $OpenBSD: shf.c,v 1.13 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: shf.c,v 1.14 2005/12/11 18:53:51 deraadt Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.3 2005/11/22 18:40:43 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/shf.c,v 1.4 2006/01/29 20:04:53 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 */
@ -260,22 +260,6 @@ shf_sclose(struct shf *shf)
return (char *) s; return (char *) s;
} }
/* Flush and free file structure, don't close file descriptor */
int
shf_finish(struct shf *shf)
{
int ret = 0;
if (shf->fd >= 0)
ret = shf_flush(shf);
if (shf->flags & SHF_ALLOCS)
afree(shf, shf->areap);
else if (shf->flags & SHF_ALLOCB)
afree(shf->buf, shf->areap);
return ret;
}
/* Un-read what has been read but not examined, or write what has been /* Un-read what has been read but not examined, or write what has been
* buffered. Returns 0 for success, EOF for (write) error. * buffered. Returns 0 for success, EOF for (write) error.
*/ */
@ -432,50 +416,6 @@ shf_fillbuf(struct shf *shf)
return 0; return 0;
} }
/* Seek to a new position in the file. If writing, flushes the buffer
* first. If reading, optimizes small relative seeks that stay inside the
* buffer. Returns 0 for success, EOF otherwise.
*/
int
shf_seek(struct shf *shf, off_t where, int from)
{
if (shf->fd < 0) {
errno = EINVAL;
return EOF;
}
if (shf->flags & SHF_ERROR) {
errno = shf->errno_;
return EOF;
}
if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF)
return EOF;
if (shf->flags & SHF_READING) {
if (from == SEEK_CUR &&
(where < 0 ? -where >= shf->rbsize - shf->rnleft :
where < shf->rnleft)) {
shf->rnleft -= where;
shf->rp += where;
return 0;
}
shf->rnleft = 0;
shf->rp = shf->buf;
}
shf->flags &= ~(SHF_EOF | SHF_READING | SHF_WRITING);
if (lseek(shf->fd, where, from) < 0) {
shf->errno_ = errno;
shf->flags |= SHF_ERROR;
return EOF;
}
return 0;
}
/* Read a buffer from shf. Returns the number of bytes read into buf, /* Read a buffer from shf. Returns the number of bytes read into buf,
* if no bytes were read, returns 0 if end of file was seen, EOF if * if no bytes were read, returns 0 if end of file was seen, EOF if
* a read error occurred. * a read error occurred.

8
syn.c
View File

@ -1,8 +1,8 @@
/* $OpenBSD: syn.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: syn.c,v 1.23 2005/12/11 20:31:21 otto Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.4 2005/11/22 18:40:44 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/syn.c,v 1.5 2006/01/29 20:04:53 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) */
@ -659,10 +659,10 @@ initkeywords(void)
struct tokeninfo const *tt; struct tokeninfo const *tt;
struct tbl *p; struct tbl *p;
tinit(&keywords, APERM, 32); /* must be 2^n (currently 20 keywords) */ ktinit(&keywords, APERM, 32); /* must be 2^n (currently 20 keywords) */
for (tt = tokentab; tt->name; tt++) { for (tt = tokentab; tt->name; tt++) {
if (tt->reserved) { if (tt->reserved) {
p = tenter(&keywords, tt->name, hash(tt->name)); p = ktenter(&keywords, tt->name, hash(tt->name));
p->flag |= DEFINED|ISSET; p->flag |= DEFINED|ISSET;
p->type = CKEYWD; p->type = CKEYWD;
p->val.i = tt->val; p->val.i = tt->val;

28
var.c
View File

@ -1,8 +1,8 @@
/* $OpenBSD: var.c,v 1.27 2005/10/08 18:02:59 otto Exp $ */ /* $OpenBSD: var.c,v 1.28 2005/12/11 20:31:21 otto Exp $ */
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.12 2005/11/22 18:40:44 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.13 2006/01/29 20:04:54 tg Exp $");
/* /*
* Variables * Variables
@ -45,8 +45,8 @@ newblock(void)
l->argv = e->loc->argv; l->argv = e->loc->argv;
} }
l->exit = l->error = NULL; l->exit = l->error = NULL;
tinit(&l->vars, &l->area, 0); ktinit(&l->vars, &l->area, 0);
tinit(&l->funs, &l->area, 0); ktinit(&l->funs, &l->area, 0);
l->next = e->loc; l->next = e->loc;
e->loc = l; e->loc = l;
} }
@ -99,9 +99,9 @@ initvar(void)
int i; int i;
struct tbl *tp; struct tbl *tp;
tinit(&specials, APERM, 32); /* must be 2^n (currently 17 specials) */ ktinit(&specials, APERM, 32); /* must be 2^n (currently 17 specials) */
for (i = 0; names[i].name; i++) { for (i = 0; names[i].name; i++) {
tp = tenter(&specials, names[i].name, hash(names[i].name)); tp = ktenter(&specials, names[i].name, hash(names[i].name));
tp->flag = DEFINED|ISSET; tp->flag = DEFINED|ISSET;
tp->type = names[i].v; tp->type = names[i].v;
} }
@ -201,7 +201,7 @@ global(const char *n)
return vp; return vp;
} }
for (l = e->loc; ; l = l->next) { for (l = e->loc; ; l = l->next) {
vp = tsearch(&l->vars, n, h); vp = ktsearch(&l->vars, n, h);
if (vp != NULL) { if (vp != NULL) {
if (array) if (array)
return arraysearch(vp, val); return arraysearch(vp, val);
@ -211,7 +211,7 @@ global(const char *n)
if (l->next == NULL) if (l->next == NULL)
break; break;
} }
vp = tenter(&l->vars, n, h); vp = ktenter(&l->vars, n, h);
if (array) if (array)
vp = arraysearch(vp, val); vp = arraysearch(vp, val);
vp->flag |= DEFINED; vp->flag |= DEFINED;
@ -242,12 +242,12 @@ local(const char *n, bool copy)
vp->areap = ATEMP; vp->areap = ATEMP;
return vp; return vp;
} }
vp = tenter(&l->vars, n, h); vp = ktenter(&l->vars, n, h);
if (copy && !(vp->flag & DEFINED)) { if (copy && !(vp->flag & DEFINED)) {
struct block *ll = l; struct block *ll = l;
struct tbl *vq = NULL; struct tbl *vq = NULL;
while ((ll = ll->next) && !(vq = tsearch(&ll->vars, n, h))) while ((ll = ll->next) && !(vq = ktsearch(&ll->vars, n, h)))
; ;
if (vq) { if (vq) {
vp->flag |= vq->flag & vp->flag |= vq->flag &
@ -826,7 +826,7 @@ makenv(void)
/* unexport any redefined instances */ /* unexport any redefined instances */
for (l2 = l->next; l2 != NULL; l2 = l2->next) { for (l2 = l->next; l2 != NULL; l2 = l2->next) {
vp2 = tsearch(&l2->vars, vp->name, h); vp2 = ktsearch(&l2->vars, vp->name, h);
if (vp2 != NULL) if (vp2 != NULL)
vp2->flag &= ~EXPORT; vp2->flag &= ~EXPORT;
} }
@ -872,7 +872,7 @@ special(const char *name)
{ {
struct tbl *tp; struct tbl *tp;
tp = tsearch(&specials, name, hash(name)); tp = ktsearch(&specials, name, hash(name));
return tp && (tp->flag & ISSET) ? tp->type : V_NONE; return tp && (tp->flag & ISSET) ? tp->type : V_NONE;
} }
@ -882,9 +882,9 @@ unspecial(const char *name)
{ {
struct tbl *tp; struct tbl *tp;
tp = tsearch(&specials, name, hash(name)); tp = ktsearch(&specials, name, hash(name));
if (tp) if (tp)
tdelete(tp); ktdelete(tp);
} }
static time_t seconds; /* time SECONDS last set */ static time_t seconds; /* time SECONDS last set */