*/
int scols_cell_set_data(struct libscols_cell *ce, const char *str)
{
- char *p = NULL;
-
- if (!ce)
- return -EINVAL;
- if (str) {
- p = strdup(str);
- if (!p)
- return -ENOMEM;
- }
- free(ce->data);
- ce->data = p;
- return 0;
+ return strdup_to_struct_member(ce, data, str);
}
/**
/**
* scols_cell_set_color:
* @ce: a pointer to a struct libscols_cell instance
- * @color: color name or ESC sequence
+ * @co: color name or ESC sequence
*
- * Set the color of @ce to @color.
+ * Set the color of @ce to @co.
*
* Returns: 0, a negative value in case of an error.
*/
-int scols_cell_set_color(struct libscols_cell *ce, const char *color)
+int scols_cell_set_color(struct libscols_cell *ce, const char *co)
{
- char *p = NULL;
-
- if (!ce)
- return -EINVAL;
- if (color) {
- if (isalpha(*color)) {
- color = color_sequence_from_colorname(color);
-
- if (!color)
- return -EINVAL;
- }
- p = strdup(color);
- if (!p)
- return -ENOMEM;
+ if (co && isalpha(*co)) {
+ co = color_sequence_from_colorname(co);
+ if (!co)
+ return -EINVAL;
}
- free(ce->color);
- ce->color = p;
- return 0;
+ return strdup_to_struct_member(ce, color, co);
}
/**
/**
* scols_column_set_color:
* @cl: a pointer to a struct libscols_column instance
- * @color: color name or ESC sequence
+ * @co: color name or ESC sequence
*
* The default color for data cells and column header.
*
*
* Returns: 0, a negative value in case of an error.
*/
-int scols_column_set_color(struct libscols_column *cl, const char *color)
+int scols_column_set_color(struct libscols_column *cl, const char *co)
{
- char *p = NULL;
-
- if (!cl)
- return -EINVAL;
- if (color) {
- if (isalpha(*color)) {
- color = color_sequence_from_colorname(color);
-
- if (!color)
- return -EINVAL;
- }
- p = strdup(color);
- if (!p)
- return -ENOMEM;
+ if (co && isalpha(*co)) {
+ co = color_sequence_from_colorname(co);
+ if (!co)
+ return -EINVAL;
}
-
- free(cl->color);
- cl->color = p;
- return 0;
+ return strdup_to_struct_member(cl, color, co);
}
/**
/**
* scols_line_set_color:
* @ln: a pointer to a struct libscols_line instance
- * @color: color name or ESC sequence
+ * @co: color name or ESC sequence
*
* Returns: 0, a negative value in case of an error.
*/
-int scols_line_set_color(struct libscols_line *ln, const char *color)
+int scols_line_set_color(struct libscols_line *ln, const char *co)
{
- char *p = NULL;
-
- if (!ln)
- return -EINVAL;
- if (color) {
- if (isalnum(*color)) {
- color = color_sequence_from_colorname(color);
-
- if (!color)
- return -EINVAL;
- }
- p = strdup(color);
- if (!p)
- return -ENOMEM;
+ if (co && isalnum(*co)) {
+ co = color_sequence_from_colorname(co);
+ if (!co)
+ return -EINVAL;
}
-
- free(ln->color);
- ln->color = p;
- return 0;
+ return strdup_to_struct_member(ln, color, co);
}
/**
#include "c.h"
#include "list.h"
+#include "strutils.h"
#include "color-names.h"
#include "debug.h"
*/
int scols_symbols_set_branch(struct libscols_symbols *sb, const char *str)
{
- char *p = NULL;
-
- assert(sb);
-
- if (!sb)
- return -EINVAL;
- if (str) {
- p = strdup(str);
- if (!p)
- return -ENOMEM;
- }
- free(sb->branch);
- sb->branch = p;
- return 0;
+ return strdup_to_struct_member(sb, branch, str);
}
/**
*/
int scols_symbols_set_vertical(struct libscols_symbols *sb, const char *str)
{
- char *p = NULL;
-
- assert(sb);
-
- if (!sb)
- return -EINVAL;
- if (str) {
- p = strdup(str);
- if (!p)
- return -ENOMEM;
- }
- free(sb->vert);
- sb->vert = p;
- return 0;
+ return strdup_to_struct_member(sb, vert, str);
}
/**
*/
int scols_symbols_set_right(struct libscols_symbols *sb, const char *str)
{
- char *p = NULL;
-
- assert(sb);
-
- if (!sb)
- return -EINVAL;
- if (str) {
- p = strdup(str);
- if (!p)
- return -ENOMEM;
- }
- free(sb->right);
- sb->right = p;
- return 0;
+ return strdup_to_struct_member(sb, right, str);
}
/**
*/
int scols_symbols_set_title_padding(struct libscols_symbols *sb, const char *str)
{
- char *p = NULL;
-
- assert(sb);
-
- if (!sb)
- return -EINVAL;
- if (str) {
- p = strdup(str);
- if (!p)
- return -ENOMEM;
- }
- free(sb->title_padding);
- sb->title_padding = p;
- return 0;
+ return strdup_to_struct_member(sb, title_padding, str);
}
/**
/**
* scols_table_set_name:
* @tb: a pointer to a struct libscols_table instance
- * @name: a name
+ * @str: a name
*
* The table name is used for example for JSON top level object name.
*
*
* Since: 2.27
*/
-int scols_table_set_name(struct libscols_table *tb, const char *name)
+int scols_table_set_name(struct libscols_table *tb, const char *str)
{
- char *p = NULL;
-
- if (!tb)
- return -EINVAL;
-
- if (name) {
- p = strdup(name);
- if (!p)
- return -ENOMEM;
- }
- free(tb->name);
- tb->name = p;
- return 0;
+ return strdup_to_struct_member(tb, name, str);
}
/**
*/
int scols_table_set_column_separator(struct libscols_table *tb, const char *sep)
{
- char *p = NULL;
-
- if (!tb)
- return -EINVAL;
- if (sep) {
- p = strdup(sep);
- if (!p)
- return -ENOMEM;
- }
-
- DBG(TAB, ul_debugobj(tb, "new columns separator: %s", sep));
- free(tb->colsep);
- tb->colsep = p;
- return 0;
+ return strdup_to_struct_member(tb, colsep, sep);
}
/**
*/
int scols_table_set_line_separator(struct libscols_table *tb, const char *sep)
{
- char *p = NULL;
-
- if (!tb)
- return -EINVAL;
-
- if (sep) {
- p = strdup(sep);
- if (!p)
- return -ENOMEM;
- }
-
- DBG(TAB, ul_debugobj(tb, "new lines separator: %s", sep));
- free(tb->linesep);
- tb->linesep = p;
- return 0;
+ return strdup_to_struct_member(tb, linesep, sep);
}
/**