Changeset 966f753 in mainline
- Timestamp:
- 2018-11-30T20:33:12Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a8c09f91
- Parents:
- a02aa5c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
ra02aa5c r966f753 45 45 #include <tinput.h> 46 46 #include <adt/odict.h> 47 #include <adt/list.h> 47 48 48 49 #include "config.h" … … 64 65 static void print_pipe_usage(void); 65 66 67 typedef struct { 68 link_t alias_hup_link; 69 alias_t *alias; 70 } alias_hup_t; 71 72 static bool find_alias_hup(alias_t *alias, list_t *alias_hups) 73 { 74 list_foreach(*alias_hups, alias_hup_link, alias_hup_t, link) { 75 if (alias == link->alias) { 76 return true; 77 } 78 } 79 80 return false; 81 } 82 66 83 /* 67 84 * Tokenizes input from console, sees if the first word is a built-in, if so … … 69 86 * the handler 70 87 */ 71 errno_t process_input(cliuser_t *usr)88 static errno_t process_input_nohup(cliuser_t *usr, list_t *alias_hups) 72 89 { 73 90 token_t *tokens_buf = calloc(WORD_MAX, sizeof(token_t)); … … 177 194 if (alias_link != NULL) { 178 195 alias_t *data = odict_get_instance(alias_link, alias_t, odict); 179 char *oldLine = usr->line; 180 181 const size_t input_length = str_size(usr->line) - str_size(cmd[0]) + str_size(data->value) + 1; 182 usr->line = (char *)malloc(input_length * sizeof(char)); 183 usr->line[0] = '\0'; 184 185 unsigned int cmd_replace_index = cmd_token_start; 186 for (i = 0; i < tokens_length; i++) { 187 if (i == cmd_replace_index) { 188 //if there is a pipe symbol than cmd_token_start will point at the SPACE after the pipe symbol 189 if (tokens[i].type == TOKTYPE_SPACE) { 190 cmd_replace_index++; 196 //check if the alias already has been resolved once 197 if (!find_alias_hup(data, alias_hups)) { 198 alias_hup_t *hup = (alias_hup_t *)calloc(1, sizeof(hup)); 199 hup->alias = data; 200 list_append(&hup->alias_hup_link, alias_hups); 201 202 char *oldLine = usr->line; 203 const size_t input_length = str_size(usr->line) - str_size(cmd[0]) + str_size(data->value) + 1; 204 usr->line = (char *)malloc(input_length * sizeof(char)); 205 usr->line[0] = '\0'; 206 207 unsigned int cmd_replace_index = cmd_token_start; 208 for (i = 0; i < tokens_length; i++) { 209 if (i == cmd_replace_index) { 210 //if there is a pipe symbol than cmd_token_start will point at the SPACE after the pipe symbol 211 if (tokens[i].type == TOKTYPE_SPACE) { 212 cmd_replace_index++; 213 str_append(usr->line, input_length, tokens[i].text); 214 continue; 215 } 216 217 str_append(usr->line, input_length, data->value); 218 } else { 191 219 str_append(usr->line, input_length, tokens[i].text); 192 continue;193 220 } 194 195 str_append(usr->line, input_length, data->value);196 } else {197 str_append(usr->line, input_length, tokens[i].text);198 221 } 199 } 200 201 //reprocess input after string replace202 rc = process_input(usr);203 usr->line = oldLine;204 goto finit;222 223 //reprocess input after string replace 224 rc = process_input_nohup(usr, alias_hups); 225 usr->line = oldLine; 226 goto finit; 227 } 205 228 } 206 229 … … 259 282 } 260 283 284 errno_t process_input(cliuser_t *usr) 285 { 286 list_t alias_hups; 287 list_initialize(&alias_hups); 288 289 errno_t rc = process_input_nohup(usr, &alias_hups); 290 291 list_foreach_safe(alias_hups, cur_link, next_link) { 292 alias_hup_t *cur_item = list_get_instance(cur_link, alias_hup_t, alias_hup_link); 293 free(cur_item); 294 } 295 296 return rc; 297 } 298 261 299 void print_pipe_usage(void) 262 300 {
Note:
See TracChangeset
for help on using the changeset viewer.