summaryrefslogtreecommitdiff
path: root/l10ntools
diff options
context:
space:
mode:
authorAndras Bartek <barteka13@gmail.com>2012-09-06 21:11:23 +0200
committerAndras Timar <atimar@suse.com>2012-09-06 21:15:02 +0200
commit4ced2d99db7ac1be3af8c114757abf3caae1b555 (patch)
treed803a6db8c827d206b595ca9430ed5821e8a07dc /l10ntools
parent23cd24bd4d4df9247f8f0496f9934a2ce6d110dd (diff)
fdo#52246 let helpex use gsicheck's tag checker
So the build will not break on translations errors in help. English segment will be used, when the localized segment has fatal error in it, e.g. a tag error that results in invalid xml. Change-Id: I8a74649d1f00f6379a7244f2582d27b8a437cd2f
Diffstat (limited to 'l10ntools')
-rw-r--r--l10ntools/Executable_gsicheck.mk6
-rw-r--r--l10ntools/StaticLibrary_transex.mk2
-rw-r--r--l10ntools/inc/export.hxx23
-rw-r--r--l10ntools/inc/gsicheck.hxx60
-rw-r--r--l10ntools/source/gsicheck.cxx456
-rw-r--r--l10ntools/source/gsimain.cxx437
-rw-r--r--l10ntools/source/helpmerge.cxx10
-rw-r--r--l10ntools/source/merge.cxx9
8 files changed, 558 insertions, 445 deletions
diff --git a/l10ntools/Executable_gsicheck.mk b/l10ntools/Executable_gsicheck.mk
index 917c00fc5866..fceb61a1554e 100644
--- a/l10ntools/Executable_gsicheck.mk
+++ b/l10ntools/Executable_gsicheck.mk
@@ -34,10 +34,12 @@ $(eval $(call gb_Executable_set_include,gsicheck,\
$(eval $(call gb_Executable_use_libraries,gsicheck,\
sal \
))
+$(eval $(call gb_Executable_use_static_libraries,gsicheck,\
+ transex \
+))
$(eval $(call gb_Executable_add_exception_objects,gsicheck,\
- l10ntools/source/gsicheck \
- l10ntools/source/tagtest \
+ l10ntools/source/gsimain \
))
# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/l10ntools/StaticLibrary_transex.mk b/l10ntools/StaticLibrary_transex.mk
index e8c84b7d3662..f9dd1650d591 100644
--- a/l10ntools/StaticLibrary_transex.mk
+++ b/l10ntools/StaticLibrary_transex.mk
@@ -37,6 +37,8 @@ $(eval $(call gb_StaticLibrary_add_exception_objects,transex,\
l10ntools/source/merge \
l10ntools/source/file \
l10ntools/source/directory \
+ l10ntools/source/tagtest \
+ l10ntools/source/gsicheck \
))
# vim: set noet sw=4 ts=4:
diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx
index a1c66e3808a1..8e4be09799de 100644
--- a/l10ntools/inc/export.hxx
+++ b/l10ntools/inc/export.hxx
@@ -71,6 +71,9 @@ typedef boost::unordered_map<rtl::OString, PFormEntrys*, rtl::OStringHash>
typedef boost::unordered_map<rtl::OString, MergeData*, rtl::OStringHash>
MergeDataHashMap;
+typedef boost::unordered_map<rtl::OString, size_t, rtl::OStringHash>
+ LineNumberHashMap;
+
#define SOURCE_LANGUAGE rtl::OString(RTL_CONSTASCII_STRINGPARAM("en-US"))
#define X_COMMENT rtl::OString(RTL_CONSTASCII_STRINGPARAM("x-comment"))
#define LIST_REFID "LIST_REFID"
@@ -374,23 +377,36 @@ private:
OStringBoolHashMap bQuickHelpTextFirst;
OStringHashMap sTitle;
OStringBoolHashMap bTitleFirst;
+ OStringHashMap sSDFLine;
+ LineNumberHashMap nLine;
public:
PFormEntrys( const rtl::OString &rPForm ) : data_( rPForm ) {};
void InsertEntry(const rtl::OString &rId, const rtl::OString &rText,
- const rtl::OString &rQuickHelpText, const rtl::OString &rTitle)
+ const rtl::OString &rQuickHelpText, const rtl::OString &rTitle,
+ const rtl::OString &rSDFLine, const std::size_t nLineIn)
{
-
sText[ rId ] = rText;
bTextFirst[ rId ] = true;
sQuickHelpText[ rId ] = rQuickHelpText;
bQuickHelpTextFirst[ rId ] = true;
sTitle[ rId ] = rTitle;
bTitleFirst[ rId ] = true;
+ sSDFLine[ rId ] = rSDFLine;
+ nLine[ rId ] = nLineIn;
}
sal_Bool GetText( rtl::OString &rReturn, sal_uInt16 nTyp, const rtl::OString &nLangIndex, sal_Bool bDel = sal_False );
sal_Bool GetTransex3Text( rtl::OString &rReturn, sal_uInt16 nTyp, const rtl::OString &nLangIndex, sal_Bool bDel = sal_False );
+ rtl::OString & GetSDF(const rtl::OString &nLangIndex)
+ {
+ return sSDFLine[nLangIndex];
+ }
+
+ std::size_t GetNLine(const rtl::OString &nLangIndex)
+ {
+ return nLine[nLangIndex];
+ }
};
//
@@ -444,7 +460,8 @@ class MergeDataFile
const rtl::OString &rLID, const rtl::OString &rPFO,
const rtl::OString &nLang, const rtl::OString &rTEXT,
const rtl::OString &rQHTEXT, const rtl::OString &rTITLE,
- const rtl::OString &sFilename, bool bCaseSensitive);
+ const rtl::OString &sFilename, bool bCaseSensitive,
+ const rtl::OString &rSDF, std::size_t nLine);
public:
explicit MergeDataFile(const rtl::OString &rFileName,
const rtl::OString& rFile, bool bCaseSensitive);
diff --git a/l10ntools/inc/gsicheck.hxx b/l10ntools/inc/gsicheck.hxx
index 467925e46767..266ea96c2543 100644
--- a/l10ntools/inc/gsicheck.hxx
+++ b/l10ntools/inc/gsicheck.hxx
@@ -33,6 +33,7 @@
#include <cstddef>
#include <vector>
+#include <fstream>
#include "tagtest.hxx"
@@ -131,6 +132,65 @@ public:
void WriteFixed( LazyStream &aFixOut );
};
+sal_Bool check(rtl::OString s,std::size_t nLine);
+
+void PrintMessage( rtl::OString const & aType, rtl::OString const & aMsg, rtl::OString const & aPrefix,
+ rtl::OString const & aContext, sal_Bool bPrintContext, std::size_t nLine, rtl::OString aUniqueId = rtl::OString() );
+
+void PrintError( rtl::OString const & aMsg, rtl::OString const & aPrefix,
+ rtl::OString const & aContext, sal_Bool bPrintContext, std::size_t nLine, rtl::OString const & aUniqueId = rtl::OString() );
+
+bool LanguageOK( rtl::OString const & aLang );
+
+class LazyStream: public std::ofstream
+{
+
+private:
+ rtl::OString aFileName;
+ bool bOpened;
+
+public:
+ LazyStream()
+ : aFileName()
+ , bOpened(false)
+ {};
+
+ void SetFileName( const rtl::OString& rFileName )
+ {
+ aFileName = rFileName;
+ };
+
+ void LazyOpen();
+};
+
+namespace {
+
+sal_Int32 const MAX_GID_LID_LEN = 250;
+
+rtl::OString copyUpTo(
+ rtl::OString const & text, sal_Int32 start, sal_Int32 maximumLength)
+{
+ assert(start >= 0 && start <= text.getLength());
+ return text.copy(start, std::min(text.getLength() - start, maximumLength));
+}
+
+rtl::OString addSuffix(
+ rtl::OString const & pathname, rtl::OString const & suffix)
+{
+ sal_Int32 n = pathname.lastIndexOf('.');
+ if (n == -1) {
+ fprintf(
+ stderr,
+ ("Error: pathname \"%s\" does not contain dot to add suffix in"
+ " front of\n"),
+ pathname.getStr());
+ exit(EXIT_FAILURE);
+ }
+ return pathname.replaceAt(n, 0, suffix);
+}
+
+}
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx
index af662d009b46..3a4c0af5d7ec 100644
--- a/l10ntools/source/gsicheck.cxx
+++ b/l10ntools/source/gsicheck.cxx
@@ -42,37 +42,9 @@
#include "tagtest.hxx"
#include "gsicheck.hxx"
-namespace {
-
-sal_Int32 const MAX_GID_LID_LEN = 250;
-
-rtl::OString copyUpTo(
- rtl::OString const & text, sal_Int32 start, sal_Int32 maximumLength)
-{
- assert(start >= 0 && start <= text.getLength());
- return text.copy(start, std::min(text.getLength() - start, maximumLength));
-}
-
-rtl::OString addSuffix(
- rtl::OString const & pathname, rtl::OString const & suffix)
-{
- sal_Int32 n = pathname.lastIndexOf('.');
- if (n == -1) {
- fprintf(
- stderr,
- ("Error: pathname \"%s\" does not contain dot to add suffix in"
- " front of\n"),
- pathname.getStr());
- exit(EXIT_FAILURE);
- }
- return pathname.replaceAt(n, 0, suffix);
-}
-
-}
-
/*****************************************************************************/
void PrintMessage( rtl::OString const & aType, rtl::OString const & aMsg, rtl::OString const & aPrefix,
- rtl::OString const & aContext, sal_Bool bPrintContext, std::size_t nLine, rtl::OString aUniqueId = rtl::OString() )
+ rtl::OString const & aContext, sal_Bool bPrintContext, std::size_t nLine, rtl::OString aUniqueId )
/*****************************************************************************/
{
fprintf( stdout, "%s %s, Line %u", aType.getStr(), aPrefix.getStr(), static_cast<unsigned>( nLine ) );
@@ -87,7 +59,7 @@ void PrintMessage( rtl::OString const & aType, rtl::OString const & aMsg, rtl::O
/*****************************************************************************/
void PrintError( rtl::OString const & aMsg, rtl::OString const & aPrefix,
- rtl::OString const & aContext, sal_Bool bPrintContext, std::size_t nLine, rtl::OString const & aUniqueId = rtl::OString() )
+ rtl::OString const & aContext, sal_Bool bPrintContext, std::size_t nLine, rtl::OString const & aUniqueId )
/*****************************************************************************/
{
PrintMessage( "Error:", aMsg, aPrefix, aContext, bPrintContext, nLine, aUniqueId );
@@ -109,27 +81,6 @@ bool LanguageOK( rtl::OString const & aLang )
&& !t0.equalsIgnoreAsciiCase(t1);
}
-class LazyStream: public std::ofstream
-{
-
-private:
- rtl::OString aFileName;
- bool bOpened;
-
-public:
- LazyStream()
- : aFileName()
- , bOpened(false)
- {};
-
- void SetFileName( const rtl::OString& rFileName )
- {
- aFileName = rFileName;
- };
-
- void LazyOpen();
-};
-
void LazyStream::LazyOpen()
{
if ( !bOpened )
@@ -641,402 +592,39 @@ void GSIBlock::WriteFixed( LazyStream &aFixOut )
}
}
-/*****************************************************************************/
-void Help()
-/*****************************************************************************/
+sal_Bool check(rtl::OString s, std::size_t nLine)
{
- fprintf( stdout, "\n" );
- fprintf( stdout, "gsicheck checks the syntax of tags in SDF-Files\n" );
- fprintf( stdout, " checks for inconsistencies and malicious UTF8 encoding\n" );
- fprintf( stdout, " checks tags in Online Help\n" );
- fprintf( stdout, " relax GID/LID length to %s\n",
- rtl::OString::valueOf(static_cast<sal_Int32>(MAX_GID_LID_LEN)).getStr() );
- fprintf( stdout, "\n" );
- fprintf( stdout, "Syntax: gsicheck [ -c ] [-f] [ -we ] [ -wef ErrorFilename ] [ -wc ]\n" );
- fprintf( stdout, " [ -wcf CorrectFilename ] [ -s | -t ] [ -l LanguageID ]\n" );
- fprintf( stdout, " [ -r ReferenceFile ] filename\n" );
- fprintf( stdout, "\n" );
- fprintf( stdout, "-c Add context to error message (Print the line containing the error)\n" );
- fprintf( stdout, "-f try to fix errors. See also -wf -wff \n" );
- fprintf( stdout, "-wf Write File containing all fixed parts\n" );
- fprintf( stdout, "-wff Same as above but give own filename\n" );
- fprintf( stdout, "-we Write File containing all errors\n" );
- fprintf( stdout, "-wef Same as above but give own filename\n" );
- fprintf( stdout, "-wc Write File containing all correct parts\n" );
- fprintf( stdout, "-wcf Same as above but give own filename\n" );
- fprintf( stdout, "-s Check only source language. Should be used before handing out to vendor.\n" );
- fprintf( stdout, "-t Check only Translation language(s). Should be used before merging.\n" );
- fprintf( stdout, "-e disable encoding checks. E.g.: double questionmark \'??\' which may be the\n" );
- fprintf( stdout, " result of false conversions\n" );
- fprintf( stdout, "-l ISO language code of the source language.\n" );
- fprintf( stdout, " Default is en-US. Use \"\" (empty string) or 'none'\n" );
- fprintf( stdout, " to disable source language dependent checks\n" );
- fprintf( stdout, "-r Reference filename to check that source language entries\n" );
- fprintf( stdout, " have not been changed\n" );
- fprintf( stdout, "\n" );
-}
-
-SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
- sal_Bool bError = sal_False;
- sal_Bool bPrintContext = sal_False;
- sal_Bool bCheckSourceLang = sal_False;
- sal_Bool bCheckTranslationLang = sal_False;
- sal_Bool bWriteError = sal_False;
- sal_Bool bWriteCorrect = sal_False;
- sal_Bool bWriteFixed = sal_False;
- sal_Bool bFixTags = sal_False;
- sal_Bool bAllowSuspicious = sal_False;
- rtl::OString aErrorFilename;
- rtl::OString aCorrectFilename;
- rtl::OString aFixedFilename;
sal_Bool bFileHasError = sal_False;
- rtl::OString aSourceLang( "en-US" ); // English is default
- rtl::OString aFilename;
- rtl::OString aReferenceFilename;
- sal_Bool bReferenceFile = sal_False;
- for ( int i = 1 ; i < argc ; i++ )
- {
- if ( *argv[ i ] == '-' )
- {
- switch (*(argv[ i ]+1))
- {
- case 'c':bPrintContext = sal_True;
- break;
- case 'w':
- {
- if ( (*(argv[ i ]+2)) == 'e' )
- {
- if ( (*(argv[ i ]+3)) == 'f' )
- if ( (i+1) < argc )
- {
- aErrorFilename = argv[i + 1];
- bWriteError = sal_True;
- i++;
- }
- else
- {
- fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
- bError = sal_True;
- }
- else
- bWriteError = sal_True;
- }
- else if ( (*(argv[ i ]+2)) == 'c' )
- if ( (*(argv[ i ]+3)) == 'f' )
- if ( (i+1) < argc )
- {
- aCorrectFilename = argv[i + 1];
- bWriteCorrect = sal_True;
- i++;
- }
- else
- {
- fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
- bError = sal_True;
- }
- else
- bWriteCorrect = sal_True;
- else if ( (*(argv[ i ]+2)) == 'f' )
- if ( (*(argv[ i ]+3)) == 'f' )
- if ( (i+1) < argc )
- {
- aFixedFilename = argv[i + 1];
- bWriteFixed = sal_True;
- bFixTags = sal_True;
- i++;
- }
- else
- {
- fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
- bError = sal_True;
- }
- else
- {
- bWriteFixed = sal_True;
- bFixTags = sal_True;
- }
- else
- {
- fprintf( stderr, "\nERROR: Unknown Switch %s!\n\n", argv[ i ] );
- bError = sal_True;
- }
- }
- break;
- case 's':bCheckSourceLang = sal_True;
- break;
- case 't':bCheckTranslationLang = sal_True;
- break;
- case 'l':
- {
- if ( (i+1) < argc )
- {
- aSourceLang = argv[ i+1 ];
- if ( aSourceLang.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("none")) )
- aSourceLang = rtl::OString();
- i++;
- }
- else
- {
- fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
- bError = sal_True;
- }
- }
- break;
- case 'r':
- {
- if ( (i+1) < argc )
- {
- aReferenceFilename = argv[ i+1 ];
- bReferenceFile = sal_True;
- i++;
- }
- else
- {
- fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
- bError = sal_True;
- }
- }
- break;
- case 'f':
- {
- bFixTags = sal_True;
- }
- break;
- case 'e':
- {
- bAllowSuspicious = sal_True;
- }
- break;
- default:
- fprintf( stderr, "\nERROR: Unknown Switch %s!\n\n", argv[ i ] );
- bError = sal_True;
- }
- }
- else
- {
- if (aFilename.isEmpty())
- aFilename = argv[i];
- else
- {
- fprintf( stderr, "\nERROR: Only one filename may be specified!\n\n");
- bError = sal_True;
- }
- }
- }
-
-
- if (aFilename.isEmpty() || bError)
- {
- Help();
- exit ( 0 );
- }
-
- if ( !aSourceLang.isEmpty() && !LanguageOK( aSourceLang ) )
- {
- fprintf( stderr, "\nERROR: The Language '%s' is invalid!\n\n", aSourceLang.getStr() );
- Help();
- exit ( 1 );
- }
-
- if ( bCheckSourceLang && bCheckTranslationLang )
- {
- fprintf( stderr, "\nERROR: The Options -s and -t are mutually exclusive.\nUse only one of them.\n\n" );
- Help();
- exit ( 1 );
- }
-
-
-
- std::ifstream aGSI(aFilename.getStr());
- if (!aGSI.is_open()) {
- fprintf( stderr, "\nERROR: Could not open GSI-File %s!\n\n", aFilename.getStr() );
- exit ( 3 );
- }
-
- std::ifstream aReferenceGSI;
- if ( bReferenceFile )
- {
- aReferenceGSI.open(aReferenceFilename.getStr());
- if (!aReferenceGSI.is_open()) {
- fprintf( stderr, "\nERROR: Could not open Input-File %s!\n\n", aFilename.getStr() );
- exit ( 3 );
- }
- }
-
- LazyStream aOkOut;
- if ( bWriteCorrect )
- {
- if (aCorrectFilename.isEmpty())
- {
- aCorrectFilename = addSuffix(
- aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_ok")));
- }
- aOkOut.SetFileName(aCorrectFilename);
- }
-
- LazyStream aErrOut;
- if ( bWriteError )
- {
- if (aErrorFilename.isEmpty())
- {
- aErrorFilename = addSuffix(
- aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_err")));
- }
- aErrOut.SetFileName(aErrorFilename);
- }
-
- LazyStream aFixOut;
- if ( bWriteFixed )
- {
- if (aFixedFilename.isEmpty())
- {
- aFixedFilename = addSuffix(
- aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_fix")));
- }
- aFixOut.SetFileName(aFixedFilename);
- }
-
-
- GSILine* pReferenceLine = NULL;
- std::size_t nReferenceLine = 0;
-
GSILine* pGSILine = NULL;
- rtl::OString aOldId("No Valid ID"); // just set to something which can never be an ID
GSIBlock *pBlock = NULL;
- std::size_t nLine = 0;
+ pGSILine = new GSILine(s, nLine );
- while (!aGSI.eof())
+ if ( !pGSILine->data_.isEmpty() )
{
- std::string s;
- std::getline(aGSI, s);
- nLine++;
- pGSILine = new GSILine(rtl::OString(s.data(), s.length()), nLine );
- sal_Bool bDelete = sal_True;
-
-
- if ( !pGSILine->data_.isEmpty() )
+ if ( FORMAT_UNKNOWN == pGSILine->GetLineFormat() )
{
- if ( FORMAT_UNKNOWN == pGSILine->GetLineFormat() )
- {
- PrintError( "Format of line is unknown. Ignoring!", "Line format", pGSILine->data_.copy( 0,40 ), bPrintContext, pGSILine->GetLineNumber() );
- pGSILine->NotOK();
- if ( bWriteError )
- {
- bFileHasError = sal_True;
- aErrOut.LazyOpen();
- aErrOut << pGSILine->data_.getStr();
- }
- }
- else if ( pGSILine->GetLineType().equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("res-comment")) )
- { // ignore comment lines, but write them to Correct Items File
- if ( bWriteCorrect )
- {
- aOkOut.LazyOpen();
- aOkOut << pGSILine->data_.getStr() << '\n';
- }
- }
- else
+ PrintError( "Format of line is unknown. Ignoring!", "Line format", pGSILine->data_.copy( 0,40 ), sal_True, pGSILine->GetLineNumber() );
+ bFileHasError = sal_True;
+ pGSILine->NotOK();
+ }
+ else if ( !(pGSILine->GetLineType().equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("res-comment"))) )
+ {
+ pBlock = new GSIBlock( sal_True, sal_False, sal_False, sal_False, sal_False );
+ pBlock->InsertLine( pGSILine, rtl::OString() );
+ bFileHasError |= pBlock->CheckSyntax( nLine, sal_False, sal_False );
+ if (pBlock!=NULL)
{
- rtl::OString aId = pGSILine->GetUniqId();
- if ( aId != aOldId )
- {
- if ( pBlock )
- {
- bFileHasError |= pBlock->CheckSyntax( nLine, !aSourceLang.isEmpty(), bFixTags );
-
- if ( bWriteError )
- pBlock->WriteError( aErrOut, !aSourceLang.isEmpty() );
- if ( bWriteCorrect )
- pBlock->WriteCorrect( aOkOut, !aSourceLang.isEmpty() );
- if ( bWriteFixed )
- pBlock->WriteFixed( aFixOut );
-
- delete pBlock;
- }
- pBlock = new GSIBlock( bPrintContext, bCheckSourceLang, bCheckTranslationLang, bReferenceFile, bAllowSuspicious );
-
- aOldId = aId;
-
-
- // find corresponding line in reference file
- if ( bReferenceFile )
- {
- sal_Bool bContinueSearching = sal_True;
- while ( ( !aReferenceGSI.eof() || pReferenceLine ) && bContinueSearching )
- {
- if ( !pReferenceLine )
- {
- std::string s2;
- std::getline(aReferenceGSI, s2);
- nReferenceLine++;
- pReferenceLine = new GSILine(
- rtl::OString(s2.data(), s2.length()),
- nReferenceLine);
- }
- if ( pReferenceLine->GetLineFormat() != FORMAT_UNKNOWN )
- {
- if ( pReferenceLine->GetUniqId() == aId && pReferenceLine->GetLanguageId() == aSourceLang )
- {
- pBlock->SetReferenceLine( pReferenceLine );
- pReferenceLine = NULL;
- }
- else if ( pReferenceLine->GetUniqId() > aId )
- {
- bContinueSearching = sal_False;
- }
- else
- {
- if ( pReferenceLine->GetUniqId() < aId && pReferenceLine->GetLanguageId() == aSourceLang )
- PrintError( "No Entry in source file found. Entry has been removed from source file", "File format", "", bPrintContext, pGSILine->GetLineNumber(), pReferenceLine->GetUniqId() );
- delete pReferenceLine;
- pReferenceLine = NULL;
- }
- }
- else
- {
- delete pReferenceLine;
- pReferenceLine = NULL;
- }
-
- }
- }
-
- }
-
- pBlock->InsertLine( pGSILine, aSourceLang );
- bDelete = sal_False;
+ delete pBlock;
+ pBlock=NULL;
+ pGSILine=NULL;
}
}
- if ( bDelete )
- delete pGSILine;
-
}
- if ( pBlock )
- {
- bFileHasError |= pBlock->CheckSyntax( nLine, !aSourceLang.isEmpty(), bFixTags );
-
- if ( bWriteError )
- pBlock->WriteError( aErrOut, !aSourceLang.isEmpty() );
- if ( bWriteCorrect )
- pBlock->WriteCorrect( aOkOut, !aSourceLang.isEmpty() );
- if ( bWriteFixed )
- pBlock->WriteFixed( aFixOut );
-
- delete pBlock;
- }
- aGSI.close();
-
- if ( bWriteError )
- aErrOut.close();
- if ( bWriteCorrect )
- aOkOut.close();
- if ( bWriteFixed )
- aFixOut.close();
-
+ delete pGSILine;
if ( bFileHasError )
- return 55;
+ return false;
else
- return 0;
+ return true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/gsimain.cxx b/l10ntools/source/gsimain.cxx
new file mode 100644
index 000000000000..4ed9d69f3aa7
--- /dev/null
+++ b/l10ntools/source/gsimain.cxx
@@ -0,0 +1,437 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "sal/config.h"
+
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <fstream>
+#include <string>
+
+#include <stdio.h>
+
+#include <rtl/strbuf.hxx>
+#include "sal/main.h"
+#include "helper.hxx"
+#include "tagtest.hxx"
+#include "gsicheck.hxx"
+
+void Help()
+{
+ fprintf( stdout, "\n" );
+ fprintf( stdout, "gsicheck checks the syntax of tags in SDF-Files\n" );
+ fprintf( stdout, " checks for inconsistencies and malicious UTF8 encoding\n" );
+ fprintf( stdout, " checks tags in Online Help\n" );
+ fprintf( stdout, " relax GID/LID length to %s\n",
+ rtl::OString::valueOf(static_cast<sal_Int32>(MAX_GID_LID_LEN)).getStr() );
+ fprintf( stdout, "\n" );
+ fprintf( stdout, "Syntax: gsicheck [ -c ] [-f] [ -we ] [ -wef ErrorFilename ] [ -wc ]\n" );
+ fprintf( stdout, " [ -wcf CorrectFilename ] [ -s | -t ] [ -l LanguageID ]\n" );
+ fprintf( stdout, " [ -r ReferenceFile ] filename\n" );
+ fprintf( stdout, "\n" );
+ fprintf( stdout, "-c Add context to error message (Print the line containing the error)\n" );
+ fprintf( stdout, "-f try to fix errors. See also -wf -wff \n" );
+ fprintf( stdout, "-wf Write File containing all fixed parts\n" );
+ fprintf( stdout, "-wff Same as above but give own filename\n" );
+ fprintf( stdout, "-we Write File containing all errors\n" );
+ fprintf( stdout, "-wef Same as above but give own filename\n" );
+ fprintf( stdout, "-wc Write File containing all correct parts\n" );
+ fprintf( stdout, "-wcf Same as above but give own filename\n" );
+ fprintf( stdout, "-s Check only source language. Should be used before handing out to vendor.\n" );
+ fprintf( stdout, "-t Check only Translation language(s). Should be used before merging.\n" );
+ fprintf( stdout, "-e disable encoding checks. E.g.: double questionmark \'??\' which may be the\n" );
+ fprintf( stdout, " result of false conversions\n" );
+ fprintf( stdout, "-l ISO language code of the source language.\n" );
+ fprintf( stdout, " Default is en-US. Use \"\" (empty string) or 'none'\n" );
+ fprintf( stdout, " to disable source language dependent checks\n" );
+ fprintf( stdout, "-r Reference filename to check that source language entries\n" );
+ fprintf( stdout, " have not been changed\n" );
+ fprintf( stdout, "\n" );
+}
+
+SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
+ sal_Bool bError = sal_False;
+ sal_Bool bPrintContext = sal_False;
+ sal_Bool bCheckSourceLang = sal_False;
+ sal_Bool bCheckTranslationLang = sal_False;
+ sal_Bool bWriteError = sal_False;
+ sal_Bool bWriteCorrect = sal_False;
+ sal_Bool bWriteFixed = sal_False;
+ sal_Bool bFixTags = sal_False;
+ sal_Bool bAllowSuspicious = sal_False;
+ rtl::OString aErrorFilename;
+ rtl::OString aCorrectFilename;
+ rtl::OString aFixedFilename;
+ sal_Bool bFileHasError = sal_False;
+ rtl::OString aSourceLang( "en-US" ); // English is default
+ rtl::OString aFilename;
+ rtl::OString aReferenceFilename;
+ sal_Bool bReferenceFile = sal_False;
+ for ( int i = 1 ; i < argc ; i++ )
+ {
+ if ( *argv[ i ] == '-' )
+ {
+ switch (*(argv[ i ]+1))
+ {
+ case 'c':bPrintContext = sal_True;
+ break;
+ case 'w':
+ {
+ if ( (*(argv[ i ]+2)) == 'e' )
+ {
+ if ( (*(argv[ i ]+3)) == 'f' )
+ if ( (i+1) < argc )
+ {
+ aErrorFilename = argv[i + 1];
+ bWriteError = sal_True;
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
+ bError = sal_True;
+ }
+ else
+ bWriteError = sal_True;
+ }
+ else if ( (*(argv[ i ]+2)) == 'c' )
+ if ( (*(argv[ i ]+3)) == 'f' )
+ if ( (i+1) < argc )
+ {
+ aCorrectFilename = argv[i + 1];
+ bWriteCorrect = sal_True;
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
+ bError = sal_True;
+ }
+ else
+ bWriteCorrect = sal_True;
+ else if ( (*(argv[ i ]+2)) == 'f' )
+ if ( (*(argv[ i ]+3)) == 'f' )
+ if ( (i+1) < argc )
+ {
+ aFixedFilename = argv[i + 1];
+ bWriteFixed = sal_True;
+ bFixTags = sal_True;
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
+ bError = sal_True;
+ }
+ else
+ {
+ bWriteFixed = sal_True;
+ bFixTags = sal_True;
+ }
+ else
+ {
+ fprintf( stderr, "\nERROR: Unknown Switch %s!\n\n", argv[ i ] );
+ bError = sal_True;
+ }
+ }
+ break;
+ case 's':bCheckSourceLang = sal_True;
+ break;
+ case 't':bCheckTranslationLang = sal_True;
+ break;
+ case 'l':
+ {
+ if ( (i+1) < argc )
+ {
+ aSourceLang = argv[ i+1 ];
+ if ( aSourceLang.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("none")) )
+ aSourceLang = rtl::OString();
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
+ bError = sal_True;
+ }
+ }
+ break;
+ case 'r':
+ {
+ if ( (i+1) < argc )
+ {
+ aReferenceFilename = argv[ i+1 ];
+ bReferenceFile = sal_True;
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] );
+ bError = sal_True;
+ }
+ }
+ break;
+ case 'f':
+ {
+ bFixTags = sal_True;
+ }
+ break;
+ case 'e':
+ {
+ bAllowSuspicious = sal_True;
+ }
+ break;
+ default:
+ fprintf( stderr, "\nERROR: Unknown Switch %s!\n\n", argv[ i ] );
+ bError = sal_True;
+ }
+ }
+ else
+ {
+ if (aFilename.isEmpty())
+ aFilename = argv[i];
+ else
+ {
+ fprintf( stderr, "\nERROR: Only one filename may be specified!\n\n");
+ bError = sal_True;
+ }
+ }
+ }
+
+
+ if (aFilename.isEmpty() || bError)
+ {
+ Help();
+ exit ( 0 );
+ }
+
+ if ( !aSourceLang.isEmpty() && !LanguageOK( aSourceLang ) )
+ {
+ fprintf( stderr, "\nERROR: The Language '%s' is invalid!\n\n", aSourceLang.getStr() );
+ Help();
+ exit ( 1 );
+ }
+
+ if ( bCheckSourceLang && bCheckTranslationLang )
+ {
+ fprintf( stderr, "\nERROR: The Options -s and -t are mutually exclusive.\nUse only one of them.\n\n" );
+ Help();
+ exit ( 1 );
+ }
+
+
+
+ std::ifstream aGSI(aFilename.getStr());
+ if (!aGSI.is_open()) {
+ fprintf( stderr, "\nERROR: Could not open GSI-File %s!\n\n", aFilename.getStr() );
+ exit ( 3 );
+ }
+
+ std::ifstream aReferenceGSI;
+ if ( bReferenceFile )
+ {
+ aReferenceGSI.open(aReferenceFilename.getStr());
+ if (!aReferenceGSI.is_open()) {
+ fprintf( stderr, "\nERROR: Could not open Input-File %s!\n\n", aFilename.getStr() );
+ exit ( 3 );
+ }
+ }
+
+ LazyStream aOkOut;
+ if ( bWriteCorrect )
+ {
+ if (aCorrectFilename.isEmpty())
+ {
+ aCorrectFilename = addSuffix(
+ aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_ok")));
+ }
+ aOkOut.SetFileName(aCorrectFilename);
+ }
+
+ LazyStream aErrOut;
+ if ( bWriteError )
+ {
+ if (aErrorFilename.isEmpty())
+ {
+ aErrorFilename = addSuffix(
+ aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_err")));
+ }
+ aErrOut.SetFileName(aErrorFilename);
+ }
+
+ LazyStream aFixOut;
+ if ( bWriteFixed )
+ {
+ if (aFixedFilename.isEmpty())
+ {
+ aFixedFilename = addSuffix(
+ aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_fix")));
+ }
+ aFixOut.SetFileName(aFixedFilename);
+ }
+
+
+ GSILine* pReferenceLine = NULL;
+ std::size_t nReferenceLine = 0;
+
+ GSILine* pGSILine = NULL;
+ rtl::OString aOldId("No Valid ID"); // just set to something which can never be an ID
+ GSIBlock *pBlock = NULL;
+ std::size_t nLine = 0;
+
+ while (!aGSI.eof())
+ {
+ std::string s;
+ std::getline(aGSI, s);
+ nLine++;
+
+ pGSILine = new GSILine(rtl::OString(s.data(), s.length()), nLine );
+ sal_Bool bDelete = sal_True;
+
+ if ( !pGSILine->data_.isEmpty() )
+ {
+ if ( FORMAT_UNKNOWN == pGSILine->GetLineFormat() )
+ {
+ PrintError( "Format of line is unknown. Ignoring!", "Line format", pGSILine->data_.copy( 0,40 ), bPrintContext, pGSILine->GetLineNumber() );
+ pGSILine->NotOK();
+ if ( bWriteError )
+ {
+ bFileHasError = sal_True;
+ aErrOut.LazyOpen();
+ aErrOut << pGSILine->data_.getStr();
+ }
+ }
+ else if ( pGSILine->GetLineType().equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("res-comment")) )
+ { // ignore comment lines, but write them to Correct Items File
+ if ( bWriteCorrect )
+ {
+ aOkOut.LazyOpen();
+ aOkOut << pGSILine->data_.getStr() << '\n';
+ }
+ }
+ else
+ {
+ rtl::OString aId = pGSILine->GetUniqId();
+ if ( aId != aOldId )
+ {
+ if ( pBlock )
+ {
+ bFileHasError |= pBlock->CheckSyntax( nLine, !aSourceLang.isEmpty(), bFixTags );
+
+ if ( bWriteError )
+ pBlock->WriteError( aErrOut, !aSourceLang.isEmpty() );
+ if ( bWriteCorrect )
+ pBlock->WriteCorrect( aOkOut, !aSourceLang.isEmpty() );
+ if ( bWriteFixed )
+ pBlock->WriteFixed( aFixOut );
+
+ delete pBlock;
+ }
+ pBlock = new GSIBlock( bPrintContext, bCheckSourceLang, bCheckTranslationLang, bReferenceFile, bAllowSuspicious );
+
+ aOldId = aId;
+
+ // find corresponding line in reference file
+ if ( bReferenceFile )
+ {
+ sal_Bool bContinueSearching = sal_True;
+ while ( ( !aReferenceGSI.eof() || pReferenceLine ) && bContinueSearching )
+ {
+ if ( !pReferenceLine )
+ {
+ std::string s2;
+ std::getline(aReferenceGSI, s2);
+ nReferenceLine++;
+ pReferenceLine = new GSILine(
+ rtl::OString(s2.data(), s2.length()),
+ nReferenceLine);
+ }
+ if ( pReferenceLine->GetLineFormat() != FORMAT_UNKNOWN )
+ {
+ if ( pReferenceLine->GetUniqId() == aId && pReferenceLine->GetLanguageId() == aSourceLang )
+ {
+ pBlock->SetReferenceLine( pReferenceLine );
+ pReferenceLine = NULL;
+ }
+ else if ( pReferenceLine->GetUniqId() > aId )
+ {
+ bContinueSearching = sal_False;
+ }
+ else
+ {
+ if ( pReferenceLine->GetUniqId() < aId && pReferenceLine->GetLanguageId() == aSourceLang )
+ PrintError( "No Entry in source file found. Entry has been removed from source file", "File format", "", bPrintContext, pGSILine->GetLineNumber(), pReferenceLine->GetUniqId() );
+ delete pReferenceLine;
+ pReferenceLine = NULL;
+ }
+ }
+ else
+ {
+ delete pReferenceLine;
+ pReferenceLine = NULL;
+ }
+
+ }
+ }
+
+ }
+ pBlock->InsertLine( pGSILine, aSourceLang );
+ bDelete = sal_False;
+ }
+ }
+ if ( bDelete )
+ delete pGSILine;
+ }
+ if ( pBlock )
+ {
+ bFileHasError |= pBlock->CheckSyntax( nLine, !aSourceLang.isEmpty(), bFixTags );
+
+ if ( bWriteError )
+ pBlock->WriteError( aErrOut, !aSourceLang.isEmpty() );
+ if ( bWriteCorrect )
+ pBlock->WriteCorrect( aOkOut, !aSourceLang.isEmpty() );
+ if ( bWriteFixed )
+ pBlock->WriteFixed( aFixOut );
+
+ delete pBlock;
+ }
+ aGSI.close();
+
+ if ( bWriteError )
+ aErrOut.close();
+ if ( bWriteCorrect )
+ aOkOut.close();
+ if ( bWriteFixed )
+ aFixOut.close();
+ if ( bFileHasError )
+ return 55;
+ else
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx
index 6f4071e32053..8e8d33fae0cb 100644
--- a/l10ntools/source/helpmerge.cxx
+++ b/l10ntools/source/helpmerge.cxx
@@ -52,6 +52,7 @@
#include "common.hxx"
#include "helper.hxx"
+#include "gsicheck.hxx"
#if OSL_DEBUG_LEVEL > 2
void HelpParser::Dump(XMLHashMap* rElem_in)
@@ -380,9 +381,12 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const rtl::OString& sCur ,
{
if( pXMLElement != NULL )
{
- data = new XMLData( sNewdata , NULL , true ); // Add new one
- pXMLElement->RemoveAndDeleteAllChildren();
- pXMLElement->AddChild( data );
+ if (check(pEntrys->GetSDF(sCur),pEntrys->GetNLine(sCur)))
+ {
+ data = new XMLData( sNewdata , NULL , true ); // Add new one
+ pXMLElement->RemoveAndDeleteAllChildren();
+ pXMLElement->AddChild( data );
+ }
aLangHM->erase( sCur );
}
}
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index 5da52c57d640..fd53f1ceddba 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -151,6 +151,7 @@ MergeDataFile::MergeDataFile(
printf("Warning : Can't open %s\n", rFileName.getStr());
return;
}
+ std::size_t nLine=0;
while (!aInputStream.eof())
{
std::string buf;
@@ -171,11 +172,12 @@ MergeDataFile::MergeDataFile(
const rtl::OString sTEXT = sLine.getToken( 0, '\t', n ); // token 10
const rtl::OString sQHTEXT = sLine.getToken( 1, '\t', n ); // token 12
const rtl::OString sTITLE = sLine.getToken( 0, '\t', n ); // token 13
+ const rtl::OString sSDF(buf.data(),buf.length());
if (!nLANG.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")))
{
aLanguageSet.insert(nLANG);
- InsertEntry( sTYP, sGID, sLID, sPFO, nLANG, sTEXT, sQHTEXT, sTITLE, filename, bCaseSensitive );
+ InsertEntry( sTYP, sGID, sLID, sPFO, nLANG, sTEXT, sQHTEXT, sTITLE, filename, bCaseSensitive, sSDF, ++nLine);
}
}
}
@@ -243,7 +245,8 @@ void MergeDataFile::InsertEntry(
const rtl::OString &rLID, const rtl::OString &rPFO,
const rtl::OString &nLANG, const rtl::OString &rTEXT,
const rtl::OString &rQHTEXT, const rtl::OString &rTITLE ,
- const rtl::OString &rInFilename , bool bCaseSensitive
+ const rtl::OString &rInFilename , bool bCaseSensitive,
+ const rtl::OString &rSDFLine, const std::size_t nLine
)
{
MergeData *pData;
@@ -274,7 +277,7 @@ void MergeDataFile::InsertEntry(
}
// finaly insert the cur string
- pFEntrys->InsertEntry( nLANG , rTEXT, rQHTEXT, rTITLE );
+ pFEntrys->InsertEntry( nLANG , rTEXT, rQHTEXT, rTITLE, rSDFLine, nLine );
}
rtl::OString MergeDataFile::CreateKey(const rtl::OString& rTYP, const rtl::OString& rGID,