ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/GArgs.h
Revision: 2
Committed: Mon Mar 22 22:03:27 2010 UTC (9 years, 6 months ago) by gpertea
File size: 2537 byte(s)
Log Message:
added my gclib source files

Line File contents
1 /*
2 **
3 GArgs is a quick'n'dirty object oriented replacement for the standard
4 getopts library call avialable on many unix platforms.
5 it accepts dash style options and = style options
6 -<letter>[ ][<value>]
7 <string>=<value>
8 */
9
10 #ifndef G_ARGS_DEFINED
11 #define G_ARGS_DEFINED
12
13
14
15 class GArgs {
16 //structure for parsing arguments format definition
17 struct fmtdef {
18 int type; // 0=dashed switch, 1=dashed value, 2='=' value
19 char* opt; //switch/opt char/string
20 };
21 int fmtcount;
22 fmtdef* fmt; //this will store format definition after parsing it
23
24 struct argdata {
25 char* opt; // this is NULL for non-dashed arguments
26 //one character for dashed style arguments
27 //one string for = style arguments
28 char* value; // is NULL for switches (dashed flags)
29 };
30 argdata* args; //arguments table after parsing it
31 int count; //total count of elements in 'args' array
32 int nonOptCount; //count of non-dashed, non= arguments
33 int nonOptPos; //current position for nonOpt arguments iterator
34 int optPos; //current position for options iterator
35 int errarg; //argv error position after parsing
36 static const char* is_opt; // = non NULL just for getOpt easy testing
37 int validOpt(char o); //parsing helper function
38 int validOpt(char* o);
39 public:
40
41 GArgs(int argc, char* const argv[], const char* format, bool nodigitopts=false);
42 /* format is:
43 <letter>[:] for e.g. p:hT <= -p testing -ptesting -h -T
44 <string>= for e.g. PID=S= <= PID=50 S=3.5
45 This means that the = options, if present, must NEVER be given after
46 dashed (non-value) switches directly
47 */
48 ~GArgs();
49 int isError(); // returns the offending argv position or 0 if no error
50 int getCount() { return count; }
51 int getFmtCount() { return fmtcount; }
52 int getNonOptCount() { return nonOptCount; }
53 char* getOpt(const char* o); /* retrieve the value for option o
54 returns
55 NULL if option not given at all
56 !=NULL if boolean option was given
57 opt's value if value option was given
58 */
59 char* getOpt(const char o);
60 int startOpt(); //init iteration through option arguments
61 char* nextOpt(); //get next option argument
62 int startNonOpt(); //init iteration through non-option arguments
63 //returns the number of non-option arguments
64 char* nextNonOpt(); //get the next non-option argument
65
66 };
67
68 #endif