Changes in uspace/app/bdsh/input.c [36ab7c7:b48d046] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
r36ab7c7 rb48d046 1 1 /* 2 2 * Copyright (c) 2008 Tim Post 3 * Copyright (c) 2011 Jiri Svoboda 4 * Copyright (c) 2011 Martin Sucha 3 5 * All rights reserved. 4 6 * … … 43 45 44 46 #include "config.h" 47 #include "compl.h" 45 48 #include "util.h" 46 49 #include "scli.h" … … 64 67 int process_input(cliuser_t *usr) 65 68 { 69 token_t *tokens = calloc(WORD_MAX, sizeof(token_t)); 70 if (tokens == NULL) 71 return ENOMEM; 72 66 73 char *cmd[WORD_MAX]; 67 74 int rc = 0; 68 75 tokenizer_t tok; 69 int i, pipe_count, processed_pipes; 70 int pipe_pos[2]; 71 char **actual_cmd; 76 unsigned int i, pipe_count, processed_pipes; 77 unsigned int pipe_pos[2]; 72 78 char *redir_from = NULL; 73 79 char *redir_to = NULL; 74 80 75 if (NULL == usr->line) 81 if (usr->line == NULL) { 82 free(tokens); 76 83 return CL_EFAIL; 77 78 rc = tok_init(&tok, usr->line, cmd, WORD_MAX); 84 } 85 86 rc = tok_init(&tok, usr->line, tokens, WORD_MAX); 79 87 if (rc != EOK) { 80 88 goto finit; 81 89 } 82 90 83 rc = tok_tokenize(&tok); 91 size_t tokens_length; 92 rc = tok_tokenize(&tok, &tokens_length); 84 93 if (rc != EOK) { 85 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--; 86 104 } 87 105 … … 91 109 * First find the pipes and check that there are no more 92 110 */ 93 int cmd_length = 0; 94 for (i = 0, pipe_count = 0; cmd[i] != NULL; i++, cmd_length++) { 95 if (cmd[i][0] == '|') { 111 for (i = 0, pipe_count = 0; i < tokens_length; i++) { 112 if (tokens[i].type == TOKTYPE_PIPE) { 96 113 if (pipe_count >= 2) { 97 114 print_pipe_usage(); … … 104 121 } 105 122 106 actual_cmd = cmd; 123 unsigned int cmd_token_start = 0; 124 unsigned int cmd_token_end = tokens_length; 125 107 126 processed_pipes = 0; 108 127 109 128 /* Check if the first part (from <file> |) is present */ 110 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) { 111 130 /* Ignore the first three tokens (from, file, pipe) and set from */ 112 redir_from = cmd[1];113 actual_cmd = cmd + 3;131 redir_from = tokens[2].text; 132 cmd_token_start = pipe_pos[0]+1; 114 133 processed_pipes++; 115 134 } … … 117 136 /* Check if the second part (| to <file>) is present */ 118 137 if ((pipe_count - processed_pipes) > 0 && 119 pipe_pos[processed_pipes] == cmd_length - 3 && 120 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) { 121 142 /* Ignore the last three tokens (pipe, to, file) and set to */ 122 redir_to = cmd[cmd_length-1]; 123 cmd[cmd_length-3] = NULL; 124 cmd_length -= 3; 143 redir_to = tokens[tokens_length-1].text; 144 cmd_token_end = pipe_pos[processed_pipes]; 125 145 processed_pipes++; 126 146 } … … 132 152 } 133 153 134 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) { 135 164 print_pipe_usage(); 136 165 rc = ENOTSUP; … … 184 213 } 185 214 tok_fini(&tok); 215 free(tokens); 186 216 187 217 return rc; … … 226 256 int rc; 227 257 228 console_flush(tinput->console); 229 console_set_style(tinput->console, STYLE_EMPHASIS); 230 printf("%s", usr->prompt); 231 console_flush(tinput->console); 232 console_set_style(tinput->console, STYLE_NORMAL); 258 tinput_set_prompt(tinput, usr->prompt); 233 259 234 260 rc = tinput_read(tinput, &str); … … 263 289 } 264 290 291 tinput_set_compl_ops(tinput, &compl_ops); 292 265 293 return 0; 266 294 }
Note:
See TracChangeset
for help on using the changeset viewer.