* PQprint() * * Format results of a query for printing. * * PQprintOpt is a typedef (structure) that contains * various flags and options. consult libpq-fe.h for * details * * This function should probably be removed sometime since psql * doesn't use it anymore. It is unclear to what extent this is used * by external clients, however. */
| 65 | * by external clients, however. |
| 66 | */ |
| 67 | void |
| 68 | PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po) |
| 69 | { |
| 70 | int nFields; |
| 71 | |
| 72 | nFields = PQnfields(res); |
| 73 | |
| 74 | if (nFields > 0) |
| 75 | { /* only print rows with at least 1 field. */ |
| 76 | int i, |
| 77 | j; |
| 78 | int nTups; |
| 79 | int *fieldMax = NULL; /* in case we don't use them */ |
| 80 | unsigned char *fieldNotNum = NULL; |
| 81 | char *border = NULL; |
| 82 | char **fields = NULL; |
| 83 | const char **fieldNames = NULL; |
| 84 | int fieldMaxLen = 0; |
| 85 | int numFieldName; |
| 86 | int fs_len = strlen(po->fieldSep); |
| 87 | int total_line_length = 0; |
| 88 | bool usePipe = false; |
| 89 | char *pagerenv; |
| 90 | |
| 91 | #if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32) |
| 92 | sigset_t osigset; |
| 93 | bool sigpipe_masked = false; |
| 94 | bool sigpipe_pending; |
| 95 | #endif |
| 96 | #if !defined(ENABLE_THREAD_SAFETY) && !defined(WIN32) |
| 97 | pqsigfunc oldsigpipehandler = NULL; |
| 98 | #endif |
| 99 | |
| 100 | #ifdef TIOCGWINSZ |
| 101 | struct winsize screen_size; |
| 102 | #else |
| 103 | struct winsize |
| 104 | { |
| 105 | int ws_row; |
| 106 | int ws_col; |
| 107 | } screen_size; |
| 108 | #endif |
| 109 | |
| 110 | nTups = PQntuples(res); |
| 111 | fieldNames = (const char **) calloc(nFields, sizeof(char *)); |
| 112 | fieldNotNum = (unsigned char *) calloc(nFields, 1); |
| 113 | fieldMax = (int *) calloc(nFields, sizeof(int)); |
| 114 | if (!fieldNames || !fieldNotNum || !fieldMax) |
| 115 | { |
| 116 | fprintf(stderr, libpq_gettext("out of memory\n")); |
| 117 | goto exit; |
| 118 | } |
| 119 | for (numFieldName = 0; |
| 120 | po->fieldName && po->fieldName[numFieldName]; |
| 121 | numFieldName++) |
| 122 | ; |
| 123 | for (j = 0; j < nFields; j++) |
| 124 | { |