Changeset 02c6dcc in mainline for uspace/app/bdsh/cmds/modules/unalias/unalias.c
- Timestamp:
- 2018-11-30T05:49:20Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d1744fd
- Parents:
- 08bd04c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/unalias/unalias.c
r08bd04c r02c6dcc 9 9 #include <stdio.h> 10 10 #include <stdlib.h> 11 #include <str.h> 11 12 #include <adt/odict.h> 12 13 … … 22 23 static const char *cmdname = "unalias"; 23 24 25 26 27 static void free_alias(odlink_t *alias_link) 28 { 29 alias_t *data = odict_get_instance(alias_link, alias_t, odict); 30 odict_remove(alias_link); 31 32 free(data->name); 33 free(data->value); 34 free(data); 35 } 36 37 24 38 /* Dispays help for unalias in various levels */ 25 39 void help_cmd_unalias(unsigned int level) 26 40 { 27 printf("This is the %s help for '%s'.\n", 28 level ? EXT_HELP : SHORT_HELP, cmdname); 41 printf("`%s' removes an alias or all aliases with -a\n", cmdname); 29 42 return; 30 43 } 44 31 45 32 46 /* Main entry point for unalias, accepts an array of arguments */ … … 34 48 { 35 49 50 if(argv[1] == NULL) { 51 help_cmd_unalias(HELP_LONG); 52 return CMD_SUCCESS; 53 } 54 36 55 size_t i; 56 odlink_t *alias_link; 37 57 38 for(i = 1; argv[i] != NULL; i++) { 39 odlink_t *alias_link = odict_find_eq(&alias_dict, (void*)argv[i], NULL); 58 for (i = 1; argv[i] != NULL; i++) { 59 if (str_cmp(argv[i], "-a") == 0) { 60 alias_link = odict_first(&alias_dict); 61 while (alias_link != NULL) { 62 odlink_t *old_alias_link = alias_link; 63 alias_link = odict_next(old_alias_link, &alias_dict); 64 free_alias(old_alias_link); 65 } 40 66 41 if(alias_link == NULL) { 67 return CMD_SUCCESS; 68 } 69 70 71 alias_link = odict_find_eq(&alias_dict, (void*)argv[i], NULL); 72 73 if (alias_link == NULL) { 42 74 printf("%s: No alias '%s' found\n", cmdname, argv[i]); 43 75 return CMD_FAILURE; 44 76 } 45 77 46 alias_t *data = odict_get_instance(alias_link, alias_t, odict); 47 odict_remove(alias_link); 48 49 free(data->name); 50 free(data->value); 51 free(data); 78 free_alias(alias_link); 52 79 } 53 80
Note:
See TracChangeset
for help on using the changeset viewer.