Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "sal/config.h"
30 : :
31 : : #include <iostream>
32 : :
33 : : #include <stdio.h>
34 : : #include <stdlib.h>
35 : :
36 : : #include "sal/main.h"
37 : :
38 : : #include "helpmerge.hxx"
39 : :
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
54 : :
55 : : // set of global variables
56 : 0 : rtl::OString sInputFile;
57 : : sal_Bool bEnableExport;
58 : : sal_Bool bMergeMode;
59 : 0 : rtl::OString sPrj;
60 : 0 : rtl::OString sPrjRoot;
61 : 0 : rtl::OString sOutputFile;
62 : 0 : rtl::OString sOutputFileX;
63 : 0 : rtl::OString sOutputFileY;
64 : 0 : rtl::OString sSDFFile;
65 : :
66 : : /*****************************************************************************/
67 : 0 : sal_Bool ParseCommandLine( int argc, char* argv[])
68 : : /*****************************************************************************/
69 : : {
70 : 0 : bEnableExport = sal_False;
71 : 0 : bMergeMode = sal_False;
72 : 0 : sPrj = "";
73 : 0 : sPrjRoot = "";
74 : 0 : Export::sLanguages = "";
75 : 0 : Export::sForcedLanguages = "";
76 : :
77 : 0 : sal_uInt16 nState = STATE_NON;
78 : 0 : sal_Bool bInput = sal_False;
79 : :
80 : : // parse command line
81 : 0 : for( int i = 1; i < argc; i++ )
82 : : {
83 : 0 : rtl::OString aArg = rtl::OString(argv[i]).toAsciiUpperCase();
84 : 0 : if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-I")))
85 : 0 : nState = STATE_INPUT; // next tokens specifies source files
86 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-O")))
87 : 0 : nState = STATE_OUTPUT; // next token specifies the dest file
88 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-X")))
89 : 0 : nState = STATE_OUTPUTX; // next token specifies the dest file
90 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-Y" )))
91 : 0 : nState = STATE_OUTPUTY; // next token specifies the dest file
92 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-P" )))
93 : 0 : nState = STATE_PRJ; // next token specifies the cur. project
94 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-LF")))
95 : 0 : nState = STATE_FORCE_LANGUAGES;
96 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-R" )))
97 : 0 : nState = STATE_ROOT; // next token specifies path to project root
98 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-M" )))
99 : 0 : nState = STATE_SDFFILE; // next token specifies the merge database
100 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-E" )))
101 : : {
102 : 0 : nState = STATE_ERRORLOG;
103 : : }
104 : 0 : else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-L" )))
105 : 0 : nState = STATE_LANGUAGES;
106 : : else
107 : : {
108 : 0 : switch ( nState )
109 : : {
110 : : case STATE_NON: {
111 : 0 : return sal_False; // no valid command line
112 : : }
113 : : //break;
114 : : case STATE_INPUT: {
115 : 0 : sInputFile = argv[ i ];
116 : 0 : bInput = sal_True; // source file found
117 : : }
118 : 0 : break;
119 : : case STATE_OUTPUT: {
120 : 0 : sOutputFile = argv[ i ]; // the dest. file
121 : : }
122 : 0 : break;
123 : : case STATE_OUTPUTX: {
124 : 0 : sOutputFileX = argv[ i ]; // the dest. file
125 : : }
126 : 0 : break;
127 : : case STATE_OUTPUTY: {
128 : 0 : sOutputFileY = argv[ i ]; // the dest. file
129 : : }
130 : 0 : break;
131 : : case STATE_PRJ: {
132 : 0 : sPrj = argv[ i ];
133 : : }
134 : 0 : break;
135 : : case STATE_ROOT: {
136 : 0 : sPrjRoot = argv[ i ]; // path to project root
137 : : }
138 : 0 : break;
139 : : case STATE_SDFFILE: {
140 : 0 : sSDFFile = argv[ i ];
141 : 0 : bMergeMode = sal_True; // activate merge mode, cause merge database found
142 : : }
143 : 0 : break;
144 : : case STATE_LANGUAGES: {
145 : 0 : Export::sLanguages = argv[ i ];
146 : : }
147 : : case STATE_FORCE_LANGUAGES:{
148 : 0 : Export::sForcedLanguages = argv[ i ];
149 : : }
150 : 0 : break;
151 : : }
152 : : }
153 : 0 : }
154 : :
155 : 0 : if ( bInput ) {
156 : : // command line is valid
157 : 0 : bEnableExport = sal_True;
158 : 0 : return sal_True;
159 : : }
160 : :
161 : : // command line is not valid
162 : 0 : return sal_False;
163 : : }
164 : :
165 : :
166 : : /*****************************************************************************/
167 : 0 : void Help()
168 : : /*****************************************************************************/
169 : : {
170 : 0 : 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" );
171 : 0 : fprintf( stdout, " Prj: Project\n" );
172 : 0 : fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" );
173 : 0 : fprintf( stdout, " FileIn: Source file (*.lng)\n" );
174 : 0 : fprintf( stdout, " FileOut: Destination file (*.*)\n" );
175 : 0 : fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
176 : 0 : fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (en-US,fr,de...)\n" );
177 : 0 : fprintf( stdout, " -LF: Force the creation of that languages\n" );
178 : :
179 : 0 : }
180 : :
181 : : /*****************************************************************************/
182 : : #ifndef TESTDRIVER
183 : :
184 : 0 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
185 : 0 : if ( !ParseCommandLine( argc, argv )) {
186 : 0 : Help();
187 : 0 : return 1;
188 : : }
189 : : //sal_uInt32 startfull = Export::startMessure();
190 : :
191 : 0 : bool hasInputList = sInputFile[0]=='@';
192 : 0 : bool hasNoError = true;
193 : :
194 : 0 : if ( sOutputFile.getLength() ){ // Merge single file ?
195 : 0 : HelpParser aParser( sInputFile );
196 : :
197 : 0 : if ( bMergeMode )
198 : : {
199 : : //sal_uInt64 startreadloc = Export::startMessure();
200 : 0 : MergeDataFile aMergeDataFile(sSDFFile, sInputFile, false);
201 : :
202 : 0 : hasNoError = aParser.Merge( sSDFFile, sOutputFile , Export::sLanguages , aMergeDataFile );
203 : : }
204 : : else
205 : 0 : hasNoError = aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot, sInputFile, new XMLFile( rtl::OUString('0') ), "help" );
206 : 0 : }else if ( sOutputFileX.getLength() && sOutputFileY.getLength() && hasInputList ) { // Merge multiple files ?
207 : 0 : if ( bMergeMode ){
208 : :
209 : 0 : ifstream aFStream( sInputFile.copy( 1 ).getStr() , ios::in );
210 : :
211 : 0 : if( !aFStream ){
212 : 0 : std::cerr << "ERROR: - helpex - Can't open the file " << sInputFile.copy( 1 ).getStr() << "\n";
213 : 0 : std::exit(EXIT_FAILURE);
214 : : }
215 : :
216 : 0 : vector<rtl::OString> filelist;
217 : 0 : rtl::OStringBuffer filename;
218 : : sal_Char aChar;
219 : 0 : while( aFStream.get( aChar ) )
220 : : {
221 : 0 : if( aChar == ' ' || aChar == '\n')
222 : 0 : filelist.push_back(filename.makeStringAndClear());
223 : : else
224 : 0 : filename.append( aChar );
225 : : }
226 : 0 : if( filename.getLength() > 0 )
227 : 0 : filelist.push_back(filename.makeStringAndClear());
228 : :
229 : 0 : aFStream.close();
230 : 0 : rtl::OString sHelpFile; // dummy
231 : 0 : MergeDataFile aMergeDataFile( sSDFFile, sHelpFile, false );
232 : :
233 : 0 : std::vector<rtl::OString> aLanguages;
234 : 0 : HelpParser::parse_languages( aLanguages , aMergeDataFile );
235 : :
236 : 0 : bool bCreateDir = true;
237 : 0 : for( vector<rtl::OString>::iterator pos = filelist.begin() ; pos != filelist.end() ; ++pos )
238 : : {
239 : 0 : sHelpFile = *pos;
240 : :
241 : 0 : HelpParser aParser( sHelpFile );
242 : 0 : hasNoError = aParser.Merge( sSDFFile , sOutputFileX , sOutputFileY , true , aLanguages , aMergeDataFile , bCreateDir );
243 : 0 : bCreateDir = false;
244 : 0 : }
245 : : }
246 : : } else
247 : 0 : std::cerr << "helpex ERROR: Wrong input parameters!\n";
248 : :
249 : 0 : if( hasNoError )
250 : 0 : return 0;
251 : : else
252 : 0 : return 1;
253 : 0 : }
254 : : #endif
255 : :
256 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|