xref: /trunk/main/l10ntools/source/lngex.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb) !
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_l10ntools.hxx"
30 #include <stdio.h>
31 
32 // local includes
33 #include "lngmerge.hxx"
34 
35 // defines to parse command line
36 #define STATE_NON       0x0001
37 #define STATE_INPUT     0x0002
38 #define STATE_OUTPUT    0x0003
39 #define STATE_PRJ       0x0004
40 #define STATE_ROOT      0x0005
41 #define STATE_MERGESRC  0x0006
42 #define STATE_ERRORLOG  0x0007
43 #define STATE_BREAKHELP 0x0008
44 #define STATE_UNMERGE   0x0009
45 #define STATE_UTF8      0x000A
46 #define STATE_ULF       0x000B
47 #define STATE_LANGUAGES 0x000C
48 
49 // set of global variables
50 ByteString sInputFile;
51 sal_Bool bEnableExport;
52 sal_Bool bMergeMode;
53 sal_Bool bErrorLog;
54 sal_Bool bUTF8;
55 sal_Bool bULF; // ULF = Unicode Language File
56 ByteString sPrj;
57 ByteString sPrjRoot;
58 ByteString sOutputFile;
59 ByteString sMergeSrc;
60 
61 /*****************************************************************************/
62 sal_Bool ParseCommandLine( int argc, char* argv[])
63 /*****************************************************************************/
64 {
65     bEnableExport = sal_False;
66     bMergeMode = sal_False;
67     bErrorLog = sal_True;
68     bUTF8 = sal_True;
69     bULF = sal_False;
70     sPrj = "";
71     sPrjRoot = "";
72     Export::sLanguages = "";
73 
74     sal_uInt16 nState = STATE_NON;
75     sal_Bool bInput = sal_False;
76 
77     // parse command line
78     for( int i = 1; i < argc; i++ ) {
79         ByteString sSwitch( argv[ i ] );
80         sSwitch.ToUpperAscii();
81         if ( sSwitch == "-I" ) {
82             nState = STATE_INPUT; // next tokens specifies source files
83         }
84         else if ( sSwitch  == "-O" ) {
85             nState = STATE_OUTPUT; // next token specifies the dest file
86         }
87         else if ( sSwitch == "-P" ) {
88             nState = STATE_PRJ; // next token specifies the cur. project
89         }
90         else if ( sSwitch == "-R" ) {
91             nState = STATE_ROOT; // next token specifies path to project root
92         }
93         else if ( sSwitch == "-M" ) {
94             nState = STATE_MERGESRC; // next token specifies the merge database
95         }
96         else if ( sSwitch == "-E" ) {
97             nState = STATE_ERRORLOG;
98             bErrorLog = sal_False;
99         }
100         else if ( sSwitch == "-UTF8" ) {
101             nState = STATE_UTF8;
102             bUTF8 = sal_True;
103         }
104 /*      else if ( sSwitch == "-NOUTF8" ) {
105             nState = STATE_UTF8;
106             bUTF8 = sal_False;
107         }*/
108 /*      else if ( sSwitch == "-ULF" ) {
109             nState = STATE_ULF;
110             bULF = sal_True;
111         }*/
112         else if ( sSwitch == "-L" ) {
113             nState = STATE_LANGUAGES;
114         }
115         else {
116             switch ( nState ) {
117                 case STATE_NON: {
118                     return sal_False;   // no valid command line
119                 }
120                 //break;
121                 case STATE_INPUT: {
122                     sInputFile = argv[ i ];
123                     bInput = sal_True; // source file found
124                 }
125                 break;
126                 case STATE_OUTPUT: {
127                     sOutputFile = argv[ i ]; // the dest. file
128                 }
129                 break;
130                 case STATE_PRJ: {
131                     sPrj = argv[ i ];
132 //                  sPrj.ToLowerAscii(); // the project
133                 }
134                 break;
135                 case STATE_ROOT: {
136                     sPrjRoot = argv[ i ]; // path to project root
137                 }
138                 break;
139                 case STATE_MERGESRC: {
140                     sMergeSrc = argv[ i ];
141                     bMergeMode = sal_True; // activate merge mode, cause merge database found
142                 }
143                 break;
144                 case STATE_LANGUAGES: {
145                     Export::sLanguages = argv[ i ];
146                 }
147                 break;
148             }
149         }
150     }
151 
152     if ( bInput ) {
153         // command line is valid
154         bULF = sal_True;
155         bEnableExport = sal_True;
156         return sal_True;
157     }
158 
159     // command line is not valid
160     return sal_False;
161 }
162 
163 
164 /*****************************************************************************/
165 void Help()
166 /*****************************************************************************/
167 {
168     fprintf( stdout, "Syntax:ULFEX[-p Prj][-r PrjRoot]-i FileIn -o FileOut[-m DataBase][-L l1,l2,...]\n" );
169     fprintf( stdout, " Prj:      Project\n" );
170     fprintf( stdout, " PrjRoot:  Path to project root (..\\.. etc.)\n" );
171     fprintf( stdout, " FileIn:   Source file (*.lng)\n" );
172     fprintf( stdout, " FileOut:  Destination file (*.*)\n" );
173     fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
174     fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
175     fprintf( stdout, "     A fallback language can be defined like this: l1=f1.\n" );
176     fprintf( stdout, "     f1, f2,... are also elements of (de,en-US...)\n" );
177     fprintf( stdout, "     Example: -L de,es=en-US\n" );
178     fprintf( stdout, "              Restriction to de and es, en-US will be fallback for es\n" );
179 }
180 
181 /*****************************************************************************/
182 #if defined(UNX) || defined(OS2)
183 int main( int argc, char *argv[] )
184 #else
185 int _cdecl main( int argc, char *argv[] )
186 #endif
187 /*****************************************************************************/
188 {
189     if ( !ParseCommandLine( argc, argv )) {
190         Help();
191         return 1;
192     }
193         fprintf(stdout, ".");
194         fflush( stdout );
195 
196     if ( sOutputFile.Len()) {
197         LngParser aParser( sInputFile, bUTF8, bULF );
198         if ( bMergeMode )
199             aParser.Merge( sMergeSrc, sOutputFile , sPrj );
200         else
201             aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot );
202     }
203 
204     return 0;
205 }
206