diff options
Diffstat (limited to 'gdb/completer.h')
-rw-r--r-- | gdb/completer.h | 101 |
1 files changed, 87 insertions, 14 deletions
diff --git a/gdb/completer.h b/gdb/completer.h index 98a12f3..0912fb2 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -1,5 +1,5 @@ /* Header for GDB line completion. - Copyright (C) 2000-2024 Free Software Foundation, Inc. + Copyright (C) 2000-2025 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,11 +14,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#if !defined (COMPLETER_H) -#define COMPLETER_H 1 +#ifndef GDB_COMPLETER_H +#define GDB_COMPLETER_H #include "gdbsupport/gdb-hashtab.h" -#include "gdbsupport/gdb_vecs.h" #include "command.h" /* Types of functions in struct match_list_displayer. */ @@ -247,12 +246,24 @@ struct completion_match_result struct completion_result { + /* The type of a function that is used to format completion results when + using the 'complete' command. MATCH is the completion word to be + printed, and QUOTE_CHAR is a trailing quote character to (possibly) + add at the end of MATCH. QUOTE_CHAR can be the null-character in + which case no trailing quote should be added. + + Return the possibly modified completion match word which should be + presented to the user. */ + using match_format_func_t = std::string (*) (const char *match, + char quote_char); + /* Create an empty result. */ completion_result (); /* Create a result. */ completion_result (char **match_list, size_t number_matches, - bool completion_suppress_append); + bool completion_suppress_append, + match_format_func_t match_format_func); /* Destroy a result. */ ~completion_result (); @@ -268,6 +279,24 @@ struct completion_result /* Sort the match list. */ void sort_match_list (); + /* Called to display all matches (used by the 'complete' command). + PREFIX is everything before the completion word. WORD is the word + being completed, this is only used if we reach the maximum number of + completions, otherwise, each line of output consists of PREFIX + followed by one of the possible completion words. + + The QUOTE_CHAR is usually appended after each possible completion + word and should be the quote character that appears before the + completion word, or the null-character if there is no quote before + the completion word. + + The QUOTE_CHAR is not always appended to the completion output. For + example, filename completions will not append QUOTE_CHAR if the + completion is a directory name. This is all handled by calling this + function. */ + void print_matches (const std::string &prefix, const char *word, + int quote_char); + private: /* Destroy the match list array and its contents. */ void reset_match_list (); @@ -292,6 +321,12 @@ public: /* Whether readline should suppress appending a whitespace, when there's only one possible completion. */ bool completion_suppress_append; + +private: + /* A function which formats a single completion match ready for display + as part of the 'complete' command output. Different completion + functions can set different formatter functions. */ + match_format_func_t m_match_formatter; }; /* Object used by completers to build a completion match list to hand @@ -428,6 +463,14 @@ public: bool from_readline () const { return m_from_readline; } + /* Set the function used to format the completion word before displaying + it to the user to F, this is used by the 'complete' command. */ + void set_match_format_func (completion_result::match_format_func_t f) + { + gdb_assert (f != nullptr); + m_match_format_func = f; + } + private: /* The type that we place into the m_entries_hash hash table. */ @@ -522,6 +565,10 @@ private: interactively. The 'complete' command is a way to generate completions not to be displayed by readline. */ bool m_from_readline; + + /* The function used to format the completion word before it is printed + in the 'complete' command output. */ + completion_result::match_format_func_t m_match_format_func; }; /* Return a string to hand off to readline as a completion match @@ -563,19 +610,45 @@ extern completion_result const char *advance_to_expression_complete_word_point (completion_tracker &tracker, const char *text); -/* Assuming TEXT is an filename, find the completion word point for - TEXT, emulating the algorithm readline uses to find the word - point. */ -extern const char *advance_to_filename_complete_word_point +/* Assuming TEXT is a filename, find the completion word point for TEXT, + emulating the algorithm readline uses to find the word point. The + filenames that are located by this function assume no filename + quoting, this function should be paired with filename_completer. */ +extern const char *advance_to_deprecated_filename_complete_word_point + (completion_tracker &tracker, const char *text); + +/* Assuming TEXT is a filename, find the completion word point for TEXT, + emulating the algorithm readline uses to find the word point. The + filenames that are located by this function assume that filenames + can be quoted, this function should be paired with + filename_maybe_quoted_completer. */ +extern const char *advance_to_filename_maybe_quoted_complete_word_point (completion_tracker &tracker, const char *text); extern void noop_completer (struct cmd_list_element *, completion_tracker &tracker, const char *, const char *); -extern void filename_completer (struct cmd_list_element *, - completion_tracker &tracker, - const char *, const char *); +/* Filename completer for commands that don't accept quoted filenames. + This completer does support completing a list of filenames that are + separated with the path separator (':' for UNIX and ';' for MS-DOS). + + When adding a new command it is better to write the command so it + accepts quoted filenames and use filename_maybe_quoted_completer, for + examples see the 'exec' and 'exec-file' commands. */ + +extern void deprecated_filename_completer + (struct cmd_list_element *, completion_tracker &tracker, + const char *, const char *); + +/* Filename completer for commands where the filename argument can be + quoted. This completer also supports completing a list of filenames + that are separated with the path separator (':' for UNIX and ';' for + MS-DOS). */ + +extern void filename_maybe_quoted_completer (struct cmd_list_element *, + completion_tracker &tracker, + const char *, const char *); extern void expression_completer (struct cmd_list_element *, completion_tracker &tracker, @@ -649,7 +722,7 @@ extern void complete_nested_command_line (completion_tracker &tracker, This function is designed so that trying to complete '/' will offer no completions, the user needs to insert the format specification themselves. Trying to complete '/FMT' (where FMT is any non-empty set - of alpha-numeric characters) will cause readline to insert a single + of alphanumeric characters) will cause readline to insert a single space, setting the user up to enter the expression. */ extern bool skip_over_slash_fmt (completion_tracker &tracker, @@ -661,4 +734,4 @@ extern bool skip_over_slash_fmt (completion_tracker &tracker, extern int max_completions; -#endif /* defined (COMPLETER_H) */ +#endif /* GDB_COMPLETER_H */ |