cutil/cutil.cpp File Reference

#include "cutil.h"
#include "callcpp.h"
#include <stdlib.h>

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define RESET_COUNT   2000

Note:
File: cutil.cpp
General utility functions
Author:
Mark Seaman, SW Productivity
Date:
Fri Oct 16 14:37:00 1987, Wed Jun 6 16:29:17 1990
 * (c) Copyright 1987, Hewlett-Packard Company.
 ** 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.
  • 1.1.1.1 2004/02/20 19:39:06 slumos Import original HP distribution
  • 1.3 90/03/06 15:39:10 15:39:10 marks (Mark Seaman) Look for correct file of <malloc.h> or <stdlib.h>
  • 1.2 90/01/15 13:02:13 13:02:13 marks (Mark Seaman) Added memory allocator (*allocate) and (*deallocate)
  • 1.1 89/10/09 14:58:29 14:58:29 marks (Mark Seaman) Initial revision

Definition at line 33 of file cutil.cpp.


Function Documentation

long long_rand ( long  limit  ) 

Compute long random number whose value is less than limit.

Do this by calling the standard cheepo random number generator and reseting it pretty often.

Definition at line 44 of file cutil.cpp.

Referenced by new_dawg_node().

00044                            {
00045 #if RAND_MAX < 0x1000000
00046   static long seed;
00047 
00048   long num;
00049   num = (long) rand () << 16;
00050   num |= rand () & 0xffff;
00051   seed ^= num;
00052   long result = num % limit;
00053   while (result < 0) {
00054     result += limit;
00055   }
00056   return result;
00057 #else
00058   return (long)((double)limit * rand()/(RAND_MAX + 1.0));
00059 #endif
00060 }

FILE* open_file ( const char *  filename,
const char *  mode 
)

Open a file for reading or writing.

If the file name parameter is NULL use stdin (or stdout) for the file. If the file can not be opened then call the error routine.

Definition at line 70 of file cutil.cpp.

References NULL.

Referenced by add_document_word(), edit_with_ocr(), read_list(), read_squished_dawg(), read_word_list(), ReadClassFile(), save_summary(), and start_recording().

00070                                                         {
00071   FILE *thisfile = NULL;
00072   if ((thisfile = fopen (filename, mode)) == NULL) {
00073     printf ("Could not open file, %s\n", filename);
00074     exit (1);
00075   }
00076   return (thisfile);
00077 }


Variable Documentation

char_proc allocate = (char_proc) c_alloc_string

Definition at line 36 of file cutil.cpp.

void_proc deallocate = (void_proc) c_free_string

Definition at line 35 of file cutil.cpp.


Generated on Wed Feb 28 19:49:21 2007 for Tesseract by  doxygen 1.5.1