1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
38 #include "helpmerge.hxx"
40 // defines to parse command line
41 #define STATE_NON 0x0001
42 #define STATE_INPUT 0x0002
43 #define STATE_OUTPUT 0x0003
44 #define STATE_PRJ 0x0004
45 #define STATE_ROOT 0x0005
46 #define STATE_SDFFILE 0x0006
47 #define STATE_ERRORLOG 0x0007
48 #define STATE_BREAKHELP 0x0008
49 #define STATE_UNMERGE 0x0009
50 #define STATE_LANGUAGES 0x000A
51 #define STATE_FORCE_LANGUAGES 0x000B
52 #define STATE_OUTPUTX 0xfe
53 #define STATE_OUTPUTY 0xff
55 // set of global variables
56 rtl::OString sInputFile
;
57 sal_Bool bEnableExport
;
62 rtl::OString sPrjRoot
;
63 rtl::OString sOutputFile
;
64 rtl::OString sOutputFileX
;
65 rtl::OString sOutputFileY
;
66 rtl::OString sSDFFile
;
68 /*****************************************************************************/
69 sal_Bool
ParseCommandLine( int argc
, char* argv
[])
70 /*****************************************************************************/
72 bEnableExport
= sal_False
;
73 bMergeMode
= sal_False
;
78 Export::sLanguages
= "";
79 Export::sForcedLanguages
= "";
81 sal_uInt16 nState
= STATE_NON
;
82 sal_Bool bInput
= sal_False
;
85 for( int i
= 1; i
< argc
; i
++ )
87 rtl::OString aArg
= rtl::OString(argv
[i
]).toAsciiUpperCase();
88 if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-I")))
89 nState
= STATE_INPUT
; // next tokens specifies source files
90 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-O")))
91 nState
= STATE_OUTPUT
; // next token specifies the dest file
92 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-X")))
93 nState
= STATE_OUTPUTX
; // next token specifies the dest file
94 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-Y" )))
95 nState
= STATE_OUTPUTY
; // next token specifies the dest file
96 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-P" )))
97 nState
= STATE_PRJ
; // next token specifies the cur. project
98 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-LF")))
99 nState
= STATE_FORCE_LANGUAGES
;
100 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-R" )))
101 nState
= STATE_ROOT
; // next token specifies path to project root
102 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-M" )))
103 nState
= STATE_SDFFILE
; // next token specifies the merge database
104 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-E" )))
106 nState
= STATE_ERRORLOG
;
107 bErrorLog
= sal_False
;
109 else if (aArg
.equalsL(RTL_CONSTASCII_STRINGPARAM("-L" )))
110 nState
= STATE_LANGUAGES
;
116 return sal_False
; // no valid command line
120 sInputFile
= argv
[ i
];
121 bInput
= sal_True
; // source file found
125 sOutputFile
= argv
[ i
]; // the dest. file
128 case STATE_OUTPUTX
: {
129 sOutputFileX
= argv
[ i
]; // the dest. file
132 case STATE_OUTPUTY
: {
133 sOutputFileY
= argv
[ i
]; // the dest. file
141 sPrjRoot
= argv
[ i
]; // path to project root
144 case STATE_SDFFILE
: {
145 sSDFFile
= argv
[ i
];
146 bMergeMode
= sal_True
; // activate merge mode, cause merge database found
149 case STATE_LANGUAGES
: {
150 Export::sLanguages
= argv
[ i
];
152 case STATE_FORCE_LANGUAGES
:{
153 Export::sForcedLanguages
= argv
[ i
];
161 // command line is valid
162 bEnableExport
= sal_True
;
166 // command line is not valid
171 /*****************************************************************************/
173 /*****************************************************************************/
175 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" );
176 fprintf( stdout
, " Prj: Project\n" );
177 fprintf( stdout
, " PrjRoot: Path to project root (..\\.. etc.)\n" );
178 fprintf( stdout
, " FileIn: Source file (*.lng)\n" );
179 fprintf( stdout
, " FileOut: Destination file (*.*)\n" );
180 fprintf( stdout
, " DataBase: Mergedata (*.sdf)\n" );
181 fprintf( stdout
, " -L: Restrict the handled languages. l1,l2,... are elements of (en-US,fr,de...)\n" );
182 fprintf( stdout
, " -LF: Force the creation of that languages\n" );
186 /*****************************************************************************/
189 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
) {
190 if ( !ParseCommandLine( argc
, argv
)) {
194 //sal_uInt32 startfull = Export::startMessure();
196 bool hasInputList
= sInputFile
[0]=='@';
197 bool hasNoError
= true;
199 if ( sOutputFile
.getLength() ){ // Merge single file ?
200 HelpParser
aParser( sInputFile
, bUTF8
, false );
204 //sal_uInt64 startreadloc = Export::startMessure();
205 MergeDataFile
aMergeDataFile(sSDFFile
, sInputFile
, sal_False
);
207 hasNoError
= aParser
.Merge( sSDFFile
, sOutputFile
, Export::sLanguages
, aMergeDataFile
);
210 hasNoError
= aParser
.CreateSDF( sOutputFile
, sPrj
, sPrjRoot
, sInputFile
, new XMLFile( rtl::OUString('0') ), "help" );
211 }else if ( sOutputFileX
.getLength() && sOutputFileY
.getLength() && hasInputList
) { // Merge multiple files ?
214 ifstream
aFStream( sInputFile
.copy( 1 ).getStr() , ios::in
);
217 std::cerr
<< "ERROR: - helpex - Can't open the file " << sInputFile
.copy( 1 ).getStr() << "\n";
218 std::exit(EXIT_FAILURE
);
221 vector
<rtl::OString
> filelist
;
222 rtl::OStringBuffer filename
;
224 while( aFStream
.get( aChar
) )
226 if( aChar
== ' ' || aChar
== '\n')
227 filelist
.push_back(filename
.makeStringAndClear());
229 filename
.append( aChar
);
231 if( filename
.getLength() > 0 )
232 filelist
.push_back(filename
.makeStringAndClear());
235 rtl::OString sHelpFile
; // dummy
236 MergeDataFile
aMergeDataFile( sSDFFile
, sHelpFile
, sal_False
);
238 std::vector
<rtl::OString
> aLanguages
;
239 HelpParser::parse_languages( aLanguages
, aMergeDataFile
);
241 bool bCreateDir
= true;
242 for( vector
<rtl::OString
>::iterator pos
= filelist
.begin() ; pos
!= filelist
.end() ; ++pos
)
246 HelpParser
aParser( sHelpFile
, bUTF8
, true );
247 hasNoError
= aParser
.Merge( sSDFFile
, sOutputFileX
, sOutputFileY
, true , aLanguages
, aMergeDataFile
, bCreateDir
);
252 std::cerr
<< "helpex ERROR: Wrong input parameters!\n";
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */