Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
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 62... Line 92...
62
    ERROR FLAGS AND VARIABLES
92
    ERROR FLAGS AND VARIABLES
63
 
93
 
64
    These variables are used or set in the error routines.
94
    These variables are used or set in the error routines.
65
*/
95
*/
66
 
96
 
67
CONST char *progname = NULL ;
97
CONST char *progname = NULL;
68
CONST char *progvers = NULL ;
98
CONST char *progvers = NULL;
69
int exit_status = EXIT_SUCCESS ;
99
int exit_status = EXIT_SUCCESS;
70
int maximum_errors = 20 ;
100
int maximum_errors = 20;
71
static int number_errors = 0 ;
101
static int number_errors = 0;
72
 
102
 
73
int crt_line_no = 1 ;
103
int crt_line_no = 1;
74
CONST char *crt_file_name = NULL ;
104
CONST char *crt_file_name = NULL;
75
 
105
 
76
 
106
 
77
/*
107
/*
78
    SET PROGRAM NAME
108
    SET PROGRAM NAME
79
 
109
 
80
    This routine sets the program name to nm and the program version to
110
    This routine sets the program name to nm and the program version to
81
    vers.
111
    vers.
82
*/
112
*/
83
 
113
 
84
void set_progname
114
void
85
    PROTO_N ( ( nm, vers ) )
-
 
86
    PROTO_T ( CONST char *nm X CONST char *vers )
115
set_progname(CONST char *nm, CONST char *vers)
87
{
116
{
88
    char *r = strrchr ( nm, '/' ) ;
117
    char *r = strrchr(nm, '/');
89
    progname = ( r ? r + 1 : nm ) ;
118
    progname = (r ? r + 1 : nm);
90
    progvers = vers ;
119
    progvers = vers;
91
    return ;
120
    return;
92
}
121
}
93
 
122
 
94
 
123
 
95
/*
124
/*
96
    PRINT VERSION NUMBER
125
    PRINT VERSION NUMBER
97
 
126
 
98
    This routine prints the program name and version number.
127
    This routine prints the program name and version number.
99
*/
128
*/
100
 
129
 
101
void report_version
130
void
102
    PROTO_Z ()
131
report_version(void)
103
{
132
{
104
    CONST char *r = RELEASE ;
133
    CONST char *r = RELEASE;
105
    CONST char *nm = progname ;
134
    CONST char *nm = progname;
106
    CONST char *vers = progvers ;
135
    CONST char *vers = progvers;
107
    if ( nm == NULL ) nm = "unknown" ;
136
    if (nm == NULL) nm = "unknown";
108
    if ( vers == NULL ) vers = "1.0" ;
137
    if (vers == NULL) vers = "1.0";
109
    fprintf_v ( stderr, "%s: Version %s (Release %s)\n", nm, vers, r ) ;
138
    fprintf_v(stderr, "%s: Version %s (Release %s)\n", nm, vers, r);
110
    return ;
139
    return;
111
}
140
}
112
 
141
 
113
 
142
 
114
/*
143
/*
115
    PRINT AN ERROR MESSAGE
144
    PRINT AN ERROR MESSAGE
116
 
145
 
117
    This routine prints an error message s with arguments args and severity
146
    This routine prints an error message s with arguments args and severity
118
    e.  fn and ln give the error position.
147
    e.  fn and ln give the error position.
119
*/
148
*/
120
 
149
 
121
static void error_msg
150
static void
122
    PROTO_N ( ( e, fn, ln, s, args ) )
-
 
123
    PROTO_T ( int e X CONST char *fn X int ln X CONST char *s X va_list args )
151
error_msg(int e, CONST char *fn, int ln, CONST char *s, va_list args)
124
{
152
{
125
    if ( e != ERROR_NONE ) {
153
    if (e != ERROR_NONE) {
126
	if ( progname ) fprintf_v ( stderr, "%s: ", progname ) ;
154
	if (progname) fprintf_v(stderr, "%s: ", progname);
127
	switch ( e ) {
155
	switch (e) {
128
	    case ERROR_WARNING : {
156
	    case ERROR_WARNING: {
129
		fprintf_v ( stderr, "Warning: " ) ;
157
		fprintf_v(stderr, "Warning: ");
130
		break ;
158
		break;
131
	    }
159
	    }
132
	    case ERROR_FATAL : {
160
	    case ERROR_FATAL: {
133
		fprintf_v ( stderr, "Fatal: " ) ;
161
		fprintf_v(stderr, "Fatal: ");
134
		exit_status = EXIT_FAILURE ;
162
		exit_status = EXIT_FAILURE;
135
		number_errors++ ;
163
		number_errors++;
136
		break ;
164
		break;
137
	    }
165
	    }
138
	    default : {
166
	    default : {
139
		fprintf_v ( stderr, "Error: " ) ;
167
		fprintf_v(stderr, "Error: ");
140
		exit_status = EXIT_FAILURE ;
168
		exit_status = EXIT_FAILURE;
141
		number_errors++ ;
169
		number_errors++;
142
		break ;
170
		break;
143
	    }
171
	    }
144
	}
172
	}
145
	if ( fn ) {
173
	if (fn) {
146
	    fprintf_v ( stderr, "%s: ", fn ) ;
174
	    fprintf_v(stderr, "%s: ", fn);
147
	    if ( ln != -1 ) fprintf_v ( stderr, "line %d: ", ln ) ;
175
	    if (ln != -1) fprintf_v(stderr, "line %d: ", ln);
148
	}
176
	}
149
	vfprintf_v ( stderr, s, args ) ;
177
	vfprintf_v(stderr, s, args);
150
	fprintf_v ( stderr, ".\n" ) ;
178
	fprintf_v(stderr, ".\n");
151
	if ( e == ERROR_FATAL ) exit ( EXIT_FAILURE ) ;
179
	if (e == ERROR_FATAL) exit(EXIT_FAILURE);
152
	if ( number_errors >= maximum_errors && maximum_errors ) {
180
	if (number_errors >= maximum_errors && maximum_errors) {
153
	    error ( ERROR_FATAL, "Too many errors (%d) - aborting",
181
	    error(ERROR_FATAL, "Too many errors (%d) - aborting",
154
		    number_errors ) ;
182
		    number_errors);
155
	}
183
	}
156
    }
184
    }
157
    return ;
185
    return;
158
}
186
}
159
 
187
 
160
 
188
 
161
/*
189
/*
162
    PRINT AN ERROR AT CURRENT POSITION
190
    PRINT AN ERROR AT CURRENT POSITION
Line 164... Line 192...
164
    This routine prints the error message s of severity e at the current
192
    This routine prints the error message s of severity e at the current
165
    file position.  s is a printf format string whose arguments are passed
193
    file position.  s is a printf format string whose arguments are passed
166
    as the optional procedure parameters.
194
    as the optional procedure parameters.
167
*/
195
*/
168
 
196
 
169
void error
197
void
170
    PROTO_V ( ( int e, CONST char *s, ... ) )
198
error(int e, CONST char *s, ...)
171
    /*VARARGS*/
199
    /*VARARGS*/
172
{
200
{
173
    va_list args ;
201
    va_list args;
174
#if FS_STDARG
202
#if FS_STDARG
175
    va_start ( args, s ) ;
203
    va_start(args, s);
176
#else
204
#else
177
    int e ;
205
    int e;
178
    CONST char *s ;
206
    CONST char *s;
179
    va_start ( args ) ;
207
    va_start(args);
180
    e = va_arg ( args, int ) ;
208
    e = va_arg(args, int);
181
    s = va_arg ( args, CONST char * ) ;
209
    s = va_arg(args, CONST char *);
182
#endif
210
#endif
183
    error_msg ( e, crt_file_name, crt_line_no, s, args ) ;
211
    error_msg(e, crt_file_name, crt_line_no, s, args);
184
    va_end ( args ) ;
212
    va_end(args);
185
    return ;
213
    return;
186
}
214
}
187
 
215
 
188
 
216
 
189
/*
217
/*
190
    PRINT AN ERROR AT A GIVEN POSITION
218
    PRINT AN ERROR AT A GIVEN POSITION
191
 
219
 
192
    This routine prints the error message s of severity e at the file
220
    This routine prints the error message s of severity e at the file
193
    position given by fn and ln.  s is as above.
221
    position given by fn and ln.  s is as above.
194
*/
222
*/
195
 
223
 
196
void error_posn
224
void
197
    PROTO_V ( ( int e, CONST char *fn, int ln, CONST char *s, ... ) )
225
error_posn(int e, CONST char *fn, int ln, CONST char *s, ...)
198
    /*VARARGS*/
226
    /*VARARGS*/
199
{
227
{
200
    va_list args ;
228
    va_list args;
201
#if FS_STDARG
229
#if FS_STDARG
202
    va_start ( args, s ) ;
230
    va_start(args, s);
203
#else
231
#else
204
    int e ;
232
    int e;
205
    CONST char *fn ;
233
    CONST char *fn;
206
    int ln ;
234
    int ln;
207
    CONST char *s ;
235
    CONST char *s;
208
    va_start ( args ) ;
236
    va_start(args);
209
    e = va_arg ( args, int ) ;
237
    e = va_arg(args, int);
210
    fn = va_arg ( args, CONST char * ) ;
238
    fn = va_arg(args, CONST char *);
211
    ln = va_arg ( args, int ) ;
239
    ln = va_arg(args, int);
212
    s = va_arg ( args, CONST char * ) ;
240
    s = va_arg(args, CONST char *);
213
#endif
241
#endif
214
    error_msg ( e, fn, ln, s, args ) ;
242
    error_msg(e, fn, ln, s, args);
215
    va_end ( args ) ;
243
    va_end(args);
216
    return ;
244
    return;
217
}
245
}
218
 
246
 
219
 
247
 
220
#ifdef DEBUG
248
#ifdef DEBUG
221
 
249
 
Line 224... Line 252...
224
 
252
 
225
    This routine prints the assertion s which occurred at the location
253
    This routine prints the assertion s which occurred at the location
226
    given by file and line.
254
    given by file and line.
227
*/
255
*/
228
 
256
 
229
void assertion
257
void
230
    PROTO_N ( ( s, file, line ) )
-
 
231
    PROTO_T ( CONST char *s X CONST char *file X int line )
258
assertion(CONST char *s, CONST char *file, int line)
232
{
259
{
233
    if ( progname ) fprintf_v ( stderr, "%s: ", progname ) ;
260
    if (progname) fprintf_v(stderr, "%s: ", progname);
234
    fprintf_v ( stderr, "Assertion: %s: line %d: '%s'.\n", file, line, s ) ;
261
    fprintf_v(stderr, "Assertion: %s: line %d: '%s'.\n", file, line, s);
235
    abort () ;
262
    abort();
236
}
263
}
237
 
264
 
238
#endif
265
#endif