Subversion Repositories tendra.SVN

Rev

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

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