about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lib/util/shhopt.c2
-rw-r--r--lib/util/shhopt.h17
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/util/shhopt.c b/lib/util/shhopt.c
index 4f7ce9c7..ccf2d1eb 100644
--- a/lib/util/shhopt.c
+++ b/lib/util/shhopt.c
@@ -77,7 +77,7 @@ optFatalFunc(const char *format, ...)
  |
  |  RETURNS       Number of options in the given array.
  |
- |  DESCRIPTION   Count elements in an optStruct-array. The strcture must
+ |  DESCRIPTION   Count elements in an optStruct-array. The structure must
  |                be ended using an element of type OPT_END.
  */
 static int
diff --git a/lib/util/shhopt.h b/lib/util/shhopt.h
index 6be7f411..9a446290 100644
--- a/lib/util/shhopt.h
+++ b/lib/util/shhopt.h
@@ -22,7 +22,8 @@ main ( int argc, char **argv ) {
     
     optStruct3 opt;
     unsigned int option_def_index = 0;
-    optEntry *option_def = malloc(100*sizeof(option_def[0]));
+    optEntry * option_def;
+    MALLOCARRAY(option_def, 100);
 
     OPTENT3(0,   "help",     OPT_FLAG,     &help_flag,    &help_spec,   0);
     OPTENT3(0,   "height",   OPT_INT,      &height,       &height_spec, 0);
@@ -69,6 +70,13 @@ Now run this program with something like
   myprog -v /etc/passwd -name=Bryan --hei=4
 
 
+  If your program takes no options (so you have no OPTENT3 macro invocations),
+  you need an OPTENTINIT call to establish the empty option table:
+
+    optEntry * option_def;
+    MALLOCARRAY(option_def, 1);
+    OPTENTINIT;
+
 ========================================================================
 #endif /* 0 */
 
@@ -190,9 +198,10 @@ 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).  It sets it to the number of times that
-   the option appears in the command line.
+   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.
 
    Here is an example: