* Use this to print any table in the supported formats. * * cont: table data and formatting options * fout: where to print to * is_pager: true if caller has already redirected fout to be a pager pipe * flog: if not null, also print the table there (for --log-file option) */
| 3319 | * flog: if not null, also print the table there (for --log-file option) |
| 3320 | */ |
| 3321 | void |
| 3322 | printTable(const printTableContent *cont, |
| 3323 | FILE *fout, bool is_pager, FILE *flog) |
| 3324 | { |
| 3325 | bool is_local_pager = false; |
| 3326 | |
| 3327 | if (cancel_pressed) |
| 3328 | return; |
| 3329 | |
| 3330 | if (cont->opt->format == PRINT_NOTHING) |
| 3331 | return; |
| 3332 | |
| 3333 | /* print_aligned_*() handle the pager themselves */ |
| 3334 | if (!is_pager && |
| 3335 | cont->opt->format != PRINT_ALIGNED && |
| 3336 | cont->opt->format != PRINT_WRAPPED) |
| 3337 | { |
| 3338 | IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager); |
| 3339 | is_local_pager = is_pager; |
| 3340 | } |
| 3341 | |
| 3342 | /* clear any pre-existing error indication on the output stream */ |
| 3343 | clearerr(fout); |
| 3344 | |
| 3345 | /* print the stuff */ |
| 3346 | |
| 3347 | if (flog) |
| 3348 | print_aligned_text(cont, flog, false); |
| 3349 | |
| 3350 | switch (cont->opt->format) |
| 3351 | { |
| 3352 | case PRINT_UNALIGNED: |
| 3353 | if (cont->opt->expanded == 1) |
| 3354 | print_unaligned_vertical(cont, fout); |
| 3355 | else |
| 3356 | print_unaligned_text(cont, fout); |
| 3357 | break; |
| 3358 | case PRINT_ALIGNED: |
| 3359 | case PRINT_WRAPPED: |
| 3360 | |
| 3361 | /* |
| 3362 | * In expanded-auto mode, force vertical if a pager is passed in; |
| 3363 | * else we may make different decisions for different hunks of the |
| 3364 | * query result. |
| 3365 | */ |
| 3366 | if (cont->opt->expanded == 1 || |
| 3367 | (cont->opt->expanded == 2 && is_pager)) |
| 3368 | print_aligned_vertical(cont, fout, is_pager); |
| 3369 | else |
| 3370 | print_aligned_text(cont, fout, is_pager); |
| 3371 | break; |
| 3372 | case PRINT_CSV: |
| 3373 | if (cont->opt->expanded == 1) |
| 3374 | print_csv_vertical(cont, fout); |
| 3375 | else |
| 3376 | print_csv_text(cont, fout); |
| 3377 | break; |
| 3378 | case PRINT_HTML: |
no test coverage detected