Changes in uspace/app/bdsh/input.c [81bc309:eff10e03] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
r81bc309 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 * … … 68 67 { 69 68 char *cmd[WORD_MAX]; 70 token_t tokens_space[WORD_MAX];71 token_t *tokens = tokens_space;72 69 int rc = 0; 73 70 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; 76 74 char *redir_from = NULL; 77 75 char *redir_to = NULL; … … 80 78 return CL_EFAIL; 81 79 82 rc = tok_init(&tok, usr->line, tokens, WORD_MAX);80 rc = tok_init(&tok, usr->line, cmd, WORD_MAX); 83 81 if (rc != EOK) { 84 82 goto finit; 85 83 } 86 84 87 size_t tokens_length; 88 rc = tok_tokenize(&tok, &tokens_length); 85 rc = tok_tokenize(&tok); 89 86 if (rc != EOK) { 90 87 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--;100 88 } 101 89 … … 105 93 * First find the pipes and check that there are no more 106 94 */ 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] == '|') { 109 98 if (pipe_count >= 2) { 110 99 print_pipe_usage(); … … 117 106 } 118 107 119 unsigned int cmd_token_start = 0; 120 unsigned int cmd_token_end = tokens_length; 121 108 actual_cmd = cmd; 122 109 processed_pipes = 0; 123 110 124 111 /* 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) { 126 113 /* 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; 129 116 processed_pipes++; 130 117 } … … 132 119 /* Check if the second part (| to <file>) is present */ 133 120 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) { 138 123 /* 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; 141 127 processed_pipes++; 142 128 } … … 148 134 } 149 135 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) { 160 137 print_pipe_usage(); 161 138 rc = ENOTSUP; … … 192 169 new_iostate.stdout = to; 193 170 } 194 195 rc = run_command( cmd, usr, &new_iostate);171 172 rc = run_command(actual_cmd, usr, &new_iostate); 196 173 197 174 finit_with_files:
Note:
See TracChangeset
for help on using the changeset viewer.