Revision: 75954
http://sourceforge.net/p/brlcad/code/75954
Author: starseeker
Date: 2020-05-27 23:52:43 +0000 (Wed, 27 May 2020)
Log Message:
-----------
Per user feedback, implement a feature similar to a script by Nick that prints
ranges of unused ids rather than each individual id. Also, don't silently
ignore invalid range specifications.
Modified Paths:
--------------
brlcad/trunk/src/libged/which.cpp
Modified: brlcad/trunk/src/libged/which.cpp
===================================================================
--- brlcad/trunk/src/libged/which.cpp 2020-05-27 18:40:40 UTC (rev 75953)
+++ brlcad/trunk/src/libged/which.cpp 2020-05-27 23:52:43 UTC (rev 75954)
@@ -139,6 +139,10 @@
ids.insert(start + k);
}
break;
+ default:
+ bu_vls_printf(gedp->ged_result_str, "Error: invalid range
specification \"%s\"", argv[j]);
+ bu_vls_free(&root);
+ return GED_ERROR;
}
}
@@ -214,12 +218,46 @@
return GED_OK;
}
}
- for (i_it = unused_ids.begin(); i_it != unused_ids.end(); i_it++) {
- if (sflag) {
+ if (sflag) {
+ for (i_it = unused_ids.begin(); i_it != unused_ids.end(); i_it++) {
bu_vls_printf(gedp->ged_result_str, " %d", *i_it);
- } else {
- bu_vls_printf(gedp->ged_result_str, " %d\n", *i_it);
}
+ } else {
+ // To reduce verbosity, assemble and print ranges of unused numbers
rather
+ // that just dumping all of them
+ int rstart = -1;
+ int rend = -1;
+ int rprev = -1;
+ for (i_it = unused_ids.begin(); i_it != unused_ids.end(); i_it++) {
+ if (rstart == -1 || (*i_it != rprev+1)) {
+ // Print intermediate results, if we find a sequence within
+ // the overall results.
+ if (rstart != -1) {
+ if (rend != -1) {
+ bu_vls_printf(gedp->ged_result_str, " %d-%d\n",
rstart, rend);
+ } else {
+ bu_vls_printf(gedp->ged_result_str, " %d\n",
rstart);
+ }
+ rend = -1;
+ }
+ rstart = *i_it;
+ rprev = *i_it;
+ continue;
+ }
+ rprev = *i_it;
+ rend = *i_it;
+ continue;
+ }
+ // Print the last results
+ if (rstart != -1) {
+ if (rend != -1) {
+ bu_vls_printf(gedp->ged_result_str, " %d-%d\n", rstart,
rend);
+ } else {
+ bu_vls_printf(gedp->ged_result_str, " %d\n", rstart);
+ }
+ rend = -1;
+ }
+
}
bu_vls_free(&root);
return GED_OK;
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