Update copyright year in gdb/gdbserver/gdbreplay version output.
[deliverable/binutils-gdb.git] / gdb / cli / cli-decode.c
CommitLineData
c906108c 1/* Handle lists of commands, their decoding and documentation, for GDB.
8926118c 2
0b302171
JB
3 Copyright (c) 1986, 1989-1991, 1998, 2000-2002, 2004, 2007-2012 Free
4 Software Foundation, Inc.
c906108c 5
c5aa993b
JM
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
c5aa993b 9 (at your option) any later version.
c906108c 10
c5aa993b
JM
11 This program 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.
c906108c 15
c5aa993b 16 You should have received a copy of the GNU General Public License
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
18
19#include "defs.h"
c906108c 20#include "symtab.h"
c906108c 21#include <ctype.h>
f77b92bf 22#include "gdb_regex.h"
5f8a3188 23#include "gdb_string.h"
f397e303 24#include "completer.h"
8b93c638 25#include "ui-out.h"
c906108c 26
d318976c
FN
27#include "cli/cli-cmds.h"
28#include "cli/cli-decode.h"
53a5351d 29
6a83354a 30#ifdef TUI
ebcd3b23 31#include "tui/tui.h" /* For tui_active et al. */
6a83354a
AC
32#endif
33
b2875cc0
AC
34#include "gdb_assert.h"
35
ebcd3b23 36/* Prototypes for local functions. */
c906108c 37
a14ed312 38static void undef_cmd_error (char *, char *);
c906108c 39
b05dcbb7 40static struct cmd_list_element *delete_cmd (char *name,
fad6eecd
TT
41 struct cmd_list_element **list,
42 struct cmd_list_element **prehook,
43 struct cmd_list_element **prehookee,
44 struct cmd_list_element **posthook,
45 struct cmd_list_element **posthookee);
b05dcbb7 46
a14ed312
KB
47static struct cmd_list_element *find_cmd (char *command,
48 int len,
49 struct cmd_list_element *clist,
50 int ignore_help_classes,
51 int *nfound);
6837a0a2 52
c85871a3 53static void help_all (struct ui_file *stream);
6e381ba0 54
5b9afe8a
YQ
55/* Look up a command whose 'prefixlist' is KEY. Return the command if found,
56 otherwise return NULL. */
57
58static struct cmd_list_element *
59lookup_cmd_for_prefixlist (struct cmd_list_element **key,
60 struct cmd_list_element *list)
61{
62 struct cmd_list_element *p = NULL;
63
64 for (p = list; p != NULL; p = p->next)
65 {
66 struct cmd_list_element *q;
67
68 if (p->prefixlist == NULL)
69 continue;
70 else if (p->prefixlist == key)
71 return p;
72
73 q = lookup_cmd_for_prefixlist (key, *(p->prefixlist));
74 if (q != NULL)
75 return q;
76 }
77
78 return NULL;
79}
80
81static void
82set_cmd_prefix (struct cmd_list_element *c, struct cmd_list_element **list)
83{
84 struct cmd_list_element *p;
85
86 /* Check to see if *LIST contains any element other than C. */
87 for (p = *list; p != NULL; p = p->next)
88 if (p != c)
89 break;
90
91 if (p == NULL)
92 {
93 /* *SET_LIST only contains SET. */
94 p = lookup_cmd_for_prefixlist (list, setlist);
95
96 c->prefix = p ? (p->cmd_pointer ? p->cmd_pointer : p) : p;
97 }
98 else
99 c->prefix = p->prefix;
100}
101
6e381ba0
VP
102static void
103print_help_for_command (struct cmd_list_element *c, char *prefix, int recurse,
104 struct ui_file *stream);
105
d318976c 106\f
9f60d481
AC
107/* Set the callback function for the specified command. For each both
108 the commands callback and func() are set. The latter set to a
109 bounce function (unless cfunc / sfunc is NULL that is). */
110
111static void
112do_cfunc (struct cmd_list_element *c, char *args, int from_tty)
113{
114 c->function.cfunc (args, from_tty); /* Ok. */
115}
116
117void
9773a94b 118set_cmd_cfunc (struct cmd_list_element *cmd, cmd_cfunc_ftype *cfunc)
9f60d481
AC
119{
120 if (cfunc == NULL)
121 cmd->func = NULL;
122 else
123 cmd->func = do_cfunc;
124 cmd->function.cfunc = cfunc; /* Ok. */
125}
126
127static void
128do_sfunc (struct cmd_list_element *c, char *args, int from_tty)
129{
130 c->function.sfunc (args, from_tty, c); /* Ok. */
131}
132
133void
9773a94b 134set_cmd_sfunc (struct cmd_list_element *cmd, cmd_sfunc_ftype *sfunc)
9f60d481
AC
135{
136 if (sfunc == NULL)
137 cmd->func = NULL;
138 else
139 cmd->func = do_sfunc;
140 cmd->function.sfunc = sfunc; /* Ok. */
141}
142
bbaca940
AC
143int
144cmd_cfunc_eq (struct cmd_list_element *cmd,
145 void (*cfunc) (char *args, int from_tty))
146{
147 return cmd->func == do_cfunc && cmd->function.cfunc == cfunc;
148}
149
7d0766f3
AC
150void
151set_cmd_context (struct cmd_list_element *cmd, void *context)
152{
153 cmd->context = context;
154}
155
156void *
157get_cmd_context (struct cmd_list_element *cmd)
158{
159 return cmd->context;
160}
161
1868c04e
AC
162enum cmd_types
163cmd_type (struct cmd_list_element *cmd)
164{
165 return cmd->type;
166}
167
5ba2abeb 168void
625e8578 169set_cmd_completer (struct cmd_list_element *cmd, completer_ftype *completer)
5ba2abeb
AC
170{
171 cmd->completer = completer; /* Ok. */
172}
173
c906108c 174/* Add element named NAME.
bc587a6b 175 Space for NAME and DOC must be allocated by the caller.
c906108c
SS
176 CLASS is the top level category into which commands are broken down
177 for "help" purposes.
178 FUN should be the function to execute the command;
179 it will get a character string as argument, with leading
180 and trailing blanks already eliminated.
181
182 DOC is a documentation string for the command.
183 Its first line should be a complete sentence.
184 It should start with ? for a command that is an abbreviation
185 or with * for a command that most users don't need to know about.
186
ebcd3b23 187 Add this command to command list *LIST.
c906108c
SS
188
189 Returns a pointer to the added command (not necessarily the head
ebcd3b23 190 of *LIST). */
c906108c
SS
191
192struct cmd_list_element *
af1c1752
KB
193add_cmd (char *name, enum command_class class, void (*fun) (char *, int),
194 char *doc, struct cmd_list_element **list)
c906108c 195{
d5b5ac79 196 struct cmd_list_element *c
cdb27c12 197 = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
b05dcbb7 198 struct cmd_list_element *p, *iter;
c906108c 199
b05dcbb7
TT
200 /* Turn each alias of the old command into an alias of the new
201 command. */
fad6eecd
TT
202 c->aliases = delete_cmd (name, list, &c->hook_pre, &c->hookee_pre,
203 &c->hook_post, &c->hookee_post);
b05dcbb7
TT
204 for (iter = c->aliases; iter; iter = iter->alias_chain)
205 iter->cmd_pointer = c;
fad6eecd
TT
206 if (c->hook_pre)
207 c->hook_pre->hookee_pre = c;
208 if (c->hookee_pre)
209 c->hookee_pre->hook_pre = c;
210 if (c->hook_post)
211 c->hook_post->hookee_post = c;
212 if (c->hookee_post)
213 c->hookee_post->hook_post = c;
c906108c 214
494b7ec9 215 if (*list == NULL || strcmp ((*list)->name, name) >= 0)
c906108c
SS
216 {
217 c->next = *list;
218 *list = c;
219 }
220 else
221 {
222 p = *list;
494b7ec9 223 while (p->next && strcmp (p->next->name, name) <= 0)
c5aa993b
JM
224 {
225 p = p->next;
226 }
c906108c
SS
227 c->next = p->next;
228 p->next = c;
229 }
230
231 c->name = name;
232 c->class = class;
9f60d481 233 set_cmd_cfunc (c, fun);
7d0766f3 234 set_cmd_context (c, NULL);
c906108c 235 c->doc = doc;
56382845
FN
236 c->flags = 0;
237 c->replacement = NULL;
47724592 238 c->pre_show_hook = NULL;
73bc900d 239 c->hook_in = 0;
c906108c
SS
240 c->prefixlist = NULL;
241 c->prefixname = NULL;
242 c->allow_unknown = 0;
5b9afe8a 243 c->prefix = NULL;
c906108c 244 c->abbrev_flag = 0;
d8906c6f
TJB
245 set_cmd_completer (c, make_symbol_completion_list_fn);
246 c->destroyer = NULL;
c906108c
SS
247 c->type = not_set_cmd;
248 c->var = NULL;
249 c->var_type = var_boolean;
250 c->enums = NULL;
251 c->user_commands = NULL;
c906108c 252 c->cmd_pointer = NULL;
b05dcbb7 253 c->alias_chain = NULL;
c906108c
SS
254
255 return c;
256}
257
56382845 258/* Deprecates a command CMD.
ebcd3b23
MS
259 REPLACEMENT is the name of the command which should be used in
260 place of this command, or NULL if no such command exists.
56382845
FN
261
262 This function does not check to see if command REPLACEMENT exists
ebcd3b23
MS
263 since gdb may not have gotten around to adding REPLACEMENT when
264 this function is called.
56382845
FN
265
266 Returns a pointer to the deprecated command. */
267
268struct cmd_list_element *
fba45db2 269deprecate_cmd (struct cmd_list_element *cmd, char *replacement)
56382845
FN
270{
271 cmd->flags |= (CMD_DEPRECATED | DEPRECATED_WARN_USER);
272
273 if (replacement != NULL)
274 cmd->replacement = replacement;
275 else
276 cmd->replacement = NULL;
277
278 return cmd;
279}
280
c906108c 281struct cmd_list_element *
fba45db2
KB
282add_alias_cmd (char *name, char *oldname, enum command_class class,
283 int abbrev_flag, struct cmd_list_element **list)
c906108c 284{
ebcd3b23
MS
285 /* Must do this since lookup_cmd tries to side-effect its first
286 arg. */
c906108c 287 char *copied_name;
d5b5ac79
AC
288 struct cmd_list_element *old;
289 struct cmd_list_element *c;
cdb27c12 290
c906108c
SS
291 copied_name = (char *) alloca (strlen (oldname) + 1);
292 strcpy (copied_name, oldname);
c5aa993b 293 old = lookup_cmd (&copied_name, *list, "", 1, 1);
c906108c
SS
294
295 if (old == 0)
296 {
fad6eecd
TT
297 struct cmd_list_element *prehook, *prehookee, *posthook, *posthookee;
298 struct cmd_list_element *aliases = delete_cmd (name, list,
299 &prehook, &prehookee,
300 &posthook, &posthookee);
cdb27c12 301
b05dcbb7 302 /* If this happens, it means a programmer error somewhere. */
300d0284 303 gdb_assert (!aliases && !prehook && !prehookee
fad6eecd 304 && !posthook && ! posthookee);
c906108c
SS
305 return 0;
306 }
307
9f60d481 308 c = add_cmd (name, class, NULL, old->doc, list);
5bc81a00
PM
309
310 /* If OLD->DOC can be freed, we should make another copy. */
311 if ((old->flags & DOC_ALLOCATED) != 0)
312 {
313 c->doc = xstrdup (old->doc);
314 c->flags |= DOC_ALLOCATED;
315 }
9f60d481
AC
316 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
317 c->func = old->func;
318 c->function = old->function;
c906108c
SS
319 c->prefixlist = old->prefixlist;
320 c->prefixname = old->prefixname;
321 c->allow_unknown = old->allow_unknown;
322 c->abbrev_flag = abbrev_flag;
323 c->cmd_pointer = old;
b05dcbb7
TT
324 c->alias_chain = old->aliases;
325 old->aliases = c;
5b9afe8a
YQ
326
327 set_cmd_prefix (c, list);
c906108c
SS
328 return c;
329}
330
ebcd3b23
MS
331/* Like add_cmd but adds an element for a command prefix: a name that
332 should be followed by a subcommand to be looked up in another
333 command list. PREFIXLIST should be the address of the variable
334 containing that list. */
c906108c
SS
335
336struct cmd_list_element *
9a2b4c1b
MS
337add_prefix_cmd (char *name, enum command_class class,
338 void (*fun) (char *, int),
af1c1752
KB
339 char *doc, struct cmd_list_element **prefixlist,
340 char *prefixname, int allow_unknown,
341 struct cmd_list_element **list)
c906108c 342{
d5b5ac79 343 struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
5b9afe8a 344 struct cmd_list_element *p;
cdb27c12 345
c906108c
SS
346 c->prefixlist = prefixlist;
347 c->prefixname = prefixname;
348 c->allow_unknown = allow_unknown;
5b9afe8a
YQ
349
350 if (list == &cmdlist)
351 c->prefix = NULL;
352 else
353 set_cmd_prefix (c, list);
354
355 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
356 for (p = *prefixlist; p != NULL; p = p->next)
357 p->prefix = c;
358
c906108c
SS
359 return c;
360}
361
ebcd3b23 362/* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
c5aa993b 363
c906108c 364struct cmd_list_element *
af1c1752
KB
365add_abbrev_prefix_cmd (char *name, enum command_class class,
366 void (*fun) (char *, int), char *doc,
367 struct cmd_list_element **prefixlist, char *prefixname,
368 int allow_unknown, struct cmd_list_element **list)
c906108c 369{
d5b5ac79 370 struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
cdb27c12 371
c906108c
SS
372 c->prefixlist = prefixlist;
373 c->prefixname = prefixname;
374 c->allow_unknown = allow_unknown;
375 c->abbrev_flag = 1;
376 return c;
377}
378
379/* This is an empty "cfunc". */
380void
fba45db2 381not_just_help_class_command (char *args, int from_tty)
c906108c
SS
382{
383}
384
385/* This is an empty "sfunc". */
a14ed312 386static void empty_sfunc (char *, int, struct cmd_list_element *);
c906108c
SS
387
388static void
fba45db2 389empty_sfunc (char *args, int from_tty, struct cmd_list_element *c)
c906108c
SS
390{
391}
392
b2875cc0 393/* Add element named NAME to command list LIST (the list for set/show
c906108c 394 or some sublist thereof).
b2875cc0 395 TYPE is set_cmd or show_cmd.
c906108c
SS
396 CLASS is as in add_cmd.
397 VAR_TYPE is the kind of thing we are setting.
398 VAR is address of the variable being controlled by this command.
399 DOC is the documentation string. */
400
b2875cc0
AC
401static struct cmd_list_element *
402add_set_or_show_cmd (char *name,
403 enum cmd_types type,
404 enum command_class class,
405 var_types var_type,
406 void *var,
407 char *doc,
408 struct cmd_list_element **list)
c906108c 409{
e00d1dc8 410 struct cmd_list_element *c = add_cmd (name, class, NULL, doc, list);
cdb27c12 411
b2875cc0
AC
412 gdb_assert (type == set_cmd || type == show_cmd);
413 c->type = type;
c906108c
SS
414 c->var_type = var_type;
415 c->var = var;
e00d1dc8 416 /* This needs to be something besides NULL so that this isn't
c906108c 417 treated as a help class. */
9f60d481 418 set_cmd_sfunc (c, empty_sfunc);
c906108c
SS
419 return c;
420}
421
e707bbc2
AC
422/* Add element named NAME to both the command SET_LIST and SHOW_LIST.
423 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
424 setting. VAR is address of the variable being controlled by this
425 command. SET_FUNC and SHOW_FUNC are the callback functions (if
3b64bf98
AC
426 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
427 strings. PRINT the format string to print the value. SET_RESULT
428 and SHOW_RESULT, if not NULL, are set to the resulting command
429 structures. */
e707bbc2 430
b3f42336 431static void
9f064c95
TT
432add_setshow_cmd_full (char *name,
433 enum command_class class,
434 var_types var_type, void *var,
3b64bf98 435 const char *set_doc, const char *show_doc,
335cca0d 436 const char *help_doc,
3b64bf98 437 cmd_sfunc_ftype *set_func,
08546159 438 show_value_ftype *show_func,
9f064c95
TT
439 struct cmd_list_element **set_list,
440 struct cmd_list_element **show_list,
441 struct cmd_list_element **set_result,
442 struct cmd_list_element **show_result)
e707bbc2
AC
443{
444 struct cmd_list_element *set;
445 struct cmd_list_element *show;
be7d7357
AC
446 char *full_set_doc;
447 char *full_show_doc;
448
449 if (help_doc != NULL)
450 {
451 full_set_doc = xstrprintf ("%s\n%s", set_doc, help_doc);
452 full_show_doc = xstrprintf ("%s\n%s", show_doc, help_doc);
453 }
454 else
455 {
456 full_set_doc = xstrdup (set_doc);
457 full_show_doc = xstrdup (show_doc);
458 }
e707bbc2 459 set = add_set_or_show_cmd (name, set_cmd, class, var_type, var,
3b64bf98 460 full_set_doc, set_list);
5bc81a00
PM
461 set->flags |= DOC_ALLOCATED;
462
e707bbc2
AC
463 if (set_func != NULL)
464 set_cmd_sfunc (set, set_func);
5b9afe8a
YQ
465
466 set_cmd_prefix (set, set_list);
467
e707bbc2 468 show = add_set_or_show_cmd (name, show_cmd, class, var_type, var,
3b64bf98 469 full_show_doc, show_list);
5bc81a00 470 show->flags |= DOC_ALLOCATED;
08546159 471 show->show_value_func = show_func;
9f064c95
TT
472
473 if (set_result != NULL)
474 *set_result = set;
475 if (show_result != NULL)
476 *show_result = show;
477}
478
1b295c3d
AC
479/* Add element named NAME to command list LIST (the list for set or
480 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
481 of strings which may follow NAME. VAR is address of the variable
482 which will contain the matching string (from ENUMLIST). */
483
484void
485add_setshow_enum_cmd (char *name,
486 enum command_class class,
40478521 487 const char *const *enumlist,
1b295c3d
AC
488 const char **var,
489 const char *set_doc,
490 const char *show_doc,
491 const char *help_doc,
1b295c3d 492 cmd_sfunc_ftype *set_func,
08546159 493 show_value_ftype *show_func,
1b295c3d 494 struct cmd_list_element **set_list,
7376b4c2 495 struct cmd_list_element **show_list)
1b295c3d
AC
496{
497 struct cmd_list_element *c;
cdb27c12 498
1b295c3d 499 add_setshow_cmd_full (name, class, var_enum, var,
335cca0d 500 set_doc, show_doc, help_doc,
1b295c3d
AC
501 set_func, show_func,
502 set_list, show_list,
7376b4c2 503 &c, NULL);
1b295c3d
AC
504 c->enums = enumlist;
505}
506
5b9afe8a
YQ
507const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL };
508
e9e68a56
AC
509/* Add an auto-boolean command named NAME to both the set and show
510 command list lists. CLASS is as in add_cmd. VAR is address of the
511 variable which will contain the value. DOC is the documentation
512 string. FUNC is the corresponding callback. */
513void
514add_setshow_auto_boolean_cmd (char *name,
515 enum command_class class,
516 enum auto_boolean *var,
3b64bf98 517 const char *set_doc, const char *show_doc,
335cca0d 518 const char *help_doc,
e9e68a56 519 cmd_sfunc_ftype *set_func,
08546159 520 show_value_ftype *show_func,
e9e68a56
AC
521 struct cmd_list_element **set_list,
522 struct cmd_list_element **show_list)
97c3646f 523{
97c3646f 524 struct cmd_list_element *c;
cdb27c12 525
9f064c95 526 add_setshow_cmd_full (name, class, var_auto_boolean, var,
2c5b56ce 527 set_doc, show_doc, help_doc,
3b64bf98 528 set_func, show_func,
9f064c95
TT
529 set_list, show_list,
530 &c, NULL);
97c3646f 531 c->enums = auto_boolean_enums;
97c3646f
AC
532}
533
e707bbc2
AC
534/* Add element named NAME to both the set and show command LISTs (the
535 list for set/show or some sublist thereof). CLASS is as in
536 add_cmd. VAR is address of the variable which will contain the
ba3e8e46 537 value. SET_DOC and SHOW_DOC are the documentation strings. */
e707bbc2 538void
3b64bf98
AC
539add_setshow_boolean_cmd (char *name, enum command_class class, int *var,
540 const char *set_doc, const char *show_doc,
335cca0d 541 const char *help_doc,
e707bbc2 542 cmd_sfunc_ftype *set_func,
08546159 543 show_value_ftype *show_func,
e707bbc2
AC
544 struct cmd_list_element **set_list,
545 struct cmd_list_element **show_list)
f3796e26
AC
546{
547 static const char *boolean_enums[] = { "on", "off", NULL };
548 struct cmd_list_element *c;
cdb27c12 549
9f064c95 550 add_setshow_cmd_full (name, class, var_boolean, var,
2c5b56ce 551 set_doc, show_doc, help_doc,
9f064c95
TT
552 set_func, show_func,
553 set_list, show_list,
554 &c, NULL);
f3796e26 555 c->enums = boolean_enums;
f3796e26
AC
556}
557
b3f42336
AC
558/* Add element named NAME to both the set and show command LISTs (the
559 list for set/show or some sublist thereof). */
560void
561add_setshow_filename_cmd (char *name, enum command_class class,
562 char **var,
563 const char *set_doc, const char *show_doc,
335cca0d 564 const char *help_doc,
b3f42336 565 cmd_sfunc_ftype *set_func,
08546159 566 show_value_ftype *show_func,
b3f42336
AC
567 struct cmd_list_element **set_list,
568 struct cmd_list_element **show_list)
569{
f397e303 570 struct cmd_list_element *set_result;
cdb27c12 571
b3f42336 572 add_setshow_cmd_full (name, class, var_filename, var,
2c5b56ce 573 set_doc, show_doc, help_doc,
b3f42336
AC
574 set_func, show_func,
575 set_list, show_list,
f397e303
AC
576 &set_result, NULL);
577 set_cmd_completer (set_result, filename_completer);
b3f42336
AC
578}
579
580/* Add element named NAME to both the set and show command LISTs (the
5efd5804
PA
581 list for set/show or some sublist thereof). */
582void
b3f42336 583add_setshow_string_cmd (char *name, enum command_class class,
6df3bc68
MS
584 char **var,
585 const char *set_doc, const char *show_doc,
586 const char *help_doc,
587 cmd_sfunc_ftype *set_func,
588 show_value_ftype *show_func,
589 struct cmd_list_element **set_list,
590 struct cmd_list_element **show_list)
b3f42336
AC
591{
592 add_setshow_cmd_full (name, class, var_string, var,
2c5b56ce 593 set_doc, show_doc, help_doc,
b3f42336
AC
594 set_func, show_func,
595 set_list, show_list,
5efd5804 596 NULL, NULL);
b3f42336
AC
597}
598
26c41df3 599/* Add element named NAME to both the set and show command LISTs (the
5efd5804
PA
600 list for set/show or some sublist thereof). */
601void
26c41df3
AC
602add_setshow_string_noescape_cmd (char *name, enum command_class class,
603 char **var,
604 const char *set_doc, const char *show_doc,
605 const char *help_doc,
606 cmd_sfunc_ftype *set_func,
607 show_value_ftype *show_func,
608 struct cmd_list_element **set_list,
609 struct cmd_list_element **show_list)
610{
611 add_setshow_cmd_full (name, class, var_string_noescape, var,
612 set_doc, show_doc, help_doc,
613 set_func, show_func,
614 set_list, show_list,
5efd5804 615 NULL, NULL);
26c41df3
AC
616}
617
b4b4ac0b
AC
618/* Add element named NAME to both the set and show command LISTs (the
619 list for set/show or some sublist thereof). */
620void
621add_setshow_optional_filename_cmd (char *name, enum command_class class,
622 char **var,
623 const char *set_doc, const char *show_doc,
624 const char *help_doc,
625 cmd_sfunc_ftype *set_func,
626 show_value_ftype *show_func,
627 struct cmd_list_element **set_list,
628 struct cmd_list_element **show_list)
629{
7f6a6314
PM
630 struct cmd_list_element *set_result;
631
b4b4ac0b
AC
632 add_setshow_cmd_full (name, class, var_optional_filename, var,
633 set_doc, show_doc, help_doc,
634 set_func, show_func,
635 set_list, show_list,
7f6a6314
PM
636 &set_result, NULL);
637
638 set_cmd_completer (set_result, filename_completer);
639
b4b4ac0b
AC
640}
641
c0d88b1b
AC
642/* Add element named NAME to both the set and show command LISTs (the
643 list for set/show or some sublist thereof). CLASS is as in
644 add_cmd. VAR is address of the variable which will contain the
6fc1c773
YQ
645 value. SET_DOC and SHOW_DOC are the documentation strings. This
646 function is only used in Python API. Please don't use it elsewhere. */
5efd5804 647void
c0d88b1b 648add_setshow_integer_cmd (char *name, enum command_class class,
47b667de 649 int *var,
6df3bc68
MS
650 const char *set_doc, const char *show_doc,
651 const char *help_doc,
652 cmd_sfunc_ftype *set_func,
653 show_value_ftype *show_func,
654 struct cmd_list_element **set_list,
655 struct cmd_list_element **show_list)
c0d88b1b
AC
656{
657 add_setshow_cmd_full (name, class, var_integer, var,
658 set_doc, show_doc, help_doc,
659 set_func, show_func,
660 set_list, show_list,
5efd5804 661 NULL, NULL);
c0d88b1b
AC
662}
663
25d29d70
AC
664/* Add element named NAME to both the set and show command LISTs (the
665 list for set/show or some sublist thereof). CLASS is as in
666 add_cmd. VAR is address of the variable which will contain the
5efd5804
PA
667 value. SET_DOC and SHOW_DOC are the documentation strings. */
668void
3b64bf98
AC
669add_setshow_uinteger_cmd (char *name, enum command_class class,
670 unsigned int *var,
671 const char *set_doc, const char *show_doc,
335cca0d 672 const char *help_doc,
25d29d70 673 cmd_sfunc_ftype *set_func,
08546159 674 show_value_ftype *show_func,
25d29d70
AC
675 struct cmd_list_element **set_list,
676 struct cmd_list_element **show_list)
677{
678 add_setshow_cmd_full (name, class, var_uinteger, var,
2c5b56ce 679 set_doc, show_doc, help_doc,
25d29d70
AC
680 set_func, show_func,
681 set_list, show_list,
5efd5804 682 NULL, NULL);
25d29d70
AC
683}
684
15170568
AC
685/* Add element named NAME to both the set and show command LISTs (the
686 list for set/show or some sublist thereof). CLASS is as in
687 add_cmd. VAR is address of the variable which will contain the
5efd5804
PA
688 value. SET_DOC and SHOW_DOC are the documentation strings. */
689void
3b64bf98
AC
690add_setshow_zinteger_cmd (char *name, enum command_class class,
691 int *var,
692 const char *set_doc, const char *show_doc,
335cca0d 693 const char *help_doc,
15170568 694 cmd_sfunc_ftype *set_func,
08546159 695 show_value_ftype *show_func,
15170568
AC
696 struct cmd_list_element **set_list,
697 struct cmd_list_element **show_list)
698{
699 add_setshow_cmd_full (name, class, var_zinteger, var,
2c5b56ce 700 set_doc, show_doc, help_doc,
15170568
AC
701 set_func, show_func,
702 set_list, show_list,
5efd5804 703 NULL, NULL);
15170568
AC
704}
705
6fc1c773
YQ
706void
707add_setshow_zuinteger_unlimited_cmd (char *name,
708 enum command_class class,
709 unsigned int *var,
710 const char *set_doc,
711 const char *show_doc,
712 const char *help_doc,
713 cmd_sfunc_ftype *set_func,
714 show_value_ftype *show_func,
715 struct cmd_list_element **set_list,
716 struct cmd_list_element **show_list)
717{
718 add_setshow_cmd_full (name, class, var_zuinteger_unlimited, var,
719 set_doc, show_doc, help_doc,
720 set_func, show_func,
721 set_list, show_list,
722 NULL, NULL);
723}
724
1e8fb976
PA
725/* Add element named NAME to both the set and show command LISTs (the
726 list for set/show or some sublist thereof). CLASS is as in
727 add_cmd. VAR is address of the variable which will contain the
5efd5804
PA
728 value. SET_DOC and SHOW_DOC are the documentation strings. */
729void
1e8fb976
PA
730add_setshow_zuinteger_cmd (char *name, enum command_class class,
731 unsigned int *var,
732 const char *set_doc, const char *show_doc,
733 const char *help_doc,
734 cmd_sfunc_ftype *set_func,
735 show_value_ftype *show_func,
736 struct cmd_list_element **set_list,
737 struct cmd_list_element **show_list)
738{
739 add_setshow_cmd_full (name, class, var_zuinteger, var,
740 set_doc, show_doc, help_doc,
741 set_func, show_func,
742 set_list, show_list,
5efd5804 743 NULL, NULL);
1e8fb976
PA
744}
745
b05dcbb7
TT
746/* Remove the command named NAME from the command list. Return the
747 list commands which were aliased to the deleted command. If the
fad6eecd
TT
748 command had no aliases, return NULL. The various *HOOKs are set to
749 the pre- and post-hook commands for the deleted command. If the
750 command does not have a hook, the corresponding out parameter is
751 set to NULL. */
c906108c 752
b05dcbb7 753static struct cmd_list_element *
fad6eecd
TT
754delete_cmd (char *name, struct cmd_list_element **list,
755 struct cmd_list_element **prehook,
756 struct cmd_list_element **prehookee,
757 struct cmd_list_element **posthook,
758 struct cmd_list_element **posthookee)
c906108c 759{
b05dcbb7
TT
760 struct cmd_list_element *iter;
761 struct cmd_list_element **previous_chain_ptr;
762 struct cmd_list_element *aliases = NULL;
c906108c 763
fad6eecd
TT
764 *prehook = NULL;
765 *prehookee = NULL;
766 *posthook = NULL;
767 *posthookee = NULL;
b05dcbb7
TT
768 previous_chain_ptr = list;
769
770 for (iter = *previous_chain_ptr; iter; iter = *previous_chain_ptr)
c906108c 771 {
b05dcbb7
TT
772 if (strcmp (iter->name, name) == 0)
773 {
d8906c6f
TJB
774 if (iter->destroyer)
775 iter->destroyer (iter, iter->context);
b05dcbb7
TT
776 if (iter->hookee_pre)
777 iter->hookee_pre->hook_pre = 0;
fad6eecd
TT
778 *prehook = iter->hook_pre;
779 *prehookee = iter->hookee_pre;
b05dcbb7
TT
780 if (iter->hookee_post)
781 iter->hookee_post->hook_post = 0;
5bc81a00
PM
782 if (iter->doc && (iter->flags & DOC_ALLOCATED) != 0)
783 xfree (iter->doc);
fad6eecd
TT
784 *posthook = iter->hook_post;
785 *posthookee = iter->hookee_post;
b05dcbb7
TT
786
787 /* Update the link. */
788 *previous_chain_ptr = iter->next;
789
790 aliases = iter->aliases;
791
792 /* If this command was an alias, remove it from the list of
793 aliases. */
794 if (iter->cmd_pointer)
795 {
796 struct cmd_list_element **prevp = &iter->cmd_pointer->aliases;
797 struct cmd_list_element *a = *prevp;
798
799 while (a != iter)
800 {
801 prevp = &a->alias_chain;
802 a = *prevp;
803 }
804 *prevp = iter->alias_chain;
805 }
806
807 xfree (iter);
808
809 /* We won't see another command with the same name. */
810 break;
811 }
812 else
813 previous_chain_ptr = &iter->next;
c906108c
SS
814 }
815
b05dcbb7 816 return aliases;
c906108c 817}
d318976c 818\f
ebcd3b23 819/* Shorthands to the commands above. */
d318976c
FN
820
821/* Add an element to the list of info subcommands. */
822
823struct cmd_list_element *
824add_info (char *name, void (*fun) (char *, int), char *doc)
825{
826 return add_cmd (name, no_class, fun, doc, &infolist);
827}
828
829/* Add an alias to the list of info subcommands. */
830
831struct cmd_list_element *
832add_info_alias (char *name, char *oldname, int abbrev_flag)
833{
834 return add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
835}
836
837/* Add an element to the list of commands. */
838
839struct cmd_list_element *
840add_com (char *name, enum command_class class, void (*fun) (char *, int),
841 char *doc)
842{
843 return add_cmd (name, class, fun, doc, &cmdlist);
844}
845
846/* Add an alias or abbreviation command to the list of commands. */
847
848struct cmd_list_element *
849add_com_alias (char *name, char *oldname, enum command_class class,
850 int abbrev_flag)
851{
852 return add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
853}
854\f
6837a0a2
DB
855/* Recursively walk the commandlist structures, and print out the
856 documentation of commands that match our regex in either their
857 name, or their documentation.
858*/
d318976c 859void
ebcd3b23
MS
860apropos_cmd (struct ui_file *stream,
861 struct cmd_list_element *commandlist,
cdb27c12 862 struct re_pattern_buffer *regex, char *prefix)
6837a0a2 863{
d5b5ac79 864 struct cmd_list_element *c;
4a98be19 865 int returnvalue;
cdb27c12 866
ebcd3b23 867 /* Walk through the commands. */
6837a0a2
DB
868 for (c=commandlist;c;c=c->next)
869 {
ebcd3b23 870 returnvalue = -1; /* Needed to avoid double printing. */
6837a0a2
DB
871 if (c->name != NULL)
872 {
ebcd3b23 873 /* Try to match against the name. */
cdb27c12
MS
874 returnvalue = re_search (regex, c->name, strlen(c->name),
875 0, strlen (c->name), NULL);
6837a0a2
DB
876 if (returnvalue >= 0)
877 {
6e381ba0
VP
878 print_help_for_command (c, prefix,
879 0 /* don't recurse */, stream);
6837a0a2
DB
880 }
881 }
4a98be19 882 if (c->doc != NULL && returnvalue < 0)
6837a0a2 883 {
ebcd3b23 884 /* Try to match against documentation. */
6837a0a2
DB
885 if (re_search(regex,c->doc,strlen(c->doc),0,strlen(c->doc),NULL) >=0)
886 {
6e381ba0
VP
887 print_help_for_command (c, prefix,
888 0 /* don't recurse */, stream);
6837a0a2
DB
889 }
890 }
ebcd3b23
MS
891 /* Check if this command has subcommands and is not an
892 abbreviation. We skip listing subcommands of abbreviations
893 in order to avoid duplicates in the output. */
5d2c29b8 894 if (c->prefixlist != NULL && !c->abbrev_flag)
6837a0a2
DB
895 {
896 /* Recursively call ourselves on the subcommand list,
ebcd3b23 897 passing the right prefix in. */
d318976c 898 apropos_cmd (stream,*c->prefixlist,regex,c->prefixname);
6837a0a2
DB
899 }
900 }
901}
c906108c
SS
902
903/* This command really has to deal with two things:
ebcd3b23
MS
904 1) I want documentation on *this string* (usually called by
905 "help commandname").
906
907 2) I want documentation on *this list* (usually called by giving a
908 command that requires subcommands. Also called by saying just
909 "help".)
910
911 I am going to split this into two seperate comamnds, help_cmd and
912 help_list. */
c906108c
SS
913
914void
fba45db2 915help_cmd (char *command, struct ui_file *stream)
c906108c
SS
916{
917 struct cmd_list_element *c;
918 extern struct cmd_list_element *cmdlist;
919
920 if (!command)
921 {
922 help_list (cmdlist, "", all_classes, stream);
923 return;
924 }
925
49a5a3a3
GM
926 if (strcmp (command, "all") == 0)
927 {
928 help_all (stream);
929 return;
930 }
931
c906108c
SS
932 c = lookup_cmd (&command, cmdlist, "", 0, 0);
933
934 if (c == 0)
935 return;
936
937 /* There are three cases here.
938 If c->prefixlist is nonzero, we have a prefix command.
939 Print its documentation, then list its subcommands.
c5aa993b 940
9f60d481
AC
941 If c->func is non NULL, we really have a command. Print its
942 documentation and return.
c5aa993b 943
9f60d481
AC
944 If c->func is NULL, we have a class name. Print its
945 documentation (as if it were a command) and then set class to the
946 number of this class so that the commands in the class will be
947 listed. */
c906108c
SS
948
949 fputs_filtered (c->doc, stream);
950 fputs_filtered ("\n", stream);
951
9f60d481 952 if (c->prefixlist == 0 && c->func != NULL)
c906108c
SS
953 return;
954 fprintf_filtered (stream, "\n");
955
ebcd3b23 956 /* If this is a prefix command, print it's subcommands. */
c906108c
SS
957 if (c->prefixlist)
958 help_list (*c->prefixlist, c->prefixname, all_commands, stream);
959
ebcd3b23 960 /* If this is a class name, print all of the commands in the class. */
9f60d481 961 if (c->func == NULL)
c906108c
SS
962 help_list (cmdlist, "", c->class, stream);
963
73bc900d
FN
964 if (c->hook_pre || c->hook_post)
965 fprintf_filtered (stream,
966 "\nThis command has a hook (or hooks) defined:\n");
967
968 if (c->hook_pre)
327529e9 969 fprintf_filtered (stream,
72fe0832 970 "\tThis command is run after : %s (pre hook)\n",
73bc900d
FN
971 c->hook_pre->name);
972 if (c->hook_post)
327529e9 973 fprintf_filtered (stream,
72fe0832 974 "\tThis command is run before : %s (post hook)\n",
73bc900d 975 c->hook_post->name);
c906108c
SS
976}
977
978/*
979 * Get a specific kind of help on a command list.
980 *
981 * LIST is the list.
982 * CMDTYPE is the prefix to use in the title string.
983 * CLASS is the class with which to list the nodes of this list (see
984 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
985 * everything, ALL_CLASSES for just classes, and non-negative for only things
986 * in a specific class.
987 * and STREAM is the output stream on which to print things.
988 * If you call this routine with a class >= 0, it recurses.
989 */
990void
fba45db2
KB
991help_list (struct cmd_list_element *list, char *cmdtype,
992 enum command_class class, struct ui_file *stream)
c906108c
SS
993{
994 int len;
995 char *cmdtype1, *cmdtype2;
c5aa993b 996
ebcd3b23
MS
997 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
998 */
c906108c
SS
999 len = strlen (cmdtype);
1000 cmdtype1 = (char *) alloca (len + 1);
1001 cmdtype1[0] = 0;
1002 cmdtype2 = (char *) alloca (len + 4);
1003 cmdtype2[0] = 0;
1004 if (len)
1005 {
1006 cmdtype1[0] = ' ';
1007 strncpy (cmdtype1 + 1, cmdtype, len - 1);
1008 cmdtype1[len] = 0;
1009 strncpy (cmdtype2, cmdtype, len - 1);
1010 strcpy (cmdtype2 + len - 1, " sub");
1011 }
1012
1013 if (class == all_classes)
1014 fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2);
1015 else
1016 fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2);
1017
c5aa993b 1018 help_cmd_list (list, class, cmdtype, (int) class >= 0, stream);
c906108c
SS
1019
1020 if (class == all_classes)
de74f71f
MS
1021 {
1022 fprintf_filtered (stream, "\n\
1023Type \"help%s\" followed by a class name for a list of commands in ",
1024 cmdtype1);
1025 wrap_here ("");
1026 fprintf_filtered (stream, "that class.");
6e381ba0
VP
1027
1028 fprintf_filtered (stream, "\n\
1029Type \"help all\" for the list of all commands.");
de74f71f 1030 }
c906108c 1031
de74f71f 1032 fprintf_filtered (stream, "\nType \"help%s\" followed by %scommand name ",
c5aa993b 1033 cmdtype1, cmdtype2);
de74f71f
MS
1034 wrap_here ("");
1035 fputs_filtered ("for ", stream);
1036 wrap_here ("");
1037 fputs_filtered ("full ", stream);
1038 wrap_here ("");
1039 fputs_filtered ("documentation.\n", stream);
6e381ba0 1040 fputs_filtered ("Type \"apropos word\" to search "
ebcd3b23 1041 "for commands related to \"word\".\n", stream);
de74f71f
MS
1042 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1043 stream);
c906108c 1044}
c5aa993b 1045
49a5a3a3 1046static void
c85871a3 1047help_all (struct ui_file *stream)
49a5a3a3
GM
1048{
1049 struct cmd_list_element *c;
1050 extern struct cmd_list_element *cmdlist;
6e381ba0 1051 int seen_unclassified = 0;
49a5a3a3
GM
1052
1053 for (c = cmdlist; c; c = c->next)
1054 {
1055 if (c->abbrev_flag)
1056 continue;
ebcd3b23
MS
1057 /* If this is a class name, print all of the commands in the
1058 class. */
6e381ba0
VP
1059
1060 if (c->func == NULL)
1061 {
1062 fprintf_filtered (stream, "\nCommand class: %s\n\n", c->name);
1063 help_cmd_list (cmdlist, c->class, "", 1, stream);
1064 }
49a5a3a3 1065 }
6e381ba0
VP
1066
1067 /* While it's expected that all commands are in some class,
1068 as a safety measure, we'll print commands outside of any
1069 class at the end. */
1070
1071 for (c = cmdlist; c; c = c->next)
1072 {
1073 if (c->abbrev_flag)
1074 continue;
1075
1076 if (c->class == no_class)
1077 {
1078 if (!seen_unclassified)
1079 {
1080 fprintf_filtered (stream, "\nUnclassified commands\n\n");
1081 seen_unclassified = 1;
1082 }
1083 print_help_for_command (c, "", 1, stream);
1084 }
1085 }
1086
49a5a3a3
GM
1087}
1088
c906108c 1089/* Print only the first line of STR on STREAM. */
d318976c 1090void
fba45db2 1091print_doc_line (struct ui_file *stream, char *str)
c906108c
SS
1092{
1093 static char *line_buffer = 0;
1094 static int line_size;
d5b5ac79 1095 char *p;
c906108c
SS
1096
1097 if (!line_buffer)
1098 {
1099 line_size = 80;
1100 line_buffer = (char *) xmalloc (line_size);
1101 }
1102
7afa1642
JK
1103 /* Keep printing '.' or ',' not followed by a whitespace for embedded strings
1104 like '.gdbinit'. */
c906108c 1105 p = str;
7afa1642
JK
1106 while (*p && *p != '\n'
1107 && ((*p != '.' && *p != ',') || (p[1] && !isspace (p[1]))))
c906108c
SS
1108 p++;
1109 if (p - str > line_size - 1)
1110 {
1111 line_size = p - str + 1;
b8c9b27d 1112 xfree (line_buffer);
c906108c
SS
1113 line_buffer = (char *) xmalloc (line_size);
1114 }
1115 strncpy (line_buffer, str, p - str);
1116 line_buffer[p - str] = '\0';
1117 if (islower (line_buffer[0]))
1118 line_buffer[0] = toupper (line_buffer[0]);
b6201d44 1119 fputs_filtered (line_buffer, stream);
c906108c
SS
1120}
1121
6e381ba0
VP
1122/* Print one-line help for command C.
1123 If RECURSE is non-zero, also print one-line descriptions
ebcd3b23 1124 of all prefixed subcommands. */
6e381ba0
VP
1125static void
1126print_help_for_command (struct cmd_list_element *c, char *prefix, int recurse,
1127 struct ui_file *stream)
1128{
1129 fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
1130 print_doc_line (stream, c->doc);
1131 fputs_filtered ("\n", stream);
1132
1133 if (recurse
1134 && c->prefixlist != 0
1135 && c->abbrev_flag == 0)
1136 /* Subcommands of a prefix command typically have 'all_commands'
1137 as class. If we pass CLASS to recursive invocation,
ebcd3b23 1138 most often we won't see anything. */
6e381ba0
VP
1139 help_cmd_list (*c->prefixlist, all_commands, c->prefixname, 1, stream);
1140}
1141
c906108c
SS
1142/*
1143 * Implement a help command on command list LIST.
1144 * RECURSE should be non-zero if this should be done recursively on
1145 * all sublists of LIST.
1146 * PREFIX is the prefix to print before each command name.
1147 * STREAM is the stream upon which the output should be written.
1148 * CLASS should be:
c5aa993b 1149 * A non-negative class number to list only commands in that
c906108c 1150 * class.
c5aa993b
JM
1151 * ALL_COMMANDS to list all commands in list.
1152 * ALL_CLASSES to list all classes in list.
c906108c
SS
1153 *
1154 * Note that RECURSE will be active on *all* sublists, not just the
1155 * ones selected by the criteria above (ie. the selection mechanism
1156 * is at the low level, not the high-level).
1157 */
1158void
fba45db2
KB
1159help_cmd_list (struct cmd_list_element *list, enum command_class class,
1160 char *prefix, int recurse, struct ui_file *stream)
c906108c 1161{
d5b5ac79 1162 struct cmd_list_element *c;
c906108c
SS
1163
1164 for (c = list; c; c = c->next)
6e381ba0 1165 {
5aafa1cc
PM
1166 if (c->abbrev_flag == 0
1167 && (class == all_commands
1168 || (class == all_classes && c->func == NULL)
1169 || (class == c->class && c->func != NULL)))
c906108c 1170 {
6e381ba0 1171 print_help_for_command (c, prefix, recurse, stream);
c906108c 1172 }
adb483fe
DJ
1173 else if (c->abbrev_flag == 0 && recurse
1174 && class == class_user && c->prefixlist != NULL)
1175 /* User-defined commands may be subcommands. */
ebcd3b23
MS
1176 help_cmd_list (*c->prefixlist, class, c->prefixname,
1177 recurse, stream);
c906108c
SS
1178 }
1179}
c906108c 1180\f
c5aa993b 1181
c906108c
SS
1182/* Search the input clist for 'command'. Return the command if
1183 found (or NULL if not), and return the number of commands
ebcd3b23 1184 found in nfound. */
c906108c
SS
1185
1186static struct cmd_list_element *
fba45db2
KB
1187find_cmd (char *command, int len, struct cmd_list_element *clist,
1188 int ignore_help_classes, int *nfound)
c906108c
SS
1189{
1190 struct cmd_list_element *found, *c;
1191
c5aa993b 1192 found = (struct cmd_list_element *) NULL;
c906108c
SS
1193 *nfound = 0;
1194 for (c = clist; c; c = c->next)
1195 if (!strncmp (command, c->name, len)
9f60d481 1196 && (!ignore_help_classes || c->func))
c906108c 1197 {
c5aa993b
JM
1198 found = c;
1199 (*nfound)++;
1200 if (c->name[len] == '\0')
1201 {
1202 *nfound = 1;
1203 break;
1204 }
c906108c
SS
1205 }
1206 return found;
1207}
1208
3386243e
AS
1209static int
1210find_command_name_length (const char *text)
1211{
1212 const char *p = text;
1213
1214 /* Treating underscores as part of command words is important
1215 so that "set args_foo()" doesn't get interpreted as
1216 "set args _foo()". */
ebcd3b23
MS
1217 /* Some characters are only used for TUI specific commands.
1218 However, they are always allowed for the sake of consistency.
1219
1220 The XDB compatibility characters are only allowed when using the
1221 right mode because they clash with other GDB commands -
1222 specifically '/' is used as a suffix for print, examine and
1223 display.
1224
1225 Note that this is larger than the character set allowed when
1226 creating user-defined commands. */
1227
ed59ded5
DE
1228 /* Recognize '!' as a single character command so that, e.g., "!ls"
1229 works as expected. */
1230 if (*p == '!')
1231 return 1;
1232
5aafa1cc 1233 while (isalnum (*p) || *p == '-' || *p == '_'
3386243e 1234 /* Characters used by TUI specific commands. */
5aafa1cc 1235 || *p == '+' || *p == '<' || *p == '>' || *p == '$'
3386243e 1236 /* Characters used for XDB compatibility. */
ed59ded5 1237 || (xdb_commands && (*p == '/' || *p == '?')))
3386243e
AS
1238 p++;
1239
1240 return p - text;
1241}
1242
5a56e9c5
DE
1243/* Return TRUE if NAME is a valid user-defined command name.
1244 This is a stricter subset of all gdb commands,
1245 see find_command_name_length. */
1246
1247int
1248valid_user_defined_cmd_name_p (const char *name)
1249{
1250 const char *p;
1251
1252 if (*name == '\0')
1253 return FALSE;
1254
1255 /* Alas "42" is a legitimate user-defined command.
1256 In the interests of not breaking anything we preserve that. */
1257
1258 for (p = name; *p != '\0'; ++p)
1259 {
1260 if (isalnum (*p)
1261 || *p == '-'
1262 || *p == '_')
1263 ; /* Ok. */
1264 else
1265 return FALSE;
1266 }
1267
1268 return TRUE;
1269}
1270
c906108c
SS
1271/* This routine takes a line of TEXT and a CLIST in which to start the
1272 lookup. When it returns it will have incremented the text pointer past
1273 the section of text it matched, set *RESULT_LIST to point to the list in
1274 which the last word was matched, and will return a pointer to the cmd
1275 list element which the text matches. It will return NULL if no match at
1276 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1277 matches are possible; in this case *RESULT_LIST will be set to point to
1278 the list in which there are ambiguous choices (and *TEXT will be set to
1279 the ambiguous text string).
1280
1281 If the located command was an abbreviation, this routine returns the base
1282 command of the abbreviation.
1283
1284 It does no error reporting whatsoever; control will always return
1285 to the superior routine.
1286
1287 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1288 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1289 if no prefix command was ever found. For example, in the case of "info a",
1290 "info" matches without ambiguity, but "a" could be "args" or "address", so
1291 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1292 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1293 list; it simply points to a specific command. In the case of an ambiguous
1294 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1295 "info t" can be "info types" or "info target"; upon return *TEXT has been
1296 advanced past "info ").
1297
1298 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1299 affect the operation).
1300
1301 This routine does *not* modify the text pointed to by TEXT.
c5aa993b 1302
c906108c
SS
1303 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1304 are actually help classes rather than commands (i.e. the function field of
1305 the struct cmd_list_element is NULL). */
1306
1307struct cmd_list_element *
fba45db2
KB
1308lookup_cmd_1 (char **text, struct cmd_list_element *clist,
1309 struct cmd_list_element **result_list, int ignore_help_classes)
c906108c 1310{
3386243e 1311 char *command;
c906108c
SS
1312 int len, tmp, nfound;
1313 struct cmd_list_element *found, *c;
56382845 1314 char *line = *text;
c906108c
SS
1315
1316 while (**text == ' ' || **text == '\t')
1317 (*text)++;
1318
3386243e
AS
1319 /* Identify the name of the command. */
1320 len = find_command_name_length (*text);
c906108c
SS
1321
1322 /* If nothing but whitespace, return 0. */
3386243e 1323 if (len == 0)
c906108c 1324 return 0;
c5aa993b 1325
c906108c 1326 /* *text and p now bracket the first command word to lookup (and
ebcd3b23 1327 it's length is len). We copy this into a local temporary. */
c906108c
SS
1328
1329
1330 command = (char *) alloca (len + 1);
22ad7fee 1331 memcpy (command, *text, len);
c906108c
SS
1332 command[len] = '\0';
1333
1334 /* Look it up. */
1335 found = 0;
1336 nfound = 0;
c5aa993b 1337 found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
c906108c 1338
ebcd3b23
MS
1339 /* We didn't find the command in the entered case, so lower case it
1340 and search again. */
c906108c
SS
1341 if (!found || nfound == 0)
1342 {
1343 for (tmp = 0; tmp < len; tmp++)
c5aa993b
JM
1344 {
1345 char x = command[tmp];
cdb27c12 1346
c5aa993b
JM
1347 command[tmp] = isupper (x) ? tolower (x) : x;
1348 }
1349 found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
c906108c
SS
1350 }
1351
1352 /* If nothing matches, we have a simple failure. */
1353 if (nfound == 0)
1354 return 0;
1355
1356 if (nfound > 1)
1357 {
1358 if (result_list != NULL)
1359 /* Will be modified in calling routine
1360 if we know what the prefix command is. */
c5aa993b 1361 *result_list = 0;
1427fe5e 1362 return CMD_LIST_AMBIGUOUS; /* Ambiguous. */
c906108c
SS
1363 }
1364
ebcd3b23 1365 /* We've matched something on this list. Move text pointer forward. */
c906108c 1366
3386243e 1367 *text += len;
c906108c 1368
c906108c 1369 if (found->cmd_pointer)
56382845 1370 {
ebcd3b23
MS
1371 /* We drop the alias (abbreviation) in favor of the command it
1372 is pointing to. If the alias is deprecated, though, we need to
56382845
FN
1373 warn the user about it before we drop it. Note that while we
1374 are warning about the alias, we may also warn about the command
1375 itself and we will adjust the appropriate DEPRECATED_WARN_USER
ebcd3b23 1376 flags. */
56382845
FN
1377
1378 if (found->flags & DEPRECATED_WARN_USER)
938f5214 1379 deprecated_cmd_warning (&line);
56382845
FN
1380 found = found->cmd_pointer;
1381 }
c906108c
SS
1382 /* If we found a prefix command, keep looking. */
1383
1384 if (found->prefixlist)
1385 {
1386 c = lookup_cmd_1 (text, *found->prefixlist, result_list,
1387 ignore_help_classes);
1388 if (!c)
1389 {
1390 /* Didn't find anything; this is as far as we got. */
1391 if (result_list != NULL)
1392 *result_list = clist;
1393 return found;
1394 }
1427fe5e 1395 else if (c == CMD_LIST_AMBIGUOUS)
c906108c 1396 {
ebcd3b23
MS
1397 /* We've gotten this far properly, but the next step is
1398 ambiguous. We need to set the result list to the best
c906108c
SS
1399 we've found (if an inferior hasn't already set it). */
1400 if (result_list != NULL)
1401 if (!*result_list)
ebcd3b23 1402 /* This used to say *result_list = *found->prefixlist.
c5aa993b 1403 If that was correct, need to modify the documentation
ebcd3b23
MS
1404 at the top of this function to clarify what is
1405 supposed to be going on. */
c906108c
SS
1406 *result_list = found;
1407 return c;
1408 }
1409 else
1410 {
1411 /* We matched! */
1412 return c;
1413 }
1414 }
1415 else
1416 {
1417 if (result_list != NULL)
1418 *result_list = clist;
1419 return found;
1420 }
1421}
1422
1423/* All this hair to move the space to the front of cmdtype */
1424
1425static void
fba45db2 1426undef_cmd_error (char *cmdtype, char *q)
c906108c 1427{
8a3fe4f8 1428 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
c5aa993b
JM
1429 cmdtype,
1430 q,
1431 *cmdtype ? " " : "",
823ca731 1432 (int) strlen (cmdtype) - 1,
c5aa993b 1433 cmdtype);
c906108c
SS
1434}
1435
1436/* Look up the contents of *LINE as a command in the command list LIST.
1437 LIST is a chain of struct cmd_list_element's.
1438 If it is found, return the struct cmd_list_element for that command
1439 and update *LINE to point after the command name, at the first argument.
1440 If not found, call error if ALLOW_UNKNOWN is zero
1441 otherwise (or if error returns) return zero.
1442 Call error if specified command is ambiguous,
1443 unless ALLOW_UNKNOWN is negative.
1444 CMDTYPE precedes the word "command" in the error message.
1445
1446 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1447 elements which are actually help classes rather than commands (i.e.
1448 the function field of the struct cmd_list_element is 0). */
1449
1450struct cmd_list_element *
fba45db2
KB
1451lookup_cmd (char **line, struct cmd_list_element *list, char *cmdtype,
1452 int allow_unknown, int ignore_help_classes)
c906108c
SS
1453{
1454 struct cmd_list_element *last_list = 0;
3cebf8d8 1455 struct cmd_list_element *c;
c64601c7
FN
1456
1457 /* Note: Do not remove trailing whitespace here because this
1458 would be wrong for complete_command. Jim Kingdon */
c5aa993b 1459
3cebf8d8
MS
1460 if (!*line)
1461 error (_("Lack of needed %scommand"), cmdtype);
1462
1463 c = lookup_cmd_1 (line, list, &last_list, ignore_help_classes);
1464
c906108c
SS
1465 if (!c)
1466 {
1467 if (!allow_unknown)
1468 {
3cebf8d8
MS
1469 char *q;
1470 int len = find_command_name_length (*line);
c906108c 1471
3cebf8d8
MS
1472 q = (char *) alloca (len + 1);
1473 strncpy (q, *line, len);
1474 q[len] = '\0';
1475 undef_cmd_error (cmdtype, q);
c906108c
SS
1476 }
1477 else
1478 return 0;
1479 }
1427fe5e 1480 else if (c == CMD_LIST_AMBIGUOUS)
c906108c
SS
1481 {
1482 /* Ambigous. Local values should be off prefixlist or called
c5aa993b 1483 values. */
c906108c
SS
1484 int local_allow_unknown = (last_list ? last_list->allow_unknown :
1485 allow_unknown);
1486 char *local_cmdtype = last_list ? last_list->prefixname : cmdtype;
1487 struct cmd_list_element *local_list =
cdb27c12 1488 (last_list ? *(last_list->prefixlist) : list);
c5aa993b 1489
c906108c
SS
1490 if (local_allow_unknown < 0)
1491 {
1492 if (last_list)
1493 return last_list; /* Found something. */
1494 else
1495 return 0; /* Found nothing. */
1496 }
1497 else
1498 {
1499 /* Report as error. */
1500 int amb_len;
1501 char ambbuf[100];
1502
1503 for (amb_len = 0;
1504 ((*line)[amb_len] && (*line)[amb_len] != ' '
1505 && (*line)[amb_len] != '\t');
1506 amb_len++)
1507 ;
c5aa993b 1508
c906108c
SS
1509 ambbuf[0] = 0;
1510 for (c = local_list; c; c = c->next)
1511 if (!strncmp (*line, c->name, amb_len))
1512 {
9a2b4c1b
MS
1513 if (strlen (ambbuf) + strlen (c->name) + 6
1514 < (int) sizeof ambbuf)
c906108c
SS
1515 {
1516 if (strlen (ambbuf))
1517 strcat (ambbuf, ", ");
1518 strcat (ambbuf, c->name);
1519 }
1520 else
1521 {
1522 strcat (ambbuf, "..");
1523 break;
1524 }
1525 }
8a3fe4f8 1526 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype,
c906108c
SS
1527 *line, ambbuf);
1528 return 0; /* lint */
1529 }
1530 }
1531 else
1532 {
1533 /* We've got something. It may still not be what the caller
1534 wants (if this command *needs* a subcommand). */
1535 while (**line == ' ' || **line == '\t')
1536 (*line)++;
1537
1538 if (c->prefixlist && **line && !c->allow_unknown)
1539 undef_cmd_error (c->prefixname, *line);
1540
1541 /* Seems to be what he wants. Return it. */
1542 return c;
1543 }
1544 return 0;
1545}
c5aa993b 1546
ebcd3b23
MS
1547/* We are here presumably because an alias or command in *TEXT is
1548 deprecated and a warning message should be generated. This
1549 function decodes *TEXT and potentially generates a warning message
1550 as outlined below.
56382845
FN
1551
1552 Example for 'set endian big' which has a fictitious alias 'seb'.
1553
1554 If alias wasn't used in *TEXT, and the command is deprecated:
1555 "warning: 'set endian big' is deprecated."
1556
1557 If alias was used, and only the alias is deprecated:
1558 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1559
ebcd3b23
MS
1560 If alias was used and command is deprecated (regardless of whether
1561 the alias itself is deprecated:
56382845
FN
1562
1563 "warning: 'set endian big' (seb) is deprecated."
1564
1565 After the message has been sent, clear the appropriate flags in the
1566 command and/or the alias so the user is no longer bothered.
1567
1568*/
1569void
1570deprecated_cmd_warning (char **text)
1571{
1572 struct cmd_list_element *alias = NULL;
1573 struct cmd_list_element *prefix_cmd = NULL;
1574 struct cmd_list_element *cmd = NULL;
edefbb7c 1575
56382845 1576 if (!lookup_cmd_composition (*text, &alias, &prefix_cmd, &cmd))
ebcd3b23 1577 /* Return if text doesn't evaluate to a command. */
56382845
FN
1578 return;
1579
1580 if (!((alias ? (alias->flags & DEPRECATED_WARN_USER) : 0)
1581 || (cmd->flags & DEPRECATED_WARN_USER) ) )
ebcd3b23 1582 /* Return if nothing is deprecated. */
56382845
FN
1583 return;
1584
1585 printf_filtered ("Warning:");
1586
1587 if (alias && !(cmd->flags & CMD_DEPRECATED))
1588 printf_filtered (" '%s', an alias for the", alias->name);
1589
1590 printf_filtered (" command '");
1591
1592 if (prefix_cmd)
1593 printf_filtered ("%s", prefix_cmd->prefixname);
1594
1595 printf_filtered ("%s", cmd->name);
1596
1597 if (alias && (cmd->flags & CMD_DEPRECATED))
1598 printf_filtered ("' (%s) is deprecated.\n", alias->name);
1599 else
1600 printf_filtered ("' is deprecated.\n");
1601
1602
ebcd3b23
MS
1603 /* If it is only the alias that is deprecated, we want to indicate
1604 the new alias, otherwise we'll indicate the new command. */
56382845
FN
1605
1606 if (alias && !(cmd->flags & CMD_DEPRECATED))
1607 {
1608 if (alias->replacement)
cdb27c12 1609 printf_filtered ("Use '%s'.\n\n", alias->replacement);
56382845 1610 else
cdb27c12 1611 printf_filtered ("No alternative known.\n\n");
56382845
FN
1612 }
1613 else
1614 {
1615 if (cmd->replacement)
cdb27c12 1616 printf_filtered ("Use '%s'.\n\n", cmd->replacement);
56382845 1617 else
cdb27c12 1618 printf_filtered ("No alternative known.\n\n");
56382845
FN
1619 }
1620
ebcd3b23 1621 /* We've warned you, now we'll keep quiet. */
56382845
FN
1622 if (alias)
1623 alias->flags &= ~DEPRECATED_WARN_USER;
1624
1625 cmd->flags &= ~DEPRECATED_WARN_USER;
1626}
1627
1628
ebcd3b23 1629/* Look up the contents of LINE as a command in the command list 'cmdlist'.
56382845
FN
1630 Return 1 on success, 0 on failure.
1631
1632 If LINE refers to an alias, *alias will point to that alias.
1633
177b42fe 1634 If LINE is a postfix command (i.e. one that is preceded by a prefix
56382845
FN
1635 command) set *prefix_cmd.
1636
1637 Set *cmd to point to the command LINE indicates.
1638
1639 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1640 exist, they are NULL when we return.
1641
1642*/
1643int
1644lookup_cmd_composition (char *text,
1645 struct cmd_list_element **alias,
1646 struct cmd_list_element **prefix_cmd,
1647 struct cmd_list_element **cmd)
1648{
3386243e 1649 char *command;
56382845
FN
1650 int len, tmp, nfound;
1651 struct cmd_list_element *cur_list;
1652 struct cmd_list_element *prev_cmd;
cdb27c12 1653
56382845
FN
1654 *alias = NULL;
1655 *prefix_cmd = NULL;
1656 *cmd = NULL;
1657
1658 cur_list = cmdlist;
1659
1660 while (1)
1661 {
7a9dd1b2 1662 /* Go through as many command lists as we need to,
ebcd3b23 1663 to find the command TEXT refers to. */
56382845
FN
1664
1665 prev_cmd = *cmd;
1666
1667 while (*text == ' ' || *text == '\t')
cdb27c12 1668 (text)++;
56382845 1669
3386243e
AS
1670 /* Identify the name of the command. */
1671 len = find_command_name_length (text);
56382845
FN
1672
1673 /* If nothing but whitespace, return. */
3386243e
AS
1674 if (len == 0)
1675 return 0;
56382845 1676
cdb27c12
MS
1677 /* Text is the start of the first command word to lookup (and
1678 it's length is len). We copy this into a local temporary. */
56382845
FN
1679
1680 command = (char *) alloca (len + 1);
22ad7fee 1681 memcpy (command, text, len);
56382845
FN
1682 command[len] = '\0';
1683
1684 /* Look it up. */
1685 *cmd = 0;
1686 nfound = 0;
1687 *cmd = find_cmd (command, len, cur_list, 1, &nfound);
1688
ebcd3b23
MS
1689 /* We didn't find the command in the entered case, so lower case
1690 it and search again.
56382845
FN
1691 */
1692 if (!*cmd || nfound == 0)
cdb27c12
MS
1693 {
1694 for (tmp = 0; tmp < len; tmp++)
1695 {
1696 char x = command[tmp];
1697
1698 command[tmp] = isupper (x) ? tolower (x) : x;
1699 }
1700 *cmd = find_cmd (command, len, cur_list, 1, &nfound);
1701 }
56382845 1702
1427fe5e 1703 if (*cmd == CMD_LIST_AMBIGUOUS)
cdb27c12
MS
1704 {
1705 return 0; /* ambiguous */
1706 }
56382845
FN
1707
1708 if (*cmd == NULL)
cdb27c12 1709 return 0; /* nothing found */
56382845 1710 else
cdb27c12
MS
1711 {
1712 if ((*cmd)->cmd_pointer)
1713 {
ebcd3b23
MS
1714 /* cmd was actually an alias, we note that an alias was
1715 used (by assigning *alais) and we set *cmd. */
cdb27c12
MS
1716 *alias = *cmd;
1717 *cmd = (*cmd)->cmd_pointer;
1718 }
1719 *prefix_cmd = prev_cmd;
1720 }
56382845 1721 if ((*cmd)->prefixlist)
cdb27c12 1722 cur_list = *(*cmd)->prefixlist;
56382845 1723 else
cdb27c12 1724 return 1;
56382845 1725
3386243e 1726 text += len;
56382845
FN
1727 }
1728}
1729
c906108c
SS
1730/* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1731
1732/* Return a vector of char pointers which point to the different
ebcd3b23 1733 possible completions in LIST of TEXT.
c906108c
SS
1734
1735 WORD points in the same buffer as TEXT, and completions should be
ebcd3b23
MS
1736 returned relative to this position. For example, suppose TEXT is
1737 "foo" and we want to complete to "foobar". If WORD is "oo", return
c906108c
SS
1738 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1739
49c4e619 1740VEC (char_ptr) *
ace21957
MF
1741complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word,
1742 int ignore_help_classes)
c906108c
SS
1743{
1744 struct cmd_list_element *ptr;
49c4e619 1745 VEC (char_ptr) *matchlist = NULL;
c906108c 1746 int textlen = strlen (text);
3f172e24
TT
1747 int pass;
1748 int saw_deprecated_match = 0;
c906108c 1749
3f172e24
TT
1750 /* We do one or two passes. In the first pass, we skip deprecated
1751 commands. If we see no matching commands in the first pass, and
1752 if we did happen to see a matching deprecated command, we do
1753 another loop to collect those. */
49c4e619 1754 for (pass = 0; matchlist == 0 && pass < 2; ++pass)
3f172e24
TT
1755 {
1756 for (ptr = list; ptr; ptr = ptr->next)
1757 if (!strncmp (ptr->name, text, textlen)
1758 && !ptr->abbrev_flag
ace21957 1759 && (!ignore_help_classes || ptr->func
3f172e24 1760 || ptr->prefixlist))
c906108c 1761 {
49c4e619
TT
1762 char *match;
1763
3f172e24
TT
1764 if (pass == 0)
1765 {
1766 if ((ptr->flags & CMD_DEPRECATED) != 0)
1767 {
1768 saw_deprecated_match = 1;
1769 continue;
1770 }
1771 }
c906108c 1772
49c4e619 1773 match = (char *) xmalloc (strlen (word) + strlen (ptr->name) + 1);
3f172e24 1774 if (word == text)
49c4e619 1775 strcpy (match, ptr->name);
3f172e24
TT
1776 else if (word > text)
1777 {
1778 /* Return some portion of ptr->name. */
49c4e619 1779 strcpy (match, ptr->name + (word - text));
3f172e24
TT
1780 }
1781 else
1782 {
1783 /* Return some of text plus ptr->name. */
49c4e619
TT
1784 strncpy (match, word, text - word);
1785 match[text - word] = '\0';
1786 strcat (match, ptr->name);
3f172e24 1787 }
49c4e619 1788 VEC_safe_push (char_ptr, matchlist, match);
c906108c 1789 }
3f172e24
TT
1790 /* If we saw no matching deprecated commands in the first pass,
1791 just bail out. */
1792 if (!saw_deprecated_match)
1793 break;
1794 }
c906108c 1795
c906108c
SS
1796 return matchlist;
1797}
1798
1799/* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1800
1801/* Return a vector of char pointers which point to the different
ebcd3b23 1802 possible completions in CMD of TEXT.
c906108c
SS
1803
1804 WORD points in the same buffer as TEXT, and completions should be
1805 returned relative to this position. For example, suppose TEXT is "foo"
1806 and we want to complete to "foobar". If WORD is "oo", return
1807 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1808
49c4e619 1809VEC (char_ptr) *
40478521 1810complete_on_enum (const char *const *enumlist,
53904c9e
AC
1811 char *text,
1812 char *word)
c906108c 1813{
49c4e619 1814 VEC (char_ptr) *matchlist = NULL;
c906108c
SS
1815 int textlen = strlen (text);
1816 int i;
53904c9e 1817 const char *name;
c906108c 1818
c906108c
SS
1819 for (i = 0; (name = enumlist[i]) != NULL; i++)
1820 if (strncmp (name, text, textlen) == 0)
1821 {
49c4e619 1822 char *match;
c906108c 1823
49c4e619 1824 match = (char *) xmalloc (strlen (word) + strlen (name) + 1);
c906108c 1825 if (word == text)
49c4e619 1826 strcpy (match, name);
c906108c
SS
1827 else if (word > text)
1828 {
1829 /* Return some portion of name. */
49c4e619 1830 strcpy (match, name + (word - text));
c906108c
SS
1831 }
1832 else
1833 {
1834 /* Return some of text plus name. */
49c4e619
TT
1835 strncpy (match, word, text - word);
1836 match[text - word] = '\0';
1837 strcat (match, name);
c906108c 1838 }
49c4e619 1839 VEC_safe_push (char_ptr, matchlist, match);
c906108c
SS
1840 }
1841
c906108c
SS
1842 return matchlist;
1843}
1844
f436dd25 1845
ebcd3b23 1846/* Check function pointer. */
f436dd25
MH
1847int
1848cmd_func_p (struct cmd_list_element *cmd)
1849{
1850 return (cmd->func != NULL);
1851}
1852
1853
ebcd3b23 1854/* Call the command function. */
f436dd25
MH
1855void
1856cmd_func (struct cmd_list_element *cmd, char *args, int from_tty)
1857{
1858 if (cmd_func_p (cmd))
1859 (*cmd->func) (cmd, args, from_tty);
1860 else
8a3fe4f8 1861 error (_("Invalid command"));
f436dd25 1862}
This page took 1.017485 seconds and 4 git commands to generate.