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