revert between 56095 -> 55830 in arch
[AROS.git] / workbench / c / shellcommands / Set.c
blob64750a8fa8f59118db9244c0c23f85aee0cab8ea
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
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 LONG VarLength;
87 char Buffer1[BUFFER_SIZE];
88 char Buffer2[BUFFER_SIZE];
91 if (SHArg(NAME) != NULL || SHArg(STRING) != NULL)
93 /* Make sure we get to here is either arguments are
94 * provided on the command line.
96 if (SHArg(NAME) != NULL && SHArg(STRING) != NULL)
98 /* Add the new local variable to the list.
102 !SetVar(SHArg(NAME),
103 SHArg(STRING),
105 GVF_LOCAL_ONLY)
108 return RETURN_ERROR;
112 else
114 SetProc = (struct Process *)FindTask(NULL);
116 ForeachNode(&(SetProc->pr_LocalVars), SetNode)
118 if (SetNode->lv_Node.ln_Type == LV_VAR)
120 /* Get a clean variable with no excess
121 * characters.
123 VarLength = -1;
124 VarLength = GetVar(SetNode->lv_Node.ln_Name,
125 &Buffer1[0],
126 BUFFER_SIZE,
127 GVF_LOCAL_ONLY
129 if (VarLength != -1)
131 GetNewString(&Buffer1[0],
132 &Buffer2[0],
133 VarLength
136 Buffer2[VarLength] = 0;
138 Printf("%-20s\t%-20s\n", SetNode->lv_Node.ln_Name, Buffer2);
144 return RETURN_OK;
146 AROS_SHCOMMAND_EXIT
147 } /* main */
149 static void GetNewString(STRPTR s, STRPTR d, LONG l)
151 int i;
152 int j;
154 i = j = 0;
156 while (i < l)
158 if (s[i] == '*' || s[i] == '\e')
160 d[j] = '*';
162 i++;
163 j++;
165 else
167 d[j] = s[i];
169 i++;
170 j++;
173 } /* GetNewString */