summaryrefslogtreecommitdiff
path: root/support/highlight/src/cli/cmdlineoptions.h
blob: c4cbe26b6d6a7e0e82a32739f9fab960f9dc1791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/***************************************************************************
                          cmdlineoptions.h  -  description
                             -------------------
    begin                : Sun Nov 25 2001
    copyright            : (C) 2001-2007 by Andre Simon
    email                : andre.simon1@gmx.de
 ***************************************************************************/


/*
This file is part of Highlight.

Highlight is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Highlight is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Highlight.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef CMDLINEOPTIONS_H
#define CMDLINEOPTIONS_H

#ifdef _WIN32
#include <windows.h>
#endif

#include <string>
#include <map>
#include <set>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>

#include "stringtools.h"
#include "enums.h"


#define OPT_ADDCONFDIR     "add-config-dir"
#define OPT_ADDDATADIR     "add-data-dir"
#define OPT_ANCHORS        "anchors"
#define OPT_ANCHOR_FN      "anchor-filename"
#define OPT_ANCHOR_PFX     "anchor-prefix"
#define OPT_ANSI           "ansi"
#define OPT_BABEL          "babel"
#define OPT_BASE_FONT      "font"
#define OPT_BASE_FONT_SIZE "font-size"
#define OPT_BATCHREC       "batch-recursive"
#define OPT_CLASSNAME      "class-name"
#define OPT_DATADIR        "data-dir"
#define OPT_DELTABS        "replace-tabs"
#define OPT_DOC_TITLE      "doc-title"
#define OPT_ENCLOSE_PRE    "enclose-pre"
#define OPT_ENCODING       "encoding"
#define OPT_FILLZEROES     "zeroes"
#define OPT_FORCE_OUTPUT   "force"
#define OPT_FORMAT         "reformat"
#define OPT_FRAGMENT       "fragment"
#define OPT_HELP           "help"
#define OPT_HTML           "html"
#define OPT_IN             "input"
#define OPT_INC_STYLE      "include-style"
#define OPT_INDEXFILE      "print-index"
#define OPT_INLINE_CSS     "inline-css"
#define OPT_KW_CASE        "kw-case"
#define OPT_LATEX          "latex"
#define OPT_LINENO         "linenumbers"
#define OPT_LINE_LEN       "line-length"
#define OPT_LISTLANGS      "list-langs"
#define OPT_LISTTHEMES     "list-themes"
#define OPT_LNR_LEN        "line-number-length"
#define OPT_LNR_START      "line-number-start"
#define OPT_MARK_LINES     "mark-line"
#define OPT_ORDERED_LIST   "ordered-list"
#define OPT_OUT            "output"
#define OPT_OUTDIR         "outdir"
#define OPT_RTF_PAGE_SIZE  "page-size"
#define OPT_RTF_CHAR_STYLES "char-styles"
#define OPT_PRINT_CONFIG   "print-config"
#define OPT_PROGRESSBAR    "progress"
#define OPT_QUIET          "quiet"
#define OPT_REPLACE_QUOTES "replace-quotes"
#define OPT_RTF            "rtf"
#define OPT_STYLE          "style"
#define OPT_STYLE_IN       "style-infile"
#define OPT_STYLE_OUT      "style-outfile"
#define OPT_SYNTAX         "syntax"
#define OPT_TEST_INPUT     "validate-input"
#define OPT_TEX            "tex"
#define OPT_VERBOSE        "verbose"
#define OPT_VERSION        "version"
#define OPT_WRAP           "wrap"
#define OPT_WRAPSIMPLE     "wrap-simple"
#define OPT_XHTML          "xhtml"
#define OPT_XML            "xml"
#define OPT_XTERM256       "xterm256"
#define OPT_SVG            "svg"
#define OPT_SVG_WIDTH      "width"
#define OPT_SVG_HEIGHT     "height"
#define OPT_SKIP_UNKNOWN   "skip"
#define OPT_CTAGS_FILE     "ctags-file"
#define OPT_PRETTY_SYMBOLS "pretty-symbols"
#define OPT_EOL_DELIM_CR   "delim-cr"
#define OPT_BBCODE         "bbcode"
#define OPT_START_NESTED   "start-nested"
#define OPT_PRINT_STYLE    "print-style"
#define OPT_NO_TRAILING_NL "no-trailing-nl"

// Improve CLI option compatibility with GNU source-highlight
#define OPT_COMPAT_DOC       "doc"
#define OPT_COMPAT_NODOC     "no-doc"
#define OPT_COMPAT_TAB       "tab"
#define OPT_COMPAT_CSS       "css"
#define OPT_COMPAT_OUTDIR    "output-dir"
#define OPT_COMPAT_FAILSAFE  "failsafe"
#define OPT_COMPAT_OUTFORMAT "out-format"
#define OPT_COMPAT_SRCLANG   "src-lang"
#define OPT_COMPAT_LINENUM   "line-number"
#define OPT_COMPAT_LINEREF   "line-number-ref"

using namespace std;

/// handle command line options

class CmdLineOptions
{
	public:

		/**Constructor
		 \param argc Argument count
		 \param argv Argument strings
		*/
		CmdLineOptions ( const int argc, const char *argv[] );
		~CmdLineOptions();

		/** \return Single output file name*/
		const string &getSingleOutFilename();

		/** \return Single input file name*/
		const string &getSingleInFilename() const;

		/** \return Output directory*/
		const string& getOutDirectory() ;

		/** \return Style output file name*/
		const string getStyleOutFilename() const;

		/** \return Style input file name*/
		const string& getStyleInFilename() const;

		/** \return Char set*/
		const string& getEncoding() const;

		/** \return SVG width*/
		const string& getSVGWidth() const;

		/** \return SVG height*/
		const string& getSVGHeight() const;

		/** \return Number of spaces to replace a tab*/
		int getNumberSpaces() const;

		/** \return True if version information should be printed*/
		bool printVersion() const;

		/** \return True if help information should be printed*/
		bool printHelp() const;

		/** \return True if debug information should be printed*/
		bool printDebugInfo() const;

		/** \return True if configuration information should be printed*/
		bool printConfigInfo() const;

		/** \return True if Style definition should be included in output*/
		bool includeStyleDef() const;

		/** \return True if line numbers should be printed*/
		bool printLineNumbers() const;

		/** \return True if CR is eol delimiter */
		bool useCRDelimiter() const;

		/** \return colour theme name */
		string getThemeName() const ;

		/** gibt true zurck, falls deutsche Hilfe ausgegeben werden soll */
		int helpLanguage() const;

		/** \return True if batch mode is active*/
		bool enableBatchMode() const;

		/** \return True if output shluld be fragmented*/
		bool fragmentOutput() const;

		/** \return output file suffix */
		string getOutFileSuffix() const;

		/** \return True if anchors should be attached to line numbers*/
		bool attachLineAnchors() const;

		/** \return True if list of installed themes should be printed*/
		bool showThemes() const;

		/** \return True if list of installed language definitions should be printed*/
		bool showLangdefs() const;

		/** \return True if loutput directory is given*/
		bool outDirGiven() const;

		/** \return True if refomatting is enabled*/
//    bool formattingEnabled();

		/** \return True if a new data directory is given*/
		bool dataDirGiven() const;

		/** \return True if an additional data directory is given*/
		bool additionalDataDirGiven() const;

		/** \return True if index file should be printed*/
		bool printIndexFile() const;

		/** \return True if quotes should be replaced by /dq in LaTeX*/
		bool replaceQuotes() const;

		/** \return True if shorthands of LaTeX Babel package should be disabled*/
		bool disableBabelShorthands() const;

		/** \return True if input file name should be used as anchor name */
		bool useFNamesAsAnchors() const;

		/** \return Data directory*/
		const string &getDataDir() const;

		/** \return Additional data directory*/
		const string &getAdditionalDataDir() const;

		/** \return Additional config data directory*/
		const string &getAdditionalConfDir() const;

		/** \return  path of user config file*/
		const string &getConfigFilePath() const;

		/** \return True if language syntax is given*/
		bool syntaxGiven() const;

		/** \return True if quiet mode is active*/
		bool quietMode() const;

		/** \return True if progress bar should be printed in batch mode */
		bool printProgress() const;

		/** \return True if line numbers are filled with leading zeroes */
		bool fillLineNrZeroes() const;

		/** \return programming syntax */
		const string &getLanguage() const ;

		/** \return Wrapping style*/
		highlight::WrapMode getWrappingStyle() const;

		/** \return List of input file names*/
		const vector <string> & getInputFileNames() const;

		/** \return Map of marked lines*/
		const map <int,string> &getMarkLines();

		/** \return indentation and reformatting scheme*/
		string getIndentScheme() const;

		/** \return RTF page size */
		const string &getPageSize() const;

		/** \return Output file format */
		highlight::OutputType getOutputType() const;

		/** \return True if chosen output format supports referenced style files */
		bool formatSupportsExtStyle();

		/** \return True if style output path was defined by user*/
		bool styleOutPathDefined() const
		{
			return opt_stylepath_explicit;
		}

		/** \return True if encoding specification should be omitted in output*/
		bool omitEncoding() const;

		/** \return True if output should be generated if languege type is unknown*/
		bool forceOutput() const;

		/** \return True if line numbers should be replaced by ordered list (HTML) */
		bool orderedList() const;

		/** \return True if a base font has been given */
		bool hasBaseFont() const ;

		/** \return True if input should be validated */
		bool validateInput() const ;

		/** \return True if CSS should be outputted within tag elements */
		bool inlineCSS() const ;

		/** \return True if fragmented html output should be enclosed with pre tags */
		bool enclosePreTag() const ;

		/** \return True if RTF output should include character styles */
		bool includeCharStyles() const ;

		/** \return True if LaTeX output should includ fancier symbols */
		bool prettySymbols() const;

		/** \return True if style should be printed */
		bool printOnlyStyle() const;

		/** \return The given base font, empty string by default */
		const string& getBaseFont() const ;

		/** \return Document title */
		const string& getDocumentTitle() const ;

		/** \return anchor prefix */
		const string& getAnchorPrefix() const ;

		/** \return class name */
		const string& getClassName() const ;

		/** \return ctags file name */
		const string& getTagsFile() const ;

		/** \return True if a base font size has been given */
		bool hasBaseFontSize() const ;
		
		/** \return True if trailing nl should be omitted */
		bool disableTrailingNL() const ;

		/** \return The given base font size, empty string by default */
		const string& getBaseFontSize() const ;

		/** \return name of nested syntax which starts the input */
		const string& getStartNestedLang() const ;

		/** \return line number width */
		int getNumberWidth();

		/** \return line length */
		int getLineLength();

		/** \return Line number start count */
		int getNumberStart();

		/** \return Keyword Case (upper, lower, unchanged) */
		StringTools::KeywordCase getKeywordCase() const;

		bool isSkippedExt ( const string& ext )
		{
			return ignoredFileTypes.count ( ext );
		}

	private:

		int numberSpaces;   // number of spaces which replace a tab
		int lineNrWidth;    // width of line number (left padding)
		int lineLength;    // length of line before wrapping
		int lineNrStart;    // line number start count
		highlight::WrapMode wrappingStyle; // line wrapping mode
		highlight::OutputType outputType;
		StringTools::KeywordCase keywordCase;

		// name of single output file
		string outFilename,
		// output directory
		outDirectory,
		// programming syntax which will be loaded
		syntax,
		// name of colour theme
		styleName,
		// name of external style file
		styleOutFilename,
		// name of file to be included in external style file
		styleInFilename,
		// used to define data directories at runtime
		dataDir, additionalDataDir, additionalConfigDir;
		// name of indenation scheme
		string indentScheme,
		pageSize, startNestedLang;

		string baseFont, baseFontSize;
		string docTitle, className;
		string markLinesArg;
		string skipArg;
		string svg_height, svg_width;
		string ctagsFile;

		bool opt_syntax;
		bool opt_include_style;
		bool opt_help;
		bool opt_version ;
		bool opt_verbose;
		bool opt_print_config;
		bool opt_linenumbers;
		bool opt_style;
		bool opt_batch_mode;
		bool opt_fragment;
		bool opt_attach_line_anchors;
		bool opt_show_themes;
		bool opt_show_langdefs;
		bool opt_asformat_output;
		bool opt_printindex;
		bool opt_quiet;
		bool opt_replacequotes;
		bool opt_babel;
		bool opt_print_progress;
		bool opt_fill_zeroes;
		bool opt_stylepath_explicit;
		bool opt_force_output;
		bool opt_ordered_list;
		bool opt_fnames_as_anchors;
		bool opt_validate;
		bool opt_inline_css;
		bool opt_enclose_pre;
		bool opt_char_styles;
		bool opt_pretty_symbols;
		bool opt_delim_CR;
		bool opt_print_style;
		bool opt_no_trailing_nl;

		bool configFileRead;

		string anchorPrefix;

		string helpLang, encodingName;
		string configFilePath;

		/** list of all input file names */
		vector <string> inputFileNames;

		/** list lines which should be marked and supplied with help string */
		map <int, string> markLines;

		/** list of file types which should be ignored */
		set <string> ignoredFileTypes;

		/** load highlight configuration file */
		void loadConfigurationFile();

		/** \return file suffix */
		string getFileSuffix ( const string & fileName ) const;

		/** \return directory name of path */
		string getDirName ( const string & path );

		/** get all entries in the directory defined by wildcard */
		void readDirectory ( const string & wildcard );

		/** \return Boolean value of paramVal */
		bool getFlag ( const string& paramVal );

		/** \return Valid path name */
		string validateDirPath ( const string & path );
};

#endif