commandlineparserbase.hh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
  2. // vi:set ts=4 sts=4 sw=4 noet :
  3. //
  4. // Copyright 2010, 2011 wkhtmltopdf authors
  5. //
  6. // This file is part of wkhtmltopdf.
  7. //
  8. // wkhtmltopdf is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU Lesser General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // wkhtmltopdf is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Lesser General Public License
  19. // along with wkhtmltopdf. If not, see <http://www.gnu.org/licenses/>.
  20. #ifndef __COMMANDLINEPARSERBASE_HH__
  21. #define __COMMANDLINEPARSERBASE_HH__
  22. #include <loadsettings.hh>
  23. #include <websettings.hh>
  24. class Outputter;
  25. class CommandLineParserBase;
  26. class ArgHandler {
  27. public:
  28. QString longName;
  29. QString desc;
  30. char shortSwitch;
  31. QVector<QString> argn;
  32. bool display;
  33. bool extended;
  34. bool qthack;
  35. virtual QString getDesc() const;
  36. virtual ~ArgHandler();
  37. int section;
  38. virtual bool operator() (const char ** args, CommandLineParserBase & parser, char * page) = 0;
  39. };
  40. class CommandLineParserBase {
  41. public:
  42. int currentMode;
  43. QString currentSection;
  44. bool currentExtended;
  45. bool currentHack;
  46. QList<QString> sections;
  47. QHash<QString, ArgHandler *> longToHandler;
  48. QHash<char, ArgHandler *> shortToHandler;
  49. QHash<QString, QList<ArgHandler *> > sectionArgumentHandles;
  50. QHash<QString, QString> sectionDesc;
  51. //basearguments.cc
  52. void section(QString s, QString desc="");
  53. void mode(int m);
  54. void qthack(bool);
  55. void extended(bool);
  56. void addarg(QString, char, QString, ArgHandler * h, bool display=true);
  57. void addDocArgs();
  58. void addWebArgs(wkhtmltopdf::settings::Web & s);
  59. void addGlobalLoadArgs(wkhtmltopdf::settings::LoadGlobal & s);
  60. void addPageLoadArgs(wkhtmltopdf::settings::LoadPage & s);
  61. //commondocparts.cc
  62. void outputName(Outputter * o) const;
  63. void outputLicense(Outputter * o) const;
  64. void outputAuthors(Outputter * o) const;
  65. void outputStaticProblems(Outputter * o) const;
  66. void outputProxyDoc(Outputter * o) const;
  67. //commandlineparserbase.cc
  68. void outputSwitches(Outputter * o, bool extended, bool doc) const;
  69. virtual char * mapAddress(char * d, char *) const {return d;}
  70. virtual void license(FILE * fd) const;
  71. virtual void version(FILE * fd) const;
  72. void parseArg(int sections, const int argc, const char ** argv, bool & defaultMode, int & arg, char * page);
  73. virtual QString appName() const = 0;
  74. const char *appVersion() const;
  75. virtual void usage(FILE * fd, bool extended) const = 0;
  76. virtual void manpage(FILE * fd) const = 0;
  77. virtual void readme(FILE * fd, bool html) const = 0;
  78. };
  79. #endif //__COMMANDLINEPARSERBASE_HH__