Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
#include "config.h"
32
#if FS_STDARG
33
#include <stdarg.h>
34
#else
35
#include <varargs.h>
36
#endif
37
#include "types.h"
38
#include "file.h"
39
#include "pretty.h"
40
#include "utility.h"
41
 
42
 
43
/*
44
    PROGRAM NAME
45
 
46
    The program name is output in all error reports.
47
*/
48
 
49
char *progname = "disp" ;
50
 
51
 
52
/*
53
    EXIT STATUS
54
 
55
    This flag is set to 1 whenever an error occurs.  It is the value
56
    with which the program finally exits.
57
*/
58
 
59
int exit_status = EXIT_SUCCESS ;
60
 
61
 
62
/*
63
    RECOVERY FLAG
64
 
65
    This flag controls whether an attempt is made to recover from
66
    non-fatal errors.  Anything after an error is likely to be of very
67
    little use.
68
*/
69
 
70
int recover = 0 ;
71
 
72
 
73
/*
74
    REPORT A FATAL ERROR
75
 
76
    An error is reported and the program aborts immediately.
77
*/
78
 
79
void fatal_error
80
    PROTO_V ( ( char *s, ... ) ) /* VARARGS */
81
{
82
    va_list args ;
83
#if FS_STDARG
84
    va_start ( args, s ) ;
85
#else
86
    char *s ;
87
    va_start ( args ) ;
88
    s = va_arg ( args, char * ) ;
89
#endif
90
    if ( progname ) IGNORE fprintf ( stderr, "%s: ", progname ) ;
91
    IGNORE fprintf ( stderr, "Error: " ) ;
92
    IGNORE vfprintf ( stderr, s, args ) ;
93
    IGNORE fprintf ( stderr, ".\n" ) ;
94
    va_end ( args ) ;
95
    exit ( EXIT_FAILURE ) ;
96
}
97
 
98
 
99
/*
100
    REPORT AN INPUT ERROR
101
 
102
    An error is reported together with the position within the input
103
    file where it occured, and the program either attempts to recover
104
    (if the recover flag is true) or outputs what it has read so far
105
    and then exits (otherwise).
106
*/
107
 
108
void input_error
109
    PROTO_V ( ( char *s, ... ) ) /* VARARGS */
110
{
111
    va_list args ;
112
    long b = here.byte ;
113
#if FS_STDARG
114
    va_start ( args, s ) ;
115
#else
116
    char *s ;
117
    va_start ( args ) ;
118
    s = va_arg ( args, char * ) ;
119
#endif
120
    if ( progname ) IGNORE fprintf ( stderr, "%s: ", progname ) ;
121
    IGNORE fprintf ( stderr, "Error: " ) ;
122
    IGNORE vfprintf ( stderr, s, args ) ;
123
    IGNORE fprintf ( stderr, ", byte %ld, bit %d.\n", b, here.bit ) ;
124
    va_end ( args ) ;
125
    exit_status = EXIT_FAILURE ;
126
    if ( !recover ) {
127
	pretty_tree () ;
128
	exit ( EXIT_FAILURE ) ;
129
    }
130
    return ;
131
}
132
 
133
 
134
/*
135
    ALLOCATE A SECTION OF MEMORY
136
 
137
    This routine allocates n bytes of memory.
138
*/
139
 
140
pointer xalloc
141
    PROTO_N ( ( n ) )
142
    PROTO_T ( int n )
143
{
144
    pointer ptr = ( pointer ) malloc ( ( size_t ) n ) ;
145
    if ( ptr == null ) fatal_error ( "Memory allocation error" ) ;
146
    return ( ptr ) ;
147
}
148
 
149
 
150
/*
151
    REALLOCATE A SECTION OF MEMORY
152
 
153
    This routine reallocates n bytes of memory.
154
*/
155
 
156
pointer xrealloc
157
    PROTO_N ( ( p, n ) )
158
    PROTO_T ( pointer p X int n )
159
{
160
    pointer ptr ;
161
    if ( p == null ) return ( xalloc ( n ) ) ;
162
    ptr = ( pointer ) realloc ( p, ( size_t ) n ) ;
163
    if ( ptr == null ) fatal_error ( "Memory allocation error" ) ;
164
    return ( ptr ) ;
165
}