#include "glyph-util.h"
#include "gunicode.h"
#include "in-addr-util.h"
+#include "json-util.h"
#include "memory-util.h"
#include "memstream-util.h"
#include "pager.h"
pid_t pid;
mode_t mode;
dev_t devnum;
+ sd_json_variant *json;
/* … add more here as we start supporting more cell data types … */
};
} TableData;
if (IN_SET(d->type, TABLE_STRV, TABLE_STRV_WRAPPED))
strv_free(d->strv);
+ if (d->type == TABLE_JSON)
+ sd_json_variant_unref(d->json);
+
return mfree(d);
}
case TABLE_DEVNUM:
return sizeof(dev_t);
+ case TABLE_JSON:
+ return sizeof(sd_json_variant*);
+
default:
assert_not_reached();
}
d->ellipsize_percent = ellipsize_percent;
d->uppercase = uppercase;
- if (IN_SET(type, TABLE_STRV, TABLE_STRV_WRAPPED)) {
+ switch (type) {
+
+ case TABLE_STRV:
+ case TABLE_STRV_WRAPPED:
d->strv = strv_copy(data);
if (!d->strv)
return NULL;
- } else
+ break;
+
+ case TABLE_JSON:
+ d->json = sd_json_variant_ref((sd_json_variant*) data);
+ break;
+
+ default:
memcpy_safe(d->data, data, data_size);
+ }
return TAKE_PTR(d);
}
data = &buffer.devnum;
break;
+ case TABLE_JSON:
+ data = va_arg(ap, sd_json_variant*);
+ break;
+
case TABLE_SET_MINIMUM_WIDTH: {
size_t w = va_arg(ap, size_t);
return CMP(minor(a->devnum), minor(b->devnum));
+ case TABLE_JSON:
+ return json_variant_compare(a->json, b->json);
+
default:
;
}
break;
+ case TABLE_JSON: {
+ if (!d->json)
+ return table_ersatz_string(t);
+
+ char *p;
+ if (sd_json_variant_format(d->json, /* flags= */ 0, &p) < 0)
+ return NULL;
+
+ d->formatted = p;
+ break;
+ }
+
default:
assert_not_reached();
}
if (IN_SET(d->type, TABLE_STRV, TABLE_STRV_WRAPPED))
return strv_isempty(d->strv);
+ if (d->type == TABLE_JSON)
+ return sd_json_variant_is_null(d->json);
+
/* Note that an empty string we do not consider empty here! */
return false;
}
SD_JSON_BUILD_UNSIGNED(major(d->devnum)),
SD_JSON_BUILD_UNSIGNED(minor(d->devnum))));
+ case TABLE_JSON:
+ if (!d->json)
+ return sd_json_variant_new_null(ret);
+
+ if (ret)
+ *ret = sd_json_variant_ref(d->json);
+
+ return 0;
+
case TABLE_STRING_WITH_ANSI: {
_cleanup_free_ char *s = strdup(d->string);
if (!s)
TABLE_MODE, /* as in UNIX file mode (mode_t), in typical octal output */
TABLE_MODE_INODE_TYPE, /* also mode_t, but displays only the inode type as string */
TABLE_DEVNUM, /* a dev_t, displayed in the usual major:minor way */
+ TABLE_JSON, /* an sd_json_variant, for output formatted into text */
_TABLE_DATA_TYPE_MAX,
/* The following are not really data types, but commands for table_add_cell_many() to make changes to