Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/input.c

    r81bc309 reff10e03  
    22 * Copyright (c) 2008 Tim Post
    33 * Copyright (c) 2011 Jiri Svoboda
    4  * Copyright (c) 2011 Martin Sucha
    54 * All rights reserved.
    65 *
     
    6867{
    6968        char *cmd[WORD_MAX];
    70         token_t tokens_space[WORD_MAX];
    71         token_t *tokens = tokens_space;
    7269        int rc = 0;
    7370        tokenizer_t tok;
    74         unsigned int i, pipe_count, processed_pipes;
    75         unsigned int pipe_pos[2];
     71        int i, pipe_count, processed_pipes;
     72        int pipe_pos[2];
     73        char **actual_cmd;
    7674        char *redir_from = NULL;
    7775        char *redir_to = NULL;
     
    8078                return CL_EFAIL;
    8179
    82         rc = tok_init(&tok, usr->line, tokens, WORD_MAX);
     80        rc = tok_init(&tok, usr->line, cmd, WORD_MAX);
    8381        if (rc != EOK) {
    8482                goto finit;
    8583        }
    8684       
    87         size_t tokens_length;
    88         rc = tok_tokenize(&tok, &tokens_length);
     85        rc = tok_tokenize(&tok);
    8986        if (rc != EOK) {
    9087                goto finit;
    91         }
    92        
    93         if (tokens_length > 0 && tokens[0].type == TOKTYPE_SPACE) {
    94                 tokens++;
    95                 tokens_length--;
    96         }
    97        
    98         if (tokens_length > 0 && tokens[tokens_length-1].type == TOKTYPE_SPACE) {
    99                 tokens_length--;
    10088        }
    10189       
     
    10593         * First find the pipes and check that there are no more
    10694         */
    107         for (i = 0, pipe_count = 0; i < tokens_length; i++) {
    108                 if (tokens[i].type == TOKTYPE_PIPE) {
     95        int cmd_length = 0;
     96        for (i = 0, pipe_count = 0; cmd[i] != NULL; i++, cmd_length++) {
     97                if (cmd[i][0] == '|') {
    10998                        if (pipe_count >= 2) {
    11099                                print_pipe_usage();
     
    117106        }
    118107       
    119         unsigned int cmd_token_start = 0;
    120         unsigned int cmd_token_end = tokens_length;
    121        
     108        actual_cmd = cmd;
    122109        processed_pipes = 0;
    123110       
    124111        /* Check if the first part (from <file> |) is present */
    125         if (pipe_count > 0 && (pipe_pos[0] == 3 || pipe_pos[0] == 4) && str_cmp(tokens[0].text, "from") == 0) {
     112        if (pipe_count > 0 && pipe_pos[0] == 2 && str_cmp(cmd[0], "from") == 0) {
    126113                /* Ignore the first three tokens (from, file, pipe) and set from */
    127                 redir_from = tokens[2].text;
    128                 cmd_token_start = pipe_pos[0]+1;
     114                redir_from = cmd[1];
     115                actual_cmd = cmd + 3;
    129116                processed_pipes++;
    130117        }
     
    132119        /* Check if the second part (| to <file>) is present */
    133120        if ((pipe_count - processed_pipes) > 0 &&
    134             (pipe_pos[processed_pipes] == tokens_length - 4 ||
    135             (pipe_pos[processed_pipes] == tokens_length - 5 &&
    136             tokens[tokens_length-4].type == TOKTYPE_SPACE )) &&
    137             str_cmp(tokens[tokens_length-3].text, "to") == 0) {
     121            pipe_pos[processed_pipes] == cmd_length - 3 &&
     122            str_cmp(cmd[cmd_length-2], "to") == 0) {
    138123                /* Ignore the last three tokens (pipe, to, file) and set to */
    139                 redir_to = tokens[tokens_length-1].text;
    140                 cmd_token_end = pipe_pos[processed_pipes];
     124                redir_to = cmd[cmd_length-1];
     125                cmd[cmd_length-3] = NULL;
     126                cmd_length -= 3;
    141127                processed_pipes++;
    142128        }
     
    148134        }
    149135       
    150         /* Convert tokens of the command to string array */
    151         unsigned int cmd_pos = 0;
    152         for (i = cmd_token_start; i < cmd_token_end; i++) {
    153                 if (tokens[i].type != TOKTYPE_SPACE) {
    154                         cmd[cmd_pos++] = tokens[i].text;
    155                 }
    156         }
    157         cmd[cmd_pos++] = NULL;
    158        
    159         if (cmd[0] == NULL) {
     136        if (actual_cmd[0] == NULL) {
    160137                print_pipe_usage();
    161138                rc = ENOTSUP;
     
    192169                new_iostate.stdout = to;
    193170        }
    194 
    195         rc = run_command(cmd, usr, &new_iostate);
     171       
     172        rc = run_command(actual_cmd, usr, &new_iostate);
    196173       
    197174finit_with_files:
Note: See TracChangeset for help on using the changeset viewer.