Revision: 76309
          http://sourceforge.net/p/brlcad/code/76309
Author:   starseeker
Date:     2020-07-10 12:37:56 +0000 (Fri, 10 Jul 2020)
Log Message:
-----------
Switch gdiff verbosity option to using the 'multiple specifications of -v 
increases verbosity' model instead of specific numerical values

Modified Paths:
--------------
    brlcad/trunk/doc/docbook/system/man1/gdiff.xml
    brlcad/trunk/include/bu/opt.h
    brlcad/trunk/src/gtools/gdiff/gdiff.c
    brlcad/trunk/src/gtools/gdiff/gdiff.h
    brlcad/trunk/src/libbu/opt.c
    brlcad/trunk/src/libged/ged_util.c

Modified: brlcad/trunk/doc/docbook/system/man1/gdiff.xml
===================================================================
--- brlcad/trunk/doc/docbook/system/man1/gdiff.xml      2020-07-10 08:31:31 UTC 
(rev 76308)
+++ brlcad/trunk/doc/docbook/system/man1/gdiff.xml      2020-07-10 12:37:56 UTC 
(rev 76309)
@@ -57,6 +57,10 @@
       </listitem>
     </varlistentry>
     <varlistentry>
+      <term><option>-q</option></term>
+      <listitem><para>Decrease the verbosity of the output.  Additional 
specifications will further decrease the output provided.  (Opposite effect of 
<option>v</option> option.) All settings for this option will respect other 
constraints applied to the reporting output.</para></listitem>
+    </varlistentry>
+    <varlistentry>
       <term><option>-u</option></term>
       <listitem>
         <para>(two-way diff) Report objects that are identical in left_model.g 
and right_model.g</para>
@@ -64,8 +68,8 @@
       </listitem>
     </varlistentry>
     <varlistentry>
-      <term><option>-v #</option></term>
-      <listitem><para>Control the verbosity of the output.  Zero will suppress 
all reporting and only the return value of the program will contain 
information, one will provide categorized lists of objects but no details on 
what changed, two will list each changed object preceded by a modifier, three 
will print more details for changed objects, and four will print all available 
information.  All settings for this option will respect other constraints 
applied to the reporting output.</para></listitem>
+      <term><option>-v</option></term>
+      <listitem><para>Increase the verbosity of the output.  Additional 
specifications will further increase the output provided.  (Opposite effect of 
<option>q</option> option.) All settings for this option will respect other 
constraints applied to the reporting output.</para></listitem>
     </varlistentry>
     <varlistentry>
       <term><option>-t #</option></term>

Modified: brlcad/trunk/include/bu/opt.h
===================================================================
--- brlcad/trunk/include/bu/opt.h       2020-07-10 08:31:31 UTC (rev 76308)
+++ brlcad/trunk/include/bu/opt.h       2020-07-10 12:37:56 UTC (rev 76309)
@@ -419,13 +419,16 @@
  */
 BU_EXPORT extern int bu_opt_vect_t(struct bu_vls *msg, size_t argc, const char 
**argv, void *set_var);
 
-// TODO - add a standard bu_opt_long_incr to increment the value held by a
-// long.  This is useful for situations where multiple specifications of
-// identical options are intended to change output, such as multiple -v options
-// to increase verbosity.
-
 /** @} */
 
+/**
+ * Process 0 arguments, incrementing the value held by a long.  This is
+ * useful for situations where multiple specifications of identical options are
+ * intended to change output, such as multiple -v options to increase
+ * verbosity.
+ */
+BU_EXPORT extern int bu_opt_incr_long(struct bu_vls *msg, size_t argc, const 
char **argv, void *set_var);
+
 __END_DECLS
 
 #endif  /* BU_OPT_H */

Modified: brlcad/trunk/src/gtools/gdiff/gdiff.c
===================================================================
--- brlcad/trunk/src/gtools/gdiff/gdiff.c       2020-07-10 08:31:31 UTC (rev 
76308)
+++ brlcad/trunk/src/gtools/gdiff/gdiff.c       2020-07-10 12:37:56 UTC (rev 
76309)
@@ -1,4 +1,4 @@
-/*                     G D I F F 2 . C
+/*                     G D I F F . C
  * BRL-CAD
  *
  * Copyright (c) 2014-2020 United States Government as represented by
@@ -20,6 +20,7 @@
 
 #include "./gdiff.h"
 #include "bu/app.h"
+#include "bu/opt.h"
 
 /*******************************************************************/
 /* Primary function for basic diff operation on two .g files */
@@ -233,69 +234,79 @@
 }
 
 static void
-gdiff_usage(const char *str) {
-    bu_log("Usage: %s [-adhmux] [-v {0-4}] [-t tol] [-F \"filter_string\"] [-M 
merged.g] left.g [ancestor.g] right.g\n", str);
-    bu_exit(1, NULL);
+gdiff_usage(const char *cmd, struct bu_opt_desc *d) {
+    struct bu_vls str = BU_VLS_INIT_ZERO;
+    char *option_help = bu_opt_describe(d, NULL);
+    bu_vls_sprintf(&str, "Usage: %s [options] left.g [ancestor.g] right.g\n", 
cmd);
+    if (option_help) {
+        bu_vls_printf(&str, "Options:\n%s\n", option_help);
+        bu_free(option_help, "help str");
+    }
+    bu_log("%s", bu_vls_cstr(&str));
+    bu_vls_free(&str);
 }
 
-
 int
-main(int argc, char **argv)
+main(int argc, const char **argv)
 {
-    int c;
     int diff_return = 0;
+    int print_help = 0;
     struct diff_state *state;
     struct db_i *left_dbip = DBI_NULL;
     struct db_i *right_dbip = DBI_NULL;
     struct db_i *ancestor_dbip = DBI_NULL;
     const char *diff_prog_name = argv[0];
+    struct bu_vls msg = BU_VLS_INIT_ZERO;
 
     bu_setprogname(argv[0]);
 
+    // Name stashed, move on
+    argc--; argv++;
+
     BU_GET(state, struct diff_state);
     diff_state_init(state);
 
-    while ((c = bu_getopt(argc, argv, "amF:M:dt:uv:xh?")) != -1) {
-       switch (c) {
-           case 'a':
-               state->return_added = 1;
-               break;
-           case 'd':
-               state->return_removed = 1;
-               break;
-           case 'm':
-               state->return_changed = 1;
-               break;
-           case 'u':
-               state->return_unchanged = 1;
-               break;
-           case 'F':
-               state->have_search_filter = 1;
-               bu_vls_sprintf(state->search_filter, "%s", bu_optarg);
-               break;
-           case 'M':
-               state->merge = 1;
-               bu_vls_sprintf(state->merge_file, "%s", bu_optarg);
-               break;
-           case 't':   /* distance tolerance for same/different decisions 
(RT_LEN_TOL is default) */
-               if (sscanf(bu_optarg, "%lf", &(state->diff_tol->dist)) != 1) {
-                   bu_log("Invalid distance tolerance specification: '%s'\n", 
bu_optarg);
-                   gdiff_usage(diff_prog_name);
-                   bu_exit (1, NULL);
-               }
-               break;
-           case 'v':   /* verbosity (2 is default) */
-               if (sscanf(bu_optarg, "%d", &(state->verbosity)) != 1) {
-                   bu_log("Invalid verbosity specification: '%s'\n", 
bu_optarg);
-                   gdiff_usage(diff_prog_name);
-                   bu_exit (1, NULL);
-               }
-               break;
-           default:
-               gdiff_usage(diff_prog_name);
-       }
+    struct bu_opt_desc d[13];
+    BU_OPT(d[0],  "h", "help",       "",        NULL,              
&print_help,              "Print help and exit");
+    BU_OPT(d[1],  "?", "",           "",        NULL,              
&print_help,              "");
+    BU_OPT(d[2],  "a", "added",      "",        NULL,              
&state->return_added,     "Report added objects");
+    BU_OPT(d[3],  "d", "deleted",    "",        NULL,              
&state->return_removed,   "Report deleted objects");
+    BU_OPT(d[4],  "m", "modified",   "",        NULL,              
&state->return_changed,   "Report modified objects");
+    BU_OPT(d[5],  "u", "unchanged",  "",        NULL,              
&state->return_unchanged, "Report unchanged objects");
+    BU_OPT(d[6],  "F", "filter",     "string",  &bu_opt_vls,       
state->search_filter,     "Report unchanged objects");
+    BU_OPT(d[7],  "M", "merge-file", "merge.g", &bu_opt_vls,       
state->merge_file,        "Specify merge file");
+    BU_OPT(d[8],  "t", "tolerance",  "#",       &bu_opt_fastf_t,   
&state->diff_tol->dist,   "numerical distance tolerance for same/different 
decisions (RT_LEN_TOL is default)");
+    BU_OPT(d[9],  "v", "verbosity",  "",        &bu_opt_incr_long, 
&state->verbosity,        "increase output verbosity (multiple specifications 
of -v increase verbosity more)");
+    BU_OPT(d[10], "q", "quiet",      "",        &bu_opt_incr_long, 
&state->quiet,            "decrease output verbosity (multiple specifications 
of -q decrease verbosity more)");
+    BU_OPT_NULL(d[11]);
+
+    int ret_ac = bu_opt_parse(&msg, argc, argv, d);
+    if (ret_ac < 0) {
+        bu_log("%s\n", bu_vls_cstr(&msg));
+        bu_vls_free(&msg);
+        bu_vls_free(state->search_filter);
+        bu_vls_free(state->merge_file);
+       BU_PUT(state, struct diff_state);
+        return BRLCAD_ERROR;
     }
+    if (print_help) {
+       gdiff_usage(diff_prog_name, d);
+        bu_vls_free(&msg);
+        bu_vls_free(state->search_filter);
+        bu_vls_free(state->merge_file);
+       BU_PUT(state, struct diff_state);
+        return BRLCAD_OK;
+    }
 
+    if (bu_vls_strlen(state->search_filter)) {
+       state->have_search_filter = 1;
+    }
+    if (bu_vls_strlen(state->merge_file)) {
+       state->merge = 1;
+    }
+
+    state->verbosity = state->verbosity - state->quiet;
+
     state->return_conflicts = 1;
 
     if (state->return_added == -1 && state->return_removed == -1 && 
state->return_changed == -1 && state->return_unchanged == 0) {
@@ -302,8 +313,7 @@
        state->return_added = 1; state->return_removed = 1; 
state->return_changed = 1;
     }
 
-    argc -= bu_optind;
-    argv += bu_optind;
+    argc = ret_ac;
 
     if (argc != 2 && argc != 3) {
        bu_log("Error - please specify either two or three .g files\n");

Modified: brlcad/trunk/src/gtools/gdiff/gdiff.h
===================================================================
--- brlcad/trunk/src/gtools/gdiff/gdiff.h       2020-07-10 08:31:31 UTC (rev 
76308)
+++ brlcad/trunk/src/gtools/gdiff/gdiff.h       2020-07-10 12:37:56 UTC (rev 
76309)
@@ -45,7 +45,8 @@
     int return_unchanged;
     int return_conflicts;
     int have_search_filter;
-    int verbosity;
+    long verbosity;
+    long quiet;
     int output_mode;
     int merge;
     struct bn_tol *diff_tol;

Modified: brlcad/trunk/src/libbu/opt.c
===================================================================
--- brlcad/trunk/src/libbu/opt.c        2020-07-10 08:31:31 UTC (rev 76308)
+++ brlcad/trunk/src/libbu/opt.c        2020-07-10 12:37:56 UTC (rev 76309)
@@ -1287,6 +1287,19 @@
     return -1;
 }
 
+int
+bu_opt_incr_long(struct bu_vls *msg, size_t UNUSED(argc), const char 
**UNUSED(argv), void *set_var)
+{
+    long *long_incr = (long *)set_var;
+    if (long_incr) {
+       (*long_incr) = (*long_incr) + 1;
+    } else {
+       if (msg) {
+           bu_vls_sprintf(msg, "No valid supplied to bu_opt_incr_long\n");
+       }
+    }
+    return 0;
+}
 
 /*
  * Local Variables:

Modified: brlcad/trunk/src/libged/ged_util.c
===================================================================
--- brlcad/trunk/src/libged/ged_util.c  2020-07-10 08:31:31 UTC (rev 76308)
+++ brlcad/trunk/src/libged/ged_util.c  2020-07-10 12:37:56 UTC (rev 76309)
@@ -278,6 +278,7 @@
     bu_vls_free(&str);
 }
 
+// TODO - replace with bu_opt_incr_long
 int
 _ged_vopt(struct bu_vls *UNUSED(msg), size_t UNUSED(argc), const char 
**UNUSED(argv), void *set_var)
 {

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



_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to