Skip to content

Commit

Permalink
Replace printf in code by a macro DPRINTF
Browse files Browse the repository at this point in the history
  • Loading branch information
Abs62 committed Jun 19, 2011
1 parent 97a6d49 commit 36e509a
Show file tree
Hide file tree
Showing 28 changed files with 162 additions and 124 deletions.
19 changes: 10 additions & 9 deletions article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QUrl>
#include "folding.hh"
#include "langcoder.hh"
#include "dprintf.hh"

using std::vector;
using std::string;
Expand Down Expand Up @@ -308,7 +309,7 @@ void ArticleRequest::altSearchFinished()

if ( altSearches.empty() )
{
printf( "alts finished\n" );
DPRINTF( "alts finished\n" );

// They all've finished! Now we can look up bodies

Expand All @@ -318,7 +319,7 @@ void ArticleRequest::altSearchFinished()

for( unsigned x = 0; x < altsVector.size(); ++x )
{
printf( "Alt: %ls\n", altsVector[ x ].c_str() );
DPRINTF( "Alt: %ls\n", altsVector[ x ].c_str() );
}

wstring wordStd = gd::toWString( word );
Expand All @@ -344,7 +345,7 @@ void ArticleRequest::bodyFinished()
if ( bodyDone )
return;

printf( "some body finished\n" );
DPRINTF( "some body finished\n" );

bool wasUpdated = false;

Expand All @@ -355,7 +356,7 @@ void ArticleRequest::bodyFinished()
{
// Good

printf( "one finished.\n" );
DPRINTF( "one finished.\n" );

Dictionary::DataRequest & req = *bodyRequests.front();

Expand Down Expand Up @@ -431,13 +432,13 @@ void ArticleRequest::bodyFinished()

foundAnyDefinitions = true;
}
printf( "erasing..\n" );
DPRINTF( "erasing..\n" );
bodyRequests.pop_front();
printf( "erase done..\n" );
DPRINTF( "erase done..\n" );
}
else
{
printf( "one not finished.\n" );
DPRINTF( "one not finished.\n" );
break;
}
}
Expand Down Expand Up @@ -575,7 +576,7 @@ void ArticleRequest::compoundSearchNextStep( bool lastSearchSucceeded )

if ( lastGoodCompoundResult.size() ) // We have something to append
{
// printf( "Appending\n" );
// DPRINTF( "Appending\n" );

if ( !firstCompoundWasFound )
{
Expand Down Expand Up @@ -670,7 +671,7 @@ void ArticleRequest::compoundSearchNextStep( bool lastSearchSucceeded )

// Look it up

// printf( "Looking up %s\n", qPrintable( currentSplittedWordCompound ) );
// DPRINTF( "Looking up %s\n", qPrintable( currentSplittedWordCompound ) );

stemmedWordFinder->prefixMatch( currentSplittedWordCompound, activeDicts, 40, // Would one be enough? Leave 40 to be safe.
Dictionary::SuitableForCompoundSearching );
Expand Down
22 changes: 11 additions & 11 deletions article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "article_netmgr.hh"
#include "wstring_qt.hh"

#include "dprintf.hh"
using std::string;

namespace
Expand Down Expand Up @@ -80,17 +80,17 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
{
QByteArray referer = req.rawHeader( "Referer" );

//printf( "Referer: %s\n", referer.data() );
//DPRINTF( "Referer: %s\n", referer.data() );

QUrl refererUrl = QUrl::fromEncoded( referer );

//printf( "Considering %s vs %s\n", getHostBase( req.url() ).toUtf8().data(),
//DPRINTF( "Considering %s vs %s\n", getHostBase( req.url() ).toUtf8().data(),
// getHostBase( refererUrl ).toUtf8().data() );

if ( !req.url().host().endsWith( refererUrl.host() ) &&
getHostBase( req.url() ) != getHostBase( refererUrl ) && !req.url().scheme().startsWith("data") )
{
printf( "Blocking element %s\n", req.url().toEncoded().data() );
DPRINTF( "Blocking element %s\n", req.url().toEncoded().data() );

return new BlockedNetworkReply( this );
}
Expand All @@ -102,9 +102,9 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
QUrl const & url, QString & contentType )
{
printf( "getResource: %ls\n", url.toString().toStdWString().c_str() );
printf( "scheme: %ls\n", url.scheme().toStdWString().c_str() );
printf( "host: %ls\n", url.host().toStdWString().c_str() );
DPRINTF( "getResource: %ls\n", url.toString().toStdWString().c_str() );
DPRINTF( "scheme: %ls\n", url.scheme().toStdWString().c_str() );
DPRINTF( "host: %ls\n", url.host().toStdWString().c_str() );

if ( url.scheme() == "gdlookup" )
{
Expand Down Expand Up @@ -149,8 +149,8 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
if ( ( url.scheme() == "bres" || url.scheme() == "gdau" ) &&
url.path().size() )
{
//printf( "Get %s\n", req.url().host().toLocal8Bit().data() );
//printf( "Get %s\n", req.url().path().toLocal8Bit().data() );
//DPRINTF( "Get %s\n", req.url().host().toLocal8Bit().data() );
//DPRINTF( "Get %s\n", req.url().path().toLocal8Bit().data() );

string id = url.host().toStdString();

Expand Down Expand Up @@ -222,7 +222,7 @@ ArticleResourceReply::ArticleResourceReply( QObject * parent,
if ( req->isFinished() )
{
emit finishedSignal();
printf( "In-place finish.\n" );
DPRINTF( "In-place finish.\n" );
}
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ qint64 ArticleResourceReply::bytesAvailable() const

qint64 ArticleResourceReply::readData( char * out, qint64 maxSize )
{
printf( "====reading %d bytes\n", (int)maxSize );
DPRINTF( "====reading %d bytes\n", (int)maxSize );

bool finished = req->isFinished();

Expand Down
15 changes: 8 additions & 7 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "wstring_qt.hh"
#include "webmultimediadownload.hh"
#include "programs.hh"
#include "dprintf.hh"

#ifdef Q_OS_WIN32
#include <windows.h>
Expand Down Expand Up @@ -240,9 +241,9 @@ void ArticleView::loadFinished( bool )
{
if ( (*i)->frameName().startsWith( "gdexpandframe-" ) )
{
//printf( "Name: %s\n", (*i)->frameName().toUtf8().data() );
//printf( "Size: %d\n", (*i)->contentsSize().height() );
//printf( ">>>>>>>>Height = %s\n", (*i)->evaluateJavaScript( "document.body.offsetHeight;" ).toString().toUtf8().data() );
//DPRINTF( "Name: %s\n", (*i)->frameName().toUtf8().data() );
//DPRINTF( "Size: %d\n", (*i)->contentsSize().height() );
//DPRINTF( ">>>>>>>>Height = %s\n", (*i)->evaluateJavaScript( "document.body.offsetHeight;" ).toString().toUtf8().data() );

// Set the height
ui.definition->page()->mainFrame()->evaluateJavaScript( QString( "document.getElementById('%1').height = %2;" ).
Expand Down Expand Up @@ -589,7 +590,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
QString const & scrollTo,
Contexts const & contexts )
{
printf( "clicked %s\n", url.toString().toLocal8Bit().data() );
DPRINTF( "clicked %s\n", url.toString().toLocal8Bit().data() );

if ( url.scheme().compare( "bword" ) == 0 )
{
Expand Down Expand Up @@ -1042,10 +1043,10 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
}
}
#if 0
printf( "%s\n", r.linkUrl().isEmpty() ? "null" : "not null" );
DPRINTF( "%s\n", r.linkUrl().isEmpty() ? "null" : "not null" );

printf( "url = %s\n", r.linkUrl().toString().toLocal8Bit().data() );
printf( "title = %s\n", r.title().toLocal8Bit().data() );
DPRINTF( "url = %s\n", r.linkUrl().toString().toLocal8Bit().data() );
DPRINTF( "title = %s\n", r.title().toLocal8Bit().data() );
#endif
}

Expand Down
11 changes: 6 additions & 5 deletions bgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "chunkedstorage.hh"
#include "langcoder.hh"
#include "language.hh"
#include "dprintf.hh"

#include <map>
#include <set>
Expand Down Expand Up @@ -873,7 +874,7 @@ void BglResourceRequest::run()
compressedData.size() ) != Z_OK ||
decompressedLength != data.size() )
{
printf( "Failed to decompress resource %s, ignoring it.\n",
DPRINTF( "Failed to decompress resource %s, ignoring it.\n",
name.c_str() );
}
else
Expand Down Expand Up @@ -907,13 +908,13 @@ sptr< Dictionary::DataRequest > BglDictionary::getResource( string const & name

for( int pos = 0; ( pos = charsetExp.indexIn( str, pos ) ) != -1; )
{
//printf( "Match: %s\n", str.mid( pos, charsetExp.matchedLength() ).toUtf8().data() );
//DPRINTF( "Match: %s\n", str.mid( pos, charsetExp.matchedLength() ).toUtf8().data() );

QString out;

for( int p = 0; ( p = oneValueExp.indexIn( charsetExp.cap( 1 ), p ) ) != -1; )
{
//printf( "Cap: %s\n", oneValueExp.cap( 1 ).toUtf8().data() );
//DPRINTF( "Cap: %s\n", oneValueExp.cap( 1 ).toUtf8().data() );
out += "&#x" + oneValueExp.cap( 1 ) + ";";

p += oneValueExp.matchedLength();
Expand Down Expand Up @@ -946,7 +947,7 @@ sptr< Dictionary::DataRequest > BglDictionary::getResource( string const & name
void ResourceHandler::handleBabylonResource( string const & filename,
char const * data, size_t size )
{
//printf( "Handling resource file %s (%u bytes)\n", filename.c_str(), size );
//DPRINTF( "Handling resource file %s (%u bytes)\n", filename.c_str(), size );

vector< unsigned char > compressedData( compressBound( size ) );

Expand Down Expand Up @@ -1085,7 +1086,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(

idxHeader.chunksOffset = chunks.finish();

printf( "Writing index...\n" );
DPRINTF( "Writing index...\n" );

// Good. Now build the index

Expand Down
9 changes: 5 additions & 4 deletions bgl_babylon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include<stdio.h>
#include<iconv.h>
#include <QTextDocument>
#include "dprintf.hh"

#ifdef _WIN32
#include <io.h>
Expand Down Expand Up @@ -283,7 +284,7 @@ bool Babylon::read(std::string &source_charset, std::string &target_charset)
convertToUtf8( m_email, TARGET_CHARSET );
convertToUtf8( m_copyright, TARGET_CHARSET );
convertToUtf8( m_description, TARGET_CHARSET );
printf("Default charset: %s\nSource Charset: %s\nTargetCharset: %s\n", m_defaultCharset.c_str(), m_sourceCharset.c_str(), m_targetCharset.c_str());
DPRINTF("Default charset: %s\nSource Charset: %s\nTargetCharset: %s\n", m_defaultCharset.c_str(), m_sourceCharset.c_str(), m_targetCharset.c_str());
return true;
}

Expand Down Expand Up @@ -639,7 +640,7 @@ void Babylon::convertToUtf8( std::string &s, unsigned int type )
iconv_t cd = iconv_open( "UTF-8", charset.c_str() );
if( cd == (iconv_t)(-1) )
{
printf( "Error openning iconv library\n" );
DPRINTF( "Error openning iconv library\n" );
exit(1);
}

Expand All @@ -660,8 +661,8 @@ void Babylon::convertToUtf8( std::string &s, unsigned int type )
defbuf = outbuf;
while (inbufbytes) {
if (iconv(cd, &inbuf, &inbufbytes, &outbuf, &outbufbytes) == (size_t)-1) {
printf( "\n%s\n", inbuf );
printf( "Error in iconv conversion\n" );
DPRINTF( "\n%s\n", inbuf );
DPRINTF( "Error in iconv conversion\n" );
inbuf++;
inbufbytes--;
}
Expand Down
Loading

0 comments on commit 36e509a

Please sign in to comment.