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
39 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD: src/bin/sh/parser.c,v 1.29.2.9 2002/10/18 11:24:04 tjr Exp $");
50 #include "expand.h" /* defines rmescapes() */
51 #include "redir.h" /* defines copyfd() */
64 #include "myhistedit.h"
68 * Shell command parser.
73 /* values returned by readtoken */
79 struct heredoc *next; /* next here document in list */
80 union node *here; /* redirection node */
81 char *eofmark; /* string indicating end of input */
82 int striptabs; /* if set, strip leading tabs */
87 struct heredoc *heredoclist; /* list of here documents to read */
88 int parsebackquote; /* nonzero if we are inside backquotes */
89 int doprompt; /* if set, prompt the user */
90 int needprompt; /* true if interactive and at start of line */
91 int lasttoken; /* last token read */
92 MKINIT int tokpushback; /* last token pushed back */
93 char *wordtext; /* text of last word returned by readtoken */
94 MKINIT int checkkwd; /* 1 == check for kwds, 2 == also eat newlines */
95 struct nodelist *backquotelist;
96 union node *redirnode;
97 struct heredoc *heredoc;
98 int quoteflag; /* set if (part of) last token was quoted */
99 int startlinno; /* line # where last token started */
101 /* XXX When 'noaliases' is set to one, no alias expansion takes place. */
102 static int noaliases = 0;
104 #define GDB_HACK 1 /* avoid local declarations which gdb can't handle */
106 static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0'};
107 static const char types[] = "}-+?=";
111 STATIC union node *list(int);
112 STATIC union node *andor(void);
113 STATIC union node *pipeline(void);
114 STATIC union node *command(void);
115 STATIC union node *simplecmd(union node **, union node *);
116 STATIC union node *makename(void);
117 STATIC void parsefname(void);
118 STATIC void parseheredoc(void);
119 STATIC int peektoken(void);
120 STATIC int readtoken(void);
121 STATIC int xxreadtoken(void);
122 STATIC int readtoken1(int, char const *, char *, int);
123 STATIC int noexpand(char *);
124 STATIC void synexpect(int);
125 STATIC void synerror(char *);
126 STATIC void setprompt(int);
130 * Read and parse a command. Returns NEOF on end of file. (NULL is a
131 * valid parse tree indicating a blank line.)
135 parsecmd(int interact)
159 union node *n1, *n2, *n3;
163 if (nlflag == 0 && tokendlist[peektoken()])
169 if (tok == TBACKGND) {
170 if (n2->type == NCMD || n2->type == NPIPE) {
171 n2->ncmd.backgnd = 1;
172 } else if (n2->type == NREDIR) {
175 n3 = (union node *)stalloc(sizeof (struct nredir));
178 n3->nredir.redirect = NULL;
186 n3 = (union node *)stalloc(sizeof (struct nbinary));
188 n3->nbinary.ch1 = n1;
189 n3->nbinary.ch2 = n2;
206 if (tokendlist[peektoken()])
213 pungetc(); /* push back EOF on input */
229 union node *n1, *n2, *n3;
234 if ((t = readtoken()) == TAND) {
236 } else if (t == TOR) {
243 n3 = (union node *)stalloc(sizeof (struct nbinary));
245 n3->nbinary.ch1 = n1;
246 n3->nbinary.ch2 = n2;
256 union node *n1, *n2, *pipenode;
257 struct nodelist *lp, *prev;
261 TRACE(("pipeline: entered\n"));
262 while (readtoken() == TNOT)
266 if (readtoken() == TPIPE) {
267 pipenode = (union node *)stalloc(sizeof (struct npipe));
268 pipenode->type = NPIPE;
269 pipenode->npipe.backgnd = 0;
270 lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
271 pipenode->npipe.cmdlist = lp;
275 lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
278 } while (readtoken() == TPIPE);
284 n2 = (union node *)stalloc(sizeof (struct nnot));
298 union node *ap, **app;
299 union node *cp, **cpp;
300 union node *redir, **rpp;
308 /* Check for redirection which may precede command */
309 while (readtoken() == TREDIR) {
310 *rpp = n2 = redirnode;
311 rpp = &n2->nfile.next;
316 while (readtoken() == TNOT) {
317 TRACE(("command: TNOT recognized\n"));
322 switch (readtoken()) {
324 n1 = (union node *)stalloc(sizeof (struct nif));
326 n1->nif.test = list(0);
327 if (readtoken() != TTHEN)
329 n1->nif.ifpart = list(0);
331 while (readtoken() == TELIF) {
332 n2->nif.elsepart = (union node *)stalloc(sizeof (struct nif));
333 n2 = n2->nif.elsepart;
335 n2->nif.test = list(0);
336 if (readtoken() != TTHEN)
338 n2->nif.ifpart = list(0);
340 if (lasttoken == TELSE)
341 n2->nif.elsepart = list(0);
343 n2->nif.elsepart = NULL;
346 if (readtoken() != TFI)
353 n1 = (union node *)stalloc(sizeof (struct nbinary));
354 n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL;
355 n1->nbinary.ch1 = list(0);
356 if ((got=readtoken()) != TDO) {
357 TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
360 n1->nbinary.ch2 = list(0);
361 if (readtoken() != TDONE)
367 if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
368 synerror("Bad for loop variable");
369 n1 = (union node *)stalloc(sizeof (struct nfor));
371 n1->nfor.var = wordtext;
372 if (readtoken() == TWORD && ! quoteflag && equal(wordtext, "in")) {
374 while (readtoken() == TWORD) {
375 n2 = (union node *)stalloc(sizeof (struct narg));
377 n2->narg.text = wordtext;
378 n2->narg.backquote = backquotelist;
380 app = &n2->narg.next;
384 if (lasttoken != TNL && lasttoken != TSEMI)
388 static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE,
391 n2 = (union node *)stalloc(sizeof (struct narg));
393 n2->narg.text = (char *)argvars;
394 n2->narg.backquote = NULL;
395 n2->narg.next = NULL;
398 * Newline or semicolon here is optional (but note
399 * that the original Bourne shell only allowed NL).
401 if (lasttoken != TNL && lasttoken != TSEMI)
405 if ((t = readtoken()) == TDO)
407 else if (t == TBEGIN)
411 n1->nfor.body = list(0);
412 if (readtoken() != t)
417 n1 = (union node *)stalloc(sizeof (struct ncase));
419 if (readtoken() != TWORD)
421 n1->ncase.expr = n2 = (union node *)stalloc(sizeof (struct narg));
423 n2->narg.text = wordtext;
424 n2->narg.backquote = backquotelist;
425 n2->narg.next = NULL;
426 while (readtoken() == TNL);
427 if (lasttoken != TWORD || ! equal(wordtext, "in"))
428 synerror("expecting \"in\"");
429 cpp = &n1->ncase.cases;
430 noaliases = 1; /* turn off alias expansion */
431 checkkwd = 2, readtoken();
432 while (lasttoken != TESAC) {
433 *cpp = cp = (union node *)stalloc(sizeof (struct nclist));
435 app = &cp->nclist.pattern;
436 if (lasttoken == TLP)
439 *app = ap = (union node *)stalloc(sizeof (struct narg));
441 ap->narg.text = wordtext;
442 ap->narg.backquote = backquotelist;
443 if (checkkwd = 2, readtoken() != TPIPE)
445 app = &ap->narg.next;
448 ap->narg.next = NULL;
449 if (lasttoken != TRP)
450 noaliases = 0, synexpect(TRP);
451 cp->nclist.body = list(0);
454 if ((t = readtoken()) != TESAC) {
456 noaliases = 0, synexpect(TENDCASE);
458 checkkwd = 2, readtoken();
460 cpp = &cp->nclist.next;
462 noaliases = 0; /* reset alias expansion */
467 n1 = (union node *)stalloc(sizeof (struct nredir));
468 n1->type = NSUBSHELL;
469 n1->nredir.n = list(0);
470 n1->nredir.redirect = NULL;
471 if (readtoken() != TRP)
477 if (readtoken() != TEND)
481 /* Handle an empty command like other simple commands. */
486 * An empty command before a ; doesn't make much sense, and
487 * should certainly be disallowed in the case of `if ;'.
496 n1 = simplecmd(rpp, redir);
502 /* Now check for redirection which may follow command */
503 while (readtoken() == TREDIR) {
504 *rpp = n2 = redirnode;
505 rpp = &n2->nfile.next;
511 if (n1->type != NSUBSHELL) {
512 n2 = (union node *)stalloc(sizeof (struct nredir));
517 n1->nredir.redirect = redir;
522 n2 = (union node *)stalloc(sizeof (struct nnot));
533 simplecmd(union node **rpp, union node *redir)
535 union node *args, **app;
536 union node **orig_rpp = rpp;
537 union node *n = NULL, *n2;
540 /* If we don't have any redirections already, then we must reset */
541 /* rpp to be the address of the local redir variable. */
548 * We save the incoming value, because we need this for shell
549 * functions. There can not be a redirect or an argument between
550 * the function name and the open parenthesis.
554 while (readtoken() == TNOT) {
555 TRACE(("command: TNOT recognized\n"));
561 if (readtoken() == TWORD) {
562 n = (union node *)stalloc(sizeof (struct narg));
564 n->narg.text = wordtext;
565 n->narg.backquote = backquotelist;
568 } else if (lasttoken == TREDIR) {
569 *rpp = n = redirnode;
570 rpp = &n->nfile.next;
571 parsefname(); /* read name of redirection file */
572 } else if (lasttoken == TLP && app == &args->narg.next
573 && rpp == orig_rpp) {
574 /* We have a function */
575 if (readtoken() != TRP)
578 if (! goodname(n->narg.text))
579 synerror("Bad function name");
582 n->narg.next = command();
591 n = (union node *)stalloc(sizeof (struct ncmd));
595 n->ncmd.redirect = redir;
599 n2 = (union node *)stalloc(sizeof (struct nnot));
613 n = (union node *)stalloc(sizeof (struct narg));
616 n->narg.text = wordtext;
617 n->narg.backquote = backquotelist;
621 void fixredir(union node *n, const char *text, int err)
623 TRACE(("Fix redir %s %d\n", text, err));
625 n->ndup.vname = NULL;
627 if (is_digit(text[0]) && text[1] == '\0')
628 n->ndup.dupfd = digit_val(text[0]);
629 else if (text[0] == '-' && text[1] == '\0')
634 synerror("Bad fd number");
636 n->ndup.vname = makename();
644 union node *n = redirnode;
646 if (readtoken() != TWORD)
648 if (n->type == NHERE) {
649 struct heredoc *here = heredoc;
655 TRACE(("Here document %d\n", n->type));
656 if (here->striptabs) {
657 while (*wordtext == '\t')
660 if (! noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN)
661 synerror("Illegal eof marker for << redirection");
663 here->eofmark = wordtext;
665 if (heredoclist == NULL)
668 for (p = heredoclist ; p->next ; p = p->next);
671 } else if (n->type == NTOFD || n->type == NFROMFD) {
672 fixredir(n, wordtext, 0);
674 n->nfile.fname = makename();
680 * Input any here documents.
686 struct heredoc *here;
689 while (heredoclist) {
691 heredoclist = here->next;
696 readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
697 here->eofmark, here->striptabs);
698 n = (union node *)stalloc(sizeof (struct narg));
701 n->narg.text = wordtext;
702 n->narg.backquote = backquotelist;
703 here->here->nhere.doc = n;
721 int savecheckkwd = checkkwd;
724 int alreadyseen = tokpushback;
743 * check for keywords and aliases
745 if (t == TWORD && !quoteflag)
747 const char * const *pp;
749 for (pp = parsekwd; *pp; pp++) {
750 if (**pp == *wordtext && equal(*pp, wordtext))
752 lasttoken = t = pp - parsekwd + KWDOFFSET;
753 TRACE(("keyword %s recognized\n", tokname[t]));
757 if (noaliases == 0 &&
758 (ap = lookupalias(wordtext, 1)) != NULL) {
759 pushstring(ap->val, strlen(ap->val), ap);
760 checkkwd = savecheckkwd;
765 checkkwd = (t == TNOT) ? savecheckkwd : 0;
769 TRACE(("token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
771 TRACE(("reread token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
778 * Read the next input token.
779 * If the token is a word, we set backquotelist to the list of cmds in
780 * backquotes. We set quoteflag to true if any part of the word was
782 * If the token is TREDIR, then we set redirnode to a structure containing
784 * In all cases, the variable startlinno is set to the number of the line
785 * on which the token starts.
787 * [Change comment: here documents and internal procedures]
788 * [Readtoken shouldn't have any arguments. Perhaps we should make the
789 * word parsing code into a separate routine. In this case, readtoken
790 * doesn't need to have any internal procedures, but parseword does.
791 * We could also make parseoperator in essence the main routine, and
792 * have parseword (readtoken1?) handle both words and redirection.]
795 #define RETURN(token) return lasttoken = token
811 for (;;) { /* until token or start of word found */
813 if (c == ' ' || c == '\t')
814 continue; /* quick check for white space first */
819 while ((c = pgetc()) != '\n' && c != PEOF);
823 if (pgetc() == '\n') {
824 startlinno = ++plinno;
835 needprompt = doprompt;
863 return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
870 * If eofmark is NULL, read a word or a redirection symbol. If eofmark
871 * is not NULL, read a here document. In the latter case, eofmark is the
872 * word which marks the end of the document and striptabs is true if
873 * leading tabs should be stripped from the document. The argument firstc
874 * is the first character of the input token or document.
876 * Because C does not have internal subroutines, I have simulated them
877 * using goto's to implement the subroutine linkage. The following macros
878 * will run code that appears at the end of readtoken1.
881 #define CHECKEND() {goto checkend; checkend_return:;}
882 #define PARSEREDIR() {goto parseredir; parseredir_return:;}
883 #define PARSESUB() {goto parsesub; parsesub_return:;}
884 #define PARSEBACKQOLD() {oldstyle = 1; goto parsebackq; parsebackq_oldreturn:;}
885 #define PARSEBACKQNEW() {oldstyle = 0; goto parsebackq; parsebackq_newreturn:;}
886 #define PARSEARITH() {goto parsearith; parsearith_return:;}
889 readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
894 char line[EOFMARKLEN + 1];
895 struct nodelist *bqlist;
898 int varnest; /* levels of variables expansion */
899 int arinest; /* levels of arithmetic expansion */
900 int parenlevel; /* levels of parens in arithmetic */
902 char const *prevsyntax; /* syntax before arithmetic */
905 /* Avoid longjmp clobbering */
920 if (syntax == DQSYNTAX)
929 loop: { /* for each line, until end of word */
931 if (c == '\034' && doprompt
932 && attyset() && ! equal(termval(), "emacs")) {
934 if (syntax == BASESYNTAX)
940 CHECKEND(); /* set c to PEOF if at end of here document */
941 for (;;) { /* until end of line or end of word */
942 CHECKSTRSPACE(3, out); /* permit 3 calls to USTPUTC */
944 synentry = syntax[c];
948 if (syntax == BASESYNTAX)
949 goto endword; /* exit outer loop */
957 goto loop; /* continue outer loop */
962 if (eofmark == NULL || dblquote)
963 USTPUTC(CTLESC, out);
966 case CBACK: /* backslash */
971 } else if (c == '\n') {
977 if (dblquote && c != '\\' &&
978 c != '`' && c != '$' &&
979 (c != '"' || eofmark != NULL))
981 if (SQSYNTAX[c] == CCTL)
982 USTPUTC(CTLESC, out);
983 else if (eofmark == NULL)
984 USTPUTC(CTLQUOTEMARK, out);
991 USTPUTC(CTLQUOTEMARK, out);
996 USTPUTC(CTLQUOTEMARK, out);
1001 if (eofmark != NULL && arinest == 0 &&
1008 } else if (eofmark == NULL) {
1009 syntax = BASESYNTAX;
1015 case CVAR: /* '$' */
1016 PARSESUB(); /* parse substitution */
1018 case CENDVAR: /* '}' */
1021 USTPUTC(CTLENDVAR, out);
1026 case CLP: /* '(' in arithmetic */
1030 case CRP: /* ')' in arithmetic */
1031 if (parenlevel > 0) {
1035 if (pgetc() == ')') {
1036 if (--arinest == 0) {
1037 USTPUTC(CTLENDARI, out);
1038 syntax = prevsyntax;
1039 if (syntax == DQSYNTAX)
1048 * (don't 2nd guess - no error)
1055 case CBQUOTE: /* '`' */
1059 goto endword; /* exit outer loop */
1062 goto endword; /* exit outer loop */
1069 if (syntax == ARISYNTAX)
1070 synerror("Missing '))'");
1071 if (syntax != BASESYNTAX && ! parsebackquote && eofmark == NULL)
1072 synerror("Unterminated quoted string");
1074 startlinno = plinno;
1075 synerror("Missing '}'");
1078 len = out - stackblock();
1080 if (eofmark == NULL) {
1081 if ((c == '>' || c == '<')
1084 && (*out == '\0' || is_digit(*out))) {
1086 return lasttoken = TREDIR;
1092 backquotelist = bqlist;
1093 grabstackblock(len);
1095 return lasttoken = TWORD;
1096 /* end of readtoken routine */
1101 * Check to see whether we are at the end of the here document. When this
1102 * is called, c is set to the first character of the next input line. If
1103 * we are at the end of the here document, this routine sets the c to PEOF.
1112 if (c == *eofmark) {
1113 if (pfgets(line, sizeof line) != NULL) {
1117 for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
1118 if (*p == '\n' && *q == '\0') {
1121 needprompt = doprompt;
1123 pushstring(line, strlen(line), NULL);
1128 goto checkend_return;
1133 * Parse a redirection operator. The variable "out" points to a string
1134 * specifying the fd to be redirected. The variable "c" contains the
1135 * first character of the redirection operator.
1142 np = (union node *)stalloc(sizeof (struct nfile));
1151 np->type = NCLOBBER;
1156 } else { /* c == '<' */
1160 if (sizeof (struct nfile) != sizeof (struct nhere)) {
1161 np = (union node *)stalloc(sizeof (struct nhere));
1165 heredoc = (struct heredoc *)stalloc(sizeof (struct heredoc));
1167 if ((c = pgetc()) == '-') {
1168 heredoc->striptabs = 1;
1170 heredoc->striptabs = 0;
1173 } else if (c == '&')
1183 np->nfile.fd = digit_val(fd);
1185 goto parseredir_return;
1190 * Parse a substitution. At this point, we have read the dollar sign
1200 static const char types[] = "}-+?=";
1202 int bracketed_name = 0; /* used to handle ${[0-9]*} variables */
1205 if (c != '(' && c != '{' && !is_name(c) && !is_special(c)) {
1208 } else if (c == '(') { /* $(command) or $((arith)) */
1209 if (pgetc() == '(') {
1216 USTPUTC(CTLVAR, out);
1217 typeloc = out - stackblock();
1218 USTPUTC(VSNORMAL, out);
1224 if ((c = pgetc()) == '}')
1236 } while (is_in_name(c));
1237 } else if (is_digit(c)) {
1238 if (bracketed_name) {
1242 } while (is_digit(c));
1248 if (! is_special(c))
1249 badsub: synerror("Bad substitution");
1262 p = strchr(types, c);
1265 subtype = p - types + VSNORMAL;
1271 subtype = c == '#' ? VSTRIMLEFT :
1284 if (subtype != VSLENGTH && (dblquote || arinest))
1286 *(stackblock() + typeloc) = subtype | flags;
1287 if (subtype != VSNORMAL)
1290 goto parsesub_return;
1295 * Called to parse command substitutions. Newstyle is set if the command
1296 * is enclosed inside $(...); nlpp is a pointer to the head of the linked
1297 * list of commands (passed by reference), and savelen is the number of
1298 * characters on the top of the stack which must be preserved.
1302 struct nodelist **nlpp;
1306 struct jmploc jmploc;
1307 struct jmploc *volatile savehandler;
1311 /* Avoid longjmp clobbering */
1315 savepbq = parsebackquote;
1316 if (setjmp(jmploc.loc)) {
1320 handler = savehandler;
1321 longjmp(handler->loc, 1);
1325 savelen = out - stackblock();
1327 str = ckmalloc(savelen);
1328 memcpy(str, stackblock(), savelen);
1330 savehandler = handler;
1334 /* We must read until the closing backquote, giving special
1335 treatment to some slashes, and then push the string and
1336 reread it as input, interpreting it normally. */
1349 switch (c = pgetc()) {
1354 if ((c = pgetc()) == '\n') {
1361 * If eating a newline, avoid putting
1362 * the newline into the new character
1363 * stream (via the STPUTC after the
1368 if (c != '\\' && c != '`' && c != '$'
1369 && (!dblquote || c != '"'))
1375 needprompt = doprompt;
1379 startlinno = plinno;
1380 synerror("EOF in backquote substitution");
1390 savelen = out - stackblock();
1392 str = ckmalloc(savelen);
1393 memcpy(str, stackblock(), savelen);
1394 setinputstring(str, 1);
1399 nlpp = &(*nlpp)->next;
1400 *nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
1401 (*nlpp)->next = NULL;
1402 parsebackquote = oldstyle;
1405 saveprompt = doprompt;
1412 doprompt = saveprompt;
1414 if (readtoken() != TRP)
1421 * Start reading from old file again, ignoring any pushed back
1422 * tokens left from the backquote parsing
1427 while (stackblocksize() <= savelen)
1431 memcpy(out, str, savelen);
1432 STADJUST(savelen, out);
1438 parsebackquote = savepbq;
1439 handler = savehandler;
1440 if (arinest || dblquote)
1441 USTPUTC(CTLBACKQ | CTLQUOTE, out);
1443 USTPUTC(CTLBACKQ, out);
1445 goto parsebackq_oldreturn;
1447 goto parsebackq_newreturn;
1451 * Parse an arithmetic expansion (indicate start of one and set state)
1455 if (++arinest == 1) {
1456 prevsyntax = syntax;
1458 USTPUTC(CTLARI, out);
1465 * we collapse embedded arithmetic expansion to
1466 * parenthesis, which should be equivalent
1470 goto parsearith_return;
1473 } /* end of readtoken */
1485 * Returns true if the text contains nothing to expand (no dollar signs
1490 noexpand(char *text)
1496 while ((c = *p++) != '\0') {
1497 if ( c == CTLQUOTEMARK)
1501 else if (BASESYNTAX[(int)c] == CCTL)
1509 * Return true if the argument is a legal variable name (a letter or
1510 * underscore followed by zero or more letters, underscores, and digits).
1514 goodname(char *name)
1522 if (! is_in_name(*p))
1530 * Called when an unexpected token is read during the parse. The argument
1531 * is the token that is expected, or -1 if more than one type of token can
1532 * occur at this point.
1536 synexpect(int token)
1541 fmtstr(msg, 64, "%s unexpected (expecting %s)",
1542 tokname[lasttoken], tokname[token]);
1544 fmtstr(msg, 64, "%s unexpected", tokname[lasttoken]);
1554 outfmt(&errout, "%s: %d: ", commandname, startlinno);
1555 outfmt(&errout, "Syntax error: %s\n", msg);
1556 error((char *)NULL);
1560 setprompt(int which)
1562 whichprompt = which;
1567 out2str(getprompt(NULL));
1571 * called by editline -- any expansions to the prompt
1572 * should be added here.
1575 getprompt(void *unused __unused)
1577 switch (whichprompt) {
1585 return "<internal prompt error>";