cutil/tessarray.cpp

Go to the documentation of this file.
00001 
00022 #include "tessarray.h"
00023 #include "callcpp.h"
00024 #include "freelist.h"
00025 
00026 #include <stdio.h>
00027 #include <string.h>
00028 #ifdef __MSW32__
00029 #include <process.h>
00030 #endif
00031 #include <ctype.h>
00032 #if MAC_OR_DOS
00033 #include <stdlib.h>
00034 #endif
00035 
00042 ARRAY array_insert(ARRAY array, int index, void *value) { 
00043   int x;
00044 
00045   array = array_push (array, NULL);
00046   for (x = array_count (array) - 1; x > index; x--)
00047     array_value (array, x) = array_value (array, x - 1);
00048   array_value (array, index) = value;
00049   return (array);
00050 }
00051 
00052 
00058 ARRAY array_new(int num) { 
00059   ARRAY temp;
00060   int x;
00061 
00062   if (num == 0)
00063     num = DEFAULT_SIZE;
00064   temp = (ARRAY) memalloc ((num - 2) * sizeof (char *) +
00065     sizeof (struct array_record));
00066   if (!temp) {
00067     cprintf ("error: Out of memory in array_new\n");
00068     exit (1);                    //?err_exit ();
00069   }
00070   array_count (temp) = 0;
00071   array_limit (temp) = num;
00072   for (x = 0; x < num; x++)
00073     array_value (temp, x) = (char *) 0;
00074   return (temp);
00075 }
00076 
00077 
00085 ARRAY array_push(ARRAY array, void *value) { 
00086   if (array_count (array) == array_limit (array)) {
00087     array = (ARRAY) memrealloc (array, (array_limit (array) * 2 - 2) *
00088       sizeof (char *) +
00089       sizeof (struct array_record),
00090       (array_limit (array) -
00091       2) * sizeof (char *) +
00092       sizeof (struct array_record));
00093     if (!array) {
00094       cprintf ("error: Out of memory in array_push\n");
00095       exit (1);                  //?err_exit ();
00096     }
00097     array_limit (array) *= 2;
00098   }
00099   array_count (array)++;
00100   array_top (array) = value;
00101   return (array);
00102 }

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