2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)parser.c 8.7 (Berkeley) 5/16/95
37 * $FreeBSD: src/bin/sh/parser.c,v 1.29.2.9 2002/10/18 11:24:04 tjr Exp $
38 * $DragonFly: src/bin/sh/parser.c,v 1.5 2004/10/01 20:30:25 dillon Exp $
46 #include "expand.h" /* defines rmescapes() */
47 #include "redir.h" /* defines copyfd() */
60 #include "myhistedit.h"
64 * Shell command parser.
69 /* values returned by readtoken */
75 struct heredoc *next; /* next here document in list */
76 union node *here; /* redirection node */
77 char *eofmark; /* string indicating end of input */
78 int striptabs; /* if set, strip leading tabs */
83 STATIC struct heredoc *heredoclist; /* list of here documents to read */
84 STATIC int parsebackquote; /* nonzero if we are inside backquotes */
85 STATIC int doprompt; /* if set, prompt the user */
86 STATIC int needprompt; /* true if interactive and at start of line */
87 STATIC int lasttoken; /* last token read */
88 MKINIT int tokpushback; /* last token pushed back */
89 STATIC char *wordtext; /* text of last word returned by readtoken */
90 MKINIT int checkkwd; /* 1 == check for kwds, 2 == also eat newlines */
91 STATIC struct nodelist *backquotelist;
92 STATIC union node *redirnode;
93 STATIC struct heredoc *heredoc;
94 STATIC int quoteflag; /* set if (part of) last token was quoted */
95 STATIC int startlinno; /* line # where last token started */
97 /* XXX When 'noaliases' is set to one, no alias expansion takes place. */
98 static int noaliases = 0;
100 #define GDB_HACK 1 /* avoid local declarations which gdb can't handle */
102 static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0'};
103 static const char types[] = "}-+?=";
107 STATIC union node *list(int);
108 STATIC union node *andor(void);
109 STATIC union node *pipeline(void);
110 STATIC union node *command(void);
111 STATIC union node *simplecmd(union node **, union node *);
112 STATIC union node *makename(void);
113 STATIC void parsefname(void);
114 STATIC void parseheredoc(void);
115 STATIC int peektoken(void);
116 STATIC int readtoken(void);
117 STATIC int xxreadtoken(void);
118 STATIC int readtoken1(int, char const *, char *, int);
119 STATIC int noexpand(char *);
120 STATIC void synexpect(int);
121 STATIC void synerror(const char *);
122 STATIC void setprompt(int);
126 * Read and parse a command. Returns NEOF on end of file. (NULL is a
127 * valid parse tree indicating a blank line.)
131 parsecmd(int interact)
155 union node *n1, *n2, *n3;
159 if (nlflag == 0 && tokendlist[peektoken()])
165 if (tok == TBACKGND) {
166 if (n2->type == NCMD || n2->type == NPIPE) {
167 n2->ncmd.backgnd = 1;
168 } else if (n2->type == NREDIR) {
171 n3 = (union node *)stalloc(sizeof (struct nredir));
174 n3->nredir.redirect = NULL;
182 n3 = (union node *)stalloc(sizeof (struct nbinary));
184 n3->nbinary.ch1 = n1;
185 n3->nbinary.ch2 = n2;
202 if (tokendlist[peektoken()])
209 pungetc(); /* push back EOF on input */
225 union node *n1, *n2, *n3;
230 if ((t = readtoken()) == TAND) {
232 } else if (t == TOR) {
239 n3 = (union node *)stalloc(sizeof (struct nbinary));
241 n3->nbinary.ch1 = n1;
242 n3->nbinary.ch2 = n2;
252 union node *n1, *n2, *pipenode;
253 struct nodelist *lp, *prev;
257 TRACE(("pipeline: entered\n"));
258 while (readtoken() == TNOT)
262 if (readtoken() == TPIPE) {
263 pipenode = (union node *)stalloc(sizeof (struct npipe));
264 pipenode->type = NPIPE;
265 pipenode->npipe.backgnd = 0;
266 lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
267 pipenode->npipe.cmdlist = lp;
271 lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
274 } while (readtoken() == TPIPE);
280 n2 = (union node *)stalloc(sizeof (struct nnot));
294 union node *ap, **app;
295 union node *cp, **cpp;
296 union node *redir, **rpp;
304 /* Check for redirection which may precede command */
305 while (readtoken() == TREDIR) {
306 *rpp = n2 = redirnode;
307 rpp = &n2->nfile.next;
312 while (readtoken() == TNOT) {
313 TRACE(("command: TNOT recognized\n"));
318 switch (readtoken()) {
320 n1 = (union node *)stalloc(sizeof (struct nif));
322 n1->nif.test = list(0);
323 if (readtoken() != TTHEN)
325 n1->nif.ifpart = list(0);
327 while (readtoken() == TELIF) {
328 n2->nif.elsepart = (union node *)stalloc(sizeof (struct nif));
329 n2 = n2->nif.elsepart;
331 n2->nif.test = list(0);
332 if (readtoken() != TTHEN)
334 n2->nif.ifpart = list(0);
336 if (lasttoken == TELSE)
337 n2->nif.elsepart = list(0);
339 n2->nif.elsepart = NULL;
342 if (readtoken() != TFI)
349 n1 = (union node *)stalloc(sizeof (struct nbinary));
350 n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL;
351 n1->nbinary.ch1 = list(0);
352 if ((got=readtoken()) != TDO) {
353 TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
356 n1->nbinary.ch2 = list(0);
357 if (readtoken() != TDONE)
363 if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
364 synerror("Bad for loop variable");
365 n1 = (union node *)stalloc(sizeof (struct nfor));
367 n1->nfor.var = wordtext;
368 if (readtoken() == TWORD && ! quoteflag && equal(wordtext, "in")) {
370 while (readtoken() == TWORD) {
371 n2 = (union node *)stalloc(sizeof (struct narg));
373 n2->narg.text = wordtext;
374 n2->narg.backquote = backquotelist;
376 app = &n2->narg.next;
380 if (lasttoken != TNL && lasttoken != TSEMI)
384 static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE,
387 n2 = (union node *)stalloc(sizeof (struct narg));
389 n2->narg.text = (char *)argvars;
390 n2->narg.backquote = NULL;
391 n2->narg.next = NULL;
394 * Newline or semicolon here is optional (but note
395 * that the original Bourne shell only allowed NL).
397 if (lasttoken != TNL && lasttoken != TSEMI)
401 if ((t = readtoken()) == TDO)
403 else if (t == TBEGIN)
407 n1->nfor.body = list(0);
408 if (readtoken() != t)
413 n1 = (union node *)stalloc(sizeof (struct ncase));
415 if (readtoken() != TWORD)
417 n1->ncase.expr = n2 = (union node *)stalloc(sizeof (struct narg));
419 n2->narg.text = wordtext;
420 n2->narg.backquote = backquotelist;
421 n2->narg.next = NULL;
422 while (readtoken() == TNL);
423 if (lasttoken != TWORD || ! equal(wordtext, "in"))
424 synerror("expecting \"in\"");
425 cpp = &n1->ncase.cases;
426 noaliases = 1; /* turn off alias expansion */
427 checkkwd = 2, readtoken();
428 while (lasttoken != TESAC) {
429 *cpp = cp = (union node *)stalloc(sizeof (struct nclist));
431 app = &cp->nclist.pattern;
432 if (lasttoken == TLP)
435 *app = ap = (union node *)stalloc(sizeof (struct narg));
437 ap->narg.text = wordtext;
438 ap->narg.backquote = backquotelist;
439 if (checkkwd = 2, readtoken() != TPIPE)
441 app = &ap->narg.next;
444 ap->narg.next = NULL;
445 if (lasttoken != TRP)
446 noaliases = 0, synexpect(TRP);
447 cp->nclist.body = list(0);
450 if ((t = readtoken()) != TESAC) {
452 noaliases = 0, synexpect(TENDCASE);
454 checkkwd = 2, readtoken();
456 cpp = &cp->nclist.next;
458 noaliases = 0; /* reset alias expansion */
463 n1 = (union node *)stalloc(sizeof (struct nredir));
464 n1->type = NSUBSHELL;
465 n1->nredir.n = list(0);
466 n1->nredir.redirect = NULL;
467 if (readtoken() != TRP)
473 if (readtoken() != TEND)
477 /* Handle an empty command like other simple commands. */
482 * An empty command before a ; doesn't make much sense, and
483 * should certainly be disallowed in the case of `if ;'.
492 n1 = simplecmd(rpp, redir);
498 /* Now check for redirection which may follow command */
499 while (readtoken() == TREDIR) {
500 *rpp = n2 = redirnode;
501 rpp = &n2->nfile.next;
507 if (n1->type != NSUBSHELL) {
508 n2 = (union node *)stalloc(sizeof (struct nredir));
513 n1->nredir.redirect = redir;
518 n2 = (union node *)stalloc(sizeof (struct nnot));
529 simplecmd(union node **rpp, union node *redir)
531 union node *args, **app;
532 union node **orig_rpp = rpp;
533 union node *n = NULL, *n2;
536 /* If we don't have any redirections already, then we must reset */
537 /* rpp to be the address of the local redir variable. */
544 * We save the incoming value, because we need this for shell
545 * functions. There can not be a redirect or an argument between
546 * the function name and the open parenthesis.
550 while (readtoken() == TNOT) {
551 TRACE(("command: TNOT recognized\n"));
557 if (readtoken() == TWORD) {
558 n = (union node *)stalloc(sizeof (struct narg));
560 n->narg.text = wordtext;
561 n->narg.backquote = backquotelist;
564 } else if (lasttoken == TREDIR) {
565 *rpp = n = redirnode;
566 rpp = &n->nfile.next;
567 parsefname(); /* read name of redirection file */
568 } else if (lasttoken == TLP && app == &args->narg.next
569 && rpp == orig_rpp) {
570 /* We have a function */
571 if (readtoken() != TRP)
574 if (! goodname(n->narg.text))
575 synerror("Bad function name");
578 n->narg.next = command();
587 n = (union node *)stalloc(sizeof (struct ncmd));
591 n->ncmd.redirect = redir;
595 n2 = (union node *)stalloc(sizeof (struct nnot));
609 n = (union node *)stalloc(sizeof (struct narg));
612 n->narg.text = wordtext;
613 n->narg.backquote = backquotelist;
617 void fixredir(union node *n, const char *text, int err)
619 TRACE(("Fix redir %s %d\n", text, err));
621 n->ndup.vname = NULL;
623 if (is_digit(text[0]) && text[1] == '\0')
624 n->ndup.dupfd = digit_val(text[0]);
625 else if (text[0] == '-' && text[1] == '\0')
630 synerror("Bad fd number");
632 n->ndup.vname = makename();
640 union node *n = redirnode;
642 if (readtoken() != TWORD)
644 if (n->type == NHERE) {
645 struct heredoc *here = heredoc;
651 TRACE(("Here document %d\n", n->type));
652 if (here->striptabs) {
653 while (*wordtext == '\t')
656 if (! noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN)
657 synerror("Illegal eof marker for << redirection");
659 here->eofmark = wordtext;
661 if (heredoclist == NULL)
664 for (p = heredoclist ; p->next ; p = p->next);
667 } else if (n->type == NTOFD || n->type == NFROMFD) {
668 fixredir(n, wordtext, 0);
670 n->nfile.fname = makename();
676 * Input any here documents.
682 struct heredoc *here;
685 while (heredoclist) {
687 heredoclist = here->next;
692 readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
693 here->eofmark, here->striptabs);
694 n = (union node *)stalloc(sizeof (struct narg));
697 n->narg.text = wordtext;
698 n->narg.backquote = backquotelist;
699 here->here->nhere.doc = n;
717 int savecheckkwd = checkkwd;
720 int alreadyseen = tokpushback;
739 * check for keywords and aliases
741 if (t == TWORD && !quoteflag)
743 const char * const *pp;
745 for (pp = parsekwd; *pp; pp++) {
746 if (**pp == *wordtext && equal(*pp, wordtext))
748 lasttoken = t = pp - parsekwd + KWDOFFSET;
749 TRACE(("keyword %s recognized\n", tokname[t]));
753 if (noaliases == 0 &&
754 (ap = lookupalias(wordtext, 1)) != NULL) {
755 pushstring(ap->val, strlen(ap->val), ap);
756 checkkwd = savecheckkwd;
761 checkkwd = (t == TNOT) ? savecheckkwd : 0;
765 TRACE(("token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
767 TRACE(("reread token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
774 * Read the next input token.
775 * If the token is a word, we set backquotelist to the list of cmds in
776 * backquotes. We set quoteflag to true if any part of the word was
778 * If the token is TREDIR, then we set redirnode to a structure containing
780 * In all cases, the variable startlinno is set to the number of the line
781 * on which the token starts.
783 * [Change comment: here documents and internal procedures]
784 * [Readtoken shouldn't have any arguments. Perhaps we should make the
785 * word parsing code into a separate routine. In this case, readtoken
786 * doesn't need to have any internal procedures, but parseword does.
787 * We could also make parseoperator in essence the main routine, and
788 * have parseword (readtoken1?) handle both words and redirection.]
791 #define RETURN(token) return lasttoken = token
807 for (;;) { /* until token or start of word found */
809 if (c == ' ' || c == '\t')
810 continue; /* quick check for white space first */
815 while ((c = pgetc()) != '\n' && c != PEOF);
819 if (pgetc() == '\n') {
820 startlinno = ++plinno;
831 needprompt = doprompt;
859 return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
866 * If eofmark is NULL, read a word or a redirection symbol. If eofmark
867 * is not NULL, read a here document. In the latter case, eofmark is the
868 * word which marks the end of the document and striptabs is true if
869 * leading tabs should be stripped from the document. The argument firstc
870 * is the first character of the input token or document.
872 * Because C does not have internal subroutines, I have simulated them
873 * using goto's to implement the subroutine linkage. The following macros
874 * will run code that appears at the end of readtoken1.
877 #define CHECKEND() {goto checkend; checkend_return:;}
878 #define PARSEREDIR() {goto parseredir; parseredir_return:;}
879 #define PARSESUB() {goto parsesub; parsesub_return:;}
880 #define PARSEBACKQOLD() {oldstyle = 1; goto parsebackq; parsebackq_oldreturn:;}
881 #define PARSEBACKQNEW() {oldstyle = 0; goto parsebackq; parsebackq_newreturn:;}
882 #define PARSEARITH() {goto parsearith; parsearith_return:;}
885 readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
890 char line[EOFMARKLEN + 1];
891 struct nodelist *bqlist;
894 int varnest; /* levels of variables expansion */
895 int arinest; /* levels of arithmetic expansion */
896 int parenlevel; /* levels of parens in arithmetic */
898 char const *prevsyntax; /* syntax before arithmetic */
901 /* Avoid longjmp clobbering */
916 if (syntax == DQSYNTAX)
925 loop: { /* for each line, until end of word */
926 CHECKEND(); /* set c to PEOF if at end of here document */
927 for (;;) { /* until end of line or end of word */
928 CHECKSTRSPACE(3, out); /* permit 3 calls to USTPUTC */
930 synentry = syntax[c];
934 if (syntax == BASESYNTAX)
935 goto endword; /* exit outer loop */
943 goto loop; /* continue outer loop */
948 if (eofmark == NULL || dblquote)
949 USTPUTC(CTLESC, out);
952 case CBACK: /* backslash */
957 } else if (c == '\n') {
963 if (dblquote && c != '\\' &&
964 c != '`' && c != '$' &&
965 (c != '"' || eofmark != NULL))
967 if (SQSYNTAX[c] == CCTL)
968 USTPUTC(CTLESC, out);
969 else if (eofmark == NULL)
970 USTPUTC(CTLQUOTEMARK, out);
977 USTPUTC(CTLQUOTEMARK, out);
982 USTPUTC(CTLQUOTEMARK, out);
987 if (eofmark != NULL && arinest == 0 &&
994 } else if (eofmark == NULL) {
1001 case CVAR: /* '$' */
1002 PARSESUB(); /* parse substitution */
1004 case CENDVAR: /* '}' */
1007 USTPUTC(CTLENDVAR, out);
1012 case CLP: /* '(' in arithmetic */
1016 case CRP: /* ')' in arithmetic */
1017 if (parenlevel > 0) {
1021 if (pgetc() == ')') {
1022 if (--arinest == 0) {
1023 USTPUTC(CTLENDARI, out);
1024 syntax = prevsyntax;
1025 if (syntax == DQSYNTAX)
1034 * (don't 2nd guess - no error)
1041 case CBQUOTE: /* '`' */
1045 goto endword; /* exit outer loop */
1048 goto endword; /* exit outer loop */
1055 if (syntax == ARISYNTAX)
1056 synerror("Missing '))'");
1057 if (syntax != BASESYNTAX && ! parsebackquote && eofmark == NULL)
1058 synerror("Unterminated quoted string");
1060 startlinno = plinno;
1061 synerror("Missing '}'");
1064 len = out - stackblock();
1066 if (eofmark == NULL) {
1067 if ((c == '>' || c == '<')
1070 && (*out == '\0' || is_digit(*out))) {
1072 return lasttoken = TREDIR;
1078 backquotelist = bqlist;
1079 grabstackblock(len);
1081 return lasttoken = TWORD;
1082 /* end of readtoken routine */
1087 * Check to see whether we are at the end of the here document. When this
1088 * is called, c is set to the first character of the next input line. If
1089 * we are at the end of the here document, this routine sets the c to PEOF.
1098 if (c == *eofmark) {
1099 if (pfgets(line, sizeof line) != NULL) {
1103 for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
1104 if (*p == '\n' && *q == '\0') {
1107 needprompt = doprompt;
1109 pushstring(line, strlen(line), NULL);
1114 goto checkend_return;
1119 * Parse a redirection operator. The variable "out" points to a string
1120 * specifying the fd to be redirected. The variable "c" contains the
1121 * first character of the redirection operator.
1128 np = (union node *)stalloc(sizeof (struct nfile));
1137 np->type = NCLOBBER;
1142 } else { /* c == '<' */
1146 if (sizeof (struct nfile) != sizeof (struct nhere)) {
1147 np = (union node *)stalloc(sizeof (struct nhere));
1151 heredoc = (struct heredoc *)stalloc(sizeof (struct heredoc));
1153 if ((c = pgetc()) == '-') {
1154 heredoc->striptabs = 1;
1156 heredoc->striptabs = 0;
1159 } else if (c == '&')
1169 np->nfile.fd = digit_val(fd);
1171 goto parseredir_return;
1176 * Parse a substitution. At this point, we have read the dollar sign
1186 static const char types[] = "}-+?=";
1188 int bracketed_name = 0; /* used to handle ${[0-9]*} variables */
1191 if (c != '(' && c != '{' && !is_name(c) && !is_special(c)) {
1194 } else if (c == '(') { /* $(command) or $((arith)) */
1195 if (pgetc() == '(') {
1202 USTPUTC(CTLVAR, out);
1203 typeloc = out - stackblock();
1204 USTPUTC(VSNORMAL, out);
1210 if ((c = pgetc()) == '}')
1222 } while (is_in_name(c));
1223 } else if (is_digit(c)) {
1224 if (bracketed_name) {
1228 } while (is_digit(c));
1234 if (! is_special(c))
1235 badsub: synerror("Bad substitution");
1248 p = strchr(types, c);
1251 subtype = p - types + VSNORMAL;
1257 subtype = c == '#' ? VSTRIMLEFT :
1270 if (subtype != VSLENGTH && (dblquote || arinest))
1272 *(stackblock() + typeloc) = subtype | flags;
1273 if (subtype != VSNORMAL)
1276 goto parsesub_return;
1281 * Called to parse command substitutions. Newstyle is set if the command
1282 * is enclosed inside $(...); nlpp is a pointer to the head of the linked
1283 * list of commands (passed by reference), and savelen is the number of
1284 * characters on the top of the stack which must be preserved.
1288 struct nodelist **nlpp;
1292 struct jmploc jmploc;
1293 struct jmploc *volatile savehandler;
1297 /* Avoid longjmp clobbering */
1301 savepbq = parsebackquote;
1302 if (setjmp(jmploc.loc)) {
1306 handler = savehandler;
1307 longjmp(handler->loc, 1);
1311 savelen = out - stackblock();
1313 str = ckmalloc(savelen);
1314 memcpy(str, stackblock(), savelen);
1316 savehandler = handler;
1320 /* We must read until the closing backquote, giving special
1321 treatment to some slashes, and then push the string and
1322 reread it as input, interpreting it normally. */
1335 switch (c = pgetc()) {
1340 if ((c = pgetc()) == '\n') {
1347 * If eating a newline, avoid putting
1348 * the newline into the new character
1349 * stream (via the STPUTC after the
1354 if (c != '\\' && c != '`' && c != '$'
1355 && (!dblquote || c != '"'))
1361 needprompt = doprompt;
1365 startlinno = plinno;
1366 synerror("EOF in backquote substitution");
1376 savelen = out - stackblock();
1378 str = ckmalloc(savelen);
1379 memcpy(str, stackblock(), savelen);
1380 setinputstring(str, 1);
1385 nlpp = &(*nlpp)->next;
1386 *nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
1387 (*nlpp)->next = NULL;
1388 parsebackquote = oldstyle;
1391 saveprompt = doprompt;
1398 doprompt = saveprompt;
1400 if (readtoken() != TRP)
1407 * Start reading from old file again, ignoring any pushed back
1408 * tokens left from the backquote parsing
1413 while (stackblocksize() <= savelen)
1417 memcpy(out, str, savelen);
1418 STADJUST(savelen, out);
1424 parsebackquote = savepbq;
1425 handler = savehandler;
1426 if (arinest || dblquote)
1427 USTPUTC(CTLBACKQ | CTLQUOTE, out);
1429 USTPUTC(CTLBACKQ, out);
1431 goto parsebackq_oldreturn;
1433 goto parsebackq_newreturn;
1437 * Parse an arithmetic expansion (indicate start of one and set state)
1441 if (++arinest == 1) {
1442 prevsyntax = syntax;
1444 USTPUTC(CTLARI, out);
1451 * we collapse embedded arithmetic expansion to
1452 * parenthesis, which should be equivalent
1456 goto parsearith_return;
1459 } /* end of readtoken */
1471 * Returns true if the text contains nothing to expand (no dollar signs
1476 noexpand(char *text)
1482 while ((c = *p++) != '\0') {
1483 if ( c == CTLQUOTEMARK)
1487 else if (BASESYNTAX[(int)c] == CCTL)
1495 * Return true if the argument is a legal variable name (a letter or
1496 * underscore followed by zero or more letters, underscores, and digits).
1500 goodname(char *name)
1508 if (! is_in_name(*p))
1516 * Called when an unexpected token is read during the parse. The argument
1517 * is the token that is expected, or -1 if more than one type of token can
1518 * occur at this point.
1522 synexpect(int token)
1527 fmtstr(msg, 64, "%s unexpected (expecting %s)",
1528 tokname[lasttoken], tokname[token]);
1530 fmtstr(msg, 64, "%s unexpected", tokname[lasttoken]);
1537 synerror(const char *msg)
1540 outfmt(&errout, "%s: %d: ", commandname, startlinno);
1541 outfmt(&errout, "Syntax error: %s\n", msg);
1542 error((char *)NULL);
1546 setprompt(int which)
1548 whichprompt = which;
1553 out2str(getprompt(NULL));
1557 * called by editline -- any expansions to the prompt
1558 * should be added here.
1561 getprompt(void *unused __unused)
1563 switch (whichprompt) {
1571 return "<internal prompt error>";