1 /* $Header: /src/pub/tcsh/sh.lex.c,v 3.52 2000/11/11 23:03:37 christos Exp $ */
3 * sh.lex.c: Lexical analysis into tokens
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 RCSID("$Id: sh.lex.c,v 3.52 2000/11/11 23:03:37 christos Exp $")
42 /* #define DEBUG_INP */
43 /* #define DEBUG_SEEK */
50 * These lexical routines read input and form lists of words.
51 * There is some involved processing here, because of the complications
52 * of input buffering, and especially because of history substitution.
54 static Char *word __P((void));
55 static int getC1 __P((int));
56 static void getdol __P((void));
57 static void getexcl __P((int));
58 static struct Hist *findev __P((Char *, bool));
59 static void setexclp __P((Char *));
60 static int bgetc __P((void));
61 static void balloc __P((int));
62 static void bfree __P((void));
63 static struct wordent *gethent __P((int));
64 static int matchs __P((Char *, Char *));
65 static int getsel __P((int *, int *, int));
66 static struct wordent *getsub __P((struct wordent *));
67 static Char *subword __P((Char *, int, bool *));
68 static struct wordent *dosub __P((int, struct wordent *, bool));
71 * Peekc is a peek character for getC, peekread for readc.
72 * There is a subtlety here in many places... history routines
73 * will read ahead and then insert stuff into the input stream.
74 * If they push back a character then they must push it behind
75 * the text substituted by the history substitution. On the other
76 * hand in several places we need 2 peek characters. To make this
77 * all work, the history routines read with getC, and make use both
78 * of ungetC and unreadc. The key observation is that the state
79 * of getC at the call of a history reference is such that calls
80 * to getC from the history routines will always yield calls of
81 * readc, unless this peeking is involved. That is to say that during
82 * getexcl the variables lap, exclp, and exclnxt are all zero.
84 * Getdol invokes history substitution, hence the extra peek, peekd,
85 * which it can ungetD to be before history substitutions.
87 static Char peekc = 0, peekd = 0;
88 static Char peekread = 0;
90 /* (Tail of) current word from ! subst */
91 static Char *exclp = NULL;
93 /* The rest of the ! subst words */
94 static struct wordent *exclnxt = NULL;
96 /* Count of remaining words in ! subst */
99 /* "Globp" for alias resubstitution */
100 int aret = TCSH_F_SEEK;
103 * Labuf implements a general buffer for lookahead during lexical operations.
104 * Text which is to be placed in the input stream can be stuck here.
105 * We stick parsed ahead $ constructs during initial input,
106 * process id's from `$$', and modified variable values (from qualifiers
107 * during expansion in sh.dol.c) here.
109 static Char labuf[BUFSIZE];
112 * Lex returns to its caller not only a wordlist (as a "var" parameter)
113 * but also whether a history substitution occurred. This is used in
114 * the main (process) routine to determine whether to echo, and also
115 * when called by the alias routine to determine whether to keep the
118 static bool hadhist = 0;
121 * Avoid alias expansion recursion via \!#
125 Char histline[BUFSIZE + 2]; /* last line input */
127 /* The +2 is to fool hp's optimizer */
128 bool histvalid = 0; /* is histline valid */
129 static Char *histlinep = NULL; /* current pointer into histline */
133 #define getC(f) (((getCtmp = peekc) != '\0') ? (peekc = 0, getCtmp) : getC1(f))
134 #define ungetC(c) peekc = (Char) c
135 #define ungetD(c) peekd = (Char) c
137 /* Use Htime to store timestamps picked up from history file for enthist()
138 * if reading saved history (sg)
140 time_t Htime = (time_t)0;
141 static time_t a2time_t __P((Char *));
144 * for history event processing
145 * in the command 'echo !?foo?:1 !$' we want the !$ to expand from the line
146 * 'foo' was found instead of the last command
148 static int uselastevent = 1;
160 histlinep = histline;
164 hp->next = hp->prev = hp;
169 while (c == ' ' || c == '\t');
170 if (c == HISTSUB && intty)
171 /* ^lef^rit from tty is short !:s^lef^rit */
177 * The following loop is written so that the links needed by freelex will
178 * be ready and rarin to go even if it is interrupted.
183 new = (struct wordent *) xmalloc((size_t) sizeof(*wdp));
191 } while (wdp->word[0] != '\n');
192 if (histlinep < histline + BUFSIZE) {
194 if (histlinep > histline && histlinep[-1] == '\n')
195 histlinep[-1] = '\0';
199 histline[BUFSIZE - 1] = '\0';
209 /* Attempt to distinguish timestamps from other possible entries.
210 * Format: "+NNNNNNNNNN" (10 digits, left padded with ascii '0') */
216 if (!word || *(s = word) != '+')
219 for (++s, ret = 0, ct = 0; *s; ++s, ++ct)
221 if (!isdigit((unsigned char)*s))
223 ret = ret * 10 + (time_t)((unsigned char)*s - '0');
236 struct wordent *sp = sp0->next;
239 xprintf("%S", sp->word);
243 if (sp->word[0] != '\n')
260 new = (struct wordent *) xmalloc((size_t) sizeof(*wdp));
267 wdp->word = Strsave(fp->word);
269 } while (wdp->word[0] != '\n');
278 while (vp->next != vp) {
281 if (fp->word != STRNULL)
282 xfree((ptr_t) fp->word);
298 #if defined(DSPMBYTE)
300 #endif /* DSPMBYTE */
305 while ((c = getC(DOALL)) == ' ' || c == '\t')
307 if (cmap(c, _META | _ESC))
333 Htime = a2time_t(hbuf);
361 #if defined(DSPMBYTE)
364 else if (mbytepos == 1 && Ismbyte1(c) && 2 <= i)
367 #endif /* DSPMBYTE */
373 else if (c == '\\') {
376 * PWP: this is dumb, but how all of the other shells work. If \ quotes
377 * a character OUTSIDE of a set of ''s, why shouldn't it quote EVERY
378 * following character INSIDE a set of ''s.
380 * Actually, all I really want to be able to say is 'foo\'bar' --> foo'bar
386 ((c == '\'') || (c == '"') ||
393 * if (c1 == '`') c = ' '; else
401 else if (c == '\n') {
402 seterror(ERR_UNMATCHED, c1);
407 else if (cmap(c, _META | _QF | _QB | _ESC)) {
419 else if (cmap(c, _QF | _QB)) { /* '"` */
421 dolflg = c == '"' ? DOALL : DOEXCL;
423 else if (c != '#' || !intty) {
433 seterror(ERR_WTOOLONG);
440 return (Strsave(wbuf));
450 if ((c = peekc) != 0) {
455 if ((c = *lap++) == 0)
458 if (cmap(c, _META | _QF | _QB))
463 if ((c = peekd) != 0) {
468 if ((c = *exclp++) != 0)
470 if (exclnxt && --exclc >= 0) {
471 exclnxt = exclnxt->next;
472 setexclp(exclnxt->word);
477 /* this will throw away the dummy history entries */
482 exclnxt = exclnxt->next;
486 setexclp(exclnxt->word);
490 if (c == '$' && (flag & DODOL)) {
494 if (c == HIST && (flag & DOEXCL)) {
507 Char name[4 * MAXVARLEN + 1];
510 bool special = 0, toolong;
512 np = name, *np++ = '$';
513 c = sc = getC(DOEXCL);
514 if (any("\t \n", c)) {
520 *np++ = (Char) c, c = getC(DOEXCL);
521 if (c == '#' || c == '?' || c == '%')
522 special++, *np++ = (Char) c, c = getC(DOEXCL);
530 seterror(ERR_SPDOLLT);
539 seterror(ERR_NEWLINE);
546 seterror(ERR_SPSTAR);
555 /* let $?0 pass for now */
563 /* we know that np < &name[4] */
565 while ((c = getC(DOEXCL)) != 0) {
574 else if (letter(c)) {
575 /* we know that np < &name[4] */
578 while ((c = getC(DOEXCL)) != 0) {
579 /* Bugfix for ${v123x} from Chris Torek, DAS DEC-90. */
580 if (!letter(c) && !Isdigit(c))
590 seterror(ERR_VARILL);
600 seterror(ERR_VARTOOLONG);
610 * Name up to here is a max of MAXVARLEN + 8.
612 ep = &np[2 * MAXVARLEN + 8];
615 * Michael Greim: Allow $ expansion to take place in selector
616 * expressions. (limits the number of characters returned)
618 c = getC(DOEXCL | DODOL);
622 seterror(ERR_NLINDEX);
632 seterror(ERR_SELOVFL);
639 * Name up to here is a max of 2 * MAXVARLEN + 8.
643 * if the :g modifier is followed by a newline, then error right away!
647 int gmodflag = 0, amodflag = 0;
652 *np++ = (Char) c, c = getC(DOEXCL);
653 if (c == 'g' || c == 'a') {
658 *np++ = (Char) c; c = getC(DOEXCL);
660 if ((c == 'g' && !gmodflag) || (c == 'a' && !amodflag)) {
665 *np++ = (Char) c; c = getC(DOEXCL);
668 /* scan s// [eichin:19910926.0512EST] */
672 *np++ = (Char) delim;
674 if (!delim || letter(delim)
675 || Isdigit(delim) || any(" \t\n", delim)) {
676 seterror(ERR_BADSUBST);
679 while ((c = getC(0)) != (-1)) {
681 if(c == delim) delimcnt--;
685 seterror(ERR_BADSUBST);
690 if (!any("htrqxesul", c)) {
691 if ((amodflag || gmodflag) && c == '\n')
692 stderror(ERR_VARSYN); /* strike */
693 seterror(ERR_BADMOD, c);
700 while ((c = getC(DOEXCL)) == ':');
710 seterror(ERR_MISSING, '}');
728 if (Strlen(cp) + (lap ? Strlen(lap) : 0) >=
729 (sizeof(labuf) - 4) / sizeof(Char)) {
730 seterror(ERR_EXPOVFL);
734 (void) Strcpy(buf, lap);
735 (void) Strcpy(labuf, cp);
737 (void) Strcat(labuf, buf);
741 static Char lhsb[32];
742 static Char slhs[32];
743 static Char rhsb[64];
750 struct wordent *hp, *ip;
751 int left, right, dol;
775 for (ip = hp->next->next; ip != alhistt; ip = ip->next)
778 for (ip = hp->next->next; ip != hp->prev; ip = ip->next)
780 left = 0, right = dol;
782 ungetC('s'), unreadc(HISTSUB), c = ':';
786 if (!any(":^$*-%", c))
792 if (letter(c) || c == '&') {
794 left = 0, right = dol;
800 if (!getsel(&left, &right, dol))
806 if (!getsel(&left, &right, dol))
811 exclc = right - left + 1;
814 if (sc == HISTSUB || c == ':') {
824 seterror(ERR_BADBANG);
829 static struct wordent *
838 Char orhsb[sizeof(rhsb) / sizeof(Char)];
846 if (c == 'g' || c == 'a') {
847 global |= (c == 'g') ? 1 : 2;
850 if (((c =='g') && !(global & 1)) || ((c == 'a') && !(global & 2))) {
851 global |= (c == 'g') ? 1 : 2;
875 seterror(ERR_NOSUBST);
878 (void) Strcpy(lhsb, slhs);
890 if (letter(delim) || Isdigit(delim) || any(" \t\n", delim)) {
893 seterror(ERR_BADSUBST);
905 if (cp > &lhsb[sizeof(lhsb) / sizeof(Char) - 2]) {
907 seterror(ERR_BADSUBST);
912 if (c != delim && c != '\\')
919 else if (lhsb[0] == 0) {
924 (void) Strcpy(orhsb, cp);
935 if (&cp[Strlen(orhsb)] > &rhsb[sizeof(rhsb) /
938 (void) Strcpy(cp, orhsb);
943 if (cp > &rhsb[sizeof(rhsb) / sizeof(Char) - 2]) {
944 seterror(ERR_RHSLONG);
949 if (c != delim /* && c != '~' */ )
960 seterror(ERR_BADBANGMOD, c);
963 (void) Strcpy(slhs, lhsb);
965 en = dosub(sc, en, global);
968 while ((c = getC(0)) == ':');
976 * From Beto Appleton (beto@aixwiz.austin.ibm.com)
978 * when using history substitution, and the variable
979 * 'history' is set to a value higher than 1000,
980 * the shell might either freeze (hang) or core-dump.
981 * We raise the limit to 50000000
984 #define HIST_PURGE -50000000
985 static struct wordent *
986 dosub(sc, en, global)
992 bool didsub = 0, didone = 0;
993 struct wordent *hp = &lexi;
1000 struct wordent *new =
1001 (struct wordent *) xcalloc(1, sizeof *wdp);
1010 Char *tword, *otword;
1012 if ((global & 1) || didsub == 0) {
1013 tword = subword(en->word, sc, &didone);
1017 while (didone && tword != STRNULL) {
1019 tword = subword(otword, sc, &didone);
1020 if (Strcmp(tword, otword) == 0) {
1021 xfree((ptr_t) otword);
1025 xfree((ptr_t) otword);
1030 tword = Strsave(en->word);
1035 seterror(ERR_MODFAIL);
1038 * ANSI mode HP/UX compiler chokes on
1039 * return &enthist(HIST_PURGE, &lexi, 0)->Hlex;
1041 hst = enthist(HIST_PURGE, &lexi, 0, 0);
1042 return &(hst->Hlex);
1046 subword(cp, type, adid)
1066 wp = domod(cp, type);
1068 return (Strsave(cp));
1075 for (mp = cp; *mp; mp++)
1076 if (matchs(mp, lhsb)) {
1077 for (np = cp; np < mp;)
1079 for (np = rhsb; *np; np++)
1089 seterror(ERR_SUBOVFL);
1098 seterror(ERR_SUBOVFL);
1102 (void) Strcat(wp, lhsb);
1109 seterror(ERR_SUBOVFL);
1113 (void) Strcat(wp, mp);
1115 return (Strsave(wbuf));
1117 return (Strsave(cp));
1134 for (xp = wp; (c = *xp) != 0; xp++)
1135 if ((c != ' ' && c != '\t') || type == 'q')
1141 for (cp = wp; *cp; cp++)
1150 for (cp = wp; *cp; cp++)
1159 if (!any(short2str(cp), '/'))
1160 return (type == 't' ? Strsave(cp) : 0);
1162 while (*--wp != '/')
1165 xp = Strsave(cp), xp[wp - cp] = 0;
1167 xp = Strsave(wp + 1);
1173 for (wp--; wp >= cp && *wp != '/'; wp--)
1176 xp = Strsave(wp + 1);
1178 xp = Strsave(cp), xp[wp - cp] = 0;
1181 return (Strsave(type == 'e' ? STRNULL : cp));
1192 while (*str && *pat && *str == *pat)
1204 bool first = *al < 0;
1209 if (quesarg == -1) {
1210 seterror(ERR_BADBANGARG);
1252 while (Isdigit(c)) {
1253 i = i * 10 + c - '0';
1275 if (*al > *ar || *ar > dol) {
1276 seterror(ERR_BADBANGARG);
1283 static struct wordent *
1293 c = sc == HISTSUB ? HIST : getC(0);
1308 if (lastev == eventno && alhistp)
1313 case '#': /* !# is command being typed in (mrh) */
1315 seterror(ERR_HISTLOOP);
1328 if (any("(=~", c)) {
1335 while (!cmap(c, _ESC | _META | _QF | _QB) && !any("^*-%${}:#", c)) {
1336 if (event != -1 && Isdigit(c))
1337 event = event * 10 + c - '0';
1340 if (np < &lhsb[sizeof(lhsb) / sizeof(Char) - 2])
1352 * History had only digits
1355 event = eventno + (alhistp == 0) - (event ? event : 0);
1359 event = sizeof(lhsb) / sizeof(lhsb[0]);
1360 np = &lhsb[--event];
1362 for (event--; np > lhsb; *np-- = lhsb[--event])
1366 hp = findev(lhsb, 0);
1381 if (np < &lhsb[sizeof(lhsb) / sizeof(Char) - 2])
1386 seterror(ERR_NOSEARCH);
1392 hp = findev(lhsb, 1);
1398 for (hp = Histlist.Hnext; hp; hp = hp->Hnext)
1399 if (hp->Hnum == event) {
1405 seterror(ERR_NOEVENT, short2str(np));
1409 static struct Hist *
1416 for (hp = Histlist.Hnext; hp; hp = hp->Hnext) {
1419 struct wordent *lp = hp->Hlex.next;
1423 * The entries added by alias substitution don't have a newline but do
1424 * have a negative event number. Savehist() trims off these entries,
1425 * but it happens before alias expansion, too early to delete those
1426 * from the previous command.
1430 if (lp->word[0] == '\n')
1438 while (*p++ == *q++);
1442 for (dp = lp->word; *dp; dp++) {
1450 while (*p++ == *q++);
1454 } while (lp->word[0] != '\n');
1456 seterror(ERR_NOEVENT, short2str(cp));
1465 if (cp && cp[0] == '\n')
1474 peekread = (Char) c;
1482 static int sincereal; /* Number of real EOFs we've seen */
1483 Char *ptr; /* For STRignoreeof */
1484 int numeof = 0; /* Value of STRignoreeof */
1489 if ((c = peekread) != 0) {
1494 /* Compute the value of EOFs */
1495 if ((ptr = varval(STRignoreeof)) != STRNULL) {
1497 if (!Isdigit(*ptr)) {
1501 numeof = numeof * 10 + *ptr++ - '0';
1504 if (numeof < 1) numeof = 26; /* Sanity check */
1511 xprintf("alvecp %c\n", *alvecp & 0xff);
1514 if ((c = *alvecp++) != 0)
1516 if (alvec && *alvec) {
1528 if ((alvecp = *alvec) != 0) {
1532 /* Infinite source! */
1538 if ((c = *evalp++) != 0)
1540 if (evalvec && *evalvec) {
1548 if (evalvec == INVPPTR) {
1552 if ((evalp = *evalvec) != 0) {
1560 if (arginp == INVPTR || onelflg == 1) {
1566 if ((c = *arginp++) == 0) {
1574 #endif /* BSDJOBS */
1577 #ifndef WINNT_NATIVE
1583 # endif /* TERMIO */
1587 #endif /* !WINNT_NATIVE */
1590 /* was isatty but raw with ignoreeof yields problems */
1591 #ifndef WINNT_NATIVE
1594 if (ioctl(SHIN, TCGETA, (ioctl_t) & tty) == 0 &&
1595 (tty.c_lflag & ICANON))
1597 if (ioctl(SHIN, TIOCGETP, (ioctl_t) & tty) == 0 &&
1598 (tty.sg_flags & RAW) == 0)
1599 # endif /* TERMIO */
1601 if (tcgetattr(SHIN, &tty) == 0 &&
1602 (tty.c_lflag & ICANON))
1604 #else /* WINNT_NATIVE */
1606 #endif /* !WINNT_NATIVE */
1608 /* was 'short' for FILEC */
1611 #endif /* BSDJOBS */
1613 if (++sincereal >= numeof) /* Too many EOFs? Bye! */
1617 (ctpgrp = tcgetpgrp(FSHTTY)) != -1 &&
1619 (void) tcsetpgrp(FSHTTY, tpgrp);
1622 # endif /* _SEQUENT */
1623 (void) killpg((pid_t) ctpgrp, SIGHUP);
1626 * With the walking process group fix, this message
1627 * is now obsolete. As the foreground process group
1628 * changes, the shell needs to adjust. Well too bad.
1630 xprintf(CGETS(16, 1, "Reset tty pgrp from %d to %d\n"),
1632 # endif /* notdef */
1635 #endif /* BSDJOBS */
1636 /* What follows is complicated EOF handling -- sterling@netcom.com */
1637 /* First, we check to see if we have ignoreeof set */
1638 if (adrof(STRignoreeof)) {
1639 /* If so, we check for any stopped jobs only on the first EOF */
1640 if ((sincereal == 1) && (chkstop == 0)) {
1644 /* If we don't have ignoreeof set, always check for stopped jobs */
1649 /* At this point, if there were stopped jobs, we would have already
1650 * called reset(). If we got this far, assume we can print an
1651 * exit/logout message if we ignoreeof, or just exit.
1653 if (adrof(STRignoreeof)) {
1654 /* If so, tell the user to use exit or logout */
1656 xprintf(CGETS(16, 2,
1657 "\nUse \"logout\" to logout.\n"));
1659 xprintf(CGETS(16, 3,
1660 "\nUse \"exit\" to leave %s.\n"),
1665 /* If we don't have ignoreeof set, just fall through */
1674 if (c == '\n' && onelflg)
1677 if (histlinep < histline + BUFSIZE)
1678 *histlinep++ = (Char) c;
1688 while (buf >= fblocks) {
1689 nfbuf = (Char **) xcalloc((size_t) (fblocks + 2),
1692 (void) blkcpy(nfbuf, fbuf);
1693 xfree((ptr_t) fbuf);
1696 fbuf[fblocks] = (Char *) xcalloc(BUFSIZE, sizeof(Char));
1705 int numleft = 0, roomleft;
1706 char tbuf[BUFSIZE + 1];
1709 if (fseekp < fbobp || fseekp > feobp) {
1710 fbobp = feobp = fseekp;
1711 (void) lseek(SHIN, fseekp, L_SET);
1713 if (fseekp == feobp) {
1718 c = read(SHIN, tbuf, BUFSIZE);
1719 while (c < 0 && errno == EINTR);
1722 stderror(ERR_SYSTEM, progname, strerror(errno));
1726 for (i = 0; i < c; i++)
1727 fbuf[0][i] = (unsigned char) tbuf[i];
1730 #ifndef WINNT_NATIVE
1731 c = fbuf[0][fseekp - fbobp];
1735 c = fbuf[0][fseekp - fbobp];
1738 #endif /* !WINNT_NATIVE */
1742 while (fseekp >= feobp) {
1743 if (editing && intty) { /* then use twenex routine */
1744 fseekp = feobp; /* where else? */
1745 c = numleft = Inputl(); /* PWP: get a line */
1746 while (numleft > 0) {
1747 off = (int) feobp % BUFSIZE;
1748 buf = (int) feobp / BUFSIZE;
1750 roomleft = BUFSIZE - off;
1751 if (roomleft > numleft)
1753 (void) memmove((ptr_t) (fbuf[buf] + off), (ptr_t) (InputBuf + c - numleft), (size_t) (roomleft * sizeof(Char)));
1754 numleft -= roomleft;
1759 off = (int) feobp % BUFSIZE;
1760 buf = (int) feobp / BUFSIZE;
1762 roomleft = BUFSIZE - off;
1763 c = read(SHIN, tbuf, (size_t) roomleft);
1766 Char *ptr = fbuf[buf] + off;
1768 for (i = 0; i < c; i++)
1769 ptr[i] = (unsigned char) tbuf[i];
1773 if (c == 0 || (c < 0 && fixio(SHIN, errno) == -1))
1776 #ifndef WINNT_NATIVE
1777 c = fbuf[(int) fseekp / BUFSIZE][(int) fseekp % BUFSIZE];
1781 c = fbuf[(int) fseekp / BUFSIZE][(int) fseekp % BUFSIZE];
1784 #endif /* !WINNT_NATIVE */
1797 sb = (int) (fseekp - 1) / BUFSIZE;
1799 for (i = 0; i < sb; i++)
1800 xfree((ptr_t) fbuf[i]);
1801 (void) blkcpy(fbuf, &fbuf[sb]);
1802 fseekp -= BUFSIZE * sb;
1803 feobp -= BUFSIZE * sb;
1812 switch (aret = l->type) {
1814 evalvec = l->a_seek;
1817 xprintf(CGETS(16, 4, "seek to eval %x %x\n"), evalvec, evalp);
1824 xprintf(CGETS(16, 5, "seek to alias %x %x\n"), alvec, alvecp);
1829 xprintf(CGETS(16, 6, "seek to file %x\n"), fseekp);
1834 xprintf(CGETS(16, 7, "Bad seek type %d\n"), aret);
1839 /* any similarity to bell telephone is purely accidental */
1844 switch (l->type = aret) {
1846 l->a_seek = evalvec;
1849 xprintf(CGETS(16, 8, "tell eval %x %x\n"), evalvec, evalp);
1856 xprintf(CGETS(16, 9, "tell alias %x %x\n"), alvec, alvecp);
1864 xprintf(CGETS(16, 10, "tell file %x\n"), fseekp);
1868 xprintf(CGETS(16, 7, "Bad seek type %d\n"), aret);
1876 (void) lseek(SHIN, (off_t) 0, L_XTND);
1892 if (arginp || onelflg || intty)
1894 if ((x = lseek(SHIN, (off_t) 0, L_INCR)) == -1)
1896 fbuf = (Char **) xcalloc(2, sizeof(Char **));
1898 fbuf[0] = (Char *) xcalloc(BUFSIZE, sizeof(Char));
1899 fseekp = fbobp = feobp = x;