/** * scols_copy_column: * @cl: a pointer to a struct libscols_column instance * * Creates a new column and copies @cl's data over to it. * * Returns: a pointer to a new struct libscols_column instance. */ struct libscols_column *scols_copy_column(const struct libscols_column *cl) { struct libscols_column *ret; assert (cl); if (!cl) return NULL; ret = scols_new_column(); if (!ret) return NULL; if (scols_column_set_color(ret, cl->color)) goto err; if (scols_cell_copy_content(&ret->header, &cl->header)) goto err; ret->width = cl->width; ret->width_min = cl->width_min; ret->width_max = cl->width_max; ret->width_avg = cl->width_avg; ret->width_hint = cl->width_hint; ret->flags = cl->flags; ret->is_extreme = cl->is_extreme; return ret; err: scols_unref_column(ret); return NULL; }
/** * scols_copy_column: * @cl: a pointer to a struct libscols_column instance * * Creates a new column and copies @cl's data over to it. * * Returns: a pointer to a new struct libscols_column instance. */ struct libscols_column *scols_copy_column(const struct libscols_column *cl) { struct libscols_column *ret; if (!cl) return NULL; ret = scols_new_column(); if (!ret) return NULL; DBG(COL, ul_debugobj((void *) cl, "copy to %p", ret)); if (scols_column_set_color(ret, cl->color)) goto err; if (scols_cell_copy_content(&ret->header, &cl->header)) goto err; ret->width = cl->width; ret->width_min = cl->width_min; ret->width_max = cl->width_max; ret->width_avg = cl->width_avg; ret->width_hint = cl->width_hint; ret->flags = cl->flags; ret->is_extreme = cl->is_extreme; return ret; err: scols_unref_column(ret); return NULL; }
static struct libscols_column *parse_column(FILE *f) { size_t len = 0; char *line = NULL; int nlines = 0; struct libscols_column *cl = NULL; while (getline(&line, &len, f) != -1) { char *p = strrchr(line, '\n'); if (p) *p = '\0'; switch (nlines) { case 0: /* NAME */ { struct libscols_cell *hr; cl = scols_new_column(); if (!cl) goto fail; hr = scols_column_get_header(cl); if (!hr || scols_cell_set_data(hr, line)) goto fail; break; } case 1: /* WIDTH-HINT */ { double whint = strtod_or_err(line, "failed to parse column whint"); if (scols_column_set_whint(cl, whint)) goto fail; break; } case 2: /* FLAGS */ { int num_flags = parse_column_flags(line); if (scols_column_set_flags(cl, num_flags)) goto fail; if (strcmp(line, "wrapnl") == 0) { scols_column_set_wrapfunc(cl, scols_wrapnl_chunksize, scols_wrapnl_nextchunk, NULL); scols_column_set_safechars(cl, "\n"); } break; } case 3: /* COLOR */ if (scols_column_set_color(cl, line)) goto fail; break; default: break; } nlines++; } free(line); return cl; fail: free(line); scols_unref_column(cl); return NULL; }