balxparse.cc

Go to the documentation of this file.
00001 ///
00002 /// \file       balxparse.cc
00003 ///
00004 ///
00005 
00006 /*
00007     Copyright (C) 2009-2010, Nicolas VIVIEN
00008     Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 
00024 #include <barry/barry.h>
00025 #include <barry/barryalx.h>
00026 #include <iostream>
00027 #include <iomanip>
00028 #include <fstream>
00029 #include "i18n.h"
00030 
00031 #include "barrygetopt.h"
00032 
00033 using namespace std;
00034 using namespace Barry;
00035 
00036 struct Languages {
00037         const char *code;
00038         const char *alxid;
00039         const char *description;
00040 };
00041 
00042 
00043 const static struct Languages langs[] = {
00044         { "en", OS_LANG_ENGLISH, "English" },
00045         { "ar", OS_LANG_ARABIC, "Arabic" },
00046         { "ca", OS_LANG_CATALAN, "Catalan" },
00047         { "cs", OS_LANG_CZECH, "Czech" },
00048         { "de", OS_LANG_GERMAN, "German" },
00049         { "sp", OS_LANG_SPANISH, "Spanish" },
00050         { "fr", OS_LANG_FRENCH, "French" },
00051         { "he", OS_LANG_HEBREW, "Hebrew" },
00052         { "hu", OS_LANG_HUNGARIAN, "Hungarian" },
00053         { "it", OS_LANG_ITALIAN, "Italian" },
00054         { "ja", OS_LANG_JAPANESE, "Japanese" },
00055         { "ko", OS_LANG_KOREAN, "Korean" },
00056         { NULL }
00057 };
00058 
00059 void Usage()
00060 {
00061         int logical, major, minor;
00062         const char *Version = Barry::Version(logical, major, minor);
00063 
00064         cerr
00065         << "balxparse - Command line ALX parser\n"
00066         << "        Copyright 2009-2010, Nicolas VIVIEN.\n"
00067         << "        Copyright 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
00068         << "        Using: " << Version << "\n"
00069         << "\n"
00070         << "   -h        This help\n"
00071         << "   -i lang   Internationalization language\n"
00072         << "   -d path   OS path with all ALX files\n"
00073         << "   -o file   OS ALX filename (Platform.alx)\n"
00074         << "\n"
00075         << "   <ALX file> ...\n"
00076         << "     Parse one or several ALX files.\n"
00077         << "\n"
00078         << "   Language supported :\n"
00079         << "\t";
00080 
00081         for (int i=0; langs[i].code!=NULL; i++) {
00082                 string s = (string) langs[i].code + " : " + (string) langs[i].description;
00083 
00084                 cerr << left << setfill(' ') << setw(18) << s;
00085 
00086                 if (((i+1) % 4) == 0)
00087                         cerr << endl << "\t";
00088         }
00089 
00090         cerr << endl;
00091 }
00092 
00093 
00094 int main(int argc, char *argv[], char *envp[])
00095 {
00096         INIT_I18N(PACKAGE);
00097 
00098         try {
00099 
00100         string lang;
00101         string pathname;
00102         string filename;
00103         string osfilename;
00104         vector<string> filenames;
00105 
00106         // process command line options
00107         for(;;) {
00108                 int cmd = getopt(argc, argv, "hi:d:o:");
00109                 if( cmd == -1 )
00110                         break;
00111 
00112                 switch( cmd )
00113                 {
00114                 case 'd':       // ALX path
00115                         pathname = optarg;
00116                         break;
00117 
00118                 case 'o':       // OS ALX filename (Platform.alx)
00119                         osfilename = optarg;
00120                         break;
00121 
00122                 case 'i':       // Language
00123                         lang = optarg;
00124                         break;
00125 
00126                 case 'h':       // help
00127                 default:
00128                         Usage();
00129                         return 0;
00130                 }
00131         }
00132 
00133         argc -= optind;
00134         argv += optind;
00135 
00136         // Put the remaining arguments into an array
00137         for (; argc > 0; argc --, argv ++) {
00138                 filenames.push_back(string(argv[0]));
00139         }
00140 
00141 
00142         // Init ALX parser
00143         ALX::OSLoader os;
00144 
00145         os.AddProperties("_vendorID", "");
00146 
00147 
00148         if (lang.length() > 0) {
00149                 for (int i=0; langs[i].code!=NULL; i++) {
00150                         string code = langs[i].code;
00151 
00152                         if (code == lang)
00153                                 os.AddProperties("langid", langs[i].alxid);
00154                 }
00155         }
00156 
00157         if (osfilename.length() > 0)
00158                 os.LoadALXFile(osfilename, false);
00159 
00160         if (pathname.length() > 0)
00161                 os.Load(pathname);
00162 
00163         if (!filenames.empty()) {
00164                 vector<string>::iterator i = filenames.begin(), end = filenames.end();
00165                 for( ; i != end; ++i ) {
00166                         os.LoadALXFile((*i), true);
00167                 }
00168         }
00169 
00170         cout << os << endl;
00171 
00172 
00173         } catch( std::exception &e ) {
00174                 cout << e.what() << endl;
00175                 return 1;
00176         }
00177 
00178         return 0;
00179 }
00180