Example #1
0
STATIC void
parseheredoc() {
      struct heredoc *here;
      union node *n;

      while (heredoclist) {
            here = heredoclist;
            heredoclist = here->next;
            if (needprompt) {
                  putprompt(ps2val());
                  needprompt = 0;
            }
            readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
                        here->eofmark, here->striptabs);
            n = (union node *)stalloc(sizeof (struct narg));
            n->narg.type = NARG;
            n->narg.next = NULL;
            n->narg.text = wordtext;
            n->narg.backquote = backquotelist;
            here->here->nhere.doc = n;
      }
}
Example #2
0
STATIC int
xxreadtoken(void)
{
	int c;

	if (tokpushback) {
		tokpushback = 0;
		return lasttoken;
	}
	if (needprompt) {
		setprompt(2);
		needprompt = 0;
	}
	startlinno = plinno;
	for (;;) {	/* until token or start of word found */
		c = pgetc_macro();
		if (c == ' ' || c == '\t')
			continue;		/* quick check for white space first */
		switch (c) {
		case ' ': case '\t':
			continue;
		case '#':
			while ((c = pgetc()) != '\n' && c != PEOF);
			pungetc();
			continue;
		case '\\':
			if (pgetc() == '\n') {
				startlinno = ++plinno;
				if (doprompt)
					setprompt(2);
				else
					setprompt(0);
				continue;
			}
			pungetc();
			goto breakloop;
		case '\n':
			plinno++;
			needprompt = doprompt;
			RETURN(TNL);
		case PEOF:
			RETURN(TEOF);
		case '&':
			if (pgetc() == '&')
				RETURN(TAND);
			pungetc();
			RETURN(TBACKGND);
		case '|':
			if (pgetc() == '|')
				RETURN(TOR);
			pungetc();
			RETURN(TPIPE);
		case ';':
			if (pgetc() == ';')
				RETURN(TENDCASE);
			pungetc();
			RETURN(TSEMI);
		case '(':
			RETURN(TLP);
		case ')':
			RETURN(TRP);
		default:
			goto breakloop;
		}
	}
breakloop:
	return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
#undef RETURN
}