Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tessarray.cpp File Reference
#include "tessarray.h"
#include "callcpp.h"
#include "freelist.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>

Go to the source code of this file.

Functions

ARRAY array_insert (ARRAY array, int index, void *value)
 
ARRAY array_new (int num)
 
ARRAY array_push (ARRAY array, void *value)
 

Function Documentation

ARRAY array_insert ( ARRAY  array,
int  index,
void *  value 
)

Definition at line 53 of file tessarray.cpp.

53  {
54  int x;
55 
56  array = array_push (array, NULL);
57  for (x = array_count (array) - 1; x > index; x--)
58  array_value (array, x) = array_value (array, x - 1);
59  array_value (array, index) = value;
60  return (array);
61 }
ARRAY array_push(ARRAY array, void *value)
Definition: tessarray.cpp:98
#define NULL
Definition: host.h:144
#define array_count(a)
Definition: tessarray.h:74
#define array_value(a, i)
Definition: tessarray.h:132
ARRAY array_new ( int  num)

Definition at line 70 of file tessarray.cpp.

70  {
71  ARRAY temp;
72  int x;
73 
74  if (num == 0)
75  num = DEFAULT_SIZE;
76  temp = (ARRAY) memalloc ((num - 2) * sizeof (char *) +
77  sizeof (struct array_record));
78  if (!temp) {
79  cprintf ("error: Out of memory in array_new\n");
80  exit (1); //?err_exit ();
81  }
82  array_count (temp) = 0;
83  array_limit (temp) = num;
84  for (x = 0; x < num; x++)
85  array_value (temp, x) = (char *) 0;
86  return (temp);
87 }
int * memalloc(int size)
Definition: freelist.cpp:22
struct array_record * ARRAY
#define array_limit(a)
Definition: tessarray.h:103
#define array_count(a)
Definition: tessarray.h:74
#define array_value(a, i)
Definition: tessarray.h:132
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
#define DEFAULT_SIZE
Definition: tessarray.h:66
ARRAY array_push ( ARRAY  array,
void *  value 
)

Definition at line 98 of file tessarray.cpp.

98  {
99  if (array_count (array) == array_limit (array)) {
100  array = (ARRAY) memrealloc (array, (array_limit (array) * 2 - 2) *
101  sizeof (char *) +
102  sizeof (struct array_record),
103  (array_limit (array) -
104  2) * sizeof (char *) +
105  sizeof (struct array_record));
106  if (!array) {
107  cprintf ("error: Out of memory in array_push\n");
108  exit (1); //?err_exit ();
109  }
110  array_limit (array) *= 2;
111  }
112  array_count (array)++;
113  array_top (array) = value;
114  return (array);
115 }
#define array_top(a)
Definition: tessarray.h:123
struct array_record * ARRAY
int * memrealloc(void *ptr, int size, int oldsize)
Definition: freelist.cpp:26
#define array_limit(a)
Definition: tessarray.h:103
#define array_count(a)
Definition: tessarray.h:74
void cprintf(const char *format,...)
Definition: callcpp.cpp:41