Bump for 3.6-28
[LibreOffice.git] / l10ntools / source / lngex.cxx
blob5f8f8cd57031e27c91812b19e8f9129bb7ea5747
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"
31 #include <stdio.h>
33 #include "sal/main.h"
35 #include "lngmerge.hxx"
37 // defines to parse command line
38 #define STATE_NON 0x0001
39 #define STATE_INPUT 0x0002
40 #define STATE_OUTPUT 0x0003
41 #define STATE_PRJ 0x0004
42 #define STATE_ROOT 0x0005
43 #define STATE_MERGESRC 0x0006
44 #define STATE_ERRORLOG 0x0007
45 #define STATE_BREAKHELP 0x0008
46 #define STATE_UNMERGE 0x0009
47 #define STATE_ULF 0x000A
48 #define STATE_LANGUAGES 0x000B
50 // set of global variables
51 rtl::OString sInputFile;
52 sal_Bool bEnableExport;
53 sal_Bool bMergeMode;
54 sal_Bool bErrorLog;
55 sal_Bool bUTF8;
56 sal_Bool bULF; // ULF = Unicode Language File
57 rtl::OString sPrj;
58 rtl::OString sPrjRoot;
59 rtl::OString sOutputFile;
60 rtl::OString sMergeSrc;
62 /*****************************************************************************/
63 sal_Bool ParseCommandLine( int argc, char* argv[])
64 /*****************************************************************************/
66 bEnableExport = sal_False;
67 bMergeMode = sal_False;
68 bErrorLog = sal_True;
69 bUTF8 = sal_True;
70 bULF = sal_False;
71 sPrj = "";
72 sPrjRoot = "";
73 Export::sLanguages = "";
75 sal_uInt16 nState = STATE_NON;
76 sal_Bool bInput = sal_False;
78 // parse command line
79 for( int i = 1; i < argc; i++ ) {
80 rtl::OString sSwitch = rtl::OString(argv[i]).toAsciiUpperCase();
81 if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-I")))
82 nState = STATE_INPUT; // next tokens specifies source files
83 else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-O")))
84 nState = STATE_OUTPUT; // next token specifies the dest file
85 else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-P")))
86 nState = STATE_PRJ; // next token specifies the cur. project
87 else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-R")))
88 nState = STATE_ROOT; // next token specifies path to project root
89 else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-M")))
90 nState = STATE_MERGESRC; // next token specifies the merge database
91 else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-E")))
93 nState = STATE_ERRORLOG;
94 bErrorLog = sal_False;
96 else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-L")))
97 nState = STATE_LANGUAGES;
98 else
100 switch ( nState ) {
101 case STATE_NON: {
102 return sal_False; // no valid command line
104 //break;
105 case STATE_INPUT: {
106 sInputFile = argv[ i ];
107 bInput = sal_True; // source file found
109 break;
110 case STATE_OUTPUT: {
111 sOutputFile = argv[ i ]; // the dest. file
113 break;
114 case STATE_PRJ: {
115 sPrj = argv[ i ];
117 break;
118 case STATE_ROOT: {
119 sPrjRoot = argv[ i ]; // path to project root
121 break;
122 case STATE_MERGESRC: {
123 sMergeSrc = argv[ i ];
124 bMergeMode = sal_True; // activate merge mode, cause merge database found
126 break;
127 case STATE_LANGUAGES: {
128 Export::sLanguages = argv[ i ];
130 break;
135 if ( bInput ) {
136 // command line is valid
137 bULF = sal_True;
138 bEnableExport = sal_True;
139 return sal_True;
142 // command line is not valid
143 return sal_False;
147 /*****************************************************************************/
148 void Help()
149 /*****************************************************************************/
151 fprintf( stdout, "Syntax:ULFEX[-p Prj][-r PrjRoot]-i FileIn -o FileOut[-m DataBase][-L l1,l2,...]\n" );
152 fprintf( stdout, " Prj: Project\n" );
153 fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" );
154 fprintf( stdout, " FileIn: Source file (*.lng)\n" );
155 fprintf( stdout, " FileOut: Destination file (*.*)\n" );
156 fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
157 fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
160 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
161 if ( !ParseCommandLine( argc, argv ))
163 Help();
164 return 1;
167 if (!sOutputFile.isEmpty())
169 LngParser aParser( sInputFile, bUTF8, bULF );
170 if ( bMergeMode )
171 aParser.Merge(sMergeSrc, sOutputFile);
172 else
173 aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot );
176 return 0;
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */