+static const char *unit_suffix[] = {
+ [UNIT_BYTE] = "",
+ [UNIT_KILOBYTE] = "KB",
+ [UNIT_MEGABYTE] = "MB",
+ [UNIT_GIGABYTE] = "GB",
+ [UNIT_TERABYTE] = "TB"
+};
+
+static bool table_set_col_opt_size(struct table *tbl, uint col_copy_idx, const char *col_arg, char **err)
+{
+ int col_type_idx = tbl->column_order[col_copy_idx].idx;
+ if(tbl->columns[col_type_idx].type != COL_TYPE_SIZE) {
+ *err = NULL;
+ return false;
+ }
+
+ if(col_arg == NULL) {
+ *err = NULL;
+ return true;
+ }
+
+ if(strcasecmp(col_arg, "b") == 0 || strcasecmp(col_arg, "bytes") == 0) {
+ tbl->column_order[col_copy_idx].output_type = UNIT_BYTE;
+ }
+
+ tbl->column_order[col_copy_idx].output_type = CELL_OUT_UNINITIALIZED;
+ for(uint i = 0; i < ARRAY_SIZE(unit_suffix); i++) {
+ if(strcasecmp(col_arg, unit_suffix[i]) == 0) {
+ tbl->column_order[col_copy_idx].output_type = i;
+ }
+ }
+
+ if(tbl->column_order[col_copy_idx].output_type == CELL_OUT_UNINITIALIZED) {
+ *err = mp_printf(tbl->pool, "Tableprinter: invalid column format option: '%s' for column %d (counted from 0)", col_arg, col_copy_idx);
+ return true;
+ }
+
+ *err = NULL;
+ return true;
+}
+
+struct table_user_type table_type_size = {
+ .set_col_instance_option = table_set_col_opt_size,
+ .type = COL_TYPE_SIZE,
+};
+
+static bool table_set_col_opt_timestamp(struct table *tbl, uint col_copy_idx, const char *col_arg, char **err)
+{
+ int col_type_idx = tbl->column_order[col_copy_idx].idx;
+ if(tbl->columns[col_type_idx].type != COL_TYPE_TIMESTAMP) {
+ *err = NULL;
+ return false;
+ }
+
+ if(col_arg == NULL) {
+ *err = NULL;
+ return true;
+ }
+
+ if(strcasecmp(col_arg, "timestamp") == 0 || strcasecmp(col_arg, "epoch") == 0) {
+ tbl->column_order[col_copy_idx].output_type = TIMESTAMP_EPOCH;
+ } else if(strcasecmp(col_arg, "datetime") == 0) {
+ tbl->column_order[col_copy_idx].output_type = TIMESTAMP_DATETIME;
+ } else {
+ *err = mp_printf(tbl->pool, "Tableprinter: invalid column format option: '%s' for column %d.", col_arg, col_copy_idx);
+ return true;
+ }
+
+ *err = NULL;
+ return true;
+}
+
+struct table_user_type table_type_timestamp = {
+ .set_col_instance_option = table_set_col_opt_timestamp,
+ .type = COL_TYPE_TIMESTAMP,
+};
+