void columns_add_column(columns_t cols, column_info_t info) { assert(info.text_width <= info.full_width && "Text width should be bigger than full width."); assert(column_id_present(info.column_id) && "Unknown column id."); if(extend_column_list(cols) == 0) { init_new_column(&cols->list[cols->count - 1], info); mark_for_recalculation(cols); } }
/* Parses format string. Returns list of size *len or NULL on error. */ static column_info_t * parse_all(map_name_cb cn, const char str[], size_t *len, void *arg) { char *saveptr; char *str_copy; char *token; column_info_t *list = NULL; size_t list_len = 0; size_t percents = 0; str_copy = strdup(str); if(str_copy == NULL) { return NULL; } saveptr = NULL; for(token = str_copy; (token = strtok_r(token, ",", &saveptr)); token = NULL) { column_info_t info; if(parse(cn, token, &info, arg) != 0) { break; } if(info.sizing == ST_PERCENT && (percents += info.full_width) > 100) { break; } if(extend_column_list(&list, &list_len) == 0) { list[list_len - 1] = info; } } free(str_copy); if(token != NULL) { free(list); return NULL; } else { *len = list_len; return list; } }