source: wkhtmltox/trunk/fuentes/src/image/imagecommandlineparser.cc @ 51

Last change on this file since 51 was 51, checked in by mabarracus, 4 years ago

wip

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