From: Christos Zoulas Date: Sat, 31 Aug 1991 12:23:49 +0000 (-0800) Subject: Bugfix for loops in aliases. X-Git-Tag: BSD-4_4-Snapshot-Development~9474 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/c4a583973d8d81f6ac5e9673f67b880be88117bb?hp=2301102024fa768a705cb4628b62d5663a24c68b Bugfix for loops in aliases. SCCS-vsn: bin/csh/csh.c 5.29 SCCS-vsn: bin/csh/csh.h 5.19 SCCS-vsn: bin/csh/func.c 5.24 SCCS-vsn: bin/csh/lex.c 5.20 SCCS-vsn: bin/csh/extern.h 5.7 --- diff --git a/usr/src/bin/csh/csh.c b/usr/src/bin/csh/csh.c index acbcdaf5d5..15b360fb3e 100644 --- a/usr/src/bin/csh/csh.c +++ b/usr/src/bin/csh/csh.c @@ -12,7 +12,7 @@ char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)csh.c 5.28 (Berkeley) %G%"; +static char sccsid[] = "@(#)csh.c 5.29 (Berkeley) %G%"; #endif /* not lint */ #include @@ -938,7 +938,7 @@ process(catch) * read fresh stuff. Otherwise, we are rereading input and don't * need or want to prompt. */ - if (fseekp == feobp) + if (aret == F_SEEK && fseekp == feobp) printprompt(); (void) fflush(cshout); } diff --git a/usr/src/bin/csh/csh.h b/usr/src/bin/csh/csh.h index bcf9da8a63..ce09aedc48 100644 --- a/usr/src/bin/csh/csh.h +++ b/usr/src/bin/csh/csh.h @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)csh.h 5.18 (Berkeley) %G% + * @(#)csh.h 5.19 (Berkeley) %G% */ /* @@ -209,6 +209,23 @@ struct Bin { Char **Bfbuf; /* The array of buffer blocks */ } B; +/* + * This structure allows us to seek inside aliases + */ +struct Ain { + int type; +#define I_SEEK -1 /* Invalid seek */ +#define A_SEEK 0 /* Alias seek */ +#define F_SEEK 1 /* File seek */ +#define E_SEEK 2 /* Eval seek */ + off_t f_seek; + Char **a_seek; +} ; +extern int aret; /* What was the last character returned */ +#define SEEKEQ(a, b) ((a)->type == (b)->type && \ + (a)->f_seek == (b)->f_seek && \ + (a)->a_seek == (b)->a_seek) + #define fseekp B.Bfseekp #define fbobp B.Bfbobp #define feobp B.Bfeobp @@ -220,7 +237,7 @@ struct Bin { * For whiles, in particular, it reseeks to the beginning of the * line the while was on; hence the while placement restrictions. */ -off_t lineloc; +struct Ain lineloc; bool cantell; /* Is current source tellable ? */ @@ -353,8 +370,8 @@ extern int nsrchn; * input. For foreach (fe), the word list is attached here. */ struct whyle { - off_t w_start; /* Point to restart loop */ - off_t w_end; /* End of loop (0 if unknown) */ + struct Ain w_start; /* Point to restart loop */ + struct Ain w_end; /* End of loop (0 if unknown) */ Char **w_fe, **w_fe0; /* Current/initial wordlist for fe */ Char *w_fename; /* Name for fe */ struct whyle *w_next; /* Next (more outer) loop */ diff --git a/usr/src/bin/csh/extern.h b/usr/src/bin/csh/extern.h index a5e2fdfe9d..7c10d0fd30 100644 --- a/usr/src/bin/csh/extern.h +++ b/usr/src/bin/csh/extern.h @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)extern.h 5.6 (Berkeley) %G% + * @(#)extern.h 5.7 (Berkeley) %G% */ #include @@ -152,7 +152,8 @@ void savehist __P((struct wordent *)); * lex.c */ void addla __P((Char *)); -void bseek __P((off_t)); +void bseek __P((struct Ain *)); +void btell __P((struct Ain *)); void btoeof __P((void)); void copylex __P((struct wordent *, struct wordent *)); Char *domod __P((Char *, int)); diff --git a/usr/src/bin/csh/func.c b/usr/src/bin/csh/func.c index 72bfd0050b..d3fe63de42 100644 --- a/usr/src/bin/csh/func.c +++ b/usr/src/bin/csh/func.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)func.c 5.23 (Berkeley) %G%"; +static char sccsid[] = "@(#)func.c 5.24 (Berkeley) %G%"; #endif /* not lint */ #include @@ -309,12 +309,12 @@ dogoto(v, t) */ zlast = T_GOTO; for (wp = whyles; wp; wp = wp->w_next) - if (wp->w_end == 0) { + if (wp->w_end.type == I_SEEK) { search(T_BREAK, 0, NULL); - wp->w_end = fseekp; + btell(&wp->w_end); } else - bseek(wp->w_end); + bseek(&wp->w_end); search(T_GOTO, 0, lp = globone(v[1], G_ERROR)); xfree((ptr_t) lp); /* @@ -407,7 +407,7 @@ doforeach(v, t) nwp = (struct whyle *) xcalloc(1, sizeof *nwp); nwp->w_fe = nwp->w_fe0 = v; gargv = 0; - nwp->w_start = fseekp; + btell(&nwp->w_start); nwp->w_fename = Strsave(cp); nwp->w_next = whyles; whyles = nwp; @@ -427,7 +427,7 @@ dowhile(v, t) struct command *t; { register int status; - register bool again = whyles != 0 && whyles->w_start == lineloc && + register bool again = whyles != 0 && SEEKEQ(&whyles->w_start, &lineloc) && whyles->w_fename == 0; v++; @@ -446,7 +446,7 @@ dowhile(v, t) (struct whyle *) xcalloc(1, sizeof(*nwp)); nwp->w_start = lineloc; - nwp->w_end = 0; + nwp->w_end.type = I_SEEK; nwp->w_next = whyles; whyles = nwp; zlast = T_WHILE; @@ -467,14 +467,14 @@ dowhile(v, t) static void preread() { - whyles->w_end = -1; + whyles->w_end.type = I_SEEK; if (setintr) (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT)); search(T_BREAK, 0, NULL); /* read the expression in */ if (setintr) (void) sigblock(sigmask(SIGINT)); - whyles->w_end = fseekp; + btell(&whyles->w_end); } void @@ -485,7 +485,7 @@ doend(v, t) { if (!whyles) stderror(ERR_NAME | ERR_NOTWHILE); - whyles->w_end = fseekp; + btell(&whyles->w_end); doagain(); } @@ -505,7 +505,7 @@ doagain() { /* Repeating a while is simple */ if (whyles->w_fename == 0) { - bseek(whyles->w_start); + bseek(&whyles->w_start); return; } /* @@ -518,7 +518,7 @@ doagain() return; } set(whyles->w_fename, Strsave(*whyles->w_fe++)); - bseek(whyles->w_start); + bseek(&whyles->w_start); } void @@ -593,10 +593,14 @@ search(type, level, goal) Stype = type; Sgoal = goal; - if (type == T_GOTO) - bseek((off_t) 0); + if (type == T_GOTO) { + struct Ain a; + a.type = F_SEEK; + a.f_seek = 0; + bseek(&a); + } do { - if (intty && fseekp == feobp) + if (intty && fseekp == feobp && aret == F_SEEK) (void) fprintf(cshout, "? "), (void) fflush(cshout); aword[0] = 0; (void) getword(aword); @@ -790,32 +794,40 @@ keyword(wp) static void toend() { - if (whyles->w_end == 0) { + if (whyles->w_end.type == I_SEEK) { search(T_BREAK, 0, NULL); - whyles->w_end = fseekp - 1; + btell(&whyles->w_end); + whyles->w_end.f_seek--; } else - bseek(whyles->w_end); + bseek(&whyles->w_end); wfree(); } void wfree() { - long o = fseekp; + struct Ain o; + struct whyle *nwp; + btell(&o); + + if (o.type != F_SEEK) + return; - while (whyles) { + for (; whyles; whyles = nwp) { register struct whyle *wp = whyles; - register struct whyle *nwp = wp->w_next; + nwp = wp->w_next; + if (wp->w_start.type != F_SEEK || wp->w_end.type != F_SEEK) + continue; - if (o >= wp->w_start && (wp->w_end == 0 || o < wp->w_end)) + if (o.f_seek >= wp->w_start.f_seek && + (wp->w_end.f_seek == 0 || o.f_seek < wp->w_end.f_seek)) break; if (wp->w_fe0) blkfree(wp->w_fe0); if (wp->w_fename) xfree((ptr_t) wp->w_fename); xfree((ptr_t) wp); - whyles = nwp; } } @@ -1193,6 +1205,8 @@ getval(lp, v) badscal: stderror(ERR_NAME | ERR_SCALEF); } + if ((f + 0.5) >= (float) 0x7fffffff || (f + 0.5) < (float) 0x80000000) + stderror(ERR_NAME | ERR_SCALEF); return ((RLIM_TYPE) (f + 0.5)); } diff --git a/usr/src/bin/csh/lex.c b/usr/src/bin/csh/lex.c index 50a97fdeab..dcc9d43eab 100644 --- a/usr/src/bin/csh/lex.c +++ b/usr/src/bin/csh/lex.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)lex.c 5.19 (Berkeley) %G%"; +static char sccsid[] = "@(#)lex.c 5.20 (Berkeley) %G%"; #endif /* not lint */ #include @@ -81,6 +81,7 @@ static int exclc = 0; /* "Globp" for alias resubstitution */ static Char *alvecp = NULL; +int aret = F_SEEK; /* * Labuf implements a general buffer for lookahead during lexical operations. @@ -118,10 +119,10 @@ lex(hp) register struct wordent *wdp; int c; - lineloc = fseekp; + btell(&lineloc); hp->next = hp->prev = hp; hp->word = STRNULL; - alvecp = 0, hadhist = 0; + hadhist = 0; do c = readc(0); while (c == ' ' || c == '\t'); @@ -1090,7 +1091,7 @@ gethent(sc) } np = lhsb; event = 0; - while (!any(": \t\\\n}'\"", c)) { + while (!cmap(c, _META | _Q | _Q1) && !any("{}:", c)) { if (event != -1 && Isdigit(c)) event = event * 10 + c - '0'; else @@ -1231,17 +1232,25 @@ readc(wanteof) register int c; static sincereal; + aret = F_SEEK; if (c = peekread) { peekread = 0; return (c); } top: + aret = F_SEEK; if (alvecp) { - if (c = *alvecp++) + aret = A_SEEK; + if (c = *alvecp++) return (c); if (alvec && *alvec) { - alvecp = *alvec++; - return (' '); + alvecp = *alvec++; + return (' '); + } + else { + aret = F_SEEK; + alvecp = NULL; + return('\n'); } } if (alvec) { @@ -1253,12 +1262,14 @@ top: return ('\n'); } if (evalp) { + aret = E_SEEK; if (c = *evalp++) return (c); - if (*evalvec) { + if (evalvec && *evalvec) { evalp = *evalvec++; return (' '); } + aret = F_SEEK; evalp = 0; } if (evalvec) { @@ -1461,29 +1472,46 @@ bfree() void bseek(l) - off_t l; - + struct Ain *l; { + switch (aret = l->type) { + case E_SEEK: + evalvec = l->a_seek; + evalp = (Char *) l->f_seek; + return; + case A_SEEK: + alvec = l->a_seek; + alvecp = (Char *) l->f_seek; + return; + case F_SEEK: + fseekp = l->f_seek; + return; + default: + (void) fprintf(csherr, "Bad seek type %d\n", aret); + abort(); + } +} - fseekp = l; - if (!cantell) { -#ifdef notdef - register struct whyle *wp; -#endif - - if (!whyles) - return; -#ifdef notdef - /* - * Christos: I don't understand this? both wp and l are local. What is - * this used for? I suspect the author meant fseek = wp->w_start - * This seek/tell stuff needs to be re-written... - */ - for (wp = whyles; wp->w_next; wp = wp->w_next) - continue; - if (wp->w_start > l) - l = wp->w_start; -#endif +void +btell(l) + struct Ain *l; +{ + switch (l->type = aret) { + case E_SEEK: + l->a_seek = evalvec; + l->f_seek = (off_t) evalp; + return; + case A_SEEK: + l->a_seek = alvec; + l->f_seek = (off_t) alvecp; + return; + case F_SEEK: + l->f_seek = fseekp; + l->a_seek = NULL; + return; + default: + (void) fprintf(csherr, "Bad seek type %d\n", aret); + abort(); } }