diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index a8041401b8b..c4e40042048 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -3339,7 +3339,7 @@ match_previous_words(int pattern_id, else if (Matches("COPY|\\copy", MatchAny, "FROM|TO")) { /* COPY requires quoted filename */ - bool force_quote = HeadMatches("COPY"); + bool force_quote = HeadMatches("COPY"); if (TailMatches("FROM")) COMPLETE_WITH_FILES_PLUS("", force_quote, "STDIN", "PROGRAM"); @@ -3349,7 +3349,8 @@ match_previous_words(int pattern_id, /* Complete COPY|\copy FROM|TO PROGRAM command */ else if (Matches("COPY|\\copy", MatchAny, "FROM|TO", "PROGRAM")) - COMPLETE_WITH_FILES("", HeadMatches("COPY")); /* COPY requires quoted filename */ + COMPLETE_WITH_FILES("", HeadMatches("COPY")); /* COPY requires quoted + * filename */ /* Complete COPY TO [PROGRAM] */ else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAnyExcept("PROGRAM")) || @@ -6271,19 +6272,18 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix /* - * This function wraps _complete_from_files() so that both literal keywords - * and filenames can be included in the completion results. + * This function returns in order one of a fixed, NULL pointer terminated list + * of string that matches file names or optionally specified list of keywords. * * If completion_charpp is set to a null-terminated array of literal keywords, - * those keywords are added to the completion results alongside filenames, - * as long as they case-insensitively match the current input. + * those keywords are added to the completion results alongside filenames if + * they case-insensitively match the current input. */ static char * complete_from_files(const char *text, int state) { - char *result; static int list_index; - static bool files_done; + static bool files_done; const char *item; /* Initialization */ @@ -6293,18 +6293,21 @@ complete_from_files(const char *text, int state) files_done = false; } - /* Return a filename that matches */ - if (!files_done && (result = _complete_from_files(text, state))) - return result; - else if (!completion_charpp) - return NULL; - else + if (!files_done) + { + char *result = _complete_from_files(text, state); + + /* Return a filename that matches */ + if (result) + return result; + + /* There are no more matching files */ files_done = true; + } /* - * If there are no more matching files, check for hard-wired keywords. - * These will only be returned if they match the input-so-far, - * ignoring case. + * Check for hard-wired keywords. These will only be returned if they + * match the input-so-far, ignoring case. */ while ((item = completion_charpp[list_index++])) {