On Fri, Feb 10, 2006 at 02:13:26PM -0500, Tom Lane wrote:
> For the most part we say "char" where we can and "unsigned char" only
> where it really matters, which is mostly inside code that's
> encoding-aware anyway.

Well, I've done this and avoided changing any public interfaces. ie the
libpq interface remains unsigned, as does the psql formatting code, but
the printTable stuff only is for the parts that actually do
formatting...

Patch attached. Passes -pedantic on gcc 3.3.5

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Index: src/bin/psql/mbprint.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/mbprint.c,v
retrieving revision 1.19
diff -u -r1.19 mbprint.c
--- src/bin/psql/mbprint.c      10 Feb 2006 00:39:04 -0000      1.19
+++ src/bin/psql/mbprint.c      10 Feb 2006 21:46:49 -0000
@@ -158,11 +158,11 @@
        {
                int chlen, chwidth;
 
-               chlen = PQmblen(pwcs, encoding);
+               chlen = PQmblen( (char*)pwcs, encoding);
                if (chlen > len)
                        break;     /* Invalid string */
                        
-               chwidth = PQdsplen(pwcs, encoding);
+               chwidth = PQdsplen( (char*)pwcs, encoding);
                
                if (chwidth > 0)
                        width += chwidth;
@@ -191,10 +191,10 @@
 
        for (; *pwcs && len > 0; pwcs += chlen)
        {
-               chlen = PQmblen(pwcs, encoding);
+               chlen = PQmblen( (char*)pwcs, encoding);
                if (len < (size_t)chlen)
                        break;
-               w = PQdsplen(pwcs, encoding);
+               w = PQdsplen( (char*)pwcs, encoding);
 
                if (chlen == 1)   /* ASCII char */
                {
@@ -257,14 +257,14 @@
                                chlen = 0;
        int linewidth = 0;
        
-       char *ptr = lines->ptr;   /* Pointer to data area */
+       unsigned char *ptr = lines->ptr;   /* Pointer to data area */
 
        for (; *pwcs && len > 0; pwcs += chlen)
        {
-               chlen = PQmblen(pwcs,encoding);
+               chlen = PQmblen( (char*)pwcs,encoding);
                if (len < (size_t)chlen)
                        break;
-               w = PQdsplen(pwcs,encoding);
+               w = PQdsplen( (char*)pwcs,encoding);
 
                if (chlen == 1)   /* single byte char char */
                {
@@ -282,13 +282,13 @@
                        }
                        else if (*pwcs == '\r')   /* Linefeed */
                        {
-                               strcpy(ptr, "\\r");
+                               strcpy( (char*)ptr, "\\r");
                                linewidth += 2;
                                ptr += 2;
                        }
                        else if (w <= 0)  /* Other control char */
                        {
-                               sprintf(ptr, "\\x%02X", *pwcs);
+                               sprintf( (char*)ptr, "\\x%02X", *pwcs);
                                linewidth += 4;
                                ptr += 4;
                        }
@@ -301,13 +301,13 @@
                else if (w <= 0)  /* Non-ascii control char */
                {
                        if (encoding == PG_UTF8)
-                               sprintf(ptr, "\\u%04X", utf2ucs(pwcs));
+                               sprintf( (char*)ptr, "\\u%04X", utf2ucs(pwcs));
                        else
                                /* This case cannot happen in the current
                                 * code because only UTF-8 signals multibyte
                                 * control characters. But we may need to
                                 * support it at some stage */
-                               sprintf(ptr, "\\u????");
+                               sprintf( (char*)ptr, "\\u????");
                                
                        ptr += 6;
                        linewidth += 6;
Index: src/bin/psql/print.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/print.c,v
retrieving revision 1.81
diff -u -r1.81 print.c
--- src/bin/psql/print.c        10 Feb 2006 15:48:05 -0000      1.81
+++ src/bin/psql/print.c        10 Feb 2006 21:46:49 -0000
@@ -357,8 +357,8 @@
 {
        unsigned int col_count = 0;
        unsigned int cell_count = 0;
-       unsigned int i,
-                               tmp;
+       unsigned int i;
+       int tmp;
        unsigned int *widths,
                                total_w;
        unsigned int *heights;
@@ -588,7 +588,7 @@
                                                         * this_line->width < 
strlen(this_ptr) and we
                                                         * get an overflow */
 
-                                                       char *my_cell = 
format_numeric_locale(this_line->ptr);
+                                                       char *my_cell = 
format_numeric_locale( (char*) this_line->ptr);
                                                        fprintf(fout, "%*s%s", 
widths[i % col_count] - strlen(my_cell), "", my_cell);
                                                        free(my_cell);
                                                }
@@ -665,13 +665,13 @@
        unsigned int record = 1;
        const char *const * ptr;
        unsigned int i,
-                               tmp = 0,
                                hwidth = 0,
                                dwidth = 0,
                                hheight = 1,
                                dheight = 1,
                                hformatsize = 0,
                                dformatsize = 0;
+       int tmp = 0;
        char       *divider;
        unsigned int cell_count = 0;
        struct lineptr *hlineptr, *dlineptr;
@@ -823,7 +823,7 @@
                        {
                                if (opt_align[i % col_count] == 'r' && 
opt_numeric_locale)
                                {
-                                       char *my_cell = 
format_numeric_locale(dlineptr[line_count].ptr);
+                                       char *my_cell = format_numeric_locale( 
(char*) dlineptr[line_count].ptr);
                                        if (opt_border < 2)
                                                fprintf(fout, "%s\n", my_cell);
                                        else
@@ -1753,7 +1753,7 @@
        headers = pg_local_calloc(nfields + 1, sizeof(*headers));
 
        for (i = 0; i < nfields; i++)
-               headers[i] = mbvalidate(PQfname(result, i), opt->topt.encoding);
+               headers[i] = (char*)mbvalidate( (unsigned char*)PQfname(result, 
i), opt->topt.encoding);
 
        /* set cells */
        ncells = PQntuples(result) * nfields;
@@ -1764,7 +1764,7 @@
                if (PQgetisnull(result, i / nfields, i % nfields))
                        cells[i] = opt->nullPrint ? opt->nullPrint : "";
                else
-                       cells[i] = mbvalidate(PQgetvalue(result, i / nfields, i 
% nfields), opt->topt.encoding);
+                       cells[i] = (char*)mbvalidate( (unsigned 
char*)PQgetvalue(result, i / nfields, i % nfields), opt->topt.encoding);
        }
 
        /* set footers */

Attachment: signature.asc
Description: Digital signature

Reply via email to