]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: update of linked list
authorRobert Kessl <kesslr@centrum.cz>
Wed, 9 Jul 2014 10:45:43 +0000 (12:45 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Wed, 9 Jul 2014 10:45:43 +0000 (12:45 +0200)
ucw/table.c
ucw/table.h

index 0dd108c9530212511732ca1dab045469275e1b22..d685035220ef9e664f749752889c44cf2284738d 100644 (file)
@@ -161,7 +161,6 @@ static void table_update_ll(struct table *tbl)
 
   for(int i = 0; i < tbl->column_count; i++) {
     tbl->columns[i].first_column = -1;
-    tbl->columns[i].last_column = -1;
   }
 
   for(int i = 0; i < cols_to_output; i++) {
@@ -170,15 +169,14 @@ static void table_update_ll(struct table *tbl)
   }
 
   for(int i = 0; i < cols_to_output; i++) {
-    int last = tbl->column_order[i].col_def->last_column;
-    if(last != -1) {
-      tbl->column_order[i].col_def->last_column = i;
-      tbl->column_order[last].next_column = i;
+    int first = tbl->column_order[i].col_def->first_column;
+    tbl->column_order[i].col_def->first_column = i;
+
+    if(first != -1) {
+      tbl->column_order[i].next_column = first;
     } else {
-      tbl->column_order[i].col_def->last_column = i;
-      tbl->column_order[i].col_def->first_column = i;
+      tbl->column_order[i].next_column = -1;
     }
-    tbl->column_order[i].next_column = -1;
   }
 }
 
index 5ca60d75a82b93b54862667de4212b0afa816a2c..f4163d3004e3cff79d8057e82cbcb249b5a27f0c 100644 (file)
@@ -125,11 +125,12 @@ struct table_column {
   const char *fmt;             // [*] Default format of each cell in the column
   enum column_type type;       // [*] Type of the cells in the column
   int first_column;             // head of linked list of columns of this type
-  int last_column;              // tail of linked list of columns of this type
+  //int last_column;              // tail of linked list of columns of this type
   struct table_user_type *type_def;
 };
 
 // FIXME: is it correct to have idx and col_def? idx is sufficient and in fact a duplicity of idx
+// idx is used only for initialization and col_def is used in other cases
 struct table_col_info {
   uint idx;                      // idx is a pointer to struct table::columns
   struct table_column *col_def;  // this is pointer to the column definition, located in the array struct table::columns
@@ -198,7 +199,7 @@ struct table {
  *
  ***/
 
-#define TBL_COL_LIST_INIT     .first_column = -1, .last_column = -1
+#define TBL_COL_LIST_INIT     .first_column = -1
 #define TBL_COL_STR(_name, _width)            { .name = _name, .width = _width, .fmt = "%s", .type = COL_TYPE_STR, TBL_COL_LIST_INIT }
 #define TBL_COL_INT(_name, _width)            { .name = _name, .width = _width, .fmt = "%d", .type = COL_TYPE_INT, TBL_COL_LIST_INIT }
 #define TBL_COL_S64(_name, _width)            { .name = _name, .width = _width, .fmt = "%lld", .type = COL_TYPE_S64, TBL_COL_LIST_INIT }