1 //@copyright_begin
2 // ================================================================
3 // Copyright Notice
4 // Copyright (C) 1998-2004 by Joe Linoff
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 // IN NO EVENT SHALL JOE LINOFF BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 // OTHER DEALINGS IN THE SOFTWARE.
24 //
25 // Comments and suggestions are always welcome.
26 // Please report bugs to http://ccdoc.sourceforge.net/ccdoc
27 // ================================================================
28 //@copyright_end
29 
30 // MULTIPLE INCLUSION GUARD
31 #ifndef ccdoc_switches_h
32 #define ccdoc_switches_h
33 
34 /**
35  * This variable allows the header version
36  * to be queried at runtime.
37  */
38 namespace {
39    char ccdoc_switches_h_rcsid[] = "$Id: switches.h,v 1.10 2004/09/30 04:16:07 jlinoff Exp $";
40 }
41 
42 #include "exceptions.h"
43 #include "log.h"
44 #include <string>
45 #include <vector>
46 #include <map>
47 #include <set>
48 #include <algorithm>
49 
50 using namespace std;
51 
52 namespace ccdoc {
53   /**
54    * Command line switch processor.
55    * @author Joe Linoff
56    * @version $Id: switches.h,v 1.10 2004/09/30 04:16:07 jlinoff Exp $
57    */
58   class switches {
59   public:
60     typedef map<string,string,less<string> > defines_type;
61     typedef set<string,less<string> > undefines_type;
62     typedef vector<string> files_type;
63   public:
64     /**
65      * Constructor.
66      * @param argc The number of switches.
67      * @param argv The array of switch values.
68      */
69     switches(int argc,char** argv);
70     /**
71      * Destructor.
72      */
73     ~switches();
74   private:
75     /**
76      * Make the default constructor private
77      * so that it is not inadvertently used.
78      */
79     switches();
80     /**
81      * Make the copy constructor private
82      * so that it is not inadvertently used.
83      */
84     switches(const switches&);
85   public:
86     /**
87      * Are the switches ok?
88      * @returns True if they are ok or false otherwise.
89      */
ok()90     bool ok() const {return m_ok;}
91   public:
92     /**
93      * Get the program name.
94      * @returns The program name.
95      */
program_name()96     string program_name() const {return m_program_name;}
97     /**
98      * Display the help message.
99      */
100     void help() const;
101   public:
102     /**
103      * Was the verbose switch specified?
104      * @returns True if verbose mode was specified or false otherwise.
105      */
verbose()106     bool verbose() const {return m_verbose;}
107     /**
108      * Was the verbose format switch specified?
109      * @returns True if verbose format mode was specified or false otherwise.
110      */
verbose_format()111     bool verbose_format() const {return m_verbose_format;}
112     /**
113      * Was the index switch specified?
114      * If it was, phase 2 is enabled.
115      * @returns True if -index was specified or false otherwise.
116      */
index()117     bool index() const {return m_index;}
118     /**
119      * Get the name of the specified database.
120      * @returns The database name.
121      */
db()122     const string& db() const {return m_db;}
123     /**
124      * Get the package name for this run.
125      * The existence of a package name indicates that
126      * that phase 1 is enabled.
127      * @returns The package name.
128      */
pkg()129     const string& pkg() const {return m_pkg;}
130     /**
131      * Get the HTML output directory for this run.
132      * The existence of the HTML output directory indicates that
133      * that phase 3 is enabled.
134      * @returns The HTML output directory.
135      */
html()136     const string& html() const {return m_html;}
137     /**
138      * Get the default root package name.
139      * This name never changes. It is used internally.
140      * @returns The default root package name for the database.
141      */
default_root()142     const string& default_root() const {return m_default_root;}
143     /**
144      * Get the root package name.
145      * @returns The root package name for the database.
146      */
root()147     const string& root() const {return m_root;}
148     /**
149      * Get the root package file name.
150      * @returns The root package name for the database.
151      */
rootfile()152     const string& rootfile() const {return m_rootfile;}
153     /**
154      * Get the URL of the parent of the root package.
155      * @returns The URL.
156      */
rooturl()157     const string& rooturl() const {return m_rooturl;}
158     /**
159      * Get the -header file name.
160      * @returns The -header file name.
161      */
header()162     const string& header() const {return m_header;}
163     /**
164      * Get the -meta file name.
165      * @returns The -meta file name.
166      */
meta()167     const string& meta() const {return m_meta;}
168     /**
169      * Get the -trailer file name.
170      * @returns The -trailer file name.
171      */
trailer()172     const string& trailer() const {return m_trailer;}
173     /**
174      * Get the -bg color name.
175      * @returns The -bg color name.
176      */
bgcolor()177     const string& bgcolor() const {return m_bgcolor;}
178     /**
179      * Get the -fgtext color name.
180      * @returns The -fgtext color name.
181      */
fgtextcolor()182     const string& fgtextcolor() const {return m_fgtextcolor;}
183     /**
184      * Get the -fglink color name.
185      * @returns The -fglink color name.
186      */
fglinkcolor()187     const string& fglinkcolor() const {return m_fglinkcolor;}
188     /**
189      * Get the -fgvlink color name.
190      * @returns The -fgvlink color name.
191      */
fgvlinkcolor()192     const string& fgvlinkcolor() const {return m_fgvlinkcolor;}
193     /**
194      * Get the -srcurl (or -sourceurl) path name.
195      * @returns The source url.
196      */
srcurl()197     const string& srcurl() const {return m_srcurl;}
198     /**
199      * Get the -imgurl (or -imageurl) path name.
200      * This is not used in this version.
201      * @returns The image url.
202      */
imgurl()203     const string& imgurl() const {return m_imgurl;}
204     /**
205      * Do the file paths contains backslashes that
206      * need to be converted (-dospaths).
207      * This must be determined at run-time because
208      * dospaths are not needed for users that run
209      * under unix shells.
210      */
dospaths()211     bool dospaths() const {return m_dospaths;}
212     /**
213      * Report whether the user specified -cdsm or -nocdsm on the
214      * command line.
215      */
cdsm()216     bool cdsm() const {return m_cdsm;}
217     /**
218      *  Report whether the user specified -tcms or -notcms on the
219      * command line.
220      * @since v08r33
221      */
tcms()222     bool tcms() const {return m_tcms;}
223     /**
224      * Report whether the user specified -rptmac1 or -norptmac1 on the
225      * command line.
226      * @since v08r34
227      */
rptmac1()228     bool rptmac1() const {return m_rptmac1;}
229   public:
230     /**
231      * Get the program version.
232      * @returns The program version.
233      */
version()234     const string& version() const {return m_version;}
235   public:
236     /**
237      * Load the defines map.
238      * Each define has a value.
239      * @param out The map to update.
240      */
241     void defines( defines_type& out ) const;
242     /**
243      * Load the undefines set.
244      * @param out The set to update.
245      */
246     void undefines( undefines_type& out ) const;
247     /**
248      * Load the files vector.
249      * @param out The files vector to update.
250      */
files(files_type & out)251     void files( files_type& out ) const {out = m_files;}
252     /**
253      * Return the number of files.
254      * @returns The number of files.
255      */
num_files()256     size_t num_files() const {return m_files.size();}
257     /**
258      * Returns the maximum file name size.
259      */
maxpathlen()260     unsigned maxpathlen() const {return m_maxpathlen;}
261   public:
262     /**
263      * Report the comments for undocumented namespaces.
264      * @returns True for -rptcfuns or false for -norptcfuns.
265      */
rptcfuns()266     bool rptcfuns() const {return m_rptcfuns;}
267     /**
268      * Report the class summary details.
269      * @returns True for -rptcsd or false for -norptcsd.
270      */
rptcsd()271     bool rptcsd() const {return m_rptcsd;}
272     /**
273      * Define the class summary indent level for the report.
274      * @returns The class summary indent level. The default is 4.
275      */
rptcsi()276     unsigned rptcsi() const {return m_rptcsi;}
277     /**
278      * Report the default package author as unascribed?
279      * @returns True for -rptdpa or false for -norptdpa.
280      */
rptdpa()281     bool rptdpa() const {return m_rptdpa;}
282     /**
283      * Report the default package description as unknown?
284      * @returns True for -rptdpd or false for -norptdpd.
285      */
rptdpd()286     bool rptdpd() const {return m_rptdpd;}
287     /**
288      * Report the default package version as unknown?
289      * @returns True for -rptdpv or false for -norptdpv.
290      */
rptdpv()291     bool rptdpv() const {return m_rptdpv;}
rpthpc()292     bool rpthpc() const {return m_rpthpc;}
rptim()293     bool rptim() const {return m_rptim;}
rptmac()294     bool rptmac() const {return m_rptmac;}
rptpri()295     bool rptpri() const {return m_rptpri;}
rptpro()296     bool rptpro() const {return m_rptpro;}
rptpub()297     bool rptpub() const {return m_rptpub;}
rpttyp()298     bool rpttyp() const {return m_rpttyp;}
rptun()299     bool rptun() const {return m_rptun;}
300     /**
301      * Report the code section using a fixed with font.
302      * @returns True if the code section should use a
303      * a fixed width font or false otherwise. The
304      * default is false.
305      */
rptfwcf()306     bool rptfwcf() const {return m_rptfwcf;}
307   public:
308     /**
309      * Get the default author string.
310      * The default value is "unascribed".
311      * @returns The default author string.
312      */
rptdefa()313     const char* rptdefa() const {return m_rptdefa.c_str();}
314     /**
315      * Get the default automatic short description string.
316      * The default value is "automatically generated".
317      * @returns The default automatic short description string.
318      */
rptdefasd()319     const char* rptdefasd() const {return m_rptdefasd.c_str();}
320     /**
321      * Get the default short description string.
322      * The default value is "undocumented".
323      * @returns The default short description string.
324      */
rptdefsd()325     const char* rptdefsd() const {return m_rptdefsd.c_str();}
326     /**
327      * Get the default version string.
328      * The default value is "unknown".
329      * @returns The default version string.
330      */
rptdefv()331     const char* rptdefv() const {return m_rptdefv.c_str();}
332   public:
333     /**
334      * Get the content type charset (issue 0074).
335      * The default value is "iso-8859-1". This field
336      * is required for HTML compliance.
337      * @returns The content-type charset.
338      */
rptctcs()339     const char* rptctcs() const {return m_rptctcs.c_str();}
340   public:
341     /**
342      * Sort class information (issue 0072). The default is true. If this
343      * flag is false, the class contents and details are not
344      * sorted.
345      * @returns The sort flag.
346      */
rptsci()347     bool rptsci() const {return m_rptsci;}
348   public:
349     /**
350      * Report source information in the contents table.
351      * @returns The flag.
352      */
rptsrc()353     bool rptsrc() const {return m_rptsrc;}
354   public:
355     /**
356      * Get the maximum length of the contents id.
357      * @returns The maximum length of the contents id.
358      */
rptmlcei()359     unsigned rptmlcei() const {return m_rptmlcei;}
360     /**
361      * Get the maximum length of the contents inherited from id.
362      * @returns The maximum length of the contents id.
363      */
rptmlcifi()364     unsigned rptmlcifi() const {return m_rptmlcifi;}
365   public:
366     /**
367      * Enable javadoc short description syntax (-[no]jdsds, issue 0082).
368      *
369      * That is, terminate the short description when a period is found that
370      * is followed by a space, tab, newline or other directive. Blank lines
371      * are ignored.
372      *
373      * If this mode is not specified, the old ccdoc style for determining
374      * short descriptions is used. Ccdoc parses until it finds a blank line
375      * and uses that to determine that a short description has been found.
376      * @returns True for -jdsds or false for -nojdsds. The default is -jdsds.
377      * @since r24
378      */
jdsds()379     bool jdsds() const {return m_jdsds;}
380   public:
381     /**
382      * Doxygen compatibility mode (-[no]doxygen).
383      * This provides limited support for commonly used doxygen
384      * directives.
385      * @returns whether doxygen support is enabled.
386      */
doxygen()387     bool doxygen() const {return m_doxygen;}
388   private:
389     bool get_arg(const char* sw,string& str,int& i,int argc,char** argv);
390     void load_file(const string& file);
391     void load_files(const string& file,const char* prefix=0);
392     void putenv(string&) const;
393   private:
394     bool m_jdsds;
395     bool m_cdsm;
396     bool m_tcms;
397     bool m_dospaths;
398     bool m_ok;
399     bool m_doxygen;
400     bool m_help;
401     bool m_verbose;
402     bool m_verbose_format;
403     bool m_index;
404     bool m_rptcfuns;
405     bool m_rptcsd;
406     unsigned m_rptcsi;
407     bool m_rptdpa;
408     bool m_rptdpd;
409     bool m_rptdpv;
410     bool m_rptfwcf;
411     bool m_rpthpc;
412     bool m_rptim;
413     bool m_rptmac;
414     bool m_rptmac1;
415     bool m_rptpri;
416     bool m_rptpro;
417     bool m_rptpub;
418     bool m_rptsci;
419     bool m_rpttyp;
420     bool m_rptun;
421     bool m_rptsrc;
422     string m_rptdefa;
423     string m_rptdefasd;
424     string m_rptdefsd;
425     string m_rptdefv;
426     string m_rptctcs;
427     unsigned m_maxpathlen;
428     vector<string> m_switches;
429     string m_default_root;
430     string m_program_name;
431     string m_db;
432     string m_pkg;
433     string m_html;
434     string m_header;
435     string m_imgurl;
436     string m_meta;
437     string m_trailer;
438     string m_root;
439     string m_rootfile;
440     string m_rooturl;
441     string m_bgcolor;
442     string m_fgtextcolor;
443     string m_fglinkcolor;
444     string m_fgvlinkcolor;
445     string m_srcurl;
446     string m_version;
447     unsigned m_rptmlcei;
448     unsigned m_rptmlcifi;
449     defines_type m_defines;
450     undefines_type m_undefines;
451     files_type m_files;
452   };
453 };
454 
455 #endif
456