static char *sccsid
= "@(#)lex.c 4.1 %G%";
* These lexical routines read input and form lists of words.
* There is some involved processing here, because of the complications
* of input buffering, and especially because of history substitution.
* Peekc is a peek characer for getC, peekread for readc.
* There is a subtlety here in many places... history routines
* will read ahead and then insert stuff into the input stream.
* If they push back a character then they must push it behind
* the text substituted by the history substitution. On the other
* hand in several places we need 2 peek characters. To make this
* all work, the history routines read with getC, and make use both
* of ungetC and unreadc. The key observation is that the state
* of getC at the call of a history reference is such that calls
* to getC from the history routines will always yield calls of
* readc, unless this peeking is involved. That is to say that during
* getexcl the variables lap, exclp, and exclnxt are all zero.
* Getdol invokes history substitution, hence the extra peek, peekd,
* which it can ungetD to be before history substitutions.
char *exclp
; /* (Tail of) current word from ! subst */
struct wordent
*exclnxt
; /* The rest of the ! subst words */
int exclc
; /* Count of remainig words in ! subst */
char *alvecp
; /* "Globp" for alias resubstitution */
* Lex returns to its caller not only a wordlist (as a "var" parameter)
* but also whether a history substitution occurred. This is used in
* the main (process) routine to determine whether to echo, and also
* when called by the alias routine to determine whether to keep the
#define ungetC(c) peekc = c
#define ungetD(c) peekd = c
register struct wordent
*hp
;
register struct wordent
*wdp
;
hp
->next
= hp
->prev
= hp
;
while (c
== ' ' || c
== '\t');
if (c
== HISTSUB
&& intty
)
/* ^lef^rit from tty is short !:s^lef^rit */
* The following loop is written so that the links needed
* by freelex will be ready and rarin to go even if it is
register struct wordent
*new = (struct wordent
*) calloc(1, sizeof *wdp
);
} while (wdp
->word
[0] != '\n');
register struct wordent
*sp
= sp0
->next
;
register struct wordent
*hp
;
register struct wordent
*wdp
;
register struct wordent
*new = (struct wordent
*) calloc(1, sizeof *wdp
);
wdp
->word
= savestr(fp
->word
);
} while (wdp
->word
[0] != '\n');
register struct wordent
*vp
;
register struct wordent
*fp
;
char *WORDMETA
= "# '`\"\t;&<>()|\n";
dolflg
= c
== '"' ? DOALL
: DOEXCL
;
seterrc("Unmatched ", c1
);
if (c
== '\n' && c1
!= '`')
if (any(c
, WORDMETA
+ intty
)) {
if (any(c
, WORDMETA
+ intty
))
if (exclnxt
&& --exclc
>= 0) {
if (c
== '$' && (flag
& DODOL
)) {
if (c
== HIST
&& (flag
& DOEXCL
)) {
*np
++ = c
, c
= getC(DOEXCL
);
if (c
== '#' || c
== '?')
special
++, *np
++ = c
, c
= getC(DOEXCL
);
while (digit(c
= getC(DOEXCL
))) {
if (np
< &name
[sizeof name
/ 2])
while (letter(c
= getC(DOEXCL
))) {
if (np
< &name
[sizeof name
/ 2])
if (np
>= &name
[sizeof name
- 8])
*np
++ = c
, c
= getC(DOEXCL
);
*np
++ = c
, c
= getC(DOEXCL
);
seterr("Variable syntax");
if (lap
!= 0 && strlen(cp
) + strlen(lap
) >= sizeof (labuf
) - 4) {
seterr("Expansion buf ovflo");
register struct wordent
*hp
, *ip
;
for (ip
= hp
->next
->next
; ip
!= alhistt
; ip
= ip
->next
)
for (ip
= hp
->next
->next
; ip
!= hp
->prev
; ip
= ip
->next
)
ungetC('s'), unreadc(HISTSUB
), c
= ':';
if (letter(c
) || c
== '&') {
if (!getsel(&left
, &right
, dol
))
if (!getsel(&left
, &right
, dol
))
exclc
= right
- left
+ 1;
if (sc
== HISTSUB
|| c
== ':') {
if (letter(delim
) || digit(delim
) || any(delim
, " \t\n")) {
seterr("Bad substitute");
if (cp
> &lhsb
[sizeof lhsb
- 2])
if (c
!= delim
&& c
!= '\\')
if (&cp[strlen(orhsb)] > &rhsb[sizeof rhsb - 2])
if (cp
> &rhsb
[sizeof rhsb
- 2]) {
if (c
!= delim
/* && c != '~' */)
seterrc("Bad ! modifier: ", c
);
en
= dosub(sc
, en
, global
);
struct wordent
*hp
= &lex
;
register struct wordent
*wdp
;
register struct wordent
*new = (struct wordent
*) calloc(1, sizeof *wdp
);
wdp
->word
= global
|| didsub
== 0 ?
subword(en
->word
, sc
, &didsub
) : savestr(en
->word
);
seterr("Modifier failed");
return (&enthist(-1000, &lex
, 0)->Hlex
);
register char *wp
, *mp
, *np
;
for (np
= rhsb
; *np
; np
++) switch (*np
) {
seterr("Subst buf ovflo");
for (xp
= wp
; c
= *xp
; xp
++)
if ((c
!= ' ' && c
!= '\t') || type
== 'q')
if (!any('/', cp
)) /* what if :h :t are both the same? */
xp
= savestr(cp
), xp
[wp
- cp
] = 0;
for (wp
--; wp
>= cp
&& *wp
!= '/'; wp
--)
xp
= savestr(cp
), xp
[wp
- cp
] = 0;
return (savestr(type
== 'e' ? "" : cp
));
register char *str
, *pat
;
while (*str
&& *pat
&& *str
== *pat
)
register int c
= getC(0);
if (*al
> *ar
|| *ar
> dol
) {
seterr("Bad ! arg selector");
register struct Hist
*hp
;
c
= sc
== HISTSUB
? HIST
: getC(0);
if (lastev
== eventno
&& alhistp
)
case '#': /* !# is command being typed in (mrh) */
while (!any(c
, ": \t\\\n}")) {
if (np
< &lhsb
[sizeof lhsb
- 2])
if (np
< &lhsb
[sizeof lhsb
- 2])
seterr("No prev search");
event
= event
* 10 + c
- '0';
event
= eventno
+ (alhistp
== 0) - (event
? event
: 0);
for (hp
= Histlist
.Hnext
; hp
; hp
= hp
->Hnext
)
register struct Hist
*hp
;
for (hp
= Histlist
.Hnext
; hp
; hp
= hp
->Hnext
)
if (matchev(hp
, cp
, anyarg
))
seterr2(cp
, ": Event not found");
register struct Hist
*hp
;
struct wordent
*lp
= &hp
->Hlex
;
for (dp
= lp
->word
; *dp
; dp
++) {
if (evalvec
== (char **)1) {
if (arginp
== (char *) 1 || onelflg
== 1) {
if ((c
= *arginp
++) == 0) {
/* was isatty but raw with ignoreeof yields problems */
if (ioctl(SHIN
, TIOCGETP
, &tty
)==0 && (tty
.sg_flags
& RAW
) == 0) {
ioctl(FSHTTY
, TIOCGPGRP
, &ctpgrp
) == 0 &&
ioctl(FSHTTY
, TIOCSPGRP
, &tpgrp
);
printf("Reset tty pgrp from %d to %d\n", ctpgrp
, tpgrp
);
if (adrof("ignoreeof")) {
printf("\nUse \"logout\" to logout.\n");
printf("\nUse \"exit\" to leave csh.\n");
if (c
== '\n' && onelflg
)
register int buf
, off
, c
;
if (fseekp
< fbobp
|| fseekp
> feobp
) {
c
= read(SHIN
, fbuf
[0], BUFSIZ
);
while (c
< 0 && errno
== EINTR
);
c
= fbuf
[0][fseekp
- fbobp
];
buf
= (int) fseekp
/ BUFSIZ
;
register char **nfbuf
= (char **) calloc(fblocks
+2, sizeof (char **));
fbuf
[fblocks
] = calloc(BUFSIZ
, sizeof (char));
buf
= (int) feobp
/ BUFSIZ
;
off
= (int) feobp
% BUFSIZ
;
c
= read(SHIN
, fbuf
[buf
] + off
, BUFSIZ
- off
);
while (c
< 0 && errno
== EINTR
);
c
= fbuf
[buf
][(int) fseekp
% BUFSIZ
];
sb
= (int) (fseekp
- 1) / BUFSIZ
;
register struct whyle
*wp
;
for (wp
= whyles
; wp
->w_next
; wp
= wp
->w_next
)
/* any similarity to bell telephone is purely accidental */
if (arginp
|| onelflg
|| intty
)
if (lseek(SHIN
, 0l, 1) < 0 || errno
== ESPIPE
)
fbuf
= (char **) calloc(2, sizeof (char **));
fbuf
[0] = calloc(BUFSIZ
, sizeof (char));
fseekp
= fbobp
= feobp
= tell(SHIN
);