imagecommandlineparser.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 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 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 General Public License
  19. // along with wkhtmltopdf. If not, see <http://www.gnu.org/licenses/>.
  20. #include "imagecommandlineparser.hh"
  21. #include "outputter.hh"
  22. #include <qwebframe.h>
  23. /*!
  24. \file commandlineparser.hh
  25. \brief Defines the ImageCommandLineParser class
  26. */
  27. /*!
  28. Output the man page to a given file
  29. \param fd The file to store the man page
  30. */
  31. void ImageCommandLineParser::manpage(FILE * fd) const {
  32. Outputter * o = Outputter::man(fd);
  33. outputManName(o);
  34. outputSynopsis(o);
  35. outputDescripton(o);
  36. outputSwitches(o, true, false);
  37. outputContact(o);
  38. outputAuthors(o);
  39. delete o;
  40. }
  41. /*!
  42. Output usage information aka. --help
  43. \param fd The file to output the information to
  44. \param extended Should we show extended arguments
  45. */
  46. void ImageCommandLineParser::usage(FILE * fd, bool extended) const {
  47. Outputter * o = Outputter::text(fd,false);
  48. outputName(o);
  49. outputSynopsis(o);
  50. outputDescripton(o);
  51. outputSwitches(o, extended, false);
  52. if (extended) {
  53. outputProxyDoc(o);
  54. }
  55. outputContact(o);
  56. delete o;
  57. }
  58. /*!
  59. Output the readme/manual
  60. \param fd The file to output to
  61. \param html Do we want the html manaul, or the README
  62. */
  63. void ImageCommandLineParser::readme(FILE * fd, bool html) const {
  64. Outputter * o = html?Outputter::html(fd):Outputter::text(fd, true);
  65. outputDocStart(o);
  66. outputContact(o);
  67. outputLicense(o);
  68. outputAuthors(o);
  69. outputSynopsis(o);
  70. outputSwitches(o, true, true);
  71. outputProxyDoc(o);
  72. outputStaticProblems(o);
  73. outputCompilation(o);
  74. outputInstallation(o);
  75. outputExamples(o);
  76. delete o;
  77. }
  78. /*!
  79. * Load default arguments and put them in the settings structure
  80. */
  81. // void ImageCommandLineParser::loadDefaults() {
  82. // d->settings.in = "-";
  83. // d->settings.proxy.host = "";
  84. // foreach (ArgHandler * h, d->longToHandler)
  85. // h->useDefault(*d);
  86. // //Load configuration from enviornment
  87. // char * val;
  88. // const char * vars[] = {"proxy","all_proxy","http_proxy", NULL};
  89. // for (int i=0; vars[i]; ++i) {
  90. // if ((val = getenv("proxy"))) {
  91. // bool ok=false;
  92. // Settings::ProxySettings p = Settings::strToProxy(val, &ok);
  93. // if (ok)
  94. // d->settings.proxy = p;
  95. // }
  96. // }
  97. // }
  98. /*!
  99. * Parse command line arguments, and set settings accordingly.
  100. * \param argc the number of command line arguments
  101. * \param argv a NULL terminated list with the arguments
  102. */
  103. void ImageCommandLineParser::parseArguments(int argc, const char ** argv, bool final) {
  104. settings.in="";
  105. settings.out="";
  106. bool defaultMode=false;
  107. for (int i=1; i < argc; ++i) {
  108. if (i==argc-2 && (argv[i][0] != '-' || argv[i][1] == '\0')) { // the arg before last (in)
  109. settings.in = argv[i];
  110. } else if (i==argc-1 && (argv[i][0] != '-' || argv[i][1] == '\0')) { // the last arg (out)
  111. settings.out = argv[i];
  112. } else {
  113. parseArg(global, argc, argv, defaultMode, i, 0);
  114. }
  115. }
  116. if (final || settings.in=="" || settings.out=="") {
  117. fprintf(stderr, "You need to specify at least one input file, and exactly one output file\nUse - for stdin or stdout\n\n");
  118. usage(stderr, false);
  119. exit(1);
  120. }
  121. }