Skip to content

Commit 5e7bedc

Browse files
committed
Modernize our readline API a tad.
Prefer to call "rl_filename_completion_function" and "rl_completion_matches", rather than using the names without the rl_ prefix. This matches Readline's documentation, and makes our code a little clearer about which names are external. On platforms that only have the un-prefixed names (just some very ancient versions of libedit, AFAICT), reverse the direction of the compatibility macro definitions to match. Also, remove our extern declaration of "filename_completion_function"; whatever libedit versions may have failed to declare that are surely dead and buried. Discussion: https://postgr.es/m/23608.1576248145@sss.pgh.pa.us
1 parent 22864f6 commit 5e7bedc

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

src/bin/psql/tab-complete.c

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@
5050
#include "settings.h"
5151
#include "stringutils.h"
5252

53-
#ifdef HAVE_RL_FILENAME_COMPLETION_FUNCTION
54-
#define filename_completion_function rl_filename_completion_function
55-
#else
56-
/* missing in some header files */
57-
extern char *filename_completion_function();
53+
/*
54+
* Ancient versions of libedit provide filename_completion_function()
55+
* instead of rl_filename_completion_function(). Likewise for
56+
* [rl_]completion_matches().
57+
*/
58+
#ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION
59+
#define rl_filename_completion_function filename_completion_function
5860
#endif
5961

60-
#ifdef HAVE_RL_COMPLETION_MATCHES
61-
#define completion_matches rl_completion_matches
62+
#ifndef HAVE_RL_COMPLETION_MATCHES
63+
#define rl_completion_matches completion_matches
6264
#endif
6365

6466
/* word break characters */
@@ -182,27 +184,27 @@ static bool completion_case_sensitive; /* completion is case sensitive */
182184
#define COMPLETE_WITH_QUERY(query) \
183185
do { \
184186
completion_charp = query; \
185-
matches = completion_matches(text, complete_from_query); \
187+
matches = rl_completion_matches(text, complete_from_query); \
186188
} while (0)
187189

188190
#define COMPLETE_WITH_VERSIONED_QUERY(query) \
189191
do { \
190192
completion_vquery = query; \
191-
matches = completion_matches(text, complete_from_versioned_query); \
193+
matches = rl_completion_matches(text, complete_from_versioned_query); \
192194
} while (0)
193195

194196
#define COMPLETE_WITH_SCHEMA_QUERY(query, addon) \
195197
do { \
196198
completion_squery = &(query); \
197199
completion_charp = addon; \
198-
matches = completion_matches(text, complete_from_schema_query); \
200+
matches = rl_completion_matches(text, complete_from_schema_query); \
199201
} while (0)
200202

201203
#define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(query, addon) \
202204
do { \
203205
completion_squery = query; \
204206
completion_vquery = addon; \
205-
matches = completion_matches(text, complete_from_versioned_schema_query); \
207+
matches = rl_completion_matches(text, complete_from_versioned_schema_query); \
206208
} while (0)
207209

208210
/*
@@ -213,14 +215,14 @@ do { \
213215
do { \
214216
completion_case_sensitive = (cs); \
215217
completion_charp = (con); \
216-
matches = completion_matches(text, complete_from_const); \
218+
matches = rl_completion_matches(text, complete_from_const); \
217219
} while (0)
218220

219221
#define COMPLETE_WITH_LIST_INT(cs, list) \
220222
do { \
221223
completion_case_sensitive = (cs); \
222224
completion_charpp = (list); \
223-
matches = completion_matches(text, complete_from_list); \
225+
matches = rl_completion_matches(text, complete_from_list); \
224226
} while (0)
225227

226228
#define COMPLETE_WITH_LIST(list) COMPLETE_WITH_LIST_INT(false, list)
@@ -260,7 +262,7 @@ do { \
260262
completion_info_charp = _completion_table; \
261263
completion_info_charp2 = _completion_schema; \
262264
} \
263-
matches = completion_matches(text, complete_from_query); \
265+
matches = rl_completion_matches(text, complete_from_query); \
264266
} while (0)
265267

266268
#define COMPLETE_WITH_ENUM_VALUE(type) \
@@ -285,7 +287,7 @@ do { \
285287
completion_info_charp = _completion_type; \
286288
completion_info_charp2 = _completion_schema; \
287289
} \
288-
matches = completion_matches(text, complete_from_query); \
290+
matches = rl_completion_matches(text, complete_from_query); \
289291
} while (0)
290292

291293
#define COMPLETE_WITH_FUNCTION_ARG(function) \
@@ -310,7 +312,7 @@ do { \
310312
completion_info_charp = _completion_function; \
311313
completion_info_charp2 = _completion_schema; \
312314
} \
313-
matches = completion_matches(text, complete_from_query); \
315+
matches = rl_completion_matches(text, complete_from_query); \
314316
} while (0)
315317

316318
/*
@@ -1335,7 +1337,7 @@ ends_with(const char *s, char c)
13351337
* According to readline spec this gets passed the text entered so far and its
13361338
* start and end positions in the readline buffer. The return value is some
13371339
* partially obscure list format that can be generated by readline's
1338-
* completion_matches() function, so we don't have to worry about it.
1340+
* rl_completion_matches() function, so we don't have to worry about it.
13391341
*/
13401342
static char **
13411343
psql_completion(const char *text, int start, int end)
@@ -1488,7 +1490,7 @@ psql_completion(const char *text, int start, int end)
14881490
/* CREATE */
14891491
/* complete with something you can create */
14901492
else if (TailMatches("CREATE"))
1491-
matches = completion_matches(text, create_command_generator);
1493+
matches = rl_completion_matches(text, create_command_generator);
14921494

14931495
/* complete with something you can create or replace */
14941496
else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -1498,7 +1500,7 @@ psql_completion(const char *text, int start, int end)
14981500
/* DROP, but not DROP embedded in other commands */
14991501
/* complete with something you can drop */
15001502
else if (Matches("DROP"))
1501-
matches = completion_matches(text, drop_command_generator);
1503+
matches = rl_completion_matches(text, drop_command_generator);
15021504

15031505
/* ALTER */
15041506

@@ -1509,7 +1511,7 @@ psql_completion(const char *text, int start, int end)
15091511

15101512
/* ALTER something */
15111513
else if (Matches("ALTER"))
1512-
matches = completion_matches(text, alter_command_generator);
1514+
matches = rl_completion_matches(text, alter_command_generator);
15131515
/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
15141516
else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
15151517
COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -2261,7 +2263,7 @@ psql_completion(const char *text, int start, int end)
22612263
Matches("COPY", "BINARY", MatchAny, "FROM|TO"))
22622264
{
22632265
completion_charp = "";
2264-
matches = completion_matches(text, complete_from_files);
2266+
matches = rl_completion_matches(text, complete_from_files);
22652267
}
22662268

22672269
/* Handle COPY [BINARY] <sth> FROM|TO filename */
@@ -2483,7 +2485,11 @@ psql_completion(const char *text, int start, int end)
24832485
else if (Matches("CREATE", "RULE", MatchAny, "AS") ||
24842486
Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS"))
24852487
COMPLETE_WITH("ON");
2486-
/* Complete "CREATE [ OR REPLACE ] RULE <sth> AS ON" with SELECT|UPDATE|INSERT|DELETE */
2488+
2489+
/*
2490+
* Complete "CREATE [ OR REPLACE ] RULE <sth> AS ON" with
2491+
* SELECT|UPDATE|INSERT|DELETE
2492+
*/
24872493
else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON") ||
24882494
Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS", "ON"))
24892495
COMPLETE_WITH("SELECT", "UPDATE", "INSERT", "DELETE");
@@ -3708,9 +3714,9 @@ psql_completion(const char *text, int start, int end)
37083714
else if (TailMatchesCS("\\h|\\help", MatchAny))
37093715
{
37103716
if (TailMatches("DROP"))
3711-
matches = completion_matches(text, drop_command_generator);
3717+
matches = rl_completion_matches(text, drop_command_generator);
37123718
else if (TailMatches("ALTER"))
3713-
matches = completion_matches(text, alter_command_generator);
3719+
matches = rl_completion_matches(text, alter_command_generator);
37143720

37153721
/*
37163722
* CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -3809,7 +3815,7 @@ psql_completion(const char *text, int start, int end)
38093815
"\\s|\\w|\\write|\\lo_import"))
38103816
{
38113817
completion_charp = "\\";
3812-
matches = completion_matches(text, complete_from_files);
3818+
matches = rl_completion_matches(text, complete_from_files);
38133819
}
38143820

38153821
/*
@@ -4395,7 +4401,7 @@ complete_from_files(const char *text, int state)
43954401
}
43964402
}
43974403

4398-
unquoted_match = filename_completion_function(unquoted_text, state);
4404+
unquoted_match = rl_filename_completion_function(unquoted_text, state);
43994405
if (unquoted_match)
44004406
{
44014407
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy