menu: added new Keywords tag to .desktop files
[barry.git] / src / a_alxparser.cc
blobcdddad3ef21b46a231da9b7b5633737fac184933
1 ///
2 /// \file a_alxparser.cc
3 /// ALX file parser (for one file)
4 ///
6 /*
7 Copyright (C) 2010, Nicolas VIVIEN
8 Copyright (C) 2005-2013, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
27 #include "a_alxparser.h"
30 namespace Barry {
33 namespace ALX {
36 ALXParser::ALXParser(OSLoader& osloader, std::istream& input)
37 : XML::XMLParser(input, "ISO-8859-1")
38 , osloader(osloader)
40 node = MAIN_NONE;
41 subnode = SUB_NONE;
42 m_register = true;
46 ALXParser::~ALXParser(void)
51 bool ALXParser::Run(const bool enable)
53 m_register = enable;
55 return XMLParser::Run();
59 void ALXParser::on_start_document()
61 // std::cout << "on_start_document()" << std::endl;
65 void ALXParser::on_end_document()
67 // std::cout << "on_end_document()" << std::endl;
71 void ALXParser::on_start_element(const Glib::ustring& name,
72 const xmlpp::SaxParser::AttributeList& attrs)
74 depth++;
76 buffdata = "";
78 switch (node) {
79 case MAIN_NONE:
80 if (name == "loader")
81 node = IN_LOADER;
82 // else
83 // exit(-1);
84 break;
86 case IN_LOADER:
87 subnode = SUB_NONE;
89 if (name == "system") {
90 node = IN_SYSTEM;
92 else if (name == "application") {
93 node = IN_APPLICATION;
95 m_codsection.reset( new Application(attrs) );
97 else if (name == "library") {
98 node = IN_LIBRARY;
100 m_codsection.reset( new Library(attrs) );
102 break;
104 case IN_SYSTEM:
105 if (name == "directory")
106 subnode = IN_DIRECTORY;
107 else if (name == "osfiles") {
108 subnode = IN_OSFILES;
110 else if (name == "application") {
111 node = IN_SYSTEM_APPLICATION;
112 subnode = SUB_NONE;
114 m_codsection.reset( new Application(attrs) );
116 else if (name == "library") {
117 node = IN_SYSTEM_LIBRARY;
118 subnode = SUB_NONE;
120 m_codsection.reset( new Application(attrs) );
122 else if ((subnode == IN_OSFILES) && (name == "os"))
123 osloader.AddProperties(attrs);
124 break;
126 case IN_LIBRARY:
127 case IN_APPLICATION:
128 case IN_APPLICATION_APPLICATION:
129 case IN_SYSTEM_APPLICATION:
130 case IN_SYSTEM_LIBRARY:
131 if (subnode == SUB_NONE) {
132 if ((node == IN_APPLICATION) && (name == "application")) {
133 node = IN_APPLICATION_APPLICATION;
135 m_savecodsection = m_codsection;
136 m_codsection.reset( new Application(attrs) );
138 else if (name == "name")
139 subnode = IN_NAME;
140 else if (name == "description")
141 subnode = IN_DESCRIPTION;
142 else if (name == "version")
143 subnode = IN_VERSION;
144 else if (name == "vendor")
145 subnode = IN_VENDOR;
146 else if (name == "copyright")
147 subnode = IN_COPYRIGHT;
148 else if (name == "directory") {
149 if (osloader.IsSupported(attrs))
150 subnode = IN_DIRECTORY;
152 else if (name == "language") {
153 if (osloader.IsSupported(attrs))
154 subnode = IN_LANGUAGE_SUPPORTED;
155 else
156 subnode = IN_LANGUAGE;
158 else if (name == "required")
159 subnode = IN_REQUIRED;
160 else if (name == "fileset") {
161 if (osloader.IsSupported(attrs))
162 subnode = IN_FILESET;
165 break;
167 default:
168 break;
173 void ALXParser::on_end_element(const Glib::ustring& name)
175 depth--;
177 switch (node) {
178 case MAIN_NONE:
179 // exit(-1);
180 break;
182 case IN_LOADER:
183 if (name == "loader")
184 node = MAIN_NONE;
185 break;
187 case IN_SYSTEM:
188 if (name == "system") {
189 subnode = SUB_NONE;
190 node = IN_LOADER;
193 switch (subnode) {
194 case IN_DIRECTORY:
195 if (name == "directory")
196 subnode = SUB_NONE;
197 break;
199 case IN_OSFILES:
200 if (name == "osfiles")
201 subnode = SUB_NONE;
202 else if (name == "os")
203 osloader.SetSFIFile(buffdata);
204 break;
205 default:
206 break;
208 break;
210 case IN_LIBRARY:
211 case IN_APPLICATION:
212 case IN_APPLICATION_APPLICATION:
213 case IN_SYSTEM_APPLICATION:
214 case IN_SYSTEM_LIBRARY:
215 if (name == "application") {
216 if (m_register)
217 osloader.AddApplication(m_codsection);
218 subnode = SUB_NONE;
219 if (node == IN_APPLICATION)
220 node = IN_LOADER;
221 else if (node == IN_SYSTEM_APPLICATION)
222 node = IN_SYSTEM;
223 else if (node == IN_APPLICATION_APPLICATION) {
224 node = IN_APPLICATION;
225 m_codsection = m_savecodsection;
228 else if (name == "library") {
229 if (m_register)
230 osloader.AddLibrary(m_codsection);
231 subnode = SUB_NONE;
232 if (node == IN_LIBRARY)
233 node = IN_LOADER;
234 else if (node == IN_SYSTEM_LIBRARY)
235 node = IN_SYSTEM;
238 switch (subnode) {
239 case IN_NAME:
240 if (name == "name") {
241 m_codsection->SetName(buffdata);
242 subnode = SUB_NONE;
244 break;
245 case IN_DESCRIPTION:
246 if (name == "description") {
247 m_codsection->SetDescription(buffdata);
248 subnode = SUB_NONE;
250 break;
251 case IN_VERSION:
252 if (name == "version") {
253 m_codsection->SetVersion(buffdata);
254 subnode = SUB_NONE;
256 break;
257 case IN_VENDOR:
258 if (name == "vendor") {
259 m_codsection->SetVendor(buffdata);
260 subnode = SUB_NONE;
262 break;
263 case IN_COPYRIGHT:
264 if (name == "copyright") {
265 m_codsection->SetCopyright(buffdata);
266 subnode = SUB_NONE;
268 break;
269 case IN_DIRECTORY:
270 if (name == "directory") {
271 m_codsection->SetDirectory(buffdata);
272 subnode = SUB_NONE;
274 break;
275 case IN_LANGUAGE:
276 if (name == "language") {
277 subnode = SUB_NONE;
279 break;
280 case IN_LANGUAGE_SUPPORTED:
281 if (name == "language") {
282 subnode = SUB_NONE;
284 else if (name == "name") {
285 m_codsection->SetName(buffdata);
287 break;
288 case IN_REQUIRED:
289 if (name == "required") {
290 subnode = SUB_NONE;
291 m_codsection->SetRequired(buffdata);
293 break;
294 case IN_FILESET:
295 if (name == "fileset") {
296 subnode = SUB_NONE;
298 else if (name == "files") {
299 m_codsection->AddFiles(buffdata);
301 break;
303 default:
304 break;
306 break;
308 default:
309 break;
314 void ALXParser::on_characters(const Glib::ustring& data)
316 buffdata.append(data);
320 void ALXParser::on_comment(const Glib::ustring& text)
322 // std::cout << "on_comment(): " << text << std::endl;
326 void ALXParser::on_warning(const Glib::ustring& text)
328 // std::cout << "on_warning(): " << text << std::endl;
332 void ALXParser::on_error(const Glib::ustring& text)
334 // std::cout << "on_error(): " << text << std::endl;
338 void ALXParser::on_fatal_error(const Glib::ustring& text)
340 std::cout << "on_fatal_error(): " << text << std::endl;
344 } // namespace ALX
346 } // namespace Barry