~ubuntu-branches/ubuntu/edgy/mcpp/edgy

« back to all changes in this revision

Viewing changes to src/mbchar.c

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2005-04-16 15:58:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050416155816-q9a9ipx724qvf3le
Tags: 2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*-
2
 
 * Copyright (c) 1998, 2002-2004 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>
 
2
 * Copyright (c) 1998, 2002-2005 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>
3
3
 * All rights reserved.
4
4
 *
5
5
 * Some parts of this code are derived from the public domain software
44
44
 */
45
45
 
46
46
/*
 
47
 * MCPP Version 2.5
 
48
 * 2005/03      kmatsui
 
49
 *      Changed type[] according to the change of magic characters assignment.
 
50
 *      Absorbed POST_STANDARD into STANDARD and OLD_PREPROCESSOR into
 
51
 *          PRE_STANDARD.
 
52
 */
 
53
 
 
54
/*
47
55
 * Character handling and multi-byte character handling routines are
48
56
 * placed here.
49
57
 */
50
58
 
51
59
#if PREPROCESSED
52
 
#include    "cpp.H"
 
60
#include    "mcpp.H"
53
61
#else
54
62
#include    "system.H"
55
63
#include    "internal.H"
58
66
/*
59
67
 * Tables of character types and multi-byte character types.
60
68
 * These tables must be rewritten for a non-Ascii machine.
 
69
 *
 
70
 * Some of these character attributes will be overwritten by
 
71
 *      execution time option '-@post' or '-@old'.
61
72
 */
62
73
 
63
74
#if DOLLAR_IN_NAME
78
89
#define PNC2    (PUNC| MB2)
79
90
#endif
80
91
 
81
 
const char      type[ UCHARMAX + 1] = {
 
92
char        type[ UCHARMAX + 1] = {
82
93
 
83
94
/* Character type codes */
84
95
/*   0,     1,     2,     3,     4,     5,     6,     7,                    */
87
98
   000,   000,   000,   000,   000,   000,   000,   000,    /* 00           */
88
99
   000,   SPA,   SPA,   SPA,   SPA,   SPA,   000,   000,    /* 08           */
89
100
   000,   000,   000,   000,   000,   000,   000,   000,    /* 10           */
90
 
   000,   000,   000,   000,   LET,   000,   000,   SPA,    /* 18           */
 
101
#if MODE == STANDARD
 
102
   000,   LET,   LET,   000,   000,   000,   000,   SPA,    /* 18           */
 
103
#else
 
104
   000,   000,   000,   000,   000,   000,   000,   000,    /* 18           */
 
105
#endif
91
106
   SPA,   PUNC,  QUO,   PUNC,  DOL,   PUNC,  PUNC,  QUO,    /* 20  !"#$%&'  */
92
107
   PUNC,  PUNC,  PUNC,  PUNC,  PUNC,  PUNC,  DOT,   PUNC,   /* 28 ()*+,-./  */
93
108
   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,    /* 30 01234567  */
177
192
#else   /* SYSTEM != SYS_MSDOS  */
178
193
/* For 32-bit or bigger systems.    */
179
194
 
180
 
const short   * type;       /* Pointer to one of the following type_*[].    */
 
195
short *     type;       /* Pointer to one of the following type_*[].    */
181
196
 
182
197
#define EJ1     0x100   /* 1st byte of EUC_JP   */
183
198
#define EJ2     0x200   /* 2nd byte of EUC_JP   */
192
207
#define EU12    (EJ12 | GB12 | KS12)
193
208
    /* 1st or 2nd byte of EUC_JP, GB2312 or KSC5601 */
194
209
 
195
 
const short     type_euc[ UCHARMAX + 1] = {
 
210
static short    type_euc[ UCHARMAX + 1] = {
196
211
/*
197
212
 * For EUC_JP, GB2312, KSC5601 or other similar multi-byte char encodings.
198
213
 */
204
219
   000,   000,   000,   000,   000,   000,   000,   000,    /* 00           */
205
220
   000,   SPA,   SPA,   SPA,   SPA,   SPA,   000,   000,    /* 08           */
206
221
   000,   000,   000,   000,   000,   000,   000,   000,    /* 10           */
207
 
   000,   000,   000,   000,   LET,   000,   000,   SPA,    /* 18           */
 
222
#if MODE == STANDARD
 
223
   000,   LET,   LET,   000,   000,   000,   000,   SPA,    /* 18           */
 
224
#else
 
225
   000,   000,   000,   000,   000,   000,   000,   000,    /* 18           */
 
226
#endif
208
227
   SPA,   PUNC,  QUO,   PUNC,  DOL,   PUNC,  PUNC,  QUO,    /* 20  !"#$%&'  */
209
228
   PUNC,  PUNC,  PUNC,  PUNC,  PUNC,  PUNC,  DOT,   PUNC,   /* 28 ()*+,-./  */
210
229
   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,    /* 30 01234567  */
237
256
   EU12,  EU12,  EU12,  EU12,  EU12,  EU12,  EU12,  000,    /*   F8 .. FF   */
238
257
};
239
258
 
240
 
const short     type_bsl[ UCHARMAX + 1] = {
 
259
static short    type_bsl[ UCHARMAX + 1] = {
241
260
/*
242
261
 * For SJIS, BIGFIVE or other similar encodings which may have '\\' value as
243
262
 * the second byte of multi-byte character.
264
283
   000,   000,   000,   000,   000,   000,   000,   000,    /* 00           */
265
284
   000,   SPA,   SPA,   SPA,   SPA,   SPA,   000,   000,    /* 08           */
266
285
   000,   000,   000,   000,   000,   000,   000,   000,    /* 10           */
267
 
   000,   000,   000,   000,   LET,   000,   000,   SPA,    /* 18           */
 
286
#if MODE == STANDARD
 
287
   000,   LET,   LET,   000,   000,   000,   000,   SPA,    /* 18           */
 
288
#else
 
289
   000,   000,   000,   000,   000,   000,   000,   000,    /* 18           */
 
290
#endif
268
291
   SPA,   PUNC,  QUO,   PUNC,  DOL,   PUNC,  PUNC,  QUO,    /* 20  !"#$%&'  */
269
292
   PUNC,  PUNC,  PUNC,  PUNC,  PUNC,  PUNC,  DOT,   PUNC,   /* 28 ()*+,-./  */
270
293
   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,    /* 30 01234567  */
305
328
#define IS2     0x80    /* 2nd byte of shift-sequence   */
306
329
#define IS3     0x100   /* 3rd byte of shift-sequence   */
307
330
#define IS4     0x200   /* 4th byte of shift-sequence   */
308
 
#define IJ1     0x400   /* 1st byte of ISO-2022-JP (ISO-2022-JP1)   */
309
 
#define IJ2     0x800   /* 2nd byte of ISO-2022-JP (ISO-2022-JP1)   */
310
 
 
311
 
#define IJ12    (IJ1 | IJ2)
312
 
 
313
 
#define PI12    (PUNC | IJ12)
314
 
#define QI12    (QUO | IJ12)
315
 
#define DT12    (DOT | IJ12)
316
 
#define DG12    (DIG | IJ12)
317
 
#define LI12    (LET | IJ12)
318
 
 
319
 
#define DL12S2  (DOL | IJ12 | IS2)
320
 
#define P12S23  (PI12 | IS2 | IS3)
321
 
#define L12S3   (LI12 | IS3)
322
 
#define L12S4   (LI12 | IS4)
323
 
 
324
 
const short     type_iso2022_jp[ UCHARMAX + 1] = {
 
331
#define IJP     0x400   /* 1st or 2nd byte of ISO-2022-JP (ISO-2022-JP1)    */
 
332
 
 
333
#define PIJP    (PUNC | IJP)
 
334
#define QIJP    (QUO | IJP)
 
335
#define DTJP    (DOT | IJP)
 
336
#define DGJP    (DIG | IJP)
 
337
#define LIJP    (LET | IJP)
 
338
 
 
339
#define DLJPS2  (DOL | IJP | IS2)
 
340
#define PJPS23  (PIJP | IS2 | IS3)
 
341
#define LJPS3   (LIJP | IS3)
 
342
#define LJPS4   (LIJP | IS4)
 
343
 
 
344
static short    type_iso2022_jp[ UCHARMAX + 1] = {
325
345
 
326
346
/* Character type codes */
327
347
/*   0,     1,     2,     3,     4,     5,     6,     7,                    */
330
350
   000,   000,   000,   000,   000,   000,   000,   000,    /* 00           */
331
351
   000,   SPA,   SPA,   SPA,   SPA,   SPA,   000,   000,    /* 08           */
332
352
   000,   000,   000,   000,   000,   000,   000,   000,    /* 10           */
333
 
   000,   000,   000,   IS1,   LET,   000,   000,   SPA,    /* 18           */
334
 
   SPA,   PI12,  QI12,  PI12,  DL12S2,PI12,  PI12,  QI12,   /* 20  !"#$%&'  */
335
 
   P12S23,PI12,  PI12,  PI12,  PI12,  PI12,  DT12,  PI12,   /* 28 ()*+,-./  */
336
 
   DG12,  DG12,  DG12,  DG12,  DG12,  DG12,  DG12,  DG12,   /* 30 01234567  */
337
 
   DG12,  DG12,  PI12,  PI12,  PI12,  PI12,  PI12,  PI12,   /* 38 89:;<=>?  */
 
353
#if MODE == STANDARD
 
354
   000,   LET,   LET,   IS1,   000,   000,   000,   SPA,    /* 18           */
 
355
#else
 
356
   000,   000,   000,   000,   000,   000,   000,   000,    /* 18           */
 
357
#endif
 
358
   SPA,   PIJP,  QIJP,  PIJP,  DLJPS2,PIJP,  PIJP,  QIJP,   /* 20  !"#$%&'  */
 
359
   PJPS23,PIJP,  PIJP,  PIJP,  PIJP,  PIJP,  DTJP,  PIJP,   /* 28 ()*+,-./  */
 
360
   DGJP,  DGJP,  DGJP,  DGJP,  DGJP,  DGJP,  DGJP,  DGJP,   /* 30 01234567  */
 
361
   DGJP,  DGJP,  PIJP,  PIJP,  PIJP,  PIJP,  PIJP,  PIJP,   /* 38 89:;<=>?  */
338
362
 
339
 
   IJ12,  LI12,  L12S3, LI12,  L12S4, LI12,  LI12,  LI12,   /* 40 @ABCDEFG  */
340
 
   LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,   /* 48 HIJKLMNO  */
341
 
   LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,   /* 50 PQRSTUVW  */
342
 
   LI12,  LI12,  LI12,  PI12,  IJ12,  PI12,  PI12,  LI12,   /* 58 XYZ[\]^_  */
343
 
   IJ12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,   /* 60 `abcdefg  */
344
 
   LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,   /* 68 hijklmno  */
345
 
   LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,  LI12,   /* 70 pqrstuvw  */
346
 
   LI12,  LI12,  LI12,  PI12,  PI12,  PI12,  PI12,  000,    /* 78 xyz{|}~   */
 
363
   IJP,   LIJP,  LJPS3, LIJP,  LJPS4, LIJP,  LIJP,  LIJP,   /* 40 @ABCDEFG  */
 
364
   LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,   /* 48 HIJKLMNO  */
 
365
   LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,   /* 50 PQRSTUVW  */
 
366
   LIJP,  LIJP,  LIJP,  PIJP,  IJP,   PIJP,  PIJP,  LIJP,   /* 58 XYZ[\]^_  */
 
367
   IJP,   LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,   /* 60 `abcdefg  */
 
368
   LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,   /* 68 hijklmno  */
 
369
   LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,  LIJP,   /* 70 pqrstuvw  */
 
370
   LIJP,  LIJP,  LIJP,  PIJP,  PIJP,  PIJP,  PIJP,  000,    /* 78 xyz{|}~   */
347
371
    /* the rests are 0 cleared  */
348
372
};
349
373
 
362
386
#define UT223   (U2_2 | U3_2 | U3_3)
363
387
/* 2nd byte of 2-byte encoding, or 2nd or 3rd byte of 3-byte encoding   */
364
388
 
365
 
const short     type_utf8[ UCHARMAX + 1] = {
 
389
static short    type_utf8[ UCHARMAX + 1] = {
366
390
 
367
391
/* Character type codes */
368
392
/*   0,     1,     2,     3,     4,     5,     6,     7,                    */
371
395
   000,   000,   000,   000,   000,   000,   000,   000,    /* 00           */
372
396
   000,   SPA,   SPA,   SPA,   SPA,   SPA,   000,   000,    /* 08           */
373
397
   000,   000,   000,   000,   000,   000,   000,   000,    /* 10           */
374
 
   000,   000,   000,   000,   LET,   000,   000,   SPA,    /* 18           */
 
398
#if MODE == STANDARD
 
399
   000,   LET,   LET,   000,   000,   000,   000,   SPA,    /* 18           */
 
400
#else
 
401
   000,   000,   000,   000,   000,   000,   000,   000,    /* 18           */
 
402
#endif
375
403
   SPA,   PUNC,  QUO,   PUNC,  DOL,   PUNC,  PUNC,  QUO,    /* 20  !"#$%&'  */
376
404
   PUNC,  PUNC,  PUNC,  PUNC,  PUNC,  PUNC,  DOT,   PUNC,   /* 28 ()*+,-./  */
377
405
   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,   DIG,    /* 30 01234567  */
407
435
#define SETLOCALE       2       /* #pragma setlocale (not __setlocale)  */
408
436
 
409
437
#define NUM_ENCODING    8
410
 
#define NUM_ALIAS       9
 
438
#define NUM_ALIAS       7
411
439
 
412
440
/*
413
441
 * Names of encoding recognized.  Table for search_encoding().
414
442
 * Note: GNU C documents that LANG=C-EUCJP (C-SJIS, C-JIS) is effective,
415
443
 * though this feature is not fully enabled in GNU C.
416
444
 */
417
 
static char *   encoding_name[ NUM_ENCODING][ NUM_ALIAS] = {
 
445
static const char * const   encoding_name[ NUM_ENCODING][ NUM_ALIAS] = {
418
446
    /* normalized LANG, Visual C full, Visual C short
419
447
        , miscellaneous  */
420
448
    { "c",        "english",    "c"
421
 
        , "c",      "en",   "latin",    "iso8859",  "",     "" },
 
449
        , "c",      "en",   "latin",    "iso8859"},
422
450
    { "ceucjp",  "",     ""
423
 
        , "eucjp",  "euc",  "ujis",     "jajpeucjp",    "",     "" },
 
451
        , "eucjp",  "euc",  "ujis",     ""},
424
452
    { "",         "chinesesimplified",  "chs"
425
 
        , "gb2312", "cngb",     "euccn",    "zhcn",     "zhcneuccn",    "" },
 
453
        , "gb2312", "cngb",     "euccn",    ""},
426
454
    { "",         "korean",   "kor"
427
 
        , "ksc5601",    "ksx1001",  "wansung",  "euckr",    "kokr", "kokreuckr" },
 
455
        , "ksc5601",    "ksx1001",  "wansung",  "euckr"},
428
456
    { "csjis",    "japanese", "jpn"
429
 
        , "sjis",   "shiftjis", "mskanji",  "jajpsjis", "",     "" },
 
457
        , "sjis",   "shiftjis", "mskanji",  ""},
430
458
    { "",         "chinesetraditional", "cht"
431
 
        , "bigfive",    "big5", "cnbig5",   "euctw",    "zhtw", "zhtweuctw" },
 
459
        , "bigfive",    "big5", "cnbig5",   "euctw"},
432
460
    { "cjis",     "",     ""
433
 
        , "iso2022jp",  "iso2022jp1",   "jis",  "jajpjis",  "",     "" },
 
461
        , "iso2022jp",  "iso2022jp1",   "jis",  ""},
434
462
    { "",         "",     ""
435
 
        , "utf8",   "utf",      "",     "",     "",     "" },
 
463
        , "utf8",   "utf",      "",     ""},
436
464
};
437
465
 
438
466
#endif  /* SYSTEM != SYS_MSDOS  */
443
471
 
444
472
static size_t   mb_read_2byte( int c1, char ** in_pp, char ** out_pp);
445
473
#if SYSTEM != SYS_MSDOS
446
 
static char *   search_encoding( char * norm, int alias);
447
 
static void     strip_bar( char * norm);
 
474
static const char *     search_encoding( char * norm, int alias);
 
475
static void     strip_bar( char * string);
448
476
static size_t   mb_read_iso2022_jp( int c1, char ** in_pp, char ** out_pp);
449
477
static size_t   mb_read_utf8( int c1, char ** in_pp, char ** out_pp);
450
478
#endif
465
493
 
466
494
#define NAMLEN  20
467
495
 
468
 
char *
 
496
const char *
469
497
#if PROTO
470
498
set_encoding( char * name, char * env, int pragma)
471
499
#else
483
511
            = "Unknown encoding: %s%.0ld%.0s";          /* _W1_ */
484
512
    const char *    too_long
485
513
            = "Too long encoding name: %s%.0ld%.0s";    /* _E_  */
 
514
    const char *    loc = "";
486
515
    int     alias;
487
 
    char *  loc = "";
488
516
    char    norm[ NAMLEN];
489
 
                /* Normalized name (stripped '_', '-', '.' and lowered  */
 
517
            /*
 
518
             * Normalized name (removed 'xxxxx.', stripped '_', '-', '.'
 
519
             * and lowered.
 
520
             */
490
521
 
491
522
    if (strlen( name) >= NAMLEN) {
492
523
        if ((env || pragma) && (warn_level & 1)) {
497
528
        }
498
529
    }
499
530
    strcpy( norm, name);
 
531
    if (norm[ 5] == '.')
 
532
        memmove( norm, norm + 5, strlen( norm + 5) + 1);
 
533
        /* Remove initial 'xxxxx.' as 'ja_JP.', 'en_US.' or any other   */
500
534
    conv_case( norm, norm + strlen( norm), LOWER);
501
535
    strip_bar( norm);
502
536
 
503
537
    if (strlen( name) == 0) {                       /* ""       */
504
538
        mbchar = MBCHAR;    /* Restore to the default encoding  */
505
 
    } else if (memcmp( norm, "iso8859", 7) == 0     /* iso8895* */
 
539
    } else if (memcmp( norm, "iso8859", 7) == 0     /* iso8859* */
506
540
            || memcmp( norm, "latin", 5) == 0       /* latin*   */
507
541
            || memcmp( norm, "en", 2) == 0) {       /* en*      */
508
542
        mbchar = 0;                 /* No multi-byte character  */
509
 
    } else if (str_eq( norm + strlen( norm) - 4, "utf8")) {
510
 
        mbchar = UTF8;                              /* *utf8    */
511
543
    } else {
512
544
        alias = 3;
513
545
#if COMPILER == GNUC
533
565
    return  loc;
534
566
}
535
567
 
536
 
static char *
 
568
static const char *
537
569
#if PROTO
538
570
search_encoding( char * norm, int alias)
539
571
#else
542
574
    int     alias;          /* The number of alias to start searching   */
543
575
#endif
544
576
{
545
 
    char *  loc;
546
 
    int     lo, al;
 
577
    const char *    loc;
 
578
    int             lo, al;
547
579
 
548
580
    for (lo = 0; lo < NUM_ENCODING; lo++) {
549
581
        for (al = alias ; al < NUM_ALIAS; al++) {
615
647
     * may contain the byte of value 0x5c.
616
648
     */
617
649
    switch (mbchar) {
618
 
    case (0)    :
619
 
    case (EUC_JP)   :
620
 
    case (GB2312)   :
621
 
    case (KSC5601)  :
 
650
    case 0      :
 
651
    case EUC_JP     :
 
652
    case GB2312     :
 
653
    case KSC5601    :
622
654
        type = type_euc;
623
655
        bsl_in_mbchar = FALSE;
624
656
        mb_read = mb_read_2byte;
625
657
        break;
626
 
    case (SJIS) :
627
 
    case (BIGFIVE)  :
 
658
    case SJIS   :
 
659
    case BIGFIVE    :
628
660
        type = type_bsl;
629
661
        bsl_in_mbchar = TRUE;
630
662
        mb_read = mb_read_2byte;
631
663
        break;
632
 
    case (ISO2022_JP)    :
 
664
    case ISO2022_JP :
633
665
        type = type_iso2022_jp;
634
666
        bsl_in_mbchar = TRUE;
635
667
        mb_read = mb_read_iso2022_jp;
636
668
        break;
637
 
    case (UTF8) :
 
669
    case UTF8   :
638
670
        type = type_utf8;
639
671
        bsl_in_mbchar = FALSE;
640
672
        mb_read = mb_read_utf8;
644
676
 
645
677
    /* Set the bit patterns for character classification.   */
646
678
    switch (mbchar) {
647
 
    case (0)    :
 
679
    case 0      :
648
680
        mbstart = 0;
649
681
        mbmask = ~0;
650
682
        break;
655
687
        mb2 = MB2;
656
688
        break;
657
689
#else
658
 
    case (EUC_JP)   :
 
690
    case EUC_JP :
659
691
        mbstart = EJ1;
660
692
        mbmask = ~EU12;
661
693
        mb2 = EJ2;
662
694
        break;
663
 
    case (GB2312)   :
 
695
    case GB2312 :
664
696
        mbstart = GB1;
665
697
        mbmask = ~EU12;
666
698
        mb2 = GB2;
667
699
        break;
668
 
    case (KSC5601)  :
 
700
    case KSC5601:
669
701
        mbstart = KS1;
670
702
        mbmask = ~EU12;
671
703
        mb2 = KS2;
672
704
        break;
673
 
    case (SJIS) :
 
705
    case SJIS   :
674
706
        mbstart = SJ1;
675
707
        mbmask = ~SB12;
676
708
        mb2 = SJ2;
677
709
        break;
678
 
    case (BIGFIVE)  :
 
710
    case BIGFIVE:
679
711
        mbstart = BF1;
680
712
        mbmask = ~SB12;
681
713
        mb2 = BF2;
682
714
        break;
683
 
    case (ISO2022_JP)    :
 
715
    case ISO2022_JP :
684
716
        mbstart = IS1;
685
 
        mbmask = ~(IS1 | IS2 | IS3 | IS4 | IJ12);
 
717
        mbmask = ~(IS1 | IS2 | IS3 | IS4 | IJP);
686
718
        break;
687
 
    case (UTF8) :
 
719
    case UTF8   :
688
720
        mbstart = (U2_1 | U3_1);
689
721
        mbmask = ~(U2_1 | U2_2 | U3_1 | U3_2 | U3_3);
690
722
        break;
696
728
     * deficiency.
697
729
     */
698
730
    switch (mbchar) {
699
 
    case (SJIS) :
 
731
    case SJIS   :
700
732
#if ! SJIS_IS_ESCAPE_FREE
701
733
        bsl_need_escape = TRUE;
702
734
#endif
703
735
        break;
704
 
    case (BIGFIVE)  :
 
736
    case BIGFIVE:
705
737
#if ! BIGFIVE_IS_ESCAPE_FREE
706
738
        bsl_need_escape = TRUE;
707
739
#endif
708
740
        break;
709
741
#if SYSTEM != SYS_MSDOS
710
 
    case (ISO2022_JP)    :
 
742
    case ISO2022_JP :
711
743
#if ! ISO2022_JP_IS_ESCAPE_FREE
712
744
        bsl_need_escape = TRUE;
713
745
#endif
717
749
        bsl_need_escape = FALSE;
718
750
        break;
719
751
    }
 
752
 
 
753
/* Modify table according to 'mode'.    */
 
754
#if MODE == STANDARD
 
755
    if (mode == POST_STD)
 
756
        type[ IN_SRC] = type[ TOK_SEP] = 0;
 
757
    else if (compat_mode)
 
758
        type[ IN_SRC] = 0;
 
759
#else
 
760
    if (mode == OLD_PREP)
 
761
        type[ COM_SEP] = SPA;
 
762
#endif
 
763
 
720
764
}
721
765
 
722
766
static size_t
785
829
        }
786
830
 
787
831
        switch (c2) {
788
 
        case (0x24) :
 
832
        case 0x24   :
789
833
            switch (c3) {
790
 
            case (0x42) :   /* 0x1b 0x24 0x42:  JIS X 0208-1983 */
 
834
            case 0x42   :   /* 0x1b 0x24 0x42:  JIS X 0208-1983 */
791
835
                break;
792
 
            case (0x28) :
 
836
            case 0x28   :
793
837
                *out_p++ = c4 = *in_p++;
794
838
                if (! (type[ c4 & UCHARMAX] & IS4))
795
839
                    error = TRUE;
799
843
                error = TRUE;
800
844
            }
801
845
            break;
802
 
        case (0x28) :
 
846
        case 0x28   :
803
847
            switch (c3) {
804
 
            case (0x42) :   /* 0x1b 0x28 0x42:  ASCII   */
 
848
            case 0x42   :   /* 0x1b 0x28 0x42:  ASCII   */
805
849
                c1 = *out_p++ = *in_p++ & UCHARMAX;
806
850
                continue;
807
851
            default :
812
856
        if (error)
813
857
            break;
814
858
 
815
 
        while (type[ c1 = *out_p++ = (*in_p++ & UCHARMAX)] & IJ1) {
816
 
            if (! (type[ *out_p++ = (*in_p++ & UCHARMAX)] & IJ2)) {
 
859
        while (type[ c1 = *out_p++ = (*in_p++ & UCHARMAX)] & IJP) {
 
860
            if (! (type[ *out_p++ = (*in_p++ & UCHARMAX)] & IJP)) {
817
861
                error = TRUE;
818
862
                break;
819
863
            }
879
923
 
880
924
#endif  /* SYSTEM != SYS_MSDOS */
881
925
 
882
 
#if MODE != POST_STANDARD
883
 
 
884
926
uexpr_t
885
927
#if PROTO
886
928
mb_eval( char ** seq_pp)
892
934
 * Evaluate the value of a multi-byte character.
893
935
 * This routine does not check the legality of the sequence.
894
936
 * This routine is called from eval_char().
 
937
 * This routine is never called in POST_STD mode.
895
938
 */
896
939
{
897
940
    char *      seq = *seq_pp;
899
942
    int         c, c1;
900
943
 
901
944
    switch (mbchar) {
902
 
    case (EUC_JP)   :
903
 
    case (GB2312)   :
904
 
    case (KSC5601)  :
905
 
    case (SJIS) :
906
 
    case (BIGFIVE)  :
 
945
    case EUC_JP :
 
946
    case GB2312 :
 
947
    case KSC5601:
 
948
    case SJIS   :
 
949
    case BIGFIVE:
907
950
        val = (*seq++ & UCHARMAX) << 8;
908
951
        val += *seq++ & UCHARMAX;       /* Evaluate the 2-byte sequence */
909
952
        break;
910
953
#if SYSTEM != SYS_MSDOS
911
 
    case (ISO2022_JP)   :
 
954
    case ISO2022_JP :
912
955
        if (type[ c = *seq++ & UCHARMAX] & IS1) {   /* Skip shift-sequence  */
913
956
            if (type[ c = *seq++ & UCHARMAX] & IS2) {
914
957
                if (type[ c1 = *seq++ & UCHARMAX] & IS3) {
924
967
        }
925
968
        val = (c << 8) + (*seq++ & UCHARMAX);       /* Evaluate the 2-byte  */
926
969
        break;
927
 
    case (UTF8) :       /* Evaluate the sequence of 2 or 3 bytes as it is   */
 
970
    case UTF8   :       /* Evaluate the sequence of 2 or 3 bytes as it is   */
928
971
        if (type[ c = *seq++ & UCHARMAX] & U2_1) {
929
972
            val = (c << 8) + (*seq++ & UCHARMAX);
930
973
        } else {
939
982
    return  val;
940
983
}
941
984
 
942
 
#endif  /* MODE != POST_STANDARD    */
943