use m4_normalize on the output strings to remove trailing spaces/tabs and consolidate...
[AROS.git] / workbench / c / shellcommands / Unalias.c
blob333f2645d5fffd28db27e704eb06d58f86148a26
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Unalias CLI command.
6 */
8 /*****************************************************************************
10 NAME
12 Unalias
14 SYNOPSIS
16 NAME
18 LOCATION
22 FUNCTION
24 Removes a previously defined shell alias.
26 If no parameters are specified, the current list of aliases are
27 displayed.
29 INPUTS
31 NAME - The name of the alias to unset.
33 RESULT
35 Standard DOS error codes.
37 NOTES
39 EXAMPLE
41 Unalias DF
43 BUGS
45 SEE ALSO
47 Alias
49 INTERNALS
51 ******************************************************************************/
54 #include <proto/dos.h>
55 #include <proto/exec.h>
57 #include <dos/dos.h>
58 #include <dos/dosextens.h>
59 #include <dos/rdargs.h>
60 #include <dos/var.h>
61 #include <exec/lists.h>
62 #include <exec/nodes.h>
63 #include <exec/types.h>
64 #include <strings.h>
66 #include <aros/shcommands.h>
68 #define BUFFER_SIZE 160
70 void GetNewString(STRPTR, STRPTR, LONG);
72 AROS_SH1(Unalias, 41.0,
73 AROS_SHA(STRPTR, ,NAME, ,NULL))
75 AROS_SHCOMMAND_INIT
77 struct Process * UnaliasProc;
78 struct LocalVar * UnaliasNode;
79 BOOL Success;
80 LONG VarLength;
81 char Buffer1[BUFFER_SIZE];
82 char Buffer2[BUFFER_SIZE];
85 if (SHArg(NAME) != NULL)
87 Success = DeleteVar(SHArg(NAME), GVF_LOCAL_ONLY | LV_ALIAS);
89 if (Success == FALSE)
91 PrintFault(IoErr(), "Unalias");
93 return RETURN_WARN;
96 else
98 /* Display a list of aliases.
100 UnaliasProc = (struct Process *)FindTask(NULL);
102 if (UnaliasProc != NULL)
104 ForeachNode(&(UnaliasProc->pr_LocalVars), UnaliasNode)
106 if (UnaliasNode->lv_Node.ln_Type == LV_ALIAS)
108 /* Get a clean variable with no excess
109 * characters.
111 VarLength = -1;
112 VarLength = GetVar(UnaliasNode->lv_Node.ln_Name,
113 &Buffer1[0],
114 BUFFER_SIZE,
115 GVF_LOCAL_ONLY | LV_ALIAS);
117 if (VarLength != -1)
119 GetNewString(&Buffer1[0],
120 &Buffer2[0],
121 VarLength);
123 Buffer2[VarLength] = 0;
125 Printf("%-20s\t%-20s\n", UnaliasNode->lv_Node.ln_Name, Buffer2);
132 return RETURN_OK;
134 AROS_SHCOMMAND_EXIT
136 } /* main */
138 void GetNewString(STRPTR s, STRPTR d, LONG l)
140 int i;
141 int j;
143 i = j = 0;
145 while (i < l)
147 if (s[i] == '*' || s[i] == '\e')
149 d[j] = '*';
151 i++;
152 j++;
154 else
156 d[j] = s[i];
158 i++;
159 j++;
162 } /* GetNewString */