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 |
/**** bistream.h --- Binary input stream handling.
|
|
|
32 |
*
|
|
|
33 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
34 |
*
|
|
|
35 |
**** Commentary:
|
|
|
36 |
*
|
|
|
37 |
***=== INTRODUCTION =========================================================
|
|
|
38 |
*
|
|
|
39 |
* This file specifies the interface to the binary input stream facility.
|
|
|
40 |
*
|
|
|
41 |
***=== TYPES ================================================================
|
|
|
42 |
*
|
|
|
43 |
** Type: BIStreamT
|
|
|
44 |
** Type: BIStreamP
|
|
|
45 |
** Repr: <private>
|
|
|
46 |
*
|
|
|
47 |
* This is the input stream type.
|
|
|
48 |
*
|
|
|
49 |
***=== FUNCTIONS ============================================================
|
|
|
50 |
*
|
|
|
51 |
** Function: void bistream_init
|
|
|
52 |
* PROTO_S ((BIStreamP bistream))
|
|
|
53 |
** Exceptions:
|
|
|
54 |
*
|
|
|
55 |
* This function initialises the specified bistream not to read from any file.
|
|
|
56 |
*
|
|
|
57 |
** Function: BoolT bistream_open
|
|
|
58 |
* PROTO_S ((BIStreamP bistream, CStringP name))
|
|
|
59 |
** Exceptions:
|
|
|
60 |
*
|
|
|
61 |
* This function initialises the specified bistream to read from the file with
|
|
|
62 |
* the specified name. The name should not be modified or deallocated until
|
|
|
63 |
* the bistream has been closed. If the file cannot be opened, the function
|
|
|
64 |
* returns false. If the file is opened successfully, the function returns
|
|
|
65 |
* true.
|
|
|
66 |
*
|
|
|
67 |
** Function: void bistream_assign
|
|
|
68 |
* PROTO_S ((BIStreamP to, BIStreamP from))
|
|
|
69 |
** Exceptions:
|
|
|
70 |
*
|
|
|
71 |
* This function assigns the from bistream to the to bistream. The from
|
|
|
72 |
* bistream should not be used again.
|
|
|
73 |
*
|
|
|
74 |
** Function: BoolT bistream_is_open
|
|
|
75 |
* PROTO_S ((BIStreamP bistream))
|
|
|
76 |
*
|
|
|
77 |
* This function returns true if the specified bistream is reading from a file,
|
|
|
78 |
* and false otherwise.
|
|
|
79 |
*
|
|
|
80 |
** Function: unsigned bistream_read_chars
|
|
|
81 |
* PROTO_S ((BIStreamP bistream, unsigned length,
|
|
|
82 |
* CStringP chars))
|
|
|
83 |
** Exceptions: XX_bistream_read_error
|
|
|
84 |
*
|
|
|
85 |
* This function reads the next length characters from the specified bistream.
|
|
|
86 |
* The characters read are placed in the chars vector, which should be long
|
|
|
87 |
* enough to hold at least length characters. The function returns the number
|
|
|
88 |
* of characters actually read.
|
|
|
89 |
*
|
|
|
90 |
** Function: unsigned bistream_read_bytes
|
|
|
91 |
* PROTO_S ((BIStreamP bistream, unsigned length,
|
|
|
92 |
* ByteP bytes))
|
|
|
93 |
** Exceptions: XX_bistream_read_error
|
|
|
94 |
*
|
|
|
95 |
* This function reads the next length bytes from the specified bistream. The
|
|
|
96 |
* bytes read are placed in the bytes vector, which should be long enough to
|
|
|
97 |
* hold at least length bytes. The function returns the number of bytes
|
|
|
98 |
* actually read.
|
|
|
99 |
*
|
|
|
100 |
** Function: BoolT bistream_read_byte
|
|
|
101 |
* PROTO_S ((BIStreamP bistream, ByteT *byte_ref))
|
|
|
102 |
** Exceptions: XX_bistream_read_error
|
|
|
103 |
*
|
|
|
104 |
* This function reads the next character from the specified bistream. If a
|
|
|
105 |
* byte is read then the byte is assigned to the reference argument, and the
|
|
|
106 |
* function returns true. If the end of file is reached, the function returns
|
|
|
107 |
* false.
|
|
|
108 |
*
|
|
|
109 |
** Function: unsigned bistream_byte
|
|
|
110 |
* PROTO_S ((BIStreamP bistream))
|
|
|
111 |
** Exceptions:
|
|
|
112 |
*
|
|
|
113 |
* This function returns the number of bytes that have been read from the
|
|
|
114 |
* specified bistream.
|
|
|
115 |
*
|
|
|
116 |
** Function: CStringP bistream_name
|
|
|
117 |
* PROTO_S ((BIStreamP bistream))
|
|
|
118 |
** Exceptions:
|
|
|
119 |
*
|
|
|
120 |
* This function returns the name of the file from which the specified
|
|
|
121 |
* bistream is reading. The return value should not be modified or
|
|
|
122 |
* deallocated.
|
|
|
123 |
*
|
|
|
124 |
** Function: void bistream_rewind
|
|
|
125 |
* PROTO_S ((BIStreamP bistream))
|
|
|
126 |
** Exceptions:
|
|
|
127 |
*
|
|
|
128 |
* This function rewinds the specified bistream.
|
|
|
129 |
*
|
|
|
130 |
** Function: void bistream_close
|
|
|
131 |
* PROTO_S ((BIStreamP bistream))
|
|
|
132 |
** Exceptions:
|
|
|
133 |
*
|
|
|
134 |
* This function closes the specified bistream.
|
|
|
135 |
*
|
|
|
136 |
***=== EXCEPTIONS ===========================================================
|
|
|
137 |
*
|
|
|
138 |
** Exception: XX_bistream_read_error (CStringP name)
|
|
|
139 |
*
|
|
|
140 |
* This exception is raised if a read attempt fails. The data thrown is a
|
|
|
141 |
* copy of the name of the file that the read error occured on. The copy
|
|
|
142 |
* should be deallocated when finished with.
|
|
|
143 |
*
|
|
|
144 |
**** Change Log:
|
|
|
145 |
* $Log: bistream.h,v $
|
|
|
146 |
* Revision 1.1.1.1 1998/01/17 15:57:17 release
|
|
|
147 |
* First version to be checked into rolling release.
|
|
|
148 |
*
|
|
|
149 |
* Revision 1.2 1994/12/12 11:45:19 smf
|
|
|
150 |
* Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
|
|
|
151 |
* OSSG C Coding Standards.
|
|
|
152 |
*
|
|
|
153 |
* Revision 1.1.1.1 1994/07/25 16:06:13 smf
|
|
|
154 |
* Initial import of os-interface shared files.
|
|
|
155 |
*
|
|
|
156 |
**/
|
|
|
157 |
|
|
|
158 |
/****************************************************************************/
|
|
|
159 |
|
|
|
160 |
#ifndef H_BISTREAM
|
|
|
161 |
#define H_BISTREAM
|
|
|
162 |
|
|
|
163 |
#include "os-interface.h"
|
|
|
164 |
#include "exception.h"
|
|
|
165 |
|
|
|
166 |
/*--------------------------------------------------------------------------*/
|
|
|
167 |
|
|
|
168 |
typedef struct BIStreamT {
|
|
|
169 |
FILE *file;
|
|
|
170 |
unsigned bytes;
|
|
|
171 |
CStringP name;
|
|
|
172 |
} BIStreamT, *BIStreamP;
|
|
|
173 |
|
|
|
174 |
/*--------------------------------------------------------------------------*/
|
|
|
175 |
|
|
|
176 |
extern ExceptionP XX_bistream_read_error;
|
|
|
177 |
|
|
|
178 |
/*--------------------------------------------------------------------------*/
|
|
|
179 |
|
|
|
180 |
extern void bistream_init
|
|
|
181 |
PROTO_S ((BIStreamP));
|
|
|
182 |
extern BoolT bistream_open
|
|
|
183 |
PROTO_S ((BIStreamP, CStringP));
|
|
|
184 |
extern void bistream_assign
|
|
|
185 |
PROTO_S ((BIStreamP, BIStreamP));
|
|
|
186 |
extern BoolT bistream_is_open
|
|
|
187 |
PROTO_S ((BIStreamP));
|
|
|
188 |
extern unsigned bistream_read_chars
|
|
|
189 |
PROTO_S ((BIStreamP, unsigned, CStringP));
|
|
|
190 |
extern unsigned bistream_read_bytes
|
|
|
191 |
PROTO_S ((BIStreamP, unsigned, ByteP));
|
|
|
192 |
extern BoolT bistream_read_byte
|
|
|
193 |
PROTO_S ((BIStreamP, ByteT *));
|
|
|
194 |
extern unsigned bistream_byte
|
|
|
195 |
PROTO_S ((BIStreamP));
|
|
|
196 |
extern CStringP bistream_name
|
|
|
197 |
PROTO_S ((BIStreamP));
|
|
|
198 |
extern void bistream_rewind
|
|
|
199 |
PROTO_S ((BIStreamP));
|
|
|
200 |
extern void bistream_close
|
|
|
201 |
PROTO_S ((BIStreamP));
|
|
|
202 |
|
|
|
203 |
#endif /* !defined (H_BISTREAM) */
|