Revision: 65125
http://sourceforge.net/p/brlcad/code/65125
Author: starseeker
Date: 2015-05-31 18:01:04 +0000 (Sun, 31 May 2015)
Log Message:
-----------
Add an option validate pass that removes any bu_opt_data entries that tested
invalid according to their testing function. Purpose is to allow calling
programs to trust casts of user_data.
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-31 17:45:05 UTC (rev 65124)
+++ brlcad/trunk/include/bu/opt.h 2015-05-31 18:01:04 UTC (rev 65125)
@@ -272,7 +272,13 @@
*/
BU_EXPORT extern void bu_opt_compact(bu_opt_data_t *results);
+/**
+ * Audit a set of results and remove any bu_opt_data entries that are not
marked
+ * as valid.
+ */
+BU_EXPORT extern void bu_opt_validate(bu_opt_data_t *results);
+
/* Standard option validators - if a custom option argument
* validation isn't needed, the functions below can be
* used for most valid data types. When data conversion is successful,
Modified: brlcad/trunk/src/conv/gcv/gcv.cpp
===================================================================
--- brlcad/trunk/src/conv/gcv/gcv.cpp 2015-05-31 17:45:05 UTC (rev 65124)
+++ brlcad/trunk/src/conv/gcv/gcv.cpp 2015-05-31 18:01:04 UTC (rev 65125)
@@ -45,6 +45,8 @@
if (!args) return;
(void)bu_opt_parse_str(&results, NULL, args, fg4_opt_desc);
+ bu_opt_compact(results);
+ bu_opt_validate(results);
d = bu_opt_find(FG4_WARN_DEFAULT_NAMES, results);
if (d) {
bu_log("FASTGEN 4 opt found: %s\n", d->name);
@@ -69,6 +71,8 @@
if (!args) return;
(void)bu_opt_parse_str(&results, NULL, args, stl_opt_desc);
+ bu_opt_compact(results);
+ bu_opt_validate(results);
d = bu_opt_find(STL_UNITS, results);
if (d) {
bu_log("STL opt found: %s:%s\n", d->name, bu_opt_data_arg(d, 0));
Modified: brlcad/trunk/src/libbu/opt.c
===================================================================
--- brlcad/trunk/src/libbu/opt.c 2015-05-31 17:45:05 UTC (rev 65124)
+++ brlcad/trunk/src/libbu/opt.c 2015-05-31 18:01:04 UTC (rev 65125)
@@ -576,7 +576,7 @@
for (i = ptblpos - 1; i >= 0; i--) {
struct bu_opt_data *dc = (struct bu_opt_data *)BU_PTBL_GET(opts, i);
if ((dc && dc->desc && data->desc) && dc->desc->index ==
data->desc->index) {
- bu_free(dc, "free duplicate");
+ bu_opt_data_free_entry(dc);
BU_PTBL_CLEAR_I(opts, i);
}
}
@@ -589,6 +589,30 @@
bu_ptbl_free(&tbl);
}
+
+void
+bu_opt_validate(struct bu_ptbl *opts)
+{
+ size_t i;
+ struct bu_ptbl tbl;
+ bu_ptbl_init(&tbl, 8, "local table");
+ for (i = 0; i < BU_PTBL_LEN(opts); i++) {
+ struct bu_opt_data *dc = (struct bu_opt_data *)BU_PTBL_GET(opts, i);
+ if (dc && (dc->valid || (dc->desc && dc->desc->index == -1))) {
+ bu_ptbl_ins(&tbl, (long *)dc);
+ } else {
+ bu_opt_data_free_entry(dc);
+ BU_PTBL_CLEAR_I(opts, i);
+ }
+ }
+ bu_ptbl_reset(opts);
+ for (i = 0; i < BU_PTBL_LEN(&tbl); i++) {
+ bu_ptbl_ins(opts, BU_PTBL_GET(&tbl, i));
+ }
+ bu_ptbl_free(&tbl);
+}
+
+
/* This implements criteria for deciding when an argv string is
* an option. Right now the criteria are:
*
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