~ubuntu-branches/ubuntu/intrepid/luatex/intrepid

« 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: 2008-07-07 11:01:13 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707110113-1y7lam37zbbb7bbt
Tags: 0.28.0-1
* two new upstream releases, see the respective ANNOUCE files
* add luasocket license statement to debian/copyright
* activate the pdfluatex format
* prepare for latex based formats
  - add the ini files from TeX Live
  - add debian/formats file
  - adjust dh_installtex incantation
  the problem is that luatex dies when loading ukrhypmp.tex from 
  texlive-lang-cyrillic, but we don't want to conflict with it by now.
* policy 3.8.0, rename README.Debian-source to README.source, and add
  notes about quilt usage
* disable patch fix-pwd-inclusion (it was from svn)

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
 
 
 
1
/* textcodes.c
 
2
   
 
3
   Copyright 2006-2008 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/>. */
24
19
 
25
20
#include "luatex-api.h"
26
21
#include <ptexlib.h>
28
23
 
29
24
#include "managed-sa.h"
30
25
 
 
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 $";
 
28
 
31
29
#define LCCODESTACK  8
32
30
#define LCCODEDEFAULT 0
33
31
 
34
 
static sa_tree  lccode_head  = NULL;
 
32
static sa_tree lccode_head = NULL;
35
33
 
36
34
#define UCCODESTACK  8
37
35
#define UCCODEDEFAULT 0
38
36
 
39
 
static sa_tree  uccode_head  = NULL;
 
37
static sa_tree uccode_head = NULL;
40
38
 
41
39
#define SFCODESTACK 8
42
40
#define SFCODEDEFAULT 1000
43
41
 
44
 
static sa_tree  sfcode_head  = NULL;
 
42
static sa_tree sfcode_head = NULL;
45
43
 
46
44
#define CATCODESTACK 8
47
45
#define CATCODEDEFAULT 12
48
46
 
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();
 
47
void set_lc_code(integer n, halfword v, quarterword gl)
 
48
{
 
49
    set_sa_item(lccode_head, n, v, gl);
 
50
}
 
51
 
 
52
halfword get_lc_code(integer n)
 
53
{
 
54
    return (halfword) get_sa_item(lccode_head, n);
 
55
}
 
56
 
 
57
static void unsavelccodes(quarterword gl)
 
58
{
 
59
    restore_sa_stack(lccode_head, gl);
 
60
}
 
61
 
 
62
static void initializelccodes(void)
 
63
{
 
64
    lccode_head = new_sa_tree(LCCODESTACK, LCCODEDEFAULT);
 
65
}
 
66
 
 
67
static void dumplccodes(void)
 
68
{
 
69
    dump_sa_tree(lccode_head);
 
70
}
 
71
 
 
72
static void undumplccodes(void)
 
73
{
 
74
    lccode_head = undump_sa_tree();
 
75
}
 
76
 
 
77
void set_uc_code(integer n, halfword v, quarterword gl)
 
78
{
 
79
    set_sa_item(uccode_head, n, v, gl);
 
80
}
 
81
 
 
82
halfword get_uc_code(integer n)
 
83
{
 
84
    return (halfword) get_sa_item(uccode_head, n);
 
85
}
 
86
 
 
87
static void unsaveuccodes(quarterword gl)
 
88
{
 
89
    restore_sa_stack(uccode_head, gl);
 
90
}
 
91
 
 
92
static void initializeuccodes(void)
 
93
{
 
94
    uccode_head = new_sa_tree(UCCODESTACK, UCCODEDEFAULT);
 
95
}
 
96
 
 
97
static void dumpuccodes(void)
 
98
{
 
99
    dump_sa_tree(uccode_head);
 
100
}
 
101
 
 
102
static void undumpuccodes(void)
 
103
{
 
104
    uccode_head = undump_sa_tree();
 
105
}
 
106
 
 
107
void set_sf_code(integer n, halfword v, quarterword gl)
 
108
{
 
109
    set_sa_item(sfcode_head, n, v, gl);
 
110
}
 
111
 
 
112
halfword get_sf_code(integer n)
 
113
{
 
114
    return (halfword) get_sa_item(sfcode_head, n);
 
115
}
 
116
 
 
117
static void unsavesfcodes(quarterword gl)
 
118
{
 
119
    restore_sa_stack(sfcode_head, gl);
 
120
}
 
121
 
 
122
static void initializesfcodes(void)
 
123
{
 
124
    sfcode_head = new_sa_tree(SFCODESTACK, SFCODEDEFAULT);
 
125
}
 
126
 
 
127
static void dumpsfcodes(void)
 
128
{
 
129
    dump_sa_tree(sfcode_head);
 
130
}
 
131
 
 
132
static void undumpsfcodes(void)
 
133
{
 
134
    sfcode_head = undump_sa_tree();
119
135
}
120
136
 
121
137
 
123
139
static int catcode_max = 0;
124
140
static unsigned char *catcode_valid = NULL;
125
141
 
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(); 
 
142
void check_catcode_sizes(int h)
 
143
{
 
144
    int k;
 
145
    if (h < 0)
 
146
        uexit(1);
 
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;
 
153
        }
 
154
        catcode_max = h;
 
155
    }
 
156
}
 
157
 
 
158
void set_cat_code(integer h, integer n, halfword v, quarterword gl)
 
159
{
 
160
    check_catcode_sizes(h);
 
161
    if (catcode_heads[h] == NULL) {
 
162
        catcode_heads[h] = new_sa_tree(CATCODESTACK, CATCODEDEFAULT);
 
163
    }
 
164
    set_sa_item(catcode_heads[h], n, v, gl);
 
165
}
 
166
 
 
167
halfword get_cat_code(integer h, integer n)
 
168
{
 
169
    check_catcode_sizes(h);
 
170
    if (catcode_heads[h] == NULL) {
 
171
        catcode_heads[h] = new_sa_tree(CATCODESTACK, CATCODEDEFAULT);
 
172
    }
 
173
    return (halfword) get_sa_item(catcode_heads[h], n);
 
174
}
 
175
 
 
176
void unsave_cat_codes(integer h, quarterword gl)
 
177
{
 
178
    int k;
 
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);
 
183
    }
 
184
}
 
185
 
 
186
void clearcatcodestack(integer h)
 
187
{
 
188
    clear_sa_stack(catcode_heads[h]);
 
189
}
 
190
 
 
191
static void initializecatcodes(void)
 
192
{
 
193
    catcode_max = 0;
 
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);
 
198
}
 
199
 
 
200
static void dumpcatcodes(void)
 
201
{
 
202
    int k, total;
 
203
    dump_int(catcode_max);
 
204
    total = 0;
 
205
    for (k = 0; k <= catcode_max; k++) {
 
206
        if (catcode_valid[k]) {
 
207
            total++;
 
208
        }
 
209
    }
 
210
    dump_int(total);
 
211
    for (k = 0; k <= catcode_max; k++) {
 
212
        if (catcode_valid[k]) {
 
213
            dump_int(k);
 
214
            dump_sa_tree(catcode_heads[k]);
 
215
        }
 
216
    }
 
217
}
 
218
 
 
219
static void undumpcatcodes(void)
 
220
{
 
221
    int total, h, k;
 
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;
 
228
    }
 
229
    undump_int(total);
 
230
    for (k = 0; k < total; k++) {
 
231
        undump_int(h);
 
232
        catcode_heads[h] = undump_sa_tree();
 
233
        catcode_valid[h] = 1;
 
234
    }
 
235
}
 
236
 
 
237
int valid_catcode_table(int h)
 
238
{
 
239
    if (h <= catcode_max && h >= 0 && catcode_valid[h]) {
 
240
        return 1;
 
241
    }
 
242
    return 0;
 
243
}
 
244
 
 
245
void copy_cat_codes(int from, int to)
 
246
{
 
247
    if (from < 0 || from > catcode_max || catcode_valid[from] == 0) {
 
248
        uexit(1);
 
249
    }
 
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;
 
254
}
 
255
 
 
256
void initex_cat_codes(int h)
 
257
{
 
258
    int k;
 
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);
 
271
    }
209
272
    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
 
 
 
273
}
 
274
 
 
275
void unsave_text_codes(quarterword grouplevel)
 
276
{
 
277
    unsavesfcodes(grouplevel);
 
278
    unsaveuccodes(grouplevel);
 
279
    unsavelccodes(grouplevel);
 
280
}
 
281
 
 
282
void initialize_text_codes(void)
 
283
{
 
284
    initializesfcodes();
 
285
    initializeuccodes();
 
286
    initializecatcodes();
 
287
    initializelccodes();
 
288
}
 
289
 
 
290
void dump_text_codes(void)
 
291
{
 
292
    dumpsfcodes();
 
293
    dumpuccodes();
 
294
    dumplccodes();
 
295
    dumpcatcodes();
 
296
}
 
297
 
 
298
void undump_text_codes(void)
 
299
{
 
300
    undumpsfcodes();
 
301
    undumpuccodes();
 
302
    undumplccodes();
 
303
    undumpcatcodes();
 
304
}