apt @VERSION@
|
00001 // -*- mode: cpp; mode: fold -*- 00002 // Description /*{{{*/ 00003 // $Id: cmndline.h,v 1.7 1999/10/31 06:32:28 jgg Exp $ 00004 /* ###################################################################### 00005 00006 Command Line Class - Sophisticated command line parser 00007 00008 This class provides a unified command line parser/option handliner/ 00009 configuration mechanism. It allows the caller to specify the option 00010 set and map the option set into the configuration class or other 00011 special functioning. 00012 00013 Filenames are stripped from the option stream and put into their 00014 own array. 00015 00016 The argument descriptor array can be initialized as: 00017 00018 CommandLine::Args Args[] = 00019 {{'q',"quiet","apt::get::quiet",CommandLine::IntLevel}, 00020 {0,0,0,0}}; 00021 00022 The flags mean, 00023 HasArg - Means the argument has a value 00024 IntLevel - Means the argument is an integer level indication, the 00025 following -qqqq (+3) -q5 (=5) -q=5 (=5) are valid 00026 Boolean - Means it is true/false or yes/no. 00027 -d (true) --no-d (false) --yes-d (true) 00028 --long (true) --no-long (false) --yes-long (true) 00029 -d=yes (true) -d=no (false) Words like enable, disable, 00030 true false, yes no and on off are recognized in logical 00031 places. 00032 InvBoolean - Same as boolean but the case with no specified sense 00033 (first case) is set to false. 00034 ConfigFile - Means this flag should be interprited as the name of 00035 a config file to read in at this point in option processing. 00036 Implies HasArg. 00037 ArbItem - Means the item is an arbitrary configuration string of 00038 the form item=value, where item is passed directly 00039 to the configuration class. 00040 The default, if the flags are 0 is to use Boolean 00041 00042 ##################################################################### */ 00043 /*}}}*/ 00044 #ifndef PKGLIB_CMNDLINE_H 00045 #define PKGLIB_CMNDLINE_H 00046 00047 00048 00049 #include <apt-pkg/configuration.h> 00050 00051 class CommandLine 00052 { 00053 public: 00054 struct Args; 00055 struct Dispatch; 00056 00057 protected: 00058 00059 Args *ArgList; 00060 Configuration *Conf; 00061 bool HandleOpt(int &I,int argc,const char *argv[], 00062 const char *&Opt,Args *A,bool PreceedeMatch = false); 00063 void static SaveInConfig(unsigned int const &argc, char const * const * const argv); 00064 00065 public: 00066 00067 enum AFlags 00068 { 00069 HasArg = (1 << 0), 00070 IntLevel = (1 << 1), 00071 Boolean = (1 << 2), 00072 InvBoolean = (1 << 3), 00073 ConfigFile = (1 << 4) | HasArg, 00074 ArbItem = (1 << 5) | HasArg 00075 }; 00076 00077 const char **FileList; 00078 00079 bool Parse(int argc,const char **argv); 00080 void ShowHelp(); 00081 unsigned int FileSize() const; 00082 bool DispatchArg(Dispatch *List,bool NoMatch = true); 00083 00084 CommandLine(Args *AList,Configuration *Conf); 00085 ~CommandLine(); 00086 }; 00087 00088 struct CommandLine::Args 00089 { 00090 char ShortOpt; 00091 const char *LongOpt; 00092 const char *ConfName; 00093 unsigned long Flags; 00094 00095 inline bool end() {return ShortOpt == 0 && LongOpt == 0;}; 00096 inline bool IsBoolean() {return Flags == 0 || (Flags & (Boolean|InvBoolean)) != 0;}; 00097 }; 00098 00099 struct CommandLine::Dispatch 00100 { 00101 const char *Match; 00102 bool (*Handler)(CommandLine &); 00103 }; 00104 00105 #endif