shared/format-table: use enum instead of Table.empty_string

All users were setting this to some static string (usually "-"), so let's
simplify things by not doing strdup, but instead limiting callers to a fixed
set of values. In preparation for the next commit, the function is renamed from
"empty" to "replacement", because it'll be used for more than empty fields. I
didn't do the whole string-table setup, because it's all used internally in one
file and this way we can immediately assert if an invalid value is passed in.

Some callers were (void)ing the error, others were ignoring it, and others
propagating. It's nicer to remove the boilerplate.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-09-22 10:16:05 +02:00
parent 5515f2169c
commit c8b62cf600
16 changed files with 51 additions and 34 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ static int output_jobs_list(sd_bus *bus, const struct job_info* jobs, unsigned n
if (arg_full)
table_set_width(table, 0);
(void) table_set_empty_string(table, "-");
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (const struct job_info *j = jobs; j < jobs + n; j++) {
if (streq(j->state, "running"))
+1 -1
View File
@@ -171,7 +171,7 @@ static int output_machines_list(struct machine_info *machine_infos, unsigned n)
if (arg_full)
table_set_width(table, 0);
(void) table_set_empty_string(table, "-");
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (struct machine_info *m = machine_infos; m < machine_infos + n; m++) {
_cleanup_free_ char *mname = NULL;
+1 -1
View File
@@ -62,7 +62,7 @@ static int output_unit_file_list(const UnitFileList *units, unsigned c) {
if (arg_full)
table_set_width(table, 0);
(void) table_set_empty_string(table, "-");
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (const UnitFileList *u = units; u < units + c; u++) {
const char *on_underline = NULL, *on_unit_color = NULL, *id;
+4 -4
View File
@@ -120,7 +120,7 @@ static int output_units_list(const UnitInfo *unit_infos, size_t c) {
if (arg_full)
table_set_width(table, 0);
(void) table_set_empty_string(table, "-");
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (const UnitInfo *u = unit_infos; unit_infos && (size_t) (u - unit_infos) < c; u++) {
_cleanup_free_ char *j = NULL;
@@ -381,7 +381,7 @@ static int output_sockets_list(struct socket_info *socket_infos, size_t cs) {
if (arg_full)
table_set_width(table, 0);
(void) table_set_empty_string(table, "-");
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (struct socket_info *s = socket_infos; s < socket_infos + cs; s++) {
_cleanup_free_ char *j = NULL;
@@ -612,7 +612,7 @@ static int output_timers_list(struct timer_info *timer_infos, size_t n) {
if (arg_full)
table_set_width(table, 0);
(void) table_set_empty_string(table, "-");
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (struct timer_info *t = timer_infos; t < timer_infos + n; t++) {
_cleanup_free_ char *j = NULL, *activates = NULL;
@@ -844,7 +844,7 @@ static int output_automounts_list(struct automount_info *infos, size_t n_infos)
if (arg_full)
table_set_width(table, 0);
(void) table_set_empty_string(table, "-");
table_set_ersatz_string(table, TABLE_ERSATZ_DASH);
for (struct automount_info *info = infos; info < infos + n_infos; info++) {
_cleanup_free_ char *j = NULL;