Debian Codegraph @

libdebugger/command/help.c

raw symbols SCIP
1 /*
2 Copyright (C) 2011, 2020 R. Bernstein <[email protected]>
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/help.c
21 *
22 * \brief Debugger ``help` command.
23 */
24
25 #include "../../src/trace.h"
26 #include "../cmd.h"
27 #include "../fns.h"
28 #include "../msg.h"
29
30 extern short_cmd_t short_command[256];
31
32 void
33 dbg_help_subcmd_entry(const char *psz_subcmd_name, const char *psz_fmt,
34 subcommand_var_info_t *p_subcmd, bool full_info)
35 {
36 if (full_info) {
37 const char *doc = p_subcmd->doc ?
38 p_subcmd->doc : p_subcmd->short_doc;
39 printf("%s ", psz_subcmd_name);
40 printf("%s\n%s.", p_subcmd->name, doc);
41 } else {
42 printf("%s ", psz_subcmd_name);
43 printf(psz_fmt, p_subcmd->name, p_subcmd->short_doc);
44 if (p_subcmd->var) {
45 if (p_subcmd->b_onoff)
46 printf(" is %s.",
47 var_to_on_off(* (int *) p_subcmd->var));
48 else
49 printf(" is %d.", *(int *)(p_subcmd->var));
50 }
51 }
52
53 printf("\n");
54 }
55
56 debug_return_t
57 dbg_help_subcmd(const char *psz_subcmd_name,
58 short_cmd_t *p_command, const char *psz_args,
59 subcommand_var_info_t *subcommands)
60 {
61 unsigned int i;
62 if (!psz_args || !*psz_args) {
63 printf("%s\n\n%s\n", p_command->use, p_command->doc);
64 } else {
65 for (i = 0; subcommands[i].name; i++) {
66 if (is_abbrev_of(psz_args, subcommands[i].name,
67 subcommands[i].min_abbrev)) {
68 dbg_help_subcmd_entry(psz_subcmd_name, "%s. %s",
69 &(subcommands[i]), true);
70 return debug_readloop;
71 }
72 }
73 dbg_errmsg("There is no \"%s %s\" command.", psz_subcmd_name, psz_args);
74 }
75 return debug_readloop;
76 }
77
78 static bool
79 is_alias(const char *psz_command_name, const alias_cmd_t *p_alias)
80 {
81 return strcmp (psz_command_name, p_alias->command) == 0;
82 }
83
84 debug_return_t
85 dbg_cmd_help(char *psz_args)
86 {
87 unsigned int i;
88
89 if (!psz_args || !*psz_args) {
90 printf (" Command Short Name Aliases\n");
91 printf (" ---------------------- ---------- ---------\n");
92 for (i = 0; dbg_commands[i].long_name; i++) {
93 unsigned int j;
94 bool b_alias = false;
95 uint8_t s=dbg_commands[i].short_name;
96 printf(" %-31s (%c)",
97 short_command[s].use, dbg_commands[i].short_name);
98 for (j = 0; aliases[j].alias; j++) {
99 if (is_alias(dbg_commands[i].long_name, &aliases[j])) {
100 if (!b_alias) {
101 printf(" %s", aliases[j].alias);
102 b_alias = true;
103 } else {
104 printf(", %s", aliases[j].alias);
105 }
106 }
107 }
108 printf("\n");
109 }
110
111 dbg_msg("\nReadline command line editing (emacs/vi mode) is available.\n"
112 "For more detailed help, type 'help *command-name*' or consult\n"
113 "the online-documentation.\n");
114
115 } else {
116 short_cmd_t *p_command;
117 const char *psz_command = "";
118
119 if (1 == strlen(psz_args)) {
120 if ( NULL != short_command[(uint8_t)psz_args[0]].func )
121 p_command = &short_command[(uint8_t)psz_args[0]];
122 else
123 p_command = NULL;
124 } else {
125 psz_command = get_word(&psz_args);
126 p_command = find_command (psz_command);
127 }
128 if (p_command) {
129 if ( p_command->func == &dbg_cmd_info ) {
130 return dbg_help_subcmd("info", p_command, psz_args, info_subcommands);
131 } else if ( p_command->func == &dbg_cmd_show ) {
132 return dbg_help_subcmd("show", p_command, psz_args, show_subcommands);
133 } else if ( p_command->func == &dbg_cmd_set ) {
134 return dbg_help_subcmd("set", p_command, psz_args, set_subcommands);
135 } else {
136 const long_cmd_t *p_long_command = &dbg_commands[p_command->id];
137 printf("%s\n\n", p_command->use);
138 printf("%s\n", p_command->doc);
139 printf("\nShort name and aliases: %c", p_long_command->short_name);
140 for (int j = 0; aliases[j].alias; j++) {
141 if (p_long_command->long_name && is_alias(p_long_command->long_name, &aliases[j])) {
142 printf(", %s", aliases[j].alias);
143 }
144 }
145 printf("\n");
146 }
147
148 } else {
149 dbg_errmsg("Undefined command `%s'. Try help for a list of commands.\n",
150 psz_command);
151 }
152 }
153
154 return debug_readloop;
155 }
156
157
158 /*
159 * Local variables:
160 * eval: (c-set-style "gnu")
161 * indent-tabs-mode: nil
162 * End:
163 */