From 7d4f47bd0bf7544dbd7f64ed4089e80780c1d2bd Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 16 Dec 2020 17:43:36 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- kbabel/Makefile.am | 2 +- kbabel/common/libgettext/CMakeLists.txt | 2 +- kbabel/common/libgettext/Makefile.am | 8 +- kbabel/datatools/accelerators/CMakeLists.txt | 2 +- kbabel/datatools/accelerators/Makefile.am | 2 +- kbabel/datatools/accelerators/main.cc | 137 --------- kbabel/datatools/accelerators/main.cpp | 137 +++++++++ kbabel/datatools/arguments/CMakeLists.txt | 2 +- kbabel/datatools/arguments/Makefile.am | 2 +- kbabel/datatools/arguments/main.cc | 277 ----------------- kbabel/datatools/arguments/main.cpp | 277 +++++++++++++++++ kbabel/datatools/context/CMakeLists.txt | 2 +- kbabel/datatools/context/Makefile.am | 2 +- kbabel/datatools/context/main.cc | 115 -------- kbabel/datatools/context/main.cpp | 115 ++++++++ kbabel/datatools/equations/CMakeLists.txt | 2 +- kbabel/datatools/equations/Makefile.am | 2 +- kbabel/datatools/equations/main.cc | 113 ------- kbabel/datatools/equations/main.cpp | 113 +++++++ kbabel/datatools/length/CMakeLists.txt | 2 +- kbabel/datatools/length/Makefile.am | 2 +- kbabel/datatools/length/main.cc | 142 --------- kbabel/datatools/length/main.cpp | 142 +++++++++ kbabel/datatools/not-translated/CMakeLists.txt | 2 +- kbabel/datatools/not-translated/Makefile.am | 2 +- kbabel/datatools/not-translated/main.cc | 129 -------- kbabel/datatools/not-translated/main.cpp | 129 ++++++++ kbabel/datatools/pluralforms/CMakeLists.txt | 2 +- kbabel/datatools/pluralforms/Makefile.am | 2 +- kbabel/datatools/pluralforms/main.cc | 129 -------- kbabel/datatools/pluralforms/main.cpp | 129 ++++++++ kbabel/datatools/punctuation/CMakeLists.txt | 2 +- kbabel/datatools/punctuation/Makefile.am | 2 +- kbabel/datatools/punctuation/main.cc | 157 ---------- kbabel/datatools/punctuation/main.cpp | 157 ++++++++++ kbabel/datatools/regexp/CMakeLists.txt | 2 +- kbabel/datatools/regexp/Makefile.am | 2 +- kbabel/datatools/regexp/main.cc | 181 ------------ kbabel/datatools/regexp/main.cpp | 181 ++++++++++++ kbabel/datatools/regexp/regexplist.xml | 4 +- kbabel/datatools/setfuzzy/CMakeLists.txt | 2 +- kbabel/datatools/setfuzzy/Makefile.am | 2 +- kbabel/datatools/setfuzzy/main.cc | 98 ------ kbabel/datatools/setfuzzy/main.cpp | 98 ++++++ kbabel/datatools/whitespace/CMakeLists.txt | 2 +- kbabel/datatools/whitespace/Makefile.am | 2 +- kbabel/datatools/whitespace/main.cc | 144 --------- kbabel/datatools/whitespace/main.cpp | 144 +++++++++ kbabel/datatools/xml/CMakeLists.txt | 2 +- kbabel/datatools/xml/Makefile.am | 2 +- kbabel/datatools/xml/main.cc | 206 ------------- kbabel/datatools/xml/main.cpp | 206 +++++++++++++ .../kbabeldict/modules/dbsearchengine/makemsgdb.C | 327 --------------------- .../modules/dbsearchengine/makemsgdb.cpp | 327 +++++++++++++++++++++ 54 files changed, 2187 insertions(+), 2187 deletions(-) delete mode 100644 kbabel/datatools/accelerators/main.cc create mode 100644 kbabel/datatools/accelerators/main.cpp delete mode 100644 kbabel/datatools/arguments/main.cc create mode 100644 kbabel/datatools/arguments/main.cpp delete mode 100644 kbabel/datatools/context/main.cc create mode 100644 kbabel/datatools/context/main.cpp delete mode 100644 kbabel/datatools/equations/main.cc create mode 100644 kbabel/datatools/equations/main.cpp delete mode 100644 kbabel/datatools/length/main.cc create mode 100644 kbabel/datatools/length/main.cpp delete mode 100644 kbabel/datatools/not-translated/main.cc create mode 100644 kbabel/datatools/not-translated/main.cpp delete mode 100644 kbabel/datatools/pluralforms/main.cc create mode 100644 kbabel/datatools/pluralforms/main.cpp delete mode 100644 kbabel/datatools/punctuation/main.cc create mode 100644 kbabel/datatools/punctuation/main.cpp delete mode 100644 kbabel/datatools/regexp/main.cc create mode 100644 kbabel/datatools/regexp/main.cpp delete mode 100644 kbabel/datatools/setfuzzy/main.cc create mode 100644 kbabel/datatools/setfuzzy/main.cpp delete mode 100644 kbabel/datatools/whitespace/main.cc create mode 100644 kbabel/datatools/whitespace/main.cpp delete mode 100644 kbabel/datatools/xml/main.cc create mode 100644 kbabel/datatools/xml/main.cpp delete mode 100644 kbabel/kbabeldict/modules/dbsearchengine/makemsgdb.C create mode 100644 kbabel/kbabeldict/modules/dbsearchengine/makemsgdb.cpp (limited to 'kbabel') diff --git a/kbabel/Makefile.am b/kbabel/Makefile.am index c38a56f3..bb902d4f 100644 --- a/kbabel/Makefile.am +++ b/kbabel/Makefile.am @@ -4,5 +4,5 @@ SUBDIRS = common filters datatools kbabeldict commonui catalogmanager kbabel add messages: rc.cpp $(EXTRACTRC) `find . -name \*.rc -o -name \*.ui` >> rc.cpp - $(XGETTEXT) `find . -name \*.cpp -o -name \*.cc` -o $(podir)/kbabel.pot + $(XGETTEXT) `find . -name \*.cpp` -o $(podir)/kbabel.pot diff --git a/kbabel/common/libgettext/CMakeLists.txt b/kbabel/common/libgettext/CMakeLists.txt index 6e118d64..a82d9826 100644 --- a/kbabel/common/libgettext/CMakeLists.txt +++ b/kbabel/common/libgettext/CMakeLists.txt @@ -17,7 +17,7 @@ include_directories( ) -##### pofiles.cc (source) ####################### +##### pofiles.cpp (source) ####################### add_custom_command( OUTPUT pofiles.cpp COMMAND ${LEX_EXECUTABLE} -+ -opofiles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pofiles.ll diff --git a/kbabel/common/libgettext/Makefile.am b/kbabel/common/libgettext/Makefile.am index 6f5f4fe2..304e2537 100644 --- a/kbabel/common/libgettext/Makefile.am +++ b/kbabel/common/libgettext/Makefile.am @@ -5,13 +5,13 @@ INCLUDES=$(all_includes) #LEX_OUTPUT_ROOT = lex.GettextBase #AM_LFLAGS = -+ -CLEANFILES = pofiles.cc +CLEANFILES = pofiles.cpp noinst_LTLIBRARIES = libgettext.la -libgettext_la_SOURCES = pofiles.cc +libgettext_la_SOURCES = pofiles.cpp -pofiles.cc: $(srcdir)/pofiles.ll - $(LEX) -+ -opofiles.cc $(srcdir)/pofiles.ll +pofiles.cpp: $(srcdir)/pofiles.ll + $(LEX) -+ -opofiles.cpp $(srcdir)/pofiles.ll noinst_HEADERS = tokens.h pofiles.h diff --git a/kbabel/datatools/accelerators/CMakeLists.txt b/kbabel/datatools/accelerators/CMakeLists.txt index 9e9567db..5dcfc21e 100644 --- a/kbabel/datatools/accelerators/CMakeLists.txt +++ b/kbabel/datatools/accelerators/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_accelstool (module) ################ tde_add_kpart( kbabel_accelstool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/accelerators/Makefile.am b/kbabel/datatools/accelerators/Makefile.am index 5ee57aae..4eff4d91 100644 --- a/kbabel/datatools/accelerators/Makefile.am +++ b/kbabel/datatools/accelerators/Makefile.am @@ -6,7 +6,7 @@ kbabel_accelstool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_accelstool.la -kbabel_accelstool_la_SOURCES = main.cc +kbabel_accelstool_la_SOURCES = main.cpp kbabel_accelstool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/accelerators/main.cc b/kbabel/datatools/accelerators/main.cc deleted file mode 100644 index 0c7cae3a..00000000 --- a/kbabel/datatools/accelerators/main.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002 Stanislav Visnovsky - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_accelstool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -AcceleratorTool::AcceleratorTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ), _cache_origin( 0 ) -{ - // bogus translation just for allowing the translation - i18n("what check found errors","accelerator"); -} - -bool AcceleratorTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Accelerator Tool does only accept the command 'validate'" << endl; - kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; - return FALSE; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Accelerator Tool only accepts datatype CatalogItem" << endl; - return FALSE; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Accelerator Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; - return FALSE; - } - - if( command == "validate" ) - { - CatalogItem* item = (CatalogItem*)(data); - - if( _cache_origin != item->project() ) - { - _context = item->project()->miscSettings().contextInfo; - _marker = item->project()->miscSettings().accelMarker; - _cache_origin = item->project(); - } - - bool hasError = false; - - if(!item->isUntranslated()) - { - // FIXME: this should care about plural forms in msgid - TQString lineid=item->msgid().first(); - lineid.replace( _context, ""); - lineid.replace(TQRegExp("\\n"),""); - lineid.simplifyWhiteSpace(); - TQString regStr(_marker); - regStr+="[^\\s]"; - TQRegExp reg(regStr); - - TQStringList str = item->msgstr(true); - for( TQStringList::Iterator form = str.begin() ; form != str.end(); form++ ) - { - TQString linestr=(*form); - linestr.simplifyWhiteSpace(); - - int n = lineid.contains(reg); - if( _marker == '&' ) - n = n - lineid.contains(TQRegExp("(&[a-z,A-Z,\\-,0-9,#]*;)|(&&(?!&+))")); - int m = linestr.contains(reg); - if( _marker == '&' ) - m = m - linestr.contains(TQRegExp("(&[a-z,A-Z,\\-,0-9,#]*;)|(&&(?!&+))")); - hasError = hasError || ( n<=1 && m != n); - } - } - - if(hasError) - { - item->appendError( "Accelerator" ); - } - else - { - item->removeError( "Accelerator" ); - } - - return !hasError; - } - return FALSE; -} - -#include "main.moc" diff --git a/kbabel/datatools/accelerators/main.cpp b/kbabel/datatools/accelerators/main.cpp new file mode 100644 index 00000000..0c7cae3a --- /dev/null +++ b/kbabel/datatools/accelerators/main.cpp @@ -0,0 +1,137 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_accelstool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +AcceleratorTool::AcceleratorTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ) +{ + // bogus translation just for allowing the translation + i18n("what check found errors","accelerator"); +} + +bool AcceleratorTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Accelerator Tool does only accept the command 'validate'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Accelerator Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Accelerator Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _marker = item->project()->miscSettings().accelMarker; + _cache_origin = item->project(); + } + + bool hasError = false; + + if(!item->isUntranslated()) + { + // FIXME: this should care about plural forms in msgid + TQString lineid=item->msgid().first(); + lineid.replace( _context, ""); + lineid.replace(TQRegExp("\\n"),""); + lineid.simplifyWhiteSpace(); + TQString regStr(_marker); + regStr+="[^\\s]"; + TQRegExp reg(regStr); + + TQStringList str = item->msgstr(true); + for( TQStringList::Iterator form = str.begin() ; form != str.end(); form++ ) + { + TQString linestr=(*form); + linestr.simplifyWhiteSpace(); + + int n = lineid.contains(reg); + if( _marker == '&' ) + n = n - lineid.contains(TQRegExp("(&[a-z,A-Z,\\-,0-9,#]*;)|(&&(?!&+))")); + int m = linestr.contains(reg); + if( _marker == '&' ) + m = m - linestr.contains(TQRegExp("(&[a-z,A-Z,\\-,0-9,#]*;)|(&&(?!&+))")); + hasError = hasError || ( n<=1 && m != n); + } + } + + if(hasError) + { + item->appendError( "Accelerator" ); + } + else + { + item->removeError( "Accelerator" ); + } + + return !hasError; + } + return FALSE; +} + +#include "main.moc" diff --git a/kbabel/datatools/arguments/CMakeLists.txt b/kbabel/datatools/arguments/CMakeLists.txt index a767a0e6..7a532ce2 100644 --- a/kbabel/datatools/arguments/CMakeLists.txt +++ b/kbabel/datatools/arguments/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_argstool (module) ####################### tde_add_kpart( kbabel_argstool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/arguments/Makefile.am b/kbabel/datatools/arguments/Makefile.am index ab4e2f01..104b9c8d 100644 --- a/kbabel/datatools/arguments/Makefile.am +++ b/kbabel/datatools/arguments/Makefile.am @@ -6,7 +6,7 @@ kbabel_argstool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_argstool.la -kbabel_argstool_la_SOURCES = main.cc +kbabel_argstool_la_SOURCES = main.cpp kbabel_argstool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/arguments/main.cc b/kbabel/datatools/arguments/main.cc deleted file mode 100644 index b6c3fa5a..00000000 --- a/kbabel/datatools/arguments/main.cc +++ /dev/null @@ -1,277 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002-2003 Stanislav Visnovsky - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_argstool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -ArgumentTool::ArgumentTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ), _cache_origin( 0 ) -{ - i18n( "what check found errors","arguments"); -} - -bool ArgumentTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Argument Tool does only accept the command 'validate' and 'shortcut'" << endl; - kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; - return FALSE; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Argument Tool only accepts datatype CatalogItem" << endl; - return FALSE; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Argument Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; - return FALSE; - } - - if( command == "validate" ) - { - CatalogItem* item = (CatalogItem*)(data); - - if( item->isNoCformat() ) return true; - bool hasError = false; - - if( _cache_origin != item->project() ) - { - _context = item->project()->miscSettings().contextInfo; - _checkPlurals = item->project()->identitySettings().checkPluralArgument; - _cache_origin = item->project(); - } - - if(!item->isUntranslated()) - { - - TQString formatChars="dioxXucsfeEgGp%"; - - if( _checkPlurals ) formatChars+="n"; - - // FIXME: this should care about plural forms in msgid - TQString line=item->msgid().first(); - TQStringList argList; - -// if( isPluralForm() ) - { - // FIXME: this is KDE specific - if( line.startsWith("_n:" )) - { - // truncate text after first \n to get args only once - line = line.mid(0,line.find("\\n")); - } - } - line.replace(_context, ""); - line.replace(TQRegExp("\\n"),""); - line.simplifyWhiteSpace(); - - // flag, for GNU only we can allow reordering - bool non_gnu = (item->pluralForm() == KDESpecific); - - int index=line.find(TQRegExp("%.")); - - while(index>=0) - { - int endIndex=line.find(TQRegExp("[^\\d]"),index+1); - if(endIndex<0) - { - endIndex=line.length(); - } - else if( formatChars.contains(line[endIndex]) ) - { - endIndex++; - } - - if(endIndex - index > 1 ) { - TQString arg = line.mid(index,endIndex-index); - if( arg.contains( TQRegExp("\\d") ) ) { - non_gnu = true; - } - argList.append(arg); - - } - - index=line.find(TQRegExp("%."),endIndex); - } - - if( item->pluralForm()==KDESpecific) - { - // FIXME: this is KDE specific - if( _checkPlurals && line.startsWith("_n:" ) && !argList.contains("%n") ) - { - argList.append("%n"); - } - } - - // generate for each plural form to be checked separately - line=item->msgstr().first(); - TQStringList lines; - - // FIXME; this is KDE specific - if( item->pluralForm() == KDESpecific ) - { - lines = TQStringList::split("\\n",line); - } - else - { - lines.append(line); - } - - TQStringList argCache = argList; - TQStringList foundArgs; - - for(TQStringList::Iterator i = lines.begin() ; i!=lines.end() ; i++) - { - // initialize for the next plural form - foundArgs.clear(); - argList = argCache; - - line=(*i); - - line.replace(TQRegExp("\\n"),""); - - TQRegExp argdesc( - "%((["+formatChars+"])" - +"|(\\d)+" - +"|(\\d)+\\$(["+formatChars+"])" - +")" ) ; - index = -1; - - do { - - index = argdesc.search( line, index+1 ); - - if( index == -1 ) break; - - // do not add a redundant argument, if it is non GNU - if( !non_gnu || !foundArgs.contains( argdesc.cap(0) ) ) - foundArgs.append( argdesc.cap( 0 ) ); - } while( true ); - - // now, compare the list - argList = argCache; - - if( non_gnu ) { - for ( TQStringList::Iterator it = foundArgs.begin(); it != foundArgs.end(); ++it ) { - if( argList.find( *it ) == argList.end() ) { - hasError = true; - break; - } else { - argList.remove( *it ); - } - } - - if( ! argList.isEmpty() ) { - hasError = true; - } - } - else - { - // handle GNU with replacements - TQStringList::Iterator oit = argList.begin(); - for ( TQStringList::Iterator it = foundArgs.begin(); it != foundArgs.end(); ++it , ++oit) { - if( *it == *oit ) { - // argument is the same, mark as used - *oit = TQString(); - } else { - // try to strip replacement - int index = (*it).find( '$' ); - if( index == -1 ) { - // there is no replacement, this is wrong - hasError = true; - break; - } - TQString place = (*it).mid( 1, index-1 ); - TQString arg = (*it).right( index ); - arg[0] = '%'; - TQStringList::Iterator a = argList.at( place.toInt()-1 ); - if( a != argList.end() && (*a) == arg ) - { - (*a) = TQString(); - } - else - { - // duplicate or index is too high - hasError = true; - } - } - } - - for ( TQStringList::Iterator it = argList.begin(); it != argList.end(); ++it) { - if( ! (*it).isNull () ) { - // argument is the same, mark as used - hasError = true; - break; - } - } - } - } - } - - if(hasError) - { - item->appendError( "Arguments" ); - } - else - { - item->removeError( "Arguments" ); - } - - return !hasError; - } - return FALSE; -} - -#include "main.moc" diff --git a/kbabel/datatools/arguments/main.cpp b/kbabel/datatools/arguments/main.cpp new file mode 100644 index 00000000..b6c3fa5a --- /dev/null +++ b/kbabel/datatools/arguments/main.cpp @@ -0,0 +1,277 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002-2003 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_argstool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +ArgumentTool::ArgumentTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ) +{ + i18n( "what check found errors","arguments"); +} + +bool ArgumentTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Argument Tool does only accept the command 'validate' and 'shortcut'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Argument Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Argument Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + if( item->isNoCformat() ) return true; + bool hasError = false; + + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _checkPlurals = item->project()->identitySettings().checkPluralArgument; + _cache_origin = item->project(); + } + + if(!item->isUntranslated()) + { + + TQString formatChars="dioxXucsfeEgGp%"; + + if( _checkPlurals ) formatChars+="n"; + + // FIXME: this should care about plural forms in msgid + TQString line=item->msgid().first(); + TQStringList argList; + +// if( isPluralForm() ) + { + // FIXME: this is KDE specific + if( line.startsWith("_n:" )) + { + // truncate text after first \n to get args only once + line = line.mid(0,line.find("\\n")); + } + } + line.replace(_context, ""); + line.replace(TQRegExp("\\n"),""); + line.simplifyWhiteSpace(); + + // flag, for GNU only we can allow reordering + bool non_gnu = (item->pluralForm() == KDESpecific); + + int index=line.find(TQRegExp("%.")); + + while(index>=0) + { + int endIndex=line.find(TQRegExp("[^\\d]"),index+1); + if(endIndex<0) + { + endIndex=line.length(); + } + else if( formatChars.contains(line[endIndex]) ) + { + endIndex++; + } + + if(endIndex - index > 1 ) { + TQString arg = line.mid(index,endIndex-index); + if( arg.contains( TQRegExp("\\d") ) ) { + non_gnu = true; + } + argList.append(arg); + + } + + index=line.find(TQRegExp("%."),endIndex); + } + + if( item->pluralForm()==KDESpecific) + { + // FIXME: this is KDE specific + if( _checkPlurals && line.startsWith("_n:" ) && !argList.contains("%n") ) + { + argList.append("%n"); + } + } + + // generate for each plural form to be checked separately + line=item->msgstr().first(); + TQStringList lines; + + // FIXME; this is KDE specific + if( item->pluralForm() == KDESpecific ) + { + lines = TQStringList::split("\\n",line); + } + else + { + lines.append(line); + } + + TQStringList argCache = argList; + TQStringList foundArgs; + + for(TQStringList::Iterator i = lines.begin() ; i!=lines.end() ; i++) + { + // initialize for the next plural form + foundArgs.clear(); + argList = argCache; + + line=(*i); + + line.replace(TQRegExp("\\n"),""); + + TQRegExp argdesc( + "%((["+formatChars+"])" + +"|(\\d)+" + +"|(\\d)+\\$(["+formatChars+"])" + +")" ) ; + index = -1; + + do { + + index = argdesc.search( line, index+1 ); + + if( index == -1 ) break; + + // do not add a redundant argument, if it is non GNU + if( !non_gnu || !foundArgs.contains( argdesc.cap(0) ) ) + foundArgs.append( argdesc.cap( 0 ) ); + } while( true ); + + // now, compare the list + argList = argCache; + + if( non_gnu ) { + for ( TQStringList::Iterator it = foundArgs.begin(); it != foundArgs.end(); ++it ) { + if( argList.find( *it ) == argList.end() ) { + hasError = true; + break; + } else { + argList.remove( *it ); + } + } + + if( ! argList.isEmpty() ) { + hasError = true; + } + } + else + { + // handle GNU with replacements + TQStringList::Iterator oit = argList.begin(); + for ( TQStringList::Iterator it = foundArgs.begin(); it != foundArgs.end(); ++it , ++oit) { + if( *it == *oit ) { + // argument is the same, mark as used + *oit = TQString(); + } else { + // try to strip replacement + int index = (*it).find( '$' ); + if( index == -1 ) { + // there is no replacement, this is wrong + hasError = true; + break; + } + TQString place = (*it).mid( 1, index-1 ); + TQString arg = (*it).right( index ); + arg[0] = '%'; + TQStringList::Iterator a = argList.at( place.toInt()-1 ); + if( a != argList.end() && (*a) == arg ) + { + (*a) = TQString(); + } + else + { + // duplicate or index is too high + hasError = true; + } + } + } + + for ( TQStringList::Iterator it = argList.begin(); it != argList.end(); ++it) { + if( ! (*it).isNull () ) { + // argument is the same, mark as used + hasError = true; + break; + } + } + } + } + } + + if(hasError) + { + item->appendError( "Arguments" ); + } + else + { + item->removeError( "Arguments" ); + } + + return !hasError; + } + return FALSE; +} + +#include "main.moc" diff --git a/kbabel/datatools/context/CMakeLists.txt b/kbabel/datatools/context/CMakeLists.txt index c448cca1..94781fef 100644 --- a/kbabel/datatools/context/CMakeLists.txt +++ b/kbabel/datatools/context/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_contexttool (module) ############### tde_add_kpart( kbabel_contexttool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/context/Makefile.am b/kbabel/datatools/context/Makefile.am index 3b56628a..6dca7415 100644 --- a/kbabel/datatools/context/Makefile.am +++ b/kbabel/datatools/context/Makefile.am @@ -6,7 +6,7 @@ kbabel_contexttool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_contexttool.la -kbabel_contexttool_la_SOURCES = main.cc +kbabel_contexttool_la_SOURCES = main.cpp kbabel_contexttool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/context/main.cc b/kbabel/datatools/context/main.cc deleted file mode 100644 index 0fb989d2..00000000 --- a/kbabel/datatools/context/main.cc +++ /dev/null @@ -1,115 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002 Stanislav Visnovsky - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_contexttool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -ContextTool::ContextTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ), _cache_origin( 0 ) -{ - i18n("what check found errors","context info"); -} - -bool ContextTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Context Tool does only accept the command 'validate' and 'shortcut'" << endl; - kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; - return FALSE; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Context Tool only accepts datatype CatalogItem" << endl; - return FALSE; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Context Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; - return FALSE; - } - - if( command == "validate" ) - { - CatalogItem* item = (CatalogItem*)(data); - - if( _cache_origin != item->project() ) - { - _context = item->project()->miscSettings().contextInfo; - _cache_origin = item->project(); - } - - bool hasError = false; - - if(!item->isUntranslated() && item->msgid().first().contains(_context) - && item->msgstr().first().contains(_context) ) - { - hasError = true; - } - - if(hasError) - { - item->appendError( "context info" ); - } - else - { - item->removeError( "context info" ); - } - - return !hasError; - } - return FALSE; -} - -#include "main.moc" diff --git a/kbabel/datatools/context/main.cpp b/kbabel/datatools/context/main.cpp new file mode 100644 index 00000000..0fb989d2 --- /dev/null +++ b/kbabel/datatools/context/main.cpp @@ -0,0 +1,115 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_contexttool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +ContextTool::ContextTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ) +{ + i18n("what check found errors","context info"); +} + +bool ContextTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Context Tool does only accept the command 'validate' and 'shortcut'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Context Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Context Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _cache_origin = item->project(); + } + + bool hasError = false; + + if(!item->isUntranslated() && item->msgid().first().contains(_context) + && item->msgstr().first().contains(_context) ) + { + hasError = true; + } + + if(hasError) + { + item->appendError( "context info" ); + } + else + { + item->removeError( "context info" ); + } + + return !hasError; + } + return FALSE; +} + +#include "main.moc" diff --git a/kbabel/datatools/equations/CMakeLists.txt b/kbabel/datatools/equations/CMakeLists.txt index f7b60f01..e4dd4a39 100644 --- a/kbabel/datatools/equations/CMakeLists.txt +++ b/kbabel/datatools/equations/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_equationstool (module) ############# tde_add_kpart( kbabel_equationstool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/equations/Makefile.am b/kbabel/datatools/equations/Makefile.am index dac35e6f..48b0f6bc 100644 --- a/kbabel/datatools/equations/Makefile.am +++ b/kbabel/datatools/equations/Makefile.am @@ -6,7 +6,7 @@ kbabel_equationstool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_equationstool.la -kbabel_equationstool_la_SOURCES = main.cc +kbabel_equationstool_la_SOURCES = main.cpp kbabel_equationstool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/equations/main.cc b/kbabel/datatools/equations/main.cc deleted file mode 100644 index c0dbbba2..00000000 --- a/kbabel/datatools/equations/main.cc +++ /dev/null @@ -1,113 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002 Stanislav Visnovsky - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_equationstool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -EquationsTool::EquationsTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ), _equation("^[a-zA-Z0-9]+=.+") -{ - i18n("what check found errors","equations"); -} - -bool EquationsTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Equations Tool does only accept the command 'validate' and 'shortcut'" << endl; - kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; - return FALSE; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Equations Tool only accepts datatype CatalogItem" << endl; - return FALSE; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Equations Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; - return FALSE; - } - - if( command == "validate" ) - { - CatalogItem* item = (CatalogItem*)(data); - - bool hasError = false; - - if(!item->isUntranslated() && !item->msgid().first().contains('\n') - && item->msgid().first().contains(_equation)) - { - int index = item->msgid().first().find('='); - TQString left = item->msgid().first().left(index); - index = item->msgstr().first().find('='); - if(left != item->msgstr().first().left(index)) - hasError = true; - } - - if(hasError) - { - item->appendError( "equations" ); - } - else - { - item->removeError( "equations" ); - } - - return !hasError; - } - return FALSE; -} - -#include "main.moc" diff --git a/kbabel/datatools/equations/main.cpp b/kbabel/datatools/equations/main.cpp new file mode 100644 index 00000000..c0dbbba2 --- /dev/null +++ b/kbabel/datatools/equations/main.cpp @@ -0,0 +1,113 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_equationstool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +EquationsTool::EquationsTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ), _equation("^[a-zA-Z0-9]+=.+") +{ + i18n("what check found errors","equations"); +} + +bool EquationsTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Equations Tool does only accept the command 'validate' and 'shortcut'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Equations Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Equations Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + bool hasError = false; + + if(!item->isUntranslated() && !item->msgid().first().contains('\n') + && item->msgid().first().contains(_equation)) + { + int index = item->msgid().first().find('='); + TQString left = item->msgid().first().left(index); + index = item->msgstr().first().find('='); + if(left != item->msgstr().first().left(index)) + hasError = true; + } + + if(hasError) + { + item->appendError( "equations" ); + } + else + { + item->removeError( "equations" ); + } + + return !hasError; + } + return FALSE; +} + +#include "main.moc" diff --git a/kbabel/datatools/length/CMakeLists.txt b/kbabel/datatools/length/CMakeLists.txt index 8750dbc5..df075cad 100644 --- a/kbabel/datatools/length/CMakeLists.txt +++ b/kbabel/datatools/length/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_lengthtool (module) ################ tde_add_kpart( kbabel_lengthtool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/length/Makefile.am b/kbabel/datatools/length/Makefile.am index 2359a95b..dc8e2867 100644 --- a/kbabel/datatools/length/Makefile.am +++ b/kbabel/datatools/length/Makefile.am @@ -6,7 +6,7 @@ kbabel_lengthtool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_lengthtool.la -kbabel_lengthtool_la_SOURCES = main.cc +kbabel_lengthtool_la_SOURCES = main.cpp kbabel_lengthtool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/length/main.cc b/kbabel/datatools/length/main.cc deleted file mode 100644 index f1c295eb..00000000 --- a/kbabel/datatools/length/main.cc +++ /dev/null @@ -1,142 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002 Stanislav Visnovsky - 2003 Dwayne Bailey - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalog.h" -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" -#include - -#include -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_lengthtool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -LengthTool::LengthTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ), _cache_origin( 0 ) -{ - i18n("which check found errors","translation has inconsistent length"); -} - -bool LengthTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Length Tool only accepts the 'validate' command" << endl; - kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; - return false; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Length Tool only accept the CatalogItem datatype" << endl; - return false; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Length Tool only accept the 'application/x-kbabel-catalogitem' mimetype" << endl; - return false; - } - - if( command == "validate" ) - { - - CatalogItem* item = (CatalogItem*)(data); - bool hasError = false; - TQStringList str, id; - - if(!item->isUntranslated()) { - - if( _cache_origin != item->project() ) - { - _context = item->project()->miscSettings().contextInfo; - _plurals = item->project()->miscSettings().singularPlural; - _cache_origin = item->project(); - } - - //Ensure KDE plural forms are in a StringList - if( item->pluralForm() == KDESpecific ) { - str = TQStringList::split( "\\n", item->msgstr().first(), true ); - id = TQStringList::split( "\\n", - item->msgid().first().replace( TQRegExp(_plurals), ""), true ); - } else { - str = item->msgstr(); - id = item->msgid(); - } - - //Check for translations that are too short or too long - //This may not be totally correct but we check both - //the singular and plural forms against each translated plural. - //FIXME: replace 10% check with configurable setting or a statistical - //based expected length relationship - int idlen, strlen; - for( TQStringList::Iterator i = id.begin() ; i != id.end() ; i++ ) { - TQString iditem = (*i); - idlen = iditem.replace( TQRegExp(_context),"").length(); - for( TQStringList::Iterator j = str.begin() ; j != str.end() ; j++ ) { - TQString stritem = (*j); - strlen = stritem.length(); - hasError = hasError || (strlen < (0.1 * idlen)) - || (strlen > (10 * idlen)); - } - } - - } - - if(hasError) - item->appendError( "translation has inconsistant length" ); - else - item->removeError( "translation has inconsistant length" ); - - return !hasError; - } - return false; -} - -#include "main.moc" diff --git a/kbabel/datatools/length/main.cpp b/kbabel/datatools/length/main.cpp new file mode 100644 index 00000000..f1c295eb --- /dev/null +++ b/kbabel/datatools/length/main.cpp @@ -0,0 +1,142 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + 2003 Dwayne Bailey + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalog.h" +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" +#include + +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_lengthtool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +LengthTool::LengthTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ) +{ + i18n("which check found errors","translation has inconsistent length"); +} + +bool LengthTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Length Tool only accepts the 'validate' command" << endl; + kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; + return false; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Length Tool only accept the CatalogItem datatype" << endl; + return false; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Length Tool only accept the 'application/x-kbabel-catalogitem' mimetype" << endl; + return false; + } + + if( command == "validate" ) + { + + CatalogItem* item = (CatalogItem*)(data); + bool hasError = false; + TQStringList str, id; + + if(!item->isUntranslated()) { + + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _plurals = item->project()->miscSettings().singularPlural; + _cache_origin = item->project(); + } + + //Ensure KDE plural forms are in a StringList + if( item->pluralForm() == KDESpecific ) { + str = TQStringList::split( "\\n", item->msgstr().first(), true ); + id = TQStringList::split( "\\n", + item->msgid().first().replace( TQRegExp(_plurals), ""), true ); + } else { + str = item->msgstr(); + id = item->msgid(); + } + + //Check for translations that are too short or too long + //This may not be totally correct but we check both + //the singular and plural forms against each translated plural. + //FIXME: replace 10% check with configurable setting or a statistical + //based expected length relationship + int idlen, strlen; + for( TQStringList::Iterator i = id.begin() ; i != id.end() ; i++ ) { + TQString iditem = (*i); + idlen = iditem.replace( TQRegExp(_context),"").length(); + for( TQStringList::Iterator j = str.begin() ; j != str.end() ; j++ ) { + TQString stritem = (*j); + strlen = stritem.length(); + hasError = hasError || (strlen < (0.1 * idlen)) + || (strlen > (10 * idlen)); + } + } + + } + + if(hasError) + item->appendError( "translation has inconsistant length" ); + else + item->removeError( "translation has inconsistant length" ); + + return !hasError; + } + return false; +} + +#include "main.moc" diff --git a/kbabel/datatools/not-translated/CMakeLists.txt b/kbabel/datatools/not-translated/CMakeLists.txt index 59d36138..41da20a1 100644 --- a/kbabel/datatools/not-translated/CMakeLists.txt +++ b/kbabel/datatools/not-translated/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_nottranslatedtool (module) ######### tde_add_kpart( kbabel_nottranslatedtool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/not-translated/Makefile.am b/kbabel/datatools/not-translated/Makefile.am index 40299023..52a88ca9 100644 --- a/kbabel/datatools/not-translated/Makefile.am +++ b/kbabel/datatools/not-translated/Makefile.am @@ -6,7 +6,7 @@ kbabel_nottranslatedtool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.l kde_module_LTLIBRARIES = kbabel_nottranslatedtool.la -kbabel_nottranslatedtool_la_SOURCES = main.cc +kbabel_nottranslatedtool_la_SOURCES = main.cpp kbabel_nottranslatedtool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/not-translated/main.cc b/kbabel/datatools/not-translated/main.cc deleted file mode 100644 index 68093191..00000000 --- a/kbabel/datatools/not-translated/main.cc +++ /dev/null @@ -1,129 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002 Stanislav Visnovsky - 2003 Dwayne Bailey - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalog.h" -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_nottranslatedtool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -NotTranslatedTool::NotTranslatedTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ) , _cache_origin( 0 ) -{ - i18n("which check found errors","English text in translation"); -} - -bool NotTranslatedTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Not Translated Tool only accepts the 'validate' command" << endl; - kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; - return false; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Not Translated Tool only accept the CatalogItem datatype" << endl; - return false; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Not Translated Tool only accept the 'application/x-kbabel-catalogitem' mimetype" << endl; - return false; - } - - if( command == "validate" ) - { - CatalogItem* item = (CatalogItem*)(data); - bool hasError = false; - - if(!item->isUntranslated()) { - if( _cache_origin != item->project() ) - { - _context = item->project()->miscSettings().contextInfo; - _plurals = item->project()->miscSettings().singularPlural; - _cache_origin = item->project(); - } - - //FIXME Expand this to do substring matching of non-translation - TQStringList id, str; - if( item->pluralForm() == KDESpecific ) { - str = TQStringList::split( "\\n", item->msgstr().first(), true ); - id = TQStringList::split( "\\n", - item->msgid().first().replace( TQRegExp(_plurals), ""), true ); - } else { - str = item->msgstr(); - id = item->msgid(); - } - for( TQStringList::Iterator i = id.begin() ; i != id.end() ; i++ ) { - TQString id_str = (*i).replace( TQRegExp(_context), ""); - for( TQStringList::Iterator j = str.begin() ; j != str.end() ; j++ ) { - TQString str_str = (*j); - hasError = hasError || ( id_str == str_str ); - } - } - - } - - if(hasError) - item->appendError( "english text in translation" ); - else - item->removeError( "english text in translation" ); - - return !hasError; - } - return false; -} - -#include "main.moc" diff --git a/kbabel/datatools/not-translated/main.cpp b/kbabel/datatools/not-translated/main.cpp new file mode 100644 index 00000000..68093191 --- /dev/null +++ b/kbabel/datatools/not-translated/main.cpp @@ -0,0 +1,129 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + 2003 Dwayne Bailey + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalog.h" +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_nottranslatedtool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +NotTranslatedTool::NotTranslatedTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ) , _cache_origin( 0 ) +{ + i18n("which check found errors","English text in translation"); +} + +bool NotTranslatedTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Not Translated Tool only accepts the 'validate' command" << endl; + kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; + return false; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Not Translated Tool only accept the CatalogItem datatype" << endl; + return false; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Not Translated Tool only accept the 'application/x-kbabel-catalogitem' mimetype" << endl; + return false; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + bool hasError = false; + + if(!item->isUntranslated()) { + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _plurals = item->project()->miscSettings().singularPlural; + _cache_origin = item->project(); + } + + //FIXME Expand this to do substring matching of non-translation + TQStringList id, str; + if( item->pluralForm() == KDESpecific ) { + str = TQStringList::split( "\\n", item->msgstr().first(), true ); + id = TQStringList::split( "\\n", + item->msgid().first().replace( TQRegExp(_plurals), ""), true ); + } else { + str = item->msgstr(); + id = item->msgid(); + } + for( TQStringList::Iterator i = id.begin() ; i != id.end() ; i++ ) { + TQString id_str = (*i).replace( TQRegExp(_context), ""); + for( TQStringList::Iterator j = str.begin() ; j != str.end() ; j++ ) { + TQString str_str = (*j); + hasError = hasError || ( id_str == str_str ); + } + } + + } + + if(hasError) + item->appendError( "english text in translation" ); + else + item->removeError( "english text in translation" ); + + return !hasError; + } + return false; +} + +#include "main.moc" diff --git a/kbabel/datatools/pluralforms/CMakeLists.txt b/kbabel/datatools/pluralforms/CMakeLists.txt index 2a86d0c3..80b3f102 100644 --- a/kbabel/datatools/pluralforms/CMakeLists.txt +++ b/kbabel/datatools/pluralforms/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_pluraltool (module) ################ tde_add_kpart( kbabel_pluraltool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/pluralforms/Makefile.am b/kbabel/datatools/pluralforms/Makefile.am index 951e08cb..53ea610d 100644 --- a/kbabel/datatools/pluralforms/Makefile.am +++ b/kbabel/datatools/pluralforms/Makefile.am @@ -6,7 +6,7 @@ kbabel_pluraltool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_pluraltool.la -kbabel_pluraltool_la_SOURCES = main.cc +kbabel_pluraltool_la_SOURCES = main.cpp kbabel_pluraltool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/pluralforms/main.cc b/kbabel/datatools/pluralforms/main.cc deleted file mode 100644 index 693a843b..00000000 --- a/kbabel/datatools/pluralforms/main.cc +++ /dev/null @@ -1,129 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002 Stanislav Visnovsky - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalog.h" -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_pluraltool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -PluralsTool::PluralsTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ), _cache_origin( 0 ), _neededForms(-1) -{ - i18n("what check found errors", "plural forms"); -} - -bool PluralsTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Plural Forms Tool does only accept the command 'validate' and 'shortcut'" << endl; - kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; - return FALSE; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Plural Forms Tool only accepts datatype CatalogItem" << endl; - return FALSE; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Plural Forms Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; - return FALSE; - } - - if( command == "validate" ) - { - if( _neededForms < 0 ) - { - Catalog* cat = new Catalog(this); - _neededForms = cat->defaultNumberOfPluralForms(); - delete cat; - } - - CatalogItem* item = (CatalogItem*)(data); - - if( _cache_origin != item->project() ) - { - _plurals = item->project()->miscSettings().singularPlural; - _cache_origin = item->project(); - } - - bool hasError = false; - - if(!item->isUntranslated() && item->pluralForm() == KDESpecific ) - { - if(_neededForms <= 0 || item->msgstr().first().contains(_plurals)) - { - hasError = true; - } - else if( item->msgstr().first().contains(TQString("\\n"))+1 != _neededForms ) - { - hasError = true; - } - } - - if(hasError) - { - item->appendError( "plural forms" ); - } - else - { - item->removeError( "plural forms" ); - } - - return !hasError; - } - return FALSE; -} - -#include "main.moc" diff --git a/kbabel/datatools/pluralforms/main.cpp b/kbabel/datatools/pluralforms/main.cpp new file mode 100644 index 00000000..693a843b --- /dev/null +++ b/kbabel/datatools/pluralforms/main.cpp @@ -0,0 +1,129 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalog.h" +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_pluraltool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +PluralsTool::PluralsTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ), _neededForms(-1) +{ + i18n("what check found errors", "plural forms"); +} + +bool PluralsTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Plural Forms Tool does only accept the command 'validate' and 'shortcut'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Plural Forms Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Plural Forms Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + if( _neededForms < 0 ) + { + Catalog* cat = new Catalog(this); + _neededForms = cat->defaultNumberOfPluralForms(); + delete cat; + } + + CatalogItem* item = (CatalogItem*)(data); + + if( _cache_origin != item->project() ) + { + _plurals = item->project()->miscSettings().singularPlural; + _cache_origin = item->project(); + } + + bool hasError = false; + + if(!item->isUntranslated() && item->pluralForm() == KDESpecific ) + { + if(_neededForms <= 0 || item->msgstr().first().contains(_plurals)) + { + hasError = true; + } + else if( item->msgstr().first().contains(TQString("\\n"))+1 != _neededForms ) + { + hasError = true; + } + } + + if(hasError) + { + item->appendError( "plural forms" ); + } + else + { + item->removeError( "plural forms" ); + } + + return !hasError; + } + return FALSE; +} + +#include "main.moc" diff --git a/kbabel/datatools/punctuation/CMakeLists.txt b/kbabel/datatools/punctuation/CMakeLists.txt index b325342f..d096dcf5 100644 --- a/kbabel/datatools/punctuation/CMakeLists.txt +++ b/kbabel/datatools/punctuation/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_punctuationtool (module) ########### tde_add_kpart( kbabel_punctuationtool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/punctuation/Makefile.am b/kbabel/datatools/punctuation/Makefile.am index 1aceb053..c30ada47 100644 --- a/kbabel/datatools/punctuation/Makefile.am +++ b/kbabel/datatools/punctuation/Makefile.am @@ -6,7 +6,7 @@ kbabel_punctuationtool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_punctuationtool.la -kbabel_punctuationtool_la_SOURCES = main.cc +kbabel_punctuationtool_la_SOURCES = main.cpp kbabel_punctuationtool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/punctuation/main.cc b/kbabel/datatools/punctuation/main.cc deleted file mode 100644 index 6d779518..00000000 --- a/kbabel/datatools/punctuation/main.cc +++ /dev/null @@ -1,157 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2003 Stanislav Visnovsky - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_punctuationtool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -PunctuationTool::PunctuationTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ) -{ - // bogus translation just for allowing the translation - i18n("what check found errors","punctuation"); -} - -bool PunctuationTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Punctuation Tool does only accept the command 'validate'" << endl; - kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; - return FALSE; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Punctuation Tool only accepts datatype CatalogItem" << endl; - return FALSE; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Punctuation Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; - return FALSE; - } - - if( command == "validate" ) - { - CatalogItem* item = (CatalogItem*)(data); - - bool hasError = false; - - if(!item->isUntranslated()) - { - TQString lineid=item->msgid().first(); - - // lookup punctuation in original text - TQRegExp punc("[\\.!\\?:]+$"); - int i = lineid.find(punc); - - TQString t(""); - - if( i != -1 ) t = lineid.right(lineid.length()-i); - - if( item->pluralForm() != NoPluralForm ) - { - // check, that both plural forms contain the same punctuation - TQString pl = *(item->msgid().at(1)); - int j = pl.find(punc); - - TQString tp(""); - if( j != -1 ) tp = pl.right(pl.length()-j); - - if( tp != t ) - { - kdWarning() << "Singular and plural form do not have the same punctuation" << endl; - } - } - - TQStringList forms = item->msgstr(true); - if( item->pluralForm() == KDESpecific ) { - forms = TQStringList::split("\\n",*item->msgstr(true).at(0)); - } - - for( TQStringList::Iterator form = forms.begin() ; form != forms.end(); form++ ) - { - TQString linestr=(*form); - - int j = linestr.find(punc); - - // there is no punctuation in original, but one in the translation - if( i == -1 && j != i ) - { - hasError = true; - break; - } - - // there is punctuation in original, but not same as in the translation - if( i != -1 && linestr.right(linestr.length()-j) != t ) - { - hasError = true; - break; - } - } - } - - if(hasError) - { - item->appendError( "punctuation" ); - } - else - { - item->removeError( "punctuation" ); - } - - return !hasError; - } - return FALSE; -} - -#include "main.moc" diff --git a/kbabel/datatools/punctuation/main.cpp b/kbabel/datatools/punctuation/main.cpp new file mode 100644 index 00000000..6d779518 --- /dev/null +++ b/kbabel/datatools/punctuation/main.cpp @@ -0,0 +1,157 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2003 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_punctuationtool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +PunctuationTool::PunctuationTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ) +{ + // bogus translation just for allowing the translation + i18n("what check found errors","punctuation"); +} + +bool PunctuationTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Punctuation Tool does only accept the command 'validate'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Punctuation Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Punctuation Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + bool hasError = false; + + if(!item->isUntranslated()) + { + TQString lineid=item->msgid().first(); + + // lookup punctuation in original text + TQRegExp punc("[\\.!\\?:]+$"); + int i = lineid.find(punc); + + TQString t(""); + + if( i != -1 ) t = lineid.right(lineid.length()-i); + + if( item->pluralForm() != NoPluralForm ) + { + // check, that both plural forms contain the same punctuation + TQString pl = *(item->msgid().at(1)); + int j = pl.find(punc); + + TQString tp(""); + if( j != -1 ) tp = pl.right(pl.length()-j); + + if( tp != t ) + { + kdWarning() << "Singular and plural form do not have the same punctuation" << endl; + } + } + + TQStringList forms = item->msgstr(true); + if( item->pluralForm() == KDESpecific ) { + forms = TQStringList::split("\\n",*item->msgstr(true).at(0)); + } + + for( TQStringList::Iterator form = forms.begin() ; form != forms.end(); form++ ) + { + TQString linestr=(*form); + + int j = linestr.find(punc); + + // there is no punctuation in original, but one in the translation + if( i == -1 && j != i ) + { + hasError = true; + break; + } + + // there is punctuation in original, but not same as in the translation + if( i != -1 && linestr.right(linestr.length()-j) != t ) + { + hasError = true; + break; + } + } + } + + if(hasError) + { + item->appendError( "punctuation" ); + } + else + { + item->removeError( "punctuation" ); + } + + return !hasError; + } + return FALSE; +} + +#include "main.moc" diff --git a/kbabel/datatools/regexp/CMakeLists.txt b/kbabel/datatools/regexp/CMakeLists.txt index 77e4553b..e75b53a4 100644 --- a/kbabel/datatools/regexp/CMakeLists.txt +++ b/kbabel/datatools/regexp/CMakeLists.txt @@ -36,7 +36,7 @@ install( FILES regexplist.xml DESTINATION ${DATA_INSTALL_DIR}/kbabel ) ##### kbabel_regexptool (module) ################ tde_add_kpart( kbabel_regexptool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/regexp/Makefile.am b/kbabel/datatools/regexp/Makefile.am index 42ebe1cb..cc574668 100644 --- a/kbabel/datatools/regexp/Makefile.am +++ b/kbabel/datatools/regexp/Makefile.am @@ -6,7 +6,7 @@ kbabel_regexptool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_regexptool.la -kbabel_regexptool_la_SOURCES = main.cc +kbabel_regexptool_la_SOURCES = main.cpp kbabel_regexptool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/regexp/main.cc b/kbabel/datatools/regexp/main.cc deleted file mode 100644 index e500728e..00000000 --- a/kbabel/datatools/regexp/main.cc +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright (C) 2005 Albert Cervera i Areny - - Based on Copyright (C) 1998, 1999 Torben Weis - 2002 Stanislav Visnovsky - 2003 Dwayne Bailey - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include -#include "catalog.h" -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_regexptool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -RegExpTool::RegExpTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ) -{ - i18n("which check found errors","translation has inconsistent length"); - loadExpressions(); - if ( ! _error.isNull() ) - KMessageBox::error( (TQWidget*)parent, i18n( "Error loading data (%1)" ).arg( _error ) ); -} - -bool RegExpTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "validate" ) - { - kdDebug(KBABEL) << "RegExpTool only accepts the 'validate' command" << endl; - kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; - return false; - } - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "RegExpTool only accepts the CatalogItem datatype" << endl; - return false; - } - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "RegExpTool only accepts the 'application/x-kbabel-catalogitem' mimetype" << endl; - return false; - } - - bool hasError = false; - if( command == "validate" ) - { - CatalogItem* item = (CatalogItem*)(data); - - if(!item->isUntranslated()) { - ExpressionList::Iterator it( _list.begin() ); - ExpressionList::Iterator end( _list.end() ); - TQStringList msgs = item->msgstr(); - TQStringList results; - for ( ; it != end; ++it ) { - results.clear(); - results = msgs.grep( (*it).regExp() ); - if ( results.size() > 0 ) { - hasError = true; - break; - } - } - } - if(hasError) { - item->appendError( "regexp" ); - } else { - item->removeError( "regexp" ); - } - } - return !hasError; -} - - -void RegExpTool::loadExpressions() -{ - // TODO: Change file path - TQFile file( TQDir::homeDirPath() + "/.trinity/share/apps/kbabel/regexplist.xml" ); - TQDomDocument doc; - - if ( ! file.open( IO_ReadOnly ) ) { - kdDebug() << "File not found" << endl; - _error = i18n( "File not found" ); - return; - } - if ( ! doc.setContent( &file ) ) { - kdDebug() << "Could not set content of xml file" << endl; - _error = i18n( "The file is not a XML" ); - return; - } - file.close(); - - TQDomElement docElem = doc.documentElement(); - TQDomNode n = docElem.firstChild(); - while( !n.isNull() ) { - TQDomElement e = n.toElement(); - if( !e.isNull() ) - elementToExpression( e ); - if ( ! _error.isNull() ) - break; - n = n.nextSibling(); - } -} - -void RegExpTool::elementToExpression( const TQDomElement& e ) -{ - TQString name; - TQString exp; - bool cs = false; //Expressions are case insensitive by default - - if ( e.tagName().compare( "item" ) != 0 ) { - _error = i18n( "Expected tag 'item'" ); - return; - } - - TQDomNode n = e.firstChild(); - if ( n.isNull() ) { - _error = i18n( "First child of 'item' is not a node" ); - return; - } - - TQDomElement el = n.toElement(); - if ( el.isNull() || el.tagName().compare( "name" ) != 0 ) { - _error = i18n( "Expected tag 'name'" ); - return; - } - name = el.text(); - - n = n.nextSibling(); - el = n.toElement(); - if ( el.isNull() || el.tagName().compare( "exp" ) != 0 ) { - _error = i18n( "Expected tag 'exp'" ); - return; - } - exp = el.text(); - - n = n.nextSibling(); - el = n.toElement(); - if ( ! el.isNull() ) - cs = true; - - kdDebug(KBABEL) << "RegExpTool: Adding expression: " << name << endl; - _list.append( Expression( name, TQRegExp( exp, cs ) ) ); -} - -#include "main.moc" diff --git a/kbabel/datatools/regexp/main.cpp b/kbabel/datatools/regexp/main.cpp new file mode 100644 index 00000000..e500728e --- /dev/null +++ b/kbabel/datatools/regexp/main.cpp @@ -0,0 +1,181 @@ +/* Copyright (C) 2005 Albert Cervera i Areny + + Based on Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + 2003 Dwayne Bailey + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include "catalog.h" +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_regexptool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +RegExpTool::RegExpTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ) +{ + i18n("which check found errors","translation has inconsistent length"); + loadExpressions(); + if ( ! _error.isNull() ) + KMessageBox::error( (TQWidget*)parent, i18n( "Error loading data (%1)" ).arg( _error ) ); +} + +bool RegExpTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "RegExpTool only accepts the 'validate' command" << endl; + kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; + return false; + } + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "RegExpTool only accepts the CatalogItem datatype" << endl; + return false; + } + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "RegExpTool only accepts the 'application/x-kbabel-catalogitem' mimetype" << endl; + return false; + } + + bool hasError = false; + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + if(!item->isUntranslated()) { + ExpressionList::Iterator it( _list.begin() ); + ExpressionList::Iterator end( _list.end() ); + TQStringList msgs = item->msgstr(); + TQStringList results; + for ( ; it != end; ++it ) { + results.clear(); + results = msgs.grep( (*it).regExp() ); + if ( results.size() > 0 ) { + hasError = true; + break; + } + } + } + if(hasError) { + item->appendError( "regexp" ); + } else { + item->removeError( "regexp" ); + } + } + return !hasError; +} + + +void RegExpTool::loadExpressions() +{ + // TODO: Change file path + TQFile file( TQDir::homeDirPath() + "/.trinity/share/apps/kbabel/regexplist.xml" ); + TQDomDocument doc; + + if ( ! file.open( IO_ReadOnly ) ) { + kdDebug() << "File not found" << endl; + _error = i18n( "File not found" ); + return; + } + if ( ! doc.setContent( &file ) ) { + kdDebug() << "Could not set content of xml file" << endl; + _error = i18n( "The file is not a XML" ); + return; + } + file.close(); + + TQDomElement docElem = doc.documentElement(); + TQDomNode n = docElem.firstChild(); + while( !n.isNull() ) { + TQDomElement e = n.toElement(); + if( !e.isNull() ) + elementToExpression( e ); + if ( ! _error.isNull() ) + break; + n = n.nextSibling(); + } +} + +void RegExpTool::elementToExpression( const TQDomElement& e ) +{ + TQString name; + TQString exp; + bool cs = false; //Expressions are case insensitive by default + + if ( e.tagName().compare( "item" ) != 0 ) { + _error = i18n( "Expected tag 'item'" ); + return; + } + + TQDomNode n = e.firstChild(); + if ( n.isNull() ) { + _error = i18n( "First child of 'item' is not a node" ); + return; + } + + TQDomElement el = n.toElement(); + if ( el.isNull() || el.tagName().compare( "name" ) != 0 ) { + _error = i18n( "Expected tag 'name'" ); + return; + } + name = el.text(); + + n = n.nextSibling(); + el = n.toElement(); + if ( el.isNull() || el.tagName().compare( "exp" ) != 0 ) { + _error = i18n( "Expected tag 'exp'" ); + return; + } + exp = el.text(); + + n = n.nextSibling(); + el = n.toElement(); + if ( ! el.isNull() ) + cs = true; + + kdDebug(KBABEL) << "RegExpTool: Adding expression: " << name << endl; + _list.append( Expression( name, TQRegExp( exp, cs ) ) ); +} + +#include "main.moc" diff --git a/kbabel/datatools/regexp/regexplist.xml b/kbabel/datatools/regexp/regexplist.xml index 72f647cb..39624092 100644 --- a/kbabel/datatools/regexp/regexplist.xml +++ b/kbabel/datatools/regexp/regexplist.xml @@ -10,7 +10,7 @@ ... - Right now the file should be copied to ~/.trinity/share/apps/kbabel/regexplist.xml. I'm sorry this cannot be configured but hope it will in the future. By the time if you need another location you have to modify the source code (main.cc) + Right now the file should be copied to ~/.trinity/share/apps/kbabel/regexplist.xml. I'm sorry this cannot be configured but hope it will in the future. By the time if you need another location you have to modify the source code (main.cpp) You'll see in the example that most expressions start with '(^| |\\t)+' and then a word. This is to ensure it _is_ a word. Using the usual expressions to ensure we pick up a whole word doesn't work for the catalan language. Anyway, if you need to match a tab be sure you use the '\\t' expression. @@ -300,4 +300,4 @@ - \ No newline at end of file + diff --git a/kbabel/datatools/setfuzzy/CMakeLists.txt b/kbabel/datatools/setfuzzy/CMakeLists.txt index 864a5030..5ccf8bac 100644 --- a/kbabel/datatools/setfuzzy/CMakeLists.txt +++ b/kbabel/datatools/setfuzzy/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_setfuzzytool (module) ############## tde_add_kpart( kbabel_setfuzzytool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/setfuzzy/Makefile.am b/kbabel/datatools/setfuzzy/Makefile.am index f1a5b8bc..1b84cb02 100644 --- a/kbabel/datatools/setfuzzy/Makefile.am +++ b/kbabel/datatools/setfuzzy/Makefile.am @@ -6,7 +6,7 @@ kbabel_setfuzzytool_la_LIBADD = ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_setfuzzytool.la -kbabel_setfuzzytool_la_SOURCES = main.cc +kbabel_setfuzzytool_la_SOURCES = main.cpp kbabel_setfuzzytool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/setfuzzy/main.cc b/kbabel/datatools/setfuzzy/main.cc deleted file mode 100644 index 7bc0ed16..00000000 --- a/kbabel/datatools/setfuzzy/main.cc +++ /dev/null @@ -1,98 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2003 Stanislav Visnovsky - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalog.h" -#include "main.h" - -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_setfuzzytool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -SetFuzzyTool::SetFuzzyTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ) -{ -} - -bool SetFuzzyTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "allfuzzy" ) - { - kdDebug(KBABEL) << "Fuzzy Toggling Tool does only accept the command 'allfuzzy'" << endl; - kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; - return FALSE; - } - - // Check wether we can accept the data - if ( datatype != "Catalog" ) - { - kdDebug(KBABEL) << "Fuzzy Toggling Tool only accepts datatype Catalog" << endl; - return FALSE; - } - - if ( mimetype != "application/x-kbabel-catalog" ) - { - kdDebug(KBABEL) << "Plural Forms Tool only accepts mimetype application/x-kbabel-catalog" << endl; - return FALSE; - } - - if( command == "allfuzzy" ) - { - Catalog* catalog = (Catalog*)(data); - - catalog->applyBeginCommand(0,Msgstr,0); - - for( uint index=0; index < catalog->numberOfEntries(); index++ ) - { - if( !catalog->isUntranslated(index) ) - { - catalog->setFuzzy(index,true); - } - } - - catalog->applyEndCommand(0,Msgstr,0); - } - return TRUE; -} - -#include "main.moc" diff --git a/kbabel/datatools/setfuzzy/main.cpp b/kbabel/datatools/setfuzzy/main.cpp new file mode 100644 index 00000000..7bc0ed16 --- /dev/null +++ b/kbabel/datatools/setfuzzy/main.cpp @@ -0,0 +1,98 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2003 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalog.h" +#include "main.h" + +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_setfuzzytool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +SetFuzzyTool::SetFuzzyTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ) +{ +} + +bool SetFuzzyTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "allfuzzy" ) + { + kdDebug(KBABEL) << "Fuzzy Toggling Tool does only accept the command 'allfuzzy'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "Catalog" ) + { + kdDebug(KBABEL) << "Fuzzy Toggling Tool only accepts datatype Catalog" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalog" ) + { + kdDebug(KBABEL) << "Plural Forms Tool only accepts mimetype application/x-kbabel-catalog" << endl; + return FALSE; + } + + if( command == "allfuzzy" ) + { + Catalog* catalog = (Catalog*)(data); + + catalog->applyBeginCommand(0,Msgstr,0); + + for( uint index=0; index < catalog->numberOfEntries(); index++ ) + { + if( !catalog->isUntranslated(index) ) + { + catalog->setFuzzy(index,true); + } + } + + catalog->applyEndCommand(0,Msgstr,0); + } + return TRUE; +} + +#include "main.moc" diff --git a/kbabel/datatools/whitespace/CMakeLists.txt b/kbabel/datatools/whitespace/CMakeLists.txt index 13f1c0f1..94784981 100644 --- a/kbabel/datatools/whitespace/CMakeLists.txt +++ b/kbabel/datatools/whitespace/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_whitespacetool (module) ############ tde_add_kpart( kbabel_whitespacetool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/whitespace/Makefile.am b/kbabel/datatools/whitespace/Makefile.am index eb3937fb..890d8dc1 100644 --- a/kbabel/datatools/whitespace/Makefile.am +++ b/kbabel/datatools/whitespace/Makefile.am @@ -6,7 +6,7 @@ kbabel_whitespacetool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_whitespacetool.la -kbabel_whitespacetool_la_SOURCES = main.cc +kbabel_whitespacetool_la_SOURCES = main.cpp kbabel_whitespacetool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/whitespace/main.cc b/kbabel/datatools/whitespace/main.cc deleted file mode 100644 index 06558211..00000000 --- a/kbabel/datatools/whitespace/main.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002 Stanislav Visnovsky - 2003 Dwayne Bailey - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalog.h" -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_whitespacetool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -WhitespaceTool::WhitespaceTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ), _cache_origin( 0 ), _equation("^[a-zA-Z0-9]+=") -{ - i18n("which check found errors","whitespace only translation"); -} - -bool WhitespaceTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - - if ( command != "validate" ) - { - kdDebug(KBABEL) << "Whitespace Tool only accepts the 'validate' command" << endl; - kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; - return false; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "Whitespace Tool only accept the CatalogItem datatype" << endl; - return false; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "Whitespace Tool only accept the 'application/x-kbabel-catalogitem' mimetype" << endl; - return false; - } - - if( command == "validate" ) - { - - CatalogItem* item = (CatalogItem*)(data); - bool hasIdError = false; - bool hasStrError = false; - TQRegExp _whitespace("^\\s+$"); - TQStringList str, id; - - if(!item->isUntranslated()) { - if( _cache_origin != item->project() ) - { - _plurals = item->project()->miscSettings().singularPlural; - _cache_origin = item->project(); - } - - //Ensure KDE plural forms are in a StringList - //FIXME Eliminate context information and this could become a generic message splitter - if( item->pluralForm() == KDESpecific ) { - str = TQStringList::split( "\\n", item->msgstr().first(), true ); - id = TQStringList::split( "\\n", - item->msgid().first().replace( TQRegExp(_plurals), ""), true ); - } else { - str = item->msgstr(); - id = item->msgid(); - } - - //Strip equations - id.first().replace( TQRegExp(_equation), ""); - str.first().replace( TQRegExp(_equation), ""); - - //Ignore Messages with blank msgid components - for( TQStringList::Iterator it = id.begin() ; it != id.end() ; it++ ) { - TQString resultstring = (*it); - hasIdError = hasIdError || resultstring.contains(_whitespace); - } - if( hasIdError ) return true; - - //Check each TQString in the List is not whitespace - for( TQStringList::Iterator it = str.begin() ; it != str.end() ; it++ ) { - TQString resultstring = (*it); - hasStrError = hasStrError || resultstring.contains(_whitespace); - } - - } - - if(hasStrError) { - item->appendError( "whitespace translation" ); - return false; - } else { - item->removeError( "whitespace translation" ); - return true; - } - - } - return false; -} - -#include "main.moc" diff --git a/kbabel/datatools/whitespace/main.cpp b/kbabel/datatools/whitespace/main.cpp new file mode 100644 index 00000000..06558211 --- /dev/null +++ b/kbabel/datatools/whitespace/main.cpp @@ -0,0 +1,144 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + 2003 Dwayne Bailey + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalog.h" +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_whitespacetool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +WhitespaceTool::WhitespaceTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ), _equation("^[a-zA-Z0-9]+=") +{ + i18n("which check found errors","whitespace only translation"); +} + +bool WhitespaceTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Whitespace Tool only accepts the 'validate' command" << endl; + kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; + return false; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Whitespace Tool only accept the CatalogItem datatype" << endl; + return false; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Whitespace Tool only accept the 'application/x-kbabel-catalogitem' mimetype" << endl; + return false; + } + + if( command == "validate" ) + { + + CatalogItem* item = (CatalogItem*)(data); + bool hasIdError = false; + bool hasStrError = false; + TQRegExp _whitespace("^\\s+$"); + TQStringList str, id; + + if(!item->isUntranslated()) { + if( _cache_origin != item->project() ) + { + _plurals = item->project()->miscSettings().singularPlural; + _cache_origin = item->project(); + } + + //Ensure KDE plural forms are in a StringList + //FIXME Eliminate context information and this could become a generic message splitter + if( item->pluralForm() == KDESpecific ) { + str = TQStringList::split( "\\n", item->msgstr().first(), true ); + id = TQStringList::split( "\\n", + item->msgid().first().replace( TQRegExp(_plurals), ""), true ); + } else { + str = item->msgstr(); + id = item->msgid(); + } + + //Strip equations + id.first().replace( TQRegExp(_equation), ""); + str.first().replace( TQRegExp(_equation), ""); + + //Ignore Messages with blank msgid components + for( TQStringList::Iterator it = id.begin() ; it != id.end() ; it++ ) { + TQString resultstring = (*it); + hasIdError = hasIdError || resultstring.contains(_whitespace); + } + if( hasIdError ) return true; + + //Check each TQString in the List is not whitespace + for( TQStringList::Iterator it = str.begin() ; it != str.end() ; it++ ) { + TQString resultstring = (*it); + hasStrError = hasStrError || resultstring.contains(_whitespace); + } + + } + + if(hasStrError) { + item->appendError( "whitespace translation" ); + return false; + } else { + item->removeError( "whitespace translation" ); + return true; + } + + } + return false; +} + +#include "main.moc" diff --git a/kbabel/datatools/xml/CMakeLists.txt b/kbabel/datatools/xml/CMakeLists.txt index 0fa9676d..ea47a588 100644 --- a/kbabel/datatools/xml/CMakeLists.txt +++ b/kbabel/datatools/xml/CMakeLists.txt @@ -34,7 +34,7 @@ tde_create_translated_desktop( ##### kbabel_xmltool (module) ################### tde_add_kpart( kbabel_xmltool AUTOMOC - SOURCES main.cc + SOURCES main.cpp LINK kbabelcommon-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kbabel/datatools/xml/Makefile.am b/kbabel/datatools/xml/Makefile.am index 3f116709..2fd2c28d 100644 --- a/kbabel/datatools/xml/Makefile.am +++ b/kbabel/datatools/xml/Makefile.am @@ -6,7 +6,7 @@ kbabel_xmltool_la_LIBADD = $(LIB_TDEIO) ../../common/libkbabelcommon.la kde_module_LTLIBRARIES = kbabel_xmltool.la -kbabel_xmltool_la_SOURCES = main.cc +kbabel_xmltool_la_SOURCES = main.cpp kbabel_xmltool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined diff --git a/kbabel/datatools/xml/main.cc b/kbabel/datatools/xml/main.cc deleted file mode 100644 index 59342c0d..00000000 --- a/kbabel/datatools/xml/main.cc +++ /dev/null @@ -1,206 +0,0 @@ -/* This file is part of KBabel - based Copyright (C) 1998, 1999 Torben Weis - 2002-2003 Stanislav Visnovsky - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the TQt library by Trolltech AS, Norway (or with modified versions - of TQt that use the same license as TQt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - TQt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. - -*/ - -#include -#include "catalogitem.h" -#include "catalogsettings.h" -#include "main.h" - -#include - -#include -#include -#include -#include -#include -#include - -/*************************************************** - * - * Factory - * - ***************************************************/ - -K_EXPORT_COMPONENT_FACTORY( kbabel_xmltool, KGenericFactory ( "kbabeldatatool" ) ) - -using namespace KBabel; - -XMLTool::XMLTool( TQObject* parent, const char* name, const TQStringList & ) - : KDataTool( parent, name ), _cache_origin( 0 ) -{ - i18n( "what check found errors", "XML tags" ); -} - -bool XMLTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) -{ - if ( command != "validate" ) - { - kdDebug(KBABEL) << "XML Tool does only accept the command 'validate' and 'shortcut'" << endl; - kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; - return FALSE; - } - - // Check wether we can accept the data - if ( datatype != "CatalogItem" ) - { - kdDebug(KBABEL) << "XML Tool only accepts datatype CatalogItem" << endl; - return FALSE; - } - - if ( mimetype != "application/x-kbabel-catalogitem" ) - { - kdDebug(KBABEL) << "XML Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; - return FALSE; - } - - if( command == "validate" ) - { - CatalogItem* item = (CatalogItem*)(data); - - if( _cache_origin != item->project() ) - { - _context = item->project()->miscSettings().contextInfo; - _cache_origin = item->project(); - } - - uint correctnessLevel = 0; - TQString msgid = item->msgid().first(); - msgid.replace( "\\\"", "\"" ); // Change '\"' to '"' - msgid.replace( TQRegExp( "&(?![a-zA-Z0-9]+;)" ), "&" ); - msgid.replace( _context, "" ); - msgid.replace("\n",""); // delete newlines - - if( _levelCache.contains(msgid) ) - { - correctnessLevel = _levelCache[msgid]; - } - else - { - // identify the level of correctness - if( isFullyCompliant(msgid) ) - { - correctnessLevel = 0; - } - else if( isNonCaseCompliant(msgid) ) - { - correctnessLevel = 1; - } - else if( isNonCaseWithoutCommonCompliant(msgid) ) - { - correctnessLevel = 2; - } - else - { - correctnessLevel = 3; - } - - _levelCache[msgid] = correctnessLevel; - } - - bool hasError = false; - - if(!item->isUntranslated()) - { - TQStringList str = item->msgstr(true); - for( TQStringList::Iterator form = str.begin() ; form != str.end() ; form++ ) - { - TQString text=(*form); - text.replace( "\\\"", "\"" ); // Change '\"' to '"' - text.replace( TQRegExp( "&(?![a-zA-Z0-9]+;)" ), "&" ); - - // isNonCaseWithoutCommonCompliant can fail - // even though higher level checks works - // see case 2. - switch( correctnessLevel ) - { - case 0: hasError = !isFullyCompliant(text); break; - case 1: hasError = !isNonCaseCompliant(text); break; - case 2: hasError = !isNonCaseWithoutCommonCompliant(text); - if (hasError) - { - hasError = !isNonCaseCompliant(text) || - !isFullyCompliant(text); - } - break; - case 3: hasError = false; break; // the original is broken - default: kdWarning() << "No compliance level, this should not happen" << endl; - } - } - } - - if(hasError) - { - item->appendError( "XML tags" ); - } - else - { - item->removeError( "XML tags" ); - } - - return !hasError; - } - return FALSE; -} - -bool XMLTool::isFullyCompliant( const TQString& text) -{ - TQDomDocument doc; - return doc.setContent("" + text + "" ); -} - -bool XMLTool::isNonCaseCompliant( const TQString& text) -{ - TQDomDocument doc; - TQString test = text.lower(); - return doc.setContent("" + test + "" ); -} - -bool XMLTool::isNonCaseWithoutCommonCompliant( const TQString& text) -{ - TQDomDocument doc; - TQString test = text.lower(); - TQRegExp rx( "(
)|(
)|(

)||(<\\w+@(\\w+.)*\\w+>)" ); - test.replace( rx, "" ); - - TQString a; - do - { - a = test; - test.replace( TQRegExp("<[^_:A-Za-z/]"), "" ); - } while( a!=test); - - test.replace( TQRegExp("<$"), "" ); - - return doc.setContent("" + test + "" ); -} - -#include "main.moc" diff --git a/kbabel/datatools/xml/main.cpp b/kbabel/datatools/xml/main.cpp new file mode 100644 index 00000000..59342c0d --- /dev/null +++ b/kbabel/datatools/xml/main.cpp @@ -0,0 +1,206 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis + 2002-2003 Stanislav Visnovsky + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the TQt library by Trolltech AS, Norway (or with modified versions + of TQt that use the same license as TQt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + TQt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include + +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_xmltool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +XMLTool::XMLTool( TQObject* parent, const char* name, const TQStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ) +{ + i18n( "what check found errors", "XML tags" ); +} + +bool XMLTool::run( const TQString& command, void* data, const TQString& datatype, const TQString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "XML Tool does only accept the command 'validate' and 'shortcut'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "XML Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "XML Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _cache_origin = item->project(); + } + + uint correctnessLevel = 0; + TQString msgid = item->msgid().first(); + msgid.replace( "\\\"", "\"" ); // Change '\"' to '"' + msgid.replace( TQRegExp( "&(?![a-zA-Z0-9]+;)" ), "&" ); + msgid.replace( _context, "" ); + msgid.replace("\n",""); // delete newlines + + if( _levelCache.contains(msgid) ) + { + correctnessLevel = _levelCache[msgid]; + } + else + { + // identify the level of correctness + if( isFullyCompliant(msgid) ) + { + correctnessLevel = 0; + } + else if( isNonCaseCompliant(msgid) ) + { + correctnessLevel = 1; + } + else if( isNonCaseWithoutCommonCompliant(msgid) ) + { + correctnessLevel = 2; + } + else + { + correctnessLevel = 3; + } + + _levelCache[msgid] = correctnessLevel; + } + + bool hasError = false; + + if(!item->isUntranslated()) + { + TQStringList str = item->msgstr(true); + for( TQStringList::Iterator form = str.begin() ; form != str.end() ; form++ ) + { + TQString text=(*form); + text.replace( "\\\"", "\"" ); // Change '\"' to '"' + text.replace( TQRegExp( "&(?![a-zA-Z0-9]+;)" ), "&" ); + + // isNonCaseWithoutCommonCompliant can fail + // even though higher level checks works + // see case 2. + switch( correctnessLevel ) + { + case 0: hasError = !isFullyCompliant(text); break; + case 1: hasError = !isNonCaseCompliant(text); break; + case 2: hasError = !isNonCaseWithoutCommonCompliant(text); + if (hasError) + { + hasError = !isNonCaseCompliant(text) || + !isFullyCompliant(text); + } + break; + case 3: hasError = false; break; // the original is broken + default: kdWarning() << "No compliance level, this should not happen" << endl; + } + } + } + + if(hasError) + { + item->appendError( "XML tags" ); + } + else + { + item->removeError( "XML tags" ); + } + + return !hasError; + } + return FALSE; +} + +bool XMLTool::isFullyCompliant( const TQString& text) +{ + TQDomDocument doc; + return doc.setContent("" + text + "" ); +} + +bool XMLTool::isNonCaseCompliant( const TQString& text) +{ + TQDomDocument doc; + TQString test = text.lower(); + return doc.setContent("" + test + "" ); +} + +bool XMLTool::isNonCaseWithoutCommonCompliant( const TQString& text) +{ + TQDomDocument doc; + TQString test = text.lower(); + TQRegExp rx( "(
)|(


)|(

)||(<\\w+@(\\w+.)*\\w+>)" ); + test.replace( rx, "" ); + + TQString a; + do + { + a = test; + test.replace( TQRegExp("<[^_:A-Za-z/]"), "" ); + } while( a!=test); + + test.replace( TQRegExp("<$"), "" ); + + return doc.setContent("" + test + "" ); +} + +#include "main.moc" diff --git a/kbabel/kbabeldict/modules/dbsearchengine/makemsgdb.C b/kbabel/kbabeldict/modules/dbsearchengine/makemsgdb.C deleted file mode 100644 index a83d947b..00000000 --- a/kbabel/kbabeldict/modules/dbsearchengine/makemsgdb.C +++ /dev/null @@ -1,327 +0,0 @@ -#include -#include -#include -#include -#include - -void removechar (char *s, int c) -{ - int i, l; - l = strlen (s); - if ((c >= l) || (c < 0)) - return; - for (i = c; i < l; i++) - s[i] = s[i + 1]; -} -void removeallc (char *s, char c) -{ - char *pos; - while ((pos = strchr (s, c)) != 0) - removechar (s, (long int) pos - (long int) s); - -} - -void normalizestr (char *s) -{ - char *pos; - while ((pos = strstr (s, "#~")) != 0) { - removechar (s, (long int) pos - (long int) s); - removechar (s, (long int) pos - (long int) s); - } - while (strchr (s, ' ') == s) - removechar (s, 0); -} - -void freadline(char *buff,FILE *f) -{ -char c; -while ((fread(&c,1,1,f)==1) && (c!='\n')) - { - *buff=c; - buff++; - } -*buff=0; - -} - -int makePoDb(const char* sourceName,const char* outputName) -{ -static bool open = false; -int m=0,n=0,h=0; -GDBM_FILE db; -datum key,value; -char *s,a[20000],b[2000],k[2000],v[2000]; -int i,*np,nmax=0,co=-1,oldref[2000]; -long int tim; -FILE *mlf; -bool nextIsFuzzy; -bool isAMsgId=true; -/* char keystring[1000],valuestring[1000]; */ - -/*Read headers, refnum end other info */ -db = gdbm_open((char *)outputName,1024,GDBM_READER,0666,0); -mlf = fopen(sourceName,"r"); -if(strrchr(sourceName,'/')!=0) -sourceName=strrchr(sourceName,'/')+1; - -if(!(db==0)) - { - printf("ciao\n"); - key.dptr=a; - strcpy(a,"__@REFNUM__"); - key.dsize=strlen(a)+1; - value = gdbm_fetch(db,key); - np=(int*)value.dptr; - nmax=*np; - for(i=0;i",oldref[co],*re); - if(oldref[r]==*re) - { - modif=true; - // fprintf(stderr,"Yes\n"); - *re=(nmax-1); - } //else fprintf(stderr,"No\n"); - } - // fprintf(stderr,"qui\n"); - if(!modif) - md=nr; - // fprintf(stderr,"modif %s\n",modif ? "true":"false"); - } - } - - } - - if(!exist) - { - int oldlen=(long int)os-(long int)oldvalue.dptr-4; - memcpy(a+4,oldvalue.dptr+4,oldlen); -// fprintf(stderr,"***!exist Old len is %d+4 1st str is %s\n",oldlen,a+4); - v++; - t=(int *)a; - *t=v; - // fprintf(stderr,"b=%s",b); - strcpy(a+4+oldlen,b); - re=(int *)(a+4+oldlen+strlen(b)+1); - *re=1; - re++; - *re=nmax-1; - //fprintf(stderr,"a+4=%s a+4+oldlen=%s",a+4,a+4+oldlen); - value.dptr=a; - value.dsize=oldlen+strlen(b)+1+4+8; - gdbm_store(db,key,value,GDBM_REPLACE); - n++; - } else - { - if(!modif) - { -// fprintf(stderr,"grossa crisi %d\n",*md); -// fprintf(stderr,"Old num of ref \n"); - int oldlen1=(long int)(md)-(long int)(oldvalue.dptr)-4; - int oldlen2=(long int)(os)-(long int)(md)-4; //-4 because nr - memcpy(a+4,oldvalue.dptr+4,oldlen1); - memcpy(a+4+oldlen1+8,oldvalue.dptr+4+oldlen1+4,oldlen2); - re=(int *)(a+4+oldlen1); - *re=(*md )+1; - // *re++; - re++; - *re=nmax-1; - t=(int *)a; - *t=v; - value.dptr=a; - value.dsize=oldlen1+oldlen2+4+8; - gdbm_store(db,key,value,GDBM_REPLACE); - n++; - } - else //if (modif) - { - value.dptr=oldvalue.dptr; - value.dsize=oldvalue.dsize; - gdbm_store(db,key,value,GDBM_REPLACE); - } - } - - h++; - } else { - - m++; - } - } - } - - } - - - } - - fclose(mlf); - gdbm_close(db); - open=false; - printf("new Key in database %d\n old key found %d\n value added %d\n",m,h,n); - return m+n; -} - - - -main(int argc,char **argv) -{ -int i; -for(i=1;i +#include +#include +#include +#include + +void removechar (char *s, int c) +{ + int i, l; + l = strlen (s); + if ((c >= l) || (c < 0)) + return; + for (i = c; i < l; i++) + s[i] = s[i + 1]; +} +void removeallc (char *s, char c) +{ + char *pos; + while ((pos = strchr (s, c)) != 0) + removechar (s, (long int) pos - (long int) s); + +} + +void normalizestr (char *s) +{ + char *pos; + while ((pos = strstr (s, "#~")) != 0) { + removechar (s, (long int) pos - (long int) s); + removechar (s, (long int) pos - (long int) s); + } + while (strchr (s, ' ') == s) + removechar (s, 0); +} + +void freadline(char *buff,FILE *f) +{ +char c; +while ((fread(&c,1,1,f)==1) && (c!='\n')) + { + *buff=c; + buff++; + } +*buff=0; + +} + +int makePoDb(const char* sourceName,const char* outputName) +{ +static bool open = false; +int m=0,n=0,h=0; +GDBM_FILE db; +datum key,value; +char *s,a[20000],b[2000],k[2000],v[2000]; +int i,*np,nmax=0,co=-1,oldref[2000]; +long int tim; +FILE *mlf; +bool nextIsFuzzy; +bool isAMsgId=true; +/* char keystring[1000],valuestring[1000]; */ + +/*Read headers, refnum end other info */ +db = gdbm_open((char *)outputName,1024,GDBM_READER,0666,0); +mlf = fopen(sourceName,"r"); +if(strrchr(sourceName,'/')!=0) +sourceName=strrchr(sourceName,'/')+1; + +if(!(db==0)) + { + printf("ciao\n"); + key.dptr=a; + strcpy(a,"__@REFNUM__"); + key.dsize=strlen(a)+1; + value = gdbm_fetch(db,key); + np=(int*)value.dptr; + nmax=*np; + for(i=0;i",oldref[co],*re); + if(oldref[r]==*re) + { + modif=true; + // fprintf(stderr,"Yes\n"); + *re=(nmax-1); + } //else fprintf(stderr,"No\n"); + } + // fprintf(stderr,"qui\n"); + if(!modif) + md=nr; + // fprintf(stderr,"modif %s\n",modif ? "true":"false"); + } + } + + } + + if(!exist) + { + int oldlen=(long int)os-(long int)oldvalue.dptr-4; + memcpy(a+4,oldvalue.dptr+4,oldlen); +// fprintf(stderr,"***!exist Old len is %d+4 1st str is %s\n",oldlen,a+4); + v++; + t=(int *)a; + *t=v; + // fprintf(stderr,"b=%s",b); + strcpy(a+4+oldlen,b); + re=(int *)(a+4+oldlen+strlen(b)+1); + *re=1; + re++; + *re=nmax-1; + //fprintf(stderr,"a+4=%s a+4+oldlen=%s",a+4,a+4+oldlen); + value.dptr=a; + value.dsize=oldlen+strlen(b)+1+4+8; + gdbm_store(db,key,value,GDBM_REPLACE); + n++; + } else + { + if(!modif) + { +// fprintf(stderr,"grossa crisi %d\n",*md); +// fprintf(stderr,"Old num of ref \n"); + int oldlen1=(long int)(md)-(long int)(oldvalue.dptr)-4; + int oldlen2=(long int)(os)-(long int)(md)-4; //-4 because nr + memcpy(a+4,oldvalue.dptr+4,oldlen1); + memcpy(a+4+oldlen1+8,oldvalue.dptr+4+oldlen1+4,oldlen2); + re=(int *)(a+4+oldlen1); + *re=(*md )+1; + // *re++; + re++; + *re=nmax-1; + t=(int *)a; + *t=v; + value.dptr=a; + value.dsize=oldlen1+oldlen2+4+8; + gdbm_store(db,key,value,GDBM_REPLACE); + n++; + } + else //if (modif) + { + value.dptr=oldvalue.dptr; + value.dsize=oldvalue.dsize; + gdbm_store(db,key,value,GDBM_REPLACE); + } + } + + h++; + } else { + + m++; + } + } + } + + } + + + } + + fclose(mlf); + gdbm_close(db); + open=false; + printf("new Key in database %d\n old key found %d\n value added %d\n",m,h,n); + return m+n; +} + + + +main(int argc,char **argv) +{ +int i; +for(i=1;i