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: 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"
__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 */
typedef struct {
@ -760,7 +760,7 @@ glob_table(const char *pat, XPtrV *wp, struct table *tp)
struct tstate ts;
struct tbl *te;
for (twalk(&ts, tp); (te = tnext(&ts)); ) {
for (ktwalk(&ts, tp); (te = ktnext(&ts)); ) {
if (gmatchx(te->name, pat, false))
XPput(*wp, str_save(te->name, ATEMP));
}
@ -3568,7 +3568,7 @@ vi_cmd(int argcnt, const char *cmd)
/* lookup letter in alias list... */
alias[1] = cmd[1];
ap = tsearch(&aliases, alias, hash(alias));
ap = ktsearch(&aliases, alias, hash(alias));
if (!cmd[1] || !ap || !(ap->flag & ISSET))
return -1;
/* 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"
__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
@ -1181,7 +1181,7 @@ homedir(char *name)
{
struct tbl *ap;
ap = tenter(&homedirs, name, hash(name));
ap = ktenter(&homedirs, name, hash(name));
if (!(ap->flag & ISSET)) {
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"
__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 **,
int volatile);
@ -688,7 +688,7 @@ shcomexec(char **wp)
{
struct tbl *tp;
tp = tsearch(&builtins, *wp, hash(*wp));
tp = ktsearch(&builtins, *wp, hash(*wp));
if (tp == NULL)
internal_errorf(1, "shcomexec: %s", *wp);
return call_builtin(tp, wp);
@ -705,11 +705,11 @@ findfunc(const char *name, unsigned int h, int create)
struct tbl *tp = NULL;
for (l = e->loc; l; l = l->next) {
tp = tsearch(&l->funs, name, h);
tp = ktsearch(&l->funs, name, h);
if (tp)
break;
if (!l->next && create) {
tp = tenter(&l->funs, name, h);
tp = ktenter(&l->funs, name, h);
tp->flag = DEFINED;
tp->type = CFUNC;
tp->val.t = NULL;
@ -751,7 +751,7 @@ define(const char *name, struct op *t)
}
if (t == NULL) { /* undefine */
tdelete(tp);
ktdelete(tp);
return was_set ? 0 : 1;
}
@ -784,7 +784,7 @@ builtin(const char *name, int (*func) (char **))
break;
}
tp = tenter(&builtins, name, hash(name));
tp = ktenter(&builtins, name, hash(name));
tp->flag = DEFINED | flag;
tp->type = CSHELL;
tp->val.f = func;
@ -810,7 +810,7 @@ findcom(const char *name, int flags)
flags &= ~FC_FUNC;
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 regular builtins, then search path...
*/
@ -832,7 +832,7 @@ findcom(const char *name, int flags)
if (!tp && (flags & FC_UNREGBI) && tbi)
tp = tbi;
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->flag & ALLOC) {
tp->flag &= ~ALLOC;
@ -847,7 +847,7 @@ findcom(const char *name, int flags)
(flags & FC_PATH)) {
if (!tp) {
if (insert && !(flags & FC_DEFPATH)) {
tp = tenter(&taliases, name, h);
tp = ktenter(&taliases, name, h);
tp->type = CTALIAS;
} else {
tp = &temp;
@ -887,7 +887,7 @@ flushcom(int all) /* just relative or all */
struct tbl *tp;
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&ALLOC) {
tp->flag &= ~(ALLOC|ISSET);
@ -1227,7 +1227,7 @@ struct select_menu_info {
char *const *args;
int arg_width;
int num_width;
} info;
};
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_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 $ */
#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
c_cd(char **wp)
@ -424,9 +424,9 @@ c_whence(char **wp)
while ((vflag || ret == 0) && (id = *wp++) != NULL) {
tp = NULL;
if ((iam_whence || vflag) && !pflag)
tp = tsearch(&keywords, id, hash(id));
tp = ktsearch(&keywords, id, hash(id));
if (!tp && !pflag) {
tp = tsearch(&aliases, id, hash(id));
tp = ktsearch(&aliases, id, hash(id));
if (tp && !(tp->flag & ISSET))
tp = NULL;
}
@ -692,7 +692,7 @@ c_typeset(char **wp)
flag = fset | fclr; /* no difference at this point.. */
if (func) {
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)
continue;
if (thing == '-')
@ -705,7 +705,7 @@ c_typeset(char **wp)
}
} else {
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;
int any_set = 0;
/*
@ -874,7 +874,7 @@ c_alias(char **wp)
if (*wp == NULL) {
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 (pflag)
shf_puts("alias ", shl_stdout);
@ -898,7 +898,7 @@ c_alias(char **wp)
alias = str_nsave(alias, val++ - alias, ATEMP);
h = hash(alias);
if (val == NULL && !tflag && !xflag) {
ap = tsearch(t, alias, h);
ap = ktsearch(t, alias, h);
if (ap != NULL && (ap->flag&ISSET)) {
if (pflag)
shf_puts("alias ", shl_stdout);
@ -914,7 +914,7 @@ c_alias(char **wp)
}
continue;
}
ap = tenter(t, alias, h);
ap = ktenter(t, alias, h);
ap->type = tflag ? CTALIAS : CALIAS;
/* Are we setting the value or just some flags? */
if ((val && !tflag) || (!val && tflag && !Uflag)) {
@ -968,7 +968,7 @@ c_unalias(char **wp)
wp += builtin_opt.optind;
for (; *wp != NULL; wp++) {
ap = tsearch(t, *wp, hash(*wp));
ap = ktsearch(t, *wp, hash(*wp));
if (ap == NULL) {
rv = 1; /* POSIX */
continue;
@ -983,7 +983,7 @@ c_unalias(char **wp)
if (all) {
struct tstate ts;
for (twalk(&ts, t); (ap = tnext(&ts)); ) {
for (ktwalk(&ts, t); (ap = ktnext(&ts)); ) {
if (ap->flag&ALLOC) {
ap->flag &= ~(ALLOC|ISSET);
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 $ */
#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 hsize;
@ -25,7 +25,6 @@ static char **hist_get_oldest(void);
static void histbackup(void);
static char **current; /* current position in history[] */
static int curpos; /* current index in history[] */
static char *hname; /* current name of history file */
static int hstarted; /* set after hist_init() called */
static Source *hist_source;
@ -432,12 +431,6 @@ histpos(void)
return current;
}
int
histN(void)
{
return curpos;
}
int
histnum(int n)
{
@ -445,11 +438,9 @@ histnum(int n)
if (n < 0 || n >= last) {
current = histptr;
curpos = last;
return last;
} else {
current = &history[n];
curpos = 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"
__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
* needed for each particular state. */
@ -710,12 +710,12 @@ Done:
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 == '}')) {
afree(yylval.cp, ATEMP);
return p->val.i;
}
if ((cf & ALIAS) && (p = tsearch(&aliases, ident, h)) &&
if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
(p->flag & ISSET)) {
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: 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 */
#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"
@ -99,15 +99,15 @@ main(int argc, char *argv[])
coproc_init();
/* set up variable and command dictionaries */
tinit(&taliases, APERM, 0);
tinit(&aliases, APERM, 0);
tinit(&homedirs, APERM, 0);
ktinit(&taliases, APERM, 0);
ktinit(&aliases, APERM, 0);
ktinit(&homedirs, APERM, 0);
/* define shell keywords */
initkeywords();
/* 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++)
builtin(shbuiltins[i].name, shbuiltins[i].func);
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
* foreground job completion and for setting up tty process group.
*/
@ -1094,7 +1086,7 @@ hash(const char *n)
}
void
tinit(struct table *tp, Area *ap, int tsize)
ktinit(struct table *tp, Area *ap, int tsize)
{
tp->areap = ap;
tp->tbls = NULL;
@ -1139,7 +1131,7 @@ texpand(struct table *tp, int nsize)
/* name to enter */
/* hash(n) */
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;
@ -1162,7 +1154,7 @@ tsearch(struct table *tp, const char *n, unsigned int h)
/* name to enter */
/* hash(n) */
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;
int len;
@ -1200,20 +1192,20 @@ Search:
}
void
tdelete(struct tbl *p)
ktdelete(struct tbl *p)
{
p->flag = 0;
}
void
twalk(struct tstate *ts, struct table *tp)
ktwalk(struct tstate *ts, struct table *tp)
{
ts->left = tp->size;
ts->next = tp->tbls;
}
struct tbl *
tnext(struct tstate *ts)
ktnext(struct tstate *ts)
{
while (--ts->left >= 0) {
struct tbl *p = *ts->next++;
@ -1230,7 +1222,7 @@ tnamecmp(void *p1, void *p2)
}
struct tbl **
tsort(struct table *tp)
ktsort(struct table *tp)
{
int i;
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 $
.\" $OpenBSD: ksh.1,v 1.107 2005/11/16 12:49:21 jmc Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.28 2006/01/29 20:04:52 tg 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 $
.\"
.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
this hack; it's in the original
.Xr ksh88 1 .
The default is
The default prompt is
.Sq $\ \&
for non-root users,
.Sq #\ \&
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
Since Backslashes and other special characters may be
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: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */
/* $OpenBSD: sh.h,v 1.29 2005/12/11 18:53:51 deraadt Exp $ */
/* $OpenBSD: shf.h,v 1.6 2005/12/11 18:53:51 deraadt 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: 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: 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: 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)
#define _ALL_SOURCE
@ -227,7 +227,6 @@ EXTERN char shell_flags [FNFLAGS];
EXTERN char null [] I__(""); /* null value for variable */
EXTERN char space [] I__(" ");
EXTERN char newline [] I__("\n");
EXTERN char slash [] I__("/");
enum temp_type {
TT_HEREDOC_EXP, /* expanded heredoc */
@ -585,7 +584,7 @@ struct block {
#define BF_DOGETOPTS BIT(0) /* save/restore getopts state */
/*
* Used by twalk() and tnext() routines.
* Used by ktwalk() and ktnext() routines.
*/
struct tstate {
int left;
@ -1048,7 +1047,6 @@ int c_fc(char **);
void sethistsize(int);
void sethistfile(const char *);
char ** histpos(void);
int histN(void);
int histnum(int);
int findhist(int, int, const char *, int);
int findhistrel(const char *);
@ -1100,7 +1098,6 @@ void newenv(int);
void quitenv(struct shf *);
void cleanup_parents_env(void);
void cleanup_proc_env(void);
void aerror(Area *, const char *) __attribute__((__noreturn__));
void errorf(const char *, ...)
__attribute__((__noreturn__, __format__ (printf, 1, 2)));
void warningf(int, const char *, ...)
@ -1130,13 +1127,13 @@ int coproc_getfd(int, const char **);
void coproc_cleanup(int);
struct temp *maketemp(Area *, Temp_type, struct temp **);
unsigned int hash(const char *);
void tinit(struct table *, Area *, int);
struct tbl * tsearch(struct table *, const char *, unsigned int);
struct tbl * tenter(struct table *, const char *, unsigned int);
void tdelete(struct tbl *);
void twalk(struct tstate *, struct table *);
struct tbl * tnext(struct tstate *);
struct tbl ** tsort(struct table *);
void ktinit(struct table *, Area *, int);
struct tbl * ktsearch(struct table *, const char *, unsigned int);
struct tbl * ktenter(struct table *, const char *, unsigned int);
void ktdelete(struct tbl *);
void ktwalk(struct tstate *, struct table *);
struct tbl * ktnext(struct tstate *);
struct tbl ** ktsort(struct table *);
/* misc.c */
void setctypes(const char *, int);
void initctypes(void);
@ -1176,9 +1173,7 @@ struct shf *shf_sopen(char *, int, int, struct shf *);
int shf_close(struct shf *);
int shf_fdclose(struct shf *);
char * shf_sclose(struct shf *);
int shf_finish(struct shf *);
int shf_flush(struct shf *);
int shf_seek(struct shf *, off_t, int);
int shf_read(char *, int, struct shf *);
char * shf_getse(char *, int, struct shf *);
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"
__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() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -260,22 +260,6 @@ shf_sclose(struct shf *shf)
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
* buffered. Returns 0 for success, EOF for (write) error.
*/
@ -432,50 +416,6 @@ shf_fillbuf(struct shf *shf)
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,
* if no bytes were read, returns 0 if end of file was seen, EOF if
* 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"
__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 {
int start_token; /* token than began nesting (eg, FOR) */
@ -659,10 +659,10 @@ initkeywords(void)
struct tokeninfo const *tt;
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++) {
if (tt->reserved) {
p = tenter(&keywords, tt->name, hash(tt->name));
p = ktenter(&keywords, tt->name, hash(tt->name));
p->flag |= DEFINED|ISSET;
p->type = CKEYWD;
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"
__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
@ -45,8 +45,8 @@ newblock(void)
l->argv = e->loc->argv;
}
l->exit = l->error = NULL;
tinit(&l->vars, &l->area, 0);
tinit(&l->funs, &l->area, 0);
ktinit(&l->vars, &l->area, 0);
ktinit(&l->funs, &l->area, 0);
l->next = e->loc;
e->loc = l;
}
@ -99,9 +99,9 @@ initvar(void)
int i;
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++) {
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->type = names[i].v;
}
@ -201,7 +201,7 @@ global(const char *n)
return vp;
}
for (l = e->loc; ; l = l->next) {
vp = tsearch(&l->vars, n, h);
vp = ktsearch(&l->vars, n, h);
if (vp != NULL) {
if (array)
return arraysearch(vp, val);
@ -211,7 +211,7 @@ global(const char *n)
if (l->next == NULL)
break;
}
vp = tenter(&l->vars, n, h);
vp = ktenter(&l->vars, n, h);
if (array)
vp = arraysearch(vp, val);
vp->flag |= DEFINED;
@ -242,12 +242,12 @@ local(const char *n, bool copy)
vp->areap = ATEMP;
return vp;
}
vp = tenter(&l->vars, n, h);
vp = ktenter(&l->vars, n, h);
if (copy && !(vp->flag & DEFINED)) {
struct block *ll = l;
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) {
vp->flag |= vq->flag &
@ -826,7 +826,7 @@ makenv(void)
/* unexport any redefined instances */
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)
vp2->flag &= ~EXPORT;
}
@ -872,7 +872,7 @@ special(const char *name)
{
struct tbl *tp;
tp = tsearch(&specials, name, hash(name));
tp = ktsearch(&specials, name, hash(name));
return tp && (tp->flag & ISSET) ? tp->type : V_NONE;
}
@ -882,9 +882,9 @@ unspecial(const char *name)
{
struct tbl *tp;
tp = tsearch(&specials, name, hash(name));
tp = ktsearch(&specials, name, hash(name));
if (tp)
tdelete(tp);
ktdelete(tp);
}
static time_t seconds; /* time SECONDS last set */