aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-print.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>1999-11-11 00:10:14 +0000
committerBruce Momjian <bruce@momjian.us>1999-11-11 00:10:14 +0000
commit2a24ec6f167a21ef074609e165d77f1f7c715259 (patch)
tree579eb1fde3baf6cf0edd60d62e3c5bf7a60698cf /src/interfaces/libpq/fe-print.c
parentc6c60302ba45ac89440ec7e2a4e1c5de3a1a61c2 (diff)
downloadpostgresql-2a24ec6f167a21ef074609e165d77f1f7c715259.tar.gz
postgresql-2a24ec6f167a21ef074609e165d77f1f7c715259.zip
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
Diffstat (limited to 'src/interfaces/libpq/fe-print.c')
-rw-r--r--src/interfaces/libpq/fe-print.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c
index 02f3455dcbc..522e1c57006 100644
--- a/src/interfaces/libpq/fe-print.c
+++ b/src/interfaces/libpq/fe-print.c
@@ -9,7 +9,7 @@
* didn't really belong there.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.27 1999/08/31 01:37:37 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.28 1999/11/11 00:10:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -50,16 +50,16 @@ static struct winsize
#endif
-static void do_field(PQprintOpt *po, PGresult *res,
+static void do_field(const PQprintOpt *po, const PGresult *res,
const int i, const int j, const int fs_len,
char **fields,
- const int nFields, char **fieldNames,
+ const int nFields, const char **fieldNames,
unsigned char *fieldNotNum, int *fieldMax,
const int fieldMaxLen, FILE *fout);
-static char *do_header(FILE *fout, PQprintOpt *po, const int nFields,
- int *fieldMax, char **fieldNames, unsigned char *fieldNotNum,
- const int fs_len, PGresult *res);
-static void output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields,
+static char *do_header(FILE *fout, const PQprintOpt *po, const int nFields,
+ int *fieldMax, const char **fieldNames, unsigned char *fieldNotNum,
+ const int fs_len, const PGresult *res);
+static void output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
unsigned char *fieldNotNum, int *fieldMax, char *border,
const int row_index);
static void fill(int length, int max, char filler, FILE *fp);
@@ -79,8 +79,8 @@ static void fill(int length, int max, char filler, FILE *fp);
void
PQprint(FILE *fout,
- PGresult *res,
- PQprintOpt *po)
+ const PGresult *res,
+ const PQprintOpt *po)
{
int nFields;
@@ -95,7 +95,7 @@ PQprint(FILE *fout,
unsigned char *fieldNotNum = NULL;
char *border = NULL;
char **fields = NULL;
- char **fieldNames;
+ const char **fieldNames;
int fieldMaxLen = 0;
int numFieldName;
int fs_len = strlen(po->fieldSep);
@@ -105,7 +105,7 @@ PQprint(FILE *fout,
char *pagerenv;
nTups = PQntuples(res);
- if (!(fieldNames = (char **) calloc(nFields, sizeof(char *))))
+ if (!(fieldNames = (const char **) calloc(nFields, sizeof(char *))))
{
perror("calloc");
exit(1);
@@ -127,7 +127,7 @@ PQprint(FILE *fout,
for (j = 0; j < nFields; j++)
{
int len;
- char *s = (j < numFieldName && po->fieldName[j][0]) ?
+ const char *s = (j < numFieldName && po->fieldName[j][0]) ?
po->fieldName[j] : PQfname(res, j);
fieldNames[j] = s;
@@ -218,7 +218,7 @@ PQprint(FILE *fout,
for (j = 0; j < nFields; j++)
{
- char *s = fieldNames[j];
+ const char *s = fieldNames[j];
fputs(s, fout);
len += strlen(s) + fs_len;
@@ -317,12 +317,12 @@ PQprint(FILE *fout,
*/
void
-PQdisplayTuples(PGresult *res,
- FILE *fp, /* where to send the output */
- int fillAlign, /* pad the fields with spaces */
- const char *fieldSep, /* field separator */
- int printHeader,/* display headers? */
- int quiet
+PQdisplayTuples(const PGresult *res,
+ FILE *fp, /* where to send the output */
+ int fillAlign, /* pad the fields with spaces */
+ const char *fieldSep, /* field separator */
+ int printHeader,/* display headers? */
+ int quiet
)
{
#define DEFAULT_FIELD_SEP " "
@@ -414,12 +414,12 @@ PQdisplayTuples(PGresult *res,
*
*/
void
-PQprintTuples(PGresult *res,
- FILE *fout, /* output stream */
- int PrintAttNames,/* print attribute names or not */
- int TerseOutput, /* delimiter bars or not? */
- int colWidth /* width of column, if 0, use variable
- * width */
+PQprintTuples(const PGresult *res,
+ FILE *fout, /* output stream */
+ int PrintAttNames,/* print attribute names or not */
+ int TerseOutput, /* delimiter bars or not? */
+ int colWidth /* width of column, if 0, use variable
+ * width */
)
{
int nFields;
@@ -475,7 +475,7 @@ PQprintTuples(PGresult *res,
{
for (j = 0; j < nFields; j++)
{
- char *pval = PQgetvalue(res, i, j);
+ const char *pval = PQgetvalue(res, i, j);
fprintf(fout, formatString,
TerseOutput ? "" : "|",
@@ -498,7 +498,7 @@ PQprintTuples(PGresult *res,
* the backend is assumed.
*/
int
-PQmblen(unsigned char *s)
+PQmblen(const unsigned char *s)
{
char *str;
int encoding = -1;
@@ -515,7 +515,7 @@ PQmblen(unsigned char *s)
/* Provide a default definition in case someone calls it anyway */
int
-PQmblen(unsigned char *s)
+PQmblen(const unsigned char *s)
{
return 1;
}
@@ -523,15 +523,15 @@ PQmblen(unsigned char *s)
#endif /* MULTIBYTE */
static void
-do_field(PQprintOpt *po, PGresult *res,
+do_field(const PQprintOpt *po, const PGresult *res,
const int i, const int j, const int fs_len,
char **fields,
- const int nFields, char **fieldNames,
+ const int nFields, char const **fieldNames,
unsigned char *fieldNotNum, int *fieldMax,
const int fieldMaxLen, FILE *fout)
{
- char *pval,
+ const char *pval,
*p;
int plen;
bool skipit;
@@ -641,9 +641,9 @@ do_field(PQprintOpt *po, PGresult *res,
static char *
-do_header(FILE *fout, PQprintOpt *po, const int nFields, int *fieldMax,
- char **fieldNames, unsigned char *fieldNotNum,
- const int fs_len, PGresult *res)
+do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax,
+ const char **fieldNames, unsigned char *fieldNotNum,
+ const int fs_len, const PGresult *res)
{
int j; /* for loop index */
@@ -697,7 +697,7 @@ do_header(FILE *fout, PQprintOpt *po, const int nFields, int *fieldMax,
fputs(po->fieldSep, fout);
for (j = 0; j < nFields; j++)
{
- char *s = PQfname(res, j);
+ const char *s = PQfname(res, j);
if (po->html3)
{
@@ -729,7 +729,7 @@ do_header(FILE *fout, PQprintOpt *po, const int nFields, int *fieldMax,
static void
-output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields,
+output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
unsigned char *fieldNotNum, int *fieldMax, char *border,
const int row_index)
{