1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: helpex.cxx,v $
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"
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
;
63 ByteString sOutputFile
;
64 ByteString sOutputFileX
;
65 ByteString sOutputFileY
;
69 /*****************************************************************************/
70 BOOL
ParseCommandLine( int argc
, char* argv
[])
71 /*****************************************************************************/
73 bEnableExport
= FALSE
;
80 Export::sLanguages
= "";
81 Export::sForcedLanguages
= "";
83 USHORT nState
= STATE_NON
;
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
;
117 else if ( ByteString( argv
[ i
] ).ToUpperAscii() == "-QQ" ) {
120 else if ( ByteString( argv
[ i
]).ToUpperAscii() == "-UTF8" ) {
124 else if ( ByteString( argv
[ i
]).ToUpperAscii() == "-NOUTF8" ) {
128 else if ( ByteString( argv
[ i
]).ToUpperAscii() == "-L" ) {
129 nState
= STATE_LANGUAGES
;
134 return FALSE
; // no valid command line
138 sInputFile
= argv
[ i
];
139 bInput
= TRUE
; // source file found
143 sOutputFile
= argv
[ i
]; // the dest. file
146 case STATE_OUTPUTX
: {
147 sOutputFileX
= argv
[ i
]; // the dest. file
150 case STATE_OUTPUTY
: {
151 sOutputFileY
= argv
[ i
]; // the dest. file
156 // sPrj.ToLowerAscii(); // the project
160 sPrjRoot
= argv
[ i
]; // path to project root
163 case STATE_SDFFILE
: {
164 sSDFFile
= argv
[ i
];
165 bMergeMode
= TRUE
; // activate merge mode, cause merge database found
168 case STATE_LANGUAGES
: {
169 Export::sLanguages
= argv
[ i
];
171 case STATE_FORCE_LANGUAGES
:{
172 Export::sForcedLanguages
= argv
[ i
];
180 // command line is valid
181 bEnableExport
= TRUE
;
185 // command line is not valid
190 /*****************************************************************************/
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 /*****************************************************************************/
213 #if defined(UNX) || defined(OS2)
214 int main( int argc
, char *argv
[] )
216 int _cdecl
main( int argc
, char *argv
[] )
218 /*****************************************************************************/
221 if ( !ParseCommandLine( argc
, argv
)) {
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 );
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
);
246 hasNoError
= aParser
.CreateSDF( sOutputFile
, sPrj
, sPrjRoot
, sInputFile
, new XMLFile( '0' ), "help" );
247 }else if ( sOutputFileX
.Len() && sOutputFileY
.Len() && hasInputList
) { // Merge multiple files ?
250 ifstream
aFStream( sInputFile
.Copy( 1 , sInputFile
.Len() ).GetBuffer() , ios::in
);
253 cerr
<< "ERROR: - helpex - Can't open the file " << sInputFile
.Copy( 1 , sInputFile
.Len() ).GetBuffer() << "\n";
257 vector
<ByteString
> filelist
;
258 rtl::OStringBuffer filename
;
260 while( aFStream
.get( aChar
) )
262 if( aChar
== ' ' || aChar
== '\n')
263 filelist
.push_back( ByteString( filename
.makeStringAndClear().getStr() ) );
265 filename
.append( aChar
);
267 if( filename
.getLength() > 0 )
268 filelist
.push_back( ByteString ( filename
.makeStringAndClear().getStr() ) );
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
)
283 cout
<< ".";cout
.flush();
285 HelpParser
aParser( sHelpFile
, bUTF8
, true );
286 hasNoError
= aParser
.Merge( sSDFFile
, sOutputFileX
, sOutputFileY
, true , aLanguages
, aMergeDataFile
, bCreateDir
);
291 cerr
<< "helpex ERROR: Wrong input parameters!\n";
293 //Export::stopMessure( ByteString("full cycle") , startfull );