Changeset 0662451 in mainline for uspace/app/bdsh/input.c
- Timestamp:
- 2011-08-19T14:44:49Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5992e0e
- Parents:
- 89660f2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
r89660f2 r0662451 67 67 { 68 68 char *cmd[WORD_MAX]; 69 token_t tokens_space[WORD_MAX]; 70 token_t *tokens = tokens_space; 69 71 int rc = 0; 70 72 tokenizer_t tok; 71 int i, pipe_count, processed_pipes; 72 int pipe_pos[2]; 73 char **actual_cmd; 73 unsigned int i, pipe_count, processed_pipes; 74 unsigned int pipe_pos[2]; 74 75 char *redir_from = NULL; 75 76 char *redir_to = NULL; … … 78 79 return CL_EFAIL; 79 80 80 rc = tok_init(&tok, usr->line, cmd, WORD_MAX);81 rc = tok_init(&tok, usr->line, tokens, WORD_MAX); 81 82 if (rc != EOK) { 82 83 goto finit; 83 84 } 84 85 85 rc = tok_tokenize(&tok); 86 size_t tokens_length; 87 rc = tok_tokenize(&tok, &tokens_length); 86 88 if (rc != EOK) { 87 89 goto finit; 90 } 91 92 if (tokens_length > 0 && tokens[0].type == TOKTYPE_SPACE) { 93 tokens++; 94 tokens_length--; 95 } 96 97 if (tokens_length > 0 && tokens[tokens_length-1].type == TOKTYPE_SPACE) { 98 tokens_length--; 88 99 } 89 100 … … 93 104 * First find the pipes and check that there are no more 94 105 */ 95 int cmd_length = 0; 96 for (i = 0, pipe_count = 0; cmd[i] != NULL; i++, cmd_length++) { 97 if (cmd[i][0] == '|') { 106 for (i = 0, pipe_count = 0; i < tokens_length; i++) { 107 if (tokens[i].type == TOKTYPE_PIPE) { 98 108 if (pipe_count >= 2) { 99 109 print_pipe_usage(); … … 106 116 } 107 117 108 actual_cmd = cmd; 118 unsigned int cmd_token_start = 0; 119 unsigned int cmd_token_end = tokens_length; 120 109 121 processed_pipes = 0; 110 122 111 123 /* Check if the first part (from <file> |) is present */ 112 if (pipe_count > 0 && pipe_pos[0] == 2 && str_cmp(cmd[0], "from") == 0) {124 if (pipe_count > 0 && (pipe_pos[0] == 3 || pipe_pos[0] == 4) && str_cmp(tokens[0].text, "from") == 0) { 113 125 /* Ignore the first three tokens (from, file, pipe) and set from */ 114 redir_from = cmd[1]; 115 actual_cmd = cmd + 3; 126 redir_from = tokens[2].text; 127 cmd_token_start = pipe_pos[0]+1; 128 printf("set cmd_token_start = %d\n", cmd_token_start); 116 129 processed_pipes++; 117 130 } … … 119 132 /* Check if the second part (| to <file>) is present */ 120 133 if ((pipe_count - processed_pipes) > 0 && 121 pipe_pos[processed_pipes] == cmd_length - 3 && 122 str_cmp(cmd[cmd_length-2], "to") == 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) { 123 138 /* Ignore the last three tokens (pipe, to, file) and set to */ 124 redir_to = cmd[cmd_length-1];125 cmd [cmd_length-3] = NULL;126 cmd_length -= 3;139 redir_to = tokens[tokens_length-1].text; 140 cmd_token_end = pipe_pos[processed_pipes]; 141 printf("set cmd_token_end = %d\n", cmd_token_end); 127 142 processed_pipes++; 128 143 } … … 134 149 } 135 150 136 if (actual_cmd[0] == NULL) { 151 /* Convert tokens of the command to string array */ 152 unsigned int cmd_pos = 0; 153 for (i = cmd_token_start; i < cmd_token_end; i++) { 154 if (tokens[i].type != TOKTYPE_SPACE) { 155 cmd[cmd_pos++] = tokens[i].text; 156 printf("%s\n", tokens[i].text); 157 } 158 } 159 cmd[cmd_pos++] = NULL; 160 161 if (cmd[0] == NULL) { 137 162 print_pipe_usage(); 138 163 rc = ENOTSUP; … … 170 195 } 171 196 172 rc = run_command( actual_cmd, usr, &new_iostate);197 rc = run_command(cmd, usr, &new_iostate); 173 198 174 199 finit_with_files:
Note:
See TracChangeset
for help on using the changeset viewer.