19
19
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
21
21
#include "ptexlib.h"
22
#include <kpathsea/c-proto.h>
25
24
static const char __svn_version[] =
26
"$Id: avlstuff.c 2599 2009-06-25 10:35:26Z taco $ "
27
"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/utils/avlstuff.c $";
29
static struct avl_table **PdfObjTree = NULL;
25
"$Id: avlstuff.c 2817 2009-07-12 00:45:27Z oneiros $ "
26
"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.50.0/source/texk/web2c/luatexdir/utils/avlstuff.c $";
31
28
/**********************************************************************/
32
29
/* memory management functions for AVL */
64
61
return strcmp((const char *) pa, (const char *) pb);
67
/**********************************************************************/
68
/* One AVL tree for each obj_type 0...pdf_objtype_max */
70
typedef struct oentry_ {
75
/* AVL sort oentry into avl_table[] */
77
static int compare_info(const void *pa, const void *pb, void *param)
80
int as, ae, bs, be, al, bl;
82
a = ((const oentry *) pa)->int0;
83
b = ((const oentry *) pb)->int0;
84
if (a < 0 && b < 0) { /* string comparison */
85
if (a <= 2097152 && b <= 2097152) {
89
ae = str_start[-a + 1]; /* start of next string in pool */
91
be = str_start[-b + 1];
94
if (al < bl) /* compare first by string length */
98
for (; as < ae; as++, bs++) {
99
if (str_pool[as] < str_pool[bs])
101
if (str_pool[as] > str_pool[bs])
106
("avlstuff.c: compare_items() for single characters: NI");
108
} else { /* integer comparison */
117
void avl_put_obj(integer objptr, integer t)
123
if (PdfObjTree == NULL) {
124
PdfObjTree = xtalloc(pdf_objtype_max + 1, struct avl_table *);
125
for (i = 0; i <= pdf_objtype_max; i++)
126
PdfObjTree[i] = NULL;
128
if (PdfObjTree[t] == NULL) {
129
PdfObjTree[t] = avl_create(compare_info, NULL, &avl_xallocator);
130
if (PdfObjTree[t] == NULL)
131
pdftex_fail("avlstuff.c: avl_create() PdfObjTree failed");
133
oe = xtalloc(1, oentry);
134
oe->int0 = obj_info(objptr);
135
oe->objptr = objptr; /* allows to relocate obj_tab */
136
pp = avl_probe(PdfObjTree[t], oe);
138
pdftex_fail("avlstuff.c: avl_probe() out of memory in insertion");
141
/* replacement for linear search pascal function "find_obj()" */
143
integer avl_find_obj(integer t, integer i, integer byname)
152
if (PdfObjTree == NULL || PdfObjTree[t] == NULL)
154
p = (oentry *) avl_find(PdfObjTree[t], &tmp);
160
/**********************************************************************/
163
static void destroy_oentry(void *pa, void *pb)
165
oentry *p = (oentry *) pa;
170
void PdfObjTree_free()
174
if (PdfObjTree == NULL)
176
for (i = 0; i <= pdf_objtype_max; i++) {
177
if (PdfObjTree[i] != NULL)
178
avl_destroy(PdfObjTree[i], destroy_oentry);