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