File: help.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 (163 lines) | stat: -rw-r--r-- 4,869 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
162
163
/*
Copyright (C) 2011, 2020 R. Bernstein <rocky@gnu.org>
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/help.c
 *
 *  \brief Debugger ``help` command.
 */

#include "../../src/trace.h"
#include "../cmd.h"
#include "../fns.h"
#include "../msg.h"

extern short_cmd_t short_command[256];

void
dbg_help_subcmd_entry(const char *psz_subcmd_name, const char *psz_fmt,
		      subcommand_var_info_t *p_subcmd, bool full_info)
{
    if (full_info) {
      const char *doc = p_subcmd->doc ?
	p_subcmd->doc : p_subcmd->short_doc;
      printf("%s ", psz_subcmd_name);
      printf("%s\n%s.", p_subcmd->name, doc);
    } else {
      printf("%s ", psz_subcmd_name);
      printf(psz_fmt, p_subcmd->name, p_subcmd->short_doc);
      if (p_subcmd->var) {
	if (p_subcmd->b_onoff)
	  printf(" is %s.",
		 var_to_on_off(* (int *) p_subcmd->var));
	else
	  printf(" is %d.", *(int *)(p_subcmd->var));
      }
    }

    printf("\n");
}

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)
{
    unsigned int i;
    if (!psz_args || !*psz_args) {
	printf("%s\n\n%s\n", p_command->use, p_command->doc);
    } else {
	for (i = 0; subcommands[i].name; i++) {
	    if (is_abbrev_of(psz_args, subcommands[i].name,
			     subcommands[i].min_abbrev)) {
		dbg_help_subcmd_entry(psz_subcmd_name, "%s. %s",
				      &(subcommands[i]), true);
		return debug_readloop;
	    }
	}
	dbg_errmsg("There is no \"%s %s\" command.", psz_subcmd_name, psz_args);
    }
    return debug_readloop;
}

static bool
is_alias(const char *psz_command_name, const alias_cmd_t *p_alias)
{
  return strcmp (psz_command_name, p_alias->command) == 0;
}

debug_return_t
dbg_cmd_help(char *psz_args)
{
  unsigned int i;

  if (!psz_args || !*psz_args) {
    printf ("  Command                  Short Name  Aliases\n");
    printf ("  ----------------------   ----------  ---------\n");
    for (i = 0; dbg_commands[i].long_name; i++) {
      unsigned int j;
      bool b_alias = false;
      uint8_t s=dbg_commands[i].short_name;
      printf("  %-31s (%c)",
	     short_command[s].use, dbg_commands[i].short_name);
      for (j = 0; aliases[j].alias; j++) {
	if (is_alias(dbg_commands[i].long_name, &aliases[j])) {
	  if (!b_alias) {
	    printf("  %s", aliases[j].alias);
	    b_alias = true;
	  } else {
	    printf(", %s", aliases[j].alias);
	  }
	}
      }
      printf("\n");
    }

    dbg_msg("\nReadline command line editing (emacs/vi mode) is available.\n"
"For more detailed help, type 'help *command-name*' or consult\n"
"the online-documentation.\n");

  } else {
      short_cmd_t *p_command;
      const char *psz_command = "";

      if (1 == strlen(psz_args)) {
	  if ( NULL != short_command[(uint8_t)psz_args[0]].func )
	      p_command = &short_command[(uint8_t)psz_args[0]];
	  else
	      p_command = NULL;
      } else {
	  psz_command = get_word(&psz_args);
	  p_command = find_command (psz_command);
      }
      if (p_command) {
	  if ( p_command->func == &dbg_cmd_info ) {
	      return dbg_help_subcmd("info", p_command, psz_args, info_subcommands);
	  } else if ( p_command->func == &dbg_cmd_show ) {
	      return dbg_help_subcmd("show", p_command, psz_args, show_subcommands);
	  } else if ( p_command->func == &dbg_cmd_set ) {
	      return dbg_help_subcmd("set", p_command, psz_args, set_subcommands);
	  } else {
            const long_cmd_t *p_long_command = &dbg_commands[p_command->id];
            printf("%s\n\n", p_command->use);
            printf("%s\n", p_command->doc);
            printf("\nShort name and aliases: %c", p_long_command->short_name);
            for (int j = 0; aliases[j].alias; j++) {
              if (p_long_command->long_name && is_alias(p_long_command->long_name, &aliases[j])) {
                printf(", %s", aliases[j].alias);
              }
            }
            printf("\n");
	  }

      } else {
	  dbg_errmsg("Undefined command `%s'. Try help for a list of commands.\n",
                     psz_command);
      }
  }

  return debug_readloop;
}

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