Changeset a35b458 in mainline for uspace/app/bdsh/input.c
- Timestamp:
- 2018-03-02T20:10:49Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
r3061bc1 ra35b458 71 71 return ENOMEM; 72 72 token_t *tokens = tokens_buf; 73 73 74 74 char *cmd[WORD_MAX]; 75 75 errno_t rc = EOK; … … 89 89 goto finit; 90 90 } 91 91 92 92 size_t tokens_length; 93 93 rc = tok_tokenize(&tok, &tokens_length); … … 95 95 goto finit; 96 96 } 97 97 98 98 if (tokens_length > 0 && tokens[0].type == TOKTYPE_SPACE) { 99 99 tokens++; 100 100 tokens_length--; 101 101 } 102 102 103 103 if (tokens_length > 0 && tokens[tokens_length-1].type == TOKTYPE_SPACE) { 104 104 tokens_length--; 105 105 } 106 106 107 107 /* Until full support for pipes is implemented, allow for a simple case: 108 108 * [from <file> |] command [| to <file>] … … 121 121 } 122 122 } 123 123 124 124 unsigned int cmd_token_start = 0; 125 125 unsigned int cmd_token_end = tokens_length; 126 126 127 127 processed_pipes = 0; 128 128 129 129 /* Check if the first part (from <file> |) is present */ 130 130 if (pipe_count > 0 && (pipe_pos[0] == 3 || pipe_pos[0] == 4) && str_cmp(tokens[0].text, "from") == 0) { … … 134 134 processed_pipes++; 135 135 } 136 136 137 137 /* Check if the second part (| to <file>) is present */ 138 138 if ((pipe_count - processed_pipes) > 0 && … … 146 146 processed_pipes++; 147 147 } 148 148 149 149 if (processed_pipes != pipe_count) { 150 150 print_pipe_usage(); … … 152 152 goto finit; 153 153 } 154 154 155 155 /* Convert tokens of the command to string array */ 156 156 unsigned int cmd_pos = 0; … … 161 161 } 162 162 cmd[cmd_pos++] = NULL; 163 163 164 164 if (cmd[0] == NULL) { 165 165 print_pipe_usage(); … … 167 167 goto finit; 168 168 } 169 169 170 170 iostate_t new_iostate = { 171 171 .stdin = stdin, … … 173 173 .stderr = stderr 174 174 }; 175 175 176 176 FILE *from = NULL; 177 177 FILE *to = NULL; 178 178 179 179 if (redir_from) { 180 180 from = fopen(redir_from, "r"); … … 186 186 new_iostate.stdin = from; 187 187 } 188 189 188 189 190 190 if (redir_to) { 191 191 to = fopen(redir_to, "w"); … … 203 203 rc = EINVAL; 204 204 } 205 205 206 206 finit_with_files: 207 207 if (from != NULL) { … … 211 211 fclose(to); 212 212 } 213 213 214 214 finit: 215 215 if (NULL != usr->line) { … … 230 230 printf("from filename | command ... | to filename\n"); 231 231 printf("command ... | to filename\n"); 232 232 233 233 } 234 234 … … 236 236 { 237 237 int id = 0; 238 238 239 239 /* We have rubbish */ 240 240 if (NULL == cmd[0]) { 241 241 return CL_ENOENT; 242 242 } 243 243 244 244 /* Is it a builtin command ? */ 245 245 if ((id = (is_builtin(cmd[0]))) > -1) { 246 246 return run_builtin(id, cmd, usr, new_iostate); 247 247 } 248 248 249 249 /* Is it a module ? */ 250 250 if ((id = (is_module(cmd[0]))) > -1) { … … 260 260 char *str; 261 261 errno_t rc; 262 262 263 263 tinput_set_prompt(tinput, usr->prompt); 264 264
Note:
See TracChangeset
for help on using the changeset viewer.