summaryrefslogtreecommitdiff
path: root/support/highlight/src/cli/main.h
blob: 2839e5c9fd69b88fdf14cb6c81d3d8a5fd558cbe (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

/*
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 HIGHLIGHT_APP
#define HIGHLIGHT_APP


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cassert>

//#include "./dirstream0.4/dirstream.h"
#include "cmdlineoptions.h"
#include "configurationreader.h"
#include "codegenerator.h"
#include "help.h"
#include "datadir.h"
#include "version.h"
#include "platform_fs.h"

#define IO_ERROR_REPORT_LENGTH 5
#define SHEBANG_CNT 12

typedef map<string, string> StringMap;

/// Main application class of the command line interface

class HLCmdLineApp
{

	public:

		HLCmdLineApp() {};
		~HLCmdLineApp() {};

		/** Start application
		  \param argc Number of command line arguments
		  \param argv values of command line arguments
		  \return EXIT_SUCCESS or EXIT_FAILURE
		*/
		int run ( const int argc, const char *argv[] );

	private:

		DataDir dataDir;
		StringMap extensions;
		StringMap scriptShebangs;
		stringstream cin_bufcopy;

		/** print version info*/
		void printVersionInfo();

		/** print configuration info*/
		void printConfigInfo ( const string& );

		/** print error message*/
		void printBadInstallationInfo();

		/** print input and output errors */
		void printIOErrorReport ( unsigned int numberErrorFiles, vector<string> & fileList, const string &action );

		/** list installed theme files
		    \return true if theme files were found
		*/
		bool printInstalledThemes();

		/** list installed language definition files
		    \return true if lang files were found
		*/
		bool printInstalledLanguages();

		/** print debug information
		    \param  lang language definition
		    \param langDefPath path to language definition
		*/
		void printDebugInfo ( const highlight::LanguageDefinition &lang,
		                      const string &langDefPath );

		string getFileSuffix ( const string &fileName );

		string guessFileType ( const string &suffix, const string &inputFile="" );

		int getNumDigits ( int i );

		void printProgressBar ( int total, int count );
		void printCurrentAction ( const string&outfilePath,
		                          int total, int count, int countWidth );

		bool readInputFilePaths ( vector<string> &fileList, string wildcard,
		                          bool recursiveSearch );

		string analyzeFile ( const string& file );
		bool loadFileTypeConfig ( const string& name, StringMap* map, StringMap* shebangMap );

};

#endif