- Fixed a regression in decoding 8-bit images (introduced in my r46589).
[AROS.git] / workbench / c / shellcommands / Unset.c
blobfd1812afe0612e7e99129f1b24b4ad080d260791
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Unset CLI command.
6 */
8 /*****************************************************************************
10 NAME
12 Unset
14 SYNOPSIS
16 NAME
18 LOCATION
22 FUNCTION
24 Deletes local variable.
26 INPUTS
28 NAME - The name of the local variable to unset.
30 RESULT
32 Standard DOS error codes.
34 NOTES
36 EXAMPLE
38 BUGS
40 SEE ALSO
42 INTERNALS
44 ******************************************************************************/
47 #include <proto/dos.h>
48 #include <proto/exec.h>
50 #include <dos/dos.h>
51 #include <dos/dosextens.h>
52 #include <dos/rdargs.h>
53 #include <dos/var.h>
54 #include <exec/lists.h>
55 #include <exec/nodes.h>
56 #include <exec/types.h>
57 #include <aros/shcommands.h>
59 #define BUFFER_SIZE 160
61 static void GetNewString(STRPTR, STRPTR, LONG);
63 AROS_SH1(Unset, 41.0,
64 AROS_SHA(STRPTR, ,NAME, ,NULL))
66 AROS_SHCOMMAND_INIT
68 struct Process * UnsetProc;
69 struct LocalVar * UnsetNode;
70 IPTR OutArgs[3];
71 LONG VarLength;
72 char Buffer1[BUFFER_SIZE];
73 char Buffer2[BUFFER_SIZE];
76 if (SHArg(NAME) != NULL)
78 /* Delete the local Var from the list.
81 if (!DeleteVar(SHArg(NAME), GVF_LOCAL_ONLY))
83 return RETURN_FAIL;
87 else
89 /* Display a list of local variables.
91 UnsetProc = (struct Process *)FindTask(NULL);
93 ForeachNode(&(UnsetProc->pr_LocalVars), UnsetNode)
95 if (UnsetNode->lv_Node.ln_Type == LV_VAR)
97 /* Get a clean variable with no excess
98 * characters.
100 VarLength = -1;
101 VarLength = GetVar(UnsetNode->lv_Node.ln_Name,
102 &Buffer1[0],
103 BUFFER_SIZE,
104 GVF_LOCAL_ONLY);
106 if (VarLength != -1)
108 GetNewString(&Buffer1[0], &Buffer2[0], VarLength);
110 Buffer2[VarLength] = 0;
112 OutArgs[0] = (IPTR)UnsetNode->lv_Node.ln_Name;
113 OutArgs[1] = (IPTR)&Buffer2[0];
114 OutArgs[2] = (IPTR)NULL;
115 VPrintf("%-20s\t%-20s\n", &OutArgs[0]);
121 return RETURN_OK;
123 AROS_SHCOMMAND_EXIT
124 } /* main */
127 static void GetNewString(STRPTR s, STRPTR d, LONG l)
129 int i;
130 int j;
132 i = j = 0;
134 while (i < l)
136 if (s[i] == '*' || s[i] == '\e')
138 d[j] = '*';
140 i++;
141 j++;
143 else
145 d[j] = s[i];
147 i++;
148 j++;
151 } /* GetNewString */