New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / shellcommands / Setenv.c
blob6f65e26fe8c6bcc5b5899ee4e5449f9494cd1f47
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Setenv CLI command
6 Lang: English
7 */
9 /*****************************************************************************
11 NAME
13 Setenv
15 SYNOPSIS
17 NAME,SAVE/S,STRING/F
19 LOCATION
21 Workbench:c
23 FUNCTION
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
31 in ENVARC:
33 If no parameters are specified, the current list of global variables
34 are displayed.
36 INPUTS
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.
44 RESULT
46 Standard DOS error codes.
48 NOTES
50 EXAMPLE
52 Setenv EDITOR Ed
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.
58 BUGS
60 SEE ALSO
62 Getenv, Unsetenv
64 INTERNALS
66 HISTORY
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>
76 #include <dos/dos.h>
77 #include <dos/exall.h>
78 #include <dos/rdargs.h>
79 #include <dos/var.h>
80 #include <exec/memory.h>
81 #include <exec/types.h>
83 #include <utility/tagitem.h>
84 #include <stdio.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))
95 AROS_SHCOMMAND_INIT
97 int Return_Value;
98 BOOL Success;
99 BPTR lock;
100 TEXT progname[108];
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),
116 SHArg(STRING),
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;
132 else
134 /* Display a list of global variables.
137 lock = Lock("ENV:", ACCESS_READ);
138 if (lock)
140 struct FileInfoBlock *FIB = AllocDosObject(DOS_FIB, NULL);
142 if (FIB)
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);
152 PutStr("\n");
156 FreeDosObject(DOS_FIB, FIB);
158 UnLock(lock);
160 else
162 PrintFault(IoErr(), progname);
164 Return_Value = RETURN_FAIL;
168 return Return_Value;
170 AROS_SHCOMMAND_EXIT
171 } /* main */