Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /branches/tendra5/src/producers/common/parse/char.c – Rev 5 and 6

Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 38... Line 68...
38
/*
68
/*
39
    ASCII FLAG
69
    ASCII FLAG
40
 
70
 
41
    This flag is true if the native codeset is ASCII.  It is initially -1
71
    This flag is true if the native codeset is ASCII.  It is initially -1
42
    indicating that the conversion tables have not been initialised.
72
    indicating that the conversion tables have not been initialised.
43
*/
73
*/
44
 
74
 
45
int is_ascii = -1 ;
75
int is_ascii = -1;
46
 
76
 
47
 
77
 
48
/*
78
/*
49
    CONVERSION TABLES
79
    CONVERSION TABLES
50
 
80
 
51
    These tables give the conversions of ASCII to and from the native
81
    These tables give the conversions of ASCII to and from the native
52
    codeset.  The ASCII to native table is deduced for the portable
82
    codeset.  The ASCII to native table is deduced for the portable
53
    codeset from the list of characters in char.h which is given in
83
    codeset from the list of characters in char.h which is given in
54
    ASCII sequence.
84
    ASCII sequence.
55
*/
85
*/
56
 
86
 
57
 
87
 
58
static character to_ascii_tab [ NO_CHAR + 1 ] ;
88
static character to_ascii_tab[NO_CHAR + 1];
59
 
89
 
60
static character from_ascii_tab [ NO_CHAR + 1 ] = {
90
static character from_ascii_tab[NO_CHAR + 1] = {
61
#define NONE			char_illegal
91
#define NONE			char_illegal
62
#define CHAR_DATA( A, B, C, D )	( D ),
92
#define CHAR_DATA(A, B, C, D)	(D),
63
#include "char.h"
93
#include "char.h"
64
#undef CHAR_DATA
94
#undef CHAR_DATA
65
    NONE			/* dummy last element */
95
	NONE			/* dummy last element */
66
} ;
96
};
67
 
97
 
68
 
98
 
69
/*
99
/*
70
    CONVERT A CHARACTER TO ASCII
100
    CONVERT A CHARACTER TO ASCII
71
 
101
 
72
    This routine converts the character c from the native codeset to
102
    This routine converts the character c from the native codeset to
73
    ASCII.
103
    ASCII.
74
*/
104
*/
75
 
105
 
76
unsigned long to_ascii
106
unsigned long
77
    PROTO_N ( ( c, ch ) )
-
 
78
    PROTO_T ( unsigned long c X int *ch )
107
to_ascii(unsigned long c, int *ch)
79
{
108
{
80
    if ( c < NO_CHAR ) {
109
	if (c < NO_CHAR) {
81
	c = ( unsigned long ) to_ascii_tab [c] ;
110
		c = (unsigned long)to_ascii_tab[c];
82
	*ch = CHAR_ASCII ;
111
		*ch = CHAR_ASCII;
83
    }
112
	}
84
    return ( c ) ;
113
	return(c);
85
}
114
}
86
 
115
 
87
 
116
 
88
/*
117
/*
89
    CONVERT A CHARACTER TO NATIVE CODESET
118
    CONVERT A CHARACTER TO NATIVE CODESET
90
 
119
 
91
    This routine converts the character c to the native codeset from
120
    This routine converts the character c to the native codeset from
92
    ASCII.
121
    ASCII.
93
*/
122
*/
94
 
123
 
95
unsigned long from_ascii
124
unsigned long
96
    PROTO_N ( ( c, ch ) )
-
 
97
    PROTO_T ( unsigned long c X int *ch )
125
from_ascii(unsigned long c, int *ch)
98
{
126
{
99
    if ( c < NO_CHAR ) {
127
	if (c < NO_CHAR) {
100
	c = ( unsigned long ) from_ascii_tab [c] ;
128
		c = (unsigned long)from_ascii_tab[c];
101
	*ch = CHAR_SIMPLE ;
129
		*ch = CHAR_SIMPLE;
102
    }
130
	}
103
    return ( c ) ;
131
	return(c);
104
}
132
}
105
 
133
 
106
 
134
 
107
/*
135
/*
108
    TRANSFORM A TABLE FROM ASCII TO NATIVE CODESET
136
    TRANSFORM A TABLE FROM ASCII TO NATIVE CODESET
109
 
137
 
110
    This routine maps the look-up table p from ASCII to native codeset.
138
    This routine maps the look-up table p from ASCII to native codeset.
111
*/
139
*/
112
 
140
 
113
void map_ascii
141
void
114
    PROTO_N ( ( p ) )
-
 
115
    PROTO_T ( unsigned char *p )
142
map_ascii(unsigned char *p)
116
{
143
{
117
    unsigned c ;
144
	unsigned c;
118
    int asc = is_ascii ;
145
	int asc = is_ascii;
119
    if ( asc == -1 ) {
146
	if (asc == -1) {
120
	/* Set up conversion tables */
147
		/* Set up conversion tables */
121
	asc = 1 ;
148
		asc = 1;
122
	for ( c = 0 ; c < NO_CHAR ; c++ ) {
149
		for (c = 0; c < NO_CHAR; c++) {
123
	    to_ascii_tab [c] = ( character ) c ;
150
			to_ascii_tab[c] = (character)c;
-
 
151
		}
-
 
152
		for (c = 0; c < NO_CHAR; c++) {
-
 
153
			unsigned a = (unsigned)from_ascii_tab[c];
-
 
154
			if (a == NONE) {
-
 
155
				a = c;
-
 
156
			}
-
 
157
			if (a != c) {
-
 
158
				asc = 0;
-
 
159
			}
-
 
160
			from_ascii_tab[c] = (character)a;
-
 
161
			to_ascii_tab[a] = (character)c;
-
 
162
		}
-
 
163
		is_ascii = asc;
124
	}
164
	}
125
	for ( c = 0 ; c < NO_CHAR ; c++ ) {
-
 
126
	    unsigned a = ( unsigned ) from_ascii_tab [c] ;
-
 
127
	    if ( a == NONE ) a = c ;
-
 
128
	    if ( a != c ) asc = 0 ;
-
 
129
	    from_ascii_tab [c] = ( character ) a ;
-
 
130
	    to_ascii_tab [a] = ( character ) c ;
-
 
131
	}
-
 
132
	is_ascii = asc ;
-
 
133
    }
-
 
134
 
165
 
135
    if ( asc == 0 ) {
166
	if (asc == 0) {
136
	/* Map table */
167
		/* Map table */
137
	unsigned char b = p [ NONE ] ;
168
		unsigned char b = p[NONE];
138
	unsigned char copy [ NO_CHAR ] ;
169
		unsigned char copy[NO_CHAR];
139
	for ( c = 0 ; c < NO_CHAR ; c++ ) {
170
		for (c = 0; c < NO_CHAR; c++) {
140
	    copy [c] = p [c] ;
171
			copy[c] = p[c];
141
	    p [c] = b ;
172
			p[c] = b;
142
	}
173
		}
143
	SET ( copy ) ;
174
		SET(copy);
144
	for ( c = 0 ; c < NO_CHAR ; c++ ) {
175
		for (c = 0; c < NO_CHAR; c++) {
145
	    character a = from_ascii_tab [c] ;
176
			character a = from_ascii_tab[c];
146
	    p [a] = copy [c] ;
177
			p[a] = copy[c];
-
 
178
		}
147
	}
179
	}
148
    }
-
 
149
    return ;
180
	return;
150
}
181
}
151
 
182
 
152
 
183
 
153
/*
184
/*
154
    TABLE OF ALPHABETIC UNICODE CHARACTERS
185
    TABLE OF ALPHABETIC UNICODE CHARACTERS
Line 158... Line 189...
158
    derived from Annex E of the standard (which derives from ISO/IEC
189
    derived from Annex E of the standard (which derives from ISO/IEC
159
    PDTR 10176) with two misprints corrected.  0e0d should be 0e8d
190
    PDTR 10176) with two misprints corrected.  0e0d should be 0e8d
160
    and 5e76 should be fe76.  Note that the upper and lower case
191
    and 5e76 should be fe76.  Note that the upper and lower case
161
    English alphabets have been included even though they are not
192
    English alphabets have been included even though they are not
162
    valid universal character names.
193
    valid universal character names.
277
#if FS_NUMBER_SUFFIX
308
#if FS_NUMBER_SUFFIX
278
    { 0x4e00UL, 0x9fa5UL }, { 0xf900UL, 0xfa2dUL }, { 0xfb1fUL, 0xfb36UL },
309
	{ 0x4e00UL, 0x9fa5UL }, { 0xf900UL, 0xfa2dUL }, { 0xfb1fUL, 0xfb36UL },
279
    { 0xfb38UL, 0xfb3cUL }, { 0xfb3eUL, 0xfb3eUL }, { 0xfb40UL, 0xfb41UL },
310
	{ 0xfb38UL, 0xfb3cUL }, { 0xfb3eUL, 0xfb3eUL }, { 0xfb40UL, 0xfb41UL },
280
    { 0xfb42UL, 0xfb44UL }, { 0xfb46UL, 0xfbb1UL }, { 0xfbd3UL, 0xfd3fUL },
311
	{ 0xfb42UL, 0xfb44UL }, { 0xfb46UL, 0xfbb1UL }, { 0xfbd3UL, 0xfd3fUL },
281
    { 0xfd50UL, 0xfd8fUL }, { 0xfd92UL, 0xfdc7UL }, { 0xfdf0UL, 0xfdfbUL },
312
	{ 0xfd50UL, 0xfd8fUL }, { 0xfd92UL, 0xfdc7UL }, { 0xfdf0UL, 0xfdfbUL },
282
    { 0xfe70UL, 0xfe72UL }, { 0xfe74UL, 0xfe74UL }, { 0xfe76UL, 0xfefcUL },
313
	{ 0xfe70UL, 0xfe72UL }, { 0xfe74UL, 0xfe74UL }, { 0xfe76UL, 0xfefcUL },
283
    { 0xff21UL, 0xff3aUL }, { 0xff41UL, 0xff5aUL }, { 0xff66UL, 0xffbeUL },
314
	{ 0xff21UL, 0xff3aUL }, { 0xff41UL, 0xff5aUL }, { 0xff66UL, 0xffbeUL },
284
    { 0xffc2UL, 0xffc7UL }, { 0xffcaUL, 0xffcfUL }, { 0xffd2UL, 0xffd7UL },
315
	{ 0xffc2UL, 0xffc7UL }, { 0xffcaUL, 0xffcfUL }, { 0xffd2UL, 0xffd7UL },
285
    { 0xffdaUL, 0xffdcUL }
316
	{ 0xffdaUL, 0xffdcUL }
286
#else
317
#else
287
    { 0x4e00, 0x9fa5 }, { 0xf900, 0xfa2d }, { 0xfb1f, 0xfb36 },
318
	{ 0x4e00, 0x9fa5 }, { 0xf900, 0xfa2d }, { 0xfb1f, 0xfb36 },
288
    { 0xfb38, 0xfb3c }, { 0xfb3e, 0xfb3e }, { 0xfb40, 0xfb41 },
319
	{ 0xfb38, 0xfb3c }, { 0xfb3e, 0xfb3e }, { 0xfb40, 0xfb41 },
289
    { 0xfb42, 0xfb44 }, { 0xfb46, 0xfbb1 }, { 0xfbd3, 0xfd3f },
320
	{ 0xfb42, 0xfb44 }, { 0xfb46, 0xfbb1 }, { 0xfbd3, 0xfd3f },
290
    { 0xfd50, 0xfd8f }, { 0xfd92, 0xfdc7 }, { 0xfdf0, 0xfdfb },
321
	{ 0xfd50, 0xfd8f }, { 0xfd92, 0xfdc7 }, { 0xfdf0, 0xfdfb },
291
    { 0xfe70, 0xfe72 }, { 0xfe74, 0xfe74 }, { 0xfe76, 0xfefc },
322
	{ 0xfe70, 0xfe72 }, { 0xfe74, 0xfe74 }, { 0xfe76, 0xfefc },
292
    { 0xff21, 0xff3a }, { 0xff41, 0xff5a }, { 0xff66, 0xffbe },
323
	{ 0xff21, 0xff3a }, { 0xff41, 0xff5a }, { 0xff66, 0xffbe },
293
    { 0xffc2, 0xffc7 }, { 0xffca, 0xffcf }, { 0xffd2, 0xffd7 },
324
	{ 0xffc2, 0xffc7 }, { 0xffca, 0xffcf }, { 0xffd2, 0xffd7 },
294
    { 0xffda, 0xffdc }
325
	{ 0xffda, 0xffdc }
295
#endif
326
#endif
296
} ;
327
};
297
 
328
 
298
 
329
 
299
/*
330
/*
300
    DOES A UNICODE CHARACTER REPRESENT AN ALPHABETIC VALUE?
331
    DOES A UNICODE CHARACTER REPRESENT AN ALPHABETIC VALUE?
301
 
332
 
302
    This routine checks whether the unicode character c represents an
333
    This routine checks whether the unicode character c represents an
303
    alphabetic value suitable for use in an identifier name.  It
334
    alphabetic value suitable for use in an identifier name.  It
304
    operates by performing a binary chop on the table above.
335
    operates by performing a binary chop on the table above.
305
*/
336
*/
306
 
337
 
307
int unicode_alpha
338
int
308
    PROTO_N ( ( c ) )
-
 
309
    PROTO_T ( unsigned long c )
339
unicode_alpha(unsigned long c)
310
{
340
{
311
    int i = 0 ;
341
	int i = 0;
312
    int j = array_size ( alpha_range ) - 1 ;
342
	int j = array_size(alpha_range) - 1;
313
    do {
343
	do {
314
	int k = ( i + j ) / 2 ;
344
		int k = (i + j) / 2;
315
	if ( c < alpha_range [k].lo ) {
345
		if (c < alpha_range[k].lo) {
316
	    /* Lower half */
346
			/* Lower half */
317
	    j = k - 1 ;
347
			j = k - 1;
318
	} else if ( c > alpha_range [k].hi ) {
348
		} else if (c > alpha_range[k].hi) {
319
	    /* Upper half */
349
			/* Upper half */
320
	    i = k + 1 ;
350
			i = k + 1;
321
	} else {
351
		} else {
322
	    /* Match found */
352
			/* Match found */
323
	    return ( 1 ) ;
353
			return(1);
324
	}
354
		}
325
    } while ( i <= j ) ;
355
	} while (i <= j);
326
    return ( 0 ) ;
356
	return(0);
327
}
357
}