2
* This file is part of CSSTidy.
4
* CSSTidy is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* CSSTidy is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with CSSTidy; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "csspp_globals.hpp"
23
#include "prepare.hpp"
25
map< string, vector<string> > predefined_templates;
28
int main(int argc, char *argv[])
31
predefined_templates["high"].push_back("<span class=\"at\">");
32
predefined_templates["high"].push_back("</span> <span class=\"format\">{</span>\n");
33
predefined_templates["high"].push_back("<span class=\"selector\">");
34
predefined_templates["high"].push_back("</span><span class=\"format\">{</span>");
35
predefined_templates["high"].push_back("<span class=\"property\">");
36
predefined_templates["high"].push_back("</span><span class=\"value\">");
37
predefined_templates["high"].push_back("</span><span class=\"format\">;</span>");
38
predefined_templates["high"].push_back("<span class=\"format\">}</span>");
39
predefined_templates["high"].push_back("\n");
40
predefined_templates["high"].push_back("\n<span class=\"format\">}\n</span>");
41
predefined_templates["high"].push_back("");
42
predefined_templates["high"].push_back("<span class=\"comment\">"); // before comment
43
predefined_templates["high"].push_back("</span>"); //after comment
44
predefined_templates["high"].push_back("\n"); // after last line @-rule
46
predefined_templates["highest"].push_back("<span class=\"at\">");
47
predefined_templates["highest"].push_back("</span><span class=\"format\">{</span>");
48
predefined_templates["highest"].push_back("<span class=\"selector\">");
49
predefined_templates["highest"].push_back("</span><span class=\"format\">{</span>");
50
predefined_templates["highest"].push_back("<span class=\"property\">");
51
predefined_templates["highest"].push_back("</span><span class=\"value\">");
52
predefined_templates["highest"].push_back("</span><span class=\"format\">;</span>");
53
predefined_templates["highest"].push_back("<span class=\"format\">}</span>");
54
predefined_templates["highest"].push_back("");
55
predefined_templates["highest"].push_back("<span class=\"format\">}</span>");
56
predefined_templates["highest"].push_back("");
57
predefined_templates["highest"].push_back("<span class=\"comment\">"); // before comment
58
predefined_templates["highest"].push_back("</span>"); //after comment
59
predefined_templates["highest"].push_back(""); // after last line @-rule
61
predefined_templates["low"].push_back("<span class=\"at\">");
62
predefined_templates["low"].push_back("</span> <span class=\"format\">{</span>\n");
63
predefined_templates["low"].push_back("<span class=\"selector\">");
64
predefined_templates["low"].push_back("</span>\n<span class=\"format\">{</span>\n");
65
predefined_templates["low"].push_back("\t<span class=\"property\">");
66
predefined_templates["low"].push_back("</span><span class=\"value\">");
67
predefined_templates["low"].push_back("</span><span class=\"format\">;</span>\n");
68
predefined_templates["low"].push_back("<span class=\"format\">}</span>");
69
predefined_templates["low"].push_back("\n\n");
70
predefined_templates["low"].push_back("\n<span class=\"format\">}</span>\n\n");
71
predefined_templates["low"].push_back("\t");
72
predefined_templates["low"].push_back("<span class=\"comment\">"); // before comment
73
predefined_templates["low"].push_back("</span>\n"); //after comment
74
predefined_templates["low"].push_back("\n"); // after last line @-rule
80
string filein = argv[1];
81
if(filein != "-" && !file_exists(argv[1]))
83
cout << "The file \"" << filein << "\" does not exist." << endl;
87
string output_filename;
89
for(int i = 2; i < argc; ++i)
91
bool output_file = true;
92
for(map<string,int>::iterator j = csst.settings.begin(); j != csst.settings.end(); ++j )
94
if(trim(argv[i]) == "--" + j->first + "=false" || trim(argv[i]) == "--" + j->first + "=0")
96
csst.settings[j->first] = 0;
99
else if(trim(argv[i]) == "--" + j->first + "=true" || trim(argv[i]) == "--" + j->first + "=1")
101
csst.settings[j->first] = 1;
104
else if(trim(argv[i]) == "--" + j->first + "=2")
106
csst.settings[j->first] = 2;
110
if(trim(argv[i]).substr(0,12) == "--css_level=")
112
csst.css_level = strtoupper(trim(argv[i]).substr(12));
115
else if(trim(argv[i]).substr(0,11) == "--template=")
117
string template_value = trim(argv[i]).substr(11);
118
if(template_value == "high" || template_value == "highest" || template_value == "low")
120
csst.csstemplate = predefined_templates[template_value];
122
else if(template_value != "default")
124
string tpl_content = file_get_contents(template_value);
125
if(tpl_content != "")
127
vector<string> tpl_arr = explode("|",tpl_content,true);
128
csst.csstemplate = tpl_arr;
135
output_filename = trim(argv[i]);
143
getline(cin, temp, '\n');
144
css_file += (temp + "\n");
147
css_file = file_get_contents(argv[1]);
150
csst.parse_css(css_file);
152
// Print CSS to screen if no output file is specified
153
if(output_filename == "")
159
csst.print_css(output_filename);
165
cout << endl << "Usage:" << endl << endl << "csstidy input_filename [\n";
166
for(map<string,int>::iterator j = csst.settings.begin(); j != csst.settings.end(); ++j )
168
if (j->first == "optimise_shorthands" || j->first == "merge_selectors") {
172
cout << " --" << j->first;
173
if(j->second == true)
175
cout << "=[true|false] |\n";
179
cout << "=[false|true] |\n";
182
cout << " --merge_selectors=[2|1|0] |\n";
183
cout << " --optimise_shorthands=[1|2|0] |\n";
184
cout << " --template=[default|filename|low|high|highest] |\n";
185
cout << " output_filename ]*" << endl;