Put pciehci.device in DEVS:USBHardware, like the other host-controller
[AROS.git] / workbench / c / shellcommands / Unsetenv.c
blobcbdcfbbfbd42f6de86a4a2f75c624b14bfbc1714
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: UnSetEnv CLI command
6 Lang: English
7 */
9 /*****************************************************************************
11 NAME
13 UnSetEnv
15 SYNOPSIS
17 NAME,SAVE/S
19 LOCATION
23 FUNCTION
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
34 is displayed.
36 INPUTS
38 NAME - The name of the global variable to unset.
40 SAVE - Unset (delete) the variable also in ENVARC:
42 RESULT
44 Standard DOS error codes.
46 NOTES
48 EXAMPLE
50 UnSetEnv EDITOR SAVE
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).
59 BUGS
61 SEE ALSO
63 GetEnv, SetEnv
65 INTERNALS
67 HISTORY
69 ******************************************************************************/
71 #include <proto/dos.h>
72 #include <proto/exec.h>
74 #include <dos/dos.h>
75 #include <dos/exall.h>
76 #include <dos/rdargs.h>
77 #include <dos/var.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))
87 AROS_SHCOMMAND_INIT
89 int Return_Value;
90 BOOL Success;
91 BPTR lock;
92 TEXT progname[108];
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;
115 else
117 /* Display a list of global variables.
120 lock = Lock("ENV:", ACCESS_READ);
121 if (lock)
123 struct FileInfoBlock *FIB = AllocDosObject(DOS_FIB, NULL);
125 if (FIB)
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);
135 PutStr("\n");
139 FreeDosObject(DOS_FIB, FIB);
141 UnLock(lock);
143 else
145 PrintFault(IoErr(), progname);
147 Return_Value = RETURN_FAIL;
151 return Return_Value;
153 AROS_SHCOMMAND_EXIT
154 } /* main */