@@ -1222,15 +1222,16 @@ print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
12221222
12231223
12241224static void
1225- print_aligned_vertical_line (const printTextFormat * format ,
1226- const unsigned short opt_border ,
1225+ print_aligned_vertical_line (const printTableOpt * topt ,
12271226 unsigned long record ,
12281227 unsigned int hwidth ,
12291228 unsigned int dwidth ,
1229+ int output_columns ,
12301230 printTextRule pos ,
12311231 FILE * fout )
12321232{
1233- const printTextLineFormat * lformat = & format -> lrule [pos ];
1233+ const printTextLineFormat * lformat = & get_line_style (topt )-> lrule [pos ];
1234+ const unsigned short opt_border = topt -> border ;
12341235 unsigned int i ;
12351236 int reclen = 0 ;
12361237
@@ -1259,21 +1260,62 @@ print_aligned_vertical_line(const printTextFormat *format,
12591260 if (reclen -- <= 0 )
12601261 fputs (lformat -> hrule , fout );
12611262 if (reclen -- <= 0 )
1262- fputs (lformat -> midvrule , fout );
1263- if (reclen -- <= 0 )
1263+ {
1264+ if (topt -> expanded_header_width_type == PRINT_XHEADER_COLUMN )
1265+ {
1266+ fputs (lformat -> rightvrule , fout );
1267+ }
1268+ else
1269+ {
1270+ fputs (lformat -> midvrule , fout );
1271+ }
1272+ }
1273+ if (reclen -- <= 0
1274+ && topt -> expanded_header_width_type != PRINT_XHEADER_COLUMN )
12641275 fputs (lformat -> hrule , fout );
12651276 }
12661277 else
12671278 {
12681279 if (reclen -- <= 0 )
12691280 fputc (' ' , fout );
12701281 }
1271- if (reclen < 0 )
1272- reclen = 0 ;
1273- for (i = reclen ; i < dwidth ; i ++ )
1274- fputs (opt_border > 0 ? lformat -> hrule : " " , fout );
1275- if (opt_border == 2 )
1276- fprintf (fout , "%s%s" , lformat -> hrule , lformat -> rightvrule );
1282+
1283+ if (topt -> expanded_header_width_type != PRINT_XHEADER_COLUMN )
1284+ {
1285+ if (topt -> expanded_header_width_type == PRINT_XHEADER_PAGE
1286+ || topt -> expanded_header_width_type == PRINT_XHEADER_EXACT_WIDTH )
1287+ {
1288+ if (topt -> expanded_header_width_type == PRINT_XHEADER_EXACT_WIDTH )
1289+ {
1290+ output_columns = topt -> expanded_header_exact_width ;
1291+ }
1292+ if (output_columns > 0 )
1293+ {
1294+ if (opt_border == 0 )
1295+ dwidth = Min (dwidth , Max (0 , (int ) (output_columns - hwidth )));
1296+ if (opt_border == 1 )
1297+ dwidth = Min (dwidth , Max (0 , (int ) (output_columns - hwidth - 3 )));
1298+ /*
1299+ * Handling the xheader width for border=2 doesn't make
1300+ * much sense because this format has an additional
1301+ * right border, but keep this for consistency.
1302+ */
1303+ if (opt_border == 2 )
1304+ dwidth = Min (dwidth , Max (0 , (int ) (output_columns - hwidth - 7 )));
1305+ }
1306+ }
1307+
1308+ if (reclen < 0 )
1309+ reclen = 0 ;
1310+ if (dwidth < reclen )
1311+ dwidth = reclen ;
1312+
1313+ for (i = reclen ; i < dwidth ; i ++ )
1314+ fputs (opt_border > 0 ? lformat -> hrule : " " , fout );
1315+ if (opt_border == 2 )
1316+ fprintf (fout , "%s%s" , lformat -> hrule , lformat -> rightvrule );
1317+ }
1318+
12771319 fputc ('\n' , fout );
12781320}
12791321
@@ -1570,11 +1612,12 @@ print_aligned_vertical(const printTableContent *cont,
15701612 lhwidth ++ ; /* for newline indicators */
15711613
15721614 if (!opt_tuples_only )
1573- print_aligned_vertical_line (format , opt_border , record ++ ,
1574- lhwidth , dwidth , pos , fout );
1615+ print_aligned_vertical_line (cont -> opt , record ++ ,
1616+ lhwidth , dwidth , output_columns ,
1617+ pos , fout );
15751618 else if (i != 0 || !cont -> opt -> start_table || opt_border == 2 )
1576- print_aligned_vertical_line (format , opt_border , 0 , lhwidth ,
1577- dwidth , pos , fout );
1619+ print_aligned_vertical_line (cont -> opt , 0 , lhwidth ,
1620+ dwidth , output_columns , pos , fout );
15781621 }
15791622
15801623 /* Format the header */
@@ -1760,8 +1803,8 @@ print_aligned_vertical(const printTableContent *cont,
17601803 if (cont -> opt -> stop_table )
17611804 {
17621805 if (opt_border == 2 && !cancel_pressed )
1763- print_aligned_vertical_line (format , opt_border , 0 , hwidth , dwidth ,
1764- PRINT_RULE_BOTTOM , fout );
1806+ print_aligned_vertical_line (cont -> opt , 0 , hwidth , dwidth ,
1807+ output_columns , PRINT_RULE_BOTTOM , fout );
17651808
17661809 /* print footers */
17671810 if (!opt_tuples_only && cont -> footers != NULL && !cancel_pressed )
0 commit comments