cmndline.h 2.8 KB

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