159 if (!config || !config->get_cell) {
163 if (config->num_cols <= 0) {
164 fprintf(config->output ? config->output : stderr,
"(No columns)\n");
172 void* block = malloc(
sizeof(
int) * (
size_t)cfg->num_cols +
sizeof(
char*) * (
size_t)cfg->num_cols);
174 fprintf(stderr,
"Memory allocation failed\n");
178 int* widths = (
int*)block;
179 const char** row_data = (
const char**)((
char*)block +
sizeof(int) * (
size_t)cfg->num_cols);
182 calculate_column_widths(cfg, widths);
185 print_separator(cfg, widths, style->top_left, style->top_mid, style->top_right);
188 if (cfg->show_header && cfg->get_header) {
189 for (
int col = 0; col < cfg->num_cols; col++) {
190 row_data[col] = cfg->get_header(cfg->user_data, col);
192 print_row(cfg, widths, row_data);
195 print_separator(cfg, widths, style->mid_left, style->mid_mid, style->mid_right);
199 for (
int row = 0; row < cfg->num_rows; row++) {
200 for (
int col = 0; col < cfg->num_cols; col++) {
201 row_data[col] = cfg->get_cell(cfg->user_data, row, col);
203 print_row(cfg, widths, row_data);
207 print_separator(cfg, widths, style->bottom_left, style->bottom_mid, style->bottom_right);
210 if (cfg->show_row_count) {
211 fprintf(cfg->output,
"(%d row%s)\n", cfg->num_rows, cfg->num_rows == 1 ?
"" :
"s");