Subversion Repositories tendra.SVN

Rev

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

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