* Add a cell to the table. * * Cells are not duplicated; you must ensure that the cell string is available * for the lifetime of the printTableContent struct. * * If translate is true, the function will pass the cell through gettext. * Otherwise, the cell will not be translated. * * If mustfree is true, the cell string is freed by printTableCleanup(). * Note: Automatic freeing of translat
| 3135 | * Note: Automatic freeing of translatable strings is not supported. |
| 3136 | */ |
| 3137 | void |
| 3138 | printTableAddCell(printTableContent *const content, char *cell, |
| 3139 | const bool translate, const bool mustfree) |
| 3140 | { |
| 3141 | long total_cells; |
| 3142 | #ifndef ENABLE_NLS |
| 3143 | (void) translate; /* unused parameter */ |
| 3144 | #endif |
| 3145 | |
| 3146 | /* product of cols and rows, using long type to prevent the int overflow */ |
| 3147 | total_cells = (long)content->ncolumns * (long)content->nrows; |
| 3148 | if (content->cellsadded >= total_cells) |
| 3149 | { |
| 3150 | fprintf(stderr, _("Cannot add cell to table content: " |
| 3151 | "total cell count of %ld exceeded, cells added: %ld.\n"), |
| 3152 | total_cells, content->cellsadded); |
| 3153 | exit(EXIT_FAILURE); |
| 3154 | } |
| 3155 | |
| 3156 | *content->cell = (char *) mbvalidate((unsigned char *) cell, |
| 3157 | content->opt->encoding); |
| 3158 | |
| 3159 | #ifdef ENABLE_NLS |
| 3160 | if (translate) |
| 3161 | *content->cell = _(*content->cell); |
| 3162 | #endif |
| 3163 | |
| 3164 | if (mustfree) |
| 3165 | { |
| 3166 | if (content->cellmustfree == NULL) |
| 3167 | content->cellmustfree = |
| 3168 | pg_malloc0((total_cells + 1) * sizeof(bool)); |
| 3169 | |
| 3170 | content->cellmustfree[content->cellsadded] = true; |
| 3171 | } |
| 3172 | content->cell++; |
| 3173 | content->cellsadded++; |
| 3174 | } |
| 3175 | |
| 3176 | /* |
| 3177 | * Add a footer to the table. |