Revision: 44539
          http://brlcad.svn.sourceforge.net/brlcad/?rev=44539&view=rev
Author:   starseeker
Date:     2011-04-29 20:27:09 +0000 (Fri, 29 Apr 2011)

Log Message:
-----------
Make a stab at improving behavior of search when multiple paths are supplied.

Modified Paths:
--------------
    brlcad/trunk/src/libged/search.c

Modified: brlcad/trunk/src/libged/search.c
===================================================================
--- brlcad/trunk/src/libged/search.c    2011-04-29 20:12:39 UTC (rev 44538)
+++ brlcad/trunk/src/libged/search.c    2011-04-29 20:27:09 UTC (rev 44539)
@@ -57,7 +57,18 @@
        return islocal;
 }
 
-void _add_toplevel(struct db_i *dbip, struct db_full_path_list *path_list, 
struct db_full_path *dfp, int local) {
+void _add_toplevel(struct db_full_path_list *path_list, int local) {
+    struct db_full_path_list *new_entry;
+    BU_GETSTRUCT(new_entry, db_full_path_list);
+    new_entry->path = (struct db_full_path *) bu_malloc(sizeof(struct 
db_full_path), "new full path");
+    db_full_path_init(new_entry->path);
+    new_entry->path->fp_maxlen = 0;
+    new_entry->local = local;
+    BU_LIST_INSERT(&(path_list->l), &(new_entry->l));
+}
+
+
+void _gen_toplevel(struct db_i *dbip, struct db_full_path_list *path_list, 
struct db_full_path *dfp, int local) {
        int i;
        struct directory *dp;
        struct db_full_path_list *new_entry;
@@ -70,7 +81,7 @@
                               db_full_path_init(new_entry->path);
                               db_dup_full_path(new_entry->path, (const struct 
db_full_path *)dfp);
                               new_entry->local = local;
-                              BU_LIST_PUSH(&(path_list->l), &(new_entry->l));
+                              BU_LIST_INSERT(&(path_list->l), &(new_entry->l));
                       }
               }
        }
@@ -95,6 +106,7 @@
     struct db_full_path_list *new_entry;
     struct db_full_path_list *path_list = NULL;
     struct db_full_path_list *dispatch_list = NULL;
+    struct db_full_path_list *local_list = NULL;
     struct db_full_path_list *search_results = NULL;
     struct bu_ptbl *uniq_db_objs;
     /* COPY argv_orig to argv; */
@@ -131,12 +143,12 @@
                            if (BU_STR_EQUAL(argv[plan_argv], "/")) {
                                    /* if we have nothing but a slash, add all 
toplevel objects to the list as
                                     * full path searches */
-                                   _add_toplevel(gedp->ged_wdbp->dbip, 
path_list, &dfp, 0);
+                                   _add_toplevel(path_list, 0);
                                    plan_argv++;
                            } else if (BU_STR_EQUAL(argv[plan_argv], ".")) {
                                    /* if we have nothing but a dot, add all 
toplevel objects to the list as
                                     * local searches */
-                                   _add_toplevel(gedp->ged_wdbp->dbip, 
path_list, &dfp, 1);
+                                   _add_toplevel(path_list, 1);
                                    plan_argv++;
                            } else {
                                    bu_vls_sprintf(&argvls, "%s", 
argv[plan_argv]);
@@ -144,7 +156,7 @@
                                    if (BU_STR_EQUAL(bu_vls_addr(&argvls), 
"/")) {
                                            /* if we have nothing but a slash, 
normalize resolved to the toplevel. Add
                                             * a toplevel search with the 
islocal flag */
-                                           _add_toplevel(gedp->ged_wdbp->dbip, 
path_list, &dfp, islocal);
+                                           _add_toplevel(path_list, islocal);
                                            plan_argv++;
                                    } else {
                                            if (!bu_vls_strlen(&argvls)) {
@@ -179,7 +191,7 @@
                            plan_found = 1;
                            if (!path_found) {
                                    /* We have a plan but not path - in that 
case, do a non-full-path tops search */
-                                   _add_toplevel(gedp->ged_wdbp->dbip, 
path_list, &dfp, 1);
+                                   _add_toplevel(path_list, 1);
                            }
                    }
            }
@@ -194,29 +206,80 @@
            db_free_full_path_list(path_list);
            return GED_ERROR;
     } else {
+           islocal = 1;
            for(BU_LIST_FOR_BACKWARDS(entry, db_full_path_list, 
&(path_list->l))) {
-                   BU_GETSTRUCT(new_entry, db_full_path_list);
-                   new_entry->path = (struct db_full_path *) 
bu_malloc(sizeof(struct db_full_path), "new full path");
-                   db_full_path_init(new_entry->path);
-                   db_dup_full_path(new_entry->path, entry->path);
-                   BU_LIST_PUSH(&(dispatch_list->l), &(new_entry->l));
-                   if (entry->local) {
+               if (!entry->local) islocal = 0;
+           }
+           /* If all searches are local, use all supplied paths in the search 
to
+            * return one unique list of objects.  If one or more paths are 
non-local,
+            * each path is treated as its own search */
+           if (islocal) {
+               int search_all = 0;
+               for(BU_LIST_FOR_BACKWARDS(entry, db_full_path_list, 
&(path_list->l))) {
+                   if (entry->path->fp_maxlen == 0) {
+                       search_all = 1;
+                   } 
+               }
+               if (search_all) {
+                   BU_GETSTRUCT(local_list, db_full_path_list);
+                   BU_LIST_INIT(&(local_list->l));
+                   _gen_toplevel(gedp->ged_wdbp->dbip, local_list, &dfp, 1);
+                   uniq_db_objs = db_search_unique_objects(dbplan, local_list, 
gedp->ged_wdbp->dbip, gedp->ged_wdbp);
+                   db_free_full_path_list(local_list);
+               } else {
+                   uniq_db_objs = db_search_unique_objects(dbplan, path_list, 
gedp->ged_wdbp->dbip, gedp->ged_wdbp);
+               }
+               for (i=(int)BU_PTBL_LEN(uniq_db_objs) - 1; i >=0 ; i--) {
+                   dp = (struct directory *)BU_PTBL_GET(uniq_db_objs, i);
+                   bu_vls_printf(&gedp->ged_result_str, "%s\n", dp->d_namep);
+               }
+               bu_ptbl_free(uniq_db_objs);
+           } else {
+               for(BU_LIST_FOR_BACKWARDS(entry, db_full_path_list, 
&(path_list->l))) {
+                   if (entry->path->fp_maxlen == 0) {
+                       BU_GETSTRUCT(local_list, db_full_path_list);
+                       BU_LIST_INIT(&(local_list->l));
+                       _gen_toplevel(gedp->ged_wdbp->dbip, local_list, &dfp, 
entry->local);
+                       if (entry->local) {
+                       uniq_db_objs = db_search_unique_objects(dbplan, 
local_list, gedp->ged_wdbp->dbip, gedp->ged_wdbp);
+                       for (i=(int)BU_PTBL_LEN(uniq_db_objs) - 1; i >=0 ; i--) 
{
+                           dp = (struct directory *)BU_PTBL_GET(uniq_db_objs, 
i);
+                           bu_vls_printf(&gedp->ged_result_str, "%s\n", 
dp->d_namep);
+                       }
+                       bu_ptbl_free(uniq_db_objs);
+                       } else {
+                           search_results = db_search_full_paths(dbplan, 
local_list, gedp->ged_wdbp->dbip, gedp->ged_wdbp);
+                           for(BU_LIST_FOR_BACKWARDS(result, 
db_full_path_list, &(search_results->l))) {
+                               bu_vls_printf(&gedp->ged_result_str, "%s\n", 
db_path_to_string(result->path));
+                           }
+                           db_free_full_path_list(search_results);
+                       }
+                       db_free_full_path_list(local_list);
+                   } else {
+                       BU_GETSTRUCT(new_entry, db_full_path_list);
+                       new_entry->path = (struct db_full_path *) 
bu_malloc(sizeof(struct db_full_path), "new full path");
+                       db_full_path_init(new_entry->path);
+                       db_dup_full_path(new_entry->path, entry->path);
+                       BU_LIST_PUSH(&(dispatch_list->l), &(new_entry->l));
+                       if (entry->local) {
                            uniq_db_objs = db_search_unique_objects(dbplan, 
dispatch_list, gedp->ged_wdbp->dbip, gedp->ged_wdbp);
                            for (i=(int)BU_PTBL_LEN(uniq_db_objs) - 1; i >=0 ; 
i--) {
-                                   dp = (struct directory 
*)BU_PTBL_GET(uniq_db_objs, i);
-                                   bu_vls_printf(&gedp->ged_result_str, 
"%s\n", dp->d_namep);
+                               dp = (struct directory 
*)BU_PTBL_GET(uniq_db_objs, i);
+                               bu_vls_printf(&gedp->ged_result_str, "%s\n", 
dp->d_namep);
                            }
                            bu_ptbl_free(uniq_db_objs);
-                   } else {
+                       } else {
                            search_results = db_search_full_paths(dbplan, 
dispatch_list, gedp->ged_wdbp->dbip, gedp->ged_wdbp);
                            for(BU_LIST_FOR_BACKWARDS(result, 
db_full_path_list, &(search_results->l))) {
-                                   bu_vls_printf(&gedp->ged_result_str, 
"%s\n", db_path_to_string(result->path));
+                               bu_vls_printf(&gedp->ged_result_str, "%s\n", 
db_path_to_string(result->path));
                            }
                            db_free_full_path_list(search_results);
+                       }
+                       db_free_full_path(new_entry->path);
+                       BU_LIST_DEQUEUE(&(new_entry->l));
+                       bu_free(new_entry, "free new_entry");
                    }
-                   db_free_full_path(new_entry->path);
-                   BU_LIST_DEQUEUE(&(new_entry->l));
-                   bu_free(new_entry, "free new_entry");
+               }
            }
            db_search_freeplan(&dbplan);
     }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to