diff options
author | Bruce Momjian | 2004-08-29 05:07:03 +0000 |
---|---|---|
committer | Bruce Momjian | 2004-08-29 05:07:03 +0000 |
commit | b6b71b85bc45b49005b5aec87cba2c33fc8baf49 (patch) | |
tree | c23dbd1dbc43972a8e48327c8a771baf36952f3d /src/bin/psql | |
parent | 90cb9c305140684b2b00c739b724f67915e11404 (diff) |
Pgindent run for 8.0.
Diffstat (limited to 'src/bin/psql')
-rw-r--r-- | src/bin/psql/command.c | 28 | ||||
-rw-r--r-- | src/bin/psql/command.h | 4 | ||||
-rw-r--r-- | src/bin/psql/common.c | 58 | ||||
-rw-r--r-- | src/bin/psql/copy.c | 46 | ||||
-rw-r--r-- | src/bin/psql/describe.c | 95 | ||||
-rw-r--r-- | src/bin/psql/help.c | 8 | ||||
-rw-r--r-- | src/bin/psql/input.c | 12 | ||||
-rw-r--r-- | src/bin/psql/mainloop.c | 16 | ||||
-rw-r--r-- | src/bin/psql/print.c | 24 | ||||
-rw-r--r-- | src/bin/psql/prompt.c | 26 | ||||
-rw-r--r-- | src/bin/psql/psqlscan.h | 14 | ||||
-rw-r--r-- | src/bin/psql/settings.h | 4 | ||||
-rw-r--r-- | src/bin/psql/startup.c | 34 | ||||
-rw-r--r-- | src/bin/psql/tab-complete.c | 227 |
14 files changed, 309 insertions, 287 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index cc00575fba5..220299bf2bd 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.124 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.125 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "command.h" @@ -44,8 +44,8 @@ /* functions for use in this file */ static backslashResult exec_command(const char *cmd, - PsqlScanState scan_state, - PQExpBuffer query_buf); + PsqlScanState scan_state, + PQExpBuffer query_buf); static bool do_edit(const char *filename_arg, PQExpBuffer query_buf); static bool do_connect(const char *new_dbname, const char *new_user); static bool do_shell(const char *command); @@ -92,7 +92,7 @@ HandleSlashCmds(PsqlScanState scan_state, * one-letter command with immediately following argument (a * still-supported, but no longer encouraged, syntax). */ - char new_cmd[2]; + char new_cmd[2]; /* don't change cmd until we know it's okay */ new_cmd[0] = cmd[0]; @@ -266,7 +266,7 @@ exec_command(const char *cmd, else if (pg_strcasecmp(cmd, "copy") == 0) { char *opt = psql_scan_slash_option(scan_state, - OT_WHOLE_LINE, NULL, false); + OT_WHOLE_LINE, NULL, false); success = do_copy(opt); free(opt); @@ -397,7 +397,7 @@ exec_command(const char *cmd, fout = stdout; while ((value = psql_scan_slash_option(scan_state, - OT_NORMAL, "ed, false))) + OT_NORMAL, "ed, false))) { if (!quoted && strcmp(value, "-n") == 0) no_newline = true; @@ -419,7 +419,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "encoding") == 0) { char *encoding = psql_scan_slash_option(scan_state, - OT_NORMAL, NULL, false); + OT_NORMAL, NULL, false); if (!encoding) { @@ -447,7 +447,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "f") == 0) { char *fname = psql_scan_slash_option(scan_state, - OT_NORMAL, NULL, false); + OT_NORMAL, NULL, false); success = do_pset("fieldsep", fname, &pset.popt, quiet); free(fname); @@ -457,7 +457,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "g") == 0) { char *fname = psql_scan_slash_option(scan_state, - OT_FILEPIPE, NULL, false); + OT_FILEPIPE, NULL, false); if (!fname) pset.gfname = NULL; @@ -474,7 +474,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "h") == 0 || strcmp(cmd, "help") == 0) { char *opt = psql_scan_slash_option(scan_state, - OT_WHOLE_LINE, NULL, false); + OT_WHOLE_LINE, NULL, false); helpSQL(opt, pset.popt.topt.pager); free(opt); @@ -582,7 +582,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "o") == 0 || strcmp(cmd, "out") == 0) { char *fname = psql_scan_slash_option(scan_state, - OT_FILEPIPE, NULL, true); + OT_FILEPIPE, NULL, true); expand_tilde(&fname); success = setQFout(fname); @@ -710,7 +710,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "T") == 0) { char *value = psql_scan_slash_option(scan_state, - OT_NORMAL, NULL, false); + OT_NORMAL, NULL, false); success = do_pset("tableattr", value, &pset.popt, quiet); free(value); @@ -822,7 +822,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "z") == 0) { char *pattern = psql_scan_slash_option(scan_state, - OT_NORMAL, NULL, true); + OT_NORMAL, NULL, true); success = permissionsList(pattern); if (pattern) @@ -833,7 +833,7 @@ exec_command(const char *cmd, else if (strcmp(cmd, "!") == 0) { char *opt = psql_scan_slash_option(scan_state, - OT_WHOLE_LINE, NULL, false); + OT_WHOLE_LINE, NULL, false); success = do_shell(opt); free(opt); diff --git a/src/bin/psql/command.h b/src/bin/psql/command.h index 2899111e83d..8149d93396b 100644 --- a/src/bin/psql/command.h +++ b/src/bin/psql/command.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.h,v 1.20 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.h,v 1.21 2004/08/29 05:06:54 momjian Exp $ */ #ifndef COMMAND_H #define COMMAND_H @@ -26,7 +26,7 @@ typedef enum _backslashResult extern backslashResult HandleSlashCmds(PsqlScanState scan_state, - PQExpBuffer query_buf); + PQExpBuffer query_buf); extern int process_file(char *filename); diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 0d0eadee904..b3e0bbfb8d6 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.89 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.90 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -57,7 +57,6 @@ typedef struct _timeb TimevalStruct; #define DIFF_MSEC(T, U) \ (((T)->time - (U)->time) * 1000.0 + \ ((T)->millitm - (U)->millitm)) - #endif extern bool prompt_state; @@ -358,10 +357,19 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query) int loc = 0; const char *sp; - int clen, slen, i, *qidx, *scridx, qoffset, scroffset, ibeg, iend, - loc_line; - char *wquery; - bool beg_trunc, end_trunc; + int clen, + slen, + i, + *qidx, + *scridx, + qoffset, + scroffset, + ibeg, + iend, + loc_line; + char *wquery; + bool beg_trunc, + end_trunc; PQExpBufferData msg; if (pset.verbosity == PQERRORS_TERSE) @@ -420,17 +428,17 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query) psql_assert(clen < slen); /* convert loc to zero-based offset in qidx/scridx arrays */ - loc--; + loc--; /* do we have something to show? */ if (loc >= 0 && loc <= clen) { - /* input line number of our syntax error. */ + /* input line number of our syntax error. */ loc_line = 1; /* first included char of extract. */ - ibeg = 0; + ibeg = 0; /* last-plus-1 included char of extract. */ - iend = clen; + iend = clen; /* * Replace tabs with spaces in the writable copy. (Later we might @@ -438,31 +446,31 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query) * but not today.) * * Extract line number and begin and end indexes of line containing - * error location. There will not be any newlines or carriage + * error location. There will not be any newlines or carriage * returns in the selected extract. */ - for (i=0; i<clen; i++) + for (i = 0; i < clen; i++) { /* character length must be 1 or it's not ASCII */ - if ((qidx[i+1]-qidx[i]) == 1) + if ((qidx[i + 1] - qidx[i]) == 1) { - if (wquery[qidx[i]] == '\t') + if (wquery[qidx[i]] == '\t') wquery[qidx[i]] = ' '; else if (wquery[qidx[i]] == '\r' || wquery[qidx[i]] == '\n') { if (i < loc) { /* - * count lines before loc. Each \r or \n counts + * count lines before loc. Each \r or \n counts * as a line except when \r \n appear together. */ if (wquery[qidx[i]] == '\r' || i == 0 || - (qidx[i]-qidx[i-1]) != 1 || - wquery[qidx[i-1]] != '\r') + (qidx[i] - qidx[i - 1]) != 1 || + wquery[qidx[i - 1]] != '\r') loc_line++; /* extract beginning = last line start before loc. */ - ibeg = i+1; + ibeg = i + 1; } else { @@ -478,30 +486,30 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query) /* If the line extracted is too long, we truncate it. */ beg_trunc = false; end_trunc = false; - if (scridx[iend]-scridx[ibeg] > DISPLAY_SIZE) + if (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE) { /* * We first truncate right if it is enough. This code might * be off a space or so on enforcing MIN_RIGHT_CUT if there's * a wide character right there, but that should be okay. */ - if (scridx[ibeg]+DISPLAY_SIZE >= scridx[loc]+MIN_RIGHT_CUT) + if (scridx[ibeg] + DISPLAY_SIZE >= scridx[loc] + MIN_RIGHT_CUT) { - while (scridx[iend]-scridx[ibeg] > DISPLAY_SIZE) + while (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE) iend--; end_trunc = true; } else { /* Truncate right if not too close to loc. */ - while (scridx[loc]+MIN_RIGHT_CUT < scridx[iend]) + while (scridx[loc] + MIN_RIGHT_CUT < scridx[iend]) { iend--; end_trunc = true; } /* Truncate left if still too long. */ - while (scridx[iend]-scridx[ibeg] > DISPLAY_SIZE) + while (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE) { ibeg++; beg_trunc = true; @@ -510,7 +518,7 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query) } /* the extract MUST contain the target position! */ - psql_assert(ibeg<=loc && loc<=iend); + psql_assert(ibeg <= loc && loc <= iend); /* truncate working copy at desired endpoint */ wquery[qidx[iend]] = '\0'; @@ -526,9 +534,7 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query) */ scroffset = 0; for (i = 0; i < msg.len; i += PQmblen(&msg.data[i], pset.encoding)) - { scroffset += PQdsplen(&msg.data[i], pset.encoding); - } /* Finish and emit the message. */ appendPQExpBufferStr(&msg, &wquery[qidx[ibeg]]); diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 8dbb091b95a..bf7aad15d49 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.53 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.54 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "copy.h" @@ -70,8 +70,8 @@ struct copy_options char *null; char *quote; char *escape; - char *force_quote_list; - char *force_notnull_list; + char *force_quote_list; + char *force_notnull_list; }; @@ -232,7 +232,7 @@ parse_slash_copy(const char *args) result->file = NULL; } else if (pg_strcasecmp(token, "pstdin") == 0 || - pg_strcasecmp(token, "pstdout") == 0) + pg_strcasecmp(token, "pstdout") == 0) { result->psql_inout = true; result->file = NULL; @@ -271,8 +271,8 @@ parse_slash_copy(const char *args) if (token) { /* - * WITH is optional. Also, the backend will allow WITH followed by - * nothing, so we do too. + * WITH is optional. Also, the backend will allow WITH followed + * by nothing, so we do too. */ if (pg_strcasecmp(token, "with") == 0) token = strtokx(NULL, whitespace, NULL, NULL, @@ -280,19 +280,15 @@ parse_slash_copy(const char *args) while (token) { - bool fetch_next; + bool fetch_next; fetch_next = true; - + /* someday allow BINARY here */ if (pg_strcasecmp(token, "oids") == 0) - { result->oids = true; - } else if (pg_strcasecmp(token, "csv") == 0) - { result->csv_mode = true; - } else if (pg_strcasecmp(token, "delimiter") == 0) { token = strtokx(NULL, whitespace, NULL, "'", @@ -434,7 +430,7 @@ do_copy(const char *args) PGresult *result; bool success; struct stat st; - + /* parse options */ options = parse_slash_copy(args); @@ -483,10 +479,8 @@ do_copy(const char *args) } if (options->csv_mode) - { appendPQExpBuffer(&query, " CSV"); - } - + if (options->quote) { if (options->quote[0] == '\'') @@ -504,14 +498,10 @@ do_copy(const char *args) } if (options->force_quote_list) - { appendPQExpBuffer(&query, " FORCE QUOTE %s", options->force_quote_list); - } if (options->force_notnull_list) - { appendPQExpBuffer(&query, " FORCE NOT NULL %s", options->force_notnull_list); - } if (options->file) canonicalize_path(options->file); @@ -521,16 +511,16 @@ do_copy(const char *args) if (options->file) copystream = fopen(options->file, PG_BINARY_R); else if (!options->psql_inout) - copystream = pset.cur_cmd_source; + copystream = pset.cur_cmd_source; else - copystream = stdin; + copystream = stdin; } else { if (options->file) copystream = fopen(options->file, "w"); else if (!options->psql_inout) - copystream = pset.queryFout; + copystream = pset.queryFout; else copystream = stdout; } @@ -578,7 +568,7 @@ do_copy(const char *args) PQclear(result); - if (options->file != NULL) + if (options->file != NULL) { if (fclose(copystream) != 0) { @@ -676,13 +666,11 @@ handleCopyIn(PGconn *conn, FILE *copystream) { if (!QUIET()) puts(gettext("Enter data to be copied followed by a newline.\n" - "End with a backslash and a period on a line by itself.")); + "End with a backslash and a period on a line by itself.")); prompt = get_prompt(PROMPT_COPY); } else - { prompt = NULL; - } while (!copydone) { /* for each input line ... */ @@ -720,8 +708,8 @@ handleCopyIn(PGconn *conn, FILE *copystream) if (c == EOF && s == copybuf && firstload) { /* - * We are guessing a little bit as to the right line-ending - * here... + * We are guessing a little bit as to the right + * line-ending here... */ if (saw_cr) PQputline(conn, "\\.\r\n"); diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 30b8443ca6e..2596688815f 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.105 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.106 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -39,8 +39,8 @@ static void processNamePattern(PQExpBuffer buf, const char *pattern, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule); -static void add_tablespace_footer(char relkind, Oid tablespace, - char **footers, int *count, PQExpBufferData buf); +static void add_tablespace_footer(char relkind, Oid tablespace, + char **footers, int *count, PQExpBufferData buf); /*---------------- * Handlers for various slash commands displaying some sort of list @@ -112,25 +112,26 @@ describeTablespaces(const char *pattern, bool verbose) PGresult *res; printQueryOpt myopt = pset.popt; - if (pset.sversion < 70500) { - fprintf(stderr, _("This server version (%d) does not support tablespaces.\n"), - pset.sversion); - return true; + if (pset.sversion < 70500) + { + fprintf(stderr, _("This server version (%d) does not support tablespaces.\n"), + pset.sversion); + return true; } initPQExpBuffer(&buf); printfPQExpBuffer(&buf, "SELECT spcname AS \"%s\",\n" - " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n" + " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n" " spclocation AS \"%s\"", _("Name"), _("Owner"), _("Location")); if (verbose) appendPQExpBuffer(&buf, - ",\n spcacl as \"%s\"", - _("Access privileges")); - + ",\n spcacl as \"%s\"", + _("Access privileges")); + appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_tablespace\n"); @@ -697,7 +698,7 @@ describeOneTableDetails(const char *schemaname, char relkind; bool hasindex; bool hasrules; - bool hasoids; + bool hasoids; Oid tablespace; } tableinfo; bool show_modifiers = false; @@ -711,8 +712,8 @@ describeOneTableDetails(const char *schemaname, /* Get general table info */ printfPQExpBuffer(&buf, - "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n" - "relhasoids %s \n" + "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n" + "relhasoids %s \n" "FROM pg_catalog.pg_class WHERE oid = '%s'", pset.sversion >= 70500 ? ", reltablespace" : "", oid); @@ -736,8 +737,8 @@ describeOneTableDetails(const char *schemaname, tableinfo.hasindex = strcmp(PQgetvalue(res, 0, 0), "t") == 0; tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 4), "t") == 0; tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0; - tableinfo.tablespace = (pset.sversion >= 70500) ? - atooid(PQgetvalue(res, 0, 6)) : 0; + tableinfo.tablespace = (pset.sversion >= 70500) ? + atooid(PQgetvalue(res, 0, 6)) : 0; PQclear(res); headers[0] = _("Column"); @@ -895,8 +896,8 @@ describeOneTableDetails(const char *schemaname, PGresult *result; printfPQExpBuffer(&buf, - "SELECT i.indisunique, i.indisprimary, i.indisclustered, a.amname, c2.relname,\n" - " pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n" + "SELECT i.indisunique, i.indisprimary, i.indisclustered, a.amname, c2.relname,\n" + " pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n" "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n" "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n" "AND i.indrelid = c2.oid", @@ -941,7 +942,7 @@ describeOneTableDetails(const char *schemaname, footers = pg_malloc_zero(4 * sizeof(*footers)); footers[count_footers++] = pg_strdup(tmpbuf.data); add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace, - footers, &count_footers, tmpbuf); + footers, &count_footers, tmpbuf); footers[count_footers] = NULL; } @@ -1020,8 +1021,8 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.hasindex) { printfPQExpBuffer(&buf, - "SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, " - "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)\n" + "SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, " + "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)\n" "FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n" "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n" "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname", @@ -1038,10 +1039,10 @@ describeOneTableDetails(const char *schemaname, { printfPQExpBuffer(&buf, "SELECT " - "pg_catalog.pg_get_constraintdef(r.oid, true), " + "pg_catalog.pg_get_constraintdef(r.oid, true), " "conname\n" "FROM pg_catalog.pg_constraint r\n" - "WHERE r.conrelid = '%s' AND r.contype = 'c'", + "WHERE r.conrelid = '%s' AND r.contype = 'c'", oid); result2 = PSQLexec(buf.data, false); if (!result2) @@ -1102,7 +1103,7 @@ describeOneTableDetails(const char *schemaname, { printfPQExpBuffer(&buf, "SELECT conname,\n" - " pg_catalog.pg_get_constraintdef(oid, true) as condef\n" + " pg_catalog.pg_get_constraintdef(oid, true) as condef\n" "FROM pg_catalog.pg_constraint r\n" "WHERE r.conrelid = '%s' AND r.contype = 'f'", oid); @@ -1255,14 +1256,15 @@ describeOneTableDetails(const char *schemaname, if (verbose) { - char *s = _("Contains OIDs"); + char *s = _("Contains OIDs"); + printfPQExpBuffer(&buf, "%s: %s", s, (tableinfo.hasoids ? _("yes") : _("no"))); footers[count_footers++] = pg_strdup(buf.data); } add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace, - footers, &count_footers, buf); + footers, &count_footers, buf); /* end of list marker */ footers[count_footers] = NULL; @@ -1315,29 +1317,30 @@ error_return: static void -add_tablespace_footer(char relkind, Oid tablespace, char **footers, - int *count, PQExpBufferData buf) +add_tablespace_footer(char relkind, Oid tablespace, char **footers, + int *count, PQExpBufferData buf) { /* relkinds for which we support tablespaces */ - if(relkind == 'r' || relkind == 'i') + if (relkind == 'r' || relkind == 'i') { /* * We ignore the database default tablespace so that users not * using tablespaces don't need to know about them. */ - if(tablespace != 0) + if (tablespace != 0) { PGresult *result1 = NULL; + printfPQExpBuffer(&buf, "SELECT spcname FROM pg_tablespace \n" - "WHERE oid = '%u';", tablespace); + "WHERE oid = '%u';", tablespace); result1 = PSQLexec(buf.data, false); - if (!result1) + if (!result1) return; /* Should always be the case, but.... */ - if(PQntuples(result1) > 0) + if (PQntuples(result1) > 0) { printfPQExpBuffer(&buf, _("Tablespace: \"%s\""), - PQgetvalue(result1, 0, 0)); + PQgetvalue(result1, 0, 0)); footers[(*count)++] = pg_strdup(buf.data); } PQclear(result1); @@ -1716,21 +1719,21 @@ listSchemas(const char *pattern, bool verbose) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT n.nspname AS \"%s\",\n" - " u.usename AS \"%s\"", - _("Name"), _("Owner")); - + "SELECT n.nspname AS \"%s\",\n" + " u.usename AS \"%s\"", + _("Name"), _("Owner")); + if (verbose) appendPQExpBuffer(&buf, - ",\n n.nspacl as \"%s\"," - " pg_catalog.obj_description(n.oid, 'pg_namespace') as \"%s\"", - _("Access privileges"), _("Description")); - + ",\n n.nspacl as \"%s\"," + " pg_catalog.obj_description(n.oid, 'pg_namespace') as \"%s\"", + _("Access privileges"), _("Description")); + appendPQExpBuffer(&buf, - "\nFROM pg_catalog.pg_namespace n LEFT JOIN pg_catalog.pg_user u\n" - " ON n.nspowner=u.usesysid\n" - "WHERE (n.nspname NOT LIKE 'pg\\\\_temp\\\\_%%' OR\n" - " n.nspname = (pg_catalog.current_schemas(true))[1])\n"); /* temp schema is first */ + "\nFROM pg_catalog.pg_namespace n LEFT JOIN pg_catalog.pg_user u\n" + " ON n.nspowner=u.usesysid\n" + "WHERE (n.nspname NOT LIKE 'pg\\\\_temp\\\\_%%' OR\n" + " n.nspname = (pg_catalog.current_schemas(true))[1])\n"); /* temp schema is first */ processNamePattern(&buf, pattern, true, false, NULL, "n.nspname", NULL, diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index a11074baa18..24d2c8f59f1 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.92 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.93 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -237,7 +237,7 @@ slashUsage(unsigned short int pager) fprintf(output, _(" \\pset NAME [VALUE]\n" " set table output option\n" " (NAME := {format|border|expanded|fieldsep|footer|null|\n" - " recordsep|tuples_only|title|tableattr|pager})\n")); + " recordsep|tuples_only|title|tableattr|pager})\n")); fprintf(output, _(" \\t show only rows (currently %s)\n"), ON(pset.popt.topt.tuples_only)); fprintf(output, _(" \\T [STRING] set HTML <table> tag attributes, or unset if none\n")); @@ -250,7 +250,7 @@ slashUsage(unsigned short int pager) fprintf(output, _(" \\lo_export LOBOID FILE\n" " \\lo_import FILE [COMMENT] \n" " \\lo_list\n" - " \\lo_unlink LOBOID large object operations\n")); + " \\lo_unlink LOBOID large object operations\n")); if (output != stdout) { @@ -308,7 +308,7 @@ helpSQL(const char *topic, unsigned short int pager) FILE *output; size_t len; int nl_count = 0; - char *ch; + char *ch; /* don't care about trailing spaces or semicolons */ len = strlen(topic); diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index 9fcaccc9b90..072df4abcee 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.36 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.37 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "input.h" @@ -171,7 +171,7 @@ initializeInput(int flags) #ifdef USE_READLINE if (flags & 1) { - char home[MAXPGPATH]; + char home[MAXPGPATH]; useReadline = true; initialize_readline(); @@ -182,7 +182,7 @@ initializeInput(int flags) using_history(); if (get_home_path(home)) { - char *psql_history; + char *psql_history; psql_history = pg_malloc(strlen(home) + 1 + strlen(PSQLHISTORY) + 1); @@ -230,12 +230,12 @@ finishInput(int exitstatus, void *arg) #ifdef USE_READLINE if (useHistory) { - char home[MAXPGPATH]; + char home[MAXPGPATH]; if (get_home_path(home)) { - char *psql_history; - int hist_size; + char *psql_history; + int hist_size; psql_history = pg_malloc(strlen(home) + 1 + strlen(PSQLHISTORY) + 1); diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c index 5de64b217d4..c555710a347 100644 --- a/src/bin/psql/mainloop.c +++ b/src/bin/psql/mainloop.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.63 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.64 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "mainloop.h" @@ -45,6 +45,7 @@ MainLoop(FILE *source) volatile promptStatus_t prompt_status = PROMPT_READY; volatile int count_eof = 0; volatile bool die_on_error = false; + /* Save the prior command source */ FILE *prev_cmd_source; bool prev_cmd_interactive; @@ -107,9 +108,7 @@ MainLoop(FILE *source) prompt_status = PROMPT_READY; if (pset.cur_cmd_interactive) - { putc('\n', stdout); - } else { successResult = EXIT_USER; @@ -245,10 +244,11 @@ MainLoop(FILE *source) /* handle backslash command */ /* - * If we added a newline to query_buf, and nothing else has - * been inserted in query_buf by the lexer, then strip off - * the newline again. This avoids any change to query_buf - * when a line contains only a backslash command. + * If we added a newline to query_buf, and nothing else + * has been inserted in query_buf by the lexer, then strip + * off the newline again. This avoids any change to + * query_buf when a line contains only a backslash + * command. */ if (query_buf->len == added_nl_pos) query_buf->data[--query_buf->len] = '\0'; @@ -256,7 +256,7 @@ MainLoop(FILE *source) slashCmdStatus = HandleSlashCmds(scan_state, query_buf->len > 0 ? - query_buf : previous_buf); + query_buf : previous_buf); success = slashCmdStatus != CMD_ERROR; diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 7d710240d9d..f4347252690 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.50 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.51 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -389,7 +389,11 @@ print_aligned_text(const char *title, const char *const * headers, fprintf(fout, "%s\n", *ptr); #ifndef __MINGW32__ - /* for some reason MinGW outputs an extra newline, so this supresses it */ + + /* + * for some reason MinGW outputs an extra newline, so this supresses + * it + */ fputc('\n', fout); #endif @@ -839,15 +843,15 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border, fputs("\\begin{tabular}{", fout); if (opt_border == 2) - fputs("| ", fout); - for (i = 0; i < col_count; i++) + fputs("| ", fout); + for (i = 0; i < col_count; i++) { - fputc(*(opt_align + i), fout); - if (opt_border != 0 && i < col_count - 1) - fputs (" | ", fout); + fputc(*(opt_align + i), fout); + if (opt_border != 0 && i < col_count - 1) + fputs(" | ", fout); } if (opt_border == 2) - fputs(" |", fout); + fputs(" |", fout); fputs("}\n", fout); @@ -861,9 +865,9 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border, { if (i != 0) fputs(" & ", fout); - fputs("\\textit{", fout); + fputs("\\textit{", fout); latex_escaped_print(*ptr, fout); - fputc('}', fout); + fputc('}', fout); } } diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c index 912eb00888d..909adb37b19 100644 --- a/src/bin/psql/prompt.c +++ b/src/bin/psql/prompt.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.36 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.37 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" #include "prompt.h" @@ -289,18 +289,20 @@ get_prompt(promptStatus_t status) break; } - case '[': - case ']': + case '[': + case ']': #if defined(USE_READLINE) && defined(RL_PROMPT_START_IGNORE) - /* - * readline >=4.0 undocumented feature: non-printing - * characters in prompt strings must be marked as such, - * in order to properly display the line during editing. - */ - buf[0] = '\001'; - buf[1] = (*p == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE; -#endif /* USE_READLINE */ - break; + + /* + * readline >=4.0 undocumented feature: non-printing + * characters in prompt strings must be marked as + * such, in order to properly display the line during + * editing. + */ + buf[0] = '\001'; + buf[1] = (*p == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE; +#endif /* USE_READLINE */ + break; default: buf[0] = *p; diff --git a/src/bin/psql/psqlscan.h b/src/bin/psql/psqlscan.h index 8c0b963a1e7..a4cb945a239 100644 --- a/src/bin/psql/psqlscan.h +++ b/src/bin/psql/psqlscan.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/psqlscan.h,v 1.2 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/psqlscan.h,v 1.3 2004/08/29 05:06:54 momjian Exp $ */ #ifndef PSQLSCAN_H #define PSQLSCAN_H @@ -40,12 +40,12 @@ extern PsqlScanState psql_scan_create(void); extern void psql_scan_destroy(PsqlScanState state); extern void psql_scan_setup(PsqlScanState state, - const char *line, int line_len); + const char *line, int line_len); extern void psql_scan_finish(PsqlScanState state); extern PsqlScanResult psql_scan(PsqlScanState state, - PQExpBuffer query_buf, - promptStatus_t *prompt); + PQExpBuffer query_buf, + promptStatus_t *prompt); extern void psql_scan_reset(PsqlScanState state); @@ -54,9 +54,9 @@ extern bool psql_scan_in_quote(PsqlScanState state); extern char *psql_scan_slash_command(PsqlScanState state); extern char *psql_scan_slash_option(PsqlScanState state, - enum slash_option_type type, - char *quote, - bool semicolon); + enum slash_option_type type, + char *quote, + bool semicolon); extern void psql_scan_slash_command_end(PsqlScanState state); diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index b5bbb937ea1..2c44b3133fb 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.20 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.21 2004/08/29 05:06:54 momjian Exp $ */ #ifndef SETTINGS_H #define SETTINGS_H @@ -41,7 +41,7 @@ typedef struct _psqlSettings FILE *cur_cmd_source; /* describe the status of the current main * loop */ bool cur_cmd_interactive; - int sversion; /* backend server version */ + int sversion; /* backend server version */ const char *progname; /* in case you renamed psql */ char *inputfile; /* for error reporting */ unsigned lineno; /* also for error reporting */ diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 8e94ced3637..e1be68b145d 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.98 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.99 2004/08/29 05:06:54 momjian Exp $ */ #include "postgres_fe.h" @@ -45,7 +45,7 @@ int optreset; PsqlSettings pset; #define SYSPSQLRC "psqlrc" -#define PSQLRC ".psqlrc" +#define PSQLRC ".psqlrc" /* * Structures to pass information between the option parsing routine @@ -121,7 +121,7 @@ main(int argc, char *argv[]) } #ifdef WIN32 - setvbuf(stderr,NULL,_IONBF,0); + setvbuf(stderr, NULL, _IONBF, 0); #endif pset.cur_cmd_source = stdin; pset.cur_cmd_interactive = false; @@ -287,7 +287,7 @@ main(int argc, char *argv[]) "Type: \\copyright for distribution terms\n" " \\h for help with SQL commands\n" " \\? for help with psql commands\n" - " \\g or terminate with semicolon to execute query\n" + " \\g or terminate with semicolon to execute query\n" " \\q to quit\n\n"), pset.progname, PG_VERSION); #ifdef USE_SSL @@ -574,10 +574,10 @@ static void process_psqlrc(char *argv0) { char *psqlrc; - char home[MAXPGPATH]; - char global_file[MAXPGPATH]; - char my_exec_path[MAXPGPATH]; - char etc_path[MAXPGPATH]; + char home[MAXPGPATH]; + char global_file[MAXPGPATH]; + char my_exec_path[MAXPGPATH]; + char etc_path[MAXPGPATH]; find_my_exec(argv0, my_exec_path); get_etc_path(my_exec_path, etc_path); @@ -610,7 +610,7 @@ process_psqlrc_file(char *filename) if (access(psqlrc, R_OK) == 0) process_file(psqlrc); else if (access(filename, R_OK) == 0) - process_file(filename); + process_file(filename); free(psqlrc); } @@ -652,7 +652,6 @@ printSSLInfo(void) printf(gettext("SSL connection (cipher: %s, bits: %i)\n\n"), SSL_get_cipher(ssl), sslbits); } - #endif @@ -666,15 +665,18 @@ printSSLInfo(void) static void checkWin32Codepage(void) { - unsigned int wincp, concp; + unsigned int wincp, + concp; wincp = GetACP(); concp = GetConsoleCP(); - if (wincp != concp) { - printf("Warning: Console codepage (%u) differs from windows codepage (%u)\n" - " 8-bit characters will not work correctly. See PostgreSQL\n" - " documentation \"Installation on Windows\" for details.\n\n", - concp, wincp); + if (wincp != concp) + { + printf("Warning: Console codepage (%u) differs from windows codepage (%u)\n" + " 8-bit characters will not work correctly. See PostgreSQL\n" + " documentation \"Installation on Windows\" for details.\n\n", + concp, wincp); } } + #endif diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index c2d2bfc2542..76449bceea7 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.113 2004/08/29 04:13:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.114 2004/08/29 05:06:54 momjian Exp $ */ /*---------------------------------------------------------------------- @@ -81,28 +81,35 @@ typedef struct SchemaQuery * "pg_catalog.pg_class c". Note that "pg_namespace n" will be added. */ const char *catname; + /* - * Selection condition --- only rows meeting this condition are candidates - * to display. If catname mentions multiple tables, include the - * necessary join condition here. For example, "c.relkind = 'r'". - * Write NULL (not an empty string) if not needed. + * Selection condition --- only rows meeting this condition are + * candidates to display. If catname mentions multiple tables, + * include the necessary join condition here. For example, "c.relkind + * = 'r'". Write NULL (not an empty string) if not needed. */ const char *selcondition; + /* * Visibility condition --- which rows are visible without schema - * qualification? For example, "pg_catalog.pg_table_is_visible(c.oid)". + * qualification? For example, + * "pg_catalog.pg_table_is_visible(c.oid)". */ const char *viscondition; + /* - * Namespace --- name of field to join to pg_namespace.oid. - * For example, "c.relnamespace". + * Namespace --- name of field to join to pg_namespace.oid. For + * example, "c.relnamespace". */ const char *namespace; + /* * Result --- the appropriately-quoted name to return, in the case of - * an unqualified name. For example, "pg_catalog.quote_ident(c.relname)". + * an unqualified name. For example, + * "pg_catalog.quote_ident(c.relname)". */ const char *result; + /* * In some cases a different result must be used for qualified names. * Enter that here, or write NULL if result can be used. @@ -121,9 +128,10 @@ static int completion_max_records; * the completion callback functions. Ugly but there is no better way. */ static const char *completion_charp; /* to pass a string */ -static const char * const *completion_charpp; /* to pass a list of strings */ -static const char *completion_info_charp; /* to pass a second string */ -static const SchemaQuery *completion_squery; /* to pass a SchemaQuery */ +static const char *const * completion_charpp; /* to pass a list of + * strings */ +static const char *completion_info_charp; /* to pass a second string */ +static const SchemaQuery *completion_squery; /* to pass a SchemaQuery */ /* A couple of macros to ease typing. You can use these to complete the given string with @@ -306,7 +314,7 @@ static const SchemaQuery Query_for_list_of_views = { * restricted to names matching a partially entered name. In these queries, * %s will be replaced by the text entered so far (suitably escaped to * become a SQL literal string). %d will be replaced by the length of the - * string (in unescaped form). A second %s, if present, will be replaced + * string (in unescaped form). A second %s, if present, will be replaced * by a suitably-escaped version of the string provided in * completion_info_charp. * @@ -401,17 +409,17 @@ static const pgsql_thing_t words_after_create[] = { {"GROUP", "SELECT pg_catalog.quote_ident(groname) FROM pg_catalog.pg_group WHERE substring(pg_catalog.quote_ident(groname),1,%d)='%s'"}, {"LANGUAGE", Query_for_list_of_languages}, {"INDEX", NULL, &Query_for_list_of_indexes}, - {"OPERATOR", NULL, NULL}, /* Querying for this is probably - * not such a good idea. */ + {"OPERATOR", NULL, NULL}, /* Querying for this is probably not such + * a good idea. */ {"RULE", "SELECT pg_catalog.quote_ident(rulename) FROM pg_catalog.pg_rules WHERE substring(pg_catalog.quote_ident(rulename),1,%d)='%s'"}, {"SCHEMA", Query_for_list_of_schemas}, {"SEQUENCE", NULL, &Query_for_list_of_sequences}, {"TABLE", NULL, &Query_for_list_of_tables}, {"TABLESPACE", Query_for_list_of_tablespaces}, - {"TEMP", NULL, NULL}, /* for CREATE TEMP TABLE ... */ + {"TEMP", NULL, NULL}, /* for CREATE TEMP TABLE ... */ {"TRIGGER", "SELECT pg_catalog.quote_ident(tgname) FROM pg_catalog.pg_trigger WHERE substring(pg_catalog.quote_ident(tgname),1,%d)='%s'"}, {"TYPE", NULL, &Query_for_list_of_datatypes}, - {"UNIQUE", NULL, NULL}, /* for CREATE UNIQUE INDEX ... */ + {"UNIQUE", NULL, NULL}, /* for CREATE UNIQUE INDEX ... */ {"USER", Query_for_list_of_users}, {"VIEW", NULL, &Query_for_list_of_views}, {NULL, NULL, NULL} /* end of list */ @@ -442,7 +450,7 @@ static char *dequote_file_name(char *text, char quote_char); void initialize_readline(void) { - rl_readline_name = (char *)pset.progname; + rl_readline_name = (char *) pset.progname; rl_attempted_completion_function = (void *) psql_completion; rl_basic_word_break_characters = "\t\n@$><=;|&{( "; @@ -473,15 +481,15 @@ psql_completion(char *text, int start, int end) *prev3_wd, *prev4_wd; - static const char * const sql_commands[] = { + static const char *const sql_commands[] = { "ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", "CLUSTER", "COMMENT", "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE", "DELETE", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH", "GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", - "PREPARE", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK", "SAVEPOINT", - "SELECT", "SET", "SHOW", "START", "TRUNCATE", "UNLISTEN", "UPDATE", "VACUUM", NULL + "PREPARE", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK", "SAVEPOINT", + "SELECT", "SET", "SHOW", "START", "TRUNCATE", "UNLISTEN", "UPDATE", "VACUUM", NULL }; - static const char * const pgsql_variables[] = { + static const char *const pgsql_variables[] = { /* these SET arguments are known in gram.y */ "CONSTRAINTS", "NAMES", @@ -587,7 +595,7 @@ psql_completion(char *text, int start, int end) NULL }; - static const char * const backslash_commands[] = { + static const char *const backslash_commands[] = { "\\a", "\\connect", "\\C", "\\cd", "\\copy", "\\copyright", "\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\df", "\\dg", "\\di", "\\dl", "\\dn", "\\do", "\\dp", "\\ds", "\\dS", @@ -646,19 +654,19 @@ psql_completion(char *text, int start, int end) pg_strcasecmp(prev3_wd, "TABLE") != 0) { static const char *const list_ALTER[] = - {"AGGREGATE", "CONVERSATION", "DATABASE","DOMAIN", "FUNCTION", - "GROUP", "INDEX", "LANGUAGE", "OPERATOR", "SCHEMA", "SEQUENCE", "TABLE", + {"AGGREGATE", "CONVERSATION", "DATABASE", "DOMAIN", "FUNCTION", + "GROUP", "INDEX", "LANGUAGE", "OPERATOR", "SCHEMA", "SEQUENCE", "TABLE", "TABLESPACE", "TRIGGER", "TYPE", "USER", NULL}; COMPLETE_WITH_LIST(list_ALTER); } - + /* ALTER AGGREGATE,CONVERSION,FUNCTION,SCHEMA <name> */ else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 && (pg_strcasecmp(prev2_wd, "AGGREGATE") == 0 || - pg_strcasecmp(prev2_wd, "CONVERSION") == 0 || - pg_strcasecmp(prev2_wd, "FUNCTION") == 0 || - pg_strcasecmp(prev2_wd, "SCHEMA") == 0 )) + pg_strcasecmp(prev2_wd, "CONVERSION") == 0 || + pg_strcasecmp(prev2_wd, "FUNCTION") == 0 || + pg_strcasecmp(prev2_wd, "SCHEMA") == 0)) { static const char *const list_ALTERGEN[] = {"OWNER TO", "RENAME TO", NULL}; @@ -682,7 +690,7 @@ psql_completion(char *text, int start, int end) { static const char *const list_ALTERINDEX[] = {"SET TABLESPACE", "OWNER TO", "RENAME TO", NULL}; - + COMPLETE_WITH_LIST(list_ALTERINDEX); } @@ -763,11 +771,11 @@ psql_completion(char *text, int start, int end) pg_strcasecmp(prev_wd, "COLUMN") == 0) COMPLETE_WITH_ATTR(prev3_wd); else if (pg_strcasecmp(prev3_wd, "TABLE") == 0 && - pg_strcasecmp(prev_wd, "CLUSTER") == 0) + pg_strcasecmp(prev_wd, "CLUSTER") == 0) COMPLETE_WITH_CONST("ON"); else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 && - pg_strcasecmp(prev2_wd, "CLUSTER") == 0 && - pg_strcasecmp(prev_wd, "ON") == 0) + pg_strcasecmp(prev2_wd, "CLUSTER") == 0 && + pg_strcasecmp(prev_wd, "ON") == 0) { completion_info_charp = prev3_wd; COMPLETE_WITH_QUERY(Query_for_index_of_table); @@ -781,16 +789,16 @@ psql_completion(char *text, int start, int end) COMPLETE_WITH_LIST(list_TABLESET); } - /* If we have TABLE <sth> SET TABLESPACE provide a list of tablespaces*/ + /* If we have TABLE <sth> SET TABLESPACE provide a list of tablespaces */ else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 && pg_strcasecmp(prev2_wd, "SET") == 0 && pg_strcasecmp(prev_wd, "TABLESPACE") == 0) COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); - /* If we have TABLE <sth> SET WITHOUT provide CLUSTER or OIDS*/ + /* If we have TABLE <sth> SET WITHOUT provide CLUSTER or OIDS */ else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 && pg_strcasecmp(prev2_wd, "SET") == 0 && pg_strcasecmp(prev_wd, "WITHOUT") == 0) - { + { static const char *const list_TABLESET2[] = {"CLUSTER", "OIDS", NULL}; @@ -841,35 +849,38 @@ psql_completion(char *text, int start, int end) /* BEGIN, END, COMMIT, ABORT */ else if (pg_strcasecmp(prev_wd, "BEGIN") == 0 || - pg_strcasecmp(prev_wd, "END") == 0 || - pg_strcasecmp(prev_wd, "COMMIT") == 0 || - pg_strcasecmp(prev_wd, "ABORT") == 0) + pg_strcasecmp(prev_wd, "END") == 0 || + pg_strcasecmp(prev_wd, "COMMIT") == 0 || + pg_strcasecmp(prev_wd, "ABORT") == 0) { - static const char * const list_TRANS[] = + static const char *const list_TRANS[] = {"WORK", "TRANSACTION", NULL}; COMPLETE_WITH_LIST(list_TRANS); } /* RELEASE SAVEPOINT */ - else if ( pg_strcasecmp(prev_wd, "RELEASE") == 0 ) + else if (pg_strcasecmp(prev_wd, "RELEASE") == 0) COMPLETE_WITH_CONST("SAVEPOINT"); /* ROLLBACK*/ - else if ( pg_strcasecmp(prev_wd, "ROLLBACK") == 0 ) + else if (pg_strcasecmp(prev_wd, "ROLLBACK") == 0) { - static const char * const list_TRANS[] = + static const char *const list_TRANS[] = {"WORK", "TRANSACTION", "TO SAVEPOINT", NULL}; COMPLETE_WITH_LIST(list_TRANS); } /* CLUSTER */ - /* If the previous word is CLUSTER and not without produce list - * of indexes. */ + + /* + * If the previous word is CLUSTER and not without produce list of + * indexes. + */ else if (pg_strcasecmp(prev_wd, "CLUSTER") == 0 && - pg_strcasecmp(prev2_wd, "WITHOUT") != 0) + pg_strcasecmp(prev2_wd, "WITHOUT") != 0) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL); /* If we have CLUSTER <sth>, then add "ON" */ - else if (pg_strcasecmp(prev2_wd, "CLUSTER") == 0 && - pg_strcasecmp(prev_wd,"ON") != 0) + else if (pg_strcasecmp(prev2_wd, "CLUSTER") == 0 && + pg_strcasecmp(prev_wd, "ON") != 0) COMPLETE_WITH_CONST("ON"); /* @@ -891,8 +902,8 @@ psql_completion(char *text, int start, int end) { static const char *const list_COMMENT[] = {"CAST", "CONVERSION", "DATABASE", "INDEX", "LANGUAGE", "RULE", "SCHEMA", - "SEQUENCE", "TABLE", "TYPE", "VIEW", "COLUMN", "AGGREGATE", "FUNCTION", - "OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", NULL}; + "SEQUENCE", "TABLE", "TYPE", "VIEW", "COLUMN", "AGGREGATE", "FUNCTION", + "OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", NULL}; COMPLETE_WITH_LIST(list_COMMENT); } @@ -1046,7 +1057,7 @@ psql_completion(char *text, int start, int end) else if (pg_strcasecmp(prev_wd, "FETCH") == 0 || pg_strcasecmp(prev_wd, "MOVE") == 0) { - static const char * const list_FETCH1[] = + static const char *const list_FETCH1[] = {"ABSOLUT", "BACKWARD", "FORWARD", "RELATIVE", NULL}; COMPLETE_WITH_LIST(list_FETCH1); @@ -1055,7 +1066,7 @@ psql_completion(char *text, int start, int end) else if (pg_strcasecmp(prev2_wd, "FETCH") == 0 || pg_strcasecmp(prev2_wd, "MOVE") == 0) { - static const char * const list_FETCH2[] = + static const char *const list_FETCH2[] = {"ALL", "NEXT", "PRIOR", NULL}; COMPLETE_WITH_LIST(list_FETCH2); @@ -1068,7 +1079,7 @@ psql_completion(char *text, int start, int end) else if (pg_strcasecmp(prev3_wd, "FETCH") == 0 || pg_strcasecmp(prev3_wd, "MOVE") == 0) { - static const char * const list_FROMTO[] = + static const char *const list_FROMTO[] = {"FROM", "TO", NULL}; COMPLETE_WITH_LIST(list_FROMTO); @@ -1079,9 +1090,9 @@ psql_completion(char *text, int start, int end) else if (pg_strcasecmp(prev_wd, "GRANT") == 0 || pg_strcasecmp(prev_wd, "REVOKE") == 0) { - static const char * const list_privileg[] = + static const char *const list_privileg[] = {"SELECT", "INSERT", "UPDATE", "DELETE", "RULE", "REFERENCES", - "TRIGGER", "CREATE", "TEMPORARY", "EXECUTE", "USAGE", "ALL", NULL}; + "TRIGGER", "CREATE", "TEMPORARY", "EXECUTE", "USAGE", "ALL", NULL}; COMPLETE_WITH_LIST(list_privileg); } @@ -1157,7 +1168,7 @@ psql_completion(char *text, int start, int end) else if (pg_strcasecmp(prev3_wd, "INSERT") == 0 && pg_strcasecmp(prev2_wd, "INTO") == 0) { - static const char * const list_INSERT[] = + static const char *const list_INSERT[] = {"DEFAULT VALUES", "SELECT", "VALUES", NULL}; COMPLETE_WITH_LIST(list_INSERT); @@ -1167,7 +1178,7 @@ psql_completion(char *text, int start, int end) pg_strcasecmp(prev3_wd, "INTO") == 0 && prev_wd[strlen(prev_wd) - 1] == ')') { - static const char * const list_INSERT[] = + static const char *const list_INSERT[] = {"SELECT", "VALUES", NULL}; COMPLETE_WITH_LIST(list_INSERT); @@ -1200,12 +1211,12 @@ psql_completion(char *text, int start, int end) (pg_strcasecmp(prev3_wd, "TABLE") == 0 && pg_strcasecmp(prev4_wd, "LOCK") == 0))) { - static const char * const lock_modes[] = + static const char *const lock_modes[] = {"ACCESS SHARE MODE", - "ROW SHARE MODE", "ROW EXCLUSIVE MODE", - "SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", - "SHARE ROW EXCLUSIVE MODE", - "EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE", NULL}; + "ROW SHARE MODE", "ROW EXCLUSIVE MODE", + "SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", + "SHARE ROW EXCLUSIVE MODE", + "EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE", NULL}; COMPLETE_WITH_LIST(lock_modes); } @@ -1215,12 +1226,12 @@ psql_completion(char *text, int start, int end) COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(relname) FROM pg_catalog.pg_listener WHERE substring(pg_catalog.quote_ident(relname),1,%d)='%s'"); /* OWNER TO - complete with available users*/ else if (pg_strcasecmp(prev2_wd, "OWNER") == 0 && - pg_strcasecmp(prev_wd, "TO") == 0) + pg_strcasecmp(prev_wd, "TO") == 0) COMPLETE_WITH_QUERY(Query_for_list_of_users); /* REINDEX */ else if (pg_strcasecmp(prev_wd, "REINDEX") == 0) { - static const char * const list_REINDEX[] = + static const char *const list_REINDEX[] = {"TABLE", "DATABASE", "INDEX", NULL}; COMPLETE_WITH_LIST(list_REINDEX); @@ -1259,7 +1270,7 @@ psql_completion(char *text, int start, int end) && pg_strcasecmp(prev2_wd, "AS") == 0 && pg_strcasecmp(prev_wd, "TRANSACTION") == 0)) { - static const char * const my_list[] = + static const char *const my_list[] = {"ISOLATION", "READ", NULL}; COMPLETE_WITH_LIST(my_list); @@ -1270,7 +1281,7 @@ psql_completion(char *text, int start, int end) || (pg_strcasecmp(prev4_wd, "CHARACTERISTICS") == 0 && pg_strcasecmp(prev3_wd, "AS") == 0)) && (pg_strcasecmp(prev2_wd, "TRANSACTION") == 0 - || pg_strcasecmp(prev2_wd, "WORK") == 0) + || pg_strcasecmp(prev2_wd, "WORK") == 0) && pg_strcasecmp(prev_wd, "ISOLATION") == 0) COMPLETE_WITH_CONST("LEVEL"); else if ((pg_strcasecmp(prev4_wd, "SET") == 0 @@ -1278,41 +1289,41 @@ psql_completion(char *text, int start, int end) || pg_strcasecmp(prev4_wd, "START") == 0 || pg_strcasecmp(prev4_wd, "AS") == 0) && (pg_strcasecmp(prev3_wd, "TRANSACTION") == 0 - || pg_strcasecmp(prev3_wd, "WORK") == 0) + || pg_strcasecmp(prev3_wd, "WORK") == 0) && pg_strcasecmp(prev2_wd, "ISOLATION") == 0 && pg_strcasecmp(prev_wd, "LEVEL") == 0) { - static const char * const my_list[] = + static const char *const my_list[] = {"READ", "REPEATABLE", "SERIALIZABLE", NULL}; COMPLETE_WITH_LIST(my_list); } else if ((pg_strcasecmp(prev4_wd, "TRANSACTION") == 0 || - pg_strcasecmp(prev4_wd, "WORK") == 0) && + pg_strcasecmp(prev4_wd, "WORK") == 0) && pg_strcasecmp(prev3_wd, "ISOLATION") == 0 && pg_strcasecmp(prev2_wd, "LEVEL") == 0 && pg_strcasecmp(prev_wd, "READ") == 0) { - static const char * const my_list[] = + static const char *const my_list[] = {"UNCOMMITTED", "COMMITTED", NULL}; COMPLETE_WITH_LIST(my_list); } - else if ((pg_strcasecmp(prev4_wd, "TRANSACTION") == 0 || - pg_strcasecmp(prev4_wd, "WORK") == 0) && + else if ((pg_strcasecmp(prev4_wd, "TRANSACTION") == 0 || + pg_strcasecmp(prev4_wd, "WORK") == 0) && pg_strcasecmp(prev3_wd, "ISOLATION") == 0 && pg_strcasecmp(prev2_wd, "LEVEL") == 0 && pg_strcasecmp(prev_wd, "REPEATABLE") == 0) COMPLETE_WITH_CONST("READ"); else if ((pg_strcasecmp(prev3_wd, "SET") == 0 || - pg_strcasecmp(prev3_wd, "BEGIN") == 0 || - pg_strcasecmp(prev3_wd, "START") == 0 || - pg_strcasecmp(prev3_wd, "AS") == 0) && + pg_strcasecmp(prev3_wd, "BEGIN") == 0 || + pg_strcasecmp(prev3_wd, "START") == 0 || + pg_strcasecmp(prev3_wd, "AS") == 0) && (pg_strcasecmp(prev2_wd, "TRANSACTION") == 0 || - pg_strcasecmp(prev2_wd, "WORK") == 0) && + pg_strcasecmp(prev2_wd, "WORK") == 0) && pg_strcasecmp(prev_wd, "READ") == 0) { - static const char * const my_list[] = + static const char *const my_list[] = {"ONLY", "WRITE", NULL}; COMPLETE_WITH_LIST(my_list); @@ -1321,7 +1332,7 @@ psql_completion(char *text, int start, int end) else if (pg_strcasecmp(prev3_wd, "SET") == 0 && pg_strcasecmp(prev2_wd, "CONSTRAINTS") == 0) { - static const char * const constraint_list[] = + static const char *const constraint_list[] = {"DEFERRED", "IMMEDIATE", NULL}; COMPLETE_WITH_LIST(constraint_list); @@ -1330,7 +1341,7 @@ psql_completion(char *text, int start, int end) else if (pg_strcasecmp(prev2_wd, "SET") == 0 && pg_strcasecmp(prev_wd, "SESSION") == 0) { - static const char * const my_list[] = + static const char *const my_list[] = {"AUTHORIZATION", "CHARACTERISTICS AS TRANSACTION", NULL}; COMPLETE_WITH_LIST(my_list); @@ -1346,28 +1357,28 @@ psql_completion(char *text, int start, int end) COMPLETE_WITH_CONST("TO"); /* Suggest possible variable values */ else if (pg_strcasecmp(prev3_wd, "SET") == 0 && - (pg_strcasecmp(prev_wd, "TO") == 0 || strcmp(prev_wd, "=") == 0)) + (pg_strcasecmp(prev_wd, "TO") == 0 || strcmp(prev_wd, "=") == 0)) { if (pg_strcasecmp(prev2_wd, "DateStyle") == 0) { - static const char * const my_list[] = + static const char *const my_list[] = {"ISO", "SQL", "Postgres", "German", - "YMD", "DMY", "MDY", - "US", "European", "NonEuropean", - "DEFAULT", NULL}; + "YMD", "DMY", "MDY", + "US", "European", "NonEuropean", + "DEFAULT", NULL}; COMPLETE_WITH_LIST(my_list); } else if (pg_strcasecmp(prev2_wd, "GEQO") == 0) { - static const char * const my_list[] = + static const char *const my_list[] = {"ON", "OFF", "DEFAULT", NULL}; COMPLETE_WITH_LIST(my_list); } else { - static const char * const my_list[] = + static const char *const my_list[] = {"DEFAULT", NULL}; COMPLETE_WITH_LIST(my_list); @@ -1463,10 +1474,10 @@ psql_completion(char *text, int start, int end) COMPLETE_WITH_LIST(sql_commands); else if (strcmp(prev_wd, "\\pset") == 0) { - static const char * const my_list[] = + static const char *const my_list[] = {"format", "border", "expanded", - "null", "fieldsep", "tuples_only", "title", "tableattr", "pager", - "recordsep", NULL}; + "null", "fieldsep", "tuples_only", "title", "tableattr", "pager", + "recordsep", NULL}; COMPLETE_WITH_LIST(my_list); } @@ -1631,7 +1642,7 @@ _complete_from_query(int is_schema_query, const char *text, int state) /* Set up suitably-escaped copies of textual inputs */ if (text) { - e_text = pg_malloc(strlen(text) * 2 + 1); + e_text = pg_malloc(strlen(text) *2 + 1); PQescapeString(e_text, text, strlen(text)); } else @@ -1639,7 +1650,7 @@ _complete_from_query(int is_schema_query, const char *text, int state) if (completion_info_charp) { - size_t charp_len; + size_t charp_len; charp_len = strlen(completion_info_charp); e_info_charp = pg_malloc(charp_len * 2 + 1); @@ -1671,27 +1682,29 @@ _complete_from_query(int is_schema_query, const char *text, int state) appendPQExpBuffer(&query_buffer, "substring(%s,1,%d)='%s'", completion_squery->result, string_length, e_text); + /* - * When fetching relation names, suppress system catalogs unless - * the input-so-far begins with "pg_". This is a compromise - * between not offering system catalogs for completion at all, - * and having them swamp the result when the input is just "p". + * When fetching relation names, suppress system catalogs + * unless the input-so-far begins with "pg_". This is a + * compromise between not offering system catalogs for + * completion at all, and having them swamp the result when + * the input is just "p". */ if (strcmp(completion_squery->catname, "pg_catalog.pg_class c") == 0 && - strncmp(text, "pg_", 3) != 0) + strncmp(text, "pg_", 3) !=0) { appendPQExpBuffer(&query_buffer, - " AND c.relnamespace <> (SELECT oid FROM" - " pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')"); + " AND c.relnamespace <> (SELECT oid FROM" + " pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')"); } /* - * Add in matching schema names, but only if there is more than - * one potential match among schema names. + * Add in matching schema names, but only if there is more + * than one potential match among schema names. */ appendPQExpBuffer(&query_buffer, "\nUNION\n" - "SELECT pg_catalog.quote_ident(n.nspname) || '.' " + "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); @@ -1703,11 +1716,11 @@ _complete_from_query(int is_schema_query, const char *text, int state) string_length, e_text); /* - * Add in matching qualified names, but only if there is exactly - * one schema matching the input-so-far. + * Add in matching qualified names, but only if there is + * exactly one schema matching the input-so-far. */ appendPQExpBuffer(&query_buffer, "\nUNION\n" - "SELECT pg_catalog.quote_ident(n.nspname) || '.' || %s " + "SELECT pg_catalog.quote_ident(n.nspname) || '.' || %s " "FROM %s, pg_catalog.pg_namespace n " "WHERE %s = n.oid AND ", qualresult, @@ -1719,7 +1732,11 @@ _complete_from_query(int is_schema_query, const char *text, int state) appendPQExpBuffer(&query_buffer, "substring(pg_catalog.quote_ident(n.nspname) || '.' || %s,1,%d)='%s'", qualresult, string_length, e_text); - /* This condition exploits the single-matching-schema rule to speed up the query */ + + /* + * This condition exploits the single-matching-schema rule to + * speed up the query + */ 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)", |