maint: updated maintainer script to support new debian source format
[barry.git] / tools / balxparse.cc
blob5fff36adf3697d04d6bd7061f1ebdd97cadd6bea
1 ///
2 /// \file balxparse.cc
3 ///
4 ///
6 /*
7 Copyright (C) 2009-2010, Nicolas VIVIEN
8 Copyright (C) 2005-2012, 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 "i18n.h"
31 #include "barrygetopt.h"
33 using namespace std;
34 using namespace Barry;
36 struct Languages {
37 const char *code;
38 const char *alxid;
39 const char *description;
43 const static struct Languages langs[] = {
44 { "en", OS_LANG_ENGLISH, "English" },
45 { "ar", OS_LANG_ARABIC, "Arabic" },
46 { "ca", OS_LANG_CATALAN, "Catalan" },
47 { "cs", OS_LANG_CZECH, "Czech" },
48 { "de", OS_LANG_GERMAN, "German" },
49 { "sp", OS_LANG_SPANISH, "Spanish" },
50 { "fr", OS_LANG_FRENCH, "French" },
51 { "he", OS_LANG_HEBREW, "Hebrew" },
52 { "hu", OS_LANG_HUNGARIAN, "Hungarian" },
53 { "it", OS_LANG_ITALIAN, "Italian" },
54 { "ja", OS_LANG_JAPANESE, "Japanese" },
55 { "ko", OS_LANG_KOREAN, "Korean" },
56 { NULL }
59 void Usage()
61 int logical, major, minor;
62 const char *Version = Barry::Version(logical, major, minor);
64 cerr
65 << "balxparse - Command line ALX parser\n"
66 << " Copyright 2009-2010, Nicolas VIVIEN.\n"
67 << " Copyright 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
68 << " Using: " << Version << "\n"
69 << "\n"
70 << " -h This help\n"
71 << " -i lang Internationalization language\n"
72 << " -d path OS path with all ALX files\n"
73 << " -o file OS ALX filename (Platform.alx)\n"
74 << "\n"
75 << " <ALX file> ...\n"
76 << " Parse one or several ALX files.\n"
77 << "\n"
78 << " Language supported :\n"
79 << "\t";
81 for (int i=0; langs[i].code!=NULL; i++) {
82 string s = (string) langs[i].code + " : " + (string) langs[i].description;
84 cerr << left << setfill(' ') << setw(18) << s;
86 if (((i+1) % 4) == 0)
87 cerr << endl << "\t";
90 cerr << endl;
94 int main(int argc, char *argv[], char *envp[])
96 INIT_I18N(PACKAGE);
98 try {
100 string lang;
101 string pathname;
102 string filename;
103 string osfilename;
104 vector<string> filenames;
106 // process command line options
107 for(;;) {
108 int cmd = getopt(argc, argv, "hi:d:o:");
109 if( cmd == -1 )
110 break;
112 switch( cmd )
114 case 'd': // ALX path
115 pathname = optarg;
116 break;
118 case 'o': // OS ALX filename (Platform.alx)
119 osfilename = optarg;
120 break;
122 case 'i': // Language
123 lang = optarg;
124 break;
126 case 'h': // help
127 default:
128 Usage();
129 return 0;
133 argc -= optind;
134 argv += optind;
136 // Put the remaining arguments into an array
137 for (; argc > 0; argc --, argv ++) {
138 filenames.push_back(string(argv[0]));
142 // Init ALX parser
143 ALX::OSLoader os;
145 os.AddProperties("_vendorID", "");
148 if (lang.length() > 0) {
149 for (int i=0; langs[i].code!=NULL; i++) {
150 string code = langs[i].code;
152 if (code == lang)
153 os.AddProperties("langid", langs[i].alxid);
157 if (osfilename.length() > 0)
158 os.LoadALXFile(osfilename, false);
160 if (pathname.length() > 0)
161 os.Load(pathname);
163 if (!filenames.empty()) {
164 vector<string>::iterator i = filenames.begin(), end = filenames.end();
165 for( ; i != end; ++i ) {
166 os.LoadALXFile((*i), true);
170 cout << os << endl;
173 } catch( std::exception &e ) {
174 cout << e.what() << endl;
175 return 1;
178 return 0;