Changes in uspace/app/bdsh/input.c [b9ae539:36ab7c7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
rb9ae539 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" … … 68 65 { 69 66 char *cmd[WORD_MAX]; 70 token_t *tokens = calloc(WORD_MAX, sizeof(token_t));71 if (tokens == NULL)72 return ENOMEM;73 67 int rc = 0; 74 68 tokenizer_t tok; 75 unsigned int i, pipe_count, processed_pipes; 76 unsigned int pipe_pos[2]; 69 int i, pipe_count, processed_pipes; 70 int pipe_pos[2]; 71 char **actual_cmd; 77 72 char *redir_from = NULL; 78 73 char *redir_to = NULL; 79 74 80 if (NULL == usr->line) { 81 free(tokens); 75 if (NULL == usr->line) 82 76 return CL_EFAIL; 83 } 84 85 rc = tok_init(&tok, usr->line, tokens, WORD_MAX); 77 78 rc = tok_init(&tok, usr->line, cmd, WORD_MAX); 86 79 if (rc != EOK) { 87 80 goto finit; 88 81 } 89 82 90 size_t tokens_length; 91 rc = tok_tokenize(&tok, &tokens_length); 83 rc = tok_tokenize(&tok); 92 84 if (rc != EOK) { 93 85 goto finit; 94 }95 96 if (tokens_length > 0 && tokens[0].type == TOKTYPE_SPACE) {97 tokens++;98 tokens_length--;99 }100 101 if (tokens_length > 0 && tokens[tokens_length-1].type == TOKTYPE_SPACE) {102 tokens_length--;103 86 } 104 87 … … 108 91 * First find the pipes and check that there are no more 109 92 */ 110 for (i = 0, pipe_count = 0; i < tokens_length; i++) { 111 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] == '|') { 112 96 if (pipe_count >= 2) { 113 97 print_pipe_usage(); … … 120 104 } 121 105 122 unsigned int cmd_token_start = 0; 123 unsigned int cmd_token_end = tokens_length; 124 106 actual_cmd = cmd; 125 107 processed_pipes = 0; 126 108 127 109 /* Check if the first part (from <file> |) is present */ 128 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) { 129 111 /* Ignore the first three tokens (from, file, pipe) and set from */ 130 redir_from = tokens[2].text;131 cmd_token_start = pipe_pos[0]+1;112 redir_from = cmd[1]; 113 actual_cmd = cmd + 3; 132 114 processed_pipes++; 133 115 } … … 135 117 /* Check if the second part (| to <file>) is present */ 136 118 if ((pipe_count - processed_pipes) > 0 && 137 (pipe_pos[processed_pipes] == tokens_length - 4 || 138 (pipe_pos[processed_pipes] == tokens_length - 5 && 139 tokens[tokens_length-4].type == TOKTYPE_SPACE )) && 140 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) { 141 121 /* Ignore the last three tokens (pipe, to, file) and set to */ 142 redir_to = tokens[tokens_length-1].text; 143 cmd_token_end = pipe_pos[processed_pipes]; 122 redir_to = cmd[cmd_length-1]; 123 cmd[cmd_length-3] = NULL; 124 cmd_length -= 3; 144 125 processed_pipes++; 145 126 } … … 151 132 } 152 133 153 /* Convert tokens of the command to string array */ 154 unsigned int cmd_pos = 0; 155 for (i = cmd_token_start; i < cmd_token_end; i++) { 156 if (tokens[i].type != TOKTYPE_SPACE) { 157 cmd[cmd_pos++] = tokens[i].text; 158 } 159 } 160 cmd[cmd_pos++] = NULL; 161 162 if (cmd[0] == NULL) { 134 if (actual_cmd[0] == NULL) { 163 135 print_pipe_usage(); 164 136 rc = ENOTSUP; … … 212 184 } 213 185 tok_fini(&tok); 214 free(tokens);215 186 216 187 return rc; … … 255 226 int rc; 256 227 257 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); 258 233 259 234 rc = tinput_read(tinput, &str); … … 288 263 } 289 264 290 tinput_set_compl_ops(tinput, &compl_ops);291 292 265 return 0; 293 266 }
Note:
See TracChangeset
for help on using the changeset viewer.