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 #include <aros/shcommands.h>
88 AROS_SH3(Setenv
, 45.0,
89 AROS_SHA(STRPTR
, ,NAME
, , NULL
),
90 AROS_SHA(IPTR
, ,SAVE
, /S
, NULL
),
91 AROS_SHA(STRPTR
, ,STRING
, /F
, NULL
))
101 GetProgramName(progname
, sizeof(progname
));
102 Return_Value
= RETURN_OK
;
104 if (SHArg(NAME
) != NULL
|| SHArg(STRING
) != NULL
)
106 /* Make sure we get to here is either arguments are
107 * provided on the command line.
109 if (SHArg(NAME
) != NULL
&& SHArg(STRING
) != NULL
)
111 /* Add the new global variable to the list.
113 Success
= SetVar(SHArg(NAME
),
116 SHArg(SAVE
) ? GVF_GLOBAL_ONLY
| GVF_SAVE_VAR
: GVF_GLOBAL_ONLY
);
118 if (Success
== FALSE
)
120 UBYTE buf
[FAULT_MAX
+128];
122 Fault(-141, NULL
, buf
, sizeof(buf
));
123 Printf(buf
, SHArg(NAME
));
124 PrintFault(IoErr(), progname
);
126 Return_Value
= RETURN_ERROR
;
132 /* Display a list of global variables.
135 lock
= Lock("ENV:", ACCESS_READ
);
138 struct FileInfoBlock
*FIB
= AllocDosObject(DOS_FIB
, NULL
);
142 if(Examine(lock
, FIB
))
144 while(ExNext(lock
, FIB
))
146 /* don't show dirs */
147 if (FIB
->fib_DirEntryType
< 0)
149 PutStr(FIB
->fib_FileName
);
154 FreeDosObject(DOS_FIB
, FIB
);
160 PrintFault(IoErr(), progname
);
162 Return_Value
= RETURN_FAIL
;