Changeset a02aa5c in mainline for uspace/app/bdsh/cmds/modules/alias/alias.c
- Timestamp:
- 2018-11-30T06:56:05Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 966f753
- Parents:
- 94619b9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/alias/alias.c
r94619b9 ra02aa5c 39 39 #include <adt/odict.h> 40 40 41 42 41 static const char *cmdname = "alias"; 43 static const char* alias_format = "%s='%s'\n"; 44 45 42 static const char *alias_format = "%s='%s'\n"; 46 43 47 44 static void list_aliases() … … 55 52 } 56 53 57 58 static bool print_alias(const char* name) 54 static bool print_alias(const char *name) 59 55 { 60 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)name, NULL);56 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)name, NULL); 61 57 if (alias_link != NULL) { 62 alias_t *data = odict_get_instance(alias_link, alias_t, odict);58 alias_t *data = odict_get_instance(alias_link, alias_t, odict); 63 59 printf(alias_format, data->name, data->value); 64 60 return true; 65 61 } 66 67 68 62 69 63 printf("%s: No alias with the name '%s' exists\n", cmdname, name); … … 71 65 } 72 66 73 74 static void set_alias(const char* name, const char* value) 67 static void set_alias(const char *name, const char *value) 75 68 { 76 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)name, NULL);69 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)name, NULL); 77 70 78 71 if (alias_link != NULL) { 79 72 //update existing value 80 alias_t *data = odict_get_instance(alias_link, alias_t, odict);73 alias_t *data = odict_get_instance(alias_link, alias_t, odict); 81 74 free(data->value); 82 75 data->value = str_dup(value); 83 76 } else { 84 77 //add new value 85 alias_t * data = (alias_t*)calloc(1, sizeof(alias_t));78 alias_t *data = (alias_t *)calloc(1, sizeof(alias_t)); 86 79 data->name = str_dup(name); 87 80 data->value = str_dup(value); … … 90 83 } 91 84 } 92 93 94 95 96 85 97 86 /* Dispays help for alias in various levels */ … … 111 100 } 112 101 113 114 102 size_t i; 115 103 for (i = 1; argv[i] != NULL; i++) { 116 char *name = str_dup(argv[i]);117 char *value;104 char *name = str_dup(argv[i]); 105 char *value; 118 106 if ((value = str_chr(name, '=')) != NULL) { 119 107 name[value - name] = '\0'; 120 108 set_alias(name, value + 1); 121 109 } else { 122 if (!print_alias(name)) {110 if (!print_alias(name)) { 123 111 free(name); 124 112 return CMD_FAILURE; … … 131 119 return CMD_SUCCESS; 132 120 } 133
Note:
See TracChangeset
for help on using the changeset viewer.