2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
5 Desc: UnSetEnv CLI command
9 /*****************************************************************************
25 Unsets 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. If set using SAVE argument, the variable is also saved
31 in ENVARC: and can then be deleted there by UnSetEnv with the SAVE argument.
33 If no parameter is specified, the current list of global variables
38 NAME - The name of the global variable to unset.
40 SAVE - Unset (delete) the variable also in ENVARC:
44 Standard DOS error codes.
52 Any program that accesses the variable "EDITOR" (like More and
53 MultiView) are able to find out the name of the text-editor the
54 user would like to use, by examining the contents of the variable.
55 This command would delete this variable in Ram (in ENV:) _and_ in
56 ENVARC: (assuming it was already set there, for example by the use
57 of the SAVE argument of SetEnv).
69 ******************************************************************************/
71 #include <proto/dos.h>
72 #include <proto/exec.h>
75 #include <dos/exall.h>
76 #include <dos/rdargs.h>
78 #include <exec/memory.h>
79 #include <exec/types.h>
80 #include <utility/tagitem.h>
81 #include <aros/shcommands.h>
83 AROS_SH2(UnSetEnv
, 45.0,
84 AROS_SHA(STRPTR
, , NAME
, , NULL
),
85 AROS_SHA(IPTR
, , SAVE
, /S
, NULL
))
94 GetProgramName(progname
, sizeof(progname
));
95 Return_Value
= RETURN_OK
;
97 if (SHArg(NAME
) != NULL
)
99 /* Delete the global variable from the list.
101 Success
= DeleteVar(SHArg(NAME
),
102 SHArg(SAVE
) ? GVF_GLOBAL_ONLY
| GVF_SAVE_VAR
: GVF_GLOBAL_ONLY
);
104 if (Success
== FALSE
)
106 UBYTE buf
[FAULT_MAX
+128];
108 Fault(-141, NULL
, buf
, sizeof(buf
));
109 Printf(buf
, SHArg(NAME
));
110 PrintFault(IoErr(), progname
);
112 Return_Value
= RETURN_ERROR
;
117 /* Display a list of global variables.
120 lock
= Lock("ENV:", ACCESS_READ
);
123 struct FileInfoBlock
*FIB
= AllocDosObject(DOS_FIB
, NULL
);
127 if(Examine(lock
, FIB
))
129 while(ExNext(lock
, FIB
))
131 /* don't show dirs */
132 if (FIB
->fib_DirEntryType
< 0)
134 PutStr(FIB
->fib_FileName
);
139 FreeDosObject(DOS_FIB
, FIB
);
145 PrintFault(IoErr(), progname
);
147 Return_Value
= RETURN_FAIL
;