File: set.c

package info (click to toggle)
remake 4.3%2Bdbg-1.6%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,688 kB
  • sloc: ansic: 38,702; sh: 5,248; perl: 1,577; makefile: 236; lisp: 26; sed: 16
file content (161 lines) | stat: -rw-r--r-- 5,127 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
  "Copyright (C) 2011, 2015, 2020 R. Bernstein <rocky@gnu.org>\n" \
  This file is part of GNU Make (remake variant).

GNU Make is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Make is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Make; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

/** \file libdebugger/command/set.c
 *
 *  \brief debugger `set` command.
 *
 *  Debugger command to change various debugger and Makefile settings and values.
 */

/* Documentation for help set, and help set xxx. Note the format has
   been customized to make ddd work. In particular for "basename" it should
   be
     set basename -- Set if were are to show shor or long filenames is off.
   (or "is on").
*/

#include "../../src/trace.h"
#include "../../src/commands.h"
#include "../../src/debug.h"
#include "../../src/main.h"
#include "../cmd.h"
#include "../fns.h"
#include "../msg.h"
#include "../subcmd.h"

#ifdef HAVE_LIBREADLINE
#include <stdio.h>
#include <stdlib.h>
/* The following line makes Solaris' gcc/cpp not puke. */
#undef HAVE_READLINE_READLINE_H
#include <readline/readline.h>

/* From readline. ?? Should this be in configure?  */
#ifndef whitespace
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
#endif
#endif /* HAVE_LIBREADLINE */

subcommand_var_info_t set_subcommands[] = {
  { "basename",
    "Set if we are to show short or long filenames",
    " {on|off|toggle} \n\nSet if we are to show short or long filenames.",
    &basename_filenames, true, 1},
  { "debug",
    "Set GNU Make debug mask (set via --debug or -d)",
    " VALUE \n\nSet GNU Make debug mask (set via --debug or -d).",
    &db_level, false, 3},
  { "ignore-errors",
    "Set value of GNU Make --ignore-errors (or -i) flag",
    " {on|off|toggle} \n\nSet value of GNU Make --ignore-errors (or -i) flag.",
    &ignore_errors_flag, true, 3},
  { "keep-going",
    "Set value of GNU Make --keep-going (or -k) flag",
    " {on|off|toggle}\n\nSet value of GNU Make --keep-going (or -k) flag.",
    &keep_going_flag,    true, 1},
  { "silent",
    "Set value of GNU Make --silent (or -s) flags.",
    " {on|off|toggle} \n\nSet value of GNU Make --silent (or -s) flags.",
    &silent_flag,        true, 1},
#ifdef FIXED
  { "trace",
    "Set value of shell_tracing.",
    NULL,
    &no_shell_trace,    false, 3},
#endif
  { "variable",
    "Change a debugger setting",
    " OPTION is one of: basename, debug, ignore-errors, keep-going, or silent\n\n"
"\n"
"See also 'setq' and 'setqx' for setting a GNU Make variable.",
    NULL,
    false, 0},
  { NULL, NULL, NULL, NULL, false, 0}
};

static bool
dbg_cmd_set_bool(const char *psz_varname, const char *psz_flag_name,
                 const char *psz_flag_value,
                 unsigned int min, int *p_bool_flag)
{
  if (is_abbrev_of (psz_varname, psz_flag_name, min)) {
      if (!psz_flag_value || 0==strlen(psz_flag_value))
	on_off_toggle(psz_flag_value, p_bool_flag);
      else
	on_off_toggle(psz_flag_value, p_bool_flag);
      dbg_cmd_show((char *) psz_flag_name);
      return true;
  }
  return false;
}


extern debug_return_t
dbg_cmd_set(char *psz_args)
{
  if (!psz_args || 0==strlen(psz_args)) {
    unsigned int i;
    for (i = 0; set_subcommands[i].name; i++) {
      dbg_help_subcmd_entry("set", "%-10s -- %s",
                            &(set_subcommands[i]), false);
    }
    return debug_readloop;
  } else {
    char *psz_varname = get_word(&psz_args);
    subcommand_var_info_t *p_subcmd_info;

    while (*psz_args && whitespace (*psz_args))
      *psz_args +=1;

    /* FIXME, add min to above table and DRY below code. */
    if (is_abbrev_of (psz_varname, "debug", 3)) {
      int dbg_mask;
      if (get_int(psz_args, &dbg_mask, true)) {
	db_level = dbg_mask;
      }
      dbg_cmd_show(psz_varname);
      return debug_readloop;
    } else if (is_abbrev_of (psz_varname, "variable", 3)) {
      /* Treat as set variable */
      return dbg_cmd_set_var(psz_args, 1);
#if FIXME_SET_ARGS
    } else if (is_abbrev_of (psz_varname, "args", 3)) {
        ...
#endif
    } else
      for (p_subcmd_info = set_subcommands; p_subcmd_info && p_subcmd_info->name;
           p_subcmd_info++) {
        if (dbg_cmd_set_bool(psz_varname, p_subcmd_info->name,
                             psz_args, p_subcmd_info->min_abbrev,
                             p_subcmd_info->var))
          return debug_readloop;
      }
    dbg_errmsg("Unknown set option %s\nSee 'help set' for options. Or did you mean setq?\n",
               psz_varname);
    return debug_cmd_error;
  }
}

/*
 * Local variables:
 * eval: (c-set-style "gnu")
 * indent-tabs-mode: nil
 * End:
 */