Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / c / shellcommands / Set.c
blobd53f7cd7f43665000ad5fb306a7964c9a17ddc5a
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Set CLI command.
6 */
8 /*****************************************************************************
10 NAME
12 Set
14 SYNOPSIS
16 NAME,STRING/F
18 LOCATION
20 Workbench:c
22 FUNCTION
24 Set a local environment variable in the current shell. If any global
25 variables have the same name the local variable will be used instead.
27 This instance the variable is only accessible from within the shell
28 it was defined.
30 If no parameters are specified, the current list of local variables
31 are displayed.
33 INPUTS
35 NAME - The name of the local variable to set.
37 STRING - The value of the local variable NAME.
39 RESULT
41 Standard DOS error codes.
43 NOTES
45 EXAMPLE
47 Set Jump 5
49 Sets a local variable called "Jump" to the value of "5".
51 BUGS
53 SEE ALSO
55 Get, Unset
57 INTERNALS
59 ******************************************************************************/
62 #include <proto/dos.h>
63 #include <proto/exec.h>
65 #include <dos/dos.h>
66 #include <dos/dosextens.h>
67 #include <dos/rdargs.h>
68 #include <dos/var.h>
69 #include <exec/lists.h>
70 #include <exec/nodes.h>
71 #include <exec/types.h>
72 #include <aros/shcommands.h>
74 #define BUFFER_SIZE 160
76 static void GetNewString(STRPTR, STRPTR, LONG);
78 AROS_SH2(Set, 41.0,
79 AROS_SHA(STRPTR, ,NAME, , NULL),
80 AROS_SHA(STRPTR, ,STRING, /F, NULL))
82 AROS_SHCOMMAND_INIT
84 struct Process * SetProc;
85 struct LocalVar * SetNode;
86 IPTR OutArgs[3];
87 LONG VarLength;
88 char Buffer1[BUFFER_SIZE];
89 char Buffer2[BUFFER_SIZE];
92 if (SHArg(NAME) != NULL || SHArg(STRING) != NULL)
94 /* Make sure we get to here is either arguments are
95 * provided on the command line.
97 if (SHArg(NAME) != NULL && SHArg(STRING) != NULL)
99 /* Add the new local variable to the list.
103 !SetVar(SHArg(NAME),
104 SHArg(STRING),
106 GVF_LOCAL_ONLY)
109 return RETURN_ERROR;
113 else
115 SetProc = (struct Process *)FindTask(NULL);
117 ForeachNode(&(SetProc->pr_LocalVars), SetNode)
119 if (SetNode->lv_Node.ln_Type == LV_VAR)
121 /* Get a clean variable with no excess
122 * characters.
124 VarLength = -1;
125 VarLength = GetVar(SetNode->lv_Node.ln_Name,
126 &Buffer1[0],
127 BUFFER_SIZE,
128 GVF_LOCAL_ONLY
130 if (VarLength != -1)
132 GetNewString(&Buffer1[0],
133 &Buffer2[0],
134 VarLength
137 Buffer2[VarLength] = NULL;
139 OutArgs[0] = (IPTR)SetNode->lv_Node.ln_Name;
140 OutArgs[1] = (IPTR)&Buffer2[0];
141 OutArgs[2] = (IPTR)NULL;
142 VPrintf("%-20s\t%-20s\n", &OutArgs[0]);
148 return RETURN_OK;
150 AROS_SHCOMMAND_EXIT
151 } /* main */
153 static void GetNewString(STRPTR s, STRPTR d, LONG l)
155 int i;
156 int j;
158 i = j = 0;
160 while (i < l)
162 if (s[i] == '*' || s[i] == '\e')
164 d[j] = '*';
166 i++;
167 j++;
169 else
171 d[j] = s[i];
173 i++;
174 j++;
177 } /* GetNewString */