| 459 | |
| 460 | |
| 461 | static char * |
| 462 | do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax, |
| 463 | const char **fieldNames, unsigned char *fieldNotNum, |
| 464 | const int fs_len, const PGresult *res) |
| 465 | { |
| 466 | int j; /* for loop index */ |
| 467 | char *border = NULL; |
| 468 | |
| 469 | if (po->html3) |
| 470 | fputs("<tr>", fout); |
| 471 | else |
| 472 | { |
| 473 | int tot = 0; |
| 474 | int n = 0; |
| 475 | char *p = NULL; |
| 476 | |
| 477 | for (; n < nFields; n++) |
| 478 | tot += fieldMax[n] + fs_len + (po->standard ? 2 : 0); |
| 479 | if (po->standard) |
| 480 | tot += fs_len * 2 + 2; |
| 481 | border = malloc(tot + 1); |
| 482 | if (!border) |
| 483 | { |
| 484 | fprintf(stderr, libpq_gettext("out of memory\n")); |
| 485 | return NULL; |
| 486 | } |
| 487 | p = border; |
| 488 | if (po->standard) |
| 489 | { |
| 490 | char *fs = po->fieldSep; |
| 491 | |
| 492 | while (*fs++) |
| 493 | *p++ = '+'; |
| 494 | } |
| 495 | for (j = 0; j < nFields; j++) |
| 496 | { |
| 497 | int len; |
| 498 | |
| 499 | for (len = fieldMax[j] + (po->standard ? 2 : 0); len--; *p++ = '-'); |
| 500 | if (po->standard || (j + 1) < nFields) |
| 501 | { |
| 502 | char *fs = po->fieldSep; |
| 503 | |
| 504 | while (*fs++) |
| 505 | *p++ = '+'; |
| 506 | } |
| 507 | } |
| 508 | *p = '\0'; |
| 509 | if (po->standard) |
| 510 | fprintf(fout, "%s\n", border); |
| 511 | } |
| 512 | if (po->standard) |
| 513 | fputs(po->fieldSep, fout); |
| 514 | for (j = 0; j < nFields; j++) |
| 515 | { |
| 516 | const char *s = PQfname(res, j); |
| 517 | |
| 518 | if (po->html3) |
no test coverage detected