You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

105 lines
3.0 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: cmndline.h,v 1.7 1999/10/31 06:32:28 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}};
  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. ArbItem - Means the item is an arbitrary configuration string of
  32. the form item=value, where item is passed directly
  33. to the configuration class.
  34. The default, if the flags are 0 is to use Boolean
  35. ##################################################################### */
  36. /*}}}*/
  37. #ifndef PKGLIB_CMNDLINE_H
  38. #define PKGLIB_CMNDLINE_H
  39. #include <apt-pkg/configuration.h>
  40. class CommandLine
  41. {
  42. public:
  43. struct Args;
  44. struct Dispatch;
  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. bool DispatchArg(Dispatch *List,bool NoMatch = true);
  65. CommandLine(Args *AList,Configuration *Conf);
  66. ~CommandLine();
  67. };
  68. struct CommandLine::Args
  69. {
  70. char ShortOpt;
  71. const char *LongOpt;
  72. const char *ConfName;
  73. unsigned long Flags;
  74. inline bool end() {return ShortOpt == 0 && LongOpt == 0;};
  75. inline bool IsBoolean() {return Flags == 0 || (Flags & (Boolean|InvBoolean)) != 0;};
  76. };
  77. struct CommandLine::Dispatch
  78. {
  79. const char *Match;
  80. bool (*Handler)(CommandLine &);
  81. };
  82. #endif