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/arguments/CMakeLists.txt | 2 +- kbabel/datatools/arguments/Makefile.am | 2 +- kbabel/datatools/arguments/main.cc | 277 ------------------------------ kbabel/datatools/arguments/main.cpp | 277 ++++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+), 279 deletions(-) delete mode 100644 kbabel/datatools/arguments/main.cc create mode 100644 kbabel/datatools/arguments/main.cpp (limited to 'kbabel/datatools/arguments') 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" -- cgit v1.2.1