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-2006 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 56... Line 86...
56
 
86
 
57
/*
87
/*
58
    NUMBER OF ERRORS
88
    NUMBER OF ERRORS
59
 
89
 
60
    This value gives the number of errors in the error catalogue.
90
    This value gives the number of errors in the error catalogue.
61
*/
91
*/
62
 
92
 
63
#define CATALOG_SIZE	array_size ( ERR_CATALOG )
93
#define CATALOG_SIZE	array_size(ERR_CATALOG)
64
unsigned catalog_size = ( unsigned ) CATALOG_SIZE ;
94
unsigned catalog_size = (unsigned)CATALOG_SIZE;
65
 
95
 
66
 
96
 
67
/*
97
/*
68
    ERROR NAME HASH TABLE
98
    ERROR NAME HASH TABLE
69
 
99
 
70
    This hash table is used to hold the names of the various errors in
100
    This hash table is used to hold the names of the various errors in
71
    the error catalogue.
101
    the error catalogue.
72
*/
102
*/
73
 
103
 
74
typedef struct err_hash_tag {
104
typedef struct err_hash_tag {
75
    int number ;
105
	int number;
76
    ERR_DATA *entry ;
106
	ERR_DATA *entry;
77
    struct err_hash_tag *next ;
107
	struct err_hash_tag *next;
78
} ERR_HASH ;
108
} ERR_HASH;
79
 
109
 
80
#define HASH_ERROR	128
110
#define HASH_ERROR	128
81
static ERR_HASH *error_hash [ HASH_ERROR + 1 ] ;
111
static ERR_HASH *error_hash[HASH_ERROR + 1];
82
static ERR_HASH *all_error_hash = NULL ;
112
static ERR_HASH *all_error_hash = NULL;
83
 
113
 
84
 
114
 
85
/*
115
/*
86
    INITIALISE THE ERROR NAME HASH TABLE
116
    INITIALISE THE ERROR NAME HASH TABLE
87
 
117
 
88
    This routine initialises the error hash table.
118
    This routine initialises the error hash table.
89
*/
119
*/
90
 
120
 
91
static void init_err_hash
121
static void
92
    PROTO_Z ()
122
init_err_hash(void)
93
{
123
{
94
    int i ;
124
	int i;
95
    ERR_DATA *cat = ERR_CATALOG ;
125
	ERR_DATA *cat = ERR_CATALOG;
96
    ERR_HASH *err = xmalloc_nof ( ERR_HASH, CATALOG_SIZE ) ;
126
	ERR_HASH *err = xmalloc_nof(ERR_HASH, CATALOG_SIZE);
97
    all_error_hash = err ;
127
	all_error_hash = err;
98
    for ( i = 0 ; i <= HASH_ERROR ; i++ ) error_hash [i] = NULL ;
-
 
99
    for ( i = 0 ; i < CATALOG_SIZE ; i++ ) {
128
	for (i = 0; i <= HASH_ERROR; i++) {
100
	unsigned long h ;
-
 
101
	CONST char *s = cat->name ;
-
 
102
	if ( s ) {
-
 
103
	    h = hash ( ustrlit ( s ) ) ;
129
		error_hash[i] = NULL;
104
	    h %= HASH_ERROR ;
-
 
105
	} else {
-
 
106
	    h = HASH_ERROR ;
-
 
107
	}
130
	}
-
 
131
	for (i = 0; i < CATALOG_SIZE; i++) {
-
 
132
		unsigned long h;
-
 
133
		CONST char *s = cat->name;
-
 
134
		if (s) {
-
 
135
			h = hash(ustrlit(s));
-
 
136
			h %= HASH_ERROR;
-
 
137
		} else {
-
 
138
			h = HASH_ERROR;
-
 
139
		}
108
	err->number = i ;
140
		err->number = i;
109
	err->entry = cat ;
141
		err->entry = cat;
110
	err->next = error_hash [h] ;
142
		err->next = error_hash[h];
111
	error_hash [h] = err ;
143
		error_hash[h] = err;
112
	cat++ ;
144
		cat++;
113
	err++ ;
145
		err++;
114
    }
146
	}
115
    return ;
147
	return;
116
}
148
}
117
 
149
 
118
 
150
 
119
/*
151
/*
120
    FIND AN ERROR NUMBER
152
    FIND AN ERROR NUMBER
121
 
153
 
122
    This routine finds the error number corresponding to the string literal
154
    This routine finds the error number corresponding to the string literal
123
    expression s.  n gives a likely value to try first.  It returns -1 if
155
    expression s.  n gives a likely value to try first.  It returns -1 if
124
    s is not the name of a known error.
156
    s is not the name of a known error.
125
*/
157
*/
126
 
158
 
127
int find_error_no
159
int
128
    PROTO_N ( ( s, n ) )
-
 
129
    PROTO_T ( STRING s X int n )
160
find_error_no(STRING s, int n)
130
{
161
{
131
    unsigned kind = DEREF_unsigned ( str_simple_kind ( s ) ) ;
162
	unsigned kind = DEREF_unsigned(str_simple_kind(s));
132
    if ( kind == STRING_NONE ) {
163
	if (kind == STRING_NONE) {
133
	ERR_HASH *err ;
164
		ERR_HASH *err;
134
	unsigned long h ;
165
		unsigned long h;
135
	string text = DEREF_string ( str_simple_text ( s ) ) ;
166
		string text = DEREF_string(str_simple_text(s));
136
	ulong len = DEREF_ulong ( str_simple_len ( s ) ) ;
167
		ulong len = DEREF_ulong(str_simple_len(s));
137
	if ( n >= 0 && n < CATALOG_SIZE ) {
168
		if (n >= 0 && n < CATALOG_SIZE) {
138
	    string nm = ustrlit ( ERR_CATALOG [n].name ) ;
169
			string nm = ustrlit(ERR_CATALOG[n].name);
139
	    if ( nm && ustreq ( text, nm ) ) {
170
			if (nm && ustreq(text, nm)) {
140
		if ( len == ( ulong ) ustrlen ( nm ) ) return ( n ) ;
171
				if (len == (ulong)ustrlen(nm)) {
-
 
172
					return (n);
141
	    }
173
				}
-
 
174
			}
142
	}
175
		}
143
	if ( all_error_hash == NULL ) init_err_hash () ;
176
		if (all_error_hash == NULL) {
-
 
177
			init_err_hash();
-
 
178
		}
144
	h = hash ( text ) ;
179
		h = hash(text);
145
	h %= HASH_ERROR ;
180
		h %= HASH_ERROR;
146
	for ( err = error_hash [h] ; err != NULL ; err = err->next ) {
181
		for (err = error_hash[h]; err != NULL; err = err->next) {
147
	    string nm = ustrlit ( err->entry->name ) ;
182
			string nm = ustrlit(err->entry->name);
148
	    if ( nm && ustreq ( text, nm ) ) {
183
			if (nm && ustreq(text, nm)) {
149
		if ( len == ( ulong ) ustrlen ( nm ) ) {
184
				if (len == (ulong)ustrlen(nm)) {
150
		    return ( err->number ) ;
185
					return (err->number);
-
 
186
				}
-
 
187
			}
151
		}
188
		}
152
	    }
-
 
153
	}
189
	}
154
    }
-
 
155
    return ( -1 ) ;
190
	return (-1);
156
}
191
}
157
 
192
 
158
 
193
 
159
/*
194
/*
160
    SET AN ERROR SEVERITY LEVEL
195
    SET AN ERROR SEVERITY LEVEL
161
 
196
 
162
    This routine sets the severity level of error number n to the error
197
    This routine sets the severity level of error number n to the error
163
    severity corresponding to the option number opt.
198
    severity corresponding to the option number opt.
164
*/
199
*/
165
 
200
 
166
void set_error_sev
201
void
167
    PROTO_N ( ( n, opt ) )
-
 
168
    PROTO_T ( int n X int opt )
202
set_error_sev(int n, int opt)
169
{
203
{
170
    if ( n >= 0 && n < CATALOG_SIZE ) {
204
	if (n >= 0 && n < CATALOG_SIZE) {
171
	ERR_CATALOG [n].usage = opt ;
205
		ERR_CATALOG[n].usage = opt;
172
    }
206
	}
173
    return ;
207
	return;
174
}
208
}
175
 
209
 
176
 
210
 
177
/*
211
/*
178
    LOOK UP A LANGUAGE DEPENDENT TERM
212
    LOOK UP A LANGUAGE DEPENDENT TERM
179
 
213
 
180
    Certain technical terms vary slightly between C and C++.  This routine
214
    Certain technical terms vary slightly between C and C++.  This routine
181
    looks up the term corresponding to the lexical token number t in the
215
    looks up the term corresponding to the lexical token number t in the
182
    current language.  The default is the normal lexical token name.
216
    current language.  The default is the normal lexical token name.
183
*/
217
*/
184
 
218
 
185
string find_vocab
219
string
186
    PROTO_N ( ( t ) )
-
 
187
    PROTO_T ( int t )
220
find_vocab(int t)
188
{
221
{
189
    CONST char *s = token_names [t] ;
222
	CONST char *s = token_names[t];
190
#if LANGUAGE_C
223
#if LANGUAGE_C
191
    switch ( t ) {
224
	switch (t) {
-
 
225
	case lex_class:
192
	case lex_class : s = "struct/union" ; break ;
226
		s = "struct/union"; break;
193
    }
227
	}
194
#endif
228
#endif
195
    return ( ustrlit ( s ) ) ;
229
	return (ustrlit(s));
196
}
230
}
197
 
231
 
198
 
232
 
199
/*
233
/*
200
    INITIALISE THE ERROR CATALOGUE
234
    INITIALISE THE ERROR CATALOGUE
201
 
235
 
202
    This routine initialises the error catalogue.
236
    This routine initialises the error catalogue.
203
*/
237
*/
204
 
238
 
205
void init_catalog
239
void
206
    PROTO_Z ()
240
init_catalog(void)
207
{
241
{
208
    ASSERT ( OPT_error == 0 ) ;
242
	ASSERT(OPT_error == 0);
209
    return ;
243
	return;
210
}
244
}
211
 
245
 
212
 
246
 
213
/*
247
/*
214
    TERMINATE THE ERROR CATALOGUE
248
    TERMINATE THE ERROR CATALOGUE
215
 
249
 
216
    This routine terminates the error catalogue.
250
    This routine terminates the error catalogue.
217
*/
251
*/
218
 
252
 
219
void term_catalog
253
void
220
    PROTO_Z ()
254
term_catalog(void)
221
{
255
{
222
    xfree_nof ( all_error_hash ) ;
256
	xfree_nof(all_error_hash);
223
    all_error_hash = NULL ;
257
	all_error_hash = NULL;
224
    return ;
258
	return;
225
}
259
}