]>
Commit | Line | Data |
---|---|---|
08e8f724 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
e1b74f61 | 3 | // $Id: cmndline.h,v 1.2 1998/09/26 05:34:25 jgg Exp $ |
08e8f724 AL |
4 | /* ###################################################################### |
5 | ||
6 | Command Line Class - Sophisticated command line parser | |
7 | ||
8 | This class provides a unified command line parser/option handliner/ | |
9 | configuration mechanism. It allows the caller to specify the option | |
10 | set and map the option set into the configuration class or other | |
11 | special functioning. | |
12 | ||
13 | Filenames are stripped from the option stream and put into their | |
14 | own array. | |
15 | ||
16 | The argument descriptor array can be initialized as: | |
17 | ||
18 | CommandLine::Args Args[] = | |
19 | {{'q',"quiet","apt::get::quiet",CommandLine::IntLevel}, | |
20 | {0,0,0,0,0}}; | |
21 | ||
22 | The flags mean, | |
23 | HasArg - Means the argument has a value | |
24 | IntLevel - Means the argument is an integer level indication, the | |
25 | following -qqqq (+3) -q5 (=5) -q=5 (=5) are valid | |
26 | Boolean - Means it is true/false or yes/no. | |
27 | -d (true) --no-d (false) --yes-d (true) | |
28 | --long (true) --no-long (false) --yes-long (true) | |
29 | -d=yes (true) -d=no (false) Words like enable, disable, | |
30 | true false, yes no and on off are recognized in logical | |
31 | places. | |
32 | InvBoolean - Same as boolean but the case with no specified sense | |
33 | (first case) is set to false. | |
34 | ConfigFile - Means this flag should be interprited as the name of | |
35 | a config file to read in at this point in option processing. | |
36 | Implies HasArg. | |
37 | The default, if the flags are 0 is to use Boolean | |
38 | ||
39 | ##################################################################### */ | |
40 | /*}}}*/ | |
41 | // Header section: pkglib | |
42 | #ifndef PKGLIB_CMNDLINE_H | |
43 | #define PKGLIB_CMNDLINE_H | |
44 | ||
45 | #ifdef __GNUG__ | |
46 | #pragma interface "apt-pkg/cmndline.h" | |
47 | #endif | |
48 | ||
49 | #include <apt-pkg/configuration.h> | |
50 | ||
51 | class CommandLine | |
52 | { | |
53 | public: | |
54 | struct Args; | |
55 | ||
56 | protected: | |
57 | ||
58 | Args *ArgList; | |
59 | Configuration *Conf; | |
60 | bool HandleOpt(int &I,int argc,const char *argv[],const char *&Opt,Args *A); | |
61 | ||
62 | public: | |
63 | ||
64 | enum AFlags | |
65 | { | |
66 | HasArg = (1 << 0), | |
67 | IntLevel = (1 << 1), | |
68 | Boolean = (1 << 2), | |
69 | InvBoolean = (1 << 3), | |
e1b74f61 AL |
70 | ConfigFile = (1 << 4) | HasArg, |
71 | ArbItem = (1 << 5) | HasArg | |
08e8f724 AL |
72 | }; |
73 | ||
74 | const char **FileList; | |
75 | ||
76 | bool Parse(int argc,const char **argv); | |
77 | void ShowHelp(); | |
e1b74f61 | 78 | unsigned int FileSize() const; |
08e8f724 AL |
79 | |
80 | CommandLine(Args *AList,Configuration *Conf); | |
e1b74f61 | 81 | ~CommandLine(); |
08e8f724 AL |
82 | }; |
83 | ||
84 | struct CommandLine::Args | |
85 | { | |
86 | char ShortOpt; | |
87 | const char *LongOpt; | |
88 | const char *ConfName; | |
89 | unsigned long Flags; | |
90 | ||
91 | inline bool end() {return ShortOpt == 0 && LongOpt == 0;}; | |
e1b74f61 | 92 | inline bool IsBoolean() {return Flags == 0 || (Flags & (Boolean|InvBoolean)) != 0;}; |
08e8f724 AL |
93 | }; |
94 | ||
95 | #endif |