Skip to content

Commit

Permalink
fix for issue 331
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@476 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
joregan committed Sep 29, 2010
1 parent dbed3e0 commit 653abd9
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 23 deletions.
4 changes: 2 additions & 2 deletions ccutil/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include_HEADERS = \
mainblk.h memblk.h memry.h memryerr.h mfcpch.h \
ndminx.h notdll.h nwmain.h \
ocrclass.h ocrshell.h platform.h qrsequence.h \
secname.h serialis.h stderr.h strngs.h \
secname.h serialis.h stderr.h strngs.h scanutils.h \
tessclas.h tessdatamanager.h tessopt.h tordvars.h tprintf.h \
unichar.h unicharmap.h unicharset.h unicity_table.h \
varable.h
Expand All @@ -24,7 +24,7 @@ libtesseract_ccutil_la_SOURCES = \
elst2.cpp elst.cpp errcode.cpp \
globaloc.cpp hashfn.cpp \
mainblk.cpp memblk.cpp memry.cpp ocrshell.cpp \
serialis.cpp strngs.cpp \
serialis.cpp strngs.cpp scanutils.cpp\
tessdatamanager.cpp tessopt.cpp tordvars.cpp tprintf.cpp \
unichar.cpp unicharmap.cpp unicharset.cpp \
varable.cpp
Expand Down
11 changes: 6 additions & 5 deletions ccutil/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ libtesseract_ccutil_la_LIBADD =
am_libtesseract_ccutil_la_OBJECTS = ambigs.lo basedir.lo bits16.lo \
boxread.lo ccutil.lo clst.lo debugwin.lo elst2.lo elst.lo \
errcode.lo globaloc.lo hashfn.lo mainblk.lo memblk.lo memry.lo \
ocrshell.lo serialis.lo strngs.lo tessdatamanager.lo \
tessopt.lo tordvars.lo tprintf.lo unichar.lo unicharmap.lo \
unicharset.lo varable.lo
ocrshell.lo serialis.lo strngs.lo scanutils.lo \
tessdatamanager.lo tessopt.lo tordvars.lo tprintf.lo \
unichar.lo unicharmap.lo unicharset.lo varable.lo
libtesseract_ccutil_la_OBJECTS = $(am_libtesseract_ccutil_la_OBJECTS)
libtesseract_ccutil_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
Expand Down Expand Up @@ -294,7 +294,7 @@ include_HEADERS = \
mainblk.h memblk.h memry.h memryerr.h mfcpch.h \
ndminx.h notdll.h nwmain.h \
ocrclass.h ocrshell.h platform.h qrsequence.h \
secname.h serialis.h stderr.h strngs.h \
secname.h serialis.h stderr.h strngs.h scanutils.h \
tessclas.h tessdatamanager.h tessopt.h tordvars.h tprintf.h \
unichar.h unicharmap.h unicharset.h unicity_table.h \
varable.h
Expand All @@ -306,7 +306,7 @@ libtesseract_ccutil_la_SOURCES = \
elst2.cpp elst.cpp errcode.cpp \
globaloc.cpp hashfn.cpp \
mainblk.cpp memblk.cpp memry.cpp ocrshell.cpp \
serialis.cpp strngs.cpp \
serialis.cpp strngs.cpp scanutils.cpp\
tessdatamanager.cpp tessopt.cpp tordvars.cpp tprintf.cpp \
unichar.cpp unicharmap.cpp unicharset.cpp \
varable.cpp
Expand Down Expand Up @@ -402,6 +402,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memblk.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memry.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ocrshell.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scanutils.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/serialis.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strngs.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tessdatamanager.Plo@am__quote@
Expand Down
40 changes: 36 additions & 4 deletions ccutil/scanutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum Ranks {
RANK_LONG = 1,
RANK_LONGLONG = 2,
RANK_PTR = INT_MAX // Special value used for pointers
RANK_PTR = 3 // Special value used for pointers
// RANK_PTR = 3 // Special value used for pointers
};

const enum Ranks kMinRank = RANK_CHAR;
Expand Down Expand Up @@ -214,19 +214,48 @@ double strtofloat(const char* s)
return minus ? -f : f;
}

static int tess_vfscanf(FILE* stream, const char *format, va_list ap);

int tess_fscanf(FILE* stream, const char *format, ...)
{
va_list ap;
int rv;

va_start(ap, format);
rv = tess_vfscanf(stream, format, ap);
va_end(ap);

return rv;
}

#ifdef EMBEDDED
int fscanf(FILE* stream, const char *format, ...)
{
va_list ap;
int rv;

va_start(ap, format);
rv = vfscanf(stream, format, ap);
rv = tess_vfscanf(stream, format, ap);
va_end(ap);

return rv;
}

int vfscanf(FILE* stream, const char *format, ...)
{
va_list ap;
int rv;

va_start(ap, format);
rv = tess_vfscanf(stream, format, ap);
va_end(ap);

return rv;
}
#endif

int vfscanf(FILE* stream, const char *format, va_list ap)
static
int tess_vfscanf(FILE* stream, const char *format, va_list ap)
{
const char *p = format;
char ch;
Expand All @@ -253,6 +282,7 @@ int vfscanf(FILE* stream, const char *format, va_list ap)
int matchinv = 0; // Is match map inverted?
unsigned char range_start = 0;
off_t start_off = ftell(stream);
double fval;

// Skip leading spaces
SkipSpace(stream);
Expand Down Expand Up @@ -414,7 +444,7 @@ int vfscanf(FILE* stream, const char *format, va_list ap)
break;
}

double fval = streamtofloat(stream);
fval = streamtofloat(stream);
switch(rank) {
case RANK_INT:
*va_arg(ap, float *) = static_cast<float>(fval);
Expand Down Expand Up @@ -539,7 +569,9 @@ int vfscanf(FILE* stream, const char *format, va_list ap)
return converted;
}

#ifdef EMBEDDED
int creat(const char *pathname, mode_t mode)
{
return open(pathname, O_CREAT | O_TRUNC | O_WRONLY, mode);
}
#endif
17 changes: 12 additions & 5 deletions ccutil/scanutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,34 @@
#ifndef SCANUTILS_H
#define SCANUTILS_H

#ifdef EMBEDDED

#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <klibc/extern.h>
#include <sys/stat.h>

// Parse a file stream according to the given format. See the fscanf manpage
// for more information, as this function attempts to mimic its behavior.
// Note that scientific floating-point notation is not supported.
// This variant is used to ensure correct reading regardless of locale.
int tess_fscanf(FILE* stream, const char *format, ...);

#ifdef EMBEDDED

#include <klibc/extern.h>

// Attempts to parse the given file stream s as an integer of the base
// 'base'. Returns the first successfully parsed integer as a uintmax_t, or
// 0, if none was found.
uintmax_t streamtoumax(FILE* s, int base);

// Parse a file stream according to the given format. See the fscanf manpage
// for more information, as this function attempts to mimic its behavior.
// Note that scientific loating-point notation is not supported.
// Note that scientific floating-point notation is not supported.
int fscanf(FILE* stream, const char *format, ...);

// Parse a file stream according to the given format. See the fscanf manpage
// for more information, as this function attempts to mimic its behavior.
// Note that scientific loating-point notation is not supported.
// Note that scientific floating-point notation is not supported.
int vfscanf(FILE* stream, const char *format, va_list ap);

// Create a file at the specified path. See the creat manpage for more
Expand Down
2 changes: 1 addition & 1 deletion ccutil/serialis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ DLLSYM void serialise_FLOAT64(FILE *f, double the_float) {
DLLSYM double de_serialise_FLOAT64(FILE *f) {
double the_float;

if (fscanf (f, "%lg", &the_float) != 1)
if (tess_fscanf (f, "%lg", &the_float) != 1)
READFAILED.error ("de_serialise_FLOAT64", ABORT, NULL);
return the_float;
}
Expand Down
4 changes: 2 additions & 2 deletions classify/clusttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ PARAM_DESC *ReadParamDesc(FILE *File, uinT16 N) {
ParamDesc[i].NonEssential = FALSE;
else
ParamDesc[i].NonEssential = TRUE;
if (fscanf (File, "%f%f", &(ParamDesc[i].Min), &(ParamDesc[i].Max)) !=
if (tess_fscanf (File, "%f%f", &(ParamDesc[i].Min), &(ParamDesc[i].Max)) !=
2)
DoError (ILLEGALMINMAXSPEC, "Illegal min or max specification");
ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;
Expand Down Expand Up @@ -289,7 +289,7 @@ ReadNFloats (FILE * File, uinT16 N, FLOAT32 Buffer[]) {
Buffer = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32));

for (i = 0; i < N; i++) {
NumFloatsRead = fscanf (File, "%f", &(Buffer[i]));
NumFloatsRead = tess_fscanf (File, "%f", &(Buffer[i]));
if (NumFloatsRead != 1) {
if ((NumFloatsRead == EOF) && (i == 0))
return (NULL);
Expand Down
2 changes: 1 addition & 1 deletion classify/ocrfeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ FEATURE ReadFeature(FILE *File, FEATURE_DESC FeatureDesc) {

Feature = NewFeature (FeatureDesc);
for (i = 0; i < Feature->Type->NumParams; i++) {
if (fscanf (File, "%f", &(Feature->Params[i])) != 1)
if (tess_fscanf (File, "%f", &(Feature->Params[i])) != 1)
DoError (ILLEGAL_FEATURE_PARAM, "Illegal feature parameter spec");
#ifndef __MSW32__
assert (!isnan(Feature->Params[i]));
Expand Down
2 changes: 1 addition & 1 deletion classify/protos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void ReadProtos(register FILE *File, CLASS_TYPE Class) {

for (Pid = 0; Pid < NumProtos; Pid++) {
Proto = ProtoIn (Class, Pid);
fscanf (File, "%f %f %f %f %f %f %f\n",
tess_fscanf (File, "%f %f %f %f %f %f %f\n",
&Proto->X,
&Proto->Y,
&Proto->Length,
Expand Down
4 changes: 4 additions & 0 deletions config/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@
#define GRAPHICS_DISABLED
#endif

#ifndef DISABLE_NLS
#define USE_NLS
#endif

/* config_auto.h: end */
#endif

4 changes: 2 additions & 2 deletions tessdata/configs/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
data_DATA = inter makebox box.train unlv ambigs.train api_config kannada box.train.stderr logfile
EXTRA_DIST = inter makebox box.train unlv ambigs.train api_config kannada box.train.stderr logfile
data_DATA = inter makebox box.train unlv ambigs.train api_config kannada box.train.stderr logfile digits
EXTRA_DIST = inter makebox box.train unlv ambigs.train api_config kannada box.train.stderr logfile digits
all: all-am

.SUFFIXES:
Expand Down

0 comments on commit 653abd9

Please sign in to comment.