1 /*-----------------------------------------------------------------------
2 
3 File  : cio_commandline.h
4 
5 Author: Stephan Schulz
6 
7 Contents
8 
9   Definitions for handling options and recognising non-option
10   arguments.
11 
12   "Why don't you use getopt()?"
13 
14   - Implementations of getopt() seem to differ significantly between
15     UNIX implementations. Finding out what the differences are and
16     coding around them seems to be more work than writing this version
17     from scratch.
18   - This implementation comes with more support for the handling of
19     numerical arguments for options.
20   - Finally, this implementation allows (well, forces) the programmer
21     to document an option _immediately_, and automates the process of
22     presenting this information to the user.
23 
24   Copyright 1998, 1999 by the author.
25   This code is released under the GNU General Public Licence and
26   the GNU Lesser General Public License.
27   See the file COPYING in the main E directory for details..
28   Run "eprover -h" for contact information.
29 
30 Changes
31 
32 <1> Sun Sep  7 00:38:12 MET DST 1997
33     New
34 
35 -----------------------------------------------------------------------*/
36 
37 #ifndef CIO_COMMANDLINE
38 
39 #define CIO_COMMANDLINE
40 
41 #include <clb_dstrings.h>
42 
43 
44 /*---------------------------------------------------------------------*/
45 /*                    Data type declarations                           */
46 /*---------------------------------------------------------------------*/
47 
48 /* Supported option types: */
49 
50 typedef enum
51 {
52    NoArg,
53    OptArg,
54    ReqArg
55 }OptArgType;
56 
57 typedef struct optcell
58 {
59    int         option_code;
60    char        shortopt;    /* Single Character options */
61    char*       longopt;     /* Double dash, GNU-Style */
62    OptArgType  type;        /* What about Arguments? */
63    char*       arg_default; /* Default for optional argument (long
64                 style only */
65    char*       desc;        /* Put the documentation in immediately! */
66 }OptCell, *Opt_p;
67 
68 
69 typedef struct clstatecell
70 {
71    int     sc_opt_c;  /* Which character of the current element of
72           argv has to be read next? */
73    int     argi;      /* Which element of argv[] ? */
74    int     argsize;   /* How large is the argv array really? */
75    int     argc;      /* How many elements in argv[]? */
76    char**  argv;      /* Vector of arguments. Processed options and
77           option args will be removed */
78 }CLStateCell, *CLState_p;
79 
80 /*---------------------------------------------------------------------*/
81 /*                Exported Functions and Variables                     */
82 /*---------------------------------------------------------------------*/
83 
84 #define CLStateCellAlloc() (CLStateCell*)SizeMalloc(sizeof(CLStateCell))
85 #define CLStateCellFree(junk)        SizeFree(junk, sizeof(CLStateCell))
86 
87 
88 #define FORMAT_WIDTH 78
89 
90 CLState_p CLStateAlloc(int argc, char* argv[]);
91 void      CLStateFree(CLState_p junk);
92 
93 Opt_p  CLStateGetOpt(CLState_p state, char** arg, OptCell options[]);
94 int    CLStateInsertArg(CLState_p state, char* arg);
95 
96 double CLStateGetFloatArg(Opt_p option, char* arg);
97 long   CLStateGetIntArg(Opt_p option, char* arg);
98 bool   CLStateGetBoolArg(Opt_p option, char* arg);
99 
100 void PrintOption(FILE* out, Opt_p option);
101 void PrintOptions(FILE* out, OptCell option[], char* header);
102 
103 
104 #endif
105 
106 /*---------------------------------------------------------------------*/
107 /*                        End of File                                  */
108 /*---------------------------------------------------------------------*/
109 
110 
111 
112 
113 
114