Revision: 77695
http://sourceforge.net/p/brlcad/code/77695
Author: brlcad
Date: 2020-11-05 07:36:07 +0000 (Thu, 05 Nov 2020)
Log Message:
-----------
refactor three of the four search result iterations into a function
Modified Paths:
--------------
brlcad/trunk/src/libged/search/search.c
Modified: brlcad/trunk/src/libged/search/search.c
===================================================================
--- brlcad/trunk/src/libged/search/search.c 2020-11-05 05:34:11 UTC (rev
77694)
+++ brlcad/trunk/src/libged/search/search.c 2020-11-05 07:36:07 UTC (rev
77695)
@@ -244,6 +244,26 @@
}
+HIDDEN void
+search_print_objs_to_vls(const struct bu_ptbl *objs, struct bu_vls *out)
+{
+ size_t len;
+
+ if (!objs || !out)
+ return;
+
+ len = BU_PTBL_LEN(objs);
+ if (len > 0) {
+ bu_sort((void *)BU_PTBL_BASEADDR(objs), len, sizeof(struct directory
*), dp_name_compare, NULL);
+
+ while (len-- > 0) {
+ struct directory *uniq_dp = (struct directory *)BU_PTBL_GET(objs,
len);
+ bu_vls_printf(out, "%s\n", uniq_dp->d_namep);
+ }
+ }
+}
+
+
int
ged_search_core(struct ged *gedp, int argc, const char *argv_orig[])
{
@@ -455,7 +475,6 @@
* return one unique list of objects. If one or more paths are non-local,
* each path is treated as its own search */
if (all_local) {
- size_t len;
struct bu_ptbl *uniq_db_objs;
BU_ALLOC(uniq_db_objs, struct bu_ptbl);
@@ -479,15 +498,8 @@
}
}
- /* For this return, we want a list of all unique leaf objects */
- bu_sort((void *)BU_PTBL_BASEADDR(uniq_db_objs),
BU_PTBL_LEN(uniq_db_objs), sizeof(struct directory *), dp_name_compare, NULL);
+ search_print_objs_to_vls(uniq_db_objs, gedp->ged_result_str);
- len = BU_PTBL_LEN(uniq_db_objs);
- while (len-- > 0) {
- struct directory *uniq_dp = (struct directory
*)BU_PTBL_GET(uniq_db_objs, len);
- bu_vls_printf(gedp->ged_result_str, "%s\n", uniq_dp->d_namep);
- }
-
bu_ptbl_free(uniq_db_objs);
bu_free(uniq_db_objs, "free unique object container");
@@ -530,21 +542,14 @@
}
}
- sr_len = j = BU_PTBL_LEN(search_results);
- if (sr_len > 0) {
- bu_sort((void *)BU_PTBL_BASEADDR(search_results),
sr_len, sizeof(struct directory *), dp_name_compare, NULL);
+ search_print_objs_to_vls(search_results,
gedp->ged_result_str);
- while (j-- > 0) {
- struct directory *uniq_dp = (struct directory
*)BU_PTBL_GET(search_results, j);
- bu_vls_printf(gedp->ged_result_str, "%s\n",
uniq_dp->d_namep);
- }
- }
+ db_search_free(search_results);
+ bu_free(search_results, "free search container");
/* Make sure to clear the flag in case of subsequent
searches of different types */
+ flags = flags & ~(DB_SEARCH_FLAT);
- flags = flags & ~(DB_SEARCH_FLAT);
- db_search_free(search_results);
- bu_free(search_results, "free search container");
} else {
struct directory *curr_path = search->paths[path_cnt];
@@ -574,21 +579,15 @@
case 1:
flags |= DB_SEARCH_RETURN_UNIQ_DP;
(void)db_search(search_results, flags,
bu_vls_addr(&search_string), 1, &curr_path, gedp->ged_wdbp->dbip, ctx);
- sr_len = j = BU_PTBL_LEN(search_results);
- if (sr_len > 0) {
- bu_sort((void
*)BU_PTBL_BASEADDR(search_results), sr_len, sizeof(struct directory *),
dp_name_compare, NULL);
+ search_print_objs_to_vls(search_results,
gedp->ged_result_str);
- while (j-- > 0) {
- struct directory *uniq_dp = (struct
directory *)BU_PTBL_GET(search_results, j);
- bu_vls_printf(gedp->ged_result_str,
"%s\n", uniq_dp->d_namep);
- }
- }
break;
default:
bu_log("Warning - ignoring unknown search type
%d\n", search->search_type);
break;
}
+
db_search_free(search_results);
bu_free(search_results, "free search container");
bu_vls_free(&fullpath_string);
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