Changeset a02aa5c in mainline
- Timestamp:
- 2018-11-30T06:56:05Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 966f753
- Parents:
- 94619b9
- Location:
- uspace/app/bdsh
- Files:
-
- 9 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 -
uspace/app/bdsh/cmds/modules/alias/alias.h
r94619b9 ra02aa5c 4 4 /* Prototypes for the alias command, excluding entry points */ 5 5 6 7 6 #endif /* ALIAS_H */ 8 -
uspace/app/bdsh/cmds/modules/alias/entry.h
r94619b9 ra02aa5c 7 7 8 8 #endif /* ALIAS_ENTRY_H */ 9 -
uspace/app/bdsh/cmds/modules/unalias/entry.h
r94619b9 ra02aa5c 7 7 8 8 #endif /* UNALIAS_ENTRY_H */ 9 -
uspace/app/bdsh/cmds/modules/unalias/unalias.c
r94619b9 ra02aa5c 39 39 #include "cmds.h" 40 40 41 42 43 41 static const char *cmdname = "unalias"; 44 45 46 42 47 43 static void free_alias(odlink_t *alias_link) … … 55 51 } 56 52 57 58 53 /* Dispays help for unalias in various levels */ 59 54 void help_cmd_unalias(unsigned int level) … … 63 58 } 64 59 65 66 60 /* Main entry point for unalias, accepts an array of arguments */ 67 61 int cmd_unalias(char **argv) 68 62 { 69 63 70 if (argv[1] == NULL) {64 if (argv[1] == NULL) { 71 65 help_cmd_unalias(HELP_LONG); 72 66 return CMD_SUCCESS; … … 88 82 } 89 83 90 91 alias_link = odict_find_eq(&alias_dict, (void*)argv[i], NULL); 84 alias_link = odict_find_eq(&alias_dict, (void *)argv[i], NULL); 92 85 93 86 if (alias_link == NULL) { … … 98 91 free_alias(alias_link); 99 92 } 100 101 102 93 103 94 return CMD_SUCCESS; 104 95 } 105 -
uspace/app/bdsh/cmds/modules/unalias/unalias.h
r94619b9 ra02aa5c 4 4 /* Prototypes for the unalias command, excluding entry points */ 5 5 6 7 6 #endif /* UNALIAS_H */ 8 -
uspace/app/bdsh/input.c
r94619b9 ra02aa5c 173 173 } 174 174 175 176 177 175 /* test if the passed cmd is an alias */ 178 odlink_t * alias_link = odict_find_eq(&alias_dict, (void*)cmd[0], NULL);176 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cmd[0], NULL); 179 177 if (alias_link != NULL) { 180 alias_t* data = odict_get_instance(alias_link, alias_t, odict); 181 char* oldLine = usr->line; 182 178 alias_t *data = odict_get_instance(alias_link, alias_t, odict); 179 char *oldLine = usr->line; 183 180 184 181 const size_t input_length = str_size(usr->line) - str_size(cmd[0]) + str_size(data->value) + 1; 185 usr->line = (char *)malloc(input_length * sizeof(char));182 usr->line = (char *)malloc(input_length * sizeof(char)); 186 183 usr->line[0] = '\0'; 187 184 … … 208 205 } 209 206 210 211 207 iostate_t new_iostate = { 212 208 .stdin = stdin, -
uspace/app/bdsh/scli.c
r94619b9 ra02aa5c 45 45 static iostate_t stdiostate; 46 46 47 48 47 odict_t alias_dict; 49 48 … … 61 60 const char *progname = PACKAGE_NAME; 62 61 63 static int alias_cmp(void * a, void*b)62 static int alias_cmp(void *a, void *b) 64 63 { 65 return str_cmp((char *)a, (char*)b);64 return str_cmp((char *)a, (char *)b); 66 65 } 67 66 68 static void *alias_key(odlink_t *odlink)67 static void *alias_key(odlink_t *odlink) 69 68 { 70 return (void *)odict_get_instance(odlink, alias_t, odict)->name;69 return (void *)odict_get_instance(odlink, alias_t, odict)->name; 71 70 } 72 71 … … 123 122 iostate = &stdiostate; 124 123 125 126 124 odict_initialize(&alias_dict, alias_key, alias_cmp); 127 125 -
uspace/app/bdsh/scli.h
r94619b9 ra02aa5c 56 56 extern void set_iostate(iostate_t *); 57 57 58 59 58 extern odict_t alias_dict; 60 61 59 62 60 typedef struct { 63 61 odlink_t odict; 64 char *name;65 char *value;62 char *name; 63 char *value; 66 64 } alias_t; 67 65 68 69 66 #endif
Note:
See TracChangeset
for help on using the changeset viewer.