about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/HISTORY5
-rw-r--r--lib/util/shhopt.c2
-rw-r--r--lib/util/shhopt.h20
3 files changed, 20 insertions, 7 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index 768a6c86..dedf5a0f 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -8,6 +8,11 @@ not yet  BJH  Release 10.87.00
 
               pamfind: Add -machine .
 
+              Multiple: fix bug: when you specify the same option twice, you
+              can get a syntax error, with the message telling you you
+              specified some other option that conflicts with it.  Should just
+              take the last setting.
+
               pnmtopng: Fix bug: Defaults to no filters.  Should be all
               filters.  Effect is larger PNG output.  Broken after Netpbm
               10.26 (January 2005) but no later than Netpbm 10.35 (August
diff --git a/lib/util/shhopt.c b/lib/util/shhopt.c
index ab489fef..c0b4ba47 100644
--- a/lib/util/shhopt.c
+++ b/lib/util/shhopt.c
@@ -394,7 +394,7 @@ static void
 optExecute(optEntry  const opt, char *arg, int lng)
 {
     if (opt.specified)
-        (*(opt.specified))++;
+        *opt.specified = 1;
 
     switch (opt.type) {
     case OPT_FLAG:
diff --git a/lib/util/shhopt.h b/lib/util/shhopt.h
index d9304f9f..03f40cc5 100644
--- a/lib/util/shhopt.h
+++ b/lib/util/shhopt.h
@@ -144,8 +144,8 @@ typedef struct {
            the rightmost one affects this return value.
         */
     unsigned int *specified;
-        /* pointer to variable in which to return the number of times that
-           the option was specified.  If NULL, don't return anything.
+        /* pointer to variable in which to return 1 if the option was
+           specified and 0 if it was not.  If NULL, don't return anything.
         */
     int        flags;      /* modifier flags. */
 } optEntry;
@@ -213,15 +213,23 @@ typedef struct {
 /* OPTENT3 is the same as OPTENTRY except that it also sets the "specified"
    element of the table entry (so it assumes OPTION_DEF is a table of optEntry
    instead of optStruct).  This is a pointer to a variable that the parser
-   will set to the number of times that the option appears in the command
-   line.
+   will set to and indication of whether the option appears in the command
+   line.  1 for yes; 0 for no.
+
+   HISTORICAL NOTE: Until 2019, this was the number of times the option was
+   specified, but much Netpbm code assumed it was never more than 1, and no
+   Netpbm code has ever given semantics to specifying the same option class
+   multiple times.
 
    Here is an example:
 
        unsigned int option_def_index = 0;
+       unsigned int help_flag;
+       const char * alpha_filename
+       unsigned int alpha_spec;
        MALLOCARRAY_NOFAIL(option_def, 100);
-       OPTENT3('h', "help",     OPT_FLAG, &help_flag, 0);
-       OPTENT3(0,   "alphaout", OPT_STRING, &alpha_filename, 0);
+       OPTENT3('h', "help",     OPT_FLAG,   &help_flag,      NULL);
+       OPTENT3(0,   "alphaout", OPT_STRING, &alpha_filename, &alpha_spec);
 */
 
 #define OPTENT3(shortvalue,longvalue,typevalue,outputvalue,specifiedvalue, \