lib: show offset and rectype in HexDumpParser
[barry.git] / tools / balxparse.cc
blobb3a6c7acc688aeec205692c95bc9dd4550facb30
1 ///
2 /// \file balxparse.cc
3 ///
4 ///
6 /*
7 Copyright (C) 2009-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.
24 #include <barry/barry.h>
25 #include <barry/barryalx.h>
26 #include <iostream>
27 #include <iomanip>
28 #include <fstream>
29 #include <getopt.h>
30 #include "i18n.h"
32 using namespace std;
33 using namespace Barry;
35 struct Languages {
36 const char *code;
37 const char *alxid;
38 const char *description;
42 const static struct Languages langs[] = {
43 { "en", OS_LANG_ENGLISH, "English" },
44 { "ar", OS_LANG_ARABIC, "Arabic" },
45 { "ca", OS_LANG_CATALAN, "Catalan" },
46 { "cs", OS_LANG_CZECH, "Czech" },
47 { "de", OS_LANG_GERMAN, "German" },
48 { "sp", OS_LANG_SPANISH, "Spanish" },
49 { "fr", OS_LANG_FRENCH, "French" },
50 { "he", OS_LANG_HEBREW, "Hebrew" },
51 { "hu", OS_LANG_HUNGARIAN, "Hungarian" },
52 { "it", OS_LANG_ITALIAN, "Italian" },
53 { "ja", OS_LANG_JAPANESE, "Japanese" },
54 { "ko", OS_LANG_KOREAN, "Korean" },
55 { NULL }
58 void Usage()
60 int major, minor;
61 const char *Version = Barry::Version(major, minor);
63 cerr
64 << "balxparse - Command line ALX parser\n"
65 << " Copyright 2009-2010, Nicolas VIVIEN.\n"
66 << " Copyright 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)\n"
67 << " Using: " << Version << "\n"
68 << "\n"
69 << " -h This help\n"
70 << " -i lang Internationalization language\n"
71 << " -d path OS path with all ALX files\n"
72 << " -o file OS ALX filename (Platform.alx)\n"
73 << "\n"
74 << " <ALX file> ...\n"
75 << " Parse one or several ALX files.\n"
76 << "\n"
77 << " Language supported :\n"
78 << "\t";
80 for (int i=0; langs[i].code!=NULL; i++) {
81 string s = (string) langs[i].code + " : " + (string) langs[i].description;
83 cerr << left << setfill(' ') << setw(18) << s;
85 if (((i+1) % 4) == 0)
86 cerr << endl << "\t";
89 cerr << endl;
93 int main(int argc, char *argv[], char *envp[])
95 INIT_I18N(PACKAGE);
97 try {
99 string lang;
100 string pathname;
101 string filename;
102 string osfilename;
103 vector<string> filenames;
105 // process command line options
106 for(;;) {
107 int cmd = getopt(argc, argv, "hi:d:o:");
108 if( cmd == -1 )
109 break;
111 switch( cmd )
113 case 'd': // ALX path
114 pathname = optarg;
115 break;
117 case 'o': // OS ALX filename (Platform.alx)
118 osfilename = optarg;
119 break;
121 case 'i': // Language
122 lang = optarg;
123 break;
125 case 'h': // help
126 default:
127 Usage();
128 return 0;
132 argc -= optind;
133 argv += optind;
135 // Put the remaining arguments into an array
136 for (; argc > 0; argc --, argv ++) {
137 filenames.push_back(string(argv[0]));
141 // Init ALX parser
142 ALX::OSLoader os;
144 os.AddProperties("_vendorID", "");
147 if (lang.length() > 0) {
148 for (int i=0; langs[i].code!=NULL; i++) {
149 string code = langs[i].code;
151 if (code == lang)
152 os.AddProperties("langid", langs[i].alxid);
156 if (osfilename.length() > 0)
157 os.LoadALXFile(osfilename, false);
159 if (pathname.length() > 0)
160 os.Load(pathname);
162 if (!filenames.empty()) {
163 vector<string>::iterator i = filenames.begin(), end = filenames.end();
164 for( ; i != end; ++i ) {
165 os.LoadALXFile((*i), true);
169 cout << os << endl;
172 } catch( std::exception &e ) {
173 cout << e.what() << endl;
174 return 1;
177 return 0;