Revision: 65116
          http://sourceforge.net/p/brlcad/code/65116
Author:   starseeker
Date:     2015-05-30 18:52:31 +0000 (Sat, 30 May 2015)
Log Message:
-----------
Add a printing function to see the full contents of a bu_opt_data ptbl

Modified Paths:
--------------
    brlcad/trunk/include/bu/opt.h
    brlcad/trunk/src/conv/gcv/gcv.cpp
    brlcad/trunk/src/libbu/opt.c

Modified: brlcad/trunk/include/bu/opt.h
===================================================================
--- brlcad/trunk/include/bu/opt.h       2015-05-30 18:03:06 UTC (rev 65115)
+++ brlcad/trunk/include/bu/opt.h       2015-05-30 18:52:31 UTC (rev 65116)
@@ -110,7 +110,15 @@
  * TODO - collapse to just bu_opt_data_free on a table? */
 BU_EXPORT extern void bu_opt_data_free_tbl(struct bu_ptbl *t);
 
+
 /**
+ * Print a table of bu_opt_data structures.  Caller
+ * is responsible for freeing return string. */
+BU_EXPORT extern void bu_opt_data_print(const char *title, struct bu_ptbl 
*data);
+
+
+
+/**
  * Convenience function for extracting args from a bu_opt_data container.
  * Provided as an easy way to get either the first arg:
  *
@@ -213,7 +221,7 @@
  * is set to 1.  A key value of -1 retrieves the bu_opt_data struct with the
  * unknown entries stored in its args table.
  */
-BU_EXPORT struct bu_opt_data *bu_opt_find(int key, struct bu_ptbl *results);
+BU_EXPORT extern struct bu_opt_data *bu_opt_find(int key, struct bu_ptbl 
*results);
 
 /**
  * Find and return a specific option from a bu_ptbl of options using an option
@@ -221,7 +229,7 @@
  * is set to 1. A NULL value passed in for name retrieves the bu_opt_data 
struct with the
  * unknown entries stored in its args table.
  */
-BU_EXPORT struct bu_opt_data *bu_opt_find_name(const char *name, struct 
bu_ptbl *opts);
+BU_EXPORT extern struct bu_opt_data *bu_opt_find_name(const char *name, struct 
bu_ptbl *opts);
 
 
 
@@ -230,14 +238,14 @@
  * get it.  This works for both valid and invalid opts, to allow for error
  * message retrieval.  If multiple instances of a key are present, the msg
  * from the last instance is returned. */
-BU_EXPORT const char *bu_opt_msg(int key, struct bu_ptbl *results);
+BU_EXPORT extern const char *bu_opt_msg(int key, struct bu_ptbl *results);
 
 /**
  * If an option has a message string associated with it, this function will
  * get it.  This works for both valid and invalid opts, to allow for error
  * message retrieval.  If multiple instances of a name are present, the msg
  * from the last instance is returned. */
-BU_EXPORT const char *bu_opt_msg_name(const char *name, struct bu_ptbl *opts);
+BU_EXPORT extern const char *bu_opt_msg_name(const char *name, struct bu_ptbl 
*opts);
 
 
 /** Output format options for bu_opt */
@@ -283,6 +291,9 @@
 BU_EXPORT extern const char *bu_opt_describe_tbl(struct bu_ptbl *dtbl, struct 
bu_opt_desc_opts *settings);
 
 
+
+
+
 /** @} */
 
 __END_DECLS

Modified: brlcad/trunk/src/conv/gcv/gcv.cpp
===================================================================
--- brlcad/trunk/src/conv/gcv/gcv.cpp   2015-05-30 18:03:06 UTC (rev 65115)
+++ brlcad/trunk/src/conv/gcv/gcv.cpp   2015-05-30 18:52:31 UTC (rev 65116)
@@ -32,44 +32,51 @@
 
 
 /* Emulate a FASTGEN4 format option processer */
-enum fg4_opt_enums { FG4_WARN_DEFAULT_NAMES };
-struct bu_opt_desc fg4_opt_desc[2] = {
-    {FG4_WARN_DEFAULT_NAMES, 0, 0, "w",  "warn-default-names", NULL, "-w", 
"--warn-default-names", "File format of input file." },
+enum fg4_opt_enums { FG4_TOL, FG4_WARN_DEFAULT_NAMES };
+struct bu_opt_desc fg4_opt_desc[3] = {
+    {FG4_TOL,                1, 1, "t",  "tol",                NULL, "-t tol", 
"--tol tol",            "Dimensional tolerance." },
+    {FG4_WARN_DEFAULT_NAMES, 0, 0, "w",  "warn-default-names", NULL, "-w",     
"--warn-default-names", "File format of input file." },
     BU_OPT_DESC_NULL
 };
 
 void fast4_arg_process(const char *args) {
-    if (!args) return;
     struct bu_opt_data *d;
     struct bu_ptbl *results;
+    if (!args) return;
 
     (void)bu_opt_parse_str(&results, NULL, args, fg4_opt_desc);
     d = bu_opt_find(FG4_WARN_DEFAULT_NAMES, results);
     if (d) {
-       bu_log("FASTGEN 4 opt: %s\n", d->name);
+       bu_log("FASTGEN 4 opt found: %s\n", d->name);
     }
 
+    bu_opt_data_print("FASTGEN4 option parsing results:", results);
+
     bu_opt_data_free_tbl(results);
 }
 
 /* Emulate a STL format option processer */
-enum stl_opt_enums { STL_UNITS };
-struct bu_opt_desc stl_opt_desc[2] = {
+enum stl_opt_enums { STL_TOL, STL_UNITS };
+struct bu_opt_desc stl_opt_desc[3] = {
+    {STL_TOL,   1, 1, "t",  "tol",   NULL, "-t tol",  "--tol tol",    
"Dimensional tolerance." },
     {STL_UNITS, 1, 1, "u",  "units", NULL, "-u unit", "--units unit", "Units 
of input file." },
     BU_OPT_DESC_NULL
 };
 
 void stl_arg_process(const char *args) {
-    if (!args) return;
     struct bu_opt_data *d;
     struct bu_ptbl *results;
+    if (!args) return;
 
     (void)bu_opt_parse_str(&results, NULL, args, stl_opt_desc);
     d = bu_opt_find(STL_UNITS, results);
     if (d) {
-       bu_log("STL opt: %s:%s\n", d->name, bu_opt_data_arg(d, 0));
+       bu_log("STL opt found: %s:%s\n", d->name, bu_opt_data_arg(d, 0));
     }
 
+    bu_opt_data_print("STL option parsing results:", results);
+
+
     bu_opt_data_free_tbl(results);
 }
 

Modified: brlcad/trunk/src/libbu/opt.c
===================================================================
--- brlcad/trunk/src/libbu/opt.c        2015-05-30 18:03:06 UTC (rev 65115)
+++ brlcad/trunk/src/libbu/opt.c        2015-05-30 18:52:31 UTC (rev 65116)
@@ -663,9 +663,54 @@
     return finalized;
 }
 
+void
+bu_opt_data_print(const char *title, struct bu_ptbl *data)
+{
+    size_t i = 0;
+    size_t j = 0;
+    int offset_1 = 3;
+    struct bu_vls log = BU_VLS_INIT_ZERO;
+    if (!data || BU_PTBL_LEN(data) == 0) return;
+    if (title) {
+       bu_vls_sprintf(&log, "%s\n", title);
+    } else {
+       bu_vls_sprintf(&log, "Options:\n");
+    }
+    for (i = 0; i < BU_PTBL_LEN(data); i++) {
+       struct bu_opt_data *d = (struct bu_opt_data *)BU_PTBL_GET(data, i);
+       if (d->name) {
+           bu_vls_printf(&log, "%*s%s", offset_1, " ", d->name);
+           if (d->valid) {
+               bu_vls_printf(&log, "\t(valid)");
+           } else {
+               bu_vls_printf(&log, "\t(invalid)");
+           }
+           if (d->desc && d->desc->arg_cnt_max > 0) {
+               if (d->args && BU_PTBL_LEN(d->args) > 0) {
+                   bu_vls_printf(&log, ": ");
+                   for (j = 0; j < BU_PTBL_LEN(d->args) - 1; j++) {
+                       bu_vls_printf(&log, "%s, ", bu_opt_data_arg(d, j));
+                   }
+                   bu_vls_printf(&log, "%s\n", bu_opt_data_arg(d, 
BU_PTBL_LEN(d->args) - 1));
+               }
+           } else {
+               bu_vls_printf(&log, "\n");
+           }
+       } else {
+           bu_vls_printf(&log, "%*s(unknown): ", offset_1, " ", d->name);
+           if (d->args && BU_PTBL_LEN(d->args) > 0) {
+               for (j = 0; j < BU_PTBL_LEN(d->args) - 1; j++) {
+                   bu_vls_printf(&log, "%s ", bu_opt_data_arg(d, j));
+               }
+               bu_vls_printf(&log, "%s\n", bu_opt_data_arg(d, 
BU_PTBL_LEN(d->args) - 1));
+           }
+       }
+    }
+    bu_log("%s", bu_vls_addr(&log));
+    bu_vls_free(&log);
+}
 
 
-
 /*
  * Local Variables:
  * mode: C

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to