]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: formatters are now const
authorRobert Kessl <kesslr@centrum.cz>
Mon, 21 Jul 2014 07:23:16 +0000 (09:23 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Mon, 21 Jul 2014 07:23:16 +0000 (09:23 +0200)
ucw/table-test.c
ucw/table.c
ucw/table.h

index c41dbf28111ee16aab845c7d9a69042924f632ca..f23c176d487facb7d6d5a19915bf37d67a800e58 100644 (file)
@@ -143,7 +143,12 @@ static bool user_defined_option(struct table *tbl UNUSED, const char *key, const
 
 static void test_option_parser(struct table *tbl)
 {
-  tbl->formatter->process_option = user_defined_option;
+  struct table_formatter test_option_fmtr = table_fmt_human_readable;
+  test_option_fmtr.process_option = user_defined_option;
+
+  const struct table_formatter *tmp_fmtr = tbl->formatter;
+  tbl->formatter = &test_option_fmtr;
+
   const char *rv = table_set_option(tbl, "invalid:option");
   if(rv) printf("Tableprinter option parser returned error: \"%s\".\n", rv);
 
@@ -155,6 +160,8 @@ static void test_option_parser(struct table *tbl)
 
   rv = table_set_option(tbl, "valuekey:value");
   if(rv) printf("Tableprinter option parser returned error: \"%s\".\n", rv);
+
+  tbl->formatter = tmp_fmtr;
 }
 
 int main(int argc UNUSED, char **argv)
index 5260a5658e9ff6e72b1dcdcf5088f15a2ab01506..272b694ce0a96496bf7a5a654eca5151f1182d8c 100644 (file)
@@ -131,7 +131,7 @@ void table_end(struct table *tbl)
 
 /*** Configuration ***/
 
-void table_set_formatter(struct table *tbl, struct table_formatter *fmt)
+void table_set_formatter(struct table *tbl, const struct table_formatter *fmt)
 {
   tbl->formatter = fmt;
 }
@@ -503,7 +503,7 @@ static void table_start_human_readable(struct table *tbl)
   }
 }
 
-struct table_formatter table_fmt_human_readable = {
+const struct table_formatter table_fmt_human_readable = {
   .row_output = table_row_human_readable,
   .table_start = table_start_human_readable,
 };
@@ -537,7 +537,7 @@ static void table_start_machine_readable(struct table *tbl)
   }
 }
 
-struct table_formatter table_fmt_machine_readable = {
+const struct table_formatter table_fmt_machine_readable = {
   .row_output = table_row_machine_readable,
   .table_start = table_start_machine_readable,
 };
@@ -561,7 +561,7 @@ static void table_start_blockline(struct table *tbl)
   }
 }
 
-struct table_formatter table_fmt_blockline = {
+const struct table_formatter table_fmt_blockline = {
   .row_output = table_row_blockline_output,
   .table_start = table_start_blockline
 };
index 4f5d98a21c4997f54e676ba4626e21413d636f13..81d1aa64118d888d45bef0627d826f91798ff135 100644 (file)
@@ -77,7 +77,7 @@
 
 // FIXME: update documentation according to the changes made in recent commits!
 
-/** Types of columns. These are seldom used explicitly, using a column definition macro is preferred. **/
+/** The COL_TYPE_ANY macro specifies a column type which can be filled with arbitrary type. **/
 
 #define COL_TYPE_ANY      NULL
 
@@ -132,7 +132,7 @@ struct table_template {
   uint cols_to_output;                      // [*] Number of columns that are printed
   const char *col_delimiter;                // [*] Delimiter that is placed between columns
   // Back-end used for table formatting and its private data
-  struct table_formatter *formatter; // FIXME: should be const?
+  const struct table_formatter *formatter; // FIXME: should be const?
 };
 
 /**
@@ -162,7 +162,7 @@ struct table {
   int col_out;                         // Index of the column that is currently printed using fb_col_out
 
   // Back-end used for table formatting and its private data
-  struct table_formatter *formatter;
+  const struct table_formatter *formatter;
   void *data;
 };
 
@@ -387,7 +387,7 @@ const char *table_set_col_order_by_name(struct table *tbl, const char *col_order
 /**
  * Sets table formatter. See below for the list of formatters.
  **/
-void table_set_formatter(struct table *tbl, struct table_formatter *fmt);
+void table_set_formatter(struct table *tbl, const struct table_formatter *fmt);
 
 /**
  * Set a table option. All options have a key and a value. Currently,
@@ -446,15 +446,15 @@ struct table_formatter {
 };
 
 /** Standard formatter for human-readable output. **/
-extern struct table_formatter table_fmt_human_readable;
+extern const struct table_formatter table_fmt_human_readable;
 
 /** Standard formatter for machine-readable output (tab-separated values). **/
-extern struct table_formatter table_fmt_machine_readable;
+extern const struct table_formatter table_fmt_machine_readable;
 
 /**
  * Standard formatter for block output. Each cell is output on its own line
  * of the form `column_name: value`. Rows are separated by blank lines.
  **/
-extern struct table_formatter table_fmt_blockline;
+extern const struct table_formatter table_fmt_blockline;
 
 #endif