Commit c5686b29 authored by Bruce Momjian's avatar Bruce Momjian

Re-run pgindent to fix breakage when exceeding 150 'else if' clauses.

Cosmetic fix only.
parent 76ce39e3
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2005, PostgreSQL Global Development Group * Copyright (c) 2000-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.139 2005/11/07 17:36:45 tgl Exp $ * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.140 2005/11/14 17:48:43 momjian Exp $
*/ */
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
...@@ -1782,134 +1782,11 @@ psql_completion(char *text, int start, int end) ...@@ -1782,134 +1782,11 @@ psql_completion(char *text, int start, int end)
matches = completion_matches(text, filename_completion_function); matches = completion_matches(text, filename_completion_function);
/* /*
* * Finally, we look through the list of "things", such as TABLE, INDEX and
* Fi * check if that was the previous word. If so, execute the query to get a
* n * list of them.
* a */
* l
* l
* y
* ,
*
* we
*
* lo
* o
* k
*
* th
* r
* o
* u
* g
* h
*
* th
* e
*
* li
* s
* t
*
* of
*
* "t
* h
* i
* n
* g
* s
* "
* ,
*
* su
* c
* h
*
* as
*
* TA
* B
* L
* E
* ,
*
* IN
* D
* E
* X
*
* an
* d
*
* ch
* e
* c
* k
*
* if
*
* th
* a
* t
*
* wa
* s
*
* th
* e
*
* pr
* e
* v
* i
* o
* u
* s
*
* wo
* r
* d
* .
*
* If
*
* so
* ,
*
* ex
* e
* c
* u
* t
* e
*
* th
* e
*
* qu
* e
* r
* y
*
* to
*
* ge
* t
*
* a
* li
* s
* t
*
* of
*
* th
* e
* m
* .
* */
else else
{ {
int i; int i;
...@@ -1928,236 +1805,29 @@ psql_completion(char *text, int start, int end) ...@@ -1928,236 +1805,29 @@ psql_completion(char *text, int start, int end)
} }
} }
/* /*
* * If we still don't have anything to match we have to fabricate some sort
* If * of default list. If we were to just return NULL, readline automatically
* * attempts filename completion, and that's usually no good.
* we */
* if (matches == NULL)
* st {
* i COMPLETE_WITH_CONST("");
* l
* l
*
* do
* n
* '
* t
*
* ha
* v
* e
*
* an
* y
* t
* h
* i
* n
* g
*
* to
*
* ma
* t
* c
* h
*
* we
*
* ha
* v
* e
*
* to
*
* fa
* b
* r
* i
* c
* a
* t
* e
*
* so
* m
* e
*
* so
* r
* t
*
* of
*
* de
* f
* a
* u
* l
* t
*
* li
* s
* t
* .
*
* If
*
* we
*
* we
* r
* e
*
* to
*
* ju
* s
* t
*
* re
* t
* u
* r
* n
*
* NU
* L
* L
* ,
*
* re
* a
* d
* l
* i
* n
* e
*
* au
* t
* o
* m
* a
* t
* i
* c
* a
* l
* l
* y
*
* at
* t
* e
* m
* p
* t
* s
*
* fi
* l
* e
* n
* a
* m
* e
*
* co
* m
* p
* l
* e
* t
* i
* o
* n
* ,
*
* an
* d
*
* th
* a
* t
* '
* s
*
* us
* u
* a
* l
* l
* y
*
* no
*
* go
* o
* d
* .
* */
if (matches == NULL)
{
COMPLETE_WITH_CONST("");
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
rl_completion_append_character = '\0'; rl_completion_append_character = '\0';
#endif #endif
} }
/* /* free storage */
* f free(prev_wd);
* r free(prev2_wd);
* e free(prev3_wd);
* e free(prev4_wd);
* free(prev5_wd);
* st
* o /* Return our Grand List O' Matches */
* r return matches;
* a }
* g
* e
*
*/
free(prev_wd);
free(prev2_wd);
free(prev3_wd);
free(prev4_wd);
free(prev5_wd);
/*
* R
* e
* t
* u
* r
* n
*
* ou
* r
*
* Gr
* a
* n
* d
*
* Li
* s
* t
*
* O'
*
* Ma
* t
* c
* h
* e
* s
*
*/
return matches;
}
...@@ -2177,152 +1847,43 @@ psql_completion(char *text, int start, int end) ...@@ -2177,152 +1847,43 @@ psql_completion(char *text, int start, int end)
/* This one gives you one from a list of things you can put after CREATE or DROP /* This one gives you one from a list of things you can put after CREATE or DROP
as defined above. as defined above.
*/ */
static char * static char *
create_command_generator(const char *text, int state) create_command_generator(const char *text, int state)
{ {
static int list_index, static int list_index,
string_length; string_length;
const char *name; const char *name;
/* /* If this is the first time for this completion, init some values */
* I if (state == 0)
* f {
* list_index = 0;
* th string_length = strlen(text);
* i }
* s
* /* find something that matches */
* is while ((name = words_after_create[list_index++].name))
* if (pg_strncasecmp(name, text, string_length) == 0)
* th return pg_strdup(name);
* e
* /* if nothing matches, return NULL */
* fi return NULL;
* r }
* s
* t
*
* ti
* m
* e
*
* fo
* r
*
* th
* i
* s
*
* co
* m
* p
* l
* e
* t
* i
* o
* n
* ,
*
* in
* i
* t
*
* so
* m
* e
*
* va
* l
* u
* e
* s
*
*/
if (state == 0)
{
list_index = 0;
string_length = strlen(text);
}
/*
* f
* i
* n
* d
*
* so
* m
* e
* t
* h
* i
* n
* g
*
* th
* a
* t
*
* ma
* t
* c
* h
* e
* s
*
*/
while ((name = words_after_create[list_index++].name))
if (pg_strncasecmp(name, text, string_length) == 0)
return pg_strdup(name);
/*
* i
* f
*
* no
* t
* h
* i
* n
* g
*
* ma
* t
* c
* h
* e
* s
* ,
*
* re
* t
* u
* r
* n
*
* NU
* L
* L
*
*/
return NULL;
}
/* The following two functions are wrappers for _complete_from_query */ /* The following two functions are wrappers for _complete_from_query */
static char * static char *
complete_from_query(const char *text, int state) complete_from_query(const char *text, int state)
{ {
return _complete_from_query(0, text, state); return _complete_from_query(0, text, state);
} }
static char * static char *
complete_from_schema_query(const char *text, int state) complete_from_schema_query(const char *text, int state)
{ {
return _complete_from_query(1, text, state); return _complete_from_query(1, text, state);
} }
/* This creates a list of matching things, according to a query pointed to /* This creates a list of matching things, according to a query pointed to
...@@ -2344,1308 +1905,228 @@ psql_completion(char *text, int start, int end) ...@@ -2344,1308 +1905,228 @@ psql_completion(char *text, int start, int end)
See top of file for examples of both kinds of query. See top of file for examples of both kinds of query.
*/ */
static char * static char *
_complete_from_query(int is_schema_query, const char *text, int state) _complete_from_query(int is_schema_query, const char *text, int state)
{ {
static int list_index, static int list_index,
string_length; string_length;
static PGresult *result = NULL; static PGresult *result = NULL;
/* /*
* * If this is the first time for this completion, we fetch a list of our
* If * "things" from the backend.
* */
* th if (state == 0)
* i {
* s PQExpBufferData query_buffer;
* char *e_text;
* is char *e_info_charp;
*
* th list_index = 0;
* e string_length = strlen(text);
*
* fi /* Free any prior result */
* r PQclear(result);
* s result = NULL;
* t
* /* Set up suitably-escaped copies of textual inputs */
* ti e_text = pg_malloc(string_length * 2 + 1);
* m PQescapeString(e_text, text, string_length);
* e
* if (completion_info_charp)
* fo {
* r size_t charp_len;
*
* th charp_len = strlen(completion_info_charp);
* i e_info_charp = pg_malloc(charp_len * 2 + 1);
* s PQescapeString(e_info_charp, completion_info_charp,
* charp_len);
* co }
* m else
* p e_info_charp = NULL;
* l
* e initPQExpBuffer(&query_buffer);
* t
* i if (is_schema_query)
* o {
* n /* completion_squery gives us the pieces to assemble */
* , const char *qualresult = completion_squery->qualresult;
*
* we if (qualresult == NULL)
* qualresult = completion_squery->result;
* fe
* t /* Get unqualified names matching the input-so-far */
* c appendPQExpBuffer(&query_buffer, "SELECT %s FROM %s WHERE ",
* h completion_squery->result,
* completion_squery->catname);
* a if (completion_squery->selcondition)
* li appendPQExpBuffer(&query_buffer, "%s AND ",
* s completion_squery->selcondition);
* t appendPQExpBuffer(&query_buffer, "substring(%s,1,%d)='%s'",
* completion_squery->result,
* of string_length, e_text);
* appendPQExpBuffer(&query_buffer, " AND %s",
* ou completion_squery->viscondition);
* r
* /*
* "t * When fetching relation names, suppress system catalogs unless
* h * the input-so-far begins with "pg_". This is a compromise
* i * between not offering system catalogs for completion at all, and
* n * having them swamp the result when the input is just "p".
* g */
* s if (strcmp(completion_squery->catname,
* " "pg_catalog.pg_class c") == 0 &&
* strncmp(text, "pg_", 3) !=0)
* fr {
* o appendPQExpBuffer(&query_buffer,
* m " AND c.relnamespace <> (SELECT oid FROM"
* " pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')");
* th }
* e
* /*
* ba * Add in matching schema names, but only if there is more than
* c * one potential match among schema names.
* k */
* e appendPQExpBuffer(&query_buffer, "\nUNION\n"
* n "SELECT pg_catalog.quote_ident(n.nspname) || '.' "
* d "FROM pg_catalog.pg_namespace n "
* . "WHERE substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d)='%s'",
* */ string_length, e_text);
if (state == 0) appendPQExpBuffer(&query_buffer,
{ " AND (SELECT pg_catalog.count(*)"
PQExpBufferData query_buffer; " FROM pg_catalog.pg_namespace"
char *e_text; " WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) ="
char *e_info_charp; " substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) > 1",
string_length, e_text);
list_index = 0;
string_length = strlen(text); /*
* Add in matching qualified names, but only if there is exactly
/* * one schema matching the input-so-far.
* F */
* r appendPQExpBuffer(&query_buffer, "\nUNION\n"
* e "SELECT pg_catalog.quote_ident(n.nspname) || '.' || %s "
* e "FROM %s, pg_catalog.pg_namespace n "
* "WHERE %s = n.oid AND ",
* an qualresult,
* y completion_squery->catname,
* completion_squery->namespace);
* pr if (completion_squery->selcondition)
* i appendPQExpBuffer(&query_buffer, "%s AND ",
* o completion_squery->selcondition);
* r appendPQExpBuffer(&query_buffer, "substring(pg_catalog.quote_ident(n.nspname) || '.' || %s,1,%d)='%s'",
* qualresult,
* re string_length, e_text);
* s
* u /*
* l * This condition exploits the single-matching-schema rule to
* t * speed up the query
* */
*/ appendPQExpBuffer(&query_buffer,
PQclear(result); " AND substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d) ="
result = NULL; " substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(n.nspname))+1)",
string_length, e_text);
/* appendPQExpBuffer(&query_buffer,
* S " AND (SELECT pg_catalog.count(*)"
* e " FROM pg_catalog.pg_namespace"
* t " WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) ="
* " substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) = 1",
* up string_length, e_text);
*
* su /* If an addon query was provided, use it */
* i if (completion_charp)
* t appendPQExpBuffer(&query_buffer, "\n%s", completion_charp);
* a }
* b else
* l {
* y /* completion_charp is an sprintf-style format string */
* - appendPQExpBuffer(&query_buffer, completion_charp,
* e string_length, e_text, e_info_charp);
* s }
* c
* a /* Limit the number of records in the result */
* p appendPQExpBuffer(&query_buffer, "\nLIMIT %d",
* e completion_max_records);
* d
* result = exec_query(query_buffer.data);
* co
* p termPQExpBuffer(&query_buffer);
* i free(e_text);
* e if (e_info_charp)
* s free(e_info_charp);
* }
* of
* /* Find something that matches */
* te if (result && PQresultStatus(result) == PGRES_TUPLES_OK)
* x {
* t const char *item;
* u
* a while (list_index < PQntuples(result) &&
* l (item = PQgetvalue(result, list_index++, 0)))
* if (pg_strncasecmp(text, item, string_length) == 0)
* in return pg_strdup(item);
* p }
* u
* t /* If nothing matches, free the db structure and return null */
* s PQclear(result);
* result = NULL;
*/ return NULL;
e_text = pg_malloc(string_length * 2 + 1); }
PQescapeString(e_text, text, string_length);
if (completion_info_charp)
{
size_t charp_len;
charp_len = strlen(completion_info_charp);
e_info_charp = pg_malloc(charp_len * 2 + 1);
PQescapeString(e_info_charp, completion_info_charp,
charp_len);
}
else
e_info_charp = NULL;
initPQExpBuffer(&query_buffer);
if (is_schema_query)
{
/*
* c
* o
* m
* p
* l
* e
* t
* i
* o
* n
* _
* s
* q
* u
* e
* r
* y
*
* gi
* v
* e
* s
*
* us
*
* th
* e
*
* pi
* e
* c
* e
* s
*
* to
*
* as
* s
* e
* m
* b
* l
* e
*
*/
const char *qualresult = completion_squery->qualresult;
if (qualresult == NULL)
qualresult = completion_squery->result;
/*
* G
* e
* t
*
* un
* q
* u
* a
* l
* i
* f
* i
* e
* d
*
* na
* m
* e
* s
*
* ma
* t
* c
* h
* i
* n
* g
*
* th
* e
*
* in
* p
* u
* t
* -
* s
* o
* -
* f
* a
* r
*
*/
appendPQExpBuffer(&query_buffer, "SELECT %s FROM %s WHERE ",
completion_squery->result,
completion_squery->catname);
if (completion_squery->selcondition)
appendPQExpBuffer(&query_buffer, "%s AND ",
completion_squery->selcondition);
appendPQExpBuffer(&query_buffer, "substring(%s,1,%d)='%s'",
completion_squery->result,
string_length, e_text);
appendPQExpBuffer(&query_buffer, " AND %s",
completion_squery->viscondition);
/*
*
* Wh
* e
* n
*
* fe
* t
* c
* h
* i
* n
* g
*
* re
* l
* a
* t
* i
* o
* n
*
* na
* m
* e
* s
* ,
*
* su
* p
* p
* r
* e
* s
* s
*
* sy
* s
* t
* e
* m
*
* ca
* t
* a
* l
* o
* g
* s
*
* un
* l
* e
* s
* s
*
* th
* e
*
* in
* p
* u
* t
* -
* s
* o
* -
* f
* a
* r
*
* be
* g
* i
* n
* s
*
* wi
* t
* h
*
* "p
* g
* _
* "
* .
*
* Th
* i
* s
*
* is
*
* a
* co
* m
* p
* r
* o
* m
* i
* s
* e
*
* be
* t
* w
* e
* e
* n
*
* no
* t
*
* of
* f
* e
* r
* i
* n
* g
*
* sy
* s
* t
* e
* m
*
* ca
* t
* a
* l
* o
* g
* s
*
* fo
* r
*
* co
* m
* p
* l
* e
* t
* i
* o
* n
*
* at
*
* al
* l
* ,
*
* an
* d
*
* ha
* v
* i
* n
* g
*
* th
* e
* m
*
* sw
* a
* m
* p
*
* th
* e
*
* re
* s
* u
* l
* t
*
* wh
* e
* n
*
* th
* e
*
* in
* p
* u
* t
*
* is
*
* ju
* s
* t
*
* "p
* "
* .
* */
if (strcmp(completion_squery->catname,
"pg_catalog.pg_class c") == 0 &&
strncmp(text, "pg_", 3) !=0)
{
appendPQExpBuffer(&query_buffer,
" AND c.relnamespace <> (SELECT oid FROM"
" pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')");
}
/*
*
* Ad
* d
*
* in
*
* ma
* t
* c
* h
* i
* n
* g
*
* sc
* h
* e
* m
* a
*
* na
* m
* e
* s
* ,
*
* bu
* t
*
* on
* l
* y
*
* if
*
* th
* e
* r
* e
*
* is
*
* mo
* r
* e
*
* th
* a
* n
*
* on
* e
*
* po
* t
* e
* n
* t
* i
* a
* l
*
* ma
* t
* c
* h
*
* am
* o
* n
* g
*
* sc
* h
* e
* m
* a
*
* na
* m
* e
* s
* .
* */
appendPQExpBuffer(&query_buffer, "\nUNION\n"
"SELECT pg_catalog.quote_ident(n.nspname) || '.' "
"FROM pg_catalog.pg_namespace n "
"WHERE substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d)='%s'",
string_length, e_text);
appendPQExpBuffer(&query_buffer,
" AND (SELECT pg_catalog.count(*)"
" FROM pg_catalog.pg_namespace"
" WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) ="
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) > 1",
string_length, e_text);
/*
*
* Ad
* d
*
* in
*
* ma
* t
* c
* h
* i
* n
* g
*
* qu
* a
* l
* i
* f
* i
* e
* d
*
* na
* m
* e
* s
* ,
*
* bu
* t
*
* on
* l
* y
*
* if
*
* th
* e
* r
* e
*
* is
*
* ex
* a
* c
* t
* l
* y
*
* on
* e
*
* sc
* h
* e
* m
* a
*
* ma
* t
* c
* h
* i
* n
* g
*
* th
* e
*
* in
* p
* u
* t
* -
* s
* o
* -
* f
* a
* r
* .
* */
appendPQExpBuffer(&query_buffer, "\nUNION\n"
"SELECT pg_catalog.quote_ident(n.nspname) || '.' || %s "
"FROM %s, pg_catalog.pg_namespace n "
"WHERE %s = n.oid AND ",
qualresult,
completion_squery->catname,
completion_squery->namespace);
if (completion_squery->selcondition)
appendPQExpBuffer(&query_buffer, "%s AND ",
completion_squery->selcondition);
appendPQExpBuffer(&query_buffer, "substring(pg_catalog.quote_ident(n.nspname) || '.' || %s,1,%d)='%s'",
qualresult,
string_length, e_text);
/*
*
* Th
* i
* s
*
* co
* n
* d
* i
* t
* i
* o
* n
*
* ex
* p
* l
* o
* i
* t
* s
*
* th
* e
*
* si
* n
* g
* l
* e
* -
* m
* a
* t
* c
* h
* i
* n
* g
* -
* s
* c
* h
* e
* m
* a
*
* ru
* l
* e
*
* to
*
* sp
* e
* e
* d
*
* up
*
* th
* e
*
* qu
* e
* r
* y
* */
appendPQExpBuffer(&query_buffer,
" AND substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d) ="
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(n.nspname))+1)",
string_length, e_text);
appendPQExpBuffer(&query_buffer,
" AND (SELECT pg_catalog.count(*)"
" FROM pg_catalog.pg_namespace"
" WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) ="
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) = 1",
string_length, e_text);
/*
* I
* f
*
* an
*
* ad
* d
* o
* n
*
* qu
* e
* r
* y
*
* wa
* s
*
* pr
* o
* v
* i
* d
* e
* d
* ,
*
* us
* e
*
* it
*
*/
if (completion_charp)
appendPQExpBuffer(&query_buffer, "\n%s", completion_charp);
}
else
{
/*
* c
* o
* m
* p
* l
* e
* t
* i
* o
* n
* _
* c
* h
* a
* r
* p
*
* is
*
* an
*
* sp
* r
* i
* n
* t
* f
* -
* s
* t
* y
* l
* e
*
* fo
* r
* m
* a
* t
*
* st
* r
* i
* n
* g
*
*/
appendPQExpBuffer(&query_buffer, completion_charp,
string_length, e_text, e_info_charp);
}
/*
* L
* i
* m
* i
* t
*
* th
* e
*
* nu
* m
* b
* e
* r
*
* of
*
* re
* c
* o
* r
* d
* s
*
* in
*
* th
* e
*
* re
* s
* u
* l
* t
*
*/
appendPQExpBuffer(&query_buffer, "\nLIMIT %d",
completion_max_records);
result = exec_query(query_buffer.data);
termPQExpBuffer(&query_buffer);
free(e_text);
if (e_info_charp)
free(e_info_charp);
}
/*
* F
* i
* n
* d
*
* so
* m
* e
* t
* h
* i
* n
* g
*
* th
* a
* t
*
* ma
* t
* c
* h
* e
* s
*
*/
if (result && PQresultStatus(result) == PGRES_TUPLES_OK)
{
const char *item;
while (list_index < PQntuples(result) &&
(item = PQgetvalue(result, list_index++, 0)))
if (pg_strncasecmp(text, item, string_length) == 0)
return pg_strdup(item);
}
/*
* I
* f
*
* no
* t
* h
* i
* n
* g
*
* ma
* t
* c
* h
* e
* s
* ,
*
* fr
* e
* e
*
* th
* e
*
* db
*
* st
* r
* u
* c
* t
* u
* r
* e
*
* an
* d
*
* re
* t
* u
* r
* n
*
* nu
* l
* l
*
*/
PQclear(result);
result = NULL;
return NULL;
}
/* This function returns in order one of a fixed, NULL pointer terminated list /* This function returns in order one of a fixed, NULL pointer terminated list
of strings (if matching). This can be used if there are only a fixed number of strings (if matching). This can be used if there are only a fixed number
SQL words that can appear at certain spot. SQL words that can appear at certain spot.
*/ */
static char * static char *
complete_from_list(const char *text, int state) complete_from_list(const char *text, int state)
{ {
static int string_length, static int string_length,
list_index, list_index,
matches; matches;
static bool casesensitive; static bool casesensitive;
const char *item; const char *item;
/* /* need to have a list */
* n psql_assert(completion_charpp);
* e
* e /* Initialization */
* d if (state == 0)
* {
* to list_index = 0;
* string_length = strlen(text);
* ha casesensitive = true;
* v matches = 0;
* e }
*
* a while ((item = completion_charpp[list_index++]))
* li {
* s /* First pass is case sensitive */
* t if (casesensitive && strncmp(text, item, string_length) == 0)
* {
*/ matches++;
psql_assert(completion_charpp); return pg_strdup(item);
}
/*
* I /* Second pass is case insensitive, don't bother counting matches */
* n if (!casesensitive && pg_strncasecmp(text, item, string_length) == 0)
* i return pg_strdup(item);
* t }
* i
* a /*
* l * No matches found. If we're not case insensitive already, lets switch to
* i * being case insensitive and try again
* z */
* a if (casesensitive && matches == 0)
* t {
* i casesensitive = false;
* o list_index = 0;
* n state++;
* return (complete_from_list(text, state));
*/ }
if (state == 0)
{ /* If no more matches, return null. */
list_index = 0; return NULL;
string_length = strlen(text); }
casesensitive = true;
matches = 0;
}
while ((item = completion_charpp[list_index++]))
{
/*
* F
* i
* r
* s
* t
*
* pa
* s
* s
*
* is
*
* ca
* s
* e
*
* se
* n
* s
* i
* t
* i
* v
* e
*
*/
if (casesensitive && strncmp(text, item, string_length) == 0)
{
matches++;
return pg_strdup(item);
}
/*
* S
* e
* c
* o
* n
* d
*
* pa
* s
* s
*
* is
*
* ca
* s
* e
*
* in
* s
* e
* n
* s
* i
* t
* i
* v
* e
* ,
*
* do
* n
* '
* t
*
* bo
* t
* h
* e
* r
*
* co
* u
* n
* t
* i
* n
* g
*
* ma
* t
* c
* h
* e
* s
*
*/
if (!casesensitive && pg_strncasecmp(text, item, string_length) == 0)
return pg_strdup(item);
}
/*
*
* No
*
* ma
* t
* c
* h
* e
* s
*
* fo
* u
* n
* d
* .
*
* If
*
* we
* '
* r
* e
*
* no
* t
*
* ca
* s
* e
*
* in
* s
* e
* n
* s
* i
* t
* i
* v
* e
*
* al
* r
* e
* a
* d
* y
* ,
*
* le
* t
* s
*
* sw
* i
* t
* c
* h
*
* to
*
* be
* i
* n
* g
*
* ca
* s
* e
*
* in
* s
* e
* n
* s
* i
* t
* i
* v
* e
*
* an
* d
*
* tr
* y
*
* ag
* a
* i
* n
* */
if (casesensitive && matches == 0)
{
casesensitive = false;
list_index = 0;
state++;
return (complete_from_list(text, state));
}
/*
* I
* f
*
* no
*
* mo
* r
* e
*
* ma
* t
* c
* h
* e
* s
* ,
*
* re
* t
* u
* r
* n
*
* nu
* l
* l
* .
*
*/
return NULL;
}
/* This function returns one fixed string the first time even if it doesn't /* This function returns one fixed string the first time even if it doesn't
...@@ -3654,19 +2135,18 @@ psql_completion(char *text, int start, int end) ...@@ -3654,19 +2135,18 @@ psql_completion(char *text, int start, int end)
will be overwritten. will be overwritten.
The string to be passed must be in completion_charp. The string to be passed must be in completion_charp.
*/ */
static char * static char *
complete_from_const(const char *text, int state) complete_from_const(const char *text, int state)
{ {
(void) text; /* We don't care about (void) text; /* We don't care about what was entered
* what was entered * already. */
* already. */
psql_assert(completion_charp); psql_assert(completion_charp);
if (state == 0) if (state == 0)
return pg_strdup(completion_charp); return pg_strdup(completion_charp);
else else
return NULL; return NULL;
} }
...@@ -3677,28 +2157,28 @@ psql_completion(char *text, int start, int end) ...@@ -3677,28 +2157,28 @@ psql_completion(char *text, int start, int end)
* Execute a query and report any errors. This should be the preferred way of * Execute a query and report any errors. This should be the preferred way of
* talking to the database in this file. * talking to the database in this file.
*/ */
static PGresult * static PGresult *
exec_query(const char *query) exec_query(const char *query)
{ {
PGresult *result; PGresult *result;
if (query == NULL || !pset.db || PQstatus(pset.db) != CONNECTION_OK) if (query == NULL || !pset.db || PQstatus(pset.db) != CONNECTION_OK)
return NULL; return NULL;
result = PQexec(pset.db, query); result = PQexec(pset.db, query);
if (result != NULL && PQresultStatus(result) != PGRES_TUPLES_OK) if (result != NULL && PQresultStatus(result) != PGRES_TUPLES_OK)
{ {
#if 0 #if 0
psql_error("tab completion: %s failed - %s\n", psql_error("tab completion: %s failed - %s\n",
query, PQresStatus(PQresultStatus(result))); query, PQresStatus(PQresultStatus(result)));
#endif #endif
PQclear(result); PQclear(result);
result = NULL; result = NULL;
} }
return result; return result;
} }
...@@ -3707,344 +2187,61 @@ psql_completion(char *text, int start, int end) ...@@ -3707,344 +2187,61 @@ psql_completion(char *text, int start, int end)
* skip that many words; e.g. skip=1 finds the word before the * skip that many words; e.g. skip=1 finds the word before the
* previous one. Return value is NULL or a malloc'ed string. * previous one. Return value is NULL or a malloc'ed string.
*/ */
static char * static char *
previous_word(int point, int skip) previous_word(int point, int skip)
{ {
int i, int i,
start = 0, start = 0,
end = -1, end = -1,
inquotes = 0; inquotes = 0;
char *s; char *s;
while (skip-- >= 0) while (skip-- >= 0)
{ {
/* /* first we look for a space before the current word */
* f for (i = point; i >= 0; i--)
* i if (rl_line_buffer[i] == ' ')
* r break;
* s
* t /* now find the first non-space which then constitutes the end */
* for (; i >= 0; i--)
* we if (rl_line_buffer[i] != ' ')
* {
* lo end = i;
* o break;
* k }
*
* fo /*
* r * If no end found we return null, because there is no word before the
* * point
* a */
* sp if (end == -1)
* a return NULL;
* c
* e /*
* * Otherwise we now look for the start. The start is either the last
* be * character before any space going backwards from the end, or it's
* f * simply character 0
* o */
* r for (start = end; start > 0; start--)
* e {
* if (rl_line_buffer[start] == '"')
* th inquotes = !inquotes;
* e if ((rl_line_buffer[start - 1] == ' ') && inquotes == 0)
* break;
* cu }
* r
* r point = start;
* e }
* n
* t /* make a copy */
* s = pg_malloc(end - start + 2);
* wo
* r strncpy(s, &rl_line_buffer[start], end - start + 1);
* d s[end - start + 1] = '\0';
*
*/ return s;
for (i = point; i >= 0; i--) }
if (rl_line_buffer[i] == ' ')
break;
/*
* n
* o
* w
*
* fi
* n
* d
*
* th
* e
*
* fi
* r
* s
* t
*
* no
* n
* -
* s
* p
* a
* c
* e
*
* wh
* i
* c
* h
*
* th
* e
* n
*
* co
* n
* s
* t
* i
* t
* u
* t
* e
* s
*
* th
* e
*
* en
* d
*
*/
for (; i >= 0; i--)
if (rl_line_buffer[i] != ' ')
{
end = i;
break;
}
/*
*
* If
*
* no
*
* en
* d
*
* fo
* u
* n
* d
*
* we
*
* re
* t
* u
* r
* n
*
* nu
* l
* l
* ,
*
* be
* c
* a
* u
* s
* e
*
* th
* e
* r
* e
*
* is
*
* no
*
* wo
* r
* d
*
* be
* f
* o
* r
* e
*
* th
* e
*
* po
* i
* n
* t
* */
if (end == -1)
return NULL;
/*
*
* Ot
* h
* e
* r
* w
* i
* s
* e
*
* we
*
* no
* w
*
* lo
* o
* k
*
* fo
* r
*
* th
* e
*
* st
* a
* r
* t
* .
*
* Th
* e
*
* st
* a
* r
* t
*
* is
*
* ei
* t
* h
* e
* r
*
* th
* e
*
* la
* s
* t
*
* ch
* a
* r
* a
* c
* t
* e
* r
*
* be
* f
* o
* r
* e
*
* an
* y
*
* sp
* a
* c
* e
*
* go
* i
* n
* g
*
* ba
* c
* k
* w
* a
* r
* d
* s
*
* fr
* o
* m
*
* th
* e
*
* en
* d
* ,
*
* or
*
* it
* '
* s
*
* si
* m
* p
* l
* y
*
* ch
* a
* r
* a
* c
* t
* e
* r
*
* 0
*/
for (start = end; start > 0; start--)
{
if (rl_line_buffer[start] == '"')
inquotes = !inquotes;
if ((rl_line_buffer[start - 1] == ' ') && inquotes == 0)
break;
}
point = start;
}
/*
* m
* a
* k
* e
*
* a
* co
* p
* y
*
*/
s = pg_malloc(end - start + 2);
strncpy(s, &rl_line_buffer[start], end - start + 1);
s[end - start + 1] = '\0';
return s;
}
...@@ -4055,42 +2252,42 @@ psql_completion(char *text, int start, int end) ...@@ -4055,42 +2252,42 @@ psql_completion(char *text, int start, int end)
* psql internal. Currently disabled because it is reported not to * psql internal. Currently disabled because it is reported not to
* cooperate with certain versions of readline. * cooperate with certain versions of readline.
*/ */
static char * static char *
quote_file_name(char *text, int match_type, char *quote_pointer) quote_file_name(char *text, int match_type, char *quote_pointer)
{ {
char *s; char *s;
size_t length; size_t length;
(void) quote_pointer; /* not used */ (void) quote_pointer; /* not used */
length = strlen(text) +(match_type == SINGLE_MATCH ? 3 : 2); length = strlen(text) +(match_type == SINGLE_MATCH ? 3 : 2);
s = pg_malloc(length); s = pg_malloc(length);
s[0] = '\''; s[0] = '\'';
strcpy(s + 1, text); strcpy(s + 1, text);
if (match_type == SINGLE_MATCH) if (match_type == SINGLE_MATCH)
s[length - 2] = '\''; s[length - 2] = '\'';
s[length - 1] = '\0'; s[length - 1] = '\0';
return s; return s;
} }
static char * static char *
dequote_file_name(char *text, char quote_char) dequote_file_name(char *text, char quote_char)
{ {
char *s; char *s;
size_t length; size_t length;
if (!quote_char) if (!quote_char)
return pg_strdup(text); return pg_strdup(text);
length = strlen(text); length = strlen(text);
s = pg_malloc(length - 2 + 1); s = pg_malloc(length - 2 + 1);
strncpy(s, text +1, length - 2); strncpy(s, text +1, length - 2);
s[length] = '\0'; s[length] = '\0';
return s; return s;
} }
#endif /* 0 */ #endif /* 0 */
#endif /* USE_READLINE */ #endif /* USE_READLINE */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment