Skip to content

Commit

Permalink
Fix compilation failures with Visual C++ 2012 (issue goldendict#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tvangeste committed Aug 7, 2013
1 parent 66c3095 commit 148fd1f
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 81 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ version.txt
.DS_Store
Info.plist
GoldenDict.xcodeproj/

# visual studio files
*.sdf
*.opensdf
*.suo
*.vcxproj.user
12 changes: 11 additions & 1 deletion about.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ About::About( QWidget * parent ): QDialog( parent )
version = QString::fromLatin1( versionFile.readAll() ).trimmed();

ui.version->setText( version );

#if defined (_MSC_VER)
QString compilerVersion = QString( "Visual C++ %1.%2.%3" )
.arg( GD_CXX_MSVC_MAJOR )
.arg( GD_CXX_MSVC_MINOR )
.arg( GD_CXX_MSVC_BUILD );
#else
QString compilerVersion = QLatin1String( "GCC " ) + QLatin1String( __VERSION__ );
#endif

ui.qtVersion->setText( tr( "Based on Qt %1 (%2, %3 bit)" ).arg(
QLatin1String( qVersion() ),
QLatin1String( "GCC " ) + QLatin1String( __VERSION__ ),
compilerVersion,
QString::number( QSysInfo::WordSize ) ) );

QFile creditsFile( ":/CREDITS.txt" );
Expand Down
16 changes: 15 additions & 1 deletion about.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@
#ifndef ABOUT_HH
#define ABOUT_HH

#include <QDialog>
#include "ui_about.h"
#include <QDialog>

// Microsoft Visual C++ version
#if defined (_MSC_VER)
// how many digits does the build number have?
# if _MSC_FULL_VER / 10000 == _MSC_VER
# define GD_CXX_MSVC_BUILD (_MSC_FULL_VER % 10000) // four digits
# elif _MSC_FULL_VER / 100000 == _MSC_VER
# define GD_CXX_MSVC_BUILD (_MSC_FULL_VER % 100000) // five digits
# else
# define GD_CXX_MSVC_BUILD 0
# endif
# define GD_CXX_MSVC_MAJOR (_MSC_VER/100-6)
# define GD_CXX_MSVC_MINOR (_MSC_VER%100)
#endif

class About: public QDialog
{
Expand Down
8 changes: 1 addition & 7 deletions article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,7 @@ void ArticleRequest::altSearchFinished()

for( unsigned x = 0; x < altsVector.size(); ++x )
{
DPRINTF( "Alt: %ls\n",
#ifdef Q_OS_WIN
gd::toQString( altsVector[ x ] ).toStdWString().c_str()
#else
altsVector[ x ].c_str()
#endif
);
qDebug() << "Alt:" << gd::toQString( altsVector[ x ] );
}

wstring wordStd = gd::toWString( word );
Expand Down
5 changes: 5 additions & 0 deletions article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ qint64 ArticleResourceReply::bytesAvailable() const

qint64 ArticleResourceReply::readData( char * out, qint64 maxSize )
{
// From the doc: "This function might be called with a maxSize of 0,
// which can be used to perform post-reading operations".
if ( maxSize == 0 )
return 0;

DPRINTF( "====reading %d bytes\n", (int)maxSize );

bool finished = req->isFinished();
Expand Down
5 changes: 4 additions & 1 deletion chunkedstorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ Reader::Reader( File::Class & f, uint32_t offset ): file( f )
{
file.seek( offset );

offsets.resize( file.read< uint32_t >() );
uint32_t size = file.read< uint32_t >();
if ( size == 0 )
return;
offsets.resize( size );
file.read( &offsets.front(), offsets.size() * sizeof( uint32_t ) );
}

Expand Down
3 changes: 3 additions & 0 deletions dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ long DataRequest::dataSize()
void DataRequest::getDataSlice( size_t offset, size_t size, void * buffer )
throw( exSliceOutOfRange )
{
if ( size == 0 )
return;

Mutex::Lock _( dataMutex );

if ( offset + size > data.size() || !hasAnyData )
Expand Down
19 changes: 13 additions & 6 deletions dictzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,16 @@ dictData *dict_data_open( const char *filename, int computeCRC )

for(;;)
{
#ifdef __WIN32
wchar_t wname[16384];
#endif
if (dict_read_header( filename, h, computeCRC )) {
break; /*
err_fatal( __func__,
"\"%s\" not in text or dzip format\n", filename );*/
}

#ifdef __WIN32
wchar_t wname[16384];
if( MultiByteToWideChar( CP_UTF8, 0, filename, -1, wname, 16384 ) == 0 )
break;

Expand Down Expand Up @@ -543,9 +545,8 @@ char *dict_data_read_ (
dictData *h, unsigned long start, unsigned long size,
const char *preFilter, const char *postFilter )
{
(void) preFilter;
(void) postFilter;
char *buffer, *pt;
char * buffer;
char * pt;
unsigned long end;
int count;
char *inBuffer;
Expand All @@ -554,6 +555,8 @@ char *dict_data_read_ (
int firstOffset, lastOffset;
int i, j;
int found, target, lastStamp;
(void) preFilter;
(void) postFilter;

end = start + size;

Expand Down Expand Up @@ -670,6 +673,10 @@ char *dict_data_read_ (
count = h->cache[target].count;
inBuffer = h->cache[target].inBuffer;
} else {
#ifdef __WIN32
DWORD pos ;
DWORD readed;
#endif
h->cache[target].chunk = -1;
if (!h->cache[target].inBuffer)
h->cache[target].inBuffer = xmalloc( h->chunkLength );
Expand All @@ -688,8 +695,8 @@ char *dict_data_read_ (
}

#ifdef __WIN32
DWORD pos = SetFilePointer( h->fd, h->offsets[ i ], 0, FILE_BEGIN );
DWORD readed = 0;
pos = SetFilePointer( h->fd, h->offsets[ i ], 0, FILE_BEGIN );
readed = 0;
if( pos != INVALID_SET_FILE_POINTER || GetLastError() != NO_ERROR )
ReadFile( h->fd, outBuffer, h->chunks[ i ], &readed, 0 );
if( h->chunks[ i ] != readed )
Expand Down
19 changes: 4 additions & 15 deletions dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void DslDictionary::doDeferredInit()

chunks = new ChunkedStorage::Reader( idx, idxHeader.chunksOffset );

// Open the .dict file
// Open the .dsl file

dz = dict_data_open( getDictionaryFilenames()[ 0 ].c_str(), 0 );

Expand Down Expand Up @@ -1607,13 +1607,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
// Building the index
initializing.indexingDictionary( Utf8::encode( scanner.getDictionaryName() ) );

DPRINTF( "Dictionary name: %ls\n",
#ifdef Q_OS_WIN
gd::toQString( scanner.getDictionaryName() ).toStdWString().c_str()
#else
scanner.getDictionaryName().c_str()
#endif
);
qDebug() << "Building the index for dictionary:"
<< gd::toQString( scanner.getDictionaryName() );

File::Class idx( indexFile, "wb" );

Expand Down Expand Up @@ -1795,13 +1790,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
if ( isDslWs( curString[ 0 ] ) )
break; // No more headwords

DPRINTF( "Alt headword: %ls\n",
#ifdef Q_OS_WIN
gd::toQString( curString ).toStdWString().c_str()
#else
curString.c_str()
#endif
);
qDebug() << "Alt headword" << gd::toQString( curString );

processUnsortedParts( curString, true );
expandTildes( curString, allEntryWords.front() );
Expand Down
20 changes: 7 additions & 13 deletions dsl_details.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */

#include "dsl_details.hh"

#include "folding.hh"
#include "langcoder.hh"
#include <wctype.h>
#include <stdio.h>
#include "dprintf.hh"
#include "ufile.hh"

#ifdef Q_OS_WIN
#include "wstring_qt.hh"
#endif

#include <stdio.h>
#include <wctype.h>

namespace Dsl {
namespace Details {
Expand Down Expand Up @@ -545,13 +544,8 @@ void ArticleDom::closeTag( wstring const & name,
else
if ( warn )
{
FDPRINTF( stderr, "Warning: no corresponding opening tag for closing tag \"/%ls\" found.\n",
#ifdef Q_OS_WIN
gd::toQString( name ).toStdWString().c_str()
#else
name.c_str()
#endif
);
qWarning() << "Warning: no corresponding opening tag for closing tag" <<
gd::toQString( name ) << "found.";
}
}

Expand Down Expand Up @@ -592,7 +586,7 @@ void ArticleDom::nextChar() throw( eot )

DslScanner::DslScanner( string const & fileName ) throw( Ex, Iconv::Ex ):
encoding( Windows1252 ), iconv( encoding ), readBufferPtr( readBuffer ),
readBufferLeft( 0 ), linesRead( 0 )
readBufferLeft( 0 ), wcharBuffer( 64 ), linesRead( 0 )
{
// Since .dz is backwards-compatible with .gz, we use gz- functions to
// read it -- they are much nicer than the dict_data- ones.
Expand Down
8 changes: 4 additions & 4 deletions dsl_details.hh
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ void expandOptionalParts( wstring & str, list< wstring > * result,
/// them.
void expandTildes( wstring & str, wstring const & tildeReplacement );

// Unescapes any escaped chars. Be sure to handle all their special meanings
// before unescaping them.
/// Unescapes any escaped chars. Be sure to handle all their special meanings
/// before unescaping them.
void unescapeDsl( wstring & str );

// Normalizes the headword. Currently turns any sequences of consecutive spaces
// into a single space.
/// Normalizes the headword. Currently turns any sequences of consecutive spaces
/// into a single space.
void normalizeHeadword( wstring & );

/// Strip DSL {{...}} comments
Expand Down
4 changes: 3 additions & 1 deletion file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

#include <sys/types.h>
#include <sys/stat.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif

#ifdef __WIN32
#include <windows.h>
Expand Down Expand Up @@ -248,7 +250,7 @@ bool Class::eof() throw( exWriteError )
if ( writeBuffer )
flushWriteBuffer();

return feof( f );
return feof( f ) != 0;
}

FILE * Class::file() throw( exWriteError )
Expand Down
8 changes: 1 addition & 7 deletions forvo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,7 @@ ForvoArticleRequest::ForvoArticleRequest( wstring const & str,
void ForvoArticleRequest::addQuery( QNetworkAccessManager & mgr,
wstring const & str )
{
DPRINTF( "Requesting article %ls\n",
#ifdef Q_OS_WIN
gd::toQString( str ).toStdWString().c_str()
#else
str.c_str()
#endif
);
qDebug() << "Requesting article" << gd::toQString( str );

QString key;

Expand Down
8 changes: 1 addition & 7 deletions hunspell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,7 @@ QVector< wstring > HunspellHeadwordsRequest::suggest( wstring & word )

if ( Folding::applySimpleCaseOnly( alt ) != lowercasedWord ) // No point in providing same word
{
DPRINTF( ">>>>>Alt: %ls\n",
#ifdef Q_OS_WIN
gd::toQString( alt ).toStdWString().c_str()
#else
alt.c_str()
#endif
);
qDebug() << ">>>>>Alt:" << gd::toQString( alt );
result.append( alt );
}
}
Expand Down
7 changes: 7 additions & 0 deletions langcoder.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/* This file is (c) 2008-2013 Konstantin Isakov <[email protected]>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */

#include "langcoder.hh"
#include "folding.hh"
#include "wstring_qt.hh"
#include "language.hh"

#ifdef _MSC_VER
#include <stub_msvc.h>
#endif

#include <cctype>
#include <QLocale>

Expand Down
10 changes: 1 addition & 9 deletions mediawiki.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,7 @@ MediaWikiArticleRequest::MediaWikiArticleRequest( wstring const & str,
void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr,
wstring const & str )
{
DPRINTF( "Requesting article %ls\n",
#ifdef Q_OS_WIN
gd::toQString( str ).toStdWString().c_str()
#else
str.c_str()
#endif
);
qDebug() << "Requesting article" << gd::toQString( str );

QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid&format=xml&redirects" );

Expand Down Expand Up @@ -367,8 +361,6 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )

QByteArray articleBody = articleString.toUtf8();

DPRINTF( "Article body after: %s\n", articleBody.data() );

articleBody.prepend( dictPtr->isToLanguageRTL() ? "<div class=\"mwiki\" dir=\"rtl\">" :
"<div class=\"mwiki\">" );
articleBody.append( "</div>" );
Expand Down
6 changes: 3 additions & 3 deletions mouseover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ MouseOver & MouseOver::instance()
#ifdef Q_OS_WIN32
const UINT WM_MY_SHOW_TRANSLATION = WM_USER + 301;
static wchar_t className[] = L"GoldenDictMouseover";
typedef BOOL WINAPI ( *ChangeWindowMessageFilterFunc )( UINT, DWORD );
typedef BOOL ( WINAPI *ChangeWindowMessageFilterFunc )( UINT, DWORD );

#ifndef CHANGEFILTERSTRUCT
#ifndef WINAPI_FAMILY
typedef struct tagCHANGEFILTERSTRUCT {
DWORD cbSize;
DWORD ExtStatus;
} CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT;
#endif

typedef BOOL WINAPI ( *ChangeWindowMessageFilterExFunc )( HWND, UINT, DWORD, PCHANGEFILTERSTRUCT );
typedef BOOL ( WINAPI *ChangeWindowMessageFilterExFunc )( HWND, UINT, DWORD, PCHANGEFILTERSTRUCT );

#endif // Q_OS_WIN32

Expand Down
Loading

0 comments on commit 148fd1f

Please sign in to comment.