Changes in uspace/app/bdsh/input.c [eff10e03:b2727f18] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
reff10e03 rb2727f18 2 2 * Copyright (c) 2008 Tim Post 3 3 * Copyright (c) 2011 Jiri Svoboda 4 * Copyright (c) 2011 Martin Sucha 4 5 * All rights reserved. 5 6 * … … 67 68 { 68 69 char *cmd[WORD_MAX]; 70 token_t tokens_space[WORD_MAX]; 71 token_t *tokens = tokens_space; 69 72 int rc = 0; 70 73 tokenizer_t tok; 71 int i, pipe_count, processed_pipes; 72 int pipe_pos[2]; 73 char **actual_cmd; 74 unsigned int i, pipe_count, processed_pipes; 75 unsigned int pipe_pos[2]; 74 76 char *redir_from = NULL; 75 77 char *redir_to = NULL; … … 78 80 return CL_EFAIL; 79 81 80 rc = tok_init(&tok, usr->line, cmd, WORD_MAX);82 rc = tok_init(&tok, usr->line, tokens, WORD_MAX); 81 83 if (rc != EOK) { 82 84 goto finit; 83 85 } 84 86 85 rc = tok_tokenize(&tok); 87 size_t tokens_length; 88 rc = tok_tokenize(&tok, &tokens_length); 86 89 if (rc != EOK) { 87 90 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--; 88 100 } 89 101 … … 93 105 * First find the pipes and check that there are no more 94 106 */ 95 int cmd_length = 0; 96 for (i = 0, pipe_count = 0; cmd[i] != NULL; i++, cmd_length++) { 97 if (cmd[i][0] == '|') { 107 for (i = 0, pipe_count = 0; i < tokens_length; i++) { 108 if (tokens[i].type == TOKTYPE_PIPE) { 98 109 if (pipe_count >= 2) { 99 110 print_pipe_usage(); … … 106 117 } 107 118 108 actual_cmd = cmd; 119 unsigned int cmd_token_start = 0; 120 unsigned int cmd_token_end = tokens_length; 121 109 122 processed_pipes = 0; 110 123 111 124 /* Check if the first part (from <file> |) is present */ 112 if (pipe_count > 0 && pipe_pos[0] == 2 && str_cmp(cmd[0], "from") == 0) {125 if (pipe_count > 0 && (pipe_pos[0] == 3 || pipe_pos[0] == 4) && str_cmp(tokens[0].text, "from") == 0) { 113 126 /* Ignore the first three tokens (from, file, pipe) and set from */ 114 redir_from = cmd[1];115 actual_cmd = cmd + 3;127 redir_from = tokens[2].text; 128 cmd_token_start = pipe_pos[0]+1; 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]; 127 141 processed_pipes++; 128 142 } … … 134 148 } 135 149 136 if (actual_cmd[0] == NULL) { 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) { 137 160 print_pipe_usage(); 138 161 rc = ENOTSUP; … … 170 193 } 171 194 172 rc = run_command( actual_cmd, usr, &new_iostate);195 rc = run_command(cmd, usr, &new_iostate); 173 196 174 197 finit_with_files:
Note:
See TracChangeset
for help on using the changeset viewer.