aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rc/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/rc/lex.c')
-rw-r--r--src/cmd/rc/lex.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/cmd/rc/lex.c b/src/cmd/rc/lex.c
index 973ddee8..e4410c00 100644
--- a/src/cmd/rc/lex.c
+++ b/src/cmd/rc/lex.c
@@ -102,15 +102,17 @@ pprompt(void)
doprompt = 0;
}
-void
+int
skipwhite(void)
{
- int c;
+ int c, skipped;
+ skipped = 0;
for(;;){
c = nextc();
/* Why did this used to be if(!inquote && c=='#') ?? */
if(c=='#'){
incomm = 1;
+ skipped = 1;
for(;;){
c = nextc();
if(c=='\n' || c==EOF) {
@@ -120,9 +122,12 @@ skipwhite(void)
advance();
}
}
- if(c==' ' || c=='\t')
+ if(c==' ' || c=='\t') {
+ skipped = 1;
advance();
- else return;
+ }
+ else
+ return skipped;
}
}
@@ -188,7 +193,7 @@ yylex(void)
{
int c, d = nextc();
char *w = tok;
- struct tree *t;
+ tree *t;
yylval.tree = 0;
/*
* Embarassing sneakiness: if the last token read was a quoted or unquoted
@@ -197,11 +202,11 @@ yylex(void)
* if the next character is the first character of a simple or compound word,
* we insert a `^' before it.
*/
- if(lastword){
+ if(lastword && flag['Y']){
lastword = 0;
if(d=='('){
advance();
- strcpy(tok, "( [SUB]");
+ strcpy(tok, "(");
return SUB;
}
if(wordchr(d) || d=='\'' || d=='`' || d=='$' || d=='"'){
@@ -210,7 +215,8 @@ yylex(void)
}
}
inquote = 0;
- skipwhite();
+ if(skipwhite() && !flag['Y'])
+ return ' ';
switch(c = advance()){
case EOF:
lastdol = 0;
@@ -231,7 +237,8 @@ yylex(void)
case '&':
lastdol = 0;
if(nextis('&')){
- skipnl();
+ if(flag['Y'])
+ skipnl();
strcpy(tok, "&&");
return ANDAND;
}
@@ -240,7 +247,8 @@ yylex(void)
case '|':
lastdol = 0;
if(nextis(c)){
- skipnl();
+ if(flag['Y'])
+ skipnl();
strcpy(tok, "||");
return OROR;
}
@@ -329,8 +337,13 @@ yylex(void)
}
*w='\0';
yylval.tree = t;
- if(t->type==PIPE)
+ if(t->type==PIPE && flag['Y'])
skipnl();
+ if(t->type==REDIR) {
+ skipwhite();
+ if(nextc() == '{')
+ t->type = REDIRW;
+ }
return t->type;
case '\'':
lastdol = 0;