Skip to content

Commit

Permalink
MinGW portability solved + some code cleanup (based on cpplint)
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@605 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
zdenop@gmail.com committed Aug 15, 2011
1 parent 7ec3dca commit 9b7375e
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 213 deletions.
8 changes: 4 additions & 4 deletions ccmain/pagesegmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@
**********************************************************************/

#ifdef WIN32
#ifndef __GNUC__
#include <windows.h>
#endif /* __GNUC__ */
#else
#include <unistd.h>
#endif
#ifdef _MSC_VER
#pragma warning(disable:4244) // Conversion warnings
#endif

#include <string>

// Include automatically generated configuration file if running autoconf.
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
#endif

#ifdef HAVE_LIBLEPT
// Include leptonica library only if autoconf (or makefile etc) tell us to.
#include "allheaders.h"
#endif

#include "tesseractclass.h"
#include "img.h"
#include "blobbox.h"
Expand Down
9 changes: 8 additions & 1 deletion ccutil/ambigs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@
//
///////////////////////////////////////////////////////////////////////

#include <string>
#include <algorithm>

#include "ambigs.h"
#include "helpers.h"

#ifdef WIN32
#ifndef __GNUC__
#define strtok_r strtok_s
#endif
#else
#include "strtok_r.h"
#endif /* __GNUC__ */
#endif /* WIN32 */

namespace tesseract {

Expand Down
73 changes: 34 additions & 39 deletions ccutil/ocrclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
* structure alignment upto 8.
**********************************************************************/

#ifndef OCRCLASS_H
#define OCRCLASS_H
#ifndef CCUTIL_OCRCLASS_H_
#define CCUTIL_OCRCLASS_H_

#ifndef __GNUC__
#ifdef __MSW32__
#include <windows.h>
#include "gettimeofday.h"
#endif
#else
#include <sys/time.h>
#endif
Expand Down Expand Up @@ -126,38 +128,35 @@ OR these together for enhancement in ocr_append_char*/
#define EUC_SUPERSCRIPT 16 /*superscript char */

/*enum for character rendering direction*/
enum OCR_CHAR_DIRECTION
{
enum OCR_CHAR_DIRECTION {
OCR_CDIR_RIGHT_LEFT, /*right to left horizontal */
OCR_CDIR_LEFT_RIGHT, /*left to right horizontal */
OCR_CDIR_TOP_BOTTOM, /*top to bottom vertical */
OCR_CDIR_BOTTOM_TOP /*bottom to top vertical */
};

/*enum for line rendering direction*/
enum OCR_LINE_DIRECTION
{
enum OCR_LINE_DIRECTION {
OCR_LDIR_DOWN_RIGHT, /*horizontal lines go down */
/*vertical lines go right */
OCR_LDIR_UP_LEFT /*horizontal lines go up */
};

/*enum for newline type*/
enum OCR_NEWLINE_TYPE
{
enum OCR_NEWLINE_TYPE {
OCR_NL_NONE, /*not a newline */
OCR_NL_NEWLINE, /*this is a newline but not new para */
OCR_NL_NEWPARA /*this is a newline and a new para */
};

/*error codes that can be returned from the API functions other than OKAY and HPERR*/
/*error codes that can be returned from the API functions other than OKAY
and HPERR*/
#define OCR_API_NO_MEM (-2) /*filled output buffer */
#define OCR_API_BAD_CHAR (-3) /*whitespace sent to ocr_append_char */
#define OCR_API_BAD_STATE (-4) /*invalid call sequence */

/*error codes used for passing errors back to the HP side*/
enum OCR_ERR_CODE
{
enum OCR_ERR_CODE {
OCR_ERR_NONE, /*no error */
OCR_ERR_CLEAN_EXIT, /*no error */
OCR_ERR_NO_MEM, /*out of memory */
Expand Down Expand Up @@ -187,8 +186,7 @@ enum OCR_ERR_CODE
* The name may be either a valid font on the system or the empty string.
**********************************************************************/

typedef struct /*font description */
{
typedef struct { /*font description */
uinT16 language; /*default language */
uinT8 font_family; /*serif/not, fixed/not */
uinT8 char_set; /*character set standard */
Expand All @@ -204,8 +202,7 @@ typedef struct /*font description */
* can recognize.
**********************************************************************/

typedef struct /*startup info */
{
typedef struct { /*startup info */
inT32 protocol; /*interface version */
uinT32 font_count; /*number of fonts */
uinT16 language; /*default language */
Expand All @@ -225,8 +222,7 @@ typedef struct /*startup info */
* The top leftmost pixel is in the most significant bit of the first byte.
**********************************************************************/

typedef struct /*bitmap strip */
{
typedef struct { /*bitmap strip */
inT16 x_size; /*width in pixels */
inT16 y_size; /*of full image */
inT16 strip_size; /*of this strip */
Expand Down Expand Up @@ -258,15 +254,15 @@ typedef struct /*bitmap strip */
* version.
**********************************************************************/

typedef struct /*single character */
{
// It should be noted that the format for char_code for version 2.0 and beyond is UTF8
// which means that ASCII characters will come out as one structure but other characters
// will be returned in two or more instances of this structure with a single byte of the
// UTF8 code in each, but each will have the same bounding box.
// Programs which want to handle languagues with different characters sets will need to
// handle extended characters appropriately, but *all* code needs to be prepared to
// receive UTF8 coded characters for characters such as bullet and fancy quotes.
typedef struct { /*single character */
// It should be noted that the format for char_code for version 2.0 and beyond
// is UTF8 which means that ASCII characters will come out as one structure but
// other characters will be returned in two or more instances of this structure
// with a single byte of the UTF8 code in each, but each will have the same
// bounding box. Programs which want to handle languagues with different
// characters sets will need to handle extended characters appropriately, but
// *all* code needs to be prepared to receive UTF8 coded characters for
// characters such as bullet and fancy quotes.
uinT16 char_code; /*character itself */
inT16 left; /*of char (-1) */
inT16 right; /*of char (-1) */
Expand Down Expand Up @@ -295,19 +291,18 @@ typedef struct /*single character */
**********************************************************************/
typedef bool (*CANCEL_FUNC)(void* cancel_this, int words);

class ETEXT_DESC /*output header */
{
class ETEXT_DESC { // output header
public:
inT16 count; /*chars in this buffer(0) */
inT16 progress; /*percent complete increasing (0-100) */
inT8 more_to_come; /*true if not last */
volatile inT8 ocr_alive; /*ocr sets to 1, HP 0 */
inT8 err_code; /*for errcode use */
CANCEL_FUNC cancel; /*returns true to cancel */
void* cancel_this; /*this or other data for cancel*/
struct timeval end_time; /*time to stop. expected to be set only by call
to set_deadline_msecs()*/
EANYCODE_CHAR text[1]; /*character data */
inT16 count; // chars in this buffer(0)
inT16 progress; // percent complete increasing (0-100)
inT8 more_to_come; // true if not last
volatile inT8 ocr_alive; // ocr sets to 1, HP 0
inT8 err_code; // for errcode use
CANCEL_FUNC cancel; // returns true to cancel
void* cancel_this; // this or other data for cancel
struct timeval end_time; // time to stop. expected to be set only by call
// to set_deadline_msecs()
EANYCODE_CHAR text[1]; // character data

ETEXT_DESC() : count(0), progress(0), more_to_come(0), ocr_alive(0),
err_code(0), cancel(NULL), cancel_this(NULL) {
Expand Down Expand Up @@ -337,4 +332,4 @@ class ETEXT_DESC /*output header */
}
};

#endif
#endif // CCUTIL_OCRCLASS_H_
34 changes: 32 additions & 2 deletions ccutil/platform.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
// Place holder
///////////////////////////////////////////////////////////////////////
// File: platform.h
// Description: Place holder
// Author:
// Created:
//
// (C) Copyright 2006, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////

#ifndef TESSERACT_CCUTIL_PLATFORM_H__
#define TESSERACT_CCUTIL_PLATFORM_H__

#define DLLSYM
#ifdef __MSW32__
#ifdef __GNUC__
#define ultoa _ultoa
typedef struct _BLOB {
unsigned int cbSize;
char *pBlobData;
} BLOB, *LPBLOB;
#endif /* __GNUC__ */
#define SIGNED
#define snprintf _snprintf
#if (_MSC_VER <= 1400)
#define vsnprintf _vsnprintf
#endif
#endif /* __MSW32__ */
#else
#define __UNIX__
#include <limits.h>
Expand All @@ -16,3 +44,5 @@
#endif
#define SIGNED signed
#endif

#endif // TESSERACT_CCUTIL_PLATFORM_H__
10 changes: 6 additions & 4 deletions dict/dawg.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*
*********************************************************************************/

#ifndef DAWG_H
#define DAWG_H
#ifndef DICT_DAWG_H_
#define DICT_DAWG_H_

/*----------------------------------------------------------------------
I n c l u d e s
Expand All @@ -35,11 +35,13 @@
#include "ratngs.h"
#include "params.h"

#ifndef __GNUC__
#ifdef __MSW32__
#define NO_EDGE (inT64) 0xffffffffffffffffi64
#endif /*__MSW32__*/
#else
#define NO_EDGE (inT64) 0xffffffffffffffffll
#endif
#endif /*__GNUC__*/

/*----------------------------------------------------------------------
T y p e s
Expand Down Expand Up @@ -481,4 +483,4 @@ class SquishedDawg : public Dawg {

} // namespace tesseract

#endif
#endif // DICT_DAWG_H_
6 changes: 2 additions & 4 deletions viewer/svutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#include <winsock.h>
struct addrinfo {
struct sockaddr* ai_addr;
int ai_addrlen;
Expand Down Expand Up @@ -66,7 +64,7 @@ const int kMaxMsgSize = 4096;
// Signals a thread to exit.
void SVSync::ExitThread() {
#ifdef WIN32
//ExitThread(0);
// ExitThread(0);
#else
pthread_exit(0);
#endif
Expand Down Expand Up @@ -248,7 +246,7 @@ char* SVNetwork::Receive() {
msg_buffer_in_[i] = '\0';
has_content = true;
#ifdef WIN32
return strtok(msg_buffer_in_,"\n");
return strtok(msg_buffer_in_, "\n");
#else
// Setup a new string tokenizer.
return strtok_r(msg_buffer_in_, "\n", &buffer_ptr_);
Expand Down
7 changes: 6 additions & 1 deletion viewer/svutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@
#define TESSERACT_VIEWER_SVUTIL_H__

#ifdef WIN32
#ifndef __GNUC__
#include <windows.h>
#define snprintf _snprintf
#if (_MSC_VER <= 1400)
#define vsnprintf _vsnprintf
#endif
#pragma warning(disable:4786)
#else
#include "platform.h"
#include <windows.h>
#endif
#else
#include <pthread.h>
#include <semaphore.h>
#endif
Expand Down Expand Up @@ -129,7 +134,7 @@ class SVNetwork {
/// Stores the messages which are supposed to go out.
std::string msg_buffer_out_;

bool has_content; // Win32 (strtok)
bool has_content; // Win32 (strtok)
/// Where we are at in our msg_buffer_in_
char* buffer_ptr_; // Unix (strtok_r)
};
Expand Down
Loading

0 comments on commit 9b7375e

Please sign in to comment.