Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 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
 */
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
/**** ostream.h --- Output 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 output stream facility.
70
 *
71
 ***=== TYPES ================================================================
72
 *
73
 ** Type:	OStreamT
74
 ** Type:	OStreamP
75
 ** Repr:	<private>
76
 *
77
 * This is the output stream type.
78
 *
79
 ***=== CONSTANTS ============================================================
80
 *
81
 ** Constant:	ostream_output
82
 *
83
 * This is the standard output stream.  Its initial buffering state is
84
 * undefined.  The ``ostream_setup'' function must be called before this
85
 * constant is used.
86
 *
87
 ** Constant:	ostream_error
88
 *
89
 * This is the standard error stream.  Its initial buffering state is
90
 * undefined.  The ``ostream_setup'' function must be called before this
91
 * constant is used.
92
 *
93
 ***=== FUNCTIONS ============================================================
94
 *
95
 ** Function:	void			ostream_setup
7 7u83 96
 *			(void)
2 7u83 97
 ** Exceptions:
98
 *
99
 * This function initialises the output stream facility.  It should be called
100
 * before any other ostream manipulation function.
101
 *
102
 ** Function:	void			ostream_init
7 7u83 103
 *			(OStreamP ostream)
2 7u83 104
 ** Exceptions:
105
 *
106
 * This function initialises the specified ostream not to write to any file.
107
 *
108
 ** Function:	BoolT			ostream_open
7 7u83 109
 *			(OStreamP ostream, CStringP name)
2 7u83 110
 ** Exceptions:
111
 *
112
 * This function initialises the specified ostream to write to the file with
113
 * the specified name.  If the file cannot be opened, the function returns
114
 * false.  If the file is opened successfully, the function returns true.  The
115
 * name should not be modified or deallocated until the ostream has been
116
 * closed.  The initial buffering state of the ostream is fully buffered.
117
 *
118
 ** Function:	BoolT			ostream_is_open
7 7u83 119
 *			(OStreamP ostream)
2 7u83 120
 ** Exceptions:
121
 *
122
 * This function returns true if the specified ostream is writing to a file,
123
 * and false otherwise.
124
 *
125
 ** Function:	void			ostream_buffer
7 7u83 126
 *			(OStreamP ostream)
2 7u83 127
 ** Exceptions:
128
 *
129
 * This function sets the buffering state of the specified ostream to fully
130
 * buffered.
131
 *
132
 ** Function:	void			ostream_unbuffer
7 7u83 133
 *			(OStreamP ostream)
2 7u83 134
 *
135
 * This function sets the buffering state of the specified ostream to
136
 * unbuffered.
137
 *
138
 ** Function:	void			ostream_close
7 7u83 139
 *			(OStreamP ostream)
2 7u83 140
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
141
 *
142
 * This function closes the specified ostream.
143
 *
144
 ** Function:	void			ostream_flush
7 7u83 145
 *			(OStreamP ostream)
2 7u83 146
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
147
 *
148
 * This function flushes the ostream's output buffer.
149
 *
150
 ** Function:	CStringP		ostream_name
7 7u83 151
 *			(OStreamP ostream)
2 7u83 152
 ** Exceptions:
153
 *
154
 * This function returns the name of the file that the specified ostream is
155
 * writing to.  The return value should not be modified or deallocated.
156
 *
157
 ** Function:	unsigned		ostream_line
7 7u83 158
 *			(OStreamP ostream)
2 7u83 159
 ** Exceptions:
160
 *
161
 * This function returns one more than the number of newlines that have been
162
 * written to the specified ostream.  The result is undefined if the stream
163
 * is not open.
164
 *
165
 ** Function:	void			write_newline
7 7u83 166
 *			(OStreamP ostream)
2 7u83 167
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
168
 *
169
 * This function writes a newline to the specified ostream.
170
 *
171
 ** Function:	void			write_tab
7 7u83 172
 *			(OStreamP ostream)
2 7u83 173
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
174
 *
175
 * This function writes a tab to the specified ostream.
176
 *
177
 ** Function:	void			write_byte
7 7u83 178
 *			(OStreamP ostream, ByteT c)
2 7u83 179
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
180
 *
181
 * This function writes the specified byte to the specified ostream.
182
 *
183
 ** Function:	void			write_char
7 7u83 184
 *			(OStreamP ostream, char c)
2 7u83 185
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
186
 *
187
 * This function writes the specified character to the specified ostream.
188
 *
189
 ** Function:	void			write_escaped_char
7 7u83 190
 *			(OStreamP ostream, char c)
2 7u83 191
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
192
 *
193
 * This function writes the specified character to the specified ostream.
194
 * This differs from the ``write_char'' function, in that it will
195
 * `pretty-print' non-printing characters.
196
 *
197
 ** Function:	void			write_int
7 7u83 198
 *			(OStreamP ostream, int i)
2 7u83 199
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
200
 *
201
 * This function writes the specified integer to the specified ostream.
202
 *
203
 ** Function:	void			write_unsigned
7 7u83 204
 *			(OStreamP ostream, unsigned i)
2 7u83 205
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
206
 *
207
 * This function writes the specified unsigned integer to the specified
208
 * ostream.
209
 *
210
 ** Function:	void			write_cstring
7 7u83 211
 *			(OStreamP ostream, CStringP cstring)
2 7u83 212
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
213
 *
214
 * This function writes the specified C string to the specified ostream.
215
 *
216
 ** Function:	void			write_bytes
7 7u83 217
 *			(OStreamP ostream, ByteP bytes,
218
 *				  unsigned length)
2 7u83 219
 ** Exceptions: XX_dalloc_no_memory, XX_ostream_write_error
220
 *
221
 * This function writes the specified sequence of bytes (of the specified
222
 * length) to the specified ostream.
223
 *
224
 ** Function:	void			write_chars
7 7u83 225
 *			(OStreamP ostream, CStringP chars,
226
 *				  unsigned length)
2 7u83 227
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
228
 *
229
 * This function writes the specified sequence of characters (of the specified
230
 * length) to the specified ostream.
231
 *
232
 ** Function:	void			write_escaped_chars
7 7u83 233
 *			(OStreamP ostream, CStringP chars,
234
 *				  unsigned length)
2 7u83 235
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
236
 *
237
 * This function writes the specified sequence of characters (of the specified
238
 * length) to the specified ostream.  This differs from the ``write_chars''
239
 * function, in that it will `pretty-print' non-printing characters.
240
 *
241
 ** Function:	void			write_system_error
7 7u83 242
 *			(OStreamP ostream);
2 7u83 243
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
244
 *
245
 * This function writes a string containing a description of the current
246
 * system error (as defined by the ``errno'' global variable) to the specified
247
 * ostream.
248
 *
249
 ** Function:	void			write_pointer
7 7u83 250
 *			(OStreamP ostream, GenericP pointer);
2 7u83 251
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
252
 *
253
 * This function writes a string containing the address of the object pointed
254
 * to by the pointer to the specified ostream.
255
 *
256
 ***=== EXCEPTIONS ===========================================================
257
 *
258
 ** Exception:	XX_ostream_write_error (CStringP name)
259
 *
260
 * This exception is raised if a write attempt fails.  The data thrown is a
261
 * copy of the name of the file on which the error occured.  The copy should
262
 * be deallocated when finished with.
263
 *
264
 **** Change Log:
265
 * $Log: ostream.h,v $
266
 * Revision 1.1.1.1  1998/01/17  15:57:46  release
267
 * First version to be checked into rolling release.
268
 *
269
 * Revision 1.2  1994/12/12  11:45:50  smf
270
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
271
 * OSSG C Coding Standards.
272
 *
273
 * Revision 1.1.1.1  1994/07/25  16:06:12  smf
274
 * Initial import of os-interface shared files.
275
 *
276
**/
277
 
278
/****************************************************************************/
279
 
280
 
281
#ifndef H_OSTREAM
282
#define H_OSTREAM
283
 
284
#include "os-interface.h"
285
#include "dalloc.h"
286
#include "exception.h"
287
 
288
/*--------------------------------------------------------------------------*/
289
 
290
typedef struct OStreamT {
291
    FILE		       *file;
292
    CStringP			name;
293
    CStringP			gen_name;
294
    int				no;
295
    unsigned			line;
296
} OStreamT, *OStreamP;
297
 
298
/*--------------------------------------------------------------------------*/
299
 
7 7u83 300
extern ExceptionP	 XX_ostream_write_error;
301
extern OStreamT		*const ostream_output;
302
extern OStreamT		*const ostream_error;
2 7u83 303
 
304
/*--------------------------------------------------------------------------*/
305
 
7 7u83 306
extern void		ostream_setup(void);
307
extern void		ostream_init(OStreamP);
308
extern BoolT		ostream_open(OStreamP, CStringP);
309
extern BoolT		ostream_is_open(OStreamP);
310
extern void		ostream_buffer(OStreamP);
311
extern void		ostream_unbuffer(OStreamP);
312
extern void		ostream_close(OStreamP);
313
extern void		ostream_flush(OStreamP);
314
extern CStringP		ostream_name(OStreamP);
315
extern CStringP		ostream_gen_name(OStreamP);
316
extern unsigned		ostream_line(OStreamP);
2 7u83 317
 
7 7u83 318
extern void		write_newline(OStreamP);
319
extern void		write_tab(OStreamP);
320
extern void		write_byte(OStreamP, ByteT);
321
extern void		write_char(OStreamP, char);
322
extern void		write_escaped_char(OStreamP, char);
323
extern void		write_int(OStreamP, int);
324
extern void		write_unsigned(OStreamP, unsigned);
325
extern void		write_cstring(OStreamP, CStringP);
326
extern void		write_bytes(OStreamP, ByteP, unsigned);
327
extern void		write_chars(OStreamP, CStringP, unsigned);
328
extern void		write_escaped_chars(OStreamP, CStringP, unsigned);
329
extern void		write_system_error(OStreamP);
330
extern void		write_pointer(OStreamP, GenericP);
2 7u83 331
 
332
/*--------------------------------------------------------------------------*/
333
 
334
#ifdef FS_FAST
7 7u83 335
#define ostream_init(os)	((os)->name = NIL(CStringP))
336
#define ostream_is_open(os)	((os)->name != NIL(CStringP))
337
#define ostream_name(os)	((os)->name)
338
#define ostream_gen_name(os)	((os)->gen_name)
339
#define ostream_line(os)	((os)->line)
2 7u83 340
#endif /* defined (FS_FAST) */
341
 
342
#endif /* !defined (H_OSTREAM) */