summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/shared/format-table.c22
-rw-r--r--src/shared/format-table.h1
2 files changed, 22 insertions, 1 deletions
diff --git a/src/shared/format-table.c b/src/shared/format-table.c
index ce79d19a57..59133007e2 100644
--- a/src/shared/format-table.c
+++ b/src/shared/format-table.c
@@ -107,6 +107,8 @@ struct Table {
size_t *sort_map; /* The columns to order rows by, in order of preference. */
size_t n_sort_map;
+
+ bool *reverse_map;
};
Table *table_new_raw(size_t n_columns) {
@@ -199,6 +201,7 @@ Table *table_unref(Table *t) {
free(t->data);
free(t->display_map);
free(t->sort_map);
+ free(t->reverse_map);
return mfree(t);
}
@@ -797,7 +800,7 @@ static int table_data_compare(const size_t *a, const size_t *b, Table *t) {
r = cell_data_compare(d, *a, dd, *b);
if (r != 0)
- return r;
+ return t->reverse_map && t->reverse_map[t->sort_map[i]] ? -r : r;
}
/* Order identical lines by the order there were originally added in */
@@ -1310,3 +1313,20 @@ size_t table_get_columns(Table *t) {
assert(t->n_columns > 0);
return t->n_columns;
}
+
+int table_set_reverse(Table *t, size_t column, bool b) {
+ assert(t);
+ assert(column < t->n_columns);
+
+ if (!t->reverse_map) {
+ if (!b)
+ return 0;
+
+ t->reverse_map = new0(bool, t->n_columns);
+ if (!t->reverse_map)
+ return -ENOMEM;
+ }
+
+ t->reverse_map[column] = b;
+ return 0;
+}
diff --git a/src/shared/format-table.h b/src/shared/format-table.h
index 2db2084062..07cb2351cb 100644
--- a/src/shared/format-table.h
+++ b/src/shared/format-table.h
@@ -53,6 +53,7 @@ void table_set_header(Table *table, bool b);
void table_set_width(Table *t, size_t width);
int table_set_display(Table *t, size_t first_column, ...);
int table_set_sort(Table *t, size_t first_column, ...);
+int table_set_reverse(Table *t, size_t column, bool b);
int table_print(Table *t, FILE *f);
int table_format(Table *t, char **ret);