Revision: 65200
          http://sourceforge.net/p/brlcad/code/65200
Author:   starseeker
Date:     2015-06-05 17:27:44 +0000 (Fri, 05 Jun 2015)
Log Message:
-----------
Work on getting an option callback API in place.  Has known bugs but making 
progress and need a checkpoint.

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

Modified: brlcad/trunk/include/bu/color.h
===================================================================
--- brlcad/trunk/include/bu/color.h     2015-06-05 15:11:15 UTC (rev 65199)
+++ brlcad/trunk/include/bu/color.h     2015-06-05 17:27:44 UTC (rev 65200)
@@ -136,13 +136,13 @@
 BU_EXPORT extern int bu_str_to_rgb(char *str, unsigned char *rgb);
 BU_EXPORT extern int bu_color_from_rgb_floats(struct bu_color *cp, fastf_t 
*rgb);
 BU_EXPORT extern int bu_color_to_rgb_floats(struct bu_color *cp, fastf_t *rgb);
+BU_EXPORT extern int bu_color_from_rgb_chars(struct bu_color *cp, unsigned 
char *rgb);
+BU_EXPORT extern int bu_color_to_rgb_chars(struct bu_color *cp, unsigned char 
*rgb);
 
 /* UNIMPLEMENTED
  *
- * BU_EXPORT export void bu_color_from_rgb_chars(struct bu_color *cp, unsigned 
char *rgb);
- * BU_EXPORT export int bu_color_to_rgb_chars(struct bu_color *cp, unsigned 
char *rgb);
- * BU_EXPORT export int bu_color_from_hsv_floats(struct bu_color *cp, fastf_t 
*hsv);
- * BU_EXPORT export int bu_color_to_hsv_floats(struct bu_color *cp, fastf_t 
*hsv);
+ * BU_EXPORT extern int bu_color_from_hsv_floats(struct bu_color *cp, fastf_t 
*hsv);
+ * BU_EXPORT extern int bu_color_to_hsv_floats(struct bu_color *cp, fastf_t 
*hsv);
  */
 
 

Modified: brlcad/trunk/include/bu/opt.h
===================================================================
--- brlcad/trunk/include/bu/opt.h       2015-06-05 15:11:15 UTC (rev 65199)
+++ brlcad/trunk/include/bu/opt.h       2015-06-05 17:27:44 UTC (rev 65200)
@@ -47,7 +47,7 @@
  * Convenience typedef for function callback to validate bu_opt
  * arguments
  */
-typedef int (*bu_opt_arg_process_t)(struct bu_vls *, struct bu_opt_data *);
+typedef int (*bu_opt_arg_process_t)(struct bu_vls *, struct bu_opt_data *, 
void *);
 
 /** Use a typedef to add contextual awareness to the option data return type */
 typedef struct bu_ptbl bu_opt_data_t;
@@ -64,8 +64,9 @@
     bu_opt_arg_process_t arg_process;
     const char *arg_helpstr;
     const char *help_string;
+    void *set_var;
 };
-#define BU_OPT_DESC_NULL {-1, 0, 0, NULL, NULL, NULL, NULL, NULL}
+#define BU_OPT_DESC_NULL {-1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL}
 
 
 /** Output format options for bu_opt documentation generation */
@@ -194,11 +195,11 @@
  * program to use the int/long/etc. without having to repeat the
  * conversion.
  */
-BU_EXPORT extern int bu_opt_arg_int(struct bu_vls *msg, struct bu_opt_data 
*data);
+BU_EXPORT extern int bu_opt_arg_int(struct bu_vls *msg, struct bu_opt_data 
*data, void *set_var);
 /* TODO - unimplemented */
-BU_EXPORT extern int bu_opt_arg_long(struct bu_vls *msg, struct bu_opt_data 
*data);
-BU_EXPORT extern int bu_opt_arg_bool(struct bu_vls *msg, struct bu_opt_data 
*data);
-BU_EXPORT extern int bu_opt_arg_double(struct bu_vls *msg, struct bu_opt_data 
*data);
+BU_EXPORT extern int bu_opt_arg_long(struct bu_vls *msg, struct bu_opt_data 
*data, void *set_var);
+BU_EXPORT extern int bu_opt_arg_bool(struct bu_vls *msg, struct bu_opt_data 
*data, void *set_var);
+BU_EXPORT extern int bu_opt_arg_double(struct bu_vls *msg, struct bu_opt_data 
*data, void *set_var);
 
 
 /** @} */

Modified: brlcad/trunk/src/conv/gcv/gcv.cpp
===================================================================
--- brlcad/trunk/src/conv/gcv/gcv.cpp   2015-06-05 15:11:15 UTC (rev 65199)
+++ brlcad/trunk/src/conv/gcv/gcv.cpp   2015-06-05 17:27:44 UTC (rev 65200)
@@ -32,16 +32,19 @@
 
 
 /* Emulate a FASTGEN4 format option processor */
-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, "tol", 
"Dimensional tolerance." },
-    {FG4_WARN_DEFAULT_NAMES, 0, 0, "w",  "warn-default-names", NULL, "",    
"File format of input file." },
-    BU_OPT_DESC_NULL
-};
-
 void fast4_arg_process(const char *args) {
     struct bu_opt_data *d;
     bu_opt_data_t *results;
+
+    static fastf_t tol;
+
+    enum fg4_opt_enums { FG4_TOL, FG4_WARN_DEFAULT_NAMES };
+    struct bu_opt_desc fg4_opt_desc[3] = {
+       {FG4_TOL,                1, 1, "t",  "tol", &bu_opt_arg_int, "tol", 
"Dimensional tolerance.", (void *)&tol},
+       {FG4_WARN_DEFAULT_NAMES, 0, 0, "w",  "warn-default-names", NULL, "", 
"File format of input file.", NULL},
+       BU_OPT_DESC_NULL
+    };
+
     if (!args) return;
 
     (void)bu_opt_parse_str(&results, NULL, args, fg4_opt_desc);
@@ -58,16 +61,20 @@
 }
 
 /* Emulate a STL format option processor */
-enum stl_opt_enums { STL_TOL, STL_UNITS };
-struct bu_opt_desc stl_opt_desc[3] = {
-    {STL_TOL,   1, 1, "t",  "tol",   NULL, "tol",  "Dimensional tolerance." },
-    {STL_UNITS, 1, 1, "u",  "units", NULL, "unit", "Units of input file." },
-    BU_OPT_DESC_NULL
-};
-
 void stl_arg_process(const char *args) {
     struct bu_opt_data *d;
     bu_opt_data_t *results;
+
+    static fastf_t tol;
+    static int units;
+
+    enum stl_opt_enums { STL_TOL, STL_UNITS };
+    struct bu_opt_desc stl_opt_desc[3] = {
+       {STL_TOL,   1, 1, "t",  "tol",   &bu_opt_arg_int, "tol",  "Dimensional 
tolerance.", (void *)&tol },
+       {STL_UNITS, 1, 1, "u",  "units", &bu_opt_arg_int, "unit", "Units of 
input file.", (void *)&units },
+       BU_OPT_DESC_NULL
+    };
+
     if (!args) return;
 
     (void)bu_opt_parse_str(&results, NULL, args, stl_opt_desc);
@@ -75,7 +82,7 @@
     bu_opt_validate(results);
     d = bu_opt_find("u", results);
     if (d) {
-       bu_log("STL opt found: %s:%s\n", d->name, d->argv[0]);
+       bu_log("STL opt found: %s:%s -> %d\n", d->name, d->argv[0], units);
     }
 
     bu_opt_data_print(results, "STL option parsing results:");
@@ -221,69 +228,53 @@
 }
 
 int
-file_stat(struct bu_vls *UNUSED(msg), struct bu_opt_data *data)
+file_stat(struct bu_vls *UNUSED(msg), struct bu_opt_data *data, void 
*UNUSED(set_var))
 {
     if (!data) return 0;
     if (!data->argv || data->argc == 0) {
-       data->valid = 0;
-       return 1;
+       return -1;
     }
     if (!bu_file_exists(data->argv[0], NULL)){
-       data->valid = 0;
+       return -1;
     }
     return 1;
 }
 
     int
-file_null(struct bu_vls *msg, struct bu_opt_data *data)
+file_null(struct bu_vls *msg, struct bu_opt_data *data, void *UNUSED(set_var))
 {
     if (!data) return 0;
     if (!data->argv || data->argc == 0) {
-       data->valid = 0;
-       return 1;
     }
     if (bu_file_exists(data->argv[0], NULL)){
-       data->valid = 0;
        if (msg) bu_vls_sprintf(msg, "Error - file %s already exists!\n", 
data->argv[0]);
+       return -1;
     }
     return 1;
 }
 
 int
-model_mime(struct bu_vls *UNUSED(msg), struct bu_opt_data *data)
+model_mime(struct bu_vls *UNUSED(msg), struct bu_opt_data *data, void 
*set_mime)
 {
     int type_int;
     mime_model_t type = MIME_MODEL_UNKNOWN;
+    mime_model_t *set_type = (mime_model_t *)set_mime;
     if (!data) return 0;
     if (!data->argv || data->argc == 0) {
-       data->valid = 0;
-       return 1;
+       return -1;
     }
     type_int = bu_file_mime(data->argv[0], MIME_MODEL);
     type = (type_int < 0) ? MIME_MODEL_UNKNOWN : (mime_model_t)type_int;
     if (type == MIME_MODEL_UNKNOWN) {
-       data->valid = 0;
-       return 1;
+       return -1;
     }
+    if (set_type) (*set_type) = type;
     return 1;
 }
 
 
 #define gcv_help_str "Print help and exit.  If a format is specified to 
--help, print help specific to that format"
-enum gcv_opt_enums { GCV_HELP, IN_FILE, OUT_FILE, IN_FORMAT, OUT_FORMAT, 
IN_OPTS, OUT_OPTS, GCV_OPTS_MAX };
-struct bu_opt_desc gcv_opt_desc[9] = {
-    {GCV_HELP,    0, 1, "h", "help",             NULL,          "format", 
gcv_help_str},
-    {GCV_HELP,    0, 1, "?", "",                 NULL,          "format", ""},
-    {IN_FILE ,    1, 1, "i", "input",            &(file_stat),  "file",   
"Input file." },
-    {OUT_FILE,    1, 1, "o", "output",           &(file_null),  "file",   
"Output file." },
-    {IN_FORMAT ,  1, 1, "",  "input-format",     &(model_mime), "format", 
"File format of input file." },
-    {OUT_FORMAT , 1, 1, "",  "output-format",    &(model_mime), "format", 
"File format of output file." },
-    {IN_OPTS ,    1, 1, "I", "input-only-opts",  NULL,          "\"[opts]\"", 
"Options to apply only while processing input file.  Quotes around the opts are 
always necessary, but brackets are only necessary when supplying a single 
option without arguments that would otherwise be interpreted as an argv entry 
by the shell, even with quotes.  Brackets will never hurt, and for robustness 
when scripting they should always be used." },
-    {OUT_OPTS,    1, 1, "O", "output-only-opts", NULL,          "\"[opts]\"", 
"Options to apply only while preparing output file.  Quotes around the opts are 
always necessary, but brackets are only necessary when supplying a single 
option without arguments that would otherwise be interpreted as an argv entry 
by the shell, even with quotes.  Brackets will never hurt, and for robustness 
when scripting they should always be used." },
-    BU_OPT_DESC_NULL
-};
 
-
 int
 main(int ac, char **av)
 {
@@ -296,8 +287,8 @@
     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;
+    static mime_model_t in_type = MIME_MODEL_UNKNOWN;
+    static mime_model_t out_type = MIME_MODEL_UNKNOWN;
     struct bu_vls in_format = BU_VLS_INIT_ZERO;
     struct bu_vls in_path_raw = BU_VLS_INIT_ZERO;
     struct bu_vls in_path = BU_VLS_INIT_ZERO;
@@ -310,6 +301,19 @@
     struct bu_opt_data *d = NULL;
     bu_opt_data_t *results = NULL;
 
+    enum gcv_opt_enums { GCV_HELP, IN_FILE, OUT_FILE, IN_FORMAT, OUT_FORMAT, 
IN_OPTS, OUT_OPTS, GCV_OPTS_MAX };
+    struct bu_opt_desc gcv_opt_desc[9] = {
+       {GCV_HELP,    0, 1, "h", "help",             NULL,          "format", 
gcv_help_str, NULL},
+       {GCV_HELP,    0, 1, "?", "",                 NULL,          "format", 
"", NULL},
+       {IN_FILE ,    1, 1, "i", "input",            &(file_stat),  "file",   
"Input file.", NULL},
+       {OUT_FILE,    1, 1, "o", "output",           &(file_null),  "file",   
"Output file.", NULL },
+       {IN_FORMAT ,  1, 1, "",  "input-format",     &(model_mime), "format", 
"File format of input file.", (void *)&in_type },
+       {OUT_FORMAT , 1, 1, "",  "output-format",    &(model_mime), "format", 
"File format of output file.", (void *)&out_type },
+       {IN_OPTS ,    1, 1, "I", "input-only-opts",  NULL,          
"\"[opts]\"", "Options to apply only while processing input file.  Quotes 
around the opts are always necessary, but brackets are only necessary when 
supplying a single option without arguments that would otherwise be interpreted 
as an argv entry by the shell, even with quotes.  Brackets will never hurt, and 
for robustness when scripting they should always be used.", NULL },
+       {OUT_OPTS,    1, 1, "O", "output-only-opts", NULL,          
"\"[opts]\"", "Options to apply only while preparing output file.  Quotes 
around the opts are always necessary, but brackets are only necessary when 
supplying a single option without arguments that would otherwise be interpreted 
as an argv entry by the shell, even with quotes.  Brackets will never hurt, and 
for robustness when scripting they should always be used.", NULL },
+       BU_OPT_DESC_NULL
+    };
+
     ac-=(ac>0); av+=(ac>0); // skip program name argv[0] if present
 
     if (ac == 0) {

Modified: brlcad/trunk/src/libbu/color.c
===================================================================
--- brlcad/trunk/src/libbu/color.c      2015-06-05 15:11:15 UTC (rev 65199)
+++ brlcad/trunk/src/libbu/color.c      2015-06-05 17:27:44 UTC (rev 65200)
@@ -215,8 +215,47 @@
     return 1;
 }
 
+int
+bu_color_to_rgb_chars(struct bu_color *cp, unsigned char *rgb)
+{
+    unsigned int r, g, b;
+    if (UNLIKELY(!cp || !rgb)) {
+       return 0;
+    }
+    r = (unsigned int)cp->buc_rgb[RED];
+    g = (unsigned int)cp->buc_rgb[GRN];
+    b = (unsigned int)cp->buc_rgb[BLU];
 
+    rgb[0] = (unsigned char)r;
+    rgb[1] = (unsigned char)g;
+    rgb[2] = (unsigned char)b;
+
+    return 1;
+}
+
+
 int
+bu_color_from_rgb_chars(struct bu_color *cp, unsigned char *rgb)
+{
+    unsigned int r, g, b;
+    if (UNLIKELY(!cp || !rgb)) {
+       return 0;
+    }
+
+    r = (unsigned int)rgb[RED];
+    g = (unsigned int)rgb[GRN];
+    b = (unsigned int)rgb[BLU];
+
+
+    cp->buc_rgb[RED] = (fastf_t)r;
+    cp->buc_rgb[GRN] = (fastf_t)g;
+    cp->buc_rgb[BLU] = (fastf_t)b;
+
+    return 1;
+}
+
+
+int
 bu_color_to_rgb_floats(struct bu_color *cp, fastf_t *rgb)
 {
     if (UNLIKELY(!cp || !rgb)) {

Modified: brlcad/trunk/src/libbu/opt.c
===================================================================
--- brlcad/trunk/src/libbu/opt.c        2015-06-05 15:11:15 UTC (rev 65199)
+++ brlcad/trunk/src/libbu/opt.c        2015-06-05 17:27:44 UTC (rev 65200)
@@ -22,6 +22,8 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h> /* for strtol */
+#include <limits.h> /* for INT_MAX */
 #include <ctype.h> /* for isspace */
 
 #include "bu/log.h"
@@ -510,7 +512,7 @@
 }
 
 int
-bu_opt_parse(struct bu_ptbl **tbl, struct bu_vls *UNUSED(msgs), int argc, 
const char **argv, struct bu_opt_desc *ds)
+bu_opt_parse(struct bu_ptbl **tbl, struct bu_vls *msgs, int argc, const char 
**argv, struct bu_opt_desc *ds)
 {
     int i = 0;
     int offset = 0;
@@ -518,7 +520,7 @@
     struct bu_ptbl *opt_data;
     struct bu_ptbl unknown_args = BU_PTBL_INIT_ZERO;
     struct bu_opt_data *unknown = NULL;
-    if (!argv || !ds) return 1;
+    if (!argv || !ds) return -1;
 
     BU_GET(opt_data, struct bu_ptbl);
     bu_ptbl_init(opt_data, 8, "opt_data");
@@ -615,7 +617,7 @@
                int g_argc = desc->arg_cnt_max;
                const char **g_argv = (const char **)bu_calloc(g_argc + arg_cnt 
+ 1, sizeof(char *), "greedy argv");
                if (!g_argc && arg_cnt) g_argc = arg_cnt;
-               if (i != argc) {
+               if (i != argc || arg_cnt) {
                    if (arg_cnt)
                        g_argv[0] = eq_arg;
                    for (k = arg_cnt; k < g_argc; k++) {
@@ -623,7 +625,16 @@
                    }
                    data->argc = g_argc;
                    data->argv = g_argv;
-                   arg_offset = (*desc->arg_process)(NULL, data);
+                   arg_offset = (*desc->arg_process)(msgs, data, 
desc->set_var);
+                   if (arg_offset == -1) {
+                       /* This isn't just an unknown option to be passed
+                        * through for possible later processing.  If the
+                        * arg_process callback returns -1, something has gone
+                        * seriously awry and a known-to-be-invalid arg was
+                        * seen.  Fail early and hard. */
+                       if (msgs) bu_vls_printf(msgs, "Invalid argument 
supplied to %s - haulting.\n", argv[i-1]);
+                       return -1;
+                   }
                    i = i + arg_offset - arg_cnt;
                    if (!arg_offset && arg_cnt) arg_offset = arg_cnt;
                    /* If we used 1 or more args, construct the final argv 
array that will
@@ -693,25 +704,37 @@
 
 
 int
-bu_opt_arg_int(struct bu_vls *UNUSED(msg), struct bu_opt_data *data)
+bu_opt_arg_int(struct bu_vls *msg, struct bu_opt_data *data, void *set_var)
 {
-    int i, ret;
+    long int l;
+    int i;
+    char *endptr = NULL;
+    int *int_set = (int *)set_var;
     if (!data) return 0;
 
-    if (data->argc != 1 || !data->argv || !data->argv[0]) {
-       data->valid = 0;
+    if (!data || !data->argv || !data->argv[0] || strlen(data->argv[0]) == 0 
|| data->argc != 1 ) {
        return 0;
     }
 
-    ret = bu_sscanf(data->argv[0], "%i", &i);
+    l = strtol(data->argv[0], &endptr, 0);
 
-    if (ret == 0) {
-       data->valid = 0;
-       return 1;
+    if (endptr != NULL && strlen(endptr) > 0) {
+       /* Had some invalid character in the input, fail */
+       if (msg) bu_vls_printf(msg, "Invalid string specifier for int: %s\n", 
data->argv[0]);
+       return -1;
+    }
+
+    /* If the long fits inside an int, we're OK */
+    if (l <= INT_MAX || l >= -INT_MAX) {
+       i = (int)l;
     } else {
-       return 1;
+       /* Too big or too small, fail */
+       if (msg) bu_vls_printf(msg, "String specifies number too large for int 
data type: %l\n", l);
+       return -1;
     }
 
+    if (int_set) (*int_set) = i;
+    return 1;
 }
 
 

Modified: brlcad/trunk/src/libbu/tests/opt.c
===================================================================
--- brlcad/trunk/src/libbu/tests/opt.c  2015-06-05 15:11:15 UTC (rev 65199)
+++ brlcad/trunk/src/libbu/tests/opt.c  2015-06-05 17:27:44 UTC (rev 65200)
@@ -19,23 +19,24 @@
  */
 
 #include "common.h"
+#include <limits.h>
 #include <ctype.h>
 #include "bu.h"
 #include "bn.h"
 #include "string.h"
 
 int
-d1_verbosity(struct bu_vls *msg, struct bu_opt_data *data)
+d1_verbosity(struct bu_vls *msg, struct bu_opt_data *data, void *set_v)
 {
-    int verb;
-    if (!data) return 0;
-    if (!data->argv || data->argc == 0) {
-       data->valid = 0;
-       return 0;
-    }
-    if (msg) bu_vls_sprintf(msg, "d1");
-    sscanf(data->argv[0], "%d", &verb);
-    if (verb < 0 || verb > 3) data->valid = 0;
+    int val = INT_MAX;
+    int *int_set = (int *)set_v;
+    int int_ret = bu_opt_arg_int(msg, data, (void *)&val);
+    if (int_ret == -1 || int_ret == 0) return int_ret;
+
+    if (val < 0 || val > 3) return -1;
+
+    if (int_set) (*int_set) = val;
+
     return 1;
 }
 
@@ -49,51 +50,44 @@
 }
 
 int
-d2_color(struct bu_vls *msg, struct bu_opt_data *data)
+d2_color(struct bu_vls *msg, struct bu_opt_data *data, void *set_c)
 {
-    unsigned int *rgb;
-    if (!data) return 0;
-    if (!data->argv || data->argc == 0) {
-       data->valid = 0;
+    struct bu_color *set_color = (struct bu_color *)set_c;
+    unsigned int rgb[3];
+    if (!data || !data->argv || !data->argv[0] || strlen(data->argv[0]) == 0 
|| data->argc == 0) {
        return 0;
     }
-    if (msg) bu_vls_sprintf(msg, "d2");
 
-    rgb = (unsigned int *)bu_calloc(3, sizeof(unsigned int), "fastf_t array");
-
     /* First, see if the first string converts to rgb */
     if (!bu_str_to_rgb((char *)data->argv[0], (unsigned char *)&rgb)) {
        /* nope - maybe we have 3 argv? */
        if (data->argc == 3) {
-           int rn = 0, gn = 0, bn = 0;
-           if (isnum(data->argv[0]))
-               rn = sscanf(data->argv[0], "%02x", &rgb[0]);
-           if (isnum(data->argv[1]))
-               gn = sscanf(data->argv[1], "%02x", &rgb[1]);
-           if (isnum(data->argv[2]))
-               bn = sscanf(data->argv[2], "%02x", &rgb[2]);
-           if (rn != 1 || gn != 1 || bn != 1) {
-               data->valid = 0;
-               bu_free(rgb, "free rgb");
-               return 1;
+           struct bu_vls tmp_color = BU_VLS_INIT_ZERO;
+           bu_vls_sprintf(&tmp_color, "%s/%s/%s", data->argv[0], 
data->argv[1], data->argv[2]);
+           if (!bu_str_to_rgb(bu_vls_addr(&tmp_color), (unsigned char *)&rgb)) 
{
+               /* Not valid with 3 */
+               bu_vls_free(&tmp_color);
+               if (msg) bu_vls_sprintf(msg, "No valid color found.");
+               return -1;
            } else {
-               data->user_data = (void *)rgb;
+               /* 3 did the job */
+               bu_vls_free(&tmp_color);
+               if (set_color) (void)bu_color_from_rgb_chars(set_color, 
(unsigned char *)&rgb);
                return 3;
            }
        } else {
            /* Not valid with 1 and don't have 3 - we require at least one, so
             * claim one argv as belonging to this option regardless. */
-           data->valid = 0;
-           bu_free(rgb, "free rgb");
-           return 1;
+           if (msg) bu_vls_sprintf(msg, "No valid color found: %s", 
data->argv[0]);
+           return -1;
        }
     } else {
        /* yep, 1 did the job */
-       data->user_data = (void *)rgb;
+       if (set_color) (void)bu_color_from_rgb_chars(set_color, (unsigned char 
*)&rgb);
        return 1;
     }
 
-    return 1;
+    return 0;
 }
 
 void
@@ -121,28 +115,32 @@
 int
 main(int argc, const char **argv)
 {
+    int ret = 0;
     int function_num;
     struct bu_ptbl *results = NULL;
+    struct bu_vls parse_msgs = BU_VLS_INIT_ZERO;
+    static int i = 0;
+    static struct bu_color color = BU_COLOR_INIT_ZERO;
 
     enum d1_opt_ind {D1_HELP, D1_VERBOSITY};
     struct bu_opt_desc d1[4] = {
-       {D1_HELP, 0, 0, "h", "help", NULL, "", help_str},
-       {D1_HELP, 0, 0, "?", "",     NULL, "", help_str},
-       {D1_VERBOSITY, 0, 1, "v", "verbosity", &(d1_verbosity), "#", "Set 
verbosity (range is 0 to 3)"},
+       {D1_HELP, 0, 0, "h", "help", NULL, "", help_str, NULL},
+       {D1_HELP, 0, 0, "?", "",     NULL, "", help_str, NULL},
+       {D1_VERBOSITY, 0, 1, "v", "verbosity", &(d1_verbosity), "#", "Set 
verbosity (range is 0 to 3)", (void *)&i},
        BU_OPT_DESC_NULL
     };
 
     enum d2_opt_ind {D2_HELP, D2_COLOR};
     struct bu_opt_desc d2[4] = {
-       {D2_HELP, 0, 0, "h", "help", NULL, "", help_str},
-       {D2_COLOR, 1, 3, "C", "color", &(d2_color), "r/g/b", "Set color"},
+       {D2_HELP, 0, 0, "h", "help", NULL, "", help_str, NULL},
+       {D2_COLOR, 1, 3, "C", "color", &(d2_color), "r/g/b", "Set color", (void 
*)&color},
        BU_OPT_DESC_NULL
     };
 
     enum d3_opt_ind {D3_HELP, D3_NUM};
     struct bu_opt_desc d3[4] = {
-       {D3_HELP, 0, 0, "h", "help", NULL, "", help_str},
-       {D3_NUM, 1, 1, "n", "num", &bu_opt_arg_int, "#", "Read number"},
+       {D3_HELP, 0, 0, "h", "help", NULL, "", help_str, NULL},
+       {D3_NUM, 1, 1, "n", "num", &bu_opt_arg_int, "#", "Read number", (void 
*)&i},
        BU_OPT_DESC_NULL
     };
 
@@ -155,25 +153,35 @@
 
     switch (function_num) {
        case 0:
-           (void)bu_opt_parse(&results, NULL, 0, NULL, NULL);
+           ret = bu_opt_parse(&results, &parse_msgs, 0, NULL, NULL);
            return (results == NULL) ? 0 : 1;
            break;
        case 1:
-           (void)bu_opt_parse(&results, NULL, argc-2, argv+2, d1);
+           ret = bu_opt_parse(&results, &parse_msgs, argc-2, argv+2, d1);
            break;
        case 2:
-           (void)bu_opt_parse(&results, NULL, argc-2, argv+2, d2);
+           ret = bu_opt_parse(&results, &parse_msgs, argc-2, argv+2, d2);
            break;
        case 3:
-           (void)bu_opt_parse(&results, NULL, argc-2, argv+2, d3);
+           ret = bu_opt_parse(&results, &parse_msgs, argc-2, argv+2, d3);
            break;
     }
 
+    if (ret == -1) {
+       bu_log("%s", bu_vls_addr(&parse_msgs));
+    }
+
     if (results) {
        bu_opt_compact(results);
        print_results(results);
+       if (function_num == 1 || function_num == 3)
+           bu_log("Int var: %d\n", i);
+       if (function_num == 2)
+           bu_log("Color var: %0.2f, %0.2f, %0.2f\n", color.buc_rgb[0], 
color.buc_rgb[1], color.buc_rgb[2]);
     }
 
+    bu_vls_free(&parse_msgs);
+
     return 0;
 }
 

Modified: brlcad/trunk/src/util/dsp_add_opt.c
===================================================================
--- brlcad/trunk/src/util/dsp_add_opt.c 2015-06-05 15:11:15 UTC (rev 65199)
+++ brlcad/trunk/src/util/dsp_add_opt.c 2015-06-05 17:27:44 UTC (rev 65200)
@@ -45,8 +45,8 @@
 
 enum dsp_add_enums {DSP_HELP};
 struct bu_opt_desc dsp_opt_desc[3] = {
-    {DSP_HELP, 0, 0, "h", "help", NULL, "", "Print help and exit"},
-    {DSP_HELP, 0, 0, "?", "",     NULL, "", ""},
+    {DSP_HELP, 0, 0, "h", "help", NULL, "", "Print help and exit", NULL},
+    {DSP_HELP, 0, 0, "?", "",     NULL, "", "", NULL},
     BU_OPT_DESC_NULL
 };
 

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