3
Copyright (c) 2006 Taco Hoekwater, <taco@elvenkind.com>
5
This file is part of LuaTeX.
7
LuaTeX is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
LuaTeX is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with LuaTeX; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#include "luatex-api.h"
29
#include "managed-sa.h"
32
#define LCCODEDEFAULT 0
34
static sa_tree lccode_head = NULL;
37
#define UCCODEDEFAULT 0
39
static sa_tree uccode_head = NULL;
42
#define SFCODEDEFAULT 1000
44
static sa_tree sfcode_head = NULL;
46
#define CATCODESTACK 8
47
#define CATCODEDEFAULT 12
49
void set_lc_code (integer n, halfword v, quarterword gl) {
50
set_sa_item(lccode_head,n,v,gl);
53
halfword get_lc_code (integer n) {
54
return (halfword)get_sa_item(lccode_head,n);
57
static void unsavelccodes (quarterword gl) {
58
restore_sa_stack(lccode_head,gl);
61
static void initializelccodes (void) {
62
lccode_head = new_sa_tree(LCCODESTACK,LCCODEDEFAULT);
65
static void dumplccodes (void) {
66
dump_sa_tree(lccode_head);
69
static void undumplccodes (void) {
70
lccode_head = undump_sa_tree();
73
void set_uc_code (integer n, halfword v, quarterword gl) {
74
set_sa_item(uccode_head,n,v,gl);
77
halfword get_uc_code (integer n) {
78
return (halfword)get_sa_item(uccode_head,n);
81
static void unsaveuccodes (quarterword gl) {
82
restore_sa_stack(uccode_head,gl);
85
static void initializeuccodes (void) {
86
uccode_head = new_sa_tree(UCCODESTACK,UCCODEDEFAULT);
89
static void dumpuccodes (void) {
90
dump_sa_tree(uccode_head);
93
static void undumpuccodes (void) {
94
uccode_head = undump_sa_tree();
97
void set_sf_code (integer n, halfword v, quarterword gl) {
98
set_sa_item(sfcode_head,n,v,gl);
101
halfword get_sf_code (integer n) {
102
return (halfword)get_sa_item(sfcode_head,n);
105
static void unsavesfcodes (quarterword gl) {
106
restore_sa_stack(sfcode_head,gl);
109
static void initializesfcodes (void) {
110
sfcode_head = new_sa_tree(SFCODESTACK,SFCODEDEFAULT);
113
static void dumpsfcodes (void) {
114
dump_sa_tree(sfcode_head);
117
static void undumpsfcodes (void) {
118
sfcode_head = undump_sa_tree();
122
static sa_tree *catcode_heads = NULL;
123
static int catcode_max = 0;
124
static unsigned char *catcode_valid = NULL;
126
void check_catcode_sizes (int h) {
131
catcode_heads = Mxrealloc_array(catcode_heads,sa_tree,(h+1));
132
catcode_valid = Mxrealloc_array(catcode_valid,unsigned char,(h+1));
133
for (k=(catcode_max+1);k<=h;k++) {
134
catcode_heads[k] = NULL;
135
catcode_valid[k] = 0;
141
void set_cat_code (integer h, integer n, halfword v, quarterword gl) {
142
check_catcode_sizes(h);
143
if (catcode_heads[h] == NULL) {
144
catcode_heads[h] = new_sa_tree(CATCODESTACK,CATCODEDEFAULT);
146
set_sa_item(catcode_heads[h],n,v,gl);
149
halfword get_cat_code (integer h, integer n) {
150
check_catcode_sizes(h);
151
if (catcode_heads[h] == NULL) {
152
catcode_heads[h] = new_sa_tree(CATCODESTACK,CATCODEDEFAULT);
154
return (halfword)get_sa_item(catcode_heads[h],n);
157
void unsave_cat_codes (integer h, quarterword gl) {
159
check_catcode_sizes(h);
160
for (k=0;k<=catcode_max;k++) {
161
if (catcode_heads[k] != NULL)
162
restore_sa_stack(catcode_heads[k],gl);
166
void clearcatcodestack(integer h) {
167
clear_sa_stack(catcode_heads[h]);
170
static void initializecatcodes (void) {
172
catcode_heads = Mxmalloc_array(sa_tree,(catcode_max+1));
173
catcode_valid = Mxmalloc_array(unsigned char,(catcode_max+1));
174
catcode_valid[0] = 1;
175
catcode_heads[0] = new_sa_tree(CATCODESTACK,CATCODEDEFAULT);
178
static void dumpcatcodes (void) {
180
dump_int(catcode_max);
182
for (k=0;k<=catcode_max;k++) {
183
if (catcode_valid[k]) {
188
for (k=0;k<=catcode_max;k++) {
189
if (catcode_valid[k]) {
191
dump_sa_tree(catcode_heads[k]);
196
static void undumpcatcodes (void) {
198
undump_int(catcode_max);
199
catcode_heads = Mxmalloc_array(sa_tree,(catcode_max+1));
200
catcode_valid = Mxmalloc_array(unsigned char,(catcode_max+1));
201
for (k=0;k<=catcode_max;k++) {
202
catcode_heads[k]=NULL;
206
for (k=0;k<total;k++) {
208
catcode_heads[h] = undump_sa_tree();
209
catcode_valid[h] = 1;
213
int valid_catcode_table (int h) {
214
if (h<=catcode_max && h>=0 && catcode_valid[h]) {
220
void copy_cat_codes (int from, int to) {
221
if (from<0 || from>catcode_max || catcode_valid[from] == 0) {
224
check_catcode_sizes(to);
225
destroy_sa_tree(catcode_heads[to]);
226
catcode_heads[to] = copy_sa_tree(catcode_heads[from]);
227
catcode_valid[to] = 1;
230
void initex_cat_codes (int h) {
232
check_catcode_sizes(h);
233
destroy_sa_tree(catcode_heads[h]);
234
catcode_heads[h] = NULL;
235
set_cat_code(h,'\r',car_ret,1);
236
set_cat_code(h,' ',spacer,1);
237
set_cat_code(h,'\\',escape,1);
238
set_cat_code(h,'%',comment,1);
239
set_cat_code(h,127,invalid_char,1);
240
set_cat_code(h,0,ignore,1);
241
for (k='A';k<='Z';k++) {
242
set_cat_code(h,k,letter,1);
243
set_cat_code(h,k+'a'-'A',letter,1);
245
catcode_valid[h] = 1;
249
unsave_text_codes (quarterword grouplevel) {
250
unsavesfcodes(grouplevel);
251
unsaveuccodes(grouplevel);
252
unsavelccodes(grouplevel);
256
initialize_text_codes (void) {
259
initializecatcodes();
264
dump_text_codes (void) {
272
undump_text_codes (void) {