@@ -1161,7 +1161,6 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
11611161struct lineptr * hlineptr ,
11621162* dlineptr ;
11631163bool is_pager = false;
1164- int output_columns = 0 ;/* Width of interactive console */
11651164
11661165if (cancel_pressed )
11671166return ;
@@ -1235,90 +1234,24 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
12351234fprintf (fout ,"%s\n" ,cont -> title );
12361235}
12371236
1238- /*
1239- * Choose target output width: \pset columns, or $COLUMNS, or ioctl
1240- */
1241- if (cont -> opt -> columns > 0 )
1242- output_columns = cont -> opt -> columns ;
1243- else if ((fout == stdout && isatty (fileno (stdout )))|| is_pager )
1244- {
1245- if (cont -> opt -> env_columns > 0 )
1246- output_columns = cont -> opt -> env_columns ;
1247- #ifdef TIOCGWINSZ
1248- else
1249- {
1250- struct winsize screen_size ;
1251-
1252- if (ioctl (fileno (stdout ),TIOCGWINSZ ,& screen_size )!= -1 )
1253- output_columns = screen_size .ws_col ;
1254- }
1255- #endif
1256- }
1257-
1258- if (cont -> opt -> format == PRINT_WRAPPED )
1259- {
1260- /*
1261- * Calculate the available width to wrap the columns to after
1262- * subtracting the maximum header width and separators. At a minimum
1263- * enough to print "[ RECORD N ]"
1264- */
1265- unsignedint width ,
1266- swidth ;
1267-
1268- if (opt_border == 0 )
1269- swidth = 1 ;/* "header data" */
1270- else if (opt_border == 1 )
1271- swidth = 3 ;/* "header | data" */
1272- else
1273- swidth = 7 ;/* "| header | data |" */
1274-
1275- /* Wrap to maximum width */
1276- width = dwidth + swidth + hwidth ;
1277- if ((output_columns > 0 )&& (width > output_columns ))
1278- {
1279- dwidth = output_columns - hwidth - swidth ;
1280- width = output_columns ;
1281- }
1282-
1283- /* Wrap to minimum width */
1284- if (!opt_tuples_only )
1285- {
1286- int delta = 1 + log10 (cont -> nrows )- width ;
1287-
1288- if (opt_border == 0 )
1289- delta += 6 ;/* "* RECORD " */
1290- else if (opt_border == 1 )
1291- delta += 10 ;/* "-[ RECORD ]" */
1292- else
1293- delta += 15 ;/* "+-[ RECORD ]-+" */
1294-
1295- if (delta > 0 )
1296- dwidth += delta ;
1297- }
1298- else if (dwidth < 3 )
1299- dwidth = 3 ;
1300- }
1301-
13021237/* print records */
13031238for (i = 0 ,ptr = cont -> cells ;* ptr ;i ++ ,ptr ++ )
13041239{
13051240printTextRule pos ;
1306- int dline ,
1307- hline ,
1241+ int line_count ,
13081242dcomplete ,
1309- hcomplete ,
1310- offset ,
1311- chars_to_output ;
1243+ hcomplete ;
13121244
13131245if (cancel_pressed )
13141246break ;
13151247
13161248if (i == 0 )
13171249pos = PRINT_RULE_TOP ;
1250+ else if (!(* (ptr + 1 )))
1251+ pos = PRINT_RULE_BOTTOM ;
13181252else
13191253pos = PRINT_RULE_MIDDLE ;
13201254
1321- /* Print record header (e.g. "[ RECORD N ]") above each record */
13221255if (i %cont -> ncolumns == 0 )
13231256{
13241257if (!opt_tuples_only )
@@ -1337,126 +1270,48 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
13371270pg_wcsformat ((const unsignedchar * )* ptr ,strlen (* ptr ),encoding ,
13381271dlineptr ,dheight );
13391272
1340- /*
1341- * Loop through header and data in parallel dealing with newlines and
1342- * wrapped lines until they're both exhausted
1343- */
1344- dline = hline = 0 ;
1273+ line_count = 0 ;
13451274dcomplete = hcomplete = 0 ;
1346- offset = 0 ;
1347- chars_to_output = dlineptr [dline ].width ;
13481275while (!dcomplete || !hcomplete )
13491276{
1350- /* Left border */
13511277if (opt_border == 2 )
1352- fprintf (fout ,"%s" ,dformat -> leftvrule );
1353-
1354- /* Header (never wrapped so just need to deal with newlines) */
1278+ fprintf (fout ,"%s " ,dformat -> leftvrule );
13551279if (!hcomplete )
13561280{
1357- int swidth ,
1358- twidth = hwidth + 1 ;
1359-
1360- fputs (hline ?format -> header_nl_left :" " ,fout );
1361- strlen_max_width (hlineptr [hline ].ptr ,& twidth ,
1362- encoding );
1363- fprintf (fout ,"%-s" ,hlineptr [hline ].ptr );
1364-
1365- swidth = hwidth - twidth ;
1366- if (swidth > 0 )/* spacer */
1367- fprintf (fout ,"%*s" ,swidth ," " );
1281+ fprintf (fout ,"%-s%*s" ,hlineptr [line_count ].ptr ,
1282+ hwidth - hlineptr [line_count ].width ,"" );
13681283
1369- if (hlineptr [hline + 1 ].ptr )
1370- {
1371- /* More lines after this one due to a newline */
1372- fputs (format -> header_nl_right ,fout );
1373- hline ++ ;
1374- }
1375- else
1376- {
1377- /* This was the last line of the header */
1378- fputs (" " ,fout );
1284+ if (!hlineptr [line_count + 1 ].ptr )
13791285hcomplete = 1 ;
1380- }
13811286}
13821287else
1383- {
1384- /* Header exhausted but more data for column */
1385- fprintf (fout ,"%*s" ,hwidth + 2 ,"" );
1386- }
1288+ fprintf (fout ,"%*s" ,hwidth ,"" );
13871289
1388- /* Separator */
13891290if (opt_border > 0 )
1390- {
1391- if (offset )
1392- fputs (format -> midvrule_wrap ,fout );
1393- else if (!dline )
1394- fputs (dformat -> midvrule ,fout );
1395- else if (dline )
1396- fputs (format -> midvrule_nl ,fout );
1397- else
1398- fputs (format -> midvrule_blank ,fout );
1399- }
1291+ fprintf (fout ," %s " ,dformat -> midvrule );
1292+ else
1293+ fputc (' ' ,fout );
14001294
1401- /* Data */
14021295if (!dcomplete )
14031296{
1404- int target_width ,
1405- bytes_to_output ,
1406- swidth ;
1407-
1408- fputs (!dcomplete && !offset ?" " :format -> wrap_left ,fout );
1409-
1410- target_width = dwidth ;
1411- bytes_to_output = strlen_max_width (dlineptr [dline ].ptr + offset ,
1412- & target_width ,encoding );
1413- fputnbytes (fout , (char * ) (dlineptr [dline ].ptr + offset ),
1414- bytes_to_output );
1415-
1416- chars_to_output -= target_width ;
1417- offset += bytes_to_output ;
1418-
1419- /* spacer */
1420- swidth = dwidth - target_width ;
1421- if (swidth > 0 )
1422- fprintf (fout ,"%*s" ,swidth ,"" );
1423-
1424- if (chars_to_output )
1425- {
1426- /* continuing a wrapped column */
1427- fputs (format -> wrap_right ,fout );
1428- }
1429- else if (dlineptr [dline + 1 ].ptr )
1430- {
1431- /* reached a newline in the column */
1432- fputs (format -> nl_right ,fout );
1433- dline ++ ;
1434- offset = 0 ;
1435- chars_to_output = dlineptr [dline ].width ;
1436- }
1297+ if (opt_border < 2 )
1298+ fprintf (fout ,"%s\n" ,dlineptr [line_count ].ptr );
14371299else
1438- {
1439- /* reached the end of the cell */
1440- fputs (" " ,fout );
1441- dcomplete = 1 ;
1442- }
1443-
1444- if (opt_border == 2 )
1445- fputs (dformat -> rightvrule ,fout );
1300+ fprintf (fout ,"%-s%*s %s\n" ,dlineptr [line_count ].ptr ,
1301+ dwidth - dlineptr [line_count ].width ,"" ,
1302+ dformat -> rightvrule );
14461303
1447- fputs ("\n" ,fout );
1304+ if (!dlineptr [line_count + 1 ].ptr )
1305+ dcomplete = 1 ;
14481306}
14491307else
14501308{
1451- /*
1452- * data exhausted (this can occur if header is longer than the
1453- * data due to newlines in the header)
1454- */
14551309if (opt_border < 2 )
1456- fputs ( "\n" ,fout );
1310+ fputc ( '\n' ,fout );
14571311else
1458- fprintf (fout ,"%*s %s\n" ,dwidth ,"" ,dformat -> rightvrule );
1312+ fprintf (fout ,"%*s %s\n" ,dwidth ,"" ,dformat -> rightvrule );
14591313}
1314+ line_count ++ ;
14601315}
14611316}
14621317