1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org 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. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_l10ntools.hxx" 30 #include <stdio.h> 31 #include <stdlib.h> 32 33 // local includes 34 #include "helpmerge.hxx" 35 36 // defines to parse command line 37 #define STATE_NON 0x0001 38 #define STATE_INPUT 0x0002 39 #define STATE_OUTPUT 0x0003 40 #define STATE_PRJ 0x0004 41 #define STATE_ROOT 0x0005 42 #define STATE_SDFFILE 0x0006 43 #define STATE_ERRORLOG 0x0007 44 #define STATE_BREAKHELP 0x0008 45 #define STATE_UNMERGE 0x0009 46 #define STATE_UTF8 0x000A 47 #define STATE_LANGUAGES 0x000B 48 #define STATE_FORCE_LANGUAGES 0x000C 49 #define STATE_OUTPUTX 0xfe 50 #define STATE_OUTPUTY 0xff 51 52 // set of global variables 53 ByteString sInputFile; 54 sal_Bool bEnableExport; 55 sal_Bool bMergeMode; 56 sal_Bool bErrorLog; 57 sal_Bool bUTF8; 58 ByteString sPrj; 59 ByteString sPrjRoot; 60 ByteString sOutputFile; 61 ByteString sOutputFileX; 62 ByteString sOutputFileY; 63 ByteString sSDFFile; 64 65 /*****************************************************************************/ 66 sal_Bool ParseCommandLine( int argc, char* argv[]) 67 /*****************************************************************************/ 68 { 69 bEnableExport = sal_False; 70 bMergeMode = sal_False; 71 bErrorLog = sal_True; 72 bUTF8 = sal_True; 73 sPrj = ""; 74 sPrjRoot = ""; 75 Export::sLanguages = ""; 76 Export::sForcedLanguages = ""; 77 78 sal_uInt16 nState = STATE_NON; 79 sal_Bool bInput = sal_False; 80 81 // parse command line 82 for( int i = 1; i < argc; i++ ) { 83 if ( ByteString( argv[ i ]).ToUpperAscii() == "-I" ) { 84 nState = STATE_INPUT; // next tokens specifies source files 85 } 86 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-O" ) { 87 nState = STATE_OUTPUT; // next token specifies the dest file 88 } 89 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-X" ) { 90 nState = STATE_OUTPUTX; // next token specifies the dest file 91 } 92 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-Y" ) { 93 nState = STATE_OUTPUTY; // next token specifies the dest file 94 } 95 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-P" ) { 96 nState = STATE_PRJ; // next token specifies the cur. project 97 } 98 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-LF" ) { 99 nState = STATE_FORCE_LANGUAGES; 100 } 101 102 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-R" ) { 103 nState = STATE_ROOT; // next token specifies path to project root 104 } 105 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-M" ) { 106 nState = STATE_SDFFILE; // next token specifies the merge database 107 } 108 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-E" ) { 109 nState = STATE_ERRORLOG; 110 bErrorLog = sal_False; 111 } 112 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-UTF8" ) { 113 nState = STATE_UTF8; 114 bUTF8 = sal_True; 115 } 116 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-NOUTF8" ) { 117 nState = STATE_UTF8; 118 bUTF8 = sal_False; 119 } 120 else if ( ByteString( argv[ i ]).ToUpperAscii() == "-L" ) { 121 nState = STATE_LANGUAGES; 122 } 123 else { 124 switch ( nState ) { 125 case STATE_NON: { 126 return sal_False; // no valid command line 127 } 128 //break; 129 case STATE_INPUT: { 130 sInputFile = argv[ i ]; 131 bInput = sal_True; // source file found 132 } 133 break; 134 case STATE_OUTPUT: { 135 sOutputFile = argv[ i ]; // the dest. file 136 } 137 break; 138 case STATE_OUTPUTX: { 139 sOutputFileX = argv[ i ]; // the dest. file 140 } 141 break; 142 case STATE_OUTPUTY: { 143 sOutputFileY = argv[ i ]; // the dest. file 144 } 145 break; 146 case STATE_PRJ: { 147 sPrj = argv[ i ]; 148 // sPrj.ToLowerAscii(); // the project 149 } 150 break; 151 case STATE_ROOT: { 152 sPrjRoot = argv[ i ]; // path to project root 153 } 154 break; 155 case STATE_SDFFILE: { 156 sSDFFile = argv[ i ]; 157 bMergeMode = sal_True; // activate merge mode, cause merge database found 158 } 159 break; 160 case STATE_LANGUAGES: { 161 Export::sLanguages = argv[ i ]; 162 } 163 case STATE_FORCE_LANGUAGES:{ 164 Export::sForcedLanguages = argv[ i ]; 165 } 166 break; 167 } 168 } 169 } 170 171 if ( bInput ) { 172 // command line is valid 173 bEnableExport = sal_True; 174 return sal_True; 175 } 176 177 // command line is not valid 178 return sal_False; 179 } 180 181 182 /*****************************************************************************/ 183 void Help() 184 /*****************************************************************************/ 185 { 186 fprintf( stdout, "Syntax: HELPEX[-p Prj][-r PrjRoot]-i FileIn ( -o FileOut | -x path -y relfile )[-m DataBase][-e][-b][-u][-L l1,l2,...] -LF l1,l2 \n" ); 187 fprintf( stdout, " Prj: Project\n" ); 188 fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" ); 189 fprintf( stdout, " FileIn: Source file (*.lng)\n" ); 190 fprintf( stdout, " FileOut: Destination file (*.*)\n" ); 191 fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" ); 192 fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (en-US,fr,de...)\n" ); 193 fprintf( stdout, " A fallback language can be defined like this: l1=f1.\n" ); 194 fprintf( stdout, " f1, f2,... are also elements of (en-US,fr,de...)\n" ); 195 fprintf( stdout, " Example: -L fr=en-US\n" ); 196 fprintf( stdout, " Restriction to fr, en-US will be fallback for fr\n" ); 197 fprintf( stdout, " -LF: Force the creation of that languages\n" ); 198 199 } 200 201 /*****************************************************************************/ 202 #ifndef TESTDRIVER 203 204 #if defined(UNX) || defined(OS2) 205 int main( int argc, char *argv[] ) 206 #else 207 int _cdecl main( int argc, char *argv[] ) 208 #endif 209 /*****************************************************************************/ 210 { 211 212 if ( !ParseCommandLine( argc, argv )) { 213 Help(); 214 return 1; 215 } 216 //sal_uInt32 startfull = Export::startMessure(); 217 218 bool hasInputList = sInputFile.GetBuffer()[0]=='@'; 219 // printf("x = %s , y = %s , o = %s\n", sOutputFileX.GetBuffer(), sOutputFileY.GetBuffer() , sOutputFile.GetBuffer() ); 220 bool hasNoError = true; 221 222 if ( sOutputFile.Len() ){ // Merge single file ? 223 //printf("DBG: Inputfile = %s\n",sInputFile.GetBuffer()); 224 HelpParser aParser( sInputFile, bUTF8 , false ); 225 226 if ( bMergeMode ) 227 { 228 229 //sal_uInt64 startreadloc = Export::startMessure(); 230 MergeDataFile aMergeDataFile( sSDFFile, sInputFile , sal_False, RTL_TEXTENCODING_MS_1252 ); 231 //MergeDataFile aMergeDataFile( sSDFFile, sInputFile , sal_False, RTL_TEXTENCODING_MS_1252, false ); 232 //Export::stopMessure( ByteString("read localize.sdf") , startreadloc ); 233 234 hasNoError = aParser.Merge( sSDFFile, sOutputFile , Export::sLanguages , aMergeDataFile ); 235 } 236 else 237 hasNoError = aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot, sInputFile, new XMLFile( '0' ), "help" ); 238 }else if ( sOutputFileX.Len() && sOutputFileY.Len() && hasInputList ) { // Merge multiple files ? 239 if ( bMergeMode ){ 240 241 ifstream aFStream( sInputFile.Copy( 1 , sInputFile.Len() ).GetBuffer() , ios::in ); 242 243 if( !aFStream ){ 244 cerr << "ERROR: - helpex - Can't open the file " << sInputFile.Copy( 1 , sInputFile.Len() ).GetBuffer() << "\n"; 245 exit(-1); 246 } 247 248 vector<ByteString> filelist; 249 rtl::OStringBuffer filename; 250 sal_Char aChar; 251 while( aFStream.get( aChar ) ) 252 { 253 if( aChar == ' ' || aChar == '\n') 254 filelist.push_back( ByteString( filename.makeStringAndClear().getStr() ) ); 255 else 256 filename.append( aChar ); 257 } 258 if( filename.getLength() > 0 ) 259 filelist.push_back( ByteString ( filename.makeStringAndClear().getStr() ) ); 260 261 aFStream.close(); 262 ByteString sHelpFile(""); // dummy 263 //MergeDataFile aMergeDataFile( sSDFFile, sHelpFile , sal_False, RTL_TEXTENCODING_MS_1252, false ); 264 MergeDataFile aMergeDataFile( sSDFFile, sHelpFile , sal_False, RTL_TEXTENCODING_MS_1252 ); 265 266 //aMergeDataFile.Dump(); 267 std::vector<ByteString> aLanguages; 268 HelpParser::parse_languages( aLanguages , aMergeDataFile ); 269 270 bool bCreateDir = true; 271 for( vector<ByteString>::iterator pos = filelist.begin() ; pos != filelist.end() ; ++pos ) 272 { 273 sHelpFile = *pos; 274 cout << ".";cout.flush(); 275 276 HelpParser aParser( sHelpFile , bUTF8 , true ); 277 hasNoError = aParser.Merge( sSDFFile , sOutputFileX , sOutputFileY , true , aLanguages , aMergeDataFile , bCreateDir ); 278 bCreateDir = false; 279 } 280 } 281 } else 282 cerr << "helpex ERROR: Wrong input parameters!\n"; 283 284 //Export::stopMessure( ByteString("full cycle") , startfull ); 285 if( hasNoError ) 286 return 0; 287 else 288 return 1; 289 } 290 #endif 291