allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / cfe / cfe / ui / ui_envcmds.c
blob9d69f3675a830fc7e5b91c338299e40b5b65504c
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Environment commands File: ui_envcmds.c
5 *
6 * User interface for environment variables
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
48 #include "lib_types.h"
49 #include "lib_string.h"
50 #include "lib_queue.h"
51 #include "lib_malloc.h"
52 #include "lib_printf.h"
54 #include "cfe_iocb.h"
55 #include "cfe_device.h"
56 #include "cfe_console.h"
57 #include "env_subr.h"
58 #include "ui_command.h"
59 #include "cfe.h"
62 int ui_init_envcmds(void);
63 static int ui_cmd_setenv(ui_cmdline_t *cmd,int argc,char *argv[]);
64 static int ui_cmd_printenv(ui_cmdline_t *cmd,int argc,char *argv[]);
65 static int ui_cmd_unsetenv(ui_cmdline_t *cmd,int argc,char *argv[]);
69 static int ui_cmd_printenv(ui_cmdline_t *cmd,int argc,char *argv[])
71 char varname[80];
72 char value[256];
73 int varlen,vallen;
74 int idx;
76 xprintf("Variable Name Value\n");
77 xprintf("-------------------- --------------------------------------------------\n");
79 idx = 0;
80 for (;;) {
81 varlen = sizeof(varname);
82 vallen = sizeof(value);
83 if (env_enum(idx,varname,&varlen,value,&vallen) < 0) break;
84 xprintf("%20s %s\n",varname,value);
85 idx++;
88 return 0;
92 static int ui_cmd_setenv(ui_cmdline_t *cmd,int argc,char *argv[])
94 char *varname;
95 char *value;
96 int roflag = ENV_FLG_NORMAL;
97 int res;
99 varname = cmd_getarg(cmd,0);
101 if (!varname) {
102 return ui_showusage(cmd);
105 value = cmd_getarg(cmd,1);
106 if (!value) {
107 return ui_showusage(cmd);
110 if (!cmd_sw_isset(cmd,"-p")) {
111 roflag = ENV_FLG_BUILTIN; /* just in memory, not NVRAM */
114 if (cmd_sw_isset(cmd,"-ro")) {
115 roflag = ENV_FLG_READONLY;
118 if ((res = env_setenv(varname,value,roflag)) == 0) {
119 if (roflag != ENV_FLG_BUILTIN) env_save();
121 else {
122 return ui_showerror(res,"Could not set environment variable '%s'",
123 varname);
126 return 0;
130 static int ui_cmd_unsetenv(ui_cmdline_t *cmd,int argc,char *argv[])
132 char *varname;
133 int res;
134 int type;
136 varname = cmd_getarg(cmd,0);
138 if (!varname) {
139 return ui_showusage(cmd);
142 type = env_envtype(varname);
144 if ((res = env_delenv(varname)) == 0) {
145 if ((type >= 0) && (type != ENV_FLG_BUILTIN)) env_save();
147 else {
148 return ui_showerror(res,"Could not delete environment variable '%s'",
149 varname);
152 return 0;
157 int ui_init_envcmds(void)
160 cmd_addcmd("setenv",
161 ui_cmd_setenv,
162 NULL,
163 "Set an environment variable.",
164 "setenv [-ro] [-p] varname value\n\n"
165 "This command sets an environment variable. By default, an environment variable\n"
166 "is stored only in memory and will not be retained across system restart.",
167 "-p;Store environment variable permanently in the NVRAM device, if present|"
168 "-ro;Causes variable to be read-only\n"
169 "(cannot be changed in the future, implies -p)");
171 cmd_addcmd("printenv",
172 ui_cmd_printenv,
173 NULL,
174 "Display the environment variables",
175 "printenv\n\n"
176 "This command prints a table of the environment variables and their\n"
177 "current values.",
178 "");
180 cmd_addcmd("unsetenv",
181 ui_cmd_unsetenv,
182 NULL,
183 "Delete an environment variable.",
184 "unsetenv varname\n\n"
185 "This command deletes an environment variable from memory and also \n"
186 "removes it from the NVRAM device (if present).",
187 "");
189 return 0;