lib: show offset and rectype in HexDumpParser
[barry.git] / src / a_alxparser.cc
blob9fd97e2e27d8ac1b7f0dbcc5d95e348596158d16
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-2010, 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 = new Application(attrs);
97 else if (name == "library") {
98 node = IN_LIBRARY;
100 m_codsection = 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 = new Application();
116 else if (name == "library") {
117 node = IN_SYSTEM_LIBRARY;
118 subnode = SUB_NONE;
120 else if ((subnode == IN_OSFILES) && (name == "os"))
121 osloader.AddProperties(attrs);
122 break;
124 case IN_LIBRARY:
125 case IN_APPLICATION:
126 case IN_SYSTEM_APPLICATION:
127 if (subnode == SUB_NONE) {
128 if (name == "name")
129 subnode = IN_NAME;
130 else if (name == "description")
131 subnode = IN_DESCRIPTION;
132 else if (name == "version")
133 subnode = IN_VERSION;
134 else if (name == "vendor")
135 subnode = IN_VENDOR;
136 else if (name == "copyright")
137 subnode = IN_COPYRIGHT;
138 else if (name == "directory") {
139 if (osloader.IsSupported(attrs))
140 subnode = IN_DIRECTORY;
142 else if (name == "language") {
143 if (osloader.IsSupported(attrs))
144 subnode = IN_LANGUAGE_SUPPORTED;
145 else
146 subnode = IN_LANGUAGE;
148 else if (name == "required")
149 subnode = IN_REQUIRED;
150 else if (name == "fileset") {
151 if (osloader.IsSupported(attrs))
152 subnode = IN_FILESET;
155 break;
157 default:
158 break;
163 void ALXParser::on_end_element(const Glib::ustring& name)
165 depth--;
167 switch (node) {
168 case MAIN_NONE:
169 // exit(-1);
170 break;
172 case IN_LOADER:
173 if (name == "loader")
174 node = MAIN_NONE;
175 break;
177 case IN_SYSTEM:
178 if (name == "system") {
179 subnode = SUB_NONE;
180 node = IN_LOADER;
183 switch (subnode) {
184 case IN_DIRECTORY:
185 if (name == "directory")
186 subnode = SUB_NONE;
187 break;
189 case IN_OSFILES:
190 if (name == "osfiles")
191 subnode = SUB_NONE;
192 else if (name == "os")
193 osloader.SetSFIFile(buffdata);
194 break;
195 default:
196 break;
198 break;
200 case IN_LIBRARY:
201 case IN_APPLICATION:
202 case IN_SYSTEM_APPLICATION:
203 if (name == "application") {
204 if (m_register)
205 osloader.AddApplication(m_codsection);
206 subnode = SUB_NONE;
207 if (node == IN_APPLICATION)
208 node = IN_LOADER;
209 else if (node == IN_SYSTEM_APPLICATION)
210 node = IN_SYSTEM;
212 else if (name == "library") {
213 if (m_register)
214 osloader.AddLibrary(m_codsection);
215 subnode = SUB_NONE;
216 if (node == IN_LIBRARY)
217 node = IN_LOADER;
220 switch (subnode) {
221 case IN_NAME:
222 if (name == "name") {
223 m_codsection->SetName(buffdata);
224 subnode = SUB_NONE;
226 break;
227 case IN_DESCRIPTION:
228 if (name == "description") {
229 m_codsection->SetDescription(buffdata);
230 subnode = SUB_NONE;
232 break;
233 case IN_VERSION:
234 if (name == "version") {
235 m_codsection->SetVersion(buffdata);
236 subnode = SUB_NONE;
238 break;
239 case IN_VENDOR:
240 if (name == "vendor") {
241 m_codsection->SetVendor(buffdata);
242 subnode = SUB_NONE;
244 break;
245 case IN_COPYRIGHT:
246 if (name == "copyright") {
247 m_codsection->SetCopyright(buffdata);
248 subnode = SUB_NONE;
250 break;
251 case IN_DIRECTORY:
252 if (name == "directory") {
253 m_codsection->SetDirectory(buffdata);
254 subnode = SUB_NONE;
256 break;
257 case IN_LANGUAGE:
258 if (name == "language") {
259 subnode = SUB_NONE;
261 break;
262 case IN_LANGUAGE_SUPPORTED:
263 if (name == "language") {
264 subnode = SUB_NONE;
266 else if (name == "name") {
267 m_codsection->SetName(buffdata);
269 break;
270 case IN_REQUIRED:
271 if (name == "required") {
272 subnode = SUB_NONE;
273 m_codsection->SetRequired(buffdata);
275 break;
276 case IN_FILESET:
277 if (name == "fileset") {
278 subnode = SUB_NONE;
280 else if (name == "files") {
281 m_codsection->AddFiles(buffdata);
283 break;
285 default:
286 break;
288 break;
290 default:
291 break;
296 void ALXParser::on_characters(const Glib::ustring& data)
298 buffdata.append(data);
302 void ALXParser::on_comment(const Glib::ustring& text)
304 // std::cout << "on_comment(): " << text << std::endl;
308 void ALXParser::on_warning(const Glib::ustring& text)
310 // std::cout << "on_warning(): " << text << std::endl;
314 void ALXParser::on_error(const Glib::ustring& text)
316 // std::cout << "on_error(): " << text << std::endl;
320 void ALXParser::on_fatal_error(const Glib::ustring& text)
322 std::cout << "on_fatal_error(): " << text << std::endl;
326 } // namespace ALX
328 } // namespace Barry