- Fixed a regression in decoding 8-bit images (introduced in my r46589).
[AROS.git] / workbench / c / shellcommands / Unalias.c
blob02cea83f63e092696ac6ddd995e48e07ce0b1a1a
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 IPTR OutArgs[4];
80 BOOL Success;
81 LONG VarLength;
82 char Buffer1[BUFFER_SIZE];
83 char Buffer2[BUFFER_SIZE];
86 if (SHArg(NAME) != NULL)
88 Success = DeleteVar(SHArg(NAME), GVF_LOCAL_ONLY | LV_ALIAS);
90 if (Success == FALSE)
92 PrintFault(IoErr(), "Unalias");
94 return RETURN_WARN;
97 else
99 /* Display a list of aliases.
101 UnaliasProc = (struct Process *)FindTask(NULL);
103 if (UnaliasProc != NULL)
105 ForeachNode(&(UnaliasProc->pr_LocalVars), UnaliasNode)
107 if (UnaliasNode->lv_Node.ln_Type == LV_ALIAS)
109 /* Get a clean variable with no excess
110 * characters.
112 VarLength = -1;
113 VarLength = GetVar(UnaliasNode->lv_Node.ln_Name,
114 &Buffer1[0],
115 BUFFER_SIZE,
116 GVF_LOCAL_ONLY | LV_ALIAS);
118 if (VarLength != -1)
120 GetNewString(&Buffer1[0],
121 &Buffer2[0],
122 VarLength);
124 Buffer2[VarLength] = 0;
126 OutArgs[0] = (IPTR)UnaliasNode->lv_Node.ln_Name;
127 OutArgs[1] = (IPTR)&Buffer2[0];
128 OutArgs[2] = (IPTR)NULL;
129 VPrintf("%-20s\t%-20s\n", &OutArgs[0]);
136 return RETURN_OK;
138 AROS_SHCOMMAND_EXIT
140 } /* main */
142 void GetNewString(STRPTR s, STRPTR d, LONG l)
144 int i;
145 int j;
147 i = j = 0;
149 while (i < l)
151 if (s[i] == '*' || s[i] == '\e')
153 d[j] = '*';
155 i++;
156 j++;
158 else
160 d[j] = s[i];
162 i++;
163 j++;
166 } /* GetNewString */