Revision: 77682
http://sourceforge.net/p/brlcad/code/77682
Author: brlcad
Date: 2020-11-04 18:51:50 +0000 (Wed, 04 Nov 2020)
Log Message:
-----------
inject some newlines for readability. helps to separate decls and setting
values from work loops. it's hard for non-authors (or at least it is for me)
to read walls of code quickly otherwise.
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-04 15:01:58 UTC (rev
77681)
+++ brlcad/trunk/src/libged/search/search.c 2020-11-04 18:51:50 UTC (rev
77682)
@@ -171,7 +171,10 @@
(*flat_only) = 0;
(*is_specific) = 0;
(*is_local) = 0;
- if (!orig || !normalized) return 0;
+
+ if (!orig || !normalized)
+ return 0;
+
if (BU_STR_EQUAL(orig, "/")) {
return 1;
}
@@ -183,6 +186,7 @@
(*flat_only) = 1;
return 1;
}
+
bu_vls_sprintf(normalized, "%s", orig);
if (bu_vls_addr(normalized)[0] == '|') {
(*is_flat) = 1;
@@ -195,11 +199,14 @@
(*is_local) = 1;
return 1;
}
+
(*is_local) = _path_scrub(normalized);
- if (!bu_vls_strlen(normalized)) return 0;
+ if (!bu_vls_strlen(normalized))
+ return 0;
if (BU_STR_EQUAL(bu_vls_addr(normalized), "/")) {
return 1;
}
+
/* We've handled the toplevel special cases - now the only question
* is is the path valid */
(*is_specific) = 1;
@@ -219,7 +226,9 @@
int j;
const char *comb_str = "-name *";
struct bu_ptbl *tmp_search;
+
BU_ALLOC(tmp_search, struct bu_ptbl);
+
(void)db_search(tmp_search, DB_SEARCH_RETURN_UNIQ_DP, comb_str, 1, &path,
gedp->ged_wdbp->dbip, ctx);
path_cnt = (int)BU_PTBL_LEN(tmp_search);
(*path_list) = (struct directory **)bu_malloc(sizeof(char *) *
(path_cnt+1), "object path array");
@@ -226,9 +235,11 @@
for (j = 0; j < path_cnt; j++) {
(*path_list)[j] = (struct directory *)BU_PTBL_GET(tmp_search, j);
}
+
(*path_list)[path_cnt] = RT_DIR_NULL;
bu_ptbl_free(tmp_search);
bu_free(tmp_search, "Free search table container");
+
return path_cnt;
}
@@ -329,16 +340,22 @@
/* If any specific paths are specified before the plan, we need to identify
* them and construct search structs. */
while (!plan_found) {
+
if (!argv[plan_argv]) {
/* OK, no plan - will use default behavior */
plan_found = 1;
+
} else {
+
if (!(_ged_plan_item(argv[plan_argv]))) {
/* We seem to have a path - figure out what type of search it
specifies */
int is_specific, is_local, is_flat, flat_only;
struct ged_search *new_search;
- int search_path_type = _ged_search_characterize_path(gedp,
argv[plan_argv], &argvls, &is_specific, &is_local, &is_flat, &flat_only);
+ int search_path_type;
+
+ search_path_type = _ged_search_characterize_path(gedp,
argv[plan_argv], &argvls, &is_specific, &is_local, &is_flat, &flat_only);
path_found = 1;
+
if (search_path_type) {
BU_ALLOC(new_search, struct ged_search);
} else {
@@ -349,16 +366,22 @@
} else {
bu_vls_trunc(gedp->ged_result_str, 0);
}
+
bu_vls_free(&argvls);
bu_argv_free(argc, argv);
_ged_free_search_set(search_set);
return (wflag) ? GED_OK : GED_ERROR;
}
+
if (!is_specific) {
- if (!is_flat && !aflag && !flat_only) new_search->path_cnt
= db_ls(gedp->ged_wdbp->dbip, DB_LS_TOPS, NULL, &(new_search->paths));
- if (!is_flat && aflag && !flat_only) new_search->path_cnt =
db_ls(gedp->ged_wdbp->dbip, DB_LS_TOPS | DB_LS_HIDDEN, NULL,
&(new_search->paths));
- if (is_flat && !aflag && !flat_only) new_search->path_cnt =
db_ls(gedp->ged_wdbp->dbip, 0, NULL, &(new_search->paths));
- if (is_flat && aflag && !flat_only) new_search->path_cnt =
db_ls(gedp->ged_wdbp->dbip, DB_LS_HIDDEN, NULL, &(new_search->paths));
+ if (!is_flat && !aflag && !flat_only)
+ new_search->path_cnt = db_ls(gedp->ged_wdbp->dbip,
DB_LS_TOPS, NULL, &(new_search->paths));
+ if (!is_flat && aflag && !flat_only)
+ new_search->path_cnt = db_ls(gedp->ged_wdbp->dbip,
DB_LS_TOPS | DB_LS_HIDDEN, NULL, &(new_search->paths));
+ if (is_flat && !aflag && !flat_only)
+ new_search->path_cnt = db_ls(gedp->ged_wdbp->dbip, 0,
NULL, &(new_search->paths));
+ if (is_flat && aflag && !flat_only)
+ new_search->path_cnt = db_ls(gedp->ged_wdbp->dbip,
DB_LS_HIDDEN, NULL, &(new_search->paths));
} else {
/* _ged_search_characterize_path verified that the
db_lookup will succeed */
struct directory *local_dp =
db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(&argvls), LOOKUP_QUIET);
@@ -371,18 +394,27 @@
new_search->path_cnt = 1;
}
}
+
new_search->search_type = is_local;
- if (flat_only) new_search->search_type = 2;
+ if (flat_only)
+ new_search->search_type = 2;
bu_ptbl_ins(search_set, (long *)new_search);
plan_argv++;
+
} else {
plan_found = 1;
+
if (!path_found) {
/* We have a plan but not path - in that case, do a
non-full-path tops search */
struct ged_search *new_search;
+
BU_ALLOC(new_search, struct ged_search);
- if (!aflag) new_search->path_cnt =
db_ls(gedp->ged_wdbp->dbip, DB_LS_TOPS, NULL, &(new_search->paths));
- if (aflag) new_search->path_cnt =
db_ls(gedp->ged_wdbp->dbip, DB_LS_TOPS | DB_LS_HIDDEN, NULL,
&(new_search->paths));
+
+ if (!aflag)
+ new_search->path_cnt = db_ls(gedp->ged_wdbp->dbip,
DB_LS_TOPS, NULL, &(new_search->paths));
+ if (aflag)
+ new_search->path_cnt = db_ls(gedp->ged_wdbp->dbip,
DB_LS_TOPS | DB_LS_HIDDEN, NULL, &(new_search->paths));
+
new_search->search_type = 1;
bu_ptbl_ins(search_set, (long *)new_search);
}
@@ -412,7 +444,9 @@
/* Check if all of our searches are local or not */
for (i = (int)BU_PTBL_LEN(search_set) - 1; i >= 0; i--) {
struct ged_search *search = (struct ged_search
*)BU_PTBL_GET(search_set, i);
- if (search->search_type != 1) all_local = 0;
+ if (search->search_type != 1) {
+ all_local = 0;
+ }
}
/* If all searches are local, use all supplied paths in the search to
@@ -422,10 +456,12 @@
struct bu_ptbl *uniq_db_objs;
BU_ALLOC(uniq_db_objs, struct bu_ptbl);
BU_PTBL_INIT(uniq_db_objs);
+
for (i = (int)BU_PTBL_LEN(search_set) - 1; i >= 0; i--) {
int path_cnt = 0;
struct ged_search *search = (struct ged_search
*)BU_PTBL_GET(search_set, i);
struct directory *curr_path = search->paths[path_cnt];
+
while (path_cnt < search->path_cnt) {
flags |= DB_SEARCH_RETURN_UNIQ_DP;
(void)db_search(uniq_db_objs, flags,
bu_vls_addr(&search_string), 1, &curr_path, gedp->ged_wdbp->dbip, ctx);
@@ -433,19 +469,25 @@
curr_path = search->paths[path_cnt];
}
}
+
/* 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);
+
for (i = (int)BU_PTBL_LEN(uniq_db_objs) - 1; i >= 0; i--) {
struct directory *uniq_dp = (struct directory
*)BU_PTBL_GET(uniq_db_objs, i);
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");
+
} else {
+
/* Search types are either mixed or all full path, so use the standard
calls and print
* the full output of each search */
struct fp_cmp_vls *sdata;
+
BU_GET(sdata, struct fp_cmp_vls);
BU_GET(sdata->left, struct bu_vls);
BU_GET(sdata->right, struct bu_vls);
@@ -458,13 +500,16 @@
int path_cnt = 0;
int j;
struct ged_search *search = (struct ged_search
*)BU_PTBL_GET(search_set, i);
+
if (search && (search->path_cnt > 0 || search->search_type == 2)) {
if (search->search_type == 2) {
int k;
struct bu_ptbl *search_results;
+
flags |= DB_SEARCH_FLAT;
BU_ALLOC(search_results, struct bu_ptbl);
bu_ptbl_init(search_results, 8, "initialize search result
table");
+
for (k = 0; k < RT_DBNHASH; k++) {
struct directory *dp;
for (dp = gedp->ged_wdbp->dbip->dbi_Head[k]; dp !=
RT_DIR_NULL; dp = dp->d_forw) {
@@ -473,6 +518,7 @@
}
}
}
+
if (BU_PTBL_LEN(search_results) > 0) {
bu_sort((void *)BU_PTBL_BASEADDR(search_results),
BU_PTBL_LEN(search_results), sizeof(struct directory *), dp_name_compare, NULL);
for (j = (int)BU_PTBL_LEN(search_results) - 1; j >= 0;
j--) {
@@ -480,22 +526,29 @@
bu_vls_printf(gedp->ged_result_str, "%s\n",
uniq_dp->d_namep);
}
}
+
/* Make sure to clear the flag in case of subsequent
searches of different types */
+
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];
+
while (path_cnt < search->path_cnt) {
struct bu_ptbl *search_results;
struct bu_vls fullpath_string = BU_VLS_INIT_ZERO;
+
BU_ALLOC(search_results, struct bu_ptbl);
bu_ptbl_init(search_results, 8, "initialize search
result table");
+
switch (search->search_type) {
case 0:
(void)db_search(search_results, flags,
bu_vls_addr(&search_string), 1, &curr_path, gedp->ged_wdbp->dbip, ctx);
+
if (BU_PTBL_LEN(search_results) > 0) {
bu_sort((void
*)BU_PTBL_BASEADDR(search_results), BU_PTBL_LEN(search_results), sizeof(struct
directory *), fp_name_compare, (void *)sdata);
+
for (j = (int)BU_PTBL_LEN(search_results) -
1; j >= 0; j--) {
struct db_full_path *dfptr = (struct
db_full_path *)BU_PTBL_GET(search_results, j);
bu_vls_trunc(&fullpath_string, 0);
@@ -508,6 +561,7 @@
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);
bu_sort((void
*)BU_PTBL_BASEADDR(search_results), BU_PTBL_LEN(search_results), sizeof(struct
directory *), dp_name_compare, NULL);
+
for (j = (int)BU_PTBL_LEN(search_results) - 1;
j >= 0; j--) {
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);
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