string-util: rename strdash_if_empty() to empty_to_dash()

This commit is contained in:
Yu Watanabe 2018-05-11 01:55:46 +09:00
parent 945403e6ed
commit c5984fe177
3 changed files with 9 additions and 13 deletions

View file

@ -58,7 +58,7 @@ static inline const char *empty_to_null(const char *p) {
return isempty(p) ? NULL : p;
}
static inline const char *strdash_if_empty(const char *str) {
static inline const char *empty_to_dash(const char *str) {
return isempty(str) ? "-" : str;
}

View file

@ -914,10 +914,6 @@ static int on_property(const char *interface, const char *name, const char *sign
return 0;
}
static const char *strdash(const char *x) {
return isempty(x) ? "-" : x;
}
static int introspect(int argc, char **argv, void *userdata) {
static const struct hash_ops member_hash_ops = {
.hash = member_hash_func,
@ -1104,15 +1100,15 @@ static int introspect(int argc, char **argv, void *userdata) {
rv = ellipsized;
} else
rv = strdash(m->result);
rv = empty_to_dash(m->result);
printf("%s%s%-*s%s %-*s %-*s %-*s%s%s%s%s%s%s\n",
is_interface ? ansi_highlight() : "",
is_interface ? "" : ".",
- !is_interface + (int) name_width, strdash(streq_ptr(m->type, "interface") ? m->interface : m->name),
- !is_interface + (int) name_width, empty_to_dash(streq_ptr(m->type, "interface") ? m->interface : m->name),
is_interface ? ansi_normal() : "",
(int) type_width, strdash(m->type),
(int) signature_width, strdash(m->signature),
(int) type_width, empty_to_dash(m->type),
(int) signature_width, empty_to_dash(m->signature),
(int) result_width, rv,
(m->flags & SD_BUS_VTABLE_DEPRECATED) ? " deprecated" : (m->flags || m->writable ? "" : " -"),
(m->flags & SD_BUS_VTABLE_METHOD_NO_REPLY) ? " no-reply" : "",

View file

@ -335,10 +335,10 @@ static int list_machines(int argc, char *argv[], void *userdata) {
r = table_add_many(table,
TABLE_STRING, name,
TABLE_STRING, class,
TABLE_STRING, strdash_if_empty(service),
TABLE_STRING, strdash_if_empty(os),
TABLE_STRING, strdash_if_empty(version_id),
TABLE_STRING, strdash_if_empty(addresses));
TABLE_STRING, empty_to_dash(service),
TABLE_STRING, empty_to_dash(os),
TABLE_STRING, empty_to_dash(version_id),
TABLE_STRING, empty_to_dash(addresses));
if (r < 0)
return log_error_errno(r, "Failed to add table row: %m");
}