remake  4.3+dbg-1.5
help.h
Go to the documentation of this file.
1 /* Write commands associated with a given target. */
2 /*
3 Copyright (C) 2011, 2020 R. Bernstein <rocky@gnu.org>
4 This file is part of GNU Make (remake variant).
5 
6 GNU Make is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10 
11 GNU Make is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GNU Make; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20 /* Debugger help command. */
21 
22 #include "help/help.h"
23 
24 void
25 dbg_help_subcmd_entry(const char *psz_subcmd_name, const char *psz_fmt,
26  subcommand_var_info_t *p_subcmd, bool full_info)
27 {
28  if (full_info) {
29  const char *doc = p_subcmd->doc ?
30  p_subcmd->doc : p_subcmd->short_doc;
31  printf("%s ", psz_subcmd_name);
32  printf("%s\n%s.", p_subcmd->name, doc);
33  } else {
34  printf("%s ", psz_subcmd_name);
35  printf(psz_fmt, p_subcmd->name, p_subcmd->short_doc);
36  if (p_subcmd->var) {
37  if (p_subcmd->b_onoff)
38  printf(" is %s.",
39  var_to_on_off(* (int *) p_subcmd->var));
40  else
41  printf(" is %d.", *(int *)(p_subcmd->var));
42  }
43  }
44 
45  printf("\n");
46 }
47 
49 dbg_help_subcmd(const char *psz_subcmd_name,
50  short_cmd_t *p_command, const char *psz_args,
51  subcommand_var_info_t *subcommands)
52 {
53  unsigned int i;
54  if (!psz_args || !*psz_args) {
55  printf("%s\n\n%s\n", p_command->use, p_command->doc);
56  } else {
57  for (i = 0; subcommands[i].name; i++) {
58  if (is_abbrev_of(psz_args, subcommands[i].name,
59  subcommands[i].min_abbrev)) {
60  dbg_help_subcmd_entry(psz_subcmd_name, "%s. %s",
61  &(subcommands[i]), true);
62  return debug_readloop;
63  }
64  }
65  dbg_errmsg("There is no \"%s %s\" command.", psz_subcmd_name, psz_args);
66  }
67  return debug_readloop;
68 }
69 
70 static bool
71 is_alias(const char *psz_command_name, const alias_cmd_t *p_alias)
72 {
73  return strcmp (psz_command_name, p_alias->command) == 0;
74 }
75 
77 dbg_cmd_help(char *psz_args)
78 {
79  unsigned int i;
80 
81  if (!psz_args || !*psz_args) {
82  printf (" Command Short Name Aliases\n");
83  printf (" ---------------------- ---------- ---------\n");
84  for (i = 0; commands[i].long_name; i++) {
85  unsigned int j;
86  bool b_alias = false;
87  uint8_t s=commands[i].short_name;
88  printf(" %-31s (%c)",
89  short_command[s].use, commands[i].short_name);
90  for (j = 0; aliases[j].alias; j++) {
91  if (is_alias(commands[i].long_name, &aliases[j])) {
92  if (!b_alias) {
93  printf(" %s", aliases[j].alias);
94  b_alias = true;
95  } else {
96  printf(", %s", aliases[j].alias);
97  }
98  }
99  }
100  printf("\n");
101  }
102 
103  dbg_msg("\nReadline command line editing (emacs/vi mode) is available.\n"
104 "For more detailed help, type 'help COMAMND-NAME' or consult\n"
105 "the online-documentation.\n");
106 
107  } else {
108  short_cmd_t *p_command;
109  const char *psz_command = "";
110 
111  if (1 == strlen(psz_args)) {
112  if ( NULL != short_command[(uint8_t)psz_args[0]].func )
113  p_command = &short_command[(uint8_t)psz_args[0]];
114  else
115  p_command = NULL;
116  } else {
117  psz_command = get_word(&psz_args);
118  p_command = find_command (psz_command);
119  }
120  if (p_command) {
121  if ( p_command->func == &dbg_cmd_info ) {
122  return dbg_help_subcmd("info", p_command, psz_args, info_subcommands);
123  } else if ( p_command->func == &dbg_cmd_show ) {
124  return dbg_help_subcmd("show", p_command, psz_args, show_subcommands);
125  } else if ( p_command->func == &dbg_cmd_set ) {
126  return dbg_help_subcmd("set", p_command, psz_args, set_subcommands);
127  } else {
128  const long_cmd_t *p_long_command = &commands[p_command->id];
129  printf("%s\n\n", p_command->use);
130  printf("%s\n", p_command->doc);
131  printf("\nShort name and aliases: %c", p_long_command->short_name);
132  for (int j = 0; aliases[j].alias; j++) {
133  if (p_long_command->long_name && is_alias(p_long_command->long_name, &aliases[j])) {
134  printf(", %s", aliases[j].alias);
135  }
136  }
137  printf("\n");
138  }
139 
140  } else {
141  dbg_errmsg("Undefined command `%s'. Try help for a list of commands.\n",
142  psz_command);
143  }
144  }
145 
146  return debug_readloop;
147 }
148 
149 static void
150 dbg_cmd_help_init(unsigned int c)
151 {
152  short_command[c].func = &dbg_cmd_help;
153  short_command[c].use = _("help [COMMAND]");
154 }
155 
156 
157 /*
158  * Local variables:
159  * eval: (c-set-style "gnu")
160  * indent-tabs-mode: nil
161  * End:
162  */
subcommand_var_info_t show_subcommands[]
Definition: show.h:24
const char * use
Definition: debugger.h:19
Definition: debugger.h:16
Definition: debugger.h:8
const char * name
Definition: subcmd.h:5
Definition: commands.h:27
void dbg_errmsg()
subcommand_var_info_t set_subcommands[]
Definition: set.h:31
debug_return_t dbg_cmd_info(char *psz_args)
Definition: command/info.h:284
bool is_abbrev_of(const char *psz_substr, const char *psz_word, unsigned int i_min)
debug_return_t dbg_cmd_show(char *psz_args)
Definition: show.h:81
debug_return_t
Definition: trace.h:32
dbg_cmd_t func
Definition: debugger.h:17
Definition: subcmd.h:4
const char * short_doc
Definition: subcmd.h:6
debug_return_t dbg_cmd_help(char *psz_args)
Definition: help.h:77
#define _(msgid)
Definition: make.h:293
Definition: trace.h:40
const char * doc
Definition: debugger.h:18
uint8_t id
Definition: debugger.h:20
const char * var_to_on_off(int i_bool)
void dbg_msg()
char * get_word(char **ppsz_str)
const char * long_name
Definition: debugger.h:9
void dbg_help_subcmd_entry(const char *psz_subcmd_name, const char *psz_fmt, subcommand_var_info_t *p_subcmd, bool full_info)
Definition: help.h:25
const char * doc
Definition: subcmd.h:7
const char short_name
Definition: debugger.h:10
debug_return_t dbg_help_subcmd(const char *psz_subcmd_name, short_cmd_t *p_command, const char *psz_args, subcommand_var_info_t *subcommands)
Definition: help.h:49
subcommand_var_info_t info_subcommands[]
Definition: command/info.h:57
bool b_onoff
Definition: subcmd.h:10
int * var
Definition: subcmd.h:8