Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | 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
#ifndef UTILITY_INCLUDED
32
#define UTILITY_INCLUDED
33
 
34
 
35
/*
36
    PROCEDURE DECLARATIONS
37
 
38
    These routines are concerned with error reporting, memory allocation
39
    and system calls.
40
*/
41
 
42
extern void error PROTO_W ( ( int, char *, ... ) ) ;
43
extern pointer xalloc PROTO_S ( ( int ) ) ;
44
extern pointer xrealloc PROTO_S ( ( pointer, int ) ) ;
45
extern char *string_copy PROTO_S ( ( char * ) ) ;
46
extern char *string_concat PROTO_S ( ( char *, char * ) ) ;
47
extern char *string_printf PROTO_W ( ( char *, ... ) ) ;
48
extern void create_dir PROTO_S ( ( char * ) ) ;
49
extern void check_name PROTO_S ( ( char * ) ) ;
50
extern time_t date_stamp PROTO_S ( ( char * ) ) ;
51
 
52
 
53
/*
54
    INPUT BUFFER
55
 
56
    This buffer is used to store input in various contexts.
57
*/
58
 
59
extern char *buffer ;
60
#define buffsize		5000
61
 
62
 
63
/*
64
    ERROR VARIABLES
65
 
66
    These variables are concerned with error reporting.
67
*/
68
 
69
extern int exit_status ;
70
extern int no_errors ;
71
extern int warnings ;
72
extern char *progname ;
73
extern char *progvers ;
74
extern time_t progdate ;
75
extern char *filename ;
76
extern int line_no ;
77
 
78
 
79
/*
80
    ERROR TYPES
81
 
82
    These values give the severity levels for the error reporting
83
    routine, error.
84
*/
85
 
86
#define ERR_FATAL		0
87
#define ERR_INTERNAL		1
88
#define ERR_SERIOUS		2
89
#define ERR_WARNING		3
90
#define ERR_INFO		4
91
 
92
 
93
/*
94
    UTILITY MACROS
95
 
96
    These macros give convenient shorthands for various constructs.
97
*/
98
 
99
#define alloc_size( T, N )\
100
	( ( int ) ( N ) * ( int ) sizeof ( T ) )
101
 
102
#define alloc_nof( T, N )\
103
	( T * ) xalloc ( alloc_size ( T, N ) )
104
 
105
#define realloc_nof( P, T, N )\
106
	( T * ) xrealloc ( ( pointer ) ( P ), alloc_size ( T, N ) )
107
 
108
#define array_size( A )\
109
	( ( int ) sizeof ( A ) / ( int ) sizeof ( A [0] ) )
110
 
111
 
112
/*
113
    GENERAL ALLOCATION ROUTINE
114
 
115
    This routine allocates a variable V of type T, allocating N at a time.
116
*/
117
 
118
#define alloc_variable( V, T, N )\
119
    {\
120
	static int no_free = 0 ;\
121
	static T *free_list = null ;\
122
	if ( no_free == 0 ) {\
123
	    no_free = N ;\
124
	    free_list = alloc_nof ( T, N ) ;\
125
	}\
126
	V = free_list + ( --no_free ) ;\
127
    }
128
 
129
 
130
#endif