Revision: 77088
http://sourceforge.net/p/brlcad/code/77088
Author: starseeker
Date: 2020-09-08 20:38:51 +0000 (Tue, 08 Sep 2020)
Log Message:
-----------
This came up again... forward port and enable the most basic of the search
command size filters from r67646. This is just the dp->d_len object size
filter, but it pairs with the ls options that can report size - with this in
place, we can use ls -lS to get an overall report of object sizes and then
search with -size and other filters to identify large or small subsets based on
type. Particular use case was trying to find a large plate mode bot in the FAA
Generic_Twin.g example: ls -lS to get an idea of size distributions and then
search -type plate -size >50000 to find larger examples. Would be nice to be
able to specify sorting the search output on size at some point as well...
Modified Paths:
--------------
brlcad/trunk/NEWS
brlcad/trunk/doc/docbook/system/mann/search.xml
brlcad/trunk/src/librt/search.c
brlcad/trunk/src/librt/search.h
Modified: brlcad/trunk/NEWS
===================================================================
--- brlcad/trunk/NEWS 2020-09-08 20:30:08 UTC (rev 77087)
+++ brlcad/trunk/NEWS 2020-09-08 20:38:51 UTC (rev 77088)
@@ -13,6 +13,7 @@
--- 2020-08-XX Release 7.32.X ---
----------------------------------------------------------------------
+* added -size filter to MGED search command - Cliff Yapp
* upgraded Tcl/Tk from 8.5.19 to 8.6.10 - Cliff Yapp
* bundled zlib & libpng use API prefix and library suffix - Cliff Yapp
* extensive improvements to OpenCL ray trace pipeline - Rishabh Suthar
Modified: brlcad/trunk/doc/docbook/system/mann/search.xml
===================================================================
--- brlcad/trunk/doc/docbook/system/mann/search.xml 2020-09-08 20:30:08 UTC
(rev 77087)
+++ brlcad/trunk/doc/docbook/system/mann/search.xml 2020-09-08 20:38:51 UTC
(rev 77088)
@@ -424,6 +424,14 @@
</listitem>
</varlistentry>
<varlistentry>
+ <term><emphasis remap="B" role="bold">-size</emphasis> <emphasis
remap="I">[>/</=]size</emphasis></term>
+ <listitem>
+ <para>
+ True if the size of the object is within the range specified.
NOTE: for combs, extrudes, and other composite objects this filter considers
<emphasis>only</emphasis> the object definition itself, not its related
elements.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><emphasis remap="B" role="bold">-stdattr</emphasis></term>
<listitem>
<para>
Modified: brlcad/trunk/src/librt/search.c
===================================================================
--- brlcad/trunk/src/librt/search.c 2020-09-08 20:30:08 UTC (rev 77087)
+++ brlcad/trunk/src/librt/search.c 2020-09-08 20:38:51 UTC (rev 77088)
@@ -132,6 +132,7 @@
{ "-path", N_PATH, c_path, O_ARGV },
{ "-print", N_PRINT, c_print, O_ZERO },
{ "-regex", N_REGEX, c_regex, O_ARGV },
+ { "-size", N_SIZE, c_size, O_ARGV },
{ "-stdattr", N_STDATTR, c_stdattr, O_ZERO },
{ "-type", N_TYPE, c_type, O_ARGV },
};
@@ -1155,6 +1156,81 @@
/*
+ * -size function --
+ *
+ * True if the database object being examined satisfies
+ * the size criteria: [><=]size
+ */
+HIDDEN int
+f_size(struct db_plan_t *plan, struct db_node_t *db_node, struct db_i
*UNUSED(dbip), struct bu_ptbl *UNUSED(results))
+{
+ struct directory *dp;
+ int ret = 0;
+ int checkval = 0;
+ struct bu_vls name = BU_VLS_INIT_ZERO;
+ struct bu_vls value = BU_VLS_INIT_ZERO;
+
+ dp = DB_FULL_PATH_CUR_DIR(db_node->path);
+ if (!dp) return 0;
+
+ /* Check for unescaped >, < or = characters. If present, the
+ * attribute must not only be present but the value assigned to
+ * the attribute must satisfy the logical expression. In the case
+ * where a > or < is used with a string argument the behavior will
+ * follow ASCII lexicographical order. In the case of equality
+ * between strings, fnmatch is used to support pattern matching
+ */
+
+ checkval = string_to_name_and_val(plan->p_un._depth_data, &name, &value);
+
+ if ((bu_vls_strlen(&value) > 0 && isdigit((int)bu_vls_addr(&value)[0]))
+ || (bu_vls_strlen(&value) == 0 && isdigit((int)bu_vls_addr(&name)[0])))
{
+ switch (checkval) {
+ case 0:
+ ret = ((int)dp->d_len == atol(bu_vls_addr(&name))) ? 1 : 0;
+ break;
+ case 1:
+ ret = ((int)dp->d_len == atol(bu_vls_addr(&value))) ? 1 : 0;
+ break;
+ case 2:
+ ret = ((int)dp->d_len > atol(bu_vls_addr(&value))) ? 1 : 0;
+ break;
+ case 3:
+ ret = ((int)dp->d_len < atol(bu_vls_addr(&value))) ? 1 : 0;
+ break;
+ case 4:
+ ret = ((int)dp->d_len >= atol(bu_vls_addr(&value))) ? 1 : 0;
+ break;
+ case 5:
+ ret = ((int)dp->d_len <= atol(bu_vls_addr(&value))) ? 1 : 0;
+ break;
+ default:
+ ret = 0;
+ break;
+ }
+ }
+ bu_vls_free(&name);
+ bu_vls_free(&value);
+
+ if (!ret) db_node->matched_filters = 0;
+ return ret;
+}
+
+
+HIDDEN int
+c_size(char *pattern, char ***UNUSED(ignored), int UNUSED(unused), struct
db_plan_t **resultplan, int *UNUSED(db_search_isoutput), struct bu_ptbl *tbl,
struct db_search_context *UNUSED(ctx))
+{
+ struct db_plan_t *newplan;
+
+ newplan = palloc(N_TYPE, f_size, tbl);
+ newplan->p_un._type_data = pattern;
+ (*resultplan) = newplan;
+
+ return BRLCAD_OK;
+}
+
+
+/*
* -bool function --
*
* True if the boolean operation combining the object into the tree matches
Modified: brlcad/trunk/src/librt/search.h
===================================================================
--- brlcad/trunk/src/librt/search.h 2020-09-08 20:30:08 UTC (rev 77087)
+++ brlcad/trunk/src/librt/search.h 2020-09-08 20:38:51 UTC (rev 77088)
@@ -77,7 +77,7 @@
N_CLOSEPAREN, N_DEPTH, N_EXEC, N_EXECDIR, N_EXPR,
N_FLAGS, N_INAME, N_IREGEX, N_LS, N_MAXDEPTH,
N_MINDEPTH, N_NAME, N_NNODES, N_NOT, N_OK, N_OPENPAREN, N_OR, N_PATH,
- N_PRINT, N_PRUNE, N_REGEX, N_STDATTR, N_TYPE, N_BOOL, N_PARAM
+ N_PRINT, N_PRUNE, N_REGEX, N_SIZE, N_STDATTR, N_TYPE, N_BOOL, N_PARAM
};
@@ -168,6 +168,7 @@
static int c_above(char *, char ***, int, struct db_plan_t **, int *, struct
bu_ptbl *, struct db_search_context *);
static int c_below(char *, char ***, int, struct db_plan_t **, int *, struct
bu_ptbl *, struct db_search_context *);
static int c_exec(char *, char ***, int, struct db_plan_t **, int *, struct
bu_ptbl *, struct db_search_context *);
+static int c_size(char *, char ***, int, struct db_plan_t **, int *, struct
bu_ptbl *, struct db_search_context *);
__END_DECLS
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