1 /* 2 * wmslib/src/wms/clp.h, part of wmslib (Library functions) 3 * Copyright (C) 1994-1996 William Shubert. 4 * See "configure.h.in" for more copyright information. 5 * 6 * Command Line Parse. 7 */ 8 9 #ifndef _WMS_CLP_H_ 10 11 #ifndef _WMS_STR_H_ 12 #include <wms/str.h> 13 #endif 14 15 #ifdef _WMS_CLP_H_ 16 Levelization Error. 17 #endif 18 #define _WMS_CLP_H_ 1 19 20 21 /********************************************************************** 22 * Data types. These are all visible to the application. 23 **********************************************************************/ 24 25 struct ClpEntry_struct; 26 27 /* Public. */ 28 #define CLPSETUP_BOOL 0x01 /* Is it "-[no]<x>" or "-<x> <arg>"? */ 29 #define CLPSETUP_SHOWBOOL 0x02 /* Show "[no]" in the help. */ 30 #define CLPSETUP_NOSAVE 0x04 31 #define CLPSETUP_ENDFLAG 0x08 32 #define CLPSETUP_HELP 0x10 /* This switch gives you help. */ 33 typedef struct ClpSetup_struct { 34 const char *name; /* NULL for just a label. */ 35 const char *defVal; 36 const char *desc; /* NULL if it doesn't show up in the help. */ 37 uint flags; 38 bool (*test)(struct ClpEntry_struct *entry); 39 } ClpSetup; 40 41 typedef enum { 42 clpWhere_unset, clpWhere_rcfile, clpWhere_xdefs, clpWhere_cmdline, 43 clpWhere_dup 44 } ClpWhere; 45 46 47 /* Private. */ 48 typedef enum { 49 clpDtype_int, clpDtype_double, clpDtype_bool, clpDtype_string, 50 clpDtype_end 51 } ClpDtype; 52 53 typedef struct ClpEntry_struct { 54 const char *name; 55 const char *desc; 56 uint flags; 57 bool (*test)(struct ClpEntry_struct *entry); 58 ClpWhere where; 59 ClpDtype type; 60 int numStrs, maxStrs; 61 union { 62 int ival; 63 double dval; 64 Str *strList; 65 bool bval; 66 } storage; 67 68 MAGIC_STRUCT 69 } ClpEntry; 70 71 72 typedef struct Clp_struct { 73 ClpEntry *infos; 74 int numInfos; 75 76 MAGIC_STRUCT 77 } Clp; 78 79 /********************************************************************** 80 * Routines available 81 **********************************************************************/ 82 extern Clp *clp_create(const ClpSetup vars[]); 83 extern void clp_destroy(Clp *clp); 84 85 /* 86 * clp_rCmdline returns the number of arguments left on the command 87 * line, or CLP_ARGS_NOGOOD if there was an error. 88 */ 89 extern int clp_rCmdline(Clp *cltab, char *argv[]); 90 91 /* 92 * clp_rFile returns FALSE if it can't find the file at all. 93 */ 94 extern bool clp_rFile(Clp *cltab, const char *fname); 95 extern void clp_wFile(Clp *cltab, const char *fname, const char *pname); 96 97 extern ClpEntry *clp_lookup(Clp *clp, const char *varName); 98 99 #define clp_where(clp, str) (clp_lookup(clp, str)->where) 100 #define clpEntry_where(ce) ((ce)->where) 101 102 extern int clpEntry_iGetInt(ClpEntry *ce, bool *err); 103 #define clp_iGetInt(clp, str, e) clpEntry_iGetInt(clp_lookup(clp, str), e) 104 #define clpEntry_getInt(ce) clpEntry_iGetInt(ce, NULL) 105 #define clp_getInt(clp, str) clpEntry_getInt(clp_lookup(clp, str)) 106 107 extern double clpEntry_iGetDouble(ClpEntry *ce, bool *err); 108 #define clpEntry_getDouble(ce) clpEntry_iGetDouble(ce, NULL) 109 #define clp_getDouble(clp, str) clpEntry_getDouble(clp_lookup(clp,str)) 110 111 #define clpEntry_numStrs(ce) ((ce)->numStrs) 112 113 extern const char *clpEntry_iGetStrNum(ClpEntry *ce, int num, bool *err); 114 #define clpEntry_getStrNum(ce, n) clpEntry_iGetStrNum(ce, n, NULL) 115 #define clp_getStrNum(clp, s, n) clpEntry_getStrNum(clp_lookup(clp, s), n) 116 117 #define clpEntry_iGetStr(ce, e) clpEntry_iGetStrNum(ce, 0, e) 118 #define clpEntry_getStr(ce) clpEntry_iGetStr(ce, NULL) 119 #define clp_getStr(clp, str) clpEntry_getStr(clp_lookup(clp, str)) 120 121 extern bool clpEntry_iGetBool(ClpEntry *ce, bool *err); 122 #define clpEntry_getBool(ce) clpEntry_iGetBool(ce, NULL) 123 #define clp_getBool(clp, str) clpEntry_getBool(clp_lookup(clp, str)) 124 125 extern bool clpEntry_setInt(ClpEntry *ce, int val); 126 #define clp_setInt(c, s, v) clpEntry_setInt(clp_lookup(c, s), v) 127 128 extern bool clpEntry_setDouble(ClpEntry *ce, double val); 129 #define clp_setDouble(c, s, v) clpEntry_setDouble(clp_lookup(c, s), v) 130 131 extern bool clpEntry_setStrNum(ClpEntry *ce, const char *val, int num); 132 #define clp_setStrNum(c, s, v, n) clpEntry_setStrNum(clp_lookup(c, s), v, n) 133 134 #define clpEntry_setStr(ce, v) clpEntry_setStrNum(ce, v, 0) 135 #define clp_setStr(c, s, v) clpEntry_setStr(clp_lookup(c, s), v) 136 137 extern bool clpEntry_setBool(ClpEntry *ce, bool val); 138 #define clp_setBool(c, s, v) clpEntry_setBool(clp_lookup(c, s), v) 139 140 141 /********************************************************************** 142 * Handy macros and constants. 143 **********************************************************************/ 144 #define CLPSETUP_MSG(message) {NULL, NULL, message, 0, NULL} 145 #define CLPSETUP_END {NULL,NULL,NULL,CLPSETUP_ENDFLAG, NULL} 146 147 #define CLP_ARGS_NOGOOD -1 148 149 #endif /* _WMS_CLP_H_ */ 150