|
3 | 3 | * |
4 | 4 | * Copyright (c) 2000-2008, PostgreSQL Global Development Group |
5 | 5 | * |
6 | | - * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.103 2008/05/16 18:35:38 tgl Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.104 2008/05/17 17:52:14 tgl Exp $ |
7 | 7 | */ |
8 | 8 | #include"postgres_fe.h" |
9 | 9 |
|
@@ -522,7 +522,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) |
522 | 522 | introws=cell_count /col_count; |
523 | 523 |
|
524 | 524 | for (i=0;i<col_count;i++) |
525 | | -width_average[i %col_count] /=rows; |
| 525 | +width_average[i] /=rows; |
526 | 526 | } |
527 | 527 |
|
528 | 528 | /* adjust the total display width based on border style */ |
@@ -645,30 +645,36 @@ print_aligned_text(const printTableContent *cont, FILE *fout) |
645 | 645 | if (!is_pager) |
646 | 646 | { |
647 | 647 | /* scan all cells, find maximum width, compute cell_count */ |
648 | | -for (i=0,ptr=cont->cells;*ptr;ptr++,i++,cell_count++) |
| 648 | +for (i=0,ptr=cont->cells;*ptr;ptr++,cell_count++) |
649 | 649 | { |
650 | 650 | intwidth, |
651 | 651 | nl_lines, |
652 | 652 | bytes_required; |
653 | 653 |
|
654 | 654 | pg_wcssize((unsignedchar*)*ptr,strlen(*ptr),encoding, |
655 | 655 | &width,&nl_lines,&bytes_required); |
656 | | -if (opt_numeric_locale&&cont->align[i %col_count]=='r') |
| 656 | +if (opt_numeric_locale&&cont->align[i]=='r') |
657 | 657 | width+=additional_numeric_locale_len(*ptr); |
658 | 658 |
|
659 | 659 | /* |
660 | 660 | *A row can have both wrapping and newlines that cause |
661 | 661 | *it to display across multiple lines. We check |
662 | 662 | *for both cases below. |
663 | 663 | */ |
664 | | -if (width>0&&width_wrap[i]&& |
665 | | -(width-1) /width_wrap[i]+nl_lines>extra_row_output_lines) |
666 | | -extra_row_output_lines= (width-1) /width_wrap[i]+nl_lines; |
| 664 | +if (width>0&&width_wrap[i]) |
| 665 | +{ |
| 666 | +unsignedintextra_lines; |
| 667 | + |
| 668 | +extra_lines= (width-1) /width_wrap[i]+nl_lines; |
| 669 | +if (extra_lines>extra_row_output_lines) |
| 670 | +extra_row_output_lines=extra_lines; |
| 671 | +} |
667 | 672 |
|
668 | | -/*If lastcolumn, add tallest column height */ |
669 | | -if (i %col_count==col_count-1) |
| 673 | +/*i is the currentcolumn number: increment with wrap */ |
| 674 | +if (++i >=col_count) |
670 | 675 | { |
671 | | -/* Add height of tallest row */ |
| 676 | +i=0; |
| 677 | +/* At last column of each row, add tallest column height */ |
672 | 678 | extra_output_lines+=extra_row_output_lines; |
673 | 679 | extra_row_output_lines=0; |
674 | 680 | } |
@@ -780,7 +786,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout) |
780 | 786 | col_lineptrs[j],max_nl_lines[j]); |
781 | 787 | curr_nl_line[j]=0; |
782 | 788 |
|
783 | | -if (opt_numeric_locale&&cont->aligns[j %col_count]=='r') |
| 789 | +if (opt_numeric_locale&&cont->aligns[j]=='r') |
784 | 790 | { |
785 | 791 | char*my_cell; |
786 | 792 |
|
|