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