Changeset 4bf08aa5 in mainline
- Timestamp:
- 2018-11-30T03:22:03Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 55e35a22
- Parents:
- 60c332e
- Location:
- uspace/app/bdsh
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/alias/alias.c
r60c332e r4bf08aa5 21 21 22 22 static const char *cmdname = "alias"; 23 static const char* alias_format = "%s /%s";23 static const char* alias_format = "%s='%s'\n"; 24 24 25 26 /*27 #include <types/adt/odict.h>28 extern void odict_initialize(odict_t *, odgetkey_t, odcmp_t);29 extern void odict_finalize(odict_t *);30 extern void odlink_initialize(odlink_t *);31 extern void odict_insert(odlink_t *, odict_t *, odlink_t *);32 extern void odict_remove(odlink_t *);33 34 extern odlink_t *odict_first(odict_t *);35 extern odlink_t *odict_next(odlink_t *, odict_t *);36 extern odlink_t *odict_find_eq(odict_t *, void *, odlink_t *);37 extern errno_t odict_validate(odict_t *);38 */39 25 40 26 … … 51 37 } 52 38 39 53 40 static int print_alias(const char* name) 54 41 { … … 62 49 63 50 64 printf(" No alias with the name '%s' exists", name);51 printf("%s: No alias with the name '%s' exists\n", cmdname, name); 65 52 return CMD_FAILURE; 66 53 } 67 54 55 68 56 static void set_alias(const char* name, const char* value) 69 57 { 70 58 odlink_t *alias_link = odict_find_eq(&alias_dict, (void*)name, NULL); 59 60 if (alias_link != NULL) { 61 //update existing value 62 alias_t* data = odict_get_instance(alias_link, alias_t, odict); 63 free(data->value); 64 data->value = str_dup(value); 65 66 printf("%s: update value ", cmdname); 67 }else { 68 //add new value 69 alias_t* data = (alias_t*)calloc(1, sizeof(alias_t)); 70 data->name = str_dup(name); 71 data->value = str_dup(value); 72 73 odict_insert(&data->odict, &alias_dict, NULL); 74 75 76 printf("%s: insert value ", cmdname); 77 } 78 79 printf(alias_format, name, value); 71 80 } 72 81 … … 78 87 void help_cmd_alias(unsigned int level) 79 88 { 80 printf("This is the %s help for '%s'.\n", 81 level ? EXT_HELP : SHORT_HELP, cmdname); 89 printf("Set a new alias with \"alias hex='cat --hex'\". Display an alias with \"alias hex\". List all alias by passing no argument.\n"); 82 90 return; 83 91 } … … 87 95 { 88 96 89 if (argv[ 0] == NULL) {97 if (argv[1] == NULL) { 90 98 list_aliases(); 91 99 return CMD_SUCCESS; 92 }else if (argv[ 1] == NULL && strpos(argv[0], "=") == -1) {93 return print_alias(argv[ 0]);100 }else if (argv[2] == NULL && str_chr(argv[1], '=') == NULL) { 101 return print_alias(argv[1]); 94 102 } 95 96 103 104 //concat all it together 97 105 char* str = (char*)malloc(INPUT_MAX * sizeof(char)); 98 106 str[0] = '\0'; 99 107 100 108 size_t i; 101 for (i = 0; argv[i] != NULL; i++) {102 str = strcat(str, argv[i]);109 for (i = 1; argv[i] != NULL; i++) { 110 str_append(str, INPUT_MAX - 1, argv[i]); 103 111 } 104 112 105 106 107 set_alias(name, value); 113 //split input 114 char* pos = str_chr(str, '='); 115 if(pos == NULL) { 116 printf("%s: bad formatted input\n", cmdname); 117 return CMD_FAILURE; 118 } 119 120 121 str[pos - str] = '\0'; 122 set_alias(str, pos + 1); 123 124 free(str); 108 125 return CMD_SUCCESS; 109 126 } -
uspace/app/bdsh/input.c
r60c332e r4bf08aa5 171 171 } 172 172 173 174 175 /* test if the passed cmd is an alias 176 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)&v, NULL); 177 e = odict_get_instance(alias_link, test_entry_t, alias_dict); 178 if() { 179 char* oldLine = usr->line; 180 181 182 //reprocess input after string replace 183 rc = process_input(usr); 184 usr->line = oldLine; 185 goto finit; 186 } 187 188 */ 189 190 173 191 iostate_t new_iostate = { 174 192 .stdin = stdin, … … 219 237 usr->line = (char *) NULL; 220 238 } 239 221 240 tok_fini(&tok); 222 241 free(tokens_buf); -
uspace/app/bdsh/scli.c
r60c332e r4bf08aa5 61 61 const char *progname = PACKAGE_NAME; 62 62 63 static int alias_cmp(void* a, void* b) { 63 static int alias_cmp(void* a, void* b) 64 { 64 65 return str_cmp((char*)a, (char*)b); 65 66 } 66 67 68 static void* alias_key(odlink_t *odlink) 69 { 70 return (void*)odict_get_instance(odlink, alias_t, odict)->name; 71 } 67 72 68 73 /* These are not exposed, even to builtins */ -
uspace/app/bdsh/scli.h
r60c332e r4bf08aa5 60 60 extern odict_t alias_dict; 61 61 62 extern void* alias_key(odlink_t *odlink);63 62 64 63 typedef struct {
Note:
See TracChangeset
for help on using the changeset viewer.