about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-05-26 17:57:16 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-05-26 17:57:16 +0000
commitc95f75ad52009a53373192c6512baa89bbca5608 (patch)
tree1f4639181e53151985eebe211221dcae2abfa889 /lib
parent0d221da32d6d1879e3c428b28e41cdc7560a59bb (diff)
downloadnetpbm-mirror-c95f75ad52009a53373192c6512baa89bbca5608.tar.gz
netpbm-mirror-c95f75ad52009a53373192c6512baa89bbca5608.tar.xz
netpbm-mirror-c95f75ad52009a53373192c6512baa89bbca5608.zip
Make shhopt 'specified' output boolean instead of a count
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3620 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/util/shhopt.c2
-rw-r--r--lib/util/shhopt.h20
2 files changed, 15 insertions, 7 deletions
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, \