Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – //branches/tendra4/src/utilities/make_mf/main.c – Rev 2

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 "types.h"
33
#include "depend.h"
34
#include "error.h"
35
#include "option.h"
36
#include "output.h"
37
#include "path.h"
38
#include "xalloc.h"
39
 
40
 
41
/*
42
    INITIALISATION FILE
43
 
44
    This macro gives the default location for the initialisation file.
45
*/
46
 
47
#ifndef INIT_FILE
48
#define INIT_FILE	"make_mf.ini"
49
#endif
50
 
51
 
52
/*
53
    READ A CONFIGURATION FILE
54
 
55
    This routine reads a sequence of configuration options from the
56
    file nm.  dir gives the standard initialisation file directory.
57
*/
58
 
59
static OPTION *read_options
60
    PROTO_N ( ( nm, dir ) )
61
    PROTO_T ( char *nm X char *dir )
62
{
63
    char *s ;
64
    OPTION *opts = NULL ;
65
    FILE *f = fopen ( nm, "r" ) ;
66
    if ( f == NULL && dir && nm [0] != '/' ) {
67
	/* Try standard directory */
68
	char *nm2 = xstrcat ( dir, nm ) ;
69
	f = fopen ( nm2, "r" ) ;
70
    }
71
    if ( f == NULL ) {
72
	error ( ERROR_SERIOUS, "Can't open configuration file, '%s'", nm ) ;
73
	return ( opts ) ;
74
    }
75
    while ( s = fgets ( pathbuff, 1000, f ), s != NULL ) {
76
	while ( *s == ' ' || *s == '\t' ) s++ ;
77
	if ( *s == '#' || *s == '\n' || *s == 0 ) {
78
	    /* Comments */
79
	} else {
80
	    /* Other lines */
81
	    char *e = strchr ( s, '\n' ) ;
82
	    if ( e ) {
83
		do {
84
		    *( e-- ) = 0 ;
85
		} while ( *e == ' ' || *e == '\t' ) ;
86
	    }
87
	    s = xstrcpy ( s ) ;
88
	    opts = add_option ( opts, s, 0 ) ;
89
	}
90
    }
91
    fclose_v ( f ) ;
92
    return ( opts ) ;
93
}
94
 
95
 
96
/*
97
    MAIN ROUTINE
98
 
99
    This is the top level routine.  It calls the initialisation routines,
100
    processes the command-line options, and calls the output routines.
101
*/
102
 
103
int main
104
    PROTO_N ( ( argc, argv ) )
105
    PROTO_T ( int argc X char **argv )
106
{
107
    int a = 1 ;
108
    char *init ;
109
    OPTION *opt ;
110
    OPTION *opts ;
111
    char *pre = NULL ;
112
    char *init_dir = NULL ;
113
 
114
    /* Call initialisation routines */
115
    set_progname ( argv [0], "1.1" ) ;
116
    init = getenv ( "MAKE_MF_INIT" ) ;
117
    if ( init == NULL ) init = INIT_FILE ;
118
    pre = strrchr ( init, '/' ) ;
119
    if ( pre ) {
120
	/* Copy the directory component */
121
	init_dir = xstrcpy ( init ) ;
122
	pre = strrchr ( init_dir, '/' ) ;
123
	pre [1] = 0 ;
124
	pre = NULL ;
125
    }
126
    if ( a < argc ) {
127
	/* '+f<init>' allowed as first option */
128
	char *arg = argv [a] ;
129
	if ( arg [0] == '+' && arg [1] == 'f' ) {
130
	    init = arg + 2 ;
131
	    a++ ;
132
	}
133
    }
134
    opts = read_options ( init, init_dir ) ;
135
    if ( exit_status == EXIT_FAILURE ) return ( exit_status ) ;
136
 
137
    /* Process command-line options */
138
    while ( a < argc ) {
139
	char *arg = argv [a] ;
140
	if ( pre ) {
141
	    arg = xstrcat ( pre, arg ) ;
142
	    pre = NULL ;
143
	} else {
144
	    arg = xstrcpy ( arg ) ;
145
	}
146
	if ( arg [0] == '-' ) {
147
	    switch ( arg [1] ) {
148
		case 'I' : case 'L' : case 'o' : {
149
		    /* Two part options */
150
		    if ( arg [2] == 0 ) pre = arg ;
151
		    break ;
152
		}
153
	    }
154
	} else if ( arg [0] == '+' ) {
155
	    switch ( arg [1] ) {
156
		case 'A' : case 'C' : case 'F' : case 'H' :
157
		case 'I' : case 'L' : case 'R' : case 'V' :
158
		case 'W' : case 'm' : case 'w' : {
159
		    /* Two part options */
160
		    if ( arg [2] == 0 ) pre = arg ;
161
		    break ;
162
		}
163
	    }
164
	}
165
	if ( pre == NULL ) opts = add_option ( opts, arg, 0 ) ;
166
	a++ ;
167
    }
168
 
169
    /* Analyse options */
170
    for ( opt = opts ; opt != NULL ; opt = opt->next ) {
171
	char *arg = opt->opt ;
172
	if ( arg [0] == '-' ) {
173
	    switch ( arg [1] ) {
174
 
175
		case 'I' : {
176
		    /* Include directory */
177
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
178
		    if ( p->alias == NULL ) p->alias = src_alias ( 0 ) ;
179
		    p->exists = 1 ;
180
		    incl_dirs = add_directory ( incl_dirs, p, 0 ) ;
181
		    goto all_options ;
182
		}
183
 
184
		case 'L' : {
185
		    /* Library directory */
186
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
187
		    if ( p->alias == NULL ) p->alias = src_alias ( 1 ) ;
188
		    p->exists = 1 ;
189
		    lib_dirs = add_directory ( lib_dirs, p, 0 ) ;
190
		    goto all_options ;
191
		}
192
 
193
		case 'o' : {
194
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
195
		    p->exists = 1 ;
196
		    output_file = p ;
197
		    goto all_options ;
198
		}
199
 
200
		default :
201
		all_options : {
202
		    /* Other options */
203
		    cmd_opts = add_option ( cmd_opts, arg, 0 ) ;
204
		    break ;
205
		}
206
	    }
207
 
208
	} else if ( arg [0] == '+' ) {
209
	    switch ( arg [1] ) {
210
 
211
		case 'A' : {
212
		    /* Alias definition */
213
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
214
		    p->exists = 1 ;
215
		    break ;
216
		}
217
 
218
		case 'C' : {
219
		    /* Current working directory */
220
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
221
		    p->exists = 1 ;
222
		    current_dir = p ;
223
		    break ;
224
		}
225
 
226
		case 'F' : {
227
		    /* Configuration file */
228
		    OPTION *fopts = read_options ( arg + 2, init_dir ) ;
229
		    if ( fopts ) {
230
			OPTION *p = fopts ;
231
			while ( p->next ) p = p->next ;
232
			p->next = opt->next ;
233
			opt->next = fopts ;
234
		    }
235
		    break ;
236
		}
237
 
238
		case 'H' : {
239
		    /* Home directory */
240
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
241
		    p->exists = 1 ;
242
		    home_dir = p ;
243
		    break ;
244
		}
245
 
246
		case 'I' : {
247
		    /* Built-in include directory */
248
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
249
		    p->exists = 1 ;
250
		    incl_dirs = add_directory ( incl_dirs, p, 1 ) ;
251
		    break ;
252
		}
253
 
254
		case 'L' : {
255
		    /* Built-in include directory */
256
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
257
		    p->exists = 1 ;
258
		    lib_dirs = add_directory ( lib_dirs, p, 1 ) ;
259
		    break ;
260
		}
261
 
262
		case 'R' : case 'V' : {
263
		    /* Rule definitions */
264
		    int dup = 0 ;
265
		    if ( arg [1] == 'V' ) dup = 1 ;
266
		    rule_opts = add_option ( rule_opts, arg + 2, dup ) ;
267
		    break ;
268
		}
269
 
270
		case 'W' : {
271
		    /* Work directory */
272
		    PATHNAME *p = make_pathname ( arg + 2, 1 ) ;
273
		    p->exists = 1 ;
274
		    work_dir = p ;
275
		    break ;
276
		}
277
 
278
		case 'i' : {
279
		    if ( streq ( arg + 1, "init" ) ) {
280
			init_pathname () ;
281
			cmd_opts = NULL ;
282
			rule_opts = NULL ;
283
			incl_dirs = NULL ;
284
			lib_dirs = NULL ;
285
			break ;
286
		    }
287
		    goto unknown_options ;
288
		}
289
 
290
		case 'm' : {
291
		    /* Machine type */
292
		    char *mach = arg + 2 ;
293
		    if ( streq ( mach, "dos" ) ) {
294
			dos_pathname = 1 ;
295
			dos_output = 1 ;
296
			break ;
297
		    }
298
		    if ( streq ( mach, "dos-unix" ) ) {
299
			dos_pathname = 1 ;
300
			dos_output = 0 ;
301
			break ;
302
		    }
303
		    if ( streq ( mach, "unix" ) ) {
304
			dos_pathname = 0 ;
305
			dos_output = 0 ;
306
			break ;
307
		    }
308
		    if ( streq ( mach, "unix-dos" ) ) {
309
			dos_pathname = 0 ;
310
			dos_output = 1 ;
311
			break ;
312
		    }
313
		    goto unknown_options ;
314
		}
315
 
316
		case 'r' : {
317
		    /* Relative pathnames */
318
		    if ( streq ( arg + 1, "relative" ) ) {
319
			relative_output = 1 ;
320
			break ;
321
		    }
322
		    goto unknown_options ;
323
		}
324
 
325
		case 'w' : {
326
		    /* Maximum width */
327
		    max_column = atoi ( arg + 2 ) ;
328
		    break ;
329
		}
330
 
331
		default :
332
		unknown_options : {
333
		    error ( ERROR_WARNING, "Unknown option, '%s'", arg ) ;
334
		    break ;
335
		}
336
	    }
337
 
338
	} else {
339
	    /* Create aliases for source directories */
340
	    PATHNAME *p = make_pathname ( arg, 1 ) ;
341
	    if ( p->up->alias == NULL ) p->up->alias = src_alias ( 0 ) ;
342
	}
343
    }
344
 
345
    /* Check for incomplete options */
346
    if ( pre ) error ( ERROR_WARNING, "Incomplete option, '%s'", pre ) ;
347
 
348
    /* Process input files */
349
    for ( opt = opts ; opt != NULL ; opt = opt->next ) {
350
	char *arg = opt->opt ;
351
	if ( arg [0] != '-' && arg [0] != '+' ) {
352
	    PATHNAME *p = make_pathname ( arg, 1 ) ;
353
	    find_dependency ( p, 0 ) ;
354
	}
355
    }
356
 
357
    /* Provide some default alias definitions */
358
    if ( work_dir->alias == NULL ) work_dir->alias = "WORK" ;
359
 
360
    /* Call output routines */
361
    output_all ( stdout ) ;
362
    return ( exit_status ) ;
363
}