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
3
Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
5
This file is part of LuaTeX.
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.
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.
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/>. */
25
20
#include "luatex-api.h"
26
21
#include <ptexlib.h>
29
24
#include "managed-sa.h"
26
static const char __svn_version[] =
27
"$Id: textcodes.c 1230 2008-05-03 11:11:32Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/tags/beta-0.28.0/src/texk/web2c/luatexdir/textcodes.c $";
31
29
#define LCCODESTACK 8
32
30
#define LCCODEDEFAULT 0
34
static sa_tree lccode_head = NULL;
32
static sa_tree lccode_head = NULL;
36
34
#define UCCODESTACK 8
37
35
#define UCCODEDEFAULT 0
39
static sa_tree uccode_head = NULL;
37
static sa_tree uccode_head = NULL;
41
39
#define SFCODESTACK 8
42
40
#define SFCODEDEFAULT 1000
44
static sa_tree sfcode_head = NULL;
42
static sa_tree sfcode_head = NULL;
46
44
#define CATCODESTACK 8
47
45
#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();
47
void set_lc_code(integer n, halfword v, quarterword gl)
49
set_sa_item(lccode_head, n, v, gl);
52
halfword get_lc_code(integer n)
54
return (halfword) get_sa_item(lccode_head, n);
57
static void unsavelccodes(quarterword gl)
59
restore_sa_stack(lccode_head, gl);
62
static void initializelccodes(void)
64
lccode_head = new_sa_tree(LCCODESTACK, LCCODEDEFAULT);
67
static void dumplccodes(void)
69
dump_sa_tree(lccode_head);
72
static void undumplccodes(void)
74
lccode_head = undump_sa_tree();
77
void set_uc_code(integer n, halfword v, quarterword gl)
79
set_sa_item(uccode_head, n, v, gl);
82
halfword get_uc_code(integer n)
84
return (halfword) get_sa_item(uccode_head, n);
87
static void unsaveuccodes(quarterword gl)
89
restore_sa_stack(uccode_head, gl);
92
static void initializeuccodes(void)
94
uccode_head = new_sa_tree(UCCODESTACK, UCCODEDEFAULT);
97
static void dumpuccodes(void)
99
dump_sa_tree(uccode_head);
102
static void undumpuccodes(void)
104
uccode_head = undump_sa_tree();
107
void set_sf_code(integer n, halfword v, quarterword gl)
109
set_sa_item(sfcode_head, n, v, gl);
112
halfword get_sf_code(integer n)
114
return (halfword) get_sa_item(sfcode_head, n);
117
static void unsavesfcodes(quarterword gl)
119
restore_sa_stack(sfcode_head, gl);
122
static void initializesfcodes(void)
124
sfcode_head = new_sa_tree(SFCODESTACK, SFCODEDEFAULT);
127
static void dumpsfcodes(void)
129
dump_sa_tree(sfcode_head);
132
static void undumpsfcodes(void)
134
sfcode_head = undump_sa_tree();
123
139
static int catcode_max = 0;
124
140
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();
142
void check_catcode_sizes(int h)
147
if (h > catcode_max) {
148
catcode_heads = Mxrealloc_array(catcode_heads, sa_tree, (h + 1));
149
catcode_valid = Mxrealloc_array(catcode_valid, unsigned char, (h + 1));
150
for (k = (catcode_max + 1); k <= h; k++) {
151
catcode_heads[k] = NULL;
152
catcode_valid[k] = 0;
158
void set_cat_code(integer h, integer n, halfword v, quarterword gl)
160
check_catcode_sizes(h);
161
if (catcode_heads[h] == NULL) {
162
catcode_heads[h] = new_sa_tree(CATCODESTACK, CATCODEDEFAULT);
164
set_sa_item(catcode_heads[h], n, v, gl);
167
halfword get_cat_code(integer h, integer n)
169
check_catcode_sizes(h);
170
if (catcode_heads[h] == NULL) {
171
catcode_heads[h] = new_sa_tree(CATCODESTACK, CATCODEDEFAULT);
173
return (halfword) get_sa_item(catcode_heads[h], n);
176
void unsave_cat_codes(integer h, quarterword gl)
179
check_catcode_sizes(h);
180
for (k = 0; k <= catcode_max; k++) {
181
if (catcode_heads[k] != NULL)
182
restore_sa_stack(catcode_heads[k], gl);
186
void clearcatcodestack(integer h)
188
clear_sa_stack(catcode_heads[h]);
191
static void initializecatcodes(void)
194
catcode_heads = Mxmalloc_array(sa_tree, (catcode_max + 1));
195
catcode_valid = Mxmalloc_array(unsigned char, (catcode_max + 1));
196
catcode_valid[0] = 1;
197
catcode_heads[0] = new_sa_tree(CATCODESTACK, CATCODEDEFAULT);
200
static void dumpcatcodes(void)
203
dump_int(catcode_max);
205
for (k = 0; k <= catcode_max; k++) {
206
if (catcode_valid[k]) {
211
for (k = 0; k <= catcode_max; k++) {
212
if (catcode_valid[k]) {
214
dump_sa_tree(catcode_heads[k]);
219
static void undumpcatcodes(void)
222
undump_int(catcode_max);
223
catcode_heads = Mxmalloc_array(sa_tree, (catcode_max + 1));
224
catcode_valid = Mxmalloc_array(unsigned char, (catcode_max + 1));
225
for (k = 0; k <= catcode_max; k++) {
226
catcode_heads[k] = NULL;
227
catcode_valid[k] = 0;
230
for (k = 0; k < total; k++) {
232
catcode_heads[h] = undump_sa_tree();
233
catcode_valid[h] = 1;
237
int valid_catcode_table(int h)
239
if (h <= catcode_max && h >= 0 && catcode_valid[h]) {
245
void copy_cat_codes(int from, int to)
247
if (from < 0 || from > catcode_max || catcode_valid[from] == 0) {
250
check_catcode_sizes(to);
251
destroy_sa_tree(catcode_heads[to]);
252
catcode_heads[to] = copy_sa_tree(catcode_heads[from]);
253
catcode_valid[to] = 1;
256
void initex_cat_codes(int h)
259
check_catcode_sizes(h);
260
destroy_sa_tree(catcode_heads[h]);
261
catcode_heads[h] = NULL;
262
set_cat_code(h, '\r', car_ret, 1);
263
set_cat_code(h, ' ', spacer, 1);
264
set_cat_code(h, '\\', escape, 1);
265
set_cat_code(h, '%', comment, 1);
266
set_cat_code(h, 127, invalid_char, 1);
267
set_cat_code(h, 0, ignore, 1);
268
for (k = 'A'; k <= 'Z'; k++) {
269
set_cat_code(h, k, letter, 1);
270
set_cat_code(h, k + 'a' - 'A', letter, 1);
209
272
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) {
275
void unsave_text_codes(quarterword grouplevel)
277
unsavesfcodes(grouplevel);
278
unsaveuccodes(grouplevel);
279
unsavelccodes(grouplevel);
282
void initialize_text_codes(void)
286
initializecatcodes();
290
void dump_text_codes(void)
298
void undump_text_codes(void)