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/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 +- 5 files changed, 185 insertions(+), 185 deletions(-) delete mode 100644 kbabel/datatools/regexp/main.cc create mode 100644 kbabel/datatools/regexp/main.cpp (limited to 'kbabel/datatools/regexp') 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 + -- cgit v1.2.1