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
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "list.h"
62
#include "list.h"
33
#include "utility.h"
63
#include "utility.h"
34
 
64
 
35
 
65
 
36
/*
66
/*
37
    SPARE LISTS
67
 * SPARE LISTS
38
 
68
 *
39
    This is a list of list structures which have been freed using
69
 * This is a list of list structures which have been freed using free_list.
40
    free_list.  new_list trys to allocate new list structures from
70
 * new_list tries to allocate new list structures from this list before using
41
    this list before using its internal array.
71
 * its internal array.
42
*/
72
 */
43
 
73
 
44
static list *spare_lists = null ;
74
static list *spare_lists = null;
45
 
75
 
46
 
76
 
47
/*
77
/*
48
    CREATE A NEW LIST
78
 * CREATE A NEW LIST
49
 
79
 *
50
    This routine allocates a new list structure.
80
 * This routine allocates a new list structure.
51
*/
81
 */
52
 
82
 
53
static list *new_list
83
static list *
54
    PROTO_Z ()
84
new_list(void)
55
{
85
{
56
    if ( spare_lists ) {
86
	if (spare_lists) {
57
	list *p = spare_lists ;
87
		list *p = spare_lists;
58
	spare_lists = p->next ;
88
		spare_lists = p->next;
59
	return ( p ) ;
89
		return (p);
60
    } else {
90
	} else {
61
	static int no_free = 0 ;
91
		static int no_free = 0;
62
	static list *free_objs = null ;
92
		static list *free_objs = null;
63
	if ( no_free == 0 ) {
93
		if (no_free == 0) {
64
	    no_free = 1000 ;
94
			no_free = 1000;
65
	    free_objs = alloc_nof ( list, no_free ) ;
95
			free_objs = alloc_nof(list, no_free);
66
	}
96
		}
67
	return ( free_objs + ( --no_free ) ) ;
97
		return (free_objs + (--no_free));
-
 
98
	}
-
 
99
}
-
 
100
 
-
 
101
 
-
 
102
/*
-
 
103
 * FREE A LIST
-
 
104
 *
-
 
105
 * This list returns p to free.
-
 
106
 */
-
 
107
 
-
 
108
void
-
 
109
free_list(list *p)
-
 
110
{
-
 
111
	spare_lists = add_list(p, spare_lists);
-
 
112
	return;
-
 
113
}
-
 
114
 
-
 
115
 
-
 
116
/*
-
 
117
 * JOIN TWO LISTS
-
 
118
 *
-
 
119
 * This routine joins two lists, p and q, and returns the result.
-
 
120
 */
-
 
121
 
-
 
122
list *
-
 
123
add_list(list *p, list *q)
-
 
124
{
-
 
125
	list *r;
-
 
126
	if (p == null) {
-
 
127
		return (q);
-
 
128
	}
-
 
129
	if (q == null) {
-
 
130
		return (p);
-
 
131
	}
-
 
132
	for (r = p ; r->next != null ; r = r->next) {
-
 
133
		;	/* empty */
-
 
134
	}
-
 
135
	r->next = q;
-
 
136
	return (p);
-
 
137
}
-
 
138
 
-
 
139
 
-
 
140
/*
-
 
141
 * ADD AN ITEM TO A LIST
-
 
142
 *
-
 
143
 * This routine adds a new item, s, to the end of the list p and returns the
-
 
144
 * result.
-
 
145
 */
-
 
146
 
-
 
147
list *
-
 
148
add_item(list *p, char *s)
-
 
149
{
-
 
150
	list *q, *r;
-
 
151
	q = new_list();
-
 
152
	q->item = s;
-
 
153
	q->next = null;
-
 
154
	if (p == null) {
-
 
155
		return (q);
-
 
156
	}
-
 
157
	for ( r = p ; r->next != null ; r = r->next ) {
-
 
158
		;	/* empty */
-
 
159
	}
-
 
160
	r->next = q;
-
 
161
	return (p);
-
 
162
}
-
 
163
 
-
 
164
 
-
 
165
/*
-
 
166
 * INSERT AN ITEM INTO A LIST
-
 
167
 *
-
 
168
 * This routine adds a new item, s, to the start of the list p and returns the
-
 
169
 * result.
-
 
170
 */
-
 
171
 
68
    }
172
list *
-
 
173
insert_item(char *s, list *p)
-
 
174
{
-
 
175
	list *q = new_list();
-
 
176
	q->item = s;
-
 
177
	q->next = p;
-
 
178
	return (q);
69
}
179
}
70
 
180
 
71
 
181
 
72
/*
182
/*
73
    FREE A LIST
183
 * Insert a command item in ascending order, based on their rank. Items with a
74
 
-
 
75
    This list returns p to free.
184
 * lower rank value are executed first.
76
*/
185
 */
77
 
186
 
78
void free_list
187
list*
79
    PROTO_N ( ( p ) )
-
 
80
    PROTO_T ( list *p )
188
insert_inorder(ordered_node* indata, list *inlst)
81
{
189
{
-
 
190
	list *head = inlst;
-
 
191
	list *curr = inlst;
82
    spare_lists = add_list ( p, spare_lists ) ;
192
	list *newlst  = new_list();
83
    return ;
193
	list *prev = newlst;
84
}
194
	list *tmp = inlst;
85
 
195
 
-
 
196
	newlst->item = indata;
-
 
197
	newlst->next = NULL;
86
 
198
 
-
 
199
	if (inlst == NULL){
-
 
200
	        return newlst;
87
/*
201
	}
88
    JOIN TWO LISTS
-
 
89
 
202
 
90
    This routine joins two lists, p and q, and returns the result.
203
	if (indata->rank < ((ordered_node*)curr->item)->rank){
-
 
204
	        newlst->next = inlst;
-
 
205
	        return newlst;
91
*/
206
	}
92
 
207
 
93
list *add_list
208
	while (curr != NULL &&
-
 
209
	           ((ordered_node*)curr->item)->rank <= indata->rank) {
94
    PROTO_N ( ( p, q ) )
210
	        prev = curr;
95
    PROTO_T ( list *p X list *q )
211
	        curr = curr->next;
96
{
212
	}
97
    list *r ;
213
	prev->next = newlst;
98
    if ( p == null ) return ( q ) ;
-
 
99
    if ( q == null ) return ( p ) ;
-
 
100
    for ( r = p ; r->next != null ; r = r->next ) /* empty */ ;
-
 
101
    r->next = q ;
214
	newlst->next = curr;
102
    return ( p ) ;
215
	return head;
103
}
216
}
104
 
217
 
105
 
218
 
106
/*
219
/*
107
    ADD AN ITEM TO A LIST
220
 * CONVERT A STRING TO A LIST
108
 
-
 
109
    This routine adds a new item, s, to the end of the list p and returns
-
 
110
    the result.
-
 
111
*/
-
 
112
 
-
 
113
list *add_item
-
 
114
    PROTO_N ( ( p, s ) )
-
 
115
    PROTO_T ( list *p X char *s )
-
 
116
{
-
 
117
    list *q, *r ;
-
 
118
    q = new_list () ;
-
 
119
    q->item = s ;
-
 
120
    q->next = null ;
-
 
121
    if ( p == null ) return ( q ) ;
-
 
122
    for ( r = p ; r->next != null ; r = r->next ) /* empty */ ;
-
 
123
    r->next = q ;
-
 
124
    return ( p ) ;
-
 
125
}
-
 
126
 
-
 
127
 
-
 
128
/*
221
 *
129
    INSERT AN ITEM INTO A LIST
-
 
130
 
-
 
131
    This routine adds a new item, s, to the start of the list p and
222
 * This routine converts a string to a list by breaking it at all white spaces
132
    returns the result.
223
 * (spaces and tabs).
133
*/
224
 */
134
 
225
 
135
list *insert_item
226
list *
136
    PROTO_N ( ( s, p ) )
227
make_list(char *s)
137
    PROTO_T ( char *s X list *p )
-
 
138
{
228
{
139
    list *q = new_list () ;
229
	list *r = null;
140
    q->item = s ;
230
	char *p = string_copy(s);
141
    q->next = p ;
-
 
142
    return ( q ) ;
231
	while (1) {
143
}
-
 
144
 
-
 
145
 
-
 
146
/*
-
 
147
    CONVERT A STRING TO A LIST
232
		while (*p == ' ' || *p == '\t') {
148
 
-
 
149
    This routine converts a string to a list by breaking it at all white
-
 
150
    spaces (spaces and tabs).
233
			*(p++) = 0;
151
*/
234
		}
152
 
-
 
153
list *make_list
235
		if (*p == 0) {
154
    PROTO_N ( ( s ) )
-
 
155
    PROTO_T ( char *s )
236
			break;
156
{
237
		}
157
    list *r = null ;
-
 
158
    char *p = string_copy ( s ) ;
-
 
159
    while ( 1 ) {
-
 
160
	while ( *p == ' ' || *p == '\t' ) *( p++ ) = 0 ;
-
 
161
	if ( *p == 0 ) break ;
-
 
162
	r = add_item ( r, p ) ;
238
		r = add_item(r, p);
163
	while ( *p && *p != ' ' && *p != '\t' ) p++ ;
239
		while (*p && *p != ' ' && *p != '\t') {
-
 
240
			p++;
164
    }
241
		}
-
 
242
	}
165
    return ( r ) ;
243
	return (r);
166
}
244
}