]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: add of table_col_is_printed
authorRobert Kessl <kesslr@centrum.cz>
Thu, 26 Jun 2014 07:37:04 +0000 (09:37 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Thu, 26 Jun 2014 07:37:04 +0000 (09:37 +0200)
ucw/table.c
ucw/table.h

index 0906ec75a883dfb63d82ffd9ce6d870e7ebac386..95944f0c23fdb00bc2e1959f10f6288e856fc075 100644 (file)
@@ -127,6 +127,16 @@ void table_set_col_order(struct table *tbl, int *col_order, int cols_to_output)
   tbl->cols_to_output = cols_to_output;
 }
 
+
+int table_col_is_printed(struct table *tbl, uint col_idx)
+{
+  for(uint i = 0; i < tbl->cols_to_output; i++) {
+    if(tbl->column_order[i] == col_idx) return 1;
+  }
+
+  return 0;
+}
+
 /**
  * TODO: This function deliberately leaks memory. When it is called multiple times,
  * previous column orders still remain allocated in the table's memory pool.
index 3fd4e34345b261eefc711617375f975ae068204e..843c039f348ddab1157cb9116eb82663502cf990 100644 (file)
@@ -322,6 +322,11 @@ const char *table_get_col_list(struct table *tbl);
  **/
 void table_set_col_order(struct table *tbl, int *col_order, int col_order_size);
 
+/**
+ * Returns 1 if col_idx will be printed, 0 otherwise.
+ **/
+int table_col_is_printed(struct table *tbl, uint col_idx);
+
 /**
  * Sets the order in which the columns are printed. The specification is a string with comma-separated column
  * names. Returns NULL for success and an error message otherwise. The string is not referenced after
@@ -371,7 +376,7 @@ const char *table_set_gary_options(struct table *tbl, char **gary_table_opts);
  *
  * A formatter is described by a structure, which contains pointers to several
  * call-back functions, which are called by the table printer at specific occasions.
+ *
  * The formatter can keep its internal state in the `data` field of `struct table`
  * and allocate temporary data from the table's memory pool. Memory allocated in
  * the `row_output` call-back is freed before the next row begins. Memory allocated