3
3
*
4
4
* Copyright 2000 by PostgreSQL Global Development Group
5
5
*
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 $
7
7
*/
8
8
#include "postgres_fe.h"
9
9
#include "common.h"
@@ -283,13 +283,11 @@ print_aligned_text(const char *title, const char *const * headers,
283
283
/* print title */
284
284
if (title && !opt_barebones )
285
285
{
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 )
290
288
fprintf (fout ,"%s\n" ,title );
291
289
else
292
- fprintf (fout ,"%-*s%s\n" , (( int ) total_w - tlen ) /2 ,"" ,title );
290
+ fprintf (fout ,"%-*s%s\n" , (total_w - tmp ) /2 ,"" ,title );
293
291
}
294
292
295
293
/* print headers */
@@ -305,7 +303,7 @@ print_aligned_text(const char *title, const char *const * headers,
305
303
306
304
for (i = 0 ;i < col_count ;i ++ )
307
305
{
308
- int nbspace ;
306
+ unsigned int nbspace ;
309
307
310
308
nbspace = widths [i ]- head_w [i ];
311
309
@@ -420,18 +418,27 @@ print_aligned_vertical(const char *title, const char *const * headers,
420
418
/* count headers and find longest one */
421
419
for (ptr = headers ;* ptr ;ptr ++ )
422
420
col_count ++ ;
423
- head_w = calloc (col_count ,sizeof (* head_w ));
424
- if (!head_w )
421
+ if (col_count > 0 )
425
422
{
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
+ }
428
429
}
430
+ else
431
+ head_w = NULL ;
432
+
429
433
for (i = 0 ;i < col_count ;i ++ )
430
434
{
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 )
432
437
hwidth = tmp ;
433
438
head_w [i ]= tmp ;
434
439
}
440
+
441
+ /* Count cells, find their lengths */
435
442
for (ptr = cells ;* ptr ;ptr ++ )
436
443
cell_count ++ ;
437
444
@@ -445,12 +452,13 @@ print_aligned_vertical(const char *title, const char *const * headers,
445
452
}
446
453
}
447
454
else
448
- cell_w = 0 ;
455
+ cell_w = NULL ;
449
456
450
457
/* find longest data cell */
451
458
for (i = 0 ,ptr = cells ;* ptr ;ptr ++ ,i ++ )
452
459
{
453
- if ((tmp = pg_wcswidth ((unsignedchar * )* ptr ,strlen (* ptr ),encoding ))> dwidth )
460
+ tmp = pg_wcswidth ((unsignedchar * )* ptr ,strlen (* ptr ),encoding );
461
+ if (tmp > dwidth )
454
462
dwidth = tmp ;
455
463
cell_w [i ]= tmp ;
456
464
}
@@ -480,7 +488,6 @@ print_aligned_vertical(const char *title, const char *const * headers,
480
488
if (opt_border == 2 )
481
489
strcat (divider ,"-+" );
482
490
483
-
484
491
/* print records */
485
492
for (i = 0 ,ptr = cells ;* ptr ;i ++ ,ptr ++ )
486
493
{
@@ -544,7 +551,6 @@ print_aligned_vertical(const char *title, const char *const * headers,
544
551
if (opt_border == 2 )
545
552
fprintf (fout ,"%s\n" ,divider );
546
553
547
-
548
554
/* print footers */
549
555
550
556
if (!opt_barebones && footers && * footers )