~ubuntu-branches/ubuntu/precise/luatex/precise

« back to all changes in this revision

Viewing changes to src/texk/web2c/luatexdir/tex/textoken.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
 
/* $Id: textoken.c 1155 2008-04-14 07:53:21Z oneiros $ */
 
1
/* textoken.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/>. */
2
19
 
3
20
#include "luatex-api.h"
4
21
#include <ptexlib.h>
5
22
 
6
23
#include "tokens.h"
7
24
 
 
25
static const char _svn_version[] =
 
26
    "$Id: textoken.c 1310 2008-06-13 10:28:26Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/tags/beta-0.28.0/src/texk/web2c/luatexdir/tex/textoken.c $";
 
27
 
8
28
/* Integer parameters and other command-related defines. This needs it's own header file! */
9
29
 
10
30
#define end_line_char_code 48   /* character placed at the right end of the buffer */
53
73
 
54
74
extern void insert_vj_template(void);
55
75
 
56
 
#define do_get_cat_code(a) do {                                         \
57
 
    if (local_catcode_table)                                            \
58
 
      a=get_cat_code(line_catcode_table,cur_chr);                       \
59
 
    else                                                                \
60
 
      a=get_cat_code(cat_code_table,cur_chr);                           \
 
76
#define do_get_cat_code(a) do {                                         \
 
77
    if (local_catcode_table)                                            \
 
78
      a=get_cat_code(line_catcode_table,cur_chr);                       \
 
79
    else                                                                \
 
80
      a=get_cat_code(cat_code_table,cur_chr);                           \
61
81
  } while (0)
62
82
 
63
83
 
79
99
static int scan_control_sequence(void); /* below */
80
100
 
81
101
typedef enum { next_line_ok, next_line_return,
82
 
        next_line_restart } next_line_retval;
 
102
    next_line_restart
 
103
} next_line_retval;
83
104
 
84
105
static next_line_retval next_line(void);        /* below */
85
106
 
131
152
    return (val);
132
153
}
133
154
 
 
155
/* This is a very basic helper */
 
156
 
 
157
char *u2s(unsigned unic)
 
158
{
 
159
    char *buf = xmalloc(5);
 
160
    char *pt = buf;
 
161
        if ( unic<0x80 )
 
162
            *pt++ = unic;
 
163
        else if ( unic<0x800 ) {
 
164
            *pt++ = 0xc0 | (unic>>6);
 
165
            *pt++ = 0x80 | (unic&0x3f);
 
166
        } else if ( unic >= 0x110000 ) {
 
167
        *pt++ = unic - 0x110000;
 
168
        } else if ( unic < 0x10000 ) {
 
169
            *pt++ = 0xe0 | (unic>>12);
 
170
            *pt++ = 0x80 | ((unic>>6)&0x3f);
 
171
            *pt++ = 0x80 | (unic&0x3f);
 
172
        } else {
 
173
        int u,z,y,x;
 
174
            unsigned val = unic-0x10000;
 
175
            u = ((val&0xf0000)>>16)+1;
 
176
        z = (val&0x0f000)>>12;
 
177
        y = (val&0x00fc0)>>6;
 
178
        x = val&0x0003f;
 
179
            *pt++ = 0xf0 | (u>>2);
 
180
            *pt++ = 0x80 | ((u&3)<<4) | z;
 
181
            *pt++ = 0x80 | y;
 
182
            *pt++ = 0x80 | x;
 
183
        }
 
184
    *pt = '\0';
 
185
    return buf;
 
186
}
 
187
 
 
188
/* We can not return |undefined_control_sequence| under some conditions
 
189
 * (inside |shift_case|, for example). This needs thinking.
 
190
 */
 
191
 
 
192
halfword active_to_cs (int curchr, int force) 
 
193
{
 
194
    int nncs = no_new_control_sequence;
 
195
    str_number activetext;
 
196
    halfword curcs;
 
197
    char *a, *b;
 
198
    char *utfbytes = xmalloc(10);
 
199
    a = u2s (0xFFFF);
 
200
    b = u2s (curchr);
 
201
    utfbytes = strcpy(utfbytes,a);
 
202
    utfbytes = strcat(utfbytes,b);
 
203
    activetext = maketexstring(utfbytes);
 
204
    if (force) 
 
205
      no_new_control_sequence = false;
 
206
    curcs = string_lookup(activetext);
 
207
    no_new_control_sequence = nncs;
 
208
    flush_str(activetext);
 
209
    free (a); 
 
210
    free (b);
 
211
    free (utfbytes);
 
212
    return curcs;
 
213
}
 
214
 
134
215
static boolean get_next_file(void)
135
216
{
136
217
  SWITCH:
169
250
        case mid_line + active_char:
170
251
        case new_line + active_char:
171
252
        case skip_blanks + active_char:        /* @<Process an active-character  */
172
 
            cur_cs = cur_chr + active_base;
 
253
          cur_cs = active_to_cs(cur_chr, false);
173
254
            cur_cmd = eq_type(cur_cs);
174
255
            cur_chr = equiv(cur_cs);
175
256
            state = mid_line;
282
363
 
283
364
#define is_hex(a) ((a>='0'&&a<='9')||(a>='a'&&a<='f'))
284
365
 
285
 
#define add_nybble(a)   do {                                            \
286
 
    if (a<='9') cur_chr=(cur_chr<<4)+a-'0';                             \
287
 
    else        cur_chr=(cur_chr<<4)+a-'a'+10;                          \
288
 
  } while (0)
289
 
 
290
 
#define hex_to_cur_chr do {                                             \
291
 
    if (c<='9')  cur_chr=c-'0';                                         \
292
 
    else         cur_chr=c-'a'+10;                                      \
293
 
    add_nybble(cc);                                                     \
294
 
  } while (0)
295
 
 
296
 
#define four_hex_to_cur_chr do {                                        \
297
 
    hex_to_cur_chr;                                                     \
298
 
    add_nybble(ccc); add_nybble(cccc);                                  \
299
 
  } while (0)
300
 
 
301
 
#define five_hex_to_cur_chr  do {                                       \
302
 
    four_hex_to_cur_chr;                                                \
303
 
    add_nybble(ccccc);                                                  \
304
 
  } while (0)
305
 
 
306
 
#define six_hex_to_cur_chr do {                                         \
307
 
    five_hex_to_cur_chr;                                                \
308
 
    add_nybble(cccccc);                                                 \
 
366
#define add_nybble(a)   do {                                            \
 
367
    if (a<='9') cur_chr=(cur_chr<<4)+a-'0';                             \
 
368
    else        cur_chr=(cur_chr<<4)+a-'a'+10;                          \
 
369
  } while (0)
 
370
 
 
371
#define hex_to_cur_chr do {                                             \
 
372
    if (c<='9')  cur_chr=c-'0';                                         \
 
373
    else         cur_chr=c-'a'+10;                                      \
 
374
    add_nybble(cc);                                                     \
 
375
  } while (0)
 
376
 
 
377
#define four_hex_to_cur_chr do {                                        \
 
378
    hex_to_cur_chr;                                                     \
 
379
    add_nybble(ccc); add_nybble(cccc);                                  \
 
380
  } while (0)
 
381
 
 
382
#define five_hex_to_cur_chr  do {                                       \
 
383
    four_hex_to_cur_chr;                                                \
 
384
    add_nybble(ccccc);                                                  \
 
385
  } while (0)
 
386
 
 
387
#define six_hex_to_cur_chr do {                                         \
 
388
    five_hex_to_cur_chr;                                                \
 
389
    add_nybble(cccccc);                                                 \
309
390
  } while (0)
310
391
 
311
392