Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC2010 support, enabled -ansi and -pedantic #4

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions cpp/SConscript
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
# -*- python -*-

Decider('MD5')
import platform
import fnmatch
import os

vars = Variables()
vars.Add(BoolVariable('DEBUG', 'Set to disable optimizations', 1))
vars.Add(BoolVariable('PIC', 'Set to 1 for to always generate PIC code', 0))
env = Environment(variables = vars)
# env.Replace(CXX = "clang++")
# env.Replace(CXX = 'clang++')

debug = env['DEBUG']
compile_options = {}
flags = []
if debug:
#compile_options['CPPDEFINES'] = "-DDEBUG"
flags.append("-O0 -g3 -ggdb -Wall")
if platform.system() is 'Windows':
compile_options['CXXFLAGS'] = '-D_CRT_SECURE_NO_WARNINGS /fp:fast /EHsc'
else:
flags.append("-Os -g3 -Wall")
if env['PIC']:
flags.append("-fPIC")

flags.append("-Wextra -Werror")
# Can't enable unless we get rid of the dynamic variable length arrays
# flags.append("-pedantic")

compile_options['CXXFLAGS'] = ' '.join(flags)
compile_options['LINKFLAGS'] = "-ldl -L/usr/lib -L/opt/local/lib -L/usr/local/lib"
cxxflags = []
if debug:
#compile_options['CPPDEFINES'] = '-DDEBUG'
cxxflags.append('-O0 -g3 -ggdb -Wall')
else:
cxxflags.append('-Os -g3 -Wall')
if env['PIC']:
cxxflags.append('-fPIC')

cxxflags.append('-Wextra -Werror')

# Force ANSI (C++98) to ensure compatibility with MSVC.
cxxflags.append('-ansi -pedantic')

compile_options['CXXFLAGS'] = ' '.join(cxxflags)
compile_options['LINKFLAGS'] = '-ldl -L/usr/lib -L/opt/local/lib -L/usr/local/lib'

def all_files(dir, ext='.cpp', level=6):
files = []
for i in range(1, level):
files += Glob(dir + ('/*' * i) + ext)
return files
files = []
for i in range(1, level):
files += Glob(dir + ('/*' * i) + ext)
return files



Expand All @@ -50,14 +55,16 @@ for root, dirnames, filenames in os.walk('/usr/lib/'):
matches.append(os.path.join(root, filename))

if matches:
magick_libs.append('iconv')
magick_libs.append('iconv')

cppunit_include = ['/opt/local/include/']
cppunit_libs = ['cppunit']

zxing_files = all_files('core/src')

zxing_include = ['core/src']
if platform.system() is 'Windows':
zxing_files += all_files('win32')
zxing_include += ['win32']
zxing_libs = env.Library('zxing', source=zxing_files, CPPPATH=zxing_include, **compile_options)

app_files = ['magick/src/MagickBitmapSource.cpp', 'magick/src/main.cpp']
Expand Down
2 changes: 2 additions & 0 deletions cpp/core/src/zxing/DecodeHints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <zxing/common/IllegalArgumentException.h>
namespace zxing {

#if !defined(_WIN32) && !defined(_WIN64)
const DecodeHintType DecodeHints::CHARACTER_SET;
#endif

const DecodeHints DecodeHints::PRODUCT_HINT(
BARCODEFORMAT_UPC_E_HINT |
Expand Down
4 changes: 2 additions & 2 deletions cpp/core/src/zxing/aztec/AztecDetectorResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace zxing {
compact_(compact),
nbDatablocks_(nbDatablocks),
nbLayers_(nbLayers) {
};
}

bool AztecDetectorResult::isCompact() {
return compact_;
Expand All @@ -42,4 +42,4 @@ namespace zxing {
return nbLayers_;
}
}
}
}
2 changes: 1 addition & 1 deletion cpp/core/src/zxing/aztec/AztecReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace zxing {

AztecReader::AztecReader() : decoder_() {
// nothing
};
}

Ref<Result> AztecReader::decode(Ref<zxing::BinaryBitmap> image) {
Detector detector(image->getBlackMatrix());
Expand Down
1 change: 1 addition & 0 deletions cpp/core/src/zxing/common/EdgeDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include <zxing/common/EdgeDetector.h>
#include <zxing/common/detector/math_utils.h>
#include <algorithm>
#include <cmath>

Expand Down
11 changes: 10 additions & 1 deletion cpp/core/src/zxing/common/detector/math_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@

#include <math.h>

#if defined(_WIN32) || defined(_WIN64)
#include <float.h>
#include <limits>
#define isnan(a) _isnan(a)
#define fmax max
#define INFINITY (std::numeric_limits<float>::infinity())
#define NAN (std::numeric_limits<float>::quiet_NaN())
#endif

namespace zxing { namespace common { namespace detector { namespace math_utils {

/**
Expand All @@ -38,7 +47,7 @@ inline float distance(float aX, float aY, float bX, float bY) {
inline float distance(int aX, int aY, int bX, int bY) {
int xDiff = aX - bX;
int yDiff = aY - bY;
return (float) sqrt(xDiff * xDiff + yDiff * yDiff);
return (float) sqrt((double)xDiff * xDiff + yDiff * yDiff);
}

}}}}
Expand Down
4 changes: 4 additions & 0 deletions cpp/core/src/zxing/common/reedsolomon/GenericGFPoly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ using zxing::GenericGFPoly;
using zxing::ArrayRef;
using zxing::Ref;

namespace zxing {

GenericGFPoly::GenericGFPoly(Ref<GenericGF> field,
ArrayRef<int> coefficients)
: field_(field) {
Expand Down Expand Up @@ -213,3 +215,5 @@ std::vector<Ref<GenericGFPoly> > GenericGFPoly::divide(Ref<GenericGFPoly> other)
returnValue[1] = remainder;
return returnValue;
}

}
10 changes: 5 additions & 5 deletions cpp/core/src/zxing/oned/ITFReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace zxing {
// interleaved white lines for the second digit.
// Therefore, need to scan 10 lines and then
// split these into two arrays
int counterDigitPairLen = 10;
const int counterDigitPairLen = 10;
int counterDigitPair[counterDigitPairLen];
for (int i=0; i<counterDigitPairLen; i++) {
counterDigitPair[i] = 0;
Expand Down Expand Up @@ -291,7 +291,7 @@ namespace zxing {
// TODO: This is very similar to implementation in UPCEANReader. Consider if they can be
// merged to a single method.
int patternLength = patternLen;
int counters[patternLength];
std::vector<int> counters(patternLength);
for (int i=0; i<patternLength; i++) {
counters[i] = 0;
}
Expand All @@ -306,7 +306,7 @@ namespace zxing {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
if (patternMatchVariance(counters, patternLength, pattern,
if (patternMatchVariance(&counters[0], patternLength, pattern,
MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
int* resultValue = new int[2];
resultValue[0] = patternStart;
Expand Down Expand Up @@ -343,11 +343,11 @@ namespace zxing {
int bestMatch = -1;
int max = PATTERNS_LEN;
for (int i = 0; i < max; i++) {
int pattern[countersLen];
std::vector<int> pattern(countersLen);
for(int ind = 0; ind<countersLen; ind++){
pattern[ind] = PATTERNS[i][ind];
}
unsigned int variance = patternMatchVariance(counters, countersLen, pattern,
unsigned int variance = patternMatchVariance(counters, countersLen, &pattern[0],
MAX_INDIVIDUAL_VARIANCE);
if (variance < bestVariance) {
bestVariance = variance;
Expand Down
1 change: 1 addition & 0 deletions cpp/core/src/zxing/oned/OneDReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "OneDReader.h"
#include <zxing/ReaderException.h>
#include <zxing/oned/OneDResultPoint.h>
#include <zxing/common/detector/math_utils.h>
#include <math.h>
#include <limits.h>

Expand Down
12 changes: 6 additions & 6 deletions cpp/core/src/zxing/oned/UPCEANReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace zxing {
bool UPCEANReader::findGuardPattern(Ref<BitArray> row, int rowOffset, bool whiteFirst,
const int pattern[], int patternLen, int* start, int* end) {
int patternLength = patternLen;
int counters[patternLength];
std::vector<int> counters(patternLength);
int countersCount = sizeof(counters) / sizeof(int);
for (int i = 0; i < countersCount; i++) {
counters[i] = 0;
Expand All @@ -189,7 +189,7 @@ namespace zxing {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
if (patternMatchVariance(counters, countersCount, pattern,
if (patternMatchVariance(&counters[0], countersCount, pattern,
MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
*start = patternStart;
*end = x;
Expand Down Expand Up @@ -231,12 +231,12 @@ namespace zxing {
case UPC_EAN_PATTERNS_L_PATTERNS:
max = L_PATTERNS_LEN;
for (int i = 0; i < max; i++) {
int pattern[countersLen];
std::vector<int> pattern(countersLen);
for(int j = 0; j< countersLen; j++){
pattern[j] = L_PATTERNS[i][j];
}

unsigned int variance = patternMatchVariance(counters, countersLen, pattern,
unsigned int variance = patternMatchVariance(counters, countersLen, &pattern[0],
MAX_INDIVIDUAL_VARIANCE);
if (variance < bestVariance) {
bestVariance = variance;
Expand All @@ -247,12 +247,12 @@ namespace zxing {
case UPC_EAN_PATTERNS_L_AND_G_PATTERNS:
max = L_AND_G_PATTERNS_LEN;
for (int i = 0; i < max; i++) {
int pattern[countersLen];
std::vector<int> pattern(countersLen);
for(int j = 0; j< countersLen; j++){
pattern[j] = L_AND_G_PATTERNS[i][j];
}

unsigned int variance = patternMatchVariance(counters, countersLen, pattern,
unsigned int variance = patternMatchVariance(counters, countersLen, &pattern[0],
MAX_INDIVIDUAL_VARIANCE);
if (variance < bestVariance) {
bestVariance = variance;
Expand Down
5 changes: 5 additions & 0 deletions cpp/core/src/zxing/qrcode/decoder/Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ using zxing::qrcode::Decoder;
using zxing::DecoderResult;
using zxing::Ref;

namespace zxing {
namespace qrcode {

Decoder::Decoder() :
rsDecoder_(GenericGF::QR_CODE_FIELD_256) {
}
Expand Down Expand Up @@ -98,3 +101,5 @@ Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
DecodedBitStreamParser::Hashtable());
}

}
}
1 change: 1 addition & 0 deletions cpp/core/src/zxing/qrcode/decoder/Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sstream>

using zxing::qrcode::Mode;
using zxing::qrcode::Version;
using std::ostringstream;

Mode Mode::TERMINATOR(0, 0, 0, 0x00, "TERMINATOR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "AlignmentPatternFinder.h"
#include <zxing/ReaderException.h>
#include <zxing/common/BitArray.h>
#include <zxing/common/detector/math_utils.h>
#include <vector>
#include <cmath>
#include <cstdlib>
Expand Down
9 changes: 8 additions & 1 deletion cpp/core/src/zxing/qrcode/detector/Detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace math_utils = zxing::common::detector::math_utils;
using std::ostringstream;
using std::min;
using std::max;
using std::isnan;
using zxing::qrcode::Detector;
using zxing::Ref;
using zxing::BitMatrix;
Expand All @@ -45,6 +44,11 @@ using zxing::DetectorResult;
using zxing::PerspectiveTransform;
using zxing::qrcode::AlignmentPattern;

namespace zxing {
namespace qrcode {

using namespace std;

Detector::Detector(Ref<BitMatrix> image) :
image_(image) {
}
Expand Down Expand Up @@ -306,3 +310,6 @@ Ref<AlignmentPattern> Detector::findAlignmentInRegion(float overallEstModuleSize
- alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_);
return alignmentFinder.find();
}

}
}
1 change: 1 addition & 0 deletions cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include <zxing/qrcode/detector/FinderPatternFinder.h>
#include <zxing/common/detector/math_utils.h>
#include <zxing/ReaderException.h>
#include <zxing/DecodeHints.h>
#include <vector>
Expand Down
14 changes: 14 additions & 0 deletions cpp/win32/iconv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _LIBICONV_H
#define _LIBICONV_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void* iconv_t;
iconv_t iconv_open(const char *tocode, const char *fromcode);
int iconv_close(iconv_t cd);
size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
#ifdef __cplusplus
}
#endif
#endif//_LIBICONV_H
Loading