From 7de7fcc8df30f49cec69268d5f5ec7f559ae8ea8 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 20 Jun 2011 00:29:11 +0400 Subject: [PATCH] Replace fprintf(stderr,...) in code by a macro FDPRINTF --- bgl.cc | 10 +++++----- bgl_babylon.cc | 14 +++++++------- btreeidx.cc | 4 ++-- dictdfiles.cc | 2 +- dprintf.hh | 2 ++ dsl.cc | 10 +++++----- dsl_details.cc | 11 ++++++----- lsa.cc | 6 +++--- stardict.cc | 22 +++++++++++----------- xdxf.cc | 2 +- xdxf2html.cc | 4 ++-- 11 files changed, 45 insertions(+), 42 deletions(-) diff --git a/bgl.cc b/bgl.cc index ade09ba1..5db9e2de 100644 --- a/bgl.cc +++ b/bgl.cc @@ -192,8 +192,8 @@ namespace if ( result < 0 ) { - fprintf( stderr, "Failed to decode utf8 of headword %s, skipping it.\n", - word.c_str() ); + FDPRINTF( stderr, "Failed to decode utf8 of headword %s, skipping it.\n", + word.c_str() ); return; } @@ -956,8 +956,8 @@ sptr< Dictionary::DataRequest > BglDictionary::getResource( string const & name if ( compress( &compressedData.front(), &compressedSize, (unsigned char const *) data, size ) != Z_OK ) { - fprintf( stderr, "Failed to compress the body of resource %s, dropping it.\n", - filename.c_str() ); + FDPRINTF( stderr, "Failed to compress the body of resource %s, dropping it.\n", + filename.c_str() ); return; } @@ -1010,7 +1010,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( if ( !b.read( sourceCharset, targetCharset ) ) { - fprintf( stderr, "Failed to start reading from %s, skipping it\n", i->c_str() ); + FDPRINTF( stderr, "Failed to start reading from %s, skipping it\n", i->c_str() ); continue; } diff --git a/bgl_babylon.cc b/bgl_babylon.cc index 3588ff76..343dde34 100644 --- a/bgl_babylon.cc +++ b/bgl_babylon.cc @@ -273,7 +273,7 @@ bool Babylon::read(std::string &source_charset, std::string &target_charset) if ( isUtf8File ) { - //fprintf( stderr, "%s: utf8 file.\n", m_title.c_str() ); + //FDPRINTF( stderr, "%s: utf8 file.\n", m_title.c_str() ); m_defaultCharset = "UTF-8"; m_sourceCharset = "UTF-8"; m_targetCharset = "UTF-8"; @@ -381,7 +381,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler ) if ( length > len - a - 2 ) { - fprintf( stderr, "Hidden displayed headword is too large %s\n", headword.c_str() ); + FDPRINTF( stderr, "Hidden displayed headword is too large %s\n", headword.c_str() ); pos += len - a; break; } @@ -396,7 +396,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler ) if ( length > len - a - 2 ) { - fprintf( stderr, "Displayed headword's length is too large for headword %s\n", headword.c_str() ); + FDPRINTF( stderr, "Displayed headword's length is too large for headword %s\n", headword.c_str() ); pos += len - a; break; } @@ -416,7 +416,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler ) if ( length > len - a - 3 ) { - fprintf( stderr, "2-byte sized displayed headword for %s is too large\n", headword.c_str() ); + FDPRINTF( stderr, "2-byte sized displayed headword for %s is too large\n", headword.c_str() ); pos += len - a; break; } @@ -434,7 +434,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler ) if ( length > len - a - 3 ) { - fprintf( stderr, "1-byte-sized transcription's length is too large for headword %s\n", headword.c_str() ); + FDPRINTF( stderr, "1-byte-sized transcription's length is too large for headword %s\n", headword.c_str() ); pos += len - a; break; } @@ -456,7 +456,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler ) if ( length > len - a - 4) { - fprintf( stderr, "2-byte-sized transcription's length is too large for headword %s\n", headword.c_str() ); + FDPRINTF( stderr, "2-byte-sized transcription's length is too large for headword %s\n", headword.c_str() ); pos += len - a; break; } @@ -478,7 +478,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler ) if ( length > len - a - 2 ) { - fprintf( stderr, "Hidden transcription is too large %s\n", headword.c_str() ); + FDPRINTF( stderr, "Hidden transcription is too large %s\n", headword.c_str() ); pos += len - a; break; } diff --git a/btreeidx.cc b/btreeidx.cc index 3d843076..d9f5d9c8 100644 --- a/btreeidx.cc +++ b/btreeidx.cc @@ -845,7 +845,7 @@ static uint32_t buildBtreeNode( IndexedWords::const_iterator & nextIndex, &compressedData.front(), &compressedSize, workMem ) != LZO_E_OK ) { - fprintf( stderr, "Failed to compress btree node.\n" ); + FDPRINTF( stderr, "Failed to compress btree node.\n" ); abort(); } @@ -858,7 +858,7 @@ static uint32_t buildBtreeNode( IndexedWords::const_iterator & nextIndex, if ( compress( &compressedData.front(), &compressedSize, &uncompressedData.front(), uncompressedData.size() ) != Z_OK ) { - fprintf( stderr, "Failed to compress btree node.\n" ); + FDPRINTF( stderr, "Failed to compress btree node.\n" ); abort(); } diff --git a/dictdfiles.cc b/dictdfiles.cc index 0e3d12c0..2002cdbb 100644 --- a/dictdfiles.cc +++ b/dictdfiles.cc @@ -436,7 +436,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } catch( std::exception & e ) { - fprintf( stderr, "Dictd dictionary reading failed: %s, error: %s\n", + FDPRINTF( stderr, "Dictd dictionary reading failed: %s, error: %s\n", i->c_str(), e.what() ); } } diff --git a/dprintf.hh b/dprintf.hh index 51c1dfe1..b09dbada 100644 --- a/dprintf.hh +++ b/dprintf.hh @@ -3,8 +3,10 @@ #ifdef NO_CONSOLE #define DPRINTF(...) +#define FDPRINTF(...) #else #define DPRINTF(...) { printf(__VA_ARGS__); } +#define FDPRINTF(...) { fprintf(__VA_ARGS__); } #endif #endif // __DPRINTF_HH_INCLUDED__ diff --git a/dsl.cc b/dsl.cc index 9a8b4d45..b435da43 100644 --- a/dsl.cc +++ b/dsl.cc @@ -1462,7 +1462,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( if ( !abrvScanner.readNextLine( curString, curOffset ) || curString.empty() ) { - fprintf( stderr, "Warning: premature end of file %s\n", abrvFileName.c_str() ); + FDPRINTF( stderr, "Warning: premature end of file %s\n", abrvFileName.c_str() ); eof = true; break; } @@ -1514,7 +1514,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } catch( std::exception & e ) { - fprintf( stderr, "Error reading abrv file %s: %s. Skipping it.\n", + FDPRINTF( stderr, "Error reading abrv file %s: %s. Skipping it.\n", abrvFileName.c_str(), e.what() ); } } @@ -1548,7 +1548,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( { if ( !isDslWs( curString[ x ] ) ) { - fprintf( stderr, "Warning: garbage string in %s at offset 0x%X\n", i->c_str(), curOffset ); + FDPRINTF( stderr, "Warning: garbage string in %s at offset 0x%X\n", i->c_str(), curOffset ); break; } } @@ -1572,7 +1572,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( { if ( ! ( hasString = scanner.readNextLine( curString, curOffset ) ) ) { - fprintf( stderr, "Warning: premature end of file %s\n", i->c_str() ); + FDPRINTF( stderr, "Warning: premature end of file %s\n", i->c_str() ); break; } @@ -1796,7 +1796,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } catch( std::exception & e ) { - fprintf( stderr, "DSL dictionary reading failed: %s:%u, error: %s\n", + FDPRINTF( stderr, "DSL dictionary reading failed: %s:%u, error: %s\n", i->c_str(), atLine, e.what() ); } } diff --git a/dsl_details.cc b/dsl_details.cc index 79787669..a024c99f 100644 --- a/dsl_details.cc +++ b/dsl_details.cc @@ -6,6 +6,7 @@ #include "langcoder.hh" #include #include +#include "dprintf.hh" namespace Dsl { namespace Details { @@ -379,7 +380,7 @@ ArticleDom::ArticleDom( wstring const & str ): stack.pop_back(); if ( stack.size() ) - fprintf( stderr, "Warning: %u tags were unclosed.\n", stack.size() ); + FDPRINTF( stderr, "Warning: %u tags were unclosed.\n", stack.size() ); } void ArticleDom::closeTag( wstring const & name, @@ -452,7 +453,7 @@ void ArticleDom::closeTag( wstring const & name, else if ( warn ) { - fprintf( stderr, "Warning: no corresponding opening tag for closing tag \"/%ls\" found.\n", + FDPRINTF( stderr, "Warning: no corresponding opening tag for closing tag \"/%ls\" found.\n", name.c_str() ); } } @@ -620,7 +621,7 @@ DslScanner::DslScanner( string const & fileName ) throw( Ex, Iconv::Ex ): if ( !needExactEncoding ) { // We don't need that! - fprintf( stderr, "Warning: encoding was specified in a Unicode file, ignoring.\n" ); + FDPRINTF( stderr, "Warning: encoding was specified in a Unicode file, ignoring.\n" ); } else if ( !wcscasecmp( arg.c_str(), GD_NATIVE_TO_WS( L"Latin" ) ) ) @@ -837,7 +838,7 @@ void processUnsortedParts( wstring & str, bool strip ) if ( refCount < 0 ) { - fprintf( stderr, "Warning: an unmatched closing brace was encountered.\n" ); + FDPRINTF( stderr, "Warning: an unmatched closing brace was encountered.\n" ); refCount = 0; // But we remove that thing either way str.erase( x, 1 ); @@ -866,7 +867,7 @@ void processUnsortedParts( wstring & str, bool strip ) if ( strip && refCount ) { - fprintf( stderr, "Warning: unclosed brace(s) encountered.\n" ); + FDPRINTF( stderr, "Warning: unclosed brace(s) encountered.\n" ); str.erase( startPos ); } } diff --git a/lsa.cc b/lsa.cc index 4ee0dbca..2a8ebdf4 100644 --- a/lsa.cc +++ b/lsa.cc @@ -459,14 +459,14 @@ sptr< Dictionary::DataRequest > LsaDictionary::getResource( string const & name if ( result <= 0 ) { - fprintf( stderr, "Warning: failed to read Vorbis data (code = %ld)\n", result ); + FDPRINTF( stderr, "Warning: failed to read Vorbis data (code = %ld)\n", result ); memset( ptr, 0, left ); break; } if ( result > left ) { - fprintf( stderr, "Warning: Vorbis decode returned more data than requested.\n" ); + FDPRINTF( stderr, "Warning: Vorbis decode returned more data than requested.\n" ); result = left; } @@ -599,7 +599,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } catch( std::exception & e ) { - fprintf( stderr, "Lingo's LSA reading failed: %s, error: %s\n", + FDPRINTF( stderr, "Lingo's LSA reading failed: %s, error: %s\n", i->c_str(), e.what() ); } } diff --git a/stardict.cc b/stardict.cc index d9cc3301..f1af1699 100644 --- a/stardict.cc +++ b/stardict.cc @@ -322,7 +322,7 @@ void StardictDictionary::loadArticle( uint32_t address, else if ( !size ) { - fprintf( stderr, "Warning: short entry for the word %s encountered.\n", headword.c_str() ); + FDPRINTF( stderr, "Warning: short entry for the word %s encountered.\n", headword.c_str() ); break; } @@ -336,7 +336,7 @@ void StardictDictionary::loadArticle( uint32_t address, if ( size < entrySize ) { - fprintf( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); + FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); break; } @@ -357,7 +357,7 @@ void StardictDictionary::loadArticle( uint32_t address, { if ( size < sizeof( uint32_t ) ) { - fprintf( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); + FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); break; } @@ -371,7 +371,7 @@ void StardictDictionary::loadArticle( uint32_t address, if ( size < entrySize ) { - fprintf( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); + FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); break; } @@ -382,7 +382,7 @@ void StardictDictionary::loadArticle( uint32_t address, } else { - fprintf( stderr, "Warning: non-alpha entry type 0x%x for the word %s encountered.\n", + FDPRINTF( stderr, "Warning: non-alpha entry type 0x%x for the word %s encountered.\n", type, headword.c_str() ); break; } @@ -400,7 +400,7 @@ void StardictDictionary::loadArticle( uint32_t address, if ( size < len + 2 ) { - fprintf( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); + FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); break; } @@ -415,7 +415,7 @@ void StardictDictionary::loadArticle( uint32_t address, // An entry which havs its size before contents if ( size < sizeof( uint32_t ) + 1 ) { - fprintf( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); + FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); break; } @@ -427,7 +427,7 @@ void StardictDictionary::loadArticle( uint32_t address, if ( size < sizeof( uint32_t ) + 1 + entrySize ) { - fprintf( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); + FDPRINTF( stderr, "Warning: malformed entry for the word %s encountered.\n", headword.c_str() ); break; } @@ -438,7 +438,7 @@ void StardictDictionary::loadArticle( uint32_t address, } else { - fprintf( stderr, "Warning: non-alpha entry type 0x%x for the word %s encountered.\n", + FDPRINTF( stderr, "Warning: non-alpha entry type 0x%x for the word %s encountered.\n", (unsigned)*ptr, headword.c_str() ); break; } @@ -928,7 +928,7 @@ static void handleIdxSynFile( string const & fileName, sizeof( uint32_t ) * 2 ) > &image.back() ) { - fprintf( stderr, "Warning: sudden end of file %s\n", fileName.c_str() ); + FDPRINTF( stderr, "Warning: sudden end of file %s\n", fileName.c_str() ); break; } @@ -1156,7 +1156,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } catch( std::exception & e ) { - fprintf( stderr, "Stardict's dictionary reading failed: %s, error: %s\n", + FDPRINTF( stderr, "Stardict's dictionary reading failed: %s, error: %s\n", i->c_str(), e.what() ); } } diff --git a/xdxf.cc b/xdxf.cc index 518cdfb2..2d7639ba 100644 --- a/xdxf.cc +++ b/xdxf.cc @@ -802,7 +802,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } catch( std::exception & e ) { - fprintf( stderr, "Xdxf dictionary reading failed: %s, error: %s\n", + FDPRINTF( stderr, "Xdxf dictionary reading failed: %s, error: %s\n", i->c_str(), e.what() ); } } diff --git a/xdxf2html.cc b/xdxf2html.cc index 64bf7695..3679a0f4 100644 --- a/xdxf2html.cc +++ b/xdxf2html.cc @@ -51,8 +51,8 @@ string convert( string const & in ) if ( !dd.setContent( QByteArray( ( "
" + inConverted + "
" ).c_str() ), false, &errorStr, &errorLine, &errorColumn ) ) { - fprintf( stderr, "Xdxf2html error, xml parse failed: %s at %d,%d\n", errorStr.toLocal8Bit().constData(), errorLine, errorColumn ); - fprintf( stderr, "The input was: %s\n", in.c_str() ); + FDPRINTF( stderr, "Xdxf2html error, xml parse failed: %s at %d,%d\n", errorStr.toLocal8Bit().constData(), errorLine, errorColumn ); + FDPRINTF( stderr, "The input was: %s\n", in.c_str() ); return in; }