2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
8 /*****************************************************************************
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
30 If no parameters are specified, the current list of local variables
35 NAME - The name of the local variable to set.
37 STRING - The value of the local variable NAME.
41 Standard DOS error codes.
49 Sets a local variable called "Jump" to the value of "5".
59 ******************************************************************************/
62 #include <proto/dos.h>
63 #include <proto/exec.h>
66 #include <dos/dosextens.h>
67 #include <dos/rdargs.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
);
79 AROS_SHA(STRPTR
, ,NAME
, , NULL
),
80 AROS_SHA(STRPTR
, ,STRING
, /F
, NULL
))
84 struct Process
* SetProc
;
85 struct LocalVar
* SetNode
;
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.
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
125 VarLength
= GetVar(SetNode
->lv_Node
.ln_Name
,
132 GetNewString(&Buffer1
[0],
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]);
153 static void GetNewString(STRPTR s
, STRPTR d
, LONG l
)
162 if (s
[i
] == '*' || s
[i
] == '\e')