1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1982-2014 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Eclipse Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.eclipse.org/org/documents/epl-v10.html *
11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * David Korn <dgkorn@gmail.com> *
18 * *
19 ***********************************************************************/
20 #include "config_ast.h" // IWYU pragma: keep
21
22 #include <stdbool.h>
23 #include <string.h>
24
25 #include "argnod.h"
26 #include "builtins.h"
27 #include "defs.h"
28 #include "sfio.h"
29 #include "shcmd.h"
30
b_set(int argc,char * argv[],Shbltin_t * context)31 int b_set(int argc, char *argv[], Shbltin_t *context) {
32 Shell_t *shp = context->shp;
33 struct tdata tdata;
34 int was_monitor = sh_isoption(shp, SH_MONITOR);
35
36 memset(&tdata, 0, sizeof(tdata));
37 tdata.sh = shp;
38 tdata.prefix = NULL;
39 if (argv[1]) {
40 if (sh_argopts(argc, argv, tdata.sh) < 0) return 2;
41 if (sh_isoption(shp, SH_VERBOSE)) {
42 sh_onstate(shp, SH_VERBOSE);
43 } else {
44 sh_offstate(shp, SH_VERBOSE);
45 }
46 if (sh_isoption(shp, SH_MONITOR) && !was_monitor) {
47 sh_onstate(shp, SH_MONITOR);
48 } else if (!sh_isoption(shp, SH_MONITOR) && was_monitor) {
49 sh_offstate(shp, SH_MONITOR);
50 }
51 } else {
52 // Scan name chain and print.
53 print_scan(sfstdout, 0, tdata.sh->var_tree, false, &tdata);
54 }
55 return 0;
56 }
57