diff options
| author | kaashoek <kaashoek> | 2006-09-07 03:16:15 +0000 | 
|---|---|---|
| committer | kaashoek <kaashoek> | 2006-09-07 03:16:15 +0000 | 
| commit | 44e6909a6d33689cefb283ecb91dfe1d874f8e0b (patch) | |
| tree | 296c91f8fec3bc5f2a569ffc1b88bd82e0c7155c | |
| parent | e00baa9f5d15d745a26cbb0a9ae54e3ea4fb9696 (diff) | |
| download | xv6-labs-44e6909a6d33689cefb283ecb91dfe1d874f8e0b.tar.gz xv6-labs-44e6909a6d33689cefb283ecb91dfe1d874f8e0b.tar.bz2 xv6-labs-44e6909a6d33689cefb283ecb91dfe1d874f8e0b.zip | |
more simplifying
| -rw-r--r-- | sh.c | 27 | 
1 files changed, 12 insertions, 15 deletions
| @@ -6,7 +6,7 @@  #define BUFSIZ  512  #define MAXARGS  10 -#define MAXNODE 2 +#define MAXIO 2  #define MAXCMD  2  // an embarrassingly naive shell @@ -22,7 +22,7 @@ struct cmd {    char argv0buf[BUFSIZ];    int argc;    int token; -  struct ionode iolist[MAXNODE]; +  struct ionode iolist[MAXIO];    struct ionode *io;  };  struct cmd cmdlist[MAXCMD]; @@ -75,30 +75,28 @@ parse(char *s)        cmd->argv[cmd->argc++] = t;        break; -    case '<':   // Input redirection +    case '>':   // Input and output redirection +    case '<':        // Grab the filename from the argument list        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;        } -      cmd->io->token = '<'; -      cmd->io->s = t; -      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"); +      if(cmd->io - cmd->iolist >= MAXIO) { +        printf(2, "too many redirections\n");          return -1;        } -      cmd->io->token = '>'; +      cmd->io->token = c;        cmd->io->s = t;        cmd->io++;        break;      case ';':  // command sequence      case '|':  // pipe +      if(cmd->io - cmd->iolist >= MAXIO) { +        printf(2, "too many redirections\n"); +        return -1; +      }        cmd->token = c;        cmd++;        break; @@ -114,7 +112,6 @@ parse(char *s)    }  } -  void  runcmd(void)  { | 
