diff --git a/.gitignore b/.gitignore index 7547a464..45ef94ca 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,9 @@ version.txt .DS_Store Info.plist GoldenDict.xcodeproj/ + +# visual studio files +*.sdf +*.opensdf +*.suo +*.vcxproj.user diff --git a/about.cc b/about.cc index 897bfb39..0e92e9ce 100644 --- a/about.cc +++ b/about.cc @@ -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" ); diff --git a/about.hh b/about.hh index 732ad13b..2376f19a 100644 --- a/about.hh +++ b/about.hh @@ -4,8 +4,22 @@ #ifndef ABOUT_HH #define ABOUT_HH -#include #include "ui_about.h" +#include + +// 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 { diff --git a/article_maker.cc b/article_maker.cc index 71c15c11..41b52680 100644 --- a/article_maker.cc +++ b/article_maker.cc @@ -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 ); diff --git a/article_netmgr.cc b/article_netmgr.cc index f6b7ec00..3347715b 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -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(); diff --git a/chunkedstorage.cc b/chunkedstorage.cc index 4a3e0cbb..761eb1b8 100644 --- a/chunkedstorage.cc +++ b/chunkedstorage.cc @@ -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 ) ); } diff --git a/dictionary.cc b/dictionary.cc index 6c861f91..88b65b8b 100644 --- a/dictionary.cc +++ b/dictionary.cc @@ -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 ) diff --git a/dictzip.c b/dictzip.c index 3b808a71..b1658373 100644 --- a/dictzip.c +++ b/dictzip.c @@ -460,6 +460,9 @@ 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__, @@ -467,7 +470,6 @@ dictData *dict_data_open( const char *filename, int computeCRC ) } #ifdef __WIN32 - wchar_t wname[16384]; if( MultiByteToWideChar( CP_UTF8, 0, filename, -1, wname, 16384 ) == 0 ) break; @@ -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; @@ -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; @@ -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 ); @@ -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 ) diff --git a/dsl.cc b/dsl.cc index 1be87892..5f976788 100644 --- a/dsl.cc +++ b/dsl.cc @@ -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 ); @@ -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" ); @@ -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() ); diff --git a/dsl_details.cc b/dsl_details.cc index 231518b0..752015a0 100644 --- a/dsl_details.cc +++ b/dsl_details.cc @@ -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 -#include #include "dprintf.hh" #include "ufile.hh" - -#ifdef Q_OS_WIN #include "wstring_qt.hh" -#endif + +#include +#include namespace Dsl { namespace Details { @@ -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."; } } @@ -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. diff --git a/dsl_details.hh b/dsl_details.hh index 94c747d4..b2d7cc92 100644 --- a/dsl_details.hh +++ b/dsl_details.hh @@ -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 diff --git a/file.cc b/file.cc index 50737675..aa4a51f5 100644 --- a/file.cc +++ b/file.cc @@ -9,7 +9,9 @@ #include #include +#ifndef _MSC_VER #include +#endif #ifdef __WIN32 #include @@ -248,7 +250,7 @@ bool Class::eof() throw( exWriteError ) if ( writeBuffer ) flushWriteBuffer(); - return feof( f ); + return feof( f ) != 0; } FILE * Class::file() throw( exWriteError ) diff --git a/forvo.cc b/forvo.cc index 332871c6..3c6b59f1 100644 --- a/forvo.cc +++ b/forvo.cc @@ -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; diff --git a/hunspell.cc b/hunspell.cc index c4a2763b..f6995f61 100644 --- a/hunspell.cc +++ b/hunspell.cc @@ -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 ); } } diff --git a/langcoder.cc b/langcoder.cc index 1ae3174b..ea410642 100644 --- a/langcoder.cc +++ b/langcoder.cc @@ -1,8 +1,15 @@ +/* This file is (c) 2008-2013 Konstantin Isakov + * 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 +#endif + #include #include diff --git a/mediawiki.cc b/mediawiki.cc index fbbc09f4..1bca49c2 100644 --- a/mediawiki.cc +++ b/mediawiki.cc @@ -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" ); @@ -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() ? "
" : "
" ); articleBody.append( "
" ); diff --git a/mouseover.cc b/mouseover.cc index ed634064..df2826e1 100644 --- a/mouseover.cc +++ b/mouseover.cc @@ -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 diff --git a/termination.cc b/termination.cc index c01c6787..0828bdf6 100644 --- a/termination.cc +++ b/termination.cc @@ -4,7 +4,11 @@ #include "termination.hh" #include #include + +#ifndef _MSC_VER #include +#endif + #include #ifndef __WIN32 @@ -28,13 +32,24 @@ static void termHandler() char * function = 0; size_t functionLength = 0; +#ifdef _MSC_VER + std::type_info * ti = 0; +#else std::type_info * ti = __cxxabiv1::__cxa_current_exception_type(); +#endif if ( ti ) { char const * name = ti->name(); +#ifdef _MSC_VER + char * ret = 0; + // avoid 'unused' warnings + (void) status; + (void) functionLength; +#else char * ret = abi::__cxa_demangle( name, function, &functionLength, &status ); +#endif if ( ret ) { diff --git a/ufile.cc b/ufile.cc index 71145c84..c78079ee 100644 --- a/ufile.cc +++ b/ufile.cc @@ -1,6 +1,7 @@ #ifdef __WIN32 #include +#include #include #include diff --git a/ufile.hh b/ufile.hh index 36dc12e8..a7a9d3d4 100644 --- a/ufile.hh +++ b/ufile.hh @@ -5,6 +5,11 @@ #include "zlib.h" +// eliminate some VC++ warnings +#ifdef _MSC_VER +#define fileno _fileno +#endif + #ifdef __cplusplus extern "C" { diff --git a/utf8.cc b/utf8.cc index d5151b7d..9d8e66dc 100644 --- a/utf8.cc +++ b/utf8.cc @@ -141,6 +141,10 @@ string encode( wstring const & in ) throw() wstring decode( string const & in ) throw( exCantDecode ) { + + if ( in.size() == 0 ) + return wstring(); + std::vector< wchar > buffer( in.size() ); long result = decode( in.data(), in.size(), &buffer.front() ); diff --git a/wordbyauto.cc b/wordbyauto.cc index bc20309d..c56b415f 100644 --- a/wordbyauto.cc +++ b/wordbyauto.cc @@ -1,6 +1,5 @@ #include #include -#include #include "wordbyauto.hh" #include "uiauto.hh" @@ -12,7 +11,7 @@ public: GDAutomationClient(); ~GDAutomationClient(); bool getWordAtPoint( POINT pt ); - WCHAR *getText() { return buffer; }; + WCHAR *getText() { return buffer; } private: WCHAR buffer[256]; IUIAutomation *pGDAutomation; diff --git a/xdxf.cc b/xdxf.cc index 699fd419..9980870e 100644 --- a/xdxf.cc +++ b/xdxf.cc @@ -25,6 +25,10 @@ #include "indexedzip.hh" #include "filetype.hh" +#ifdef _MSC_VER +#include +#endif + #include #include #include @@ -94,7 +98,11 @@ struct IdxHeader // resource index. uint32_t zipIndexRootOffset; uint32_t revisionNumber; // Format revision -} __attribute__((packed)); +} +#ifndef _MSC_VER +__attribute__((packed)) +#endif +; bool indexIsOldOrBad( string const & indexFile ) { diff --git a/zipfile.cc b/zipfile.cc index 397a111c..7c4f1562 100644 --- a/zipfile.cc +++ b/zipfile.cc @@ -16,7 +16,11 @@ struct EndOfCdirRecord quint16 numDisk, numDiskCd, totalEntriesDisk, totalEntries; quint32 size, offset; quint16 commentLength; -} __attribute__((packed)); +} +#ifndef _MSC_VER +__attribute__((packed)) +#endif +; struct CentralFileHeaderRecord { @@ -26,7 +30,11 @@ struct CentralFileHeaderRecord quint16 fileNameLength, extraFieldLength, fileCommentLength, diskNumberStart, intFileAttrs; quint32 externalFileAttrs, offsetOfLocalHeader; -} __attribute__((packed)); +} +#ifndef _MSC_VER +__attribute__((packed)) +#endif +; struct LocalFileHeaderRecord { @@ -34,7 +42,11 @@ struct LocalFileHeaderRecord quint16 verNeeded, gpBits, compressionMethod, fileTime, fileDate; quint32 crc32, compressedSize, uncompressedSize; quint16 fileNameLength, extraFieldLength; -} __attribute__((packed)); +} +#ifndef _MSC_VER +__attribute__((packed)) +#endif +; #pragma pack( pop )