Debian Codegraph @

libdebugger/command/set.c

raw symbols SCIP
1 /*
2 "Copyright (C) 2011, 2015, 2020 R. Bernstein <[email protected]>\n" \
3 This file is part of GNU Make (remake variant).
4
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 /** \file libdebugger/command/set.c
21 *
22 * \brief debugger `set` command.
23 *
24 * Debugger command to change various debugger and Makefile settings and values.
25 */
26
27 /* Documentation for help set, and help set xxx. Note the format has
28 been customized to make ddd work. In particular for "basename" it should
29 be
30 set basename -- Set if were are to show shor or long filenames is off.
31 (or "is on").
32 */
33
34 #include "../../src/trace.h"
35 #include "../../src/commands.h"
36 #include "../../src/debug.h"
37 #include "../../src/main.h"
38 #include "../cmd.h"
39 #include "../fns.h"
40 #include "../msg.h"
41 #include "../subcmd.h"
42
43 #ifdef HAVE_LIBREADLINE
44 #include <stdio.h>
45 #include <stdlib.h>
46 /* The following line makes Solaris' gcc/cpp not puke. */
47 #undef HAVE_READLINE_READLINE_H
48 #include <readline/readline.h>
49
50 /* From readline. ?? Should this be in configure? */
51 #ifndef whitespace
52 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
53 #endif
54 #endif /* HAVE_LIBREADLINE */
55
56 subcommand_var_info_t set_subcommands[] = {
57 { "basename",
58 "Set if we are to show short or long filenames",
59 " {on|off|toggle} \n\nSet if we are to show short or long filenames.",
60 &basename_filenames, true, 1},
61 { "debug",
62 "Set GNU Make debug mask (set via --debug or -d)",
63 " VALUE \n\nSet GNU Make debug mask (set via --debug or -d).",
64 &db_level, false, 3},
65 { "ignore-errors",
66 "Set value of GNU Make --ignore-errors (or -i) flag",
67 " {on|off|toggle} \n\nSet value of GNU Make --ignore-errors (or -i) flag.",
68 &ignore_errors_flag, true, 3},
69 { "keep-going",
70 "Set value of GNU Make --keep-going (or -k) flag",
71 " {on|off|toggle}\n\nSet value of GNU Make --keep-going (or -k) flag.",
72 &keep_going_flag, true, 1},
73 { "silent",
74 "Set value of GNU Make --silent (or -s) flags.",
75 " {on|off|toggle} \n\nSet value of GNU Make --silent (or -s) flags.",
76 &silent_flag, true, 1},
77 #ifdef FIXED
78 { "trace",
79 "Set value of shell_tracing.",
80 NULL,
81 &no_shell_trace, false, 3},
82 #endif
83 { "variable",
84 "Change a debugger setting",
85 " OPTION is one of: basename, debug, ignore-errors, keep-going, or silent\n\n"
86 "\n"
87 "See also 'setq' and 'setqx' for setting a GNU Make variable.",
88 NULL,
89 false, 0},
90 { NULL, NULL, NULL, NULL, false, 0}
91 };
92
93 static bool
94 dbg_cmd_set_bool(const char *psz_varname, const char *psz_flag_name,
95 const char *psz_flag_value,
96 unsigned int min, int *p_bool_flag)
97 {
98 if (is_abbrev_of (psz_varname, psz_flag_name, min)) {
99 if (!psz_flag_value || 0==strlen(psz_flag_value))
100 on_off_toggle(psz_flag_value, p_bool_flag);
101 else
102 on_off_toggle(psz_flag_value, p_bool_flag);
103 dbg_cmd_show((char *) psz_flag_name);
104 return true;
105 }
106 return false;
107 }
108
109
110 extern debug_return_t
111 dbg_cmd_set(char *psz_args)
112 {
113 if (!psz_args || 0==strlen(psz_args)) {
114 unsigned int i;
115 for (i = 0; set_subcommands[i].name; i++) {
116 dbg_help_subcmd_entry("set", "%-10s -- %s",
117 &(set_subcommands[i]), false);
118 }
119 return debug_readloop;
120 } else {
121 char *psz_varname = get_word(&psz_args);
122 subcommand_var_info_t *p_subcmd_info;
123
124 while (*psz_args && whitespace (*psz_args))
125 *psz_args +=1;
126
127 /* FIXME, add min to above table and DRY below code. */
128 if (is_abbrev_of (psz_varname, "debug", 3)) {
129 int dbg_mask;
130 if (get_int(psz_args, &dbg_mask, true)) {
131 db_level = dbg_mask;
132 }
133 dbg_cmd_show(psz_varname);
134 return debug_readloop;
135 } else if (is_abbrev_of (psz_varname, "variable", 3)) {
136 /* Treat as set variable */
137 return dbg_cmd_set_var(psz_args, 1);
138 #if FIXME_SET_ARGS
139 } else if (is_abbrev_of (psz_varname, "args", 3)) {
140 ...
141 #endif
142 } else
143 for (p_subcmd_info = set_subcommands; p_subcmd_info && p_subcmd_info->name;
144 p_subcmd_info++) {
145 if (dbg_cmd_set_bool(psz_varname, p_subcmd_info->name,
146 psz_args, p_subcmd_info->min_abbrev,
147 p_subcmd_info->var))
148 return debug_readloop;
149 }
150 dbg_errmsg("Unknown set option %s\nSee 'help set' for options. Or did you mean setq?\n",
151 psz_varname);
152 return debug_cmd_error;
153 }
154 }
155
156 /*
157 * Local variables:
158 * eval: (c-set-style "gnu")
159 * indent-tabs-mode: nil
160 * End:
161 */