提交 44e6909a 创建 作者: kaashoek's avatar kaashoek

more simplifying

上级 e00baa9f
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define BUFSIZ 512 #define BUFSIZ 512
#define MAXARGS 10 #define MAXARGS 10
#define MAXNODE 2 #define MAXIO 2
#define MAXCMD 2 #define MAXCMD 2
// an embarrassingly naive shell // an embarrassingly naive shell
...@@ -22,7 +22,7 @@ struct cmd { ...@@ -22,7 +22,7 @@ struct cmd {
char argv0buf[BUFSIZ]; char argv0buf[BUFSIZ];
int argc; int argc;
int token; int token;
struct ionode iolist[MAXNODE]; struct ionode iolist[MAXIO];
struct ionode *io; struct ionode *io;
}; };
struct cmd cmdlist[MAXCMD]; struct cmd cmdlist[MAXCMD];
...@@ -75,30 +75,28 @@ parse(char *s) ...@@ -75,30 +75,28 @@ parse(char *s)
cmd->argv[cmd->argc++] = t; cmd->argv[cmd->argc++] = t;
break; break;
case '<': // Input redirection case '>': // Input and output redirection
case '<':
// Grab the filename from the argument list // Grab the filename from the argument list
if(gettoken(0, &t) != 'w') { if(gettoken(0, &t) != 'w') {
printf(2, "syntax error: < not followed by word\n"); printf(2, "syntax error: > not followed by word\n");
return -1; return -1;
} }
cmd->io->token = '<'; if(cmd->io - cmd->iolist >= MAXIO) {
cmd->io->s = t; printf(2, "too many redirections\n");
cmd->io++;
break;
case '>': // Output redirection
// Grab the filename from the argument list
if(gettoken(0, &t) != 'w') {
printf(2, "syntax error: > not followed by word\n");
return -1; return -1;
} }
cmd->io->token = '>'; cmd->io->token = c;
cmd->io->s = t; cmd->io->s = t;
cmd->io++; cmd->io++;
break; break;
case ';': // command sequence case ';': // command sequence
case '|': // pipe case '|': // pipe
if(cmd->io - cmd->iolist >= MAXIO) {
printf(2, "too many redirections\n");
return -1;
}
cmd->token = c; cmd->token = c;
cmd++; cmd++;
break; break;
...@@ -114,7 +112,6 @@ parse(char *s) ...@@ -114,7 +112,6 @@ parse(char *s)
} }
} }
void void
runcmd(void) runcmd(void)
{ {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论