2 |
7u83 |
1 |
/*
|
7 |
7u83 |
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 |
*/
|
|
|
31 |
/*
|
2 |
7u83 |
32 |
Crown Copyright (c) 1997
|
7 |
7u83 |
33 |
|
2 |
7u83 |
34 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
35 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
36 |
acting through the Defence Evaluation and Research Agency
|
|
|
37 |
(DERA). It is made available to Recipients with a
|
|
|
38 |
royalty-free licence for its use, reproduction, transfer
|
|
|
39 |
to other parties and amendment for any purpose not excluding
|
|
|
40 |
product development provided that any such use et cetera
|
|
|
41 |
shall be deemed to be acceptance of the following conditions:-
|
7 |
7u83 |
42 |
|
2 |
7u83 |
43 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
44 |
reproduced upon any copies or amended versions of it;
|
7 |
7u83 |
45 |
|
2 |
7u83 |
46 |
(2) Any amended version of it shall be clearly marked to
|
|
|
47 |
show both the nature of and the organisation responsible
|
|
|
48 |
for the relevant amendment or amendments;
|
7 |
7u83 |
49 |
|
2 |
7u83 |
50 |
(3) Its onward transfer from a recipient to another
|
|
|
51 |
party shall be deemed to be that party's acceptance of
|
|
|
52 |
these conditions;
|
7 |
7u83 |
53 |
|
2 |
7u83 |
54 |
(4) DERA gives no warranty or assurance as to its
|
|
|
55 |
quality or suitability for any purpose and DERA accepts
|
|
|
56 |
no liability whatsoever in relation to any use to which
|
|
|
57 |
it may be put.
|
|
|
58 |
*/
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
/**** bistream.h --- Binary input stream handling.
|
|
|
62 |
*
|
|
|
63 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
64 |
*
|
|
|
65 |
**** Commentary:
|
|
|
66 |
*
|
|
|
67 |
***=== INTRODUCTION =========================================================
|
|
|
68 |
*
|
|
|
69 |
* This file specifies the interface to the binary input stream facility.
|
|
|
70 |
*
|
|
|
71 |
***=== TYPES ================================================================
|
|
|
72 |
*
|
|
|
73 |
** Type: BIStreamT
|
|
|
74 |
** Type: BIStreamP
|
|
|
75 |
** Repr: <private>
|
|
|
76 |
*
|
|
|
77 |
* This is the input stream type.
|
|
|
78 |
*
|
|
|
79 |
***=== FUNCTIONS ============================================================
|
|
|
80 |
*
|
7 |
7u83 |
81 |
** Function: void bistream_init(BIStreamP bistream)
|
2 |
7u83 |
82 |
** Exceptions:
|
|
|
83 |
*
|
|
|
84 |
* This function initialises the specified bistream not to read from any file.
|
|
|
85 |
*
|
7 |
7u83 |
86 |
** Function: BoolT bistream_open(BIStreamP bistream, CStringP name)
|
2 |
7u83 |
87 |
** Exceptions:
|
|
|
88 |
*
|
|
|
89 |
* This function initialises the specified bistream to read from the file with
|
|
|
90 |
* the specified name. The name should not be modified or deallocated until
|
|
|
91 |
* the bistream has been closed. If the file cannot be opened, the function
|
|
|
92 |
* returns false. If the file is opened successfully, the function returns
|
|
|
93 |
* true.
|
|
|
94 |
*
|
7 |
7u83 |
95 |
** Function: void bistream_assign(BIStreamP to, BIStreamP from)
|
2 |
7u83 |
96 |
** Exceptions:
|
|
|
97 |
*
|
|
|
98 |
* This function assigns the from bistream to the to bistream. The from
|
|
|
99 |
* bistream should not be used again.
|
|
|
100 |
*
|
7 |
7u83 |
101 |
** Function: BoolT bistream_is_open(BIStreamP bistream)
|
2 |
7u83 |
102 |
*
|
|
|
103 |
* This function returns true if the specified bistream is reading from a file,
|
|
|
104 |
* and false otherwise.
|
|
|
105 |
*
|
7 |
7u83 |
106 |
** Function: unsigned bistream_read_chars(BIStreamP bistream,
|
|
|
107 |
* unsigned length, CStringP chars)
|
2 |
7u83 |
108 |
** Exceptions: XX_bistream_read_error
|
|
|
109 |
*
|
|
|
110 |
* This function reads the next length characters from the specified bistream.
|
|
|
111 |
* The characters read are placed in the chars vector, which should be long
|
|
|
112 |
* enough to hold at least length characters. The function returns the number
|
|
|
113 |
* of characters actually read.
|
|
|
114 |
*
|
7 |
7u83 |
115 |
** Function: unsigned bistream_read_bytes(BIStreamP bistream,
|
|
|
116 |
* unsigned length, ByteP bytes)
|
2 |
7u83 |
117 |
** Exceptions: XX_bistream_read_error
|
|
|
118 |
*
|
|
|
119 |
* This function reads the next length bytes from the specified bistream. The
|
|
|
120 |
* bytes read are placed in the bytes vector, which should be long enough to
|
|
|
121 |
* hold at least length bytes. The function returns the number of bytes
|
|
|
122 |
* actually read.
|
|
|
123 |
*
|
7 |
7u83 |
124 |
** Function: BoolT bistream_read_byte(BIStreamP bistream, ByteT *byte_ref)
|
2 |
7u83 |
125 |
** Exceptions: XX_bistream_read_error
|
|
|
126 |
*
|
|
|
127 |
* This function reads the next character from the specified bistream. If a
|
|
|
128 |
* byte is read then the byte is assigned to the reference argument, and the
|
|
|
129 |
* function returns true. If the end of file is reached, the function returns
|
|
|
130 |
* false.
|
|
|
131 |
*
|
7 |
7u83 |
132 |
** Function: unsigned bistream_byte(BIStreamP bistream)
|
2 |
7u83 |
133 |
** Exceptions:
|
|
|
134 |
*
|
|
|
135 |
* This function returns the number of bytes that have been read from the
|
|
|
136 |
* specified bistream.
|
|
|
137 |
*
|
7 |
7u83 |
138 |
** Function: CStringP bistream_name(BIStreamP bistream)
|
2 |
7u83 |
139 |
** Exceptions:
|
|
|
140 |
*
|
|
|
141 |
* This function returns the name of the file from which the specified
|
|
|
142 |
* bistream is reading. The return value should not be modified or
|
|
|
143 |
* deallocated.
|
|
|
144 |
*
|
7 |
7u83 |
145 |
** Function: void bistream_rewind(BIStreamP bistream)
|
2 |
7u83 |
146 |
** Exceptions:
|
|
|
147 |
*
|
|
|
148 |
* This function rewinds the specified bistream.
|
|
|
149 |
*
|
7 |
7u83 |
150 |
** Function: void bistream_close(BIStreamP bistream)
|
2 |
7u83 |
151 |
** Exceptions:
|
|
|
152 |
*
|
|
|
153 |
* This function closes the specified bistream.
|
|
|
154 |
*
|
|
|
155 |
***=== EXCEPTIONS ===========================================================
|
|
|
156 |
*
|
|
|
157 |
** Exception: XX_bistream_read_error (CStringP name)
|
|
|
158 |
*
|
|
|
159 |
* This exception is raised if a read attempt fails. The data thrown is a
|
|
|
160 |
* copy of the name of the file that the read error occured on. The copy
|
|
|
161 |
* should be deallocated when finished with.
|
|
|
162 |
*
|
|
|
163 |
**** Change Log:
|
|
|
164 |
* $Log: bistream.h,v $
|
|
|
165 |
* Revision 1.1.1.1 1998/01/17 15:57:17 release
|
|
|
166 |
* First version to be checked into rolling release.
|
|
|
167 |
*
|
|
|
168 |
* Revision 1.2 1994/12/12 11:45:19 smf
|
|
|
169 |
* Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
|
|
|
170 |
* OSSG C Coding Standards.
|
|
|
171 |
*
|
|
|
172 |
* Revision 1.1.1.1 1994/07/25 16:06:13 smf
|
|
|
173 |
* Initial import of os-interface shared files.
|
|
|
174 |
*
|
|
|
175 |
**/
|
|
|
176 |
|
|
|
177 |
/****************************************************************************/
|
|
|
178 |
|
|
|
179 |
#ifndef H_BISTREAM
|
|
|
180 |
#define H_BISTREAM
|
|
|
181 |
|
|
|
182 |
#include "os-interface.h"
|
|
|
183 |
#include "exception.h"
|
|
|
184 |
|
|
|
185 |
/*--------------------------------------------------------------------------*/
|
|
|
186 |
|
|
|
187 |
typedef struct BIStreamT {
|
|
|
188 |
FILE *file;
|
|
|
189 |
unsigned bytes;
|
|
|
190 |
CStringP name;
|
|
|
191 |
} BIStreamT, *BIStreamP;
|
|
|
192 |
|
|
|
193 |
/*--------------------------------------------------------------------------*/
|
|
|
194 |
|
|
|
195 |
extern ExceptionP XX_bistream_read_error;
|
|
|
196 |
|
|
|
197 |
/*--------------------------------------------------------------------------*/
|
|
|
198 |
|
|
|
199 |
extern void bistream_init
|
7 |
7u83 |
200 |
(BIStreamP);
|
2 |
7u83 |
201 |
extern BoolT bistream_open
|
7 |
7u83 |
202 |
(BIStreamP, CStringP);
|
2 |
7u83 |
203 |
extern void bistream_assign
|
7 |
7u83 |
204 |
(BIStreamP, BIStreamP);
|
2 |
7u83 |
205 |
extern BoolT bistream_is_open
|
7 |
7u83 |
206 |
(BIStreamP);
|
2 |
7u83 |
207 |
extern unsigned bistream_read_chars
|
7 |
7u83 |
208 |
(BIStreamP, unsigned, CStringP);
|
2 |
7u83 |
209 |
extern unsigned bistream_read_bytes
|
7 |
7u83 |
210 |
(BIStreamP, unsigned, ByteP);
|
2 |
7u83 |
211 |
extern BoolT bistream_read_byte
|
7 |
7u83 |
212 |
(BIStreamP, ByteT *);
|
2 |
7u83 |
213 |
extern unsigned bistream_byte
|
7 |
7u83 |
214 |
(BIStreamP);
|
2 |
7u83 |
215 |
extern CStringP bistream_name
|
7 |
7u83 |
216 |
(BIStreamP);
|
2 |
7u83 |
217 |
extern void bistream_rewind
|
7 |
7u83 |
218 |
(BIStreamP);
|
2 |
7u83 |
219 |
extern void bistream_close
|
7 |
7u83 |
220 |
(BIStreamP);
|
2 |
7u83 |
221 |
|
|
|
222 |
#endif /* !defined (H_BISTREAM) */
|