Revision: 65184
          http://sourceforge.net/p/brlcad/code/65184
Author:   starseeker
Date:     2015-06-04 20:11:45 +0000 (Thu, 04 Jun 2015)
Log Message:
-----------
Make it easy to get the argv array of strings that weren't handled by the 
option parser, as well as the count of that array.

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

Modified: brlcad/trunk/include/bu/opt.h
===================================================================
--- brlcad/trunk/include/bu/opt.h       2015-06-04 20:09:48 UTC (rev 65183)
+++ brlcad/trunk/include/bu/opt.h       2015-06-04 20:11:45 UTC (rev 65184)
@@ -126,10 +126,15 @@
  * Find and return a specific option from a bu_opt_data_t of options using an 
option
  * string as the lookup key.  Will only return an option if its valid entry
  * 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.
+ * unused entries stored in its args list.
  */
 BU_EXPORT extern struct bu_opt_data *bu_opt_find(const char *name, 
bu_opt_data_t *results);
 
+/** Convenience wrapper for reporting the count of unused argv entries */
+#define BU_OPT_UNUSED_ARGC(_results) (_results && bu_opt_find(NULL, _results) 
!= NULL) ? bu_opt_find(NULL, _results)->argc : 0
+/** Convenience wrapper for retrieving the unused entries argv array */
+#define BU_OPT_UNUSED_ARGV(_results) (_results && bu_opt_find(NULL, _results) 
!= NULL) ? bu_opt_find(NULL, _results)->argv : NULL
+
 /**
  * Parse argv array using option descs.
  *

Modified: brlcad/trunk/src/conv/gcv/gcv.cpp
===================================================================
--- brlcad/trunk/src/conv/gcv/gcv.cpp   2015-06-04 20:09:48 UTC (rev 65183)
+++ brlcad/trunk/src/conv/gcv/gcv.cpp   2015-06-04 20:11:45 UTC (rev 65184)
@@ -290,8 +290,10 @@
     size_t i;
     int fmt = 0;
     int ret = 0;
+    int uac = 0;
     const char *in_fmt = NULL;
     const char *out_fmt = NULL;
+    const char **uav = NULL;
     mime_model_t in_type = MIME_MODEL_UNKNOWN;
     mime_model_t out_type = MIME_MODEL_UNKNOWN;
     struct bu_vls in_format = BU_VLS_INIT_ZERO;
@@ -367,21 +369,20 @@
 
     /* If not specified explicitly with -i or -o, the input and output paths 
must always
      * be the last two arguments supplied */
-    d = bu_opt_find(NULL, results);
-    if (d) {
-       if (d->argv && d->argc > 1)
-           bu_vls_sprintf(&in_path_raw, "%s", d->argv[d->argc - 2]);
-       if (d->argv && d->argc > 0)
-           bu_vls_sprintf(&out_path_raw, "%s", d->argv[d->argc - 1]);
-    }
+    uac = BU_OPT_UNUSED_ARGC(results);
+    uav = BU_OPT_UNUSED_ARGV(results);
+    if (uav && uac > 1)
+       bu_vls_sprintf(&in_path_raw, "%s", uav[uac - 2]);
+    if (uav && uac > 0)
+       bu_vls_sprintf(&out_path_raw, "%s", uav[uac - 1]);
 
     /* Any unknown strings not otherwise processed are passed to both input 
and output.
      * These are deliberately placed at the beginning of the input strings, so 
any
      * input/output specific options have a chance to override them. */
-    if (d && d->argc > 2) {
-       for (i = 0; i < (size_t)d->argc - 2; i++) {
-           bu_vls_printf(&input_opts, " %s ", d->argv[i]);
-           bu_vls_printf(&output_opts, " %s ", d->argv[i]);
+    if (uac > 2) {
+       for (i = 0; i < (size_t)uac - 2; i++) {
+           bu_vls_printf(&input_opts, " %s ", uav[i]);
+           bu_vls_printf(&output_opts, " %s ", uav[i]);
        }
        if (bu_vls_strlen(&input_opts) > 0) bu_log("Unknown options (input): 
%s\n", bu_vls_addr(&input_opts));
        if (bu_vls_strlen(&output_opts) > 0) bu_log("Unknown options (output): 
%s\n", bu_vls_addr(&output_opts));

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