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