xref: /AOO41X/main/l10ntools/source/lngex.cxx (revision 3cd96b95fb0ad23ccdd883f9b15a685c459d45ca)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_l10ntools.hxx"
26 #include <stdio.h>
27 
28 // local includes
29 #include "lngmerge.hxx"
30 
31 // defines to parse command line
32 #define STATE_NON       0x0001
33 #define STATE_INPUT     0x0002
34 #define STATE_OUTPUT    0x0003
35 #define STATE_PRJ       0x0004
36 #define STATE_ROOT      0x0005
37 #define STATE_MERGESRC  0x0006
38 #define STATE_ERRORLOG  0x0007
39 #define STATE_BREAKHELP 0x0008
40 #define STATE_UNMERGE   0x0009
41 #define STATE_UTF8      0x000A
42 #define STATE_ULF       0x000B
43 #define STATE_LANGUAGES 0x000C
44 
45 // set of global variables
46 ByteString sInputFile;
47 sal_Bool bEnableExport;
48 sal_Bool bMergeMode;
49 sal_Bool bErrorLog;
50 sal_Bool bUTF8;
51 sal_Bool bULF; // ULF = Unicode Language File
52 ByteString sPrj;
53 ByteString sPrjRoot;
54 ByteString sOutputFile;
55 ByteString sMergeSrc;
56 
57 /*****************************************************************************/
ParseCommandLine(int argc,char * argv[])58 sal_Bool ParseCommandLine( int argc, char* argv[])
59 /*****************************************************************************/
60 {
61     bEnableExport = sal_False;
62     bMergeMode = sal_False;
63     bErrorLog = sal_True;
64     bUTF8 = sal_True;
65     bULF = sal_False;
66     sPrj = "";
67     sPrjRoot = "";
68     Export::sLanguages = "";
69 
70     sal_uInt16 nState = STATE_NON;
71     sal_Bool bInput = sal_False;
72 
73     // parse command line
74     for( int i = 1; i < argc; i++ ) {
75         ByteString sSwitch( argv[ i ] );
76         sSwitch.ToUpperAscii();
77         if ( sSwitch == "-I" ) {
78             nState = STATE_INPUT; // next tokens specifies source files
79         }
80         else if ( sSwitch  == "-O" ) {
81             nState = STATE_OUTPUT; // next token specifies the dest file
82         }
83         else if ( sSwitch == "-P" ) {
84             nState = STATE_PRJ; // next token specifies the cur. project
85         }
86         else if ( sSwitch == "-R" ) {
87             nState = STATE_ROOT; // next token specifies path to project root
88         }
89         else if ( sSwitch == "-M" ) {
90             nState = STATE_MERGESRC; // next token specifies the merge database
91         }
92         else if ( sSwitch == "-E" ) {
93             nState = STATE_ERRORLOG;
94             bErrorLog = sal_False;
95         }
96         else if ( sSwitch == "-UTF8" ) {
97             nState = STATE_UTF8;
98             bUTF8 = sal_True;
99         }
100 /*      else if ( sSwitch == "-NOUTF8" ) {
101             nState = STATE_UTF8;
102             bUTF8 = sal_False;
103         }*/
104 /*      else if ( sSwitch == "-ULF" ) {
105             nState = STATE_ULF;
106             bULF = sal_True;
107         }*/
108         else if ( sSwitch == "-L" ) {
109             nState = STATE_LANGUAGES;
110         }
111         else {
112             switch ( nState ) {
113                 case STATE_NON: {
114                     return sal_False;   // no valid command line
115                 }
116                 //break;
117                 case STATE_INPUT: {
118                     sInputFile = argv[ i ];
119                     bInput = sal_True; // source file found
120                 }
121                 break;
122                 case STATE_OUTPUT: {
123                     sOutputFile = argv[ i ]; // the dest. file
124                 }
125                 break;
126                 case STATE_PRJ: {
127                     sPrj = argv[ i ];
128 //                  sPrj.ToLowerAscii(); // the project
129                 }
130                 break;
131                 case STATE_ROOT: {
132                     sPrjRoot = argv[ i ]; // path to project root
133                 }
134                 break;
135                 case STATE_MERGESRC: {
136                     sMergeSrc = argv[ i ];
137                     bMergeMode = sal_True; // activate merge mode, cause merge database found
138                 }
139                 break;
140                 case STATE_LANGUAGES: {
141                     Export::sLanguages = argv[ i ];
142                 }
143                 break;
144             }
145         }
146     }
147 
148     if ( bInput ) {
149         // command line is valid
150         bULF = sal_True;
151         bEnableExport = sal_True;
152         return sal_True;
153     }
154 
155     // command line is not valid
156     return sal_False;
157 }
158 
159 
160 /*****************************************************************************/
Help()161 void Help()
162 /*****************************************************************************/
163 {
164     fprintf( stdout, "Syntax:ULFEX[-p Prj][-r PrjRoot]-i FileIn -o FileOut[-m DataBase][-L l1,l2,...]\n" );
165     fprintf( stdout, " Prj:      Project\n" );
166     fprintf( stdout, " PrjRoot:  Path to project root (..\\.. etc.)\n" );
167     fprintf( stdout, " FileIn:   Source file (*.lng)\n" );
168     fprintf( stdout, " FileOut:  Destination file (*.*)\n" );
169     fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
170     fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
171     fprintf( stdout, "     A fallback language can be defined like this: l1=f1.\n" );
172     fprintf( stdout, "     f1, f2,... are also elements of (de,en-US...)\n" );
173     fprintf( stdout, "     Example: -L de,es=en-US\n" );
174     fprintf( stdout, "              Restriction to de and es, en-US will be fallback for es\n" );
175 }
176 
177 /*****************************************************************************/
178 #if defined(UNX) || defined(OS2)
main(int argc,char * argv[])179 int main( int argc, char *argv[] )
180 #else
181 int _cdecl main( int argc, char *argv[] )
182 #endif
183 /*****************************************************************************/
184 {
185     if ( !ParseCommandLine( argc, argv )) {
186         Help();
187         return 1;
188     }
189         fprintf(stdout, ".");
190         fflush( stdout );
191 
192     if ( sOutputFile.Len()) {
193         LngParser aParser( sInputFile, bUTF8, bULF );
194         if ( bMergeMode )
195             aParser.Merge( sMergeSrc, sOutputFile , sPrj );
196         else
197             aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot );
198     }
199 
200     return 0;
201 }
202