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