Revision: 75953
          http://sourceforge.net/p/brlcad/code/75953
Author:   starseeker
Date:     2020-05-27 18:40:40 +0000 (Wed, 27 May 2020)
Log Message:
-----------
Use the alphanum sorting for search outputs - produces a more intuitive 
ordering for .g files like m35.g which have r#[#][#] naming patterns.

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

Modified: brlcad/trunk/NEWS
===================================================================
--- brlcad/trunk/NEWS   2020-05-27 17:59:09 UTC (rev 75952)
+++ brlcad/trunk/NEWS   2020-05-27 18:40:40 UTC (rev 75953)
@@ -13,6 +13,7 @@
 --- 20XX-XX-XX  Release 7.3X.X                                     ---
 ----------------------------------------------------------------------
 
+* improved output path sorting of search command - Cliff Yapp
 * added 3dm-g failure message about supported versions - Cliff Yapp
 * fixed bw-png writing corrupted png files on Windows - Sean Morrison
 

Modified: brlcad/trunk/src/libged/comb.c
===================================================================
--- brlcad/trunk/src/libged/comb.c      2020-05-27 17:59:09 UTC (rev 75952)
+++ brlcad/trunk/src/libged/comb.c      2020-05-27 18:40:40 UTC (rev 75953)
@@ -206,7 +206,7 @@
 }
 
 /* bu_sort functions for solids */
-HIDDEN int
+static int
 name_compare(const void *d1, const void *d2, void *UNUSED(arg))
 {
     struct directory *dp1 = *(struct directory **)d1;

Modified: brlcad/trunk/src/libged/search.c
===================================================================
--- brlcad/trunk/src/libged/search.c    2020-05-27 17:59:09 UTC (rev 75952)
+++ brlcad/trunk/src/libged/search.c    2020-05-27 18:40:40 UTC (rev 75953)
@@ -37,10 +37,41 @@
 #include "bu/cmd.h"
 #include "bu/getopt.h"
 #include "bu/path.h"
+#include "bu/sort.h"
 
+#include "./alphanum.h"
 #include "./ged_private.h"
 
+static int
+dp_name_compare(const void *d1, const void *d2, void *arg)
+{
+    struct directory *dp1 = *(struct directory **)d1;
+    struct directory *dp2 = *(struct directory **)d2;
+    int ret = alphanum_impl((const char *)dp2->d_namep, (const char 
*)dp1->d_namep, arg);
+    return ret;
+}
 
+struct fp_cmp_vls {
+    struct bu_vls *left;
+    struct bu_vls *right;
+    struct db_i *dbip;
+    int print_verbose_info;
+};
+static int
+fp_name_compare(const void *d1, const void *d2, void *arg)
+{
+    struct db_full_path *fp1 = *(struct db_full_path **)d1;
+    struct db_full_path *fp2 = *(struct db_full_path **)d2;
+    struct fp_cmp_vls *data = (struct fp_cmp_vls *)arg;
+    bu_vls_trunc(data->left, 0);
+    bu_vls_trunc(data->right, 0);
+    db_fullpath_to_vls(data->left, fp1, data->dbip, data->print_verbose_info);
+    db_fullpath_to_vls(data->right, fp2, data->dbip, data->print_verbose_info);
+    int ret = alphanum_impl(bu_vls_cstr(data->right), bu_vls_cstr(data->left), 
arg);
+    return ret;
+}
+
+
 struct ged_search {
     struct directory **paths;
     int path_cnt;
@@ -403,6 +434,7 @@
            }
        }
        /* 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);
@@ -412,6 +444,16 @@
     } 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);
+       bu_vls_init(sdata->left);
+       bu_vls_init(sdata->right);
+       sdata->dbip = gedp->ged_wdbp->dbip;
+       sdata->print_verbose_info = print_verbose_info;
+
        for (i = 0; i < (int)BU_PTBL_LEN(search_set); i++) {
            int path_cnt = 0;
            int j;
@@ -432,6 +474,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--) {
                            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);
@@ -452,6 +495,7 @@
                            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);
@@ -463,6 +507,7 @@
                            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);
+                               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);
@@ -481,6 +526,12 @@
                }
            }
        }
+
+       bu_vls_free(sdata->left);
+       bu_vls_free(sdata->right);
+       BU_PUT(sdata->left, struct bu_vls);
+       BU_PUT(sdata->right, struct bu_vls);
+       BU_PUT(sdata, struct fp_cmp_vls);
     }
 
     /* Done - free memory */

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

Reply via email to