merge the formfield patch from ooo-build
[ooovba.git] / transex3 / source / lngex.cxx
blobfcc379440bdfa38d30c05dbf16f50ddcb6128741
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: lngex.cxx,v $
10 * $Revision: 1.18 $
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>
35 // local includes
36 #include "lngmerge.hxx"
38 // defines to parse command line
39 #define STATE_NON 0x0001
40 #define STATE_INPUT 0x0002
41 #define STATE_OUTPUT 0x0003
42 #define STATE_PRJ 0x0004
43 #define STATE_ROOT 0x0005
44 #define STATE_MERGESRC 0x0006
45 #define STATE_ERRORLOG 0x0007
46 #define STATE_BREAKHELP 0x0008
47 #define STATE_UNMERGE 0x0009
48 #define STATE_UTF8 0x000A
49 #define STATE_ULF 0x000B
50 #define STATE_LANGUAGES 0x000C
52 // set of global variables
53 ByteString sInputFile;
54 BOOL bEnableExport;
55 BOOL bMergeMode;
56 BOOL bErrorLog;
57 BOOL bUTF8;
58 BOOL bULF; // ULF = Unicode Language File
59 bool bQuiet;
60 ByteString sPrj;
61 ByteString sPrjRoot;
62 ByteString sOutputFile;
63 ByteString sMergeSrc;
65 /*****************************************************************************/
66 BOOL ParseCommandLine( int argc, char* argv[])
67 /*****************************************************************************/
69 bEnableExport = FALSE;
70 bMergeMode = FALSE;
71 bErrorLog = TRUE;
72 bUTF8 = TRUE;
73 bULF = FALSE;
74 bQuiet = false;
75 sPrj = "";
76 sPrjRoot = "";
77 Export::sLanguages = "";
79 USHORT nState = STATE_NON;
80 BOOL bInput = FALSE;
82 // parse command line
83 for( int i = 1; i < argc; i++ ) {
84 ByteString sSwitch( argv[ i ] );
85 sSwitch.ToUpperAscii();
86 if ( sSwitch == "-I" ) {
87 nState = STATE_INPUT; // next tokens specifies source files
89 else if ( sSwitch == "-O" ) {
90 nState = STATE_OUTPUT; // next token specifies the dest file
92 else if ( sSwitch == "-P" ) {
93 nState = STATE_PRJ; // next token specifies the cur. project
95 else if ( sSwitch == "-R" ) {
96 nState = STATE_ROOT; // next token specifies path to project root
98 else if ( sSwitch == "-QQ" ) {
99 bQuiet = true;
101 else if ( sSwitch == "-M" ) {
102 nState = STATE_MERGESRC; // next token specifies the merge database
104 else if ( sSwitch == "-E" ) {
105 nState = STATE_ERRORLOG;
106 bErrorLog = FALSE;
108 else if ( sSwitch == "-UTF8" ) {
109 nState = STATE_UTF8;
110 bUTF8 = TRUE;
112 /* else if ( sSwitch == "-NOUTF8" ) {
113 nState = STATE_UTF8;
114 bUTF8 = FALSE;
116 /* else if ( sSwitch == "-ULF" ) {
117 nState = STATE_ULF;
118 bULF = TRUE;
120 else if ( sSwitch == "-L" ) {
121 nState = STATE_LANGUAGES;
123 else {
124 switch ( nState ) {
125 case STATE_NON: {
126 return FALSE; // no valid command line
128 //break;
129 case STATE_INPUT: {
130 sInputFile = argv[ i ];
131 bInput = TRUE; // source file found
133 break;
134 case STATE_OUTPUT: {
135 sOutputFile = argv[ i ]; // the dest. file
137 break;
138 case STATE_PRJ: {
139 sPrj = argv[ i ];
140 // sPrj.ToLowerAscii(); // the project
142 break;
143 case STATE_ROOT: {
144 sPrjRoot = argv[ i ]; // path to project root
146 break;
147 case STATE_MERGESRC: {
148 sMergeSrc = argv[ i ];
149 bMergeMode = TRUE; // activate merge mode, cause merge database found
151 break;
152 case STATE_LANGUAGES: {
153 Export::sLanguages = argv[ i ];
155 break;
160 if ( bInput ) {
161 // command line is valid
162 bULF = TRUE;
163 bEnableExport = TRUE;
164 return TRUE;
167 // command line is not valid
168 return FALSE;
172 /*****************************************************************************/
173 void Help()
174 /*****************************************************************************/
176 //fprintf( stdout, "Syntax:ULFEX[-p Prj][-r PrjRoot]-i FileIn -o FileOut[-m DataBase][-e][-b][-u][-NOUTF8][-ULF][-L l1,l2,...]\n" );
177 fprintf( stdout, "Syntax:ULFEX[-p Prj][-r PrjRoot]-i FileIn -o FileOut[-m DataBase][-L l1,l2,...]\n" );
178 fprintf( stdout, " Prj: Project\n" );
179 fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" );
180 fprintf( stdout, " FileIn: Source file (*.lng)\n" );
181 fprintf( stdout, " FileOut: Destination file (*.*)\n" );
182 fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
183 fprintf( stdout, " -QQ: quite output\n" );
184 //fprintf( stdout, " -NOUTF8: disable UTF8 as language independent encoding\n" );
185 //fprintf( stdout, " -ULF: enables Unicode Language File format, leads to UTF8 encoded version of lng files" );
186 fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
187 fprintf( stdout, " A fallback language can be defined like this: l1=f1.\n" );
188 fprintf( stdout, " f1, f2,... are also elements of (de,en-US...)\n" );
189 fprintf( stdout, " Example: -L de,es=en-US\n" );
190 fprintf( stdout, " Restriction to de and es, en-US will be fallback for es\n" );
193 /*****************************************************************************/
194 #if defined(UNX) || defined(OS2)
195 int main( int argc, char *argv[] )
196 #else
197 int _cdecl main( int argc, char *argv[] )
198 #endif
199 /*****************************************************************************/
201 if ( !ParseCommandLine( argc, argv )) {
202 Help();
203 return 1;
205 if( !bQuiet ){
206 fprintf( stdout, "\nUlfEx 1 Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.\n" );
207 fprintf( stdout, "====================================================================\n" );
208 fprintf( stdout, "\nProcessing File %s ...\n", sInputFile.GetBuffer());
209 }else
211 fprintf(stdout, ".");
212 fflush( stdout );
215 if ( sOutputFile.Len()) {
216 LngParser aParser( sInputFile, bUTF8, bULF , bQuiet );
217 if ( bMergeMode )
218 aParser.Merge( sMergeSrc, sOutputFile , sPrj );
219 else
220 aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot );
223 if( !bQuiet ) fprintf( stdout, "\n=================================================\n\n" );
225 return 0;