2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Setenv CLI command
9 /*****************************************************************************
25 Sets a global variable from the current shell. These variables can
26 be accessed from any program executing at any time.
28 These variables are usually not saved in the ENVARC: directory, hence they
29 can only be used by programs during the current execution of the
30 operating system. When using SAVE argument, the variable is also saved
33 If no parameters are specified, the current list of global variables
38 NAME - The name of the global variable to set.
40 SAVE - Save the variable also in ENVARC:
42 STRING - The value of the global variable NAME.
46 Standard DOS error codes.
54 Any program that accesses the variable "EDITOR" will be able to
55 find out the name of the text-editor the user would like to use,
56 by examining the contents of the variable.
68 30-Jul-1997 laguest Initial inclusion into the AROS tree
69 13-Aug-1997 srittau Minor changes
71 ******************************************************************************/
73 #include <proto/dos.h>
74 #include <proto/exec.h>
77 #include <dos/exall.h>
78 #include <dos/rdargs.h>
80 #include <exec/memory.h>
81 #include <exec/types.h>
83 #include <utility/tagitem.h>
86 #define SH_GLOBAL_DOSBASE 1 /* because of Printf from amiga.lib */
88 #include <aros/shcommands.h>
90 AROS_SH3(Setenv
, 45.0,
91 AROS_SHA(STRPTR
, ,NAME
, , NULL
),
92 AROS_SHA(IPTR
, ,SAVE
, /S
, NULL
),
93 AROS_SHA(STRPTR
, ,STRING
, /F
, NULL
))
103 GetProgramName(progname
, sizeof(progname
));
104 Return_Value
= RETURN_OK
;
106 if (SHArg(NAME
) != NULL
|| SHArg(STRING
) != NULL
)
108 /* Make sure we get to here is either arguments are
109 * provided on the command line.
111 if (SHArg(NAME
) != NULL
&& SHArg(STRING
) != NULL
)
113 /* Add the new global variable to the list.
115 Success
= SetVar(SHArg(NAME
),
118 SHArg(SAVE
) ? GVF_GLOBAL_ONLY
| GVF_SAVE_VAR
: GVF_GLOBAL_ONLY
);
120 if (Success
== FALSE
)
122 UBYTE buf
[FAULT_MAX
+128];
124 Fault(-141, NULL
, buf
, sizeof(buf
));
125 Printf(buf
, SHArg(NAME
));
126 PrintFault(IoErr(), progname
);
128 Return_Value
= RETURN_ERROR
;
134 /* Display a list of global variables.
137 lock
= Lock("ENV:", ACCESS_READ
);
140 struct FileInfoBlock
*FIB
= AllocDosObject(DOS_FIB
, NULL
);
144 if(Examine(lock
, FIB
))
146 while(ExNext(lock
, FIB
))
148 /* don't show dirs */
149 if (FIB
->fib_DirEntryType
< 0)
151 PutStr(FIB
->fib_FileName
);
156 FreeDosObject(DOS_FIB
, FIB
);
162 PrintFault(IoErr(), progname
);
164 Return_Value
= RETURN_FAIL
;