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