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