source: mainline/uspace/app/bdsh/cmds/modules/unalias/unalias.c@ 02c6dcc

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 02c6dcc was 02c6dcc, checked in by Matthieu Riolo <matthieu.riolo@…>, 7 years ago

correcting help message; implementing -a argument

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* Automatically generated by mknewcmd on Fre Nov 30 05:45:31 CET 2018
2 * This is machine generated output. The author of mknewcmd claims no
3 * copyright over the contents of this file. Where legally permitted, the
4 * contents herein are donated to the public domain.
5 *
6 * You should apply any license and copyright that you wish to this file,
7 * replacing this header in its entirety. */
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <str.h>
12#include <adt/odict.h>
13
14#include "config.h"
15#include "util.h"
16#include "errors.h"
17#include "entry.h"
18#include "unalias.h"
19#include "cmds.h"
20
21
22
23static const char *cmdname = "unalias";
24
25
26
27static 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
38/* Dispays help for unalias in various levels */
39void help_cmd_unalias(unsigned int level)
40{
41 printf("`%s' removes an alias or all aliases with -a\n", cmdname);
42 return;
43}
44
45
46/* Main entry point for unalias, accepts an array of arguments */
47int cmd_unalias(char **argv)
48{
49
50 if(argv[1] == NULL) {
51 help_cmd_unalias(HELP_LONG);
52 return CMD_SUCCESS;
53 }
54
55 size_t i;
56 odlink_t *alias_link;
57
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 }
66
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) {
74 printf("%s: No alias '%s' found\n", cmdname, argv[i]);
75 return CMD_FAILURE;
76 }
77
78 free_alias(alias_link);
79 }
80
81
82
83 return CMD_SUCCESS;
84}
85
Note: See TracBrowser for help on using the repository browser.