]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: cmndline.h,v 1.7 1999/10/31 06:32:28 jgg Exp $ | |
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}}; | |
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 | ArbItem - Means the item is an arbitrary configuration string of | |
38 | the form item=value, where item is passed directly | |
39 | to the configuration class. | |
40 | The default, if the flags are 0 is to use Boolean | |
41 | ||
42 | ##################################################################### */ | |
43 | /*}}}*/ | |
44 | #ifndef PKGLIB_CMNDLINE_H | |
45 | #define PKGLIB_CMNDLINE_H | |
46 | ||
47 | #ifndef APT_8_CLEANER_HEADERS | |
48 | #include <apt-pkg/configuration.h> | |
49 | #endif | |
50 | ||
51 | class Configuration; | |
52 | ||
53 | class CommandLine | |
54 | { | |
55 | public: | |
56 | struct Args; | |
57 | struct Dispatch; | |
58 | ||
59 | protected: | |
60 | ||
61 | Args *ArgList; | |
62 | Configuration *Conf; | |
63 | bool HandleOpt(int &I,int argc,const char *argv[], | |
64 | const char *&Opt,Args *A,bool PreceedeMatch = false); | |
65 | void static SaveInConfig(unsigned int const &argc, char const * const * const argv); | |
66 | ||
67 | public: | |
68 | ||
69 | enum AFlags | |
70 | { | |
71 | HasArg = (1 << 0), | |
72 | IntLevel = (1 << 1), | |
73 | Boolean = (1 << 2), | |
74 | InvBoolean = (1 << 3), | |
75 | ConfigFile = (1 << 4) | HasArg, | |
76 | ArbItem = (1 << 5) | HasArg | |
77 | }; | |
78 | ||
79 | const char **FileList; | |
80 | ||
81 | bool Parse(int argc,const char **argv); | |
82 | void ShowHelp(); | |
83 | unsigned int FileSize() const; | |
84 | bool DispatchArg(Dispatch *List,bool NoMatch = true); | |
85 | ||
86 | CommandLine(Args *AList,Configuration *Conf); | |
87 | ~CommandLine(); | |
88 | }; | |
89 | ||
90 | struct CommandLine::Args | |
91 | { | |
92 | char ShortOpt; | |
93 | const char *LongOpt; | |
94 | const char *ConfName; | |
95 | unsigned long Flags; | |
96 | ||
97 | inline bool end() {return ShortOpt == 0 && LongOpt == 0;}; | |
98 | inline bool IsBoolean() {return Flags == 0 || (Flags & (Boolean|InvBoolean)) != 0;}; | |
99 | }; | |
100 | ||
101 | struct CommandLine::Dispatch | |
102 | { | |
103 | const char *Match; | |
104 | bool (*Handler)(CommandLine &); | |
105 | }; | |
106 | ||
107 | #endif |