"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/cli/cmdlineoptions.h" (12 May 2020, 16844 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "cmdlineoptions.h": 3.56_vs_3.57.

    1 /***************************************************************************
    2                           cmdlineoptions.h  -  description
    3                              -------------------
    4     begin                : Sun Nov 25 2001
    5     copyright            : (C) 2001-2017 by Andre Simon
    6     email                : a.simon@mailbox.org
    7  ***************************************************************************/
    8 
    9 
   10 /*
   11 This file is part of Highlight.
   12 
   13 Highlight is free software: you can redistribute it and/or modify
   14 it under the terms of the GNU General Public License as published by
   15 the Free Software Foundation, either version 3 of the License, or
   16 (at your option) any later version.
   17 
   18 Highlight is distributed in the hope that it will be useful,
   19 but WITHOUT ANY WARRANTY; without even the implied warranty of
   20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   21 GNU General Public License for more details.
   22 
   23 You should have received a copy of the GNU General Public License
   24 along with Highlight.  If not, see <http://www.gnu.org/licenses/>.
   25 */
   26 
   27 
   28 #ifndef CMDLINEOPTIONS_H
   29 #define CMDLINEOPTIONS_H
   30 
   31 #ifdef _WIN32
   32 #include <windows.h>
   33 #endif
   34 
   35 #include <string>
   36 #include <map>
   37 #include <set>
   38 #include <cstdlib>
   39 #include <iostream>
   40 #include <fstream>
   41 #include <vector>
   42 
   43 #include "stringtools.h"
   44 #include "enums.h"
   45 
   46 #define OPT_OUTFORMAT      "out-format"
   47 #define OPT_ANCHORS        "anchors"
   48 #define OPT_ANCHOR_FN      "anchor-filename"
   49 #define OPT_ANCHOR_PFX     "anchor-prefix"
   50 #define OPT_LATEX_BABEL    "babel"
   51 #define OPT_LATEX_BEAMER   "beamer"
   52 #define OPT_BASE_FONT      "font"
   53 #define OPT_BASE_FONT_SIZE "font-size"
   54 #define OPT_BATCHREC       "batch-recursive"
   55 #define OPT_CLASSNAME      "class-name"
   56 #define OPT_DATADIR        "data-dir"
   57 #define OPT_DELTABS        "replace-tabs"
   58 #define OPT_DOC_TITLE      "doc-title"
   59 #define OPT_ENCLOSE_PRE    "enclose-pre"
   60 #define OPT_ENCODING       "encoding"
   61 #define OPT_FILLZEROES     "zeroes"
   62 #define OPT_FORCE_OUTPUT   "force"
   63 #define OPT_FORMAT         "reformat"
   64 #define OPT_FRAGMENT       "fragment"
   65 #define OPT_HELP           "help"
   66 #define OPT_IN             "input"
   67 #define OPT_INC_STYLE      "include-style"
   68 #define OPT_INDEXFILE      "print-index"
   69 #define OPT_INLINE_CSS     "inline-css"
   70 #define OPT_KW_CASE        "kw-case"
   71 #define OPT_LINENO         "line-numbers"
   72 #define OPT_LINE_LEN       "line-length"
   73 #define OPT_LIST_SCRIPTS   "list-scripts"
   74 #define OPT_LNR_LEN        "line-number-length"
   75 #define OPT_LNR_START      "line-number-start"
   76 #define OPT_ORDERED_LIST   "ordered-list"
   77 #define OPT_OUT            "output"
   78 #define OPT_OUTDIR         "outdir"
   79 #define OPT_RTF_PAGE_SIZE  "page-size"
   80 #define OPT_RTF_CHAR_STYLES "char-styles"
   81 #define OPT_RTF_PAGE_COLOR "page-color"
   82 #define OPT_PRINT_CONFIG   "print-config"
   83 #define OPT_PROGRESSBAR    "progress"
   84 #define OPT_QUIET          "quiet"
   85 #define OPT_REPLACE_QUOTES "replace-quotes"
   86 #define OPT_STYLE          "style"
   87 #define OPT_STYLE_IN       "style-infile"
   88 #define OPT_STYLE_OUT      "style-outfile"
   89 #define OPT_SYNTAX         "syntax"
   90 #define OPT_TEST_INPUT     "validate-input"
   91 #define OPT_VERBOSE        "verbose"
   92 #define OPT_VERSION        "version"
   93 #define OPT_WRAP           "wrap"
   94 #define OPT_WRAPSIMPLE     "wrap-simple"
   95 #define OPT_SVG_WIDTH      "width"
   96 #define OPT_SVG_HEIGHT     "height"
   97 #define OPT_SKIP_UNKNOWN   "skip"
   98 #define OPT_PRETTY_SYMBOLS "pretty-symbols"
   99 #define OPT_EOL_DELIM_CR   "delim-cr"
  100 #define OPT_START_NESTED   "start-nested"
  101 #define OPT_PRINT_STYLE    "print-style"
  102 #define OPT_NO_TRAILING_NL "no-trailing-nl"
  103 #define OPT_PLUGIN         "plug-in"
  104 #define OPT_ABS_CFG_PATH   "config-file"
  105 #define OPT_PLUGIN_READFILE  "plug-in-read"
  106 #define OPT_PLUGIN_PARAMETER "plug-in-param"
  107 #define OPT_NO_NUMBER_WL     "wrap-no-numbers"
  108 #define OPT_KEEP_INJECTIONS  "keep-injections"
  109 #define OPT_FORCE_STDOUT     "stdout"
  110 #define OPT_NO_VERSION_INFO  "no-version-info"
  111 #define OPT_CANVAS           "canvas"
  112 #define OPT_REFORMAT_OPT     "reformat-option"
  113 #define OPT_RANGE_OPT        "line-range"
  114 #define OPT_BASE16           "base16"
  115 #define OPT_CATEGORIES       "list-cat"  
  116 #define OPT_PIPED_FNAME      "syntax-by-name"
  117 #define OPT_ISOLATE_TAGS     "isolate"
  118 #define OPT_MAX_FILE_SIZE    "max-size"
  119 
  120 // Improve CLI option compatibility with GNU source-highlight
  121 #define OPT_COMPAT_DOC       "doc"
  122 #define OPT_COMPAT_NODOC     "no-doc"
  123 #define OPT_COMPAT_TAB       "tab"
  124 #define OPT_COMPAT_CSS       "css"
  125 #define OPT_COMPAT_OUTDIR    "output-dir"
  126 #define OPT_COMPAT_FAILSAFE  "failsafe"
  127 #define OPT_COMPAT_SRCLANG   "src-lang"
  128 #define OPT_COMPAT_LINENUM   "line-number"
  129 #define OPT_COMPAT_LINEREF   "line-number-ref"
  130 
  131 using namespace std;
  132 
  133 /// handle command line options
  134 
  135 class CmdLineOptions
  136 {
  137 public:
  138 
  139     /**Constructor
  140      \param argc Argument count
  141      \param argv Argument strings
  142     */
  143     CmdLineOptions ( const int argc, const char *argv[] );
  144     ~CmdLineOptions();
  145 
  146     /** \return Single output file name*/
  147     const string &getSingleOutFilename();
  148 
  149     /** \return Single input file name*/
  150     const string &getSingleInFilename() const;
  151 
  152     /** \return Output directory*/
  153     const string& getOutDirectory() ;
  154 
  155     /** \return Style output file name*/
  156     const string getStyleOutFilename() const;
  157 
  158     /** \return Style input file name*/
  159     const string& getStyleInFilename() const;
  160 
  161     /** \return Char set*/
  162     const string& getEncoding() const;
  163 
  164     /** \return SVG width*/
  165     const string& getSVGWidth() const;
  166 
  167     /** \return SVG height*/
  168     const string& getSVGHeight() const;
  169     
  170     /** \return Number of spaces to replace a tab*/
  171     int getNumberSpaces() const;
  172 
  173     /** \return True if version information should be printed*/
  174     bool printVersion() const;
  175 
  176     /** \return True if help information should be printed*/
  177     bool printHelp() const;
  178 
  179     /** \return True if debug information should be printed*/
  180     bool printDebugInfo() const;
  181 
  182     /** \return True if configuration information should be printed*/
  183     bool printConfigInfo() const;
  184 
  185     /** \return True if Style definition should be included in output*/
  186     bool includeStyleDef() const;
  187 
  188     /** \return True if line numbers should be printed*/
  189     bool printLineNumbers() const;
  190 
  191     /** \return True if CR is eol delimiter */
  192     bool useCRDelimiter() const;
  193 
  194     /** \return colour theme name */
  195     string getThemeName() const ;
  196 
  197     /** gibt true zurck, falls deutsche Hilfe ausgegeben werden soll */
  198     int helpLanguage() const;
  199 
  200     /** \return True if batch mode is active*/
  201     bool enableBatchMode() const;
  202 
  203     /** \return True if output shluld be fragmented*/
  204     bool fragmentOutput() const;
  205 
  206     /** \return output file suffix */
  207     string getOutFileSuffix() const;
  208 
  209     /** \return True if anchors should be attached to line numbers*/
  210     bool attachLineAnchors() const;
  211 
  212     /** \return True if loutput directory is given*/
  213     bool outDirGiven() const;
  214 
  215     /** \return True if a new data directory is given*/
  216     bool dataDirGiven() const;
  217 
  218     /** \return True if index file should be printed*/
  219     bool printIndexFile() const;
  220 
  221     /** \return True if quotes should be replaced by /dq in LaTeX*/
  222     bool replaceQuotes() const;
  223 
  224     /** \return True if shorthands of LaTeX Babel package should be disabled*/
  225     bool disableBabelShorthands() const;
  226     
  227     /** \return True if support for the Beamer package should be enabled*/
  228     bool enableBeamerMode() const;
  229 
  230     /** \return True if input file name should be used as anchor name */
  231     bool useFNamesAsAnchors() const;
  232 
  233     /** \return Data directory*/
  234     const string &getDataDir() const;
  235 
  236     /** \return True if language syntax is given*/
  237     bool syntaxGiven() const;
  238 
  239     /** \return True if quiet mode is active*/
  240     bool quietMode() const;
  241 
  242     /** \return True if progress bar should be printed in batch mode */
  243     bool printProgress() const;
  244 
  245     /** \return True if line numbers are filled with leading zeroes */
  246     bool fillLineNrZeroes() const;
  247     
  248     /** \return True if plug-in injections are outputted despite of --fragment */
  249     bool keepInjections() const;
  250 
  251     /** \return True if files should be sent to stdout in batch mode */
  252     bool forceStdout() const;
  253 
  254      /** \return True if output should not contain version info comment */
  255     bool omitVersionInfo() const;
  256     
  257     /** \return programming syntax */
  258     const string &getSyntax() const ;
  259 
  260     /** \return Wrapping style*/
  261     highlight::WrapMode getWrappingStyle() const;
  262 
  263     /** \return List of input file names*/
  264     const vector <string> & getInputFileNames() const;
  265 
  266     /** \return indentation and reformatting scheme*/
  267     string getIndentScheme() const;
  268 
  269     /** \return RTF page size */
  270     const string &getPageSize() const;
  271 
  272     /** \return Output file format */
  273     highlight::OutputType getOutputType() const;
  274 
  275     /** \return True if chosen output format supports referenced style files */
  276     bool formatSupportsExtStyle();
  277 
  278     /** \return True if style output path was defined by user*/
  279     bool styleOutPathDefined() const
  280     {
  281         return opt_stylepath_explicit;
  282     }
  283 
  284     /** \return True if encoding specification should be omitted in output*/
  285     bool omitEncoding() const;
  286 
  287      /** \return True if encoding was set by user*/
  288     bool encodingDefined() const
  289         {
  290         return opt_encoding_explicit;
  291     }
  292    
  293     /** \return True if style was defined by user*/
  294     bool styleDefined() const
  295     {
  296         return !styleName.empty();
  297     }
  298     
  299     /** \return True if output should be generated if language type is unknown*/
  300     bool forceOutput() const;
  301 
  302     /** \return True if line numbers should be replaced by ordered list (HTML) */
  303     bool orderedList() const;
  304 
  305     /** \return True if a base font has been given */
  306     bool hasBaseFont() const ;
  307 
  308     /** \return True if input should be validated */
  309     bool validateInput() const ;
  310 
  311     /** \return True if wrapped lines should get unique numbers */
  312     bool numberWrappedLines() const ;
  313 
  314     /** \return True if CSS should be outputted within tag elements */
  315     bool inlineCSS() const ;
  316 
  317     /** \return True if fragmented html output should be enclosed with pre tags */
  318     bool enclosePreTag() const ;
  319 
  320     /** \return True if RTF output should include character styles */
  321     bool includeCharStyles() const ;
  322 
  323     /** \return True if RTF output should include page color */
  324     bool includePageColor() const ;
  325     
  326     /** \return True if LaTeX output should include fancier symbols */
  327     bool prettySymbols() const;
  328 
  329     /** \return True if style should be printed */
  330     bool printOnlyStyle() const;
  331 
  332     /** \return True if Base16 theme should be used */
  333     bool useBase16Theme() const;
  334 
  335     /** \return True if output token of the same syntax category should be in separate tags */
  336     bool isolateTags() const;
  337     
  338     /** \return max. input file size (default 256 MB) */
  339     off_t getMaxFileSize() const;
  340     
  341     /** \return The given base font, empty string by default */
  342     const string& getBaseFont() const ;
  343 
  344     /** \return Document title */
  345     const string& getDocumentTitle() const ;
  346 
  347     /** \return anchor prefix */
  348     const string& getAnchorPrefix() const ;
  349 
  350     /** \return class name */
  351     const string& getClassName() const ;
  352 
  353     /** \return list of plugin file paths */
  354     const vector <string> &getPluginPaths() const;
  355 
  356     /** \return list of astyle options */
  357     const vector <string> &getAStyleOptions() const;
  358         
  359     /** \return 1 if trailing nl should be omitted, 
  360      *          2 if it should only be omitted for empty input */
  361     int disableTrailingNL() const ;
  362 
  363     /** \return The given base font size, empty string by default */
  364     const string& getBaseFontSize() const ;
  365 
  366     /** \return name of nested syntax which starts the input */
  367     const string& getStartNestedLang() const ;
  368 
  369     /** \return absolute theme definition path name */
  370     const string& getAbsThemePath() const ;
  371 
  372     /** \return absolute language definition path name */
  373     const string& getAbsLangPath() const ;
  374 
  375     /** \return parameter passed to plugin */
  376     const string& getPluginParameter() const ;
  377 
  378     /** \return category to filter scripts of --list-scripts */
  379     const string& getCategories() const ;
  380 
  381     /** \return optional help topic */
  382     const string& getHelpTopic() const;
  383 
  384     /** \return name of the file which will later be redirected to highlight's stdin */
  385     const string& getSyntaxByFilename() const;
  386 
  387     /** \return category of scripts which should be listed */
  388     const string& getListScriptKind() const;
  389     
  390         /** \return fallback syntax if not defined or found by filename or shebang */
  391     const string& getFallbackSyntax() const;
  392 
  393     /** \return line number width */
  394     int getNumberWidth();
  395 
  396     /** \return line length */
  397     int getLineLength();
  398 
  399     /** \return Line number start count */
  400     int getNumberStart();
  401 
  402     /** \return ANSI background color padding width */
  403     int getCanvasPadding();
  404     
  405     /** \return line range start */
  406     int getLineRangeStart();
  407     
  408     /** \return line range end (number of lines starting from getLineRangeStart() ) */
  409     int getLineRangeEnd();
  410     
  411     /** \return Keyword Case (upper, lower, unchanged) */
  412     StringTools::KeywordCase getKeywordCase() const;
  413 
  414     /** \return true if file extension should be ignored */
  415     bool isSkippedExt ( const string& ext )
  416     {
  417         return ignoredFileTypes.count ( ext );
  418     }
  419 
  420 private:
  421 
  422     int numberSpaces;   // number of spaces which replace a tab
  423     int lineNrWidth;    // width of line number (left padding)
  424     int lineLength;    // length of line before wrapping
  425     int lineNrStart;    // line number start count
  426     int lineRangeStart;    // line range start 
  427     int lineRangeEnd;    // line range end
  428     int opt_no_trailing_nl;
  429 
  430     unsigned int canvasPaddingWidth;    // line number start count
  431 
  432     highlight::WrapMode wrappingStyle; // line wrapping mode
  433     highlight::OutputType outputType;
  434     StringTools::KeywordCase keywordCase;
  435 
  436     // name of single output file
  437     string outFilename,
  438            // output directory
  439            outDirectory,
  440            // programming syntax which will be loaded
  441            syntax,
  442            // name of colour theme
  443            styleName,
  444            // name of external style file
  445            styleOutFilename,
  446            // name of file to be included in external style file
  447            styleInFilename,
  448            // used to define data directories at runtime
  449            dataDir;
  450            
  451     // name of indenation scheme
  452     string indentScheme,
  453            pageSize, 
  454            startNestedLang;
  455 
  456     string baseFont, baseFontSize;
  457     string docTitle, className;
  458     string skipArg;
  459     string svg_height, svg_width;
  460     string absThemePath, absLangPath/*, twoPassFile*/;
  461 
  462     bool opt_syntax;
  463     bool opt_include_style;
  464     bool opt_help;
  465     bool opt_version ;
  466     bool opt_verbose;
  467     bool opt_print_config;
  468     bool opt_linenumbers;
  469     bool opt_batch_mode;
  470     bool opt_fragment;
  471     bool opt_attach_line_anchors;
  472     bool opt_printindex;
  473     bool opt_quiet;
  474     bool opt_replacequotes;
  475     bool opt_babel;
  476     bool opt_beamer;
  477     bool opt_print_progress;
  478     bool opt_fill_zeroes;
  479     bool opt_stylepath_explicit;
  480     bool opt_force_output;
  481     bool opt_ordered_list;
  482     bool opt_fnames_as_anchors;
  483     bool opt_validate;
  484     bool opt_number_wrapped_lines;
  485     bool opt_inline_css;
  486     bool opt_enclose_pre;
  487     bool opt_char_styles;
  488     bool opt_page_color;
  489     bool opt_pretty_symbols;
  490     bool opt_delim_CR;
  491     bool opt_print_style;
  492     bool opt_base16_theme;
  493     bool opt_keep_injections;
  494     bool opt_force_stdout;
  495     bool opt_no_version_info;
  496     bool explicit_output_format;
  497     bool opt_isolate;
  498     bool opt_encoding_explicit;
  499     
  500     off_t maxFileSize;
  501 
  502     string fallbackSyntax, anchorPrefix;
  503     string helpLang, encodingName;
  504 
  505     string pluginPath, pluginParameter, 
  506            listScriptCategory, helpTopic, redirectedFilename, listScriptType;
  507 
  508     /** list of all input file names */
  509     vector <string> inputFileNames;
  510 
  511     /** list of plugin file names */
  512     vector <string> userPlugins;
  513 
  514     /** list of additional Artistic Style options */
  515     vector <string> astyleOptions;
  516     
  517     /** list of file types which should be ignored */
  518     set <string> ignoredFileTypes;
  519 
  520     /** \return file suffix */
  521     string getFileSuffix ( const string & fileName ) const;
  522 
  523     /** \return directory name of path */
  524     string getDirName ( const string & path );
  525 
  526     /** get all entries in the directory defined by wildcard */
  527     void readDirectory ( const string & wildcard );
  528 
  529     /** \return Valid path name */
  530     string validateDirPath ( const string & path );
  531     
  532     void parseRuntimeOptions( const int argc, const char *argv[], bool readInputFilenames=true);
  533 };
  534 
  535 #endif