33 *
44 * Copyright 2000 by PostgreSQL Global Development Group
55 *
6- * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.36 2003/03/18 22: 15:44 petere Exp $
6+ * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.37 2003/04/04 15:48:38 tgl Exp $
77 */
88#include "postgres_fe.h"
99#include "common.h"
@@ -283,13 +283,11 @@ print_aligned_text(const char *title, const char *const * headers,
283283/* print title */
284284if (title && !opt_barebones )
285285{
286- int tlen ;
287-
288- tlen = pg_wcswidth ((unsignedchar * )title ,strlen (title ),encoding );
289- if (tlen >= (int )total_w )
286+ tmp = pg_wcswidth ((unsignedchar * )title ,strlen (title ),encoding );
287+ if (tmp >=total_w )
290288fprintf (fout ,"%s\n" ,title );
291289else
292- fprintf (fout ,"%-*s%s\n" , (( int ) total_w - tlen ) /2 ,"" ,title );
290+ fprintf (fout ,"%-*s%s\n" , (total_w - tmp ) /2 ,"" ,title );
293291}
294292
295293/* print headers */
@@ -305,7 +303,7 @@ print_aligned_text(const char *title, const char *const * headers,
305303
306304for (i = 0 ;i < col_count ;i ++ )
307305{
308- int nbspace ;
306+ unsigned int nbspace ;
309307
310308nbspace = widths [i ]- head_w [i ];
311309
@@ -420,18 +418,27 @@ print_aligned_vertical(const char *title, const char *const * headers,
420418/* count headers and find longest one */
421419for (ptr = headers ;* ptr ;ptr ++ )
422420col_count ++ ;
423- head_w = calloc (col_count ,sizeof (* head_w ));
424- if (!head_w )
421+ if (col_count > 0 )
425422{
426- perror ("calloc" );
427- exit (EXIT_FAILURE );
423+ head_w = calloc (col_count ,sizeof (* head_w ));
424+ if (!head_w )
425+ {
426+ perror ("calloc" );
427+ exit (EXIT_FAILURE );
428+ }
428429}
430+ else
431+ head_w = NULL ;
432+
429433for (i = 0 ;i < col_count ;i ++ )
430434{
431- if ((tmp = pg_wcswidth ((unsignedchar * )headers [i ],strlen (headers [i ]),encoding ))> hwidth )
435+ tmp = pg_wcswidth ((unsignedchar * )headers [i ],strlen (headers [i ]),encoding );
436+ if (tmp > hwidth )
432437hwidth = tmp ;
433438head_w [i ]= tmp ;
434439}
440+
441+ /* Count cells, find their lengths */
435442for (ptr = cells ;* ptr ;ptr ++ )
436443cell_count ++ ;
437444
@@ -445,12 +452,13 @@ print_aligned_vertical(const char *title, const char *const * headers,
445452}
446453}
447454else
448- cell_w = 0 ;
455+ cell_w = NULL ;
449456
450457/* find longest data cell */
451458for (i = 0 ,ptr = cells ;* ptr ;ptr ++ ,i ++ )
452459{
453- if ((tmp = pg_wcswidth ((unsignedchar * )* ptr ,strlen (* ptr ),encoding ))> dwidth )
460+ tmp = pg_wcswidth ((unsignedchar * )* ptr ,strlen (* ptr ),encoding );
461+ if (tmp > dwidth )
454462dwidth = tmp ;
455463cell_w [i ]= tmp ;
456464}
@@ -480,7 +488,6 @@ print_aligned_vertical(const char *title, const char *const * headers,
480488if (opt_border == 2 )
481489strcat (divider ,"-+" );
482490
483-
484491/* print records */
485492for (i = 0 ,ptr = cells ;* ptr ;i ++ ,ptr ++ )
486493{
@@ -544,7 +551,6 @@ print_aligned_vertical(const char *title, const char *const * headers,
544551if (opt_border == 2 )
545552fprintf (fout ,"%s\n" ,divider );
546553
547-
548554/* print footers */
549555
550556if (!opt_barebones && footers && * footers )