Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
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 40... Line 70...
40
    ARRAY OF HIGH LEVEL SORTS
70
    ARRAY OF HIGH LEVEL SORTS
41
 
71
 
42
    All high level sorts are held in the table high_sorts.
72
    All high level sorts are held in the table high_sorts.
43
*/
73
*/
44
 
74
 
45
high_sort *high_sorts = null ;
75
high_sort *high_sorts = null;
46
int crt_high_sort = 0 ;
76
int crt_high_sort = 0;
47
static int total_high_sort = 0 ;
77
static int total_high_sort = 0;
48
 
78
 
49
 
79
 
50
/*
80
/*
51
    ALLOCATE A NEW HIGH LEVEL SORT
81
    ALLOCATE A NEW HIGH LEVEL SORT
52
 
82
 
53
    This routine allocates a new high level sort in the table high_sorts
83
    This routine allocates a new high level sort in the table high_sorts
54
    which is a copy of the local variable q.
84
    which is a copy of the local variable q.
55
*/
85
*/
56
 
86
 
57
high_sort *new_high_sort
87
high_sort *
58
    PROTO_N ( ( q ) )
-
 
59
    PROTO_T ( high_sort *q )
88
new_high_sort(high_sort *q)
60
{
89
{
61
    int c ;
90
    int c;
62
    high_sort *p ;
91
    high_sort *p;
63
    if ( find_high_sort ( q->name ) != SORT_unknown ) {
92
    if (find_high_sort(q->name)!= SORT_unknown) {
64
	is_fatal = 0 ;
93
	is_fatal = 0;
65
	input_error ( "Sort %s already defined", q->name ) ;
94
	input_error("Sort %s already defined", q->name);
66
    }
95
    }
67
    c = crt_high_sort++ ;
96
    c = crt_high_sort++;
68
    if ( c >= total_high_sort ) {
97
    if (c >= total_high_sort) {
69
	total_high_sort += 100 ;
98
	total_high_sort += 100;
70
	high_sorts = realloc_nof ( high_sorts, high_sort, total_high_sort ) ;
99
	high_sorts = realloc_nof(high_sorts, high_sort, total_high_sort);
71
    }
100
    }
72
    p = high_sorts + c ;
101
    p = high_sorts + c;
73
    p->name = q->name ;
102
    p->name = q->name;
74
    p->id = c + high_start ;
103
    p->id = c + high_start;
75
    p->res = q->res ;
104
    p->res = q->res;
76
    p->no_args = q->no_args ;
105
    p->no_args = q->no_args;
77
    p->args = q->args ;
106
    p->args = q->args;
78
    return ( p ) ;
107
    return(p);
79
}
108
}
80
 
109
 
81
 
110
 
82
/*
111
/*
83
    DEFINE A HIGH-LEVEL SORT FROM TOKEN INFORMATION
112
    DEFINE A HIGH-LEVEL SORT FROM TOKEN INFORMATION
84
 
113
 
85
    This routine allocates a new high level sort in the table high_sorts
114
    This routine allocates a new high level sort in the table high_sorts
86
    which has name nm and sort given by the token information tok_info.
115
    which has name nm and sort given by the token information tok_info.
87
*/
116
*/
88
 
117
 
89
void set_high_sort
118
void
90
    PROTO_N ( ( nm, info ) )
-
 
91
    PROTO_T ( char *nm X tok_info *info )
119
set_high_sort(char *nm, tok_info *info)
92
{
120
{
93
    high_sort h ;
121
    high_sort h;
94
    char *q = info->args ;
122
    char *q = info->args;
95
    h.name = nm ;
123
    h.name = nm;
96
    h.res = info->res ;
124
    h.res = info->res;
97
    if ( q == null ) {
125
    if (q == null) {
98
	h.no_args = 0 ;
126
	h.no_args = 0;
99
	h.args = null ;
127
	h.args = null;
100
    } else {
128
    } else {
101
	int i = 0 ;
129
	int i = 0;
102
	h.args = alloc_nof ( sortname, strlen ( q ) ) ;
130
	h.args = alloc_nof(sortname, strlen(q));
103
	while ( *q ) {
131
	while (*q) {
104
	    sortname s ;
132
	    sortname s;
105
	    q = find_sortname ( q, &s ) ;
133
	    q = find_sortname(q, &s);
106
	    q++ ;
134
	    q++;
107
	    h.args [ i++ ] = s ;
135
	    h.args[i++] = s;
108
	}
136
	}
109
	h.no_args = i ;
137
	h.no_args = i;
110
    }
138
    }
111
    IGNORE new_high_sort ( &h ) ;
139
    IGNORE new_high_sort(&h);
112
    return ;
140
    return;
113
}
141
}
114
 
142
 
115
 
143
 
116
/*
144
/*
117
    ENSURE THAT HIGH LEVEL SORTS ARE UNIQUELY NUMBERED
145
    ENSURE THAT HIGH LEVEL SORTS ARE UNIQUELY NUMBERED
Line 119... Line 147...
119
    This routine checks that two high level sorts with the same result
147
    This routine checks that two high level sorts with the same result
120
    and argument sorts are assigned the same sort number.  Given a
148
    and argument sorts are assigned the same sort number.  Given a
121
    high level sort h, it returns any equivalent sort.
149
    high level sort h, it returns any equivalent sort.
122
*/
150
*/
123
 
151
 
124
high_sort *unique_high_sort
152
high_sort *
125
    PROTO_N ( ( h ) )
-
 
126
    PROTO_T ( high_sort *h )
153
unique_high_sort(high_sort *h)
127
{
154
{
128
    int i, j ;
155
    int i, j;
129
    for ( i = 0 ; i < crt_high_sort ; i++ ) {
156
    for (i = 0; i < crt_high_sort; i++) {
130
	high_sort *p = high_sorts + i ;
157
	high_sort *p = high_sorts + i;
131
	if ( p->res == h->res && p->no_args == h->no_args ) {
158
	if (p->res == h->res && p->no_args == h->no_args) {
132
	    boolean ok = 1 ;
159
	    boolean ok = 1;
133
	    if ( p == h ) return ( h ) ;
160
	    if (p == h) return(h);
134
	    for ( j = 0 ; j < p->no_args && ok ; j++ ) {
161
	    for (j = 0; j < p->no_args && ok; j++) {
135
		if ( p->args [j] != h->args [j] ) ok = 0 ;
162
		if (p->args[j]!= h->args[j])ok = 0;
136
	    }
163
	    }
137
	    if ( ok ) {
164
	    if (ok) {
138
		h->id = SORT_unknown ;
165
		h->id = SORT_unknown;
139
		return ( p ) ;
166
		return(p);
140
	    }
167
	    }
141
	}
168
	}
142
    }
169
    }
143
    return ( h ) ;
170
    return(h);
144
}
171
}
145
 
172
 
146
 
173
 
147
/*
174
/*
148
    FIND A HIGH-LEVEL SORT FROM ITS NAME
175
    FIND A HIGH-LEVEL SORT FROM ITS NAME
Line 150... Line 177...
150
    This routine searches for a sort named nm, firstly in the built-in
177
    This routine searches for a sort named nm, firstly in the built-in
151
    sorts, then in the high level sort table.  The corresponding sort
178
    sorts, then in the high level sort table.  The corresponding sort
152
    number is returned.
179
    number is returned.
153
*/
180
*/
154
 
181
 
155
sortname find_high_sort
182
sortname
156
    PROTO_N ( ( nm ) )
-
 
157
    PROTO_T ( char *nm )
183
find_high_sort(char *nm)
158
{
184
{
159
    int i ;
185
    int i;
160
    construct *q = search_cons_hash ( nm, SORT_sortname ) ;
186
    construct *q = search_cons_hash(nm, SORT_sortname);
161
    if ( q ) {
187
    if (q) {
162
	if ( get_char_info ( q ) ) {
188
	if (get_char_info(q)) {
163
	    is_fatal = 0 ;
189
	    is_fatal = 0;
164
	    input_error ( "Illegal sort name, %s", nm ) ;
190
	    input_error("Illegal sort name, %s", nm);
165
	}
191
	}
166
	return ( ( sortname ) q->encoding ) ;
192
	return((sortname)q->encoding);
167
    }
193
    }
168
    for ( i = 0 ; i < crt_high_sort ; i++ ) {
194
    for (i = 0; i < crt_high_sort; i++) {
169
	high_sort *p = high_sorts + i ;
195
	high_sort *p = high_sorts + i;
170
	if ( streq ( nm, p->name ) ) return ( p->id ) ;
196
	if (streq(nm, p->name)) return(p->id);
171
    }
197
    }
172
    return ( SORT_unknown ) ;
198
    return(SORT_unknown);
173
}
199
}
174
 
200
 
175
 
201
 
176
/*
202
/*
177
    FORM A DECODE STRING FOR A HIGH-LEVEL SORT
203
    FORM A DECODE STRING FOR A HIGH-LEVEL SORT
178
 
204
 
179
    This routine forms the decode string corresponding to the arguments
205
    This routine forms the decode string corresponding to the arguments
180
    of the high level sort p.
206
    of the high level sort p.
181
*/
207
*/
182
 
208
 
183
char *find_decode_string
209
char *
184
    PROTO_N ( ( p ) )
-
 
185
    PROTO_T ( high_sort *p )
210
find_decode_string(high_sort *p)
186
{
211
{
187
    int i, n = p->no_args ;
212
    int i, n = p->no_args;
188
    char abuff [100], *a = abuff ;
213
    char abuff[100], *a = abuff;
189
    if ( n == 0 ) return ( null ) ;
214
    if (n == 0) return(null);
190
    for ( i = 0 ; i < n ; i++ ) {
215
    for (i = 0; i < n; i++) {
191
	sortname s = p->args [i] ;
216
	sortname s = p->args[i];
192
	if ( is_high ( s ) ) {
217
	if (is_high(s)) {
193
	    sprint_high_sort ( a, s ) ;
218
	    sprint_high_sort(a, s);
194
	    while ( *a ) a++ ;
219
	    while (*a)a++;
195
	} else {
220
	} else {
196
	    *( a++ ) = sort_letters [s] ;
221
	    *(a++) = sort_letters[s];
197
	}
222
	}
198
    }
223
    }
199
    *a = 0 ;
224
    *a = 0;
200
    return ( string_copy_aux ( abuff ) ) ;
225
    return(string_copy_aux(abuff));
201
}
226
}
202
 
227
 
203
 
228
 
204
/*
229
/*
205
    FIND THE SORTNAME CORRESPONDING TO A DECODE STRING
230
    FIND THE SORTNAME CORRESPONDING TO A DECODE STRING
Line 207... Line 232...
207
    This routine finds the sort corresponding to the decode string
232
    This routine finds the sort corresponding to the decode string
208
    pointed to by p.  This is returned via the pointer q, the procedure
233
    pointed to by p.  This is returned via the pointer q, the procedure
209
    returning a pointer to the character at the end of the sort encoding.
234
    returning a pointer to the character at the end of the sort encoding.
210
*/
235
*/
211
 
236
 
212
char *find_sortname
237
char *
213
    PROTO_N ( ( p, q ) )
-
 
214
    PROTO_T ( char *p X sortname *q )
238
find_sortname(char *p, sortname *q)
215
{
239
{
216
    int n = 0 ;
240
    int n = 0;
217
    sortname s ;
241
    sortname s;
218
    if ( *p == 'T' ) {
242
    if (*p == 'T') {
219
	while ( *( ++p ) != '#' ) n = 10 * n + ( *p - '0' ) ;
243
	while (*(++p)!= '#')n = 10 * n + (*p - '0');
220
	s = ( sortname ) ( high_start + n ) ;
244
	s = (sortname)(high_start + n);
221
    } else {
245
    } else {
222
	while ( *p != sort_letters [n] ) n++ ;
246
	while (*p != sort_letters[n])n++;
223
	s = ( sortname ) n ;
247
	s = (sortname)n;
224
    }
248
    }
225
    if ( q ) *q = s ;
249
    if (q)*q = s;
226
    return ( p ) ;
250
    return(p);
227
}
251
}