Changes in uspace/app/bdsh/input.c [e62f8e3:09ab0a9a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
re62f8e3 r09ab0a9a 3 3 * Copyright (c) 2011 Jiri Svoboda 4 4 * Copyright (c) 2011 Martin Sucha 5 * Copyright (c) 2018 Matthieu Riolo6 5 * All rights reserved. 7 6 * … … 44 43 #include <stdbool.h> 45 44 #include <tinput.h> 46 #include <adt/odict.h>47 #include <adt/list.h>48 45 49 46 #include "config.h" … … 65 62 static void print_pipe_usage(void); 66 63 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 83 64 /* 84 65 * Tokenizes input from console, sees if the first word is a built-in, if so … … 86 67 * the handler 87 68 */ 88 static errno_t process_input_nohup(cliuser_t *usr, list_t *alias_hups, size_t count_executed_hups) 89 { 90 if (count_executed_hups >= HUBS_MAX) { 91 cli_error(CL_EFAIL, "%s: maximal alias hubs reached\n", PACKAGE_NAME); 92 return ELIMIT; 93 } 94 69 errno_t process_input(cliuser_t *usr) 70 { 95 71 token_t *tokens_buf = calloc(WORD_MAX, sizeof(token_t)); 96 72 if (tokens_buf == NULL) … … 195 171 } 196 172 197 /* test if the passed cmd is an alias */198 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cmd[0], NULL);199 if (alias_link != NULL) {200 alias_t *data = odict_get_instance(alias_link, alias_t, odict);201 /* check if the alias already has been resolved once */202 if (!find_alias_hup(data, alias_hups)) {203 alias_hup_t *hup = (alias_hup_t *)calloc(1, sizeof(alias_hup_t));204 if (hup == NULL) {205 cli_error(CL_EFAIL, "%s: cannot allocate alias structure\n", PACKAGE_NAME);206 rc = ENOMEM;207 goto finit;208 }209 210 hup->alias = data;211 list_append(&hup->alias_hup_link, alias_hups);212 213 char *oldLine = usr->line;214 const size_t input_length = str_size(usr->line) - str_size(cmd[0]) + str_size(data->value) + 1;215 usr->line = (char *)malloc(input_length);216 if (usr->line == NULL) {217 cli_error(CL_EFAIL, "%s: cannot allocate input structure\n", PACKAGE_NAME);218 rc = ENOMEM;219 goto finit;220 }221 222 usr->line[0] = '\0';223 224 unsigned int cmd_replace_index = cmd_token_start;225 for (i = 0; i < tokens_length; i++) {226 if (i == cmd_replace_index) {227 /* if there is a pipe symbol than cmd_token_start will point at the SPACE after the pipe symbol */228 if (tokens[i].type == TOKTYPE_SPACE) {229 cmd_replace_index++;230 str_append(usr->line, input_length, tokens[i].text);231 continue;232 }233 234 str_append(usr->line, input_length, data->value);235 } else {236 str_append(usr->line, input_length, tokens[i].text);237 }238 }239 240 /* reprocess input after string replace */241 rc = process_input_nohup(usr, alias_hups, count_executed_hups + 1);242 usr->line = oldLine;243 goto finit;244 }245 }246 247 173 iostate_t new_iostate = { 248 174 .stdin = stdin, … … 299 225 } 300 226 301 errno_t process_input(cliuser_t *usr)302 {303 list_t alias_hups;304 list_initialize(&alias_hups);305 306 errno_t rc = process_input_nohup(usr, &alias_hups, 0);307 308 list_foreach_safe(alias_hups, cur_link, next_link) {309 alias_hup_t *cur_item = list_get_instance(cur_link, alias_hup_t, alias_hup_link);310 free(cur_item);311 }312 313 return rc;314 }315 316 227 void print_pipe_usage(void) 317 228 {
Note:
See TracChangeset
for help on using the changeset viewer.