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-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 63... Line 93...
63
 * standard input.  The ``istream_setup'' function must be called before this
93
 * standard input.  The ``istream_setup'' function must be called before this
64
 * constant is used.
94
 * constant is used.
65
 *
95
 *
66
 ***=== FUNCTIONS ============================================================
96
 ***=== FUNCTIONS ============================================================
67
 *
97
 *
68
 ** Function:	void			istream_setup
98
 ** Function:	void istream_setup(void)
69
 *			PROTO_S ((void))
-
 
70
 ** Exceptions:
99
 ** Exceptions:
71
 *
100
 *
72
 * This function initialises the input stream facility.  It should be called
101
 * This function initialises the input stream facility.  It should be called
73
 * before any other istream manipulation function.
102
 * before any other istream manipulation function.
74
 *
103
 *
75
 ** Function:	void			istream_init
104
 ** Function:	void istream_init(IStreamP istream)
76
 *			PROTO_S ((IStreamP istream))
-
 
77
 ** Exceptions:
105
 ** Exceptions:
78
 *
106
 *
79
 * This function initialises the specified istream not to read from any file.
107
 * This function initialises the specified istream not to read from any file.
80
 *
108
 *
81
 ** Function:	BoolT			istream_open
-
 
82
 *			PROTO_S ((IStreamP istream, CStringP name))
109
 ** Function:	BoolT istream_open(IStreamP istream, CStringP name)
83
 ** Exceptions: XX_dalloc_no_memory, XX_istream_read_error
110
 ** Exceptions: XX_dalloc_no_memory, XX_istream_read_error
84
 *
111
 *
85
 * This function initialises the specified istream to read from the file with
112
 * This function initialises the specified istream to read from the file with
86
 * the specified name.  The name should not be modified or deallocated until
113
 * the specified name.  The name should not be modified or deallocated until
87
 * the istream has been closed.  If the file cannot be opened, the function
114
 * the istream has been closed.  If the file cannot be opened, the function
88
 * returns false. If the file is opened successfully, the function returns
115
 * returns false. If the file is opened successfully, the function returns
89
 * true.
116
 * true.
90
 *
117
 *
91
 ** Function:	void			istream_assign
-
 
92
 *			PROTO_S ((IStreamP to, IStreamP from))
118
 ** Function:	void istream_assign(IStreamP to, IStreamP from)
93
 ** Exceptions:
119
 ** Exceptions:
94
 *
120
 *
95
 * This function assigns the from istream to the to istream.  The from istream
121
 * This function assigns the from istream to the to istream.  The from istream
96
 * should not be used again.
122
 * should not be used again.
97
 *
123
 *
98
 ** Function:	BoolT			istream_is_open
124
 ** Function:	BoolT istream_is_open(IStreamP istream)
99
 *			PROTO_S ((IStreamP istream))
-
 
100
 *
125
 *
101
 * This function returns true if the specified istream is reading from a file,
126
 * This function returns true if the specified istream is reading from a file,
102
 * and false otherwise.
127
 * and false otherwise.
103
 *
128
 *
104
 ** Function:	BoolT			istream_read_char
-
 
105
 *			PROTO_S ((IStreamP istream, char *c_ref))
129
 ** Function:	BoolT istream_read_char(IStreamP istream, char *c_ref)
106
 ** Exceptions:	XX_dalloc_no_memory, XX_istream_read_error
130
 ** Exceptions:	XX_dalloc_no_memory, XX_istream_read_error
107
 *
131
 *
108
 * This function reads the next character from the specified istream (and
132
 * This function reads the next character from the specified istream (and
109
 * advances the character pointer).  If a character is read then the character
133
 * advances the character pointer).  If a character is read then the character
110
 * is assigned to the reference argument, and the function returns true.  If
134
 * is assigned to the reference argument, and the function returns true.  If
111
 * the end of file is reached, the function returns false.  If the character
135
 * the end of file is reached, the function returns false.  If the character
112
 * read is a newline, then the istream's line count is incremented.
136
 * read is a newline, then the istream's line count is incremented.
113
 *
137
 *
114
 ** Function:	BoolT			istream_peek_char
-
 
115
 *			PROTO_S ((IStreamP istream, char *c_ref))
138
 ** Function:	BoolT istream_peek_char(IStreamP istream, char *c_ref)
116
 ** Exceptions:	XX_dalloc_no_memory, XX_istream_read_error
139
 ** Exceptions:	XX_dalloc_no_memory, XX_istream_read_error
117
 *
140
 *
118
 * This function reads the next character from the specified istream (but does
141
 * This function reads the next character from the specified istream (but does
119
 * not advance the character pointer).  If a character is read then the
142
 * not advance the character pointer).  If a character is read then the
120
 * character is assigned to the reference argument, and the function returns
143
 * character is assigned to the reference argument, and the function returns
121
 * true.  If the end of file is reached, the function returns false.
144
 * true.  If the end of file is reached, the function returns false.
122
 *
145
 *
123
 ** Function:	IStreamStatusT		istream_read_escaped_char
146
 ** Function:	IStreamStatusT istream_read_escaped_char(IStreamP istream,
124
 *			PROTO_S ((IStreamP istream, char *c_ref))
147
 *							 char *c_ref)
125
 ** Exceptions:	XX_dalloc_no_memory, XX_istream_read_error
148
 ** Exceptions:	XX_dalloc_no_memory, XX_istream_read_error
126
 *
149
 *
127
 * This function reads a character sequence from the specified istream, and
150
 * This function reads a character sequence from the specified istream, and
128
 * parses it as an escaped character sequence.  Normally, the character to
151
 * parses it as an escaped character sequence.  Normally, the character to
129
 * which the sequence evaluates is assigned to the reference argument and
152
 * which the sequence evaluates is assigned to the reference argument and
Line 132... Line 155...
132
 * error).  If there is an error in the syntax of the character sequence, then
155
 * error).  If there is an error in the syntax of the character sequence, then
133
 * ``ISTREAM_STAT_SYNTAX_ERROR'' is returned.  If any of the characters read
156
 * ``ISTREAM_STAT_SYNTAX_ERROR'' is returned.  If any of the characters read
134
 * are newline characters, then the istream's line counter will be incremented
157
 * are newline characters, then the istream's line counter will be incremented
135
 * for each newline.
158
 * for each newline.
136
 *
159
 *
137
 ** Function:	void			istream_inc_line
160
 ** Function:	void istream_inc_line(IStreamP istream)
138
 *			PROTO_S ((IStreamP istream))
-
 
139
 ** Exceptions:
161
 ** Exceptions:
140
 *
162
 *
141
 * This function increments the specified istream's line counter.  It should
163
 * This function increments the specified istream's line counter.  It should
142
 * only really be called as specified in the documentation for the
164
 * only really be called as specified in the documentation for the
143
 * ``ISTREAM_READ_CHAR'' macro.
165
 * ``ISTREAM_READ_CHAR'' macro.
144
 *
166
 *
145
 ** Function:	unsigned		istream_line
167
 ** Function:	unsigned istream_line(IStreamP istream)
146
 *			PROTO_S ((IStreamP istream))
-
 
147
 ** Exceptions:
168
 ** Exceptions:
148
 *
169
 *
149
 * This function returns the line number of the specified istream (one more
170
 * This function returns the line number of the specified istream (one more
150
 * than the number of newlines that have been read).
171
 * than the number of newlines that have been read).
151
 *
172
 *
152
 ** Function:	CStringP		istream_name
173
 ** Function:	CStringP istream_name(IStreamP istream)
153
 *			PROTO_S ((IStreamP istream))
-
 
154
 ** Exceptions:
174
 ** Exceptions:
155
 *
175
 *
156
 * This function returns the name of the file from which the specified istream
176
 * This function returns the name of the file from which the specified istream
157
 * is reading. The return value should not be modified or deallocated.
177
 * is reading. The return value should not be modified or deallocated.
158
 *
178
 *
159
 ** Function:	void			istream_close
179
 ** Function:	void istream_close(IStreamP istream)
160
 *			PROTO_S ((IStreamP istream))
-
 
161
 ** Exceptions:
180
 ** Exceptions:
162
 *
181
 *
163
 * This function closes the specified istream.
182
 * This function closes the specified istream.
164
 *
183
 *
165
 ***=== MACROS ===============================================================
184
 ***=== MACROS ===============================================================
Line 262... Line 281...
262
extern IStreamT		 *const istream_input;
281
extern IStreamT		 *const istream_input;
263
 
282
 
264
/*--------------------------------------------------------------------------*/
283
/*--------------------------------------------------------------------------*/
265
 
284
 
266
extern void			istream_setup
285
extern void			istream_setup
267
	PROTO_S ((void));
286
(void);
268
extern void			istream_init
287
extern void			istream_init
269
	PROTO_S ((IStreamP));
288
(IStreamP);
270
extern BoolT			istream_open
289
extern BoolT			istream_open
271
	PROTO_S ((IStreamP, CStringP));
290
(IStreamP, CStringP);
272
extern void			istream_assign
291
extern void			istream_assign
273
	PROTO_S ((IStreamP, IStreamP));
292
(IStreamP, IStreamP);
274
extern BoolT			istream_is_open
293
extern BoolT			istream_is_open
275
	PROTO_S ((IStreamP));
294
(IStreamP);
276
extern BoolT			istream_read_char
295
extern BoolT			istream_read_char
277
	PROTO_S ((IStreamP, char *));
296
(IStreamP, char *);
278
extern BoolT			istream_peek_char
297
extern BoolT			istream_peek_char
279
	PROTO_S ((IStreamP, char *));
298
(IStreamP, char *);
280
extern IStreamStatusT		istream_read_escaped_char
299
extern IStreamStatusT		istream_read_escaped_char
281
	PROTO_S ((IStreamP, char *));
300
(IStreamP, char *);
282
extern void			istream_inc_line
301
extern void			istream_inc_line
283
	PROTO_S ((IStreamP));
302
(IStreamP);
284
extern unsigned			istream_line
303
extern unsigned			istream_line
285
	PROTO_S ((IStreamP));
304
(IStreamP);
286
extern CStringP			istream_name
305
extern CStringP			istream_name
287
	PROTO_S ((IStreamP));
306
(IStreamP);
288
extern void			istream_close
307
extern void			istream_close
289
	PROTO_S ((IStreamP));
308
(IStreamP);
290
 
309
 
291
/*--------------------------------------------------------------------------*/
310
/*--------------------------------------------------------------------------*/
292
 
311
 
293
extern void			X__istream_fill_buffer
312
extern void			X__istream_fill_buffer
294
	PROTO_S ((IStreamP));
313
(IStreamP);
295
 
314
 
296
/*--------------------------------------------------------------------------*/
315
/*--------------------------------------------------------------------------*/
297
 
316
 
298
#define ISTREAM_READ_CHAR(istream) \
317
#define ISTREAM_READ_CHAR(istream)\
299
(((istream)->read_last = TRUE), (*((istream)->current) ++))
318
    (((istream)->read_last = TRUE), (*((istream)->current)++))
300
 
319
 
301
#define ISTREAM_PEEK_CHAR(istream) \
320
#define ISTREAM_PEEK_CHAR(istream)\
302
(((istream)->read_last = FALSE), (*((istream)->current)))
321
    (((istream)->read_last = FALSE), (*((istream)->current)))
303
 
322
 
304
#define ISTREAM_HANDLE_NULL(istream,redo,eof) \
323
#define ISTREAM_HANDLE_NULL(istream,redo,eof)\
305
{ \
324
{ \
306
    IStreamP X___is = (istream); \
325
    IStreamP X___is = (istream); \
307
    if (X___is->read_last) { \
326
    if (X___is->read_last) { \
308
	if (X___is->current == X___is->end) { \
327
	if (X___is->current == X___is->end) { \
309
	    if (X___is->end == X___is->limit) { \
328
	    if (X___is->end == X___is->limit) { \
310
		X__istream_fill_buffer (X___is); \
329
		X__istream_fill_buffer(X___is); \
311
		goto redo; \
330
		goto redo; \
312
	    } else { \
331
	    } else { \
313
		X___is->current --; \
332
		X___is->current--; \
314
		goto eof; \
333
		goto eof; \
315
	    } \
334
	    } \
316
	} \
335
	} \
317
    } else { \
336
    } else { \
318
	if (X___is->current == (X___is->end - 1)) { \
337
	if (X___is->current == (X___is->end - 1)) { \
319
	    if (X___is->end == X___is->limit) { \
338
	    if (X___is->end == X___is->limit) { \
320
		X__istream_fill_buffer (X___is); \
339
		X__istream_fill_buffer(X___is); \
321
		goto redo; \
340
		goto redo; \
322
	    } else { \
341
	    } else { \
323
		goto eof; \
342
		goto eof; \
324
	    } \
343
	    } \
325
	} \
344
	} \
Line 327... Line 346...
327
}
346
}
328
 
347
 
329
/*--------------------------------------------------------------------------*/
348
/*--------------------------------------------------------------------------*/
330
 
349
 
331
#ifdef FS_FAST
350
#ifdef FS_FAST
332
#define istream_init(is) ((is)->name = NIL (CStringP))
351
#define istream_init(is)	((is)->name = NIL(CStringP))
333
#define istream_is_open(is) ((is)->name != NIL (CStringP))
352
#define istream_is_open(is)	((is)->name != NIL(CStringP))
334
#define istream_inc_line(is) ((is)->line ++)
353
#define istream_inc_line(is)	((is)->line++)
335
#define istream_line(is) ((is)->line)
354
#define istream_line(is)	((is)->line)
336
#define istream_name(is) ((is)->name)
355
#define istream_name(is)	((is)->name)
337
#endif /* defined (FS_FAST) */
356
#endif /* defined (FS_FAST) */
338
 
357
 
339
#endif /* !defined (H_ISTREAM) */
358
#endif /* !defined (H_ISTREAM) */