1 /* managed-sa.h
2 
3    Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
4 
5    This file is part of LuaTeX.
6 
7    LuaTeX is free software; you can redistribute it and/or modify it under
8    the terms of the GNU General Public License as published by the Free
9    Software Foundation; either version 2 of the License, or (at your
10    option) any later version.
11 
12    LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15    License for more details.
16 
17    You should have received a copy of the GNU General Public License along
18    with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
19 
20 
21 #ifndef MANAGED_SA_H
22 #  define MANAGED_SA_H 1
23 
24 /* the next two sets of three had better match up exactly, but using bare numbers
25   is easier on the C compiler */
26 
27 #  define HIGHPART 128
28 #  define MIDPART 128
29 #  define LOWPART 128
30 
31 #  define HIGHPART_PART(a) (((a)>>14)&127)
32 #  define MIDPART_PART(a)  (((a)>>7)&127)
33 #  define LOWPART_PART(a)  ((a)&127)
34 
35 #  define Mxmalloc_array(a,b)  xmalloc((unsigned)((unsigned)(b)*sizeof(a)))
36 #  define Mxcalloc_array(a,b)  xcalloc((b),sizeof(a))
37 #  define Mxrealloc_array(a,b,c)  xrealloc((a),(unsigned)((unsigned)(c)*sizeof(b)))
38 
39 typedef unsigned int sa_tree_item;
40 
41 typedef struct {
42     int code;
43     int level;
44     sa_tree_item value;
45 } sa_stack_item;
46 
47 
48 typedef struct {
49     int stack_size;             /* initial stack size   */
50     int stack_step;             /* increment stack step */
51     int stack_ptr;              /* current stack point  */
52     sa_tree_item dflt;          /* default item value   */
53     sa_tree_item ***tree;       /* item tree head       */
54     sa_stack_item *stack;       /* stack tree head      */
55 } sa_tree_head;
56 
57 typedef sa_tree_head *sa_tree;
58 
59 extern sa_tree_item get_sa_item(const sa_tree head, const int n);
60 extern void set_sa_item(sa_tree head, int n, sa_tree_item v, int gl);
61 extern void rawset_sa_item(sa_tree head, int n, sa_tree_item v);
62 
63 extern sa_tree new_sa_tree(int size, sa_tree_item dflt);
64 
65 extern sa_tree copy_sa_tree(sa_tree head);
66 extern void destroy_sa_tree(sa_tree head);
67 
68 extern void dump_sa_tree(sa_tree a);
69 extern sa_tree undump_sa_tree(void);
70 
71 extern void restore_sa_stack(sa_tree a, int gl);
72 extern void clear_sa_stack(sa_tree a);
73 
74 #endif
75