"Fossies" - the Fresh Open Source Software Archive 
Member "ansifilter-2.18/src/main.cpp" (30 Jan 2021, 9541 Bytes) of package /linux/privat/ansifilter-2.18.tar.bz2:
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.
For more information about "main.cpp" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.17_vs_2.18.
1 /***************************************************************************
2 main.cpp - description
3 -------------------
4
5 copyright : (C) 2007-2021 by Andre Simon
6 email : a.simon@mailbox.org
7
8 Highlight is a universal source code to HTML converter. Syntax highlighting
9 is formatted by Cascading Style Sheets. It's possible to easily enhance
10 highlight's parsing database.
11
12 ***************************************************************************/
13
14 /*
15 This file is part of ANSIFilter.
16
17 ANSIFilter is free software: you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation, either version 3 of the License, or
20 (at your option) any later version.
21
22 ANSIFilter is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with ANSIFilter. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31 #include <memory>
32 #include "main.h"
33 #include "codegenerator.h"
34 #include "platform_fs.h"
35
36 using namespace std;
37
38 void ANSIFilterApp::printVersionInfo()
39 {
40 cout << "\n ansifilter version "
41 << Info::getVersion()
42 << "\n Copyright (C) 2007-2021 Andre Simon <a dot simon at mailbox.org>"
43 << "\n\n Argparser class"
44 << "\n Copyright (C) 2006-2008 Antonio Diaz Diaz <ant_diaz at teleline.es>"
45 << "\n\n This software is released under the terms of the GNU General "
46 << "Public License."
47 << "\n For more information about these matters, see the file named "
48 << "COPYING.\n";
49 }
50
51 void ANSIFilterApp::printHelp()
52 {
53 cout << "Invocation: ansifilter [OPTION]... [FILE]...\n\n";
54 cout << "ansifilter handles text files containing ANSI terminal escape codes.\n";
55 cout << "\nFile handling:\n";
56 cout << " -i, --input=<file> Name of input file\n";
57 cout << " -o, --output=<file> Name of output file\n";
58 cout << " -O, --outdir=<dir> Name of output directory\n";
59 cout << " -t, --tail Continue reading after end-of-file (like tail -f)\n";
60 cout << " -x, --max-size=<size> Set maximum input file size\n";
61 cout << " (examples: 512M, 1G; default: 256M)\n";
62 cout << "\nOutput text formats:\n";
63 cout << " -T, --text (default) Output text\n";
64 cout << " -H, --html Output HTML\n";
65 cout << " -M, --pango Output Pango Markup\n";
66 cout << " -L, --latex Output LaTeX\n";
67 cout << " -P, --tex Output Plain TeX\n";
68 cout << " -R, --rtf Output RTF\n";
69 cout << " -S, --svg Output SVG\n";
70 cout << " -B, --bbcode Output BBCode\n";
71 cout << "\nFormat options:\n";
72 cout << " -a, --anchors(=self) Add HTML line anchors (opt: self referencing, assumes -l)\n";
73 cout << " -d, --doc-title Set HTML/LaTeX/SVG document title\n";
74 cout << " -e, --encoding=<enc> Set HTML/RTF encoding (must match input file encoding);\n";
75 cout << " omit encoding information if enc=NONE\n";
76 cout << " -f, --fragment Omit HTML header and footer\n";
77 cout << " -F, --font=<font> Set HTML/RTF/SVG font face\n";
78 cout << " -k, --ignore-clear(=0) Do not adhere to clear (ESC K) commands (default: true)\n";
79 cout << " -c, --ignore-csi Do not adhere to CSI commands (useful for UTF-8 input)\n";
80 cout << " -l, --line-numbers Print line numbers in output file\n";
81 cout << " -m, --map=<path> Read color mapping file (see README)\n";
82 cout << " -r, --style-ref=<rf> Set HTML/TeX/LaTeX/SVG stylesheet path\n";
83 cout << " -s, --font-size=<fs> Set HTML/RTF/SVG font size\n";
84 cout << " -p, --plain Ignore ANSI formatting information\n";
85 cout << " -w, --wrap=<len> Wrap long lines\n";
86 cout << " --no-trailing-nl Omit trailing newline\n";
87 cout << " --no-version-info Omit version info comment\n";
88 cout << " --wrap-no-numbers Omit line numbers of wrapped lines (assumes -l)\n";
89 cout << " --derived-styles Output dynamic stylesheets (HTML/SVG)\n";
90
91 cout << "\nANSI art options:\n";
92 cout << " --art-cp437 Parse codepage 437 ANSI art (HTML and RTF output)\n";
93 cout << " --art-bin Parse BIN/XBIN ANSI art (HTML output, no stdin)\n";
94 cout << " --art-tundra Parse Tundra ANSI art (HTML output, no stdin)\n";
95 cout << " --art-width Set ANSI art width (default 80)\n";
96 cout << " --art-height Set ANSI art height (default 150)\n";
97
98 cout << "\nSVG output options:\n";
99 cout << " --height set image height (units allowed)\n";
100 cout << " --width set image width (see --height)\n";
101
102 cout << "\nOther options:\n";
103 cout << " -h, --help Print help\n";
104 cout << " -v, --version Print version and license info\n";
105 cout << "\nExamples:\n";
106 cout << "ansifilter -i input.ansi -o output.txt\n";
107 cout << "ansifilter *.txt\n";
108 cout << "tail -f server.log | ansifilter\n\n";
109 cout << "Parsing XBIN files overrides --art-width, --art-height and --map options.\n";
110 cout << "The ANSI art file formats BIN, XBIN and TND cannot be read from stdin.\n";
111 cout << "\nPlease report bugs to " << Info::getEmail()<< "\n";
112 cout << "For updates see " << Info::getWebsite()<< "\n";
113 }
114
115 int ANSIFilterApp::run( const int argc, const char *argv[] )
116 {
117
118 CmdLineOptions options(argc, argv);
119
120 if (options.printVersion()) {
121 printVersionInfo();
122 return EXIT_SUCCESS;
123 }
124
125 if (options.printHelp()) {
126 printHelp();
127 return EXIT_SUCCESS;
128 }
129
130 const vector <string> inFileList=options.getInputFileNames();
131 unique_ptr<ansifilter::CodeGenerator> generator(ansifilter::CodeGenerator::getInstance(options.getOutputType()));
132
133 string outDirectory = options.getOutDirectory();
134
135 unsigned int fileCount=inFileList.size(), i=0;
136 string::size_type pos=0;
137 string inFileName, outFilePath;
138 string mapPath = options.getMapPath();
139 bool failure=false;
140
141 if (!generator->setColorMap(mapPath)){
142 std::cerr <<"could not read map file: " << mapPath << "\n";
143 return EXIT_FAILURE;
144 }
145
146 while (i < fileCount && !failure) {
147
148 if (fileCount>1) {
149 pos=(inFileList[i]).find_last_of(Platform::pathSeparator);
150 inFileName = inFileList[i].substr(pos+1);
151 outFilePath = outDirectory;
152 outFilePath += inFileName;
153 outFilePath += options.getOutFileSuffix();
154 } else {
155 outFilePath = options.getSingleOutFilename();
156 }
157
158 if ( inFileList[i].size() && Platform::fileSize(inFileList[i]) > options.getMaxFileSize() ) {
159
160 std::cerr <<"file exceeds max size (see --max-size): " << inFileList[i] << "\n";
161 return EXIT_FAILURE;
162 }
163
164 generator->setTitle(options.getDocumentTitle().empty()?
165 inFileList[i]:options.getDocumentTitle());
166
167 generator->setEncoding(options.getEncoding());
168 generator->setFragmentCode(options.fragmentOutput());
169 generator->setPlainOutput(options.plainOutput());
170 generator->setContinueReading(options.ignoreInputEOF());
171 generator->setFont(options.getFont());
172 generator->setFontSize(options.getFontSize());
173 generator->setStyleSheet(options.getStyleSheetPath());
174 generator->setPreformatting(ansifilter::WRAP_SIMPLE, options.getWrapLineLength());
175 generator->setShowLineNumbers(options.showLineNumbers());
176 generator->setWrapNoNumbers(!options.wrapNoNumbers());
177 generator->setAddAnchors(options.addAnchors(), options.addFunnyAnchors());
178 generator->setParseCodePage437(options.parseCP437());
179 generator->setParseAsciiBin(options.parseAsciiBin());
180 generator->setParseAsciiTundra(options.parseAsciiTundra());
181 generator->setIgnoreClearSeq(options.ignoreClearSeq());
182 generator->setIgnoreCSISeq(options.ignoreCSISeq());
183
184 generator->setApplyDynStyles(options.applyDynStyles());
185
186 generator->setAsciiArtSize(options.getAsciiArtWidth(), options.getAsciiArtHeight());
187 generator->setOmitTrailingCR(options.omitTrailingCR());
188 generator->setOmitVersionInfo(options.omitVersionInfo());
189
190 generator->setSVGSize ( options.getWidth(), options.getHeight() );
191
192 ansifilter::ParseError error = generator->generateFile(inFileList[i], outFilePath);
193
194 if (error==ansifilter::BAD_INPUT) {
195 std::cerr << "could not read input: " << inFileList[i] << "\n";
196 failure=true;
197 } else if (error==ansifilter::BAD_OUTPUT) {
198 std::cerr << "could not write output: " << outFilePath << "\n";
199 failure=true;
200 }
201 ++i;
202 }
203
204 if (options.applyDynStyles() && !failure) {
205 string styleStyleSheetPath = outDirectory + "derived_styles.css";
206 generator->printDynamicStyleFile(styleStyleSheetPath);
207 }
208
209 return (failure) ? EXIT_FAILURE : EXIT_SUCCESS;
210 }
211
212 int main( const int argc, const char *argv[] )
213 {
214 ANSIFilterApp app;
215 return app.run(argc, argv);
216 }