Changes in uspace/app/bdsh/input.c [b48d046:eff10e03] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
rb48d046 reff10e03 2 2 * Copyright (c) 2008 Tim Post 3 3 * Copyright (c) 2011 Jiri Svoboda 4 * Copyright (c) 2011 Martin Sucha5 4 * All rights reserved. 6 5 * … … 67 66 int process_input(cliuser_t *usr) 68 67 { 69 token_t *tokens = calloc(WORD_MAX, sizeof(token_t));70 if (tokens == NULL)71 return ENOMEM;72 73 68 char *cmd[WORD_MAX]; 74 69 int rc = 0; 75 70 tokenizer_t tok; 76 unsigned int i, pipe_count, processed_pipes; 77 unsigned int pipe_pos[2]; 71 int i, pipe_count, processed_pipes; 72 int pipe_pos[2]; 73 char **actual_cmd; 78 74 char *redir_from = NULL; 79 75 char *redir_to = NULL; 80 76 81 if (usr->line == NULL) { 82 free(tokens); 77 if (NULL == usr->line) 83 78 return CL_EFAIL; 84 } 85 86 rc = tok_init(&tok, usr->line, tokens, WORD_MAX); 79 80 rc = tok_init(&tok, usr->line, cmd, WORD_MAX); 87 81 if (rc != EOK) { 88 82 goto finit; 89 83 } 90 84 91 size_t tokens_length; 92 rc = tok_tokenize(&tok, &tokens_length); 85 rc = tok_tokenize(&tok); 93 86 if (rc != EOK) { 94 87 goto finit; 95 }96 97 if (tokens_length > 0 && tokens[0].type == TOKTYPE_SPACE) {98 tokens++;99 tokens_length--;100 }101 102 if (tokens_length > 0 && tokens[tokens_length-1].type == TOKTYPE_SPACE) {103 tokens_length--;104 88 } 105 89 … … 109 93 * First find the pipes and check that there are no more 110 94 */ 111 for (i = 0, pipe_count = 0; i < tokens_length; i++) { 112 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] == '|') { 113 98 if (pipe_count >= 2) { 114 99 print_pipe_usage(); … … 121 106 } 122 107 123 unsigned int cmd_token_start = 0; 124 unsigned int cmd_token_end = tokens_length; 125 108 actual_cmd = cmd; 126 109 processed_pipes = 0; 127 110 128 111 /* Check if the first part (from <file> |) is present */ 129 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) { 130 113 /* Ignore the first three tokens (from, file, pipe) and set from */ 131 redir_from = tokens[2].text;132 cmd_token_start = pipe_pos[0]+1;114 redir_from = cmd[1]; 115 actual_cmd = cmd + 3; 133 116 processed_pipes++; 134 117 } … … 136 119 /* Check if the second part (| to <file>) is present */ 137 120 if ((pipe_count - processed_pipes) > 0 && 138 (pipe_pos[processed_pipes] == tokens_length - 4 || 139 (pipe_pos[processed_pipes] == tokens_length - 5 && 140 tokens[tokens_length-4].type == TOKTYPE_SPACE )) && 141 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) { 142 123 /* Ignore the last three tokens (pipe, to, file) and set to */ 143 redir_to = tokens[tokens_length-1].text; 144 cmd_token_end = pipe_pos[processed_pipes]; 124 redir_to = cmd[cmd_length-1]; 125 cmd[cmd_length-3] = NULL; 126 cmd_length -= 3; 145 127 processed_pipes++; 146 128 } … … 152 134 } 153 135 154 /* Convert tokens of the command to string array */ 155 unsigned int cmd_pos = 0; 156 for (i = cmd_token_start; i < cmd_token_end; i++) { 157 if (tokens[i].type != TOKTYPE_SPACE) { 158 cmd[cmd_pos++] = tokens[i].text; 159 } 160 } 161 cmd[cmd_pos++] = NULL; 162 163 if (cmd[0] == NULL) { 136 if (actual_cmd[0] == NULL) { 164 137 print_pipe_usage(); 165 138 rc = ENOTSUP; … … 197 170 } 198 171 199 rc = run_command( cmd, usr, &new_iostate);172 rc = run_command(actual_cmd, usr, &new_iostate); 200 173 201 174 finit_with_files: … … 213 186 } 214 187 tok_fini(&tok); 215 free(tokens);216 188 217 189 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.