@@ -478,7 +478,9 @@ re_set_syntax(syntax)
478
478
#define WC2MBC1ST (c ) \
479
479
((current_mbctype != MBCTYPE_UTF8) ? ((c<0x100) ? (c) : (((c)>>8)&0xff)) : utf8_firstbyte(c))
480
480
481
- int mbc_startpos _ ((const char * start , int pos ));
481
+ typedef unsigned int (* mbc_startpos_func_t ) _ ((const char * string , unsigned int pos ));
482
+ const mbc_startpos_func_t mbc_startpos_func [];
483
+ #define mbc_startpos (start , pos ) (*mbc_startpos_func[current_mbctype])((start), (pos))
482
484
483
485
static unsigned int
484
486
utf8_firstbyte (c )
@@ -4384,7 +4386,6 @@ re_free_registers(regs)
4384
4386
Created for grep multi-byte extension Jul., 1993 by t^2 (Takahiro Tanimoto)
4385
4387
Last change: Jul. 9, 1993 by t^2 */
4386
4388
static const unsigned char mbctab_ascii [] = {
4387
- /* forward scan */
4388
4389
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4389
4390
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4390
4391
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -4401,28 +4402,9 @@ static const unsigned char mbctab_ascii[] = {
4401
4402
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4402
4403
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4403
4404
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4404
-
4405
- /* reverse scan */
4406
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4407
- 0 , 0 , 0 , 0 , 0 , 0 , 0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
4423
4406
4424
4407
static const unsigned char mbctab_euc [] = { /* 0xA1-0xFE */
4425
- /* forward scan */
4426
4408
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4427
4409
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4428
4410
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -4439,28 +4421,9 @@ static const unsigned char mbctab_euc[] = { /* 0xA1-0xFE */
4439
4421
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4440
4422
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4441
4423
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 ,
4442
-
4443
- /* reverse scan */
4444
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4445
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4446
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4447
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4448
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4449
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4450
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4451
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4452
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4453
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4454
- 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4455
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4456
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4457
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4458
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4459
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0
4460
4424
};
4461
4425
4462
- static const unsigned char mbctab_sjis [] = { /* 0x80-0x9f,0xE0-0xFF */
4463
- /* forward scan */
4426
+ static const unsigned char mbctab_sjis [] = { /* 0x80-0x9f,0xE0-0xFC */
4464
4427
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4465
4428
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4466
4429
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -4476,9 +4439,10 @@ static const unsigned char mbctab_sjis[] = { /* 0x80-0x9f,0xE0-0xFF */
4476
4439
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4477
4440
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4478
4441
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4479
- 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 ,
4442
+ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0
4443
+ };
4480
4444
4481
- /* reverse scan */
4445
+ static const unsigned char mbctab_sjis_trail [] = { /* 0x40-0x7E,0x80-0xFC */
4482
4446
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4483
4447
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4484
4448
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -4498,7 +4462,6 @@ static const unsigned char mbctab_sjis[] = { /* 0x80-0x9f,0xE0-0xFF */
4498
4462
};
4499
4463
4500
4464
static const unsigned char mbctab_utf8 [] = {
4501
- /* forward scan */
4502
4465
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4503
4466
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4504
4467
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -4515,24 +4478,6 @@ static const unsigned char mbctab_utf8[] = {
4515
4478
1 ,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 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
4532
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4533
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4534
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4535
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
4536
4481
};
4537
4482
4538
4483
const unsigned char * re_mbctab = mbctab_ascii ;
@@ -4561,36 +4506,87 @@ re_mbcinit(mbctype)
4561
4506
}
4562
4507
}
4563
4508
4564
- int
4565
- mbc_startpos (string , pos )
4509
+ #define mbc_isfirst (t , c ) (t)[(unsigned char)(c)]
4510
+ #define mbc_len (t , c ) ((t)[(unsigned char)(c)]+1)
4511
+
4512
+ static unsigned int asc_startpos _ ((const char * string , unsigned int pos ));
4513
+ static unsigned int
4514
+ asc_startpos (string , pos )
4566
4515
const char * string ;
4567
- int pos ;
4516
+ unsigned int pos ;
4568
4517
{
4569
- int i = pos , w ;
4518
+ return pos ;
4519
+ }
4520
+
4521
+ #define euc_islead (c ) ((unsigned char)((c) - 0xa1) > 0xfe - 0xa1)
4522
+ #define euc_mbclen (c ) mbc_len(mbctab_euc, (c))
4523
+ static unsigned int euc_startpos _ ((const char * string , unsigned int pos ));
4524
+ static unsigned int
4525
+ euc_startpos (string , pos )
4526
+ const char * string ;
4527
+ unsigned int pos ;
4528
+ {
4529
+ unsigned int i = pos , w ;
4570
4530
4571
- while (i > 0 && re_mbctab [( unsigned char ) string [i ]+ 256 ] ) {
4531
+ while (i > 0 && ! euc_islead ( string [i ]) ) {
4572
4532
-- i ;
4573
4533
}
4574
- if (i == pos || i + (w = mbclen (string [i ])) > pos ) return i ;
4534
+ if (i == pos || i + (w = euc_mbclen (string [i ])) > pos ) {
4535
+ return i ;
4536
+ }
4575
4537
i += w ;
4538
+ return i + ((pos - i ) & ~1 );
4539
+ }
4576
4540
4577
- switch (current_mbctype ) {
4578
- case MBCTYPE_EUC :
4579
- return i + ((pos - i ) & ~1 );
4541
+ #define sjis_isfirst (c ) mbc_isfirst(mbctab_sjis, (c))
4542
+ #define sjis_istrail (c ) mbctab_sjis_trail[(unsigned char)(c)]
4543
+ #define sjis_mbclen (c ) mbc_len(mbctab_sjis, (c))
4544
+ static unsigned int sjis_startpos _ ((const char * string , unsigned int pos ));
4545
+ static unsigned int
4546
+ sjis_startpos (string , pos )
4547
+ const char * string ;
4548
+ unsigned int pos ;
4549
+ {
4550
+ unsigned int i = pos , w ;
4580
4551
4581
- case MBCTYPE_SJIS :
4582
- while (i + (w = mbclen (string [i ])) < pos ) {
4583
- i += w ;
4584
- }
4552
+ if (i > 0 && sjis_istrail (string [i ])) {
4553
+ do {
4554
+ if (!sjis_isfirst (string [-- i ])) {
4555
+ ++ i ;
4556
+ break ;
4557
+ }
4558
+ } while (i > 0 );
4559
+ }
4560
+ if (i == pos || i + (w = sjis_mbclen (string [i ])) > pos ) {
4585
4561
return i ;
4562
+ }
4563
+ i += w ;
4564
+ return i + ((pos - i ) & ~1 );
4565
+ }
4586
4566
4587
- case MBCTYPE_UTF8 :
4567
+ #define utf8_islead (c ) ((unsigned char)((c) & 0xc0) != 0x80)
4568
+ #define utf8_mbclen (c ) mbc_len(mbctab_utf8, (c))
4569
+ static unsigned int utf8_startpos _ ((const char * string , unsigned int pos ));
4570
+ static unsigned int
4571
+ utf8_startpos (string , pos )
4572
+ const char * string ;
4573
+ unsigned int pos ;
4574
+ {
4575
+ unsigned int i = pos , w ;
4576
+
4577
+ while (i > 0 && !utf8_islead (string [i ])) {
4578
+ -- i ;
4579
+ }
4580
+ if (i == pos || i + (w = utf8_mbclen (string [i ])) > pos ) {
4588
4581
return i ;
4589
- default :
4590
- return pos ;
4591
4582
}
4583
+ return i + w ;
4592
4584
}
4593
4585
4586
+ const mbc_startpos_func_t mbc_startpos_func [4 ] = {
4587
+ asc_startpos , euc_startpos , sjis_startpos , utf8_startpos
4588
+ };
4589
+
4594
4590
/*
4595
4591
vi: sw=2 ts=8
4596
4592
Local variables:
0 commit comments