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
#include "external.h"
33
#include "filename.h"
34
#include "list.h"
35
#include "execute.h"
36
#include "flags.h"
37
#include "startup.h"
38
#include "utility.h"
39
 
40
 
41
/*
42
    THE STARTUP AND ENDUP FILES
43
 
44
    These variables give the names and file descriptors for the startup
45
    and endup files, plus the command-line options to pass them to the
46
    producer.
47
*/
48
 
49
static FILE *startup_file = null, *endup_file = null ;
50
static char *startup_name = null, *endup_name = null ;
51
char *startup_opt = null, *endup_opt = null ;
52
 
53
 
54
/*
55
    ADD A MESSAGE TO THE STARTUP FILE
56
 
57
    This routine prints the message s to the tcc startup file.
58
*/
59
 
60
void add_to_startup
61
    PROTO_N ( ( s ) )
62
    PROTO_T ( char *s )
63
{
64
    if ( startup_name == null ) {
65
	startup_name = temp_name ( temporary_dir, "ts" ) ;
66
	startup_opt = string_concat ( "-f", startup_name ) ;
67
    }
68
    opt_startup = add_item ( opt_startup, s ) ;
69
    if ( dry_run ) return ;
70
    if ( startup_file == null ) {
71
	startup_file = fopen ( startup_name, "a" ) ;
72
	if ( startup_file == null ) {
73
	    error ( SERIOUS, "Can't open startup file, '%s'", startup_name ) ;
74
	    return ;
75
	}
76
	IGNORE fprintf ( startup_file, "#line 1 \"%s\"\n", name_h_file ) ;
77
    }
78
    IGNORE fputs ( s, startup_file ) ;
79
    return ;
80
}
81
 
82
 
83
/*
84
    ADD A MESSAGE TO THE ENDUP FILE
85
 
86
    This routine prints the message s to the tcc endup file.
87
*/
88
 
89
void add_to_endup
90
    PROTO_N ( ( s ) )
91
    PROTO_T ( char *s )
92
{
93
    if ( endup_name == null ) {
94
	endup_name = temp_name ( temporary_dir, "te" ) ;
95
	startup_opt = string_concat ( "-e", endup_name ) ;
96
    }
97
    opt_endup = add_item ( opt_endup, s ) ;
98
    if ( dry_run ) return ;
99
    if ( endup_file == null ) {
100
	endup_file = fopen ( endup_name, "a" ) ;
101
	if ( endup_file == null ) {
102
	    error ( SERIOUS, "Can't open endup file, '%s'", endup_name ) ;
103
	    return ;
104
	}
105
	IGNORE fprintf ( endup_file, "#line 1 \"%s\"\n", name_E_file ) ;
106
    }
107
    IGNORE fputs ( s, endup_file ) ;
108
    return ;
109
}
110
 
111
 
112
/*
113
    THE TOKEN DEFINITION FILE
114
 
115
    This file is used to hold TDF notation for the definition of the
116
    command-line tokens.
117
*/
118
 
119
static FILE *tokdef_file = null ;
120
char *tokdef_name = null ;
121
 
122
 
123
/*
124
    ADD A MESSAGE TO THE TOKEN DEFINITION FILE
125
 
126
    This routine prints the message s to the tcc token definition file.
127
*/
128
 
129
void add_to_tokdef
130
    PROTO_N ( ( s ) )
131
    PROTO_T ( char *s )
132
{
133
    if ( tokdef_name == null ) {
134
	tokdef_name = temp_name ( temporary_dir, "td" ) ;
135
    }
136
    if ( dry_run ) return ;
137
    if ( tokdef_file == null ) {
138
	tokdef_file = fopen ( tokdef_name, "a" ) ;
139
	if ( tokdef_file == null ) {
140
	    error ( SERIOUS, "Can't open token definition file, '%s'",
141
		    tokdef_name ) ;
142
	    return ;
143
	}
144
	IGNORE fputs ( "( make_tokdec ~char variety )\n", tokdef_file ) ;
145
	IGNORE fputs ( "( make_tokdec ~signed_int variety )\n\n",
146
		       tokdef_file ) ;
147
    }
148
    IGNORE fputs ( s, tokdef_file ) ;
149
    return ;
150
}
151
 
152
 
153
/*
154
    CLOSE THE STARTUP AND ENDUP FILES
155
 
156
    This routine closes the startup and endup files.
157
*/
158
 
159
void close_startup
160
    PROTO_Z ()
161
{
162
    if ( startup_file ) {
163
	IGNORE fclose ( startup_file ) ;
164
	startup_file = null ;
165
    }
166
    if ( endup_file ) {
167
	IGNORE fclose ( endup_file ) ;
168
	endup_file = null ;
169
    }
170
    if ( tokdef_file ) {
171
	IGNORE fclose ( tokdef_file ) ;
172
	tokdef_file = null ;
173
    }
174
    return ;
175
}
176
 
177
 
178
/*
179
    CLEAN UP THE STARTUP AND ENDUP FILES
180
 
181
    This routine is called before the program terminates either to
182
    remove the tcc startup and endup files or to move them if they
183
    are to be preserved.
184
*/
185
 
186
void remove_startup
187
    PROTO_Z ()
188
{
189
    if ( keeps [ STARTUP_FILE ] ) {
190
	if ( startup_name ) {
191
	    cmd_list ( exec_move ) ;
192
	    cmd_string ( startup_name ) ;
193
	    cmd_string ( name_h_file ) ;
194
	    IGNORE execute ( no_filename, no_filename ) ;
195
	}
196
	if ( endup_name ) {
197
	    cmd_list ( exec_move ) ;
198
	    cmd_string ( endup_name ) ;
199
	    cmd_string ( name_E_file ) ;
200
	    IGNORE execute ( no_filename, no_filename ) ;
201
	}
202
	if ( tokdef_name ) {
203
	    cmd_list ( exec_move ) ;
204
	    cmd_string ( tokdef_name ) ;
205
	    cmd_string ( name_p_file ) ;
206
	    IGNORE execute ( no_filename, no_filename ) ;
207
	}
208
    } else {
209
	if ( startup_name ) {
210
	    cmd_list ( exec_remove ) ;
211
	    cmd_string ( startup_name ) ;
212
	    IGNORE execute ( no_filename, no_filename ) ;
213
	}
214
	if ( endup_name ) {
215
	    cmd_list ( exec_remove ) ;
216
	    cmd_string ( endup_name ) ;
217
	    IGNORE execute ( no_filename, no_filename ) ;
218
	}
219
	if ( tokdef_name ) {
220
	    cmd_list ( exec_remove ) ;
221
	    cmd_string ( tokdef_name ) ;
222
	    IGNORE execute ( no_filename, no_filename ) ;
223
	}
224
    }
225
    return ;
226
}
227
 
228
 
229
/*
230
    DEAL WITH STARTUP PRAGMA OPTIONS
231
 
232
    This routine translates command-line compilation mode options into
233
    the corresponding pragma statements.
234
*/
235
 
236
void add_pragma
237
    PROTO_N ( ( s ) )
238
    PROTO_T ( char *s )
239
{
240
    char *e ;
241
    char *level = "warning" ;
242
    static char *start_scope = "#pragma TenDRA begin\n" ;
243
    if ( start_scope ) {
244
	add_to_startup ( start_scope ) ;
245
	start_scope = null ;
246
    }
247
    e = strchr ( s, '=' ) ;
248
    if ( e ) {
249
	level = e + 1 ;
250
	*e = 0 ;
251
    }
252
 
253
    /* Write option to startup file */
254
    add_to_startup ( "#pragma TenDRA option \"" ) ;
255
    add_to_startup ( s ) ;
256
    add_to_startup ( "\" " ) ;
257
    add_to_startup ( level ) ;
258
    add_to_startup ( "\n" ) ;
259
    return ;
260
}
261
 
262
 
263
/*
264
    DEAL WITH STARTUP TOKEN OPTIONS
265
 
266
    This routine translates command-line token definition options into
267
    the corresponding pragma statements.
268
*/
269
 
270
void add_token
271
    PROTO_N ( ( s ) )
272
    PROTO_T ( char *s )
273
{
274
    char *type = "int" ;
275
    char *defn = "1" ;
276
    char *e = strchr ( s, '=' ) ;
277
    if ( e ) {
278
	defn = e + 1 ;
279
	*e = 0 ;
280
    }
281
 
282
    /* Write token description to startup file */
283
    add_to_startup ( "#pragma token EXP const : " ) ;
284
    add_to_startup ( type ) ;
285
    add_to_startup ( " : " ) ;
286
    add_to_startup ( s ) ;
287
    add_to_startup ( " #\n" ) ;
288
    add_to_startup ( "#pragma interface " ) ;
289
    add_to_startup ( s ) ;
290
    add_to_startup ( "\n" ) ;
291
 
292
    /* Write definition to token definition file */
293
    add_to_tokdef ( "( make_tokdef " ) ;
294
    add_to_tokdef ( s ) ;
295
    add_to_tokdef ( " exp\n" ) ;
296
    add_to_tokdef ( "  ( make_int ~signed_int " ) ;
297
    add_to_tokdef ( defn ) ;
298
    add_to_tokdef ( " ) )\n\n" ) ;
299
    return ;
300
}