summaryrefslogtreecommitdiff
path: root/l10ntools/source/common.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'l10ntools/source/common.cxx')
-rw-r--r--l10ntools/source/common.cxx153
1 files changed, 153 insertions, 0 deletions
diff --git a/l10ntools/source/common.cxx b/l10ntools/source/common.cxx
new file mode 100644
index 000000000000..35302117a984
--- /dev/null
+++ b/l10ntools/source/common.cxx
@@ -0,0 +1,153 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "common.hxx"
+#include "po.cxx"
+
+//flags for handleArguments()
+#define STATE_NON 0x0001
+#define STATE_INPUT 0x0002
+#define STATE_OUTPUT 0x0003
+#define STATE_MERGESRC 0x0005
+#define STATE_LANGUAGES 0x0006
+
+namespace common {
+
+bool handleArguments(
+ int argc, char * argv[], HandledArgs& o_aHandledArgs)
+{
+ o_aHandledArgs = HandledArgs();
+ sal_uInt16 nState = STATE_NON;
+
+ for( int i = 1; i < argc; i++ )
+ {
+ if ( OString( argv[ i ] ).toAsciiUpperCase() == "-I" )
+ {
+ nState = STATE_INPUT; // next token specifies source file
+ }
+ else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-O" )
+ {
+ nState = STATE_OUTPUT; // next token specifies the dest file
+ }
+ else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" )
+ {
+ nState = STATE_MERGESRC; // next token specifies the merge database
+ }
+ else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" )
+ {
+ nState = STATE_LANGUAGES;
+ }
+ else
+ {
+ switch ( nState )
+ {
+ case STATE_NON:
+ {
+ return false; // no valid command line
+ }
+ case STATE_INPUT:
+ {
+ o_aHandledArgs.m_sInputFile = OString( argv[i] );
+ }
+ break;
+ case STATE_OUTPUT:
+ {
+ o_aHandledArgs.m_sOutputFile = OString( argv[i] );
+ }
+ break;
+ case STATE_MERGESRC:
+ {
+ o_aHandledArgs.m_sMergeSrc = OString( argv[i] );
+ o_aHandledArgs.m_bMergeMode = true;
+ }
+ break;
+ case STATE_LANGUAGES:
+ {
+ o_aHandledArgs.m_sLanguage = OString( argv[i] );
+ }
+ break;
+ }
+ }
+ }
+ if( !o_aHandledArgs.m_sInputFile.isEmpty() &&
+ !o_aHandledArgs.m_sOutputFile.isEmpty() )
+ {
+ return true;
+ }
+ else
+ {
+ o_aHandledArgs = HandledArgs();
+ return false;
+ }
+}
+
+void writeUsage(const OString& rName, const OString& rFileType)
+{
+ std::cout
+ << " Syntax: " << rName.getStr()
+ << " -i FileIn -o FileOut [-m DataBase] [-l Lang]\n"
+ << " FileIn: Source files (" << rFileType.getStr() << ")\n"
+ << " FileOut: Destination file (*.*)\n"
+ << " DataBase: Mergedata (*.po)\n"
+ << " Lang: Restrict the handled languag; one element of\n"
+ << " (de, en-US, ...) or all\n";
+}
+
+void writePoEntry(
+ const OString& rExecutable, PoOfstream& rPoStream, const OString& rSourceFile,
+ const OString& rResType, const OString& rGroupId, const OString& rLocalId,
+ const OString& rHelpText, const OString& rText, const PoEntry::TYPE eType )
+{
+ try
+ {
+ PoEntry aPO(rSourceFile, rResType, rGroupId, rLocalId, rHelpText, rText, eType);
+ rPoStream.writeEntry( aPO );
+ }
+ catch( PoEntry::Exception& aException )
+ {
+ if(aException == PoEntry::NOSOURCFILE)
+ {
+ std::cerr << rExecutable << " warning: no sourcefile specified for po entry\n";
+ }
+ else
+ {
+ std::cerr << rExecutable << " warning: inavlid po attributes extracted from " << rSourceFile << "\n";
+ if(aException == PoEntry::NOGROUPID)
+ {
+ std::cerr << "No groupID specified!\n";
+ std::cerr << "String: " << rText << "\n";
+ }
+ else if (aException == PoEntry::NOSTRING)
+ {
+ std::cerr << "No string specified!\n";
+ std::cerr << "GroupID: " << rGroupId << "\n";
+ if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
+ }
+ else
+ {
+ if (aException == PoEntry::NORESTYPE)
+ {
+ std::cerr << "No resource type specified!\n";
+ }
+ else if (aException == PoEntry::WRONGHELPTEXT)
+ {
+ std::cerr << "x-comment length is 5 characters:" << rHelpText << "\n";
+ }
+
+ std::cerr << "GroupID: " << rGroupId << "\n";
+ if( !rLocalId.isEmpty() ) std::cerr << "LocalID: " << rLocalId << "\n";
+ std::cerr << "String: " << rText << "\n";
+ }
+ }
+ }
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */