~ubuntu-branches/ubuntu/jaunty/luatex/jaunty

« back to all changes in this revision

Viewing changes to src/texk/web2c/luatexdir/textcodes.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2007-09-24 12:56:11 UTC
  • Revision ID: james.westby@ubuntu.com-20070924125611-a8ge689azbptxvla
Tags: upstream-0.11.2
ImportĀ upstreamĀ versionĀ 0.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* 
 
3
Copyright (c) 2006 Taco Hoekwater, <taco@elvenkind.com>
 
4
 
 
5
This file is part of LuaTeX.
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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
 
20
 
 
21
$Id $
 
22
*/
 
23
 
 
24
 
 
25
#include "luatex-api.h"
 
26
#include <ptexlib.h>
 
27
#include <stdarg.h>
 
28
 
 
29
#include "managed-sa.h"
 
30
 
 
31
#define LCCODESTACK  8
 
32
#define LCCODEDEFAULT 0
 
33
 
 
34
static sa_tree  lccode_head  = NULL;
 
35
 
 
36
#define UCCODESTACK  8
 
37
#define UCCODEDEFAULT 0
 
38
 
 
39
static sa_tree  uccode_head  = NULL;
 
40
 
 
41
#define SFCODESTACK 8
 
42
#define SFCODEDEFAULT 1000
 
43
 
 
44
static sa_tree  sfcode_head  = NULL;
 
45
 
 
46
#define CATCODESTACK 8
 
47
#define CATCODEDEFAULT 12
 
48
 
 
49
void  set_lc_code (integer n, halfword v, quarterword gl) {
 
50
  set_sa_item(lccode_head,n,v,gl);
 
51
}
 
52
 
 
53
halfword get_lc_code (integer n) {
 
54
  return (halfword)get_sa_item(lccode_head,n);
 
55
}
 
56
 
 
57
static void unsavelccodes (quarterword gl) {
 
58
  restore_sa_stack(lccode_head,gl);
 
59
}
 
60
 
 
61
static void initializelccodes (void) {
 
62
  lccode_head = new_sa_tree(LCCODESTACK,LCCODEDEFAULT);
 
63
}
 
64
 
 
65
static void dumplccodes (void) {
 
66
  dump_sa_tree(lccode_head);
 
67
}
 
68
 
 
69
static void undumplccodes (void) {
 
70
  lccode_head  = undump_sa_tree();
 
71
}
 
72
 
 
73
void  set_uc_code (integer n, halfword v, quarterword gl) {
 
74
  set_sa_item(uccode_head,n,v,gl);
 
75
}
 
76
 
 
77
halfword get_uc_code (integer n) {
 
78
  return (halfword)get_sa_item(uccode_head,n);
 
79
}
 
80
 
 
81
static void unsaveuccodes (quarterword gl) {
 
82
  restore_sa_stack(uccode_head,gl);
 
83
}
 
84
 
 
85
static void initializeuccodes (void) {
 
86
  uccode_head = new_sa_tree(UCCODESTACK,UCCODEDEFAULT);
 
87
}
 
88
 
 
89
static void dumpuccodes (void) {
 
90
  dump_sa_tree(uccode_head);
 
91
}
 
92
 
 
93
static void undumpuccodes (void) {
 
94
  uccode_head  = undump_sa_tree();
 
95
}
 
96
 
 
97
void  set_sf_code (integer n, halfword v, quarterword gl) {
 
98
  set_sa_item(sfcode_head,n,v,gl);
 
99
}
 
100
 
 
101
halfword get_sf_code (integer n) {
 
102
  return (halfword)get_sa_item(sfcode_head,n);
 
103
}
 
104
 
 
105
static void unsavesfcodes (quarterword gl) {
 
106
  restore_sa_stack(sfcode_head,gl);
 
107
}
 
108
 
 
109
static void initializesfcodes (void) {
 
110
  sfcode_head = new_sa_tree(SFCODESTACK,SFCODEDEFAULT);
 
111
}
 
112
 
 
113
static void dumpsfcodes (void) {
 
114
  dump_sa_tree(sfcode_head);
 
115
}
 
116
 
 
117
static void undumpsfcodes (void) {
 
118
  sfcode_head  = undump_sa_tree();
 
119
}
 
120
 
 
121
 
 
122
static sa_tree *catcode_heads = NULL;
 
123
static int catcode_max = 0;
 
124
static unsigned char *catcode_valid = NULL;
 
125
 
 
126
void check_catcode_sizes (int h) {
 
127
  int k;
 
128
  if (h < 0)
 
129
    uexit(1);
 
130
  if (h>catcode_max) {
 
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;
 
136
        }
 
137
        catcode_max = h;
 
138
  }
 
139
}
 
140
 
 
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);
 
145
  }
 
146
  set_sa_item(catcode_heads[h],n,v,gl);
 
147
}
 
148
 
 
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);
 
153
  }
 
154
  return (halfword)get_sa_item(catcode_heads[h],n);
 
155
}
 
156
 
 
157
void unsave_cat_codes (integer h, quarterword gl) {
 
158
  int k;
 
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);
 
163
  }
 
164
}
 
165
 
 
166
void clearcatcodestack(integer h) {
 
167
  clear_sa_stack(catcode_heads[h]);
 
168
}
 
169
 
 
170
static void initializecatcodes (void) {
 
171
  catcode_max   = 0;
 
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);
 
176
}
 
177
 
 
178
static void dumpcatcodes (void) {
 
179
  int k,total;
 
180
  dump_int(catcode_max);
 
181
  total = 0;
 
182
  for (k=0;k<=catcode_max;k++) {
 
183
    if (catcode_valid[k]) {
 
184
      total++;
 
185
    }
 
186
  }
 
187
  dump_int(total);
 
188
  for (k=0;k<=catcode_max;k++) {
 
189
    if (catcode_valid[k]) {
 
190
      dump_int(k);
 
191
      dump_sa_tree(catcode_heads[k]);
 
192
    }
 
193
  }
 
194
}
 
195
 
 
196
static void undumpcatcodes (void) {
 
197
  int total,h,k;
 
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;
 
203
    catcode_valid[k]=0;
 
204
  }
 
205
  undump_int(total);
 
206
  for (k=0;k<total;k++) {
 
207
    undump_int(h);
 
208
    catcode_heads[h] = undump_sa_tree(); 
 
209
    catcode_valid[h] = 1;
 
210
  }
 
211
}
 
212
 
 
213
int valid_catcode_table (int h) {
 
214
  if (h<=catcode_max && h>=0 && catcode_valid[h]) {
 
215
    return 1;
 
216
  }
 
217
  return 0;
 
218
}
 
219
 
 
220
void copy_cat_codes (int from, int to) {
 
221
  if (from<0 || from>catcode_max || catcode_valid[from] == 0) {
 
222
        uexit(1);
 
223
  }
 
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;
 
228
}
 
229
 
 
230
void initex_cat_codes (int h) {
 
231
  int k;
 
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);
 
244
  }
 
245
  catcode_valid[h] = 1;
 
246
}
 
247
 
 
248
void 
 
249
unsave_text_codes (quarterword grouplevel) {
 
250
  unsavesfcodes(grouplevel);
 
251
  unsaveuccodes(grouplevel);
 
252
  unsavelccodes(grouplevel);
 
253
}
 
254
 
 
255
void 
 
256
initialize_text_codes (void) {
 
257
  initializesfcodes();
 
258
  initializeuccodes();
 
259
  initializecatcodes();
 
260
  initializelccodes();
 
261
}
 
262
 
 
263
void 
 
264
dump_text_codes (void) {
 
265
  dumpsfcodes();
 
266
  dumpuccodes();
 
267
  dumplccodes();
 
268
  dumpcatcodes();
 
269
}
 
270
 
 
271
void 
 
272
undump_text_codes (void) {
 
273
  undumpsfcodes();
 
274
  undumpuccodes();
 
275
  undumplccodes();
 
276
  undumpcatcodes();
 
277
}
 
278