11 return !strchr("\n \t#;&|^$=`'{}()<>", c) && c!=EOF;
19 * return 'a'<=c && c<='z' || 'A'<=c && c<='Z' || '0'<=c && c<='9'
20 * || c=='_' || c=='*';
22 return c>' ' && !strchr("!\"#$%&'()+,-./:;<=>?@[\\]^`{|}~", c);
29 * Look ahead in the input stream
40 * Consume the lookahead character.
52 * read a character from the input stream
59 static int peekc = EOF;
69 c = rchr(runq->cmdfd);
70 if(!inquote && c=='\\'){
71 c = rchr(runq->cmdfd);
72 if(c=='\n' && !incomm){ /* don't continue a comment */
81 doprompt = doprompt || c=='\n' || c==EOF;
84 else if(flag['V'] || ndot>=2 && flag['v']) pchr(err, c);
98 if((fd=open("/dev/wdir", OWRITE))>=0){
99 getwd(dir, sizeof(dir));
100 write(fd, dir, strlen(dir));
105 prompt = vlook("prompt");
106 if(prompt->val && prompt->val->next)
107 promptstr = prompt->val->next->word;
121 /* Why did this used to be if(!inquote && c=='#') ?? */
126 if(c=='\n' || c==EOF) {
133 if(c==' ' || c=='\t')
163 addtok(char *p, int val)
169 yyerror("token buffer too short");
177 addutf(char *p, int c)
182 p = addtok(p, c); /* 1-byte UTF runes are special */
188 for(i=1; i < UTFmax; i++){
191 p = addtok(p, advance());
198 int lastdol; /* was the last token read '$' or '$#' or '"'? */
199 int lastword; /* was the last token read a word or compound word terminator? */
209 * Embarassing sneakiness: if the last token read was a quoted or unquoted
210 * WORD then we alter the meaning of what follows. If the next character
211 * is `(', we return SUB (a subscript paren) and consume the `('. Otherwise,
212 * if the next character is the first character of a simple or compound word,
213 * we insert a `^' before it.
219 strcpy(tok, "( [SUB]");
222 if(wordchr(d) || d=='\'' || d=='`' || d=='$' || d=='"'){
229 switch(c = advance()){
266 * funny redirection tokens:
267 * redir: arrow | arrow '[' fd ']'
268 * arrow: '<' | '<<' | '>' | '>>' | '|'
269 * fd: digit | digit '=' | digit '=' digit
270 * digit: '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
271 * some possibilities are nonsensical and get a message.
287 else t->rtype = WRITE;
295 } else if (nextis('>')){
298 } else t->rtype = READ;
309 yyerror(t->type==PIPE?"pipe syntax"
310 :"redirection syntax");
315 t->fd0 = t->fd0*10+c-'0';
318 }while('0'<=c && c<='9');
324 if('0'<=c && c<='9'){
329 t->fd0 = t->fd0*10+c-'0';
332 }while('0'<=c && c<='9');
341 || t->type==DUP && (t->rtype==HERE || t->rtype==APPEND))
367 t = token(tok, WORD);
379 if(c=='*' || c=='[' || c=='?' || c==GLOB)
383 if(lastdol?!idchr(c):!wordchr(c)) break;