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-2011, 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 <getopt.h>
00030 #include "i18n.h"
00031 
00032 using namespace std;
00033 using namespace Barry;
00034 
00035 struct Languages {
00036         const char *code;
00037         const char *alxid;
00038         const char *description;
00039 };
00040 
00041 
00042 const static struct Languages langs[] = {
00043         { "en", OS_LANG_ENGLISH, "English" },
00044         { "ar", OS_LANG_ARABIC, "Arabic" },
00045         { "ca", OS_LANG_CATALAN, "Catalan" },
00046         { "cs", OS_LANG_CZECH, "Czech" },
00047         { "de", OS_LANG_GERMAN, "German" },
00048         { "sp", OS_LANG_SPANISH, "Spanish" },
00049         { "fr", OS_LANG_FRENCH, "French" },
00050         { "he", OS_LANG_HEBREW, "Hebrew" },
00051         { "hu", OS_LANG_HUNGARIAN, "Hungarian" },
00052         { "it", OS_LANG_ITALIAN, "Italian" },
00053         { "ja", OS_LANG_JAPANESE, "Japanese" },
00054         { "ko", OS_LANG_KOREAN, "Korean" },
00055         { NULL }
00056 };
00057 
00058 void Usage()
00059 {
00060         int major, minor;
00061         const char *Version = Barry::Version(major, minor);
00062 
00063         cerr
00064         << "balxparse - Command line ALX parser\n"
00065         << "        Copyright 2009-2010, Nicolas VIVIEN.\n"
00066         << "        Copyright 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
00067         << "        Using: " << Version << "\n"
00068         << "\n"
00069         << "   -h        This help\n"
00070         << "   -i lang   Internationalization language\n"
00071         << "   -d path   OS path with all ALX files\n"
00072         << "   -o file   OS ALX filename (Platform.alx)\n"
00073         << "\n"
00074         << "   <ALX file> ...\n"
00075         << "     Parse one or several ALX files.\n"
00076         << "\n"
00077         << "   Language supported :\n"
00078         << "\t";
00079 
00080         for (int i=0; langs[i].code!=NULL; i++) {
00081                 string s = (string) langs[i].code + " : " + (string) langs[i].description;
00082 
00083                 cerr << left << setfill(' ') << setw(18) << s;
00084 
00085                 if (((i+1) % 4) == 0)
00086                         cerr << endl << "\t";
00087         }
00088 
00089         cerr << endl;
00090 }
00091 
00092 
00093 int main(int argc, char *argv[], char *envp[])
00094 {
00095         INIT_I18N(PACKAGE);
00096 
00097         try {
00098 
00099         string lang;
00100         string pathname;
00101         string filename;
00102         string osfilename;
00103         vector<string> filenames;
00104 
00105         // process command line options
00106         for(;;) {
00107                 int cmd = getopt(argc, argv, "hi:d:o:");
00108                 if( cmd == -1 )
00109                         break;
00110 
00111                 switch( cmd )
00112                 {
00113                 case 'd':       // ALX path
00114                         pathname = optarg;
00115                         break;
00116 
00117                 case 'o':       // OS ALX filename (Platform.alx)
00118                         osfilename = optarg;
00119                         break;
00120 
00121                 case 'i':       // Language
00122                         lang = optarg;
00123                         break;
00124 
00125                 case 'h':       // help
00126                 default:
00127                         Usage();
00128                         return 0;
00129                 }
00130         }
00131 
00132         argc -= optind;
00133         argv += optind;
00134 
00135         // Put the remaining arguments into an array
00136         for (; argc > 0; argc --, argv ++) {
00137                 filenames.push_back(string(argv[0]));
00138         }
00139 
00140 
00141         // Init ALX parser
00142         ALX::OSLoader os;
00143 
00144         os.AddProperties("_vendorID", "");
00145 
00146 
00147         if (lang.length() > 0) {
00148                 for (int i=0; langs[i].code!=NULL; i++) {
00149                         string code = langs[i].code;
00150 
00151                         if (code == lang)
00152                                 os.AddProperties("langid", langs[i].alxid);
00153                 }
00154         }
00155 
00156         if (osfilename.length() > 0)
00157                 os.LoadALXFile(osfilename, false);
00158 
00159         if (pathname.length() > 0)
00160                 os.Load(pathname);
00161 
00162         if (!filenames.empty()) {
00163                 vector<string>::iterator i = filenames.begin(), end = filenames.end();
00164                 for( ; i != end; ++i ) {
00165                         os.LoadALXFile((*i), true);
00166                 }
00167         }
00168 
00169         cout << os << endl;
00170 
00171 
00172         } catch( std::exception &e ) {
00173                 cout << e.what() << endl;
00174                 return 1;
00175         }
00176 
00177         return 0;
00178 }
00179 

Generated on Tue Mar 1 17:50:14 2011 for Barry by  doxygen 1.5.6