50
50
#include "settings.h"
51
51
#include "stringutils.h"
52
52
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
58
60
#endif
59
61
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
62
64
#endif
63
65
64
66
/* word break characters */
@@ -182,27 +184,27 @@ static bool completion_case_sensitive;/* completion is case sensitive */
182
184
#define COMPLETE_WITH_QUERY (query ) \
183
185
do { \
184
186
completion_charp = query; \
185
- matches =completion_matches (text, complete_from_query); \
187
+ matches =rl_completion_matches (text, complete_from_query); \
186
188
} while (0)
187
189
188
190
#define COMPLETE_WITH_VERSIONED_QUERY (query ) \
189
191
do { \
190
192
completion_vquery = query; \
191
- matches =completion_matches (text, complete_from_versioned_query); \
193
+ matches =rl_completion_matches (text, complete_from_versioned_query); \
192
194
} while (0)
193
195
194
196
#define COMPLETE_WITH_SCHEMA_QUERY (query ,addon ) \
195
197
do { \
196
198
completion_squery = &(query); \
197
199
completion_charp = addon; \
198
- matches =completion_matches (text, complete_from_schema_query); \
200
+ matches =rl_completion_matches (text, complete_from_schema_query); \
199
201
} while (0)
200
202
201
203
#define COMPLETE_WITH_VERSIONED_SCHEMA_QUERY (query ,addon ) \
202
204
do { \
203
205
completion_squery = query; \
204
206
completion_vquery = addon; \
205
- matches =completion_matches (text, complete_from_versioned_schema_query); \
207
+ matches =rl_completion_matches (text, complete_from_versioned_schema_query); \
206
208
} while (0)
207
209
208
210
/*
@@ -213,14 +215,14 @@ do { \
213
215
do { \
214
216
completion_case_sensitive = (cs); \
215
217
completion_charp = (con); \
216
- matches =completion_matches (text, complete_from_const); \
218
+ matches =rl_completion_matches (text, complete_from_const); \
217
219
} while (0)
218
220
219
221
#define COMPLETE_WITH_LIST_INT (cs ,list ) \
220
222
do { \
221
223
completion_case_sensitive = (cs); \
222
224
completion_charpp = (list); \
223
- matches =completion_matches (text, complete_from_list); \
225
+ matches =rl_completion_matches (text, complete_from_list); \
224
226
} while (0)
225
227
226
228
#define COMPLETE_WITH_LIST (list ) COMPLETE_WITH_LIST_INT(false, list)
@@ -260,7 +262,7 @@ do { \
260
262
completion_info_charp = _completion_table; \
261
263
completion_info_charp2 = _completion_schema; \
262
264
} \
263
- matches =completion_matches (text, complete_from_query); \
265
+ matches =rl_completion_matches (text, complete_from_query); \
264
266
} while (0)
265
267
266
268
#define COMPLETE_WITH_ENUM_VALUE (type ) \
@@ -285,7 +287,7 @@ do { \
285
287
completion_info_charp = _completion_type; \
286
288
completion_info_charp2 = _completion_schema; \
287
289
} \
288
- matches =completion_matches (text, complete_from_query); \
290
+ matches =rl_completion_matches (text, complete_from_query); \
289
291
} while (0)
290
292
291
293
#define COMPLETE_WITH_FUNCTION_ARG (function ) \
@@ -310,7 +312,7 @@ do { \
310
312
completion_info_charp = _completion_function; \
311
313
completion_info_charp2 = _completion_schema; \
312
314
} \
313
- matches =completion_matches (text, complete_from_query); \
315
+ matches =rl_completion_matches (text, complete_from_query); \
314
316
} while (0)
315
317
316
318
/*
@@ -1335,7 +1337,7 @@ ends_with(const char *s, char c)
1335
1337
* According to readline spec this gets passed the text entered so far and its
1336
1338
* start and end positions in the readline buffer. The return value is some
1337
1339
* 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.
1339
1341
*/
1340
1342
static char * *
1341
1343
psql_completion (const char * text ,int start ,int end )
@@ -1488,7 +1490,7 @@ psql_completion(const char *text, int start, int end)
1488
1490
/* CREATE */
1489
1491
/* complete with something you can create */
1490
1492
else if (TailMatches ("CREATE" ))
1491
- matches = completion_matches (text ,create_command_generator );
1493
+ matches = rl_completion_matches (text ,create_command_generator );
1492
1494
1493
1495
/* complete with something you can create or replace */
1494
1496
else if (TailMatches ("CREATE" ,"OR" ,"REPLACE" ))
@@ -1498,7 +1500,7 @@ psql_completion(const char *text, int start, int end)
1498
1500
/* DROP, but not DROP embedded in other commands */
1499
1501
/* complete with something you can drop */
1500
1502
else if (Matches ("DROP" ))
1501
- matches = completion_matches (text ,drop_command_generator );
1503
+ matches = rl_completion_matches (text ,drop_command_generator );
1502
1504
1503
1505
/* ALTER */
1504
1506
@@ -1509,7 +1511,7 @@ psql_completion(const char *text, int start, int end)
1509
1511
1510
1512
/* ALTER something */
1511
1513
else if (Matches ("ALTER" ))
1512
- matches = completion_matches (text ,alter_command_generator );
1514
+ matches = rl_completion_matches (text ,alter_command_generator );
1513
1515
/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
1514
1516
else if (TailMatches ("ALL" ,"IN" ,"TABLESPACE" ,MatchAny ))
1515
1517
COMPLETE_WITH ("SET TABLESPACE" ,"OWNED BY" );
@@ -2261,7 +2263,7 @@ psql_completion(const char *text, int start, int end)
2261
2263
Matches ("COPY" ,"BINARY" ,MatchAny ,"FROM|TO" ))
2262
2264
{
2263
2265
completion_charp = "" ;
2264
- matches = completion_matches (text ,complete_from_files );
2266
+ matches = rl_completion_matches (text ,complete_from_files );
2265
2267
}
2266
2268
2267
2269
/* Handle COPY [BINARY] <sth> FROM|TO filename */
@@ -2483,7 +2485,11 @@ psql_completion(const char *text, int start, int end)
2483
2485
else if (Matches ("CREATE" ,"RULE" ,MatchAny ,"AS" )||
2484
2486
Matches ("CREATE" ,"OR" ,"REPLACE" ,"RULE" ,MatchAny ,"AS" ))
2485
2487
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
+ */
2487
2493
else if (Matches ("CREATE" ,"RULE" ,MatchAny ,"AS" ,"ON" )||
2488
2494
Matches ("CREATE" ,"OR" ,"REPLACE" ,"RULE" ,MatchAny ,"AS" ,"ON" ))
2489
2495
COMPLETE_WITH ("SELECT" ,"UPDATE" ,"INSERT" ,"DELETE" );
@@ -3708,9 +3714,9 @@ psql_completion(const char *text, int start, int end)
3708
3714
else if (TailMatchesCS ("\\h|\\help" ,MatchAny ))
3709
3715
{
3710
3716
if (TailMatches ("DROP" ))
3711
- matches = completion_matches (text ,drop_command_generator );
3717
+ matches = rl_completion_matches (text ,drop_command_generator );
3712
3718
else if (TailMatches ("ALTER" ))
3713
- matches = completion_matches (text ,alter_command_generator );
3719
+ matches = rl_completion_matches (text ,alter_command_generator );
3714
3720
3715
3721
/*
3716
3722
* 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)
3809
3815
"\\s|\\w|\\write|\\lo_import" ))
3810
3816
{
3811
3817
completion_charp = "\\" ;
3812
- matches = completion_matches (text ,complete_from_files );
3818
+ matches = rl_completion_matches (text ,complete_from_files );
3813
3819
}
3814
3820
3815
3821
/*
@@ -4395,7 +4401,7 @@ complete_from_files(const char *text, int state)
4395
4401
}
4396
4402
}
4397
4403
4398
- unquoted_match = filename_completion_function (unquoted_text ,state );
4404
+ unquoted_match = rl_filename_completion_function (unquoted_text ,state );
4399
4405
if (unquoted_match )
4400
4406
{
4401
4407
/*