~ubuntu-branches/ubuntu/wily/csstidy/wily

« back to all changes in this revision

Viewing changes to main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Coyner
  • Date: 2008-02-24 20:52:52 UTC
  • mfrom: (2.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20080224205252-i9t0wyrnjeedczz2
Tags: 1.4-3
* Add patch gcc43fix which contains an uncaught missing include in
  csstidy/misc.cpp. Closes: #455123.
* Bumped Standards-Version to 3.7.3. No changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of CSSTidy.
3
 
 *
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.
8
 
 *
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.
13
 
 *
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
17
 
 */
18
 
 
19
 
using namespace std;
20
 
 
21
 
#include "csspp_globals.hpp"
22
 
 
23
 
#include "prepare.hpp"
24
 
 
25
 
map< string, vector<string> > predefined_templates;
26
 
 
27
 
 
28
 
int main(int argc, char *argv[])
29
 
{
30
 
        prepare();
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
45
 
        
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
60
 
                
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
75
 
        
76
 
        csstidy csst;
77
 
 
78
 
        if(argc > 1)
79
 
        {
80
 
                string filein = argv[1];
81
 
                if(filein != "-" && !file_exists(argv[1]))
82
 
                {
83
 
                        cout << "The file \"" << filein << "\" does not exist." << endl;
84
 
                        return EXIT_FAILURE;
85
 
                }
86
 
                
87
 
                string output_filename;
88
 
                
89
 
                for(int i = 2; i < argc; ++i)
90
 
                {
91
 
                        bool output_file = true;
92
 
                        for(map<string,int>::iterator j = csst.settings.begin(); j != csst.settings.end(); ++j )
93
 
                        {
94
 
                                if(trim(argv[i]) == "--" + j->first + "=false" || trim(argv[i]) == "--" + j->first + "=0")
95
 
                                {
96
 
                                        csst.settings[j->first] = 0;
97
 
                                        output_file = false;
98
 
                                }
99
 
                                else if(trim(argv[i]) == "--" + j->first + "=true" || trim(argv[i]) == "--" + j->first + "=1")
100
 
                                {
101
 
                                        csst.settings[j->first] = 1;
102
 
                                        output_file = false;
103
 
                                }
104
 
                                else if(trim(argv[i]) == "--" + j->first + "=2")
105
 
                                {
106
 
                                        csst.settings[j->first] = 2;
107
 
                                        output_file = false;
108
 
                                }
109
 
                        }
110
 
                        if(trim(argv[i]).substr(0,12) == "--css_level=")
111
 
                        {
112
 
                                csst.css_level = strtoupper(trim(argv[i]).substr(12));
113
 
                                output_file = false;
114
 
                        }
115
 
                        else if(trim(argv[i]).substr(0,11) == "--template=")
116
 
                        {
117
 
                                string template_value = trim(argv[i]).substr(11);
118
 
                                if(template_value == "high" || template_value == "highest" || template_value == "low")
119
 
                                {
120
 
                                        csst.csstemplate = predefined_templates[template_value];
121
 
                                }
122
 
                                else if(template_value != "default")
123
 
                                {
124
 
                                        string tpl_content = file_get_contents(template_value);
125
 
                                        if(tpl_content != "")
126
 
                                        {
127
 
                                                vector<string> tpl_arr = explode("|",tpl_content,true);
128
 
                                                csst.csstemplate = tpl_arr;
129
 
                                        }
130
 
                                }
131
 
                                output_file = false;
132
 
                        }
133
 
                        if(output_file)
134
 
                        {
135
 
                                output_filename = trim(argv[i]);
136
 
                        }
137
 
                }
138
 
                
139
 
                string css_file;
140
 
        if(filein == "-") {
141
 
                        string temp;
142
 
                        do {
143
 
                                getline(cin, temp, '\n');
144
 
                                css_file += (temp + "\n");
145
 
                        } while(cin);
146
 
                } else {
147
 
            css_file = file_get_contents(argv[1]);
148
 
        }
149
 
 
150
 
                csst.parse_css(css_file);
151
 
                
152
 
                // Print CSS to screen if no output file is specified
153
 
                if(output_filename == "")
154
 
                {
155
 
                        csst.print_css();
156
 
                }
157
 
                else
158
 
                {
159
 
                        csst.print_css(output_filename);
160
 
                }
161
 
                
162
 
                return EXIT_SUCCESS;
163
 
        }
164
 
 
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 )
167
 
        {
168
 
                if (j->first == "optimise_shorthands" || j->first == "merge_selectors") {
169
 
                        continue;
170
 
                }
171
 
                
172
 
                cout << " --" << j->first;
173
 
                if(j->second == true)
174
 
                {
175
 
                        cout << "=[true|false] |\n";
176
 
                }
177
 
                else
178
 
                {
179
 
                        cout << "=[false|true] |\n";
180
 
                }
181
 
        }
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;
186
 
        
187
 
        return EXIT_SUCCESS;
188
 
}