Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5/src/tools/tnc/high.c – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
#include "config.h"
32
#include "types.h"
33
#include "high.h"
34
#include "table.h"
35
#include "tdf.h"
36
#include "utility.h"
37
 
38
 
39
/*
40
    ARRAY OF HIGH LEVEL SORTS
41
 
42
    All high level sorts are held in the table high_sorts.
43
*/
44
 
45
high_sort *high_sorts = null ;
46
int crt_high_sort = 0 ;
47
static int total_high_sort = 0 ;
48
 
49
 
50
/*
51
    ALLOCATE A NEW HIGH LEVEL SORT
52
 
53
    This routine allocates a new high level sort in the table high_sorts
54
    which is a copy of the local variable q.
55
*/
56
 
57
high_sort *new_high_sort
58
    PROTO_N ( ( q ) )
59
    PROTO_T ( high_sort *q )
60
{
61
    int c ;
62
    high_sort *p ;
63
    if ( find_high_sort ( q->name ) != SORT_unknown ) {
64
	is_fatal = 0 ;
65
	input_error ( "Sort %s already defined", q->name ) ;
66
    }
67
    c = crt_high_sort++ ;
68
    if ( c >= total_high_sort ) {
69
	total_high_sort += 100 ;
70
	high_sorts = realloc_nof ( high_sorts, high_sort, total_high_sort ) ;
71
    }
72
    p = high_sorts + c ;
73
    p->name = q->name ;
74
    p->id = c + high_start ;
75
    p->res = q->res ;
76
    p->no_args = q->no_args ;
77
    p->args = q->args ;
78
    return ( p ) ;
79
}
80
 
81
 
82
/*
83
    DEFINE A HIGH-LEVEL SORT FROM TOKEN INFORMATION
84
 
85
    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.
87
*/
88
 
89
void set_high_sort
90
    PROTO_N ( ( nm, info ) )
91
    PROTO_T ( char *nm X tok_info *info )
92
{
93
    high_sort h ;
94
    char *q = info->args ;
95
    h.name = nm ;
96
    h.res = info->res ;
97
    if ( q == null ) {
98
	h.no_args = 0 ;
99
	h.args = null ;
100
    } else {
101
	int i = 0 ;
102
	h.args = alloc_nof ( sortname, strlen ( q ) ) ;
103
	while ( *q ) {
104
	    sortname s ;
105
	    q = find_sortname ( q, &s ) ;
106
	    q++ ;
107
	    h.args [ i++ ] = s ;
108
	}
109
	h.no_args = i ;
110
    }
111
    IGNORE new_high_sort ( &h ) ;
112
    return ;
113
}
114
 
115
 
116
/*
117
    ENSURE THAT HIGH LEVEL SORTS ARE UNIQUELY NUMBERED
118
 
119
    This routine checks that two high level sorts with the same result
120
    and argument sorts are assigned the same sort number.  Given a
121
    high level sort h, it returns any equivalent sort.
122
*/
123
 
124
high_sort *unique_high_sort
125
    PROTO_N ( ( h ) )
126
    PROTO_T ( high_sort *h )
127
{
128
    int i, j ;
129
    for ( i = 0 ; i < crt_high_sort ; i++ ) {
130
	high_sort *p = high_sorts + i ;
131
	if ( p->res == h->res && p->no_args == h->no_args ) {
132
	    boolean ok = 1 ;
133
	    if ( p == h ) return ( h ) ;
134
	    for ( j = 0 ; j < p->no_args && ok ; j++ ) {
135
		if ( p->args [j] != h->args [j] ) ok = 0 ;
136
	    }
137
	    if ( ok ) {
138
		h->id = SORT_unknown ;
139
		return ( p ) ;
140
	    }
141
	}
142
    }
143
    return ( h ) ;
144
}
145
 
146
 
147
/*
148
    FIND A HIGH-LEVEL SORT FROM ITS NAME
149
 
150
    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
152
    number is returned.
153
*/
154
 
155
sortname find_high_sort
156
    PROTO_N ( ( nm ) )
157
    PROTO_T ( char *nm )
158
{
159
    int i ;
160
    construct *q = search_cons_hash ( nm, SORT_sortname ) ;
161
    if ( q ) {
162
	if ( get_char_info ( q ) ) {
163
	    is_fatal = 0 ;
164
	    input_error ( "Illegal sort name, %s", nm ) ;
165
	}
166
	return ( ( sortname ) q->encoding ) ;
167
    }
168
    for ( i = 0 ; i < crt_high_sort ; i++ ) {
169
	high_sort *p = high_sorts + i ;
170
	if ( streq ( nm, p->name ) ) return ( p->id ) ;
171
    }
172
    return ( SORT_unknown ) ;
173
}
174
 
175
 
176
/*
177
    FORM A DECODE STRING FOR A HIGH-LEVEL SORT
178
 
179
    This routine forms the decode string corresponding to the arguments
180
    of the high level sort p.
181
*/
182
 
183
char *find_decode_string
184
    PROTO_N ( ( p ) )
185
    PROTO_T ( high_sort *p )
186
{
187
    int i, n = p->no_args ;
188
    char abuff [100], *a = abuff ;
189
    if ( n == 0 ) return ( null ) ;
190
    for ( i = 0 ; i < n ; i++ ) {
191
	sortname s = p->args [i] ;
192
	if ( is_high ( s ) ) {
193
	    sprint_high_sort ( a, s ) ;
194
	    while ( *a ) a++ ;
195
	} else {
196
	    *( a++ ) = sort_letters [s] ;
197
	}
198
    }
199
    *a = 0 ;
200
    return ( string_copy_aux ( abuff ) ) ;
201
}
202
 
203
 
204
/*
205
    FIND THE SORTNAME CORRESPONDING TO A DECODE STRING
206
 
207
    This routine finds the sort corresponding to the decode string
208
    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.
210
*/
211
 
212
char *find_sortname
213
    PROTO_N ( ( p, q ) )
214
    PROTO_T ( char *p X sortname *q )
215
{
216
    int n = 0 ;
217
    sortname s ;
218
    if ( *p == 'T' ) {
219
	while ( *( ++p ) != '#' ) n = 10 * n + ( *p - '0' ) ;
220
	s = ( sortname ) ( high_start + n ) ;
221
    } else {
222
	while ( *p != sort_letters [n] ) n++ ;
223
	s = ( sortname ) n ;
224
    }
225
    if ( q ) *q = s ;
226
    return ( p ) ;
227
}