From 2a24ec6f167a21ef074609e165d77f1f7c715259 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 11 Nov 1999 00:10:14 +0000 Subject: In the spirit of TODO item * Add use of 'const' for varibles in source tree (which is misspelled, btw.) I went through the front-end libpq code and did so. This affects in particular the various accessor functions (such as PQdb() and PQgetvalue()) as well as, by necessity, the internal helpers they use. I have been really thorough in that regard, perhaps some people will find it annoying that things like char * foo = PQgetvalue(res, 0, 0) will generate a warning. On the other hand it _should_ generate one. This is no real compatibility break, although a few clients will have to be fixed to suppress warnings. (Which again would be in the spirit of the above TODO.) In addition I replaced some int's by size_t's and removed some warnings (and generated some new ones -- grmpf!). Also I rewrote PQoidStatus (so it actually honors the const!) and supplied a new function PQoidValue that returns a proper Oid type. This is only front-end stuff, none of the communicaton stuff was touched. The psql patch also adds some new consts to honor the new libpq situation, as well as fixes a fatal condition that resulted when using the -V (--version) option and there is no database listening. So, to summarize, the psql you should definitely put in (with or without the libpq). If you think I went too far with the const-mania in libpq, let me know and I'll make adjustments. If you approve it, I will also update the docs. -Peter -- Peter Eisentraut Sernanders vaeg 10:115 --- src/bin/psql/print.c | 74 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 31 deletions(-) (limited to 'src/bin/psql/print.c') diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 5c6525b6f3..90b4f59d61 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -28,13 +28,14 @@ static void -print_unaligned_text(const char *title, char **headers, char **cells, char **footers, +print_unaligned_text(const char *title, const char * const * headers, + const char * const * cells, const char * const * footers, const char *opt_fieldsep, bool opt_barebones, FILE *fout) { unsigned int col_count = 0; unsigned int i; - char **ptr; + const char * const * ptr; if (!opt_fieldsep) opt_fieldsep = ""; @@ -80,14 +81,15 @@ print_unaligned_text(const char *title, char **headers, char **cells, char **foo static void -print_unaligned_vertical(const char *title, char **headers, char **cells, char **footers, +print_unaligned_vertical(const char *title, const char * const * headers, + const char * const * cells, const char * const * footers, const char *opt_fieldsep, bool opt_barebones, FILE *fout) { unsigned int col_count = 0; unsigned int i; unsigned int record = 1; - char **ptr; + const char * const * ptr; if (!opt_fieldsep) opt_fieldsep = ""; @@ -167,8 +169,9 @@ _print_horizontal_line(const unsigned int col_count, const unsigned int *widths, static void -print_aligned_text(const char *title, char **headers, char **cells, char **footers, -const char *opt_align, bool opt_barebones, unsigned short int opt_border, +print_aligned_text(const char *title, const char * const * headers, + const char * const * cells, const char * const * footers, + const char *opt_align, bool opt_barebones, unsigned short int opt_border, FILE *fout) { unsigned int col_count = 0; @@ -176,7 +179,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border, tmp; unsigned int *widths, total_w; - char **ptr; + const char * const * ptr; /* count columns */ for (ptr = headers; *ptr; ptr++) @@ -308,13 +311,14 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border, static void -print_aligned_vertical(const char *title, char **headers, char **cells, char **footers, +print_aligned_vertical(const char *title, const char * const * headers, + const char * const * cells, const char * const * footers, bool opt_barebones, unsigned short int opt_border, FILE *fout) { unsigned int col_count = 0; unsigned int record = 1; - char **ptr; + const char * const *ptr; unsigned int i, tmp, hwidth = 0, @@ -471,14 +475,15 @@ html_escaped_print(const char *in, FILE *fout) static void -print_html_text(const char *title, char **headers, char **cells, char **footers, -const char *opt_align, bool opt_barebones, unsigned short int opt_border, - char *opt_table_attr, +print_html_text(const char *title, const char * const * headers, + const char * const * cells, const char * const * footers, + const char *opt_align, bool opt_barebones, unsigned short int opt_border, + const char *opt_table_attr, FILE *fout) { unsigned int col_count = 0; unsigned int i; - char **ptr; + const char * const *ptr; fprintf(fout, "border; FILE *pager = NULL, *output; @@ -868,7 +879,7 @@ printTable(const char *title, char **headers, char **cells, char **footers, unsigned int col_count = 0, row_count = 0, lines; - char **ptr; + const char * const *ptr; int result; struct winsize screen_size; @@ -952,11 +963,11 @@ printTable(const char *title, char **headers, char **cells, char **footers, void -printQuery(PGresult *result, const printQueryOpt * opt, FILE *fout) +printQuery(const PGresult *result, const printQueryOpt * opt, FILE *fout) { int nfields; - char **headers; - char **cells; + const char **headers; + const char **cells; char **footers; char *align; int i; @@ -1043,8 +1054,9 @@ printQuery(PGresult *result, const printQueryOpt * opt, FILE *fout) /* call table printer */ - printTable(opt->title, headers, cells, footers ? footers : opt->footers, align, - &opt->topt, fout); + printTable(opt->title, headers, cells, + footers ? (const char * const *)footers : (const char * const *)(opt->footers), + align, &opt->topt, fout); free(headers); free(cells); -- cgit v1.2.1