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