Makefile.am: Ship `debian/compat'.
[cfd] / mdwopt.h
index 5ac9d80..ba3a024 100644 (file)
--- a/mdwopt.h
+++ b/mdwopt.h
@@ -1,10 +1,8 @@
 /* -*-c-*-
  *
- * $Id: mdwopt.h,v 1.3 1999/05/14 18:51:42 mdw Exp $
- *
  * Options parsing, similar to GNU @getopt_long@
  *
- * (c) 1996 Mark Wooding
+ * (c) 1996 Straylight/Edgeware
  */
 
 /*----- Licensing notice --------------------------------------------------*
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: mdwopt.h,v $
- * Revision 1.3  1999/05/14 18:51:42  mdw
- * Reformat the LGPL notice slightly.
- *
- * Revision 1.2  1999/05/13 22:57:23  mdw
- * Change `-ise' to `-ize' throughout.
- *
- * Revision 1.1.1.1  1999/05/05 19:23:47  mdw
- * New import.  The old CVS repository was lost in a disk disaster.
- *
- * --- Previous lives ---
- *
- * %Log: mdwopt.h,v %
- * Revision 1.5  1997/08/09 20:27:59  mdw
- * Fix spelling of `Licensing'.
- *
- * Revision 1.4  1997/07/29 21:11:49  mdw
- * Fixed address of the FSF.
- *
- * Revision 1.3  1996/12/31 19:41:33  mdw
- * Formatting changes.
- *
- * Revision 1.2  1996/11/23 00:47:25  mdw
- * Added `MdwOpt' object from the `anagram' source code.
- *
- * Revision 1.1  1996/09/24 18:01:43  mdw
- * Initial revision
- *
- */
-
 #ifndef MDWOPT_H
 #define MDWOPT_H
 
 /* --- @mdwopt_data@ --- *
  *
  * Contains all the information needed by the @mdwopt@ routine to do its
- * work.
+ * work.  Try not to use @prog@ any more.  If you're using mLib, the @quis@/
+ * @ego@ interface works better.
  */
 
 typedef struct {
+
   /* --- Public variables --- */
 
   char *arg;                           /* Arg of current option, or 0 */
@@ -134,28 +102,37 @@ enum {
 
 /* --- New style flag names --- */
 
+#define OPTF_NOARG 0u                  /* No argument */
+#define OPTF_ARGREQ 1u                 /* Required argument */
+#define OPTF_ARGOPT 2u                 /* Optional argument */
+#define OPTF_ARG 3u                    /* Argument type bitmask */
+#define OPTF_SWITCH 4u                 /* OR val into flag, don't store */
+#define OPTF_NEGATE 8u                 /* Allow long option to be negated */
+
+#define OPTF_NOLONGS 1u                        /* Don't read long options */
+#define OPTF_NOSHORTS 2u               /* Don't read short options */
+#define OPTF_NUMBERS 4u                        /* Read numeric options */
+#define OPTF_NEGATION 8u               /* Allow `%|+|%' for negations */
+#define OPTF_ENVVAR 16u                        /* Parse options from env var */
+#define OPTF_NOPROGNAME 32u            /* Don't set @optprog@  */
+#define OPTF_NEGNUMBER 64u             /* Allow negated number options */
+
+#define OPTF_NEGATED 256u              /* Option flag was negated by user */
+
+/* --- Older new-style names --- */
+
 enum {
-  gFlag_argReq = 1,                    /* Required argument */
-  gFlag_argOpt = 2,                    /* Optional argument */
-  gFlag_switch = 4,                    /* OR val into flag, don't store */
-  gFlag_negate = 8,                    /* Allow long option to be negated */
-  gFlag__last_long_opt_flag = 0                /* Dummy value */
+  gFlag_argReq = 1, gFlag_argOpt = 2, gFlag_switch = 4, gFlag_negate = 8
 };
 
 enum {
-  gFlag_noLongs = 1,                   /* Don't read long options */
-  gFlag_noShorts = 2,                  /* Don't read short options */
-  gFlag_numbers = 4,                   /* Read numeric options */
-  gFlag_negation = 8,                  /* Allow `%|+|%' for negations */
-  gFlag_envVar = 16,                   /* Parse options from env var */
-  gFlag_noProgName = 32,               /* Don't set @optprog@  */
-  gFlag_negNumber = 64,                        /* Allow negated number options */
-  gFlag__last_mdwopt_flag = 0          /* Dummy value */
+  gFlag_noLongs = 1, gFlag_noShorts = 2, gFlag_numbers = 4,
+  gFlag_negation = 8, gFlag_envVar = 16, gFlag_noProgName = 32,
+  gFlag_negNumber = 64
 };
 
 enum {
-  gFlag_negated = 256,                 /* Option flag was negated by user */
-  gFlag__last_return_flag = 0          /* Dummy value */
+  gFlag_negated = 256
 };
 
 /*----- Main code ---------------------------------------------------------*/
@@ -312,7 +289,7 @@ enum {
  *              the caller.  A pointer to an argument is stored in
  *              @data->arg@, or @NULL@ is stored if there was no argument.
  *              If a negated option was found, the option character is
- *              returned ORred with @gFlag_negated@ (bit 8 set).
+ *              returned ORred with @OPTF_NEGATED@ (bit 8 set).
  *
  *              Long options are described in a table.  Each entry in the
  *              table is of type @struct option@, and the table is terminated
@@ -330,9 +307,9 @@ enum {
  *              table entry.  If @flag@ is nonzero, it points to an integer
  *              to be modified by mdwopt.  Usually the value in the @val@
  *              field is simply stored in the @flag@ variable. If the flag
- *              @gFlag_switch@ is set, however, the value is combined with
+ *              @OPTF_SWITCH@ is set, however, the value is combined with
  *              the existing value of the flags using a bitwise OR.  If
- *              @gFlag_negate@ is set, then the flag bit will be cleared if a
+ *              @OPTF_NEGATE@ is set, then the flag bit will be cleared if a
  *              matching negated long option is found.  The value 0 is
  *              returned.
  *
@@ -345,11 +322,12 @@ enum {
  *              Numeric options, if enabled, cause the value `%|#|%' to be
  *              returned, and the numeric value to be stored in @data->opt@.
  *
- *              If the flag @gFlag_envVar@ is set on entry, options will be
+ *              If the flag @OPTF_ENVVAR@ is set on entry, options will be
  *              extracted from an environment variable whose name is built by
- *              capitalising all the letters of the program's name.  (This
+ *              capitalizing all the letters of the program's name.  (This
  *              allows a user to have different default settings for a
- *              program, by calling it through different symbolic links.)  */
+ *              program, by calling it through different symbolic links.)
+ */
 
 extern int mdwopt(int /*argc*/, char *const */*argv*/,
                  const char */*shortopt*/,
@@ -358,10 +336,10 @@ extern int mdwopt(int /*argc*/, char *const */*argv*/,
 
 /* --- Macros for more commonly used routines --- */
 
-#define getopt(c, v, o) mdwopt(c, v, o, 0, 0, 0, gFlag_noLongs)
+#define getopt(c, v, o) mdwopt(c, v, o, 0, 0, 0, OPTF_NOLONGS)
 #define getopt_long(c, v, o, l, li) mdwopt(c, v, o, l, li, 0, 0)
 #define getopt_long_only(c, v, o, l, li)                               \
-  mdwopt(c, v, o, l, li, 0, gFlag_noShorts)
+  mdwopt(c, v, o, l, li, 0, OPTF_NOSHORTS)
 
 #ifdef __cplusplus
 }