Subversion Repositories tendra.SVN

Rev

Rev 2 | 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
/*** main.c --- tld program main routine.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file contains the main routine for the TDF linker.  It performs
38
 * argument parsing, and then calls one of "builder_main", "contents_main",
39
 * "extract_main" or "linker_main" to do the actual work.  See the files in
40
 * the "frontends" directory for more details.
41
 *
42
 *** Change Log:
43
 * $Log: main.c,v $
44
 * Revision 1.2  1998/02/06  17:05:29  release
45
 * Last minute pre-release polishing.
46
 *
47
 * Revision 1.1.1.1  1998/01/17  15:57:16  release
48
 * First version to be checked into rolling release.
49
 *
50
 * Revision 1.12  1997/11/05  14:39:35  smf
51
 * main.c:
52
 * 	- Updated "VERSION" number.
53
 *
54
 * Revision 1.11  1996/05/23  16:03:15  smf
55
 * main.c:
56
 * 	- updated version number.
57
 *
58
 * Revision 1.10  1996/03/27  10:42:35  smf
59
 * main.c:
60
 * 	- updated version number.
61
 *
62
 * Revision 1.9  1996/03/04  17:01:16  smf
63
 * main.c:
64
 * 	- updated version number.
65
 *
66
 * Revision 1.8  1995/12/04  11:51:32  smf
67
 * Updated version.
68
 *
69
 * Fixed version message to include architecture name banner.
70
 *
71
 * Revision 1.7  1995/09/22  08:35:00  smf
72
 * Updated version number.
73
 * Fixed problems with incomplete structure definitions (to shut "tcc" up).
74
 *
75
 * Revision 1.6  1995/09/08  16:10:50  smf
76
 * Updated version number.
77
 *
78
 * Revision 1.5  1995/07/07  15:31:46  smf
79
 * Updated to support TDF specification 4.0.
80
 *
81
 * Revision 1.4  1995/07/05  11:56:59  smf
82
 * Incremented version number.  Added release identification to version string.
83
 * Removed "build_tld" from CVS control.
84
 *
85
 * Revision 1.3  1994/12/12  11:41:40  smf
86
 * Upgrade VERSION to 3.6#2.
87
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
88
 * OSSG C Coding Standards.
89
 *
90
 * Revision 1.2  1994/08/23  09:38:19  smf
91
 * Fixed bug DR114:ids-too-long.  Updated linker build process.
92
 *
93
 * Revision 1.1.1.1  1994/07/25  16:03:21  smf
94
 * Initial import of TDF linker 3.5 non shared files.
95
 *
96
**/
97
 
98
/****************************************************************************/
99
 
100
#include "os-interface.h"
101
#include "release.h"
102
#include "arg-data.h"
103
#include "arg-parse.h"
104
#include "builder.h"
105
#include "contents.h"
106
#include "debug.h"
107
#include "error.h"
108
#include "error-file.h"
109
#include "exception.h"
110
#include "extract.h"
111
#include "gen-errors.h"
112
#include "linker.h"
113
#include "rename-file.h"
114
 
115
#include "solve-cycles.h"
116
 
117
/*--------------------------------------------------------------------------*/
118
 
119
#define USAGE "\
120
\tusage: [mode] [option ...] file ...\n\
121
\twhere mode is one of: '-mc' (create library), '-ml' (link capsules),\n\
122
\t'-mt' (library table of contents) or '-mx' (extract from library),\n\
123
\tand option (for the current mode - default '-ml') is one of:"
124
#ifndef VERSION
125
#define VERSION "tld version 4.0#7"
126
#endif /* !defined (VERSION) */
127
#ifndef RELEASE
128
#define RELEASE "LOCAL"
129
#endif /* !defined (RELEASE) */
130
#ifndef BANNER
131
#define BANNER ""
132
#endif /* !defined (BANNER) */
133
 
134
/*--------------------------------------------------------------------------*/
135
 
136
#ifdef FS_NO_ENUM
137
typedef int ModeT, *ModeP;
138
#define MODE_BUILDER		(0)
139
#define MODE_CONTENTS		(1)
140
#define MODE_EXTRACT		(2)
141
#define MODE_LINKER		(3)
142
#else
143
typedef enum {
144
    MODE_BUILDER,
145
    MODE_CONTENTS,
146
    MODE_EXTRACT,
147
    MODE_LINKER
148
} ModeT, *ModeP;
149
#endif /* defined (FS_NO_ENUM) */
150
 
151
/*--------------------------------------------------------------------------*/
152
 
153
static BoolT    main_used_one_off = FALSE;
154
static BoolT    main_used_other   = FALSE;
155
static ArgDataT main_arg_data;
156
 
157
/*--------------------------------------------------------------------------*/
158
 
159
static void
160
main_print_version PROTO_Z ()
161
{
162
    write_cstring (ostream_error, VERSION);
163
    write_cstring (ostream_error, " (");
164
    write_cstring (ostream_error, RELEASE);
165
    write_cstring (ostream_error, ")");
166
    write_cstring (ostream_error, BANNER);
167
    write_newline (ostream_error);
168
    ostream_flush (ostream_error);
169
}
170
 
171
static void
172
main_handle_all PROTO_N ((option, usage, gclosure, enable))
173
		PROTO_T (CStringP  option X
174
			 ArgUsageP usage X
175
			 GenericP  gclosure X
176
			 BoolT     enable)
177
{
178
    UNUSED (option);
179
    UNUSED (usage);
180
    UNUSED (gclosure);
181
    main_used_other = TRUE;
182
    arg_data_set_extract_all (&main_arg_data, enable);
183
}
184
 
185
static void
186
main_handle_all_hide_defd PROTO_N ((option, usage, gclosure, enable))
187
			  PROTO_T (CStringP  option X
188
				   ArgUsageP usage X
189
				   GenericP  gclosure X
190
				   BoolT     enable)
191
{
192
    UNUSED (option);
193
    UNUSED (usage);
194
    UNUSED (gclosure);
195
    main_used_other = TRUE;
196
    arg_data_set_all_hide_defd (&main_arg_data, enable);
197
}
198
 
199
static void
200
main_handle_basename PROTO_N ((option, usage, gclosure, enable))
201
		     PROTO_T (CStringP  option X
202
			      ArgUsageP usage X
203
			      GenericP  gclosure X
204
			      BoolT     enable)
205
{
206
    UNUSED (option);
207
    UNUSED (usage);
208
    UNUSED (gclosure);
209
    main_used_other = TRUE;
210
    arg_data_set_extract_basename (&main_arg_data, enable);
211
}
212
 
213
static void
214
main_handle_debug_file PROTO_N ((option, usage, gclosure, debug_file))
215
		       PROTO_T (CStringP  option X
216
				ArgUsageP usage X
217
				GenericP  gclosure X
218
				CStringP  debug_file)
219
{
220
    UNUSED (option);
221
    UNUSED (usage);
222
    UNUSED (gclosure);
223
    main_used_other = TRUE;
224
    arg_data_set_debug_file (&main_arg_data, debug_file);
225
}
226
 
227
static void
228
main_handle_help PROTO_N ((option, usage, gclosure))
229
		 PROTO_T (CStringP  option X
230
			  ArgUsageP usage X
231
			  GenericP  gclosure)
232
{
233
    UNUSED (option);
234
    UNUSED (gclosure);
235
    main_used_one_off = TRUE;
236
    write_arg_usage (ostream_error, usage);
237
    write_newline (ostream_error);
238
    ostream_flush (ostream_error);
239
}
240
 
241
static void
242
main_handle_hide PROTO_N ((option, usage, gclosure, shape, name))
243
		 PROTO_T (CStringP  option X
244
			  ArgUsageP usage X
245
			  GenericP  gclosure X
246
			  CStringP  shape X
247
			  CStringP  name)
248
{
249
    UNUSED (option);
250
    UNUSED (usage);
251
    UNUSED (gclosure);
252
    main_used_other = TRUE;
253
    arg_data_add_hide (&main_arg_data, shape, name);
254
}
255
 
256
static void
257
main_handle_hide_defined PROTO_N ((option, usage, gclosure, shape))
258
			 PROTO_T (CStringP  option X
259
				  ArgUsageP usage X
260
				  GenericP  gclosure X
261
				  CStringP  shape)
262
{
263
    UNUSED (option);
264
    UNUSED (usage);
265
    UNUSED (gclosure);
266
    main_used_other = TRUE;
267
    arg_data_add_hide_defined (&main_arg_data, shape);
268
}
269
 
270
static void
271
main_handle_index PROTO_N ((option, usage, gclosure, enable))
272
		  PROTO_T (CStringP  option X
273
			   ArgUsageP usage X
274
			   GenericP  gclosure X
275
			   BoolT     enable)
276
{
277
    UNUSED (option);
278
    UNUSED (usage);
279
    UNUSED (gclosure);
280
    main_used_other = TRUE;
281
    arg_data_set_content_index (&main_arg_data, enable);
282
}
283
 
284
static void
285
main_handle_info PROTO_N ((option, usage, gclosure, enable))
286
		 PROTO_T (CStringP  option X
287
			  ArgUsageP usage X
288
			  GenericP  gclosure X
289
			  BoolT     enable)
290
{
291
    UNUSED (option);
292
    UNUSED (usage);
293
    UNUSED (gclosure);
294
    main_used_other = TRUE;
295
    if (enable) {
296
	error_set_min_report_severity (ERROR_SEVERITY_INFORMATION);
297
    } else {
298
	error_set_min_report_severity (ERROR_SEVERITY_ERROR);
299
    }
300
}
301
 
302
static void
303
main_handle_keep PROTO_N ((option, usage, gclosure, shape, name))
304
		 PROTO_T (CStringP  option X
305
			  ArgUsageP usage X
306
			  GenericP  gclosure X
307
			  CStringP  shape X
308
			  CStringP  name)
309
{
310
    UNUSED (option);
311
    UNUSED (usage);
312
    UNUSED (gclosure);
313
    main_used_other = TRUE;
314
    arg_data_add_keep (&main_arg_data, shape, name);
315
}
316
 
317
static void
318
main_handle_keep_all PROTO_N ((option, usage, gclosure, shape))
319
		     PROTO_T (CStringP  option X
320
			      ArgUsageP usage X
321
			      GenericP  gclosure X
322
			      CStringP  shape)
323
{
324
    UNUSED (option);
325
    UNUSED (usage);
326
    UNUSED (gclosure);
327
    main_used_other = TRUE;
328
    arg_data_add_keep_all (&main_arg_data, shape);
329
}
330
 
331
static void
332
main_handle_library_file PROTO_N ((option, usage, gclosure, library_file))
333
			 PROTO_T (CStringP  option X
334
				  ArgUsageP usage X
335
				  GenericP  gclosure X
336
				  CStringP  library_file)
337
{
338
    UNUSED (option);
339
    UNUSED (usage);
340
    UNUSED (gclosure);
341
    main_used_other = TRUE;
342
    arg_data_add_library_file (&main_arg_data, library_file);
343
}
344
 
345
static void
346
main_handle_match_base PROTO_N ((option, usage, gclosure, enable))
347
		       PROTO_T (CStringP  option X
348
				ArgUsageP usage X
349
				GenericP  gclosure X
350
				BoolT     enable)
351
{
352
    UNUSED (option);
353
    UNUSED (usage);
354
    UNUSED (gclosure);
355
    main_used_other = TRUE;
356
    arg_data_set_extract_match_base (&main_arg_data, enable);
357
}
358
 
359
static void
360
main_handle_output_file PROTO_N ((option, usage, gclosure, output_file))
361
			PROTO_T (CStringP  option X
362
				 ArgUsageP usage X
363
				 GenericP  gclosure X
364
				 CStringP  output_file)
365
{
366
    UNUSED (option);
367
    UNUSED (usage);
368
    UNUSED (gclosure);
369
    main_used_other = TRUE;
370
    arg_data_set_output_file (&main_arg_data, output_file);
371
}
372
 
373
static void
374
main_handle_library_path PROTO_N ((option, usage, gclosure, directory))
375
			 PROTO_T (CStringP  option X
376
				  ArgUsageP usage X
377
				  GenericP  gclosure X
378
				  CStringP  directory)
379
{
380
    UNUSED (option);
381
    UNUSED (usage);
382
    UNUSED (gclosure);
383
    main_used_other = TRUE;
384
    arg_data_add_library_path (&main_arg_data, directory);
385
}
386
 
387
static void
388
main_handle_rename PROTO_N ((option, usage, gclosure, shape, from, to))
389
		   PROTO_T (CStringP  option X
390
			    ArgUsageP usage X
391
			    GenericP  gclosure X
392
			    CStringP  shape X
393
			    CStringP  from X
394
			    CStringP  to)
395
{
396
    UNUSED (option);
397
    UNUSED (usage);
398
    UNUSED (gclosure);
399
    main_used_other = TRUE;
400
    arg_data_parse_rename (&main_arg_data, shape, from, to);
401
}
402
 
403
static void
404
main_handle_rename_file PROTO_N ((option, usage, gclosure, name))
405
			PROTO_T (CStringP  option X
406
				 ArgUsageP usage X
407
				 GenericP  gclosure X
408
				 CStringP  name)
409
{
410
    UNUSED (option);
411
    UNUSED (usage);
412
    UNUSED (gclosure);
413
    main_used_other = TRUE;
414
    rename_file_parse (name, &main_arg_data);
415
}
416
 
417
static void
418
main_handle_show_errors PROTO_N ((option, usage, gclosure))
419
			PROTO_T (CStringP  option X
420
				 ArgUsageP usage X
421
				 GenericP  gclosure)
422
{
423
    UNUSED (option);
424
    UNUSED (usage);
425
    UNUSED (gclosure);
426
    main_used_one_off = TRUE;
427
    write_error_file (ostream_output);
428
    ostream_flush (ostream_output);
429
}
430
 
431
static void
432
main_handle_size PROTO_N ((option, usage, gclosure, enable))
433
		 PROTO_T (CStringP  option X
434
			  ArgUsageP usage X
435
			  GenericP  gclosure X
436
			  BoolT     enable)
437
{
438
    UNUSED (option);
439
    UNUSED (usage);
440
    UNUSED (gclosure);
441
    main_used_other = TRUE;
442
    arg_data_set_content_size (&main_arg_data, enable);
443
}
444
 
445
static void
446
main_handle_suppress PROTO_N ((option, usage, gclosure, shape, name))
447
		     PROTO_T (CStringP  option X
448
			      ArgUsageP usage X
449
			      GenericP  gclosure X
450
			      CStringP  shape X
451
			      CStringP  name)
452
{
453
    UNUSED (option);
454
    UNUSED (usage);
455
    UNUSED (gclosure);
456
    main_used_other = TRUE;
457
    arg_data_add_suppress (&main_arg_data, shape, name);
458
}
459
 
460
static void
461
main_handle_suppress_all PROTO_N ((option, usage, gclosure, shape))
462
			 PROTO_T (CStringP  option X
463
				  ArgUsageP usage X
464
				  GenericP  gclosure X
465
				  CStringP  shape)
466
{
467
    UNUSED (option);
468
    UNUSED (usage);
469
    UNUSED (gclosure);
470
    main_used_other = TRUE;
471
    arg_data_add_suppress_all (&main_arg_data, shape);
472
}
473
 
474
static void
475
main_handle_suppress_mult PROTO_N ((option, usage, gclosure, enable))
476
			  PROTO_T (CStringP  option X
477
				   ArgUsageP usage X
478
				   GenericP  gclosure X
479
				   BoolT     enable)
480
{
481
    UNUSED (option);
482
    UNUSED (usage);
483
    UNUSED (gclosure);
484
    main_used_other = TRUE;
485
    arg_data_set_suppress_mult (&main_arg_data, enable);
486
}
487
 
488
static void
489
main_handle_tdf_version PROTO_N ((option, usage, gclosure, enable))
490
    			PROTO_T (CStringP  option X
491
				 ArgUsageP usage X
492
				 GenericP  gclosure X
493
				 BoolT     enable)
494
{
495
    UNUSED (option);
496
    UNUSED (usage);
497
    UNUSED (gclosure);
498
    main_used_other = TRUE;
499
    arg_data_set_content_version (&main_arg_data, enable);
500
}
501
 
502
static void
503
main_handle_unit_file PROTO_N ((option, usage, gclosure, unit_file))
504
		      PROTO_T (CStringP  option X
505
			       ArgUsageP usage X
506
			       GenericP  gclosure X
507
			       CStringP  unit_file)
508
{
509
    UNUSED (option);
510
    UNUSED (usage);
511
    UNUSED (gclosure);
512
    main_used_other = TRUE;
513
    arg_data_set_unit_file (&main_arg_data, unit_file);
514
}
515
 
516
static void
517
main_handle_version PROTO_N ((option, usage, gclosure))
518
		    PROTO_T (CStringP  option X
519
			     ArgUsageP usage X
520
			     GenericP  gclosure)
521
{
522
    UNUSED (option);
523
    UNUSED (usage);
524
    UNUSED (gclosure);
525
    main_used_one_off = TRUE;
526
    main_print_version ();
527
}
528
 
529
static void
530
main_handle_warning PROTO_N ((option, usage, gclosure, enable))
531
		    PROTO_T (CStringP  option X
532
			     ArgUsageP usage X
533
			     GenericP  gclosure X
534
			     BoolT     enable)
535
{
536
    UNUSED (option);
537
    UNUSED (usage);
538
    UNUSED (gclosure);
539
    main_used_other = TRUE;
540
    if (enable) {
541
	error_set_min_report_severity (ERROR_SEVERITY_WARNING);
542
    } else {
543
	error_set_min_report_severity (ERROR_SEVERITY_ERROR);
544
    }
545
}
546
 
547
/*--------------------------------------------------------------------------*/
548
 
549
static EStringDataT main_description_strings [] = {
550
    UB {
551
	"description of all",
552
	"\n\tEnable/disable extraction of all capsules."
553
    } UE, UB {
554
	"description of all-hide-defined",
555
	"\n\tEnable/disable hiding of all external names of any shape that have a definition."
556
    } UE, UB {
557
	"description of basename",
558
	"\n\tEnable/disable extraction of capsules to their basename."
559
    } UE, UB {
560
	"description of debug-file",
561
	" FILE\n\tWrite debugging output to FILE."
562
    } UE, UB {
563
	"description of help",
564
	"\n\tDisplay an option summary for the current mode."
565
    } UE, UB {
566
	"description of hide",
567
	" SHAPE NAME\n\tHide the external SHAPE NAME."
568
    } UE, UB {
569
	"description of hide-defined",
570
	" SHAPE\n\tHide all external SHAPE names that have a definition."
571
    } UE, UB {
572
	"description of include-library",
573
	" LIBRARY\n\tInclude the contents of LIBRARY in the output library."
574
    } UE, UB {
575
	"description of index",
576
	"\n\tEnable/disable the display of the library index as well as the capsule names."
577
    } UE, UB {
578
	"description of info",
579
	"\n\tEnable/disable informational messages."
580
    } UE, UB {
581
	"description of keep",
582
	" SHAPE NAME\n\tEnsure that external SHAPE NAME is not hidden."
583
    } UE, UB {
584
	"description of keep-all",
585
	" SHAPE\n\tEnsure that no external SHAPE is hidden."
586
    } UE, UB {
587
	"description of library-file",
588
	" FILE\n\tUse FILE as a TDF library."
589
    } UE, UB {
590
	"description of l",
591
	"FILE\n\tUse FILE as a TDF library."
592
    } UE, UB {
593
	"description of match-basename",
594
	"\n\tEnable/disable matching capsules by their basename"
595
    } UE, UB {
596
	"description of output-file",
597
	" FILE\n\tWrite output to FILE (default 'library.tl')."
598
    } UE, UB {
599
	"description of path",
600
	" DIRECTORY\n\tAppend DIRECTORY to library search path."
601
    } UE, UB {
602
	"description of L",
603
	"DIRECTORY\n\tAppend DIRECTORY to library search path."
604
    } UE, UB {
605
	"description of rename",
606
	" SHAPE FROM TO\n\tRename SHAPE FROM to TO."
607
    } UE, UB {
608
	"description of rename-file",
609
	" FILE\n\tParse FILE as a rename file."
610
    } UE, UB {
611
	"description of size",
612
	"\n\tEnable/disable the display of the size of library capsules as well as their names."
613
    } UE, UB {
614
	"description of show-errors",
615
	"\n\tDisplay the current error table on the standard output."
616
    } UE, UB {
617
	"description of suppress",
618
	" SHAPE NAME\n\tDo not try to find a definition for SHAPE NAME."
619
    } UE, UB {
620
	"description of suppress-all",
621
	" SHAPE\n\tDo not try to find a definition for any SHAPE."
622
    } UE, UB {
623
	"description of suppress-mult",
624
	"\n\tEnable/disable the suppression of multiple definitions as library definitions."
625
    } UE, UB {
626
	"description of tdf-version",
627
	"\n\tEnable/disable the display of the version of a TDF library."
628
    } UE, UB {
629
	"description of unit-file",
630
	" FILE\n\tRead unit set names from FILE."
631
    } UE, UB {
632
	"description of version",
633
	"\n\tDisplay the version number on the standard error."
634
    } UE, UB {
635
	"description of warning",
636
	"\n\tEnable/disable warning messages."
637
    } UE, ERROR_END_STRING_LIST
638
};
639
 
640
#ifdef __TenDRA__
641
/* Some conversions to ArgProcP are slightly suspect */
642
#pragma TenDRA begin
643
#pragma TenDRA conversion analysis (pointer-pointer) off
644
#endif
645
 
646
static ArgListT main_builder_arg_list [] = {
647
    {
648
	"debug-file", 'd',			AT_FOLLOWING,
649
	(ArgProcP) main_handle_debug_file,	NIL (GenericP),
650
	UB "description of debug-file" UE
651
    }, {
652
	"help", '?',				AT_EMPTY,
653
	(ArgProcP) main_handle_help,		NIL (GenericP),
654
	UB "description of help" UE
655
    }, {
656
	"include-library", 'i',			AT_FOLLOWING,
657
	(ArgProcP) main_handle_library_file,	NIL (GenericP),
658
	UB "description of include-library" UE
659
    }, {
660
	"output-file", 'o',			AT_FOLLOWING,
661
	(ArgProcP) main_handle_output_file,	NIL (GenericP),
662
	UB "description of output-file" UE
663
    }, {
664
	"show-errors", 'e',			AT_EMPTY,
665
	(ArgProcP) main_handle_show_errors,	NIL (GenericP),
666
	UB "description of show-errors" UE
667
    }, {
668
	"suppress", 's',			AT_FOLLOWING2,
669
	(ArgProcP) main_handle_suppress,	NIL (GenericP),
670
	UB "description of suppress" UE
671
    }, {
672
	"suppress-all", 'S',			AT_FOLLOWING,
673
	(ArgProcP) main_handle_suppress_all,	NIL (GenericP),
674
	UB "description of suppress-all" UE
675
    }, {
676
	"suppress-mult", 'M',			AT_PROC_SWITCH,
677
	(ArgProcP) main_handle_suppress_mult,	NIL (GenericP),
678
	UB "description of suppress-mult" UE
679
    }, {
680
	"unit-file", 'u',			AT_FOLLOWING,
681
	(ArgProcP) main_handle_unit_file,	NIL (GenericP),
682
	UB "description of unit-file" UE
683
    }, {
684
	"version", 'v',				AT_EMPTY,
685
	(ArgProcP) main_handle_version,		NIL (GenericP),
686
	UB "description of version" UE
687
    }, ARG_PARSE_END_LIST
688
};
689
 
690
static ArgListT main_contents_arg_list [] = {
691
    {
692
	"debug-file", 'd',			AT_FOLLOWING,
693
	(ArgProcP) main_handle_debug_file,	NIL (GenericP),
694
	UB "description of debug-file" UE
695
    }, {
696
	"help", '?',				AT_EMPTY,
697
	(ArgProcP) main_handle_help,		NIL (GenericP),
698
	UB "description of help" UE
699
    }, {
700
	"index", 'i',				AT_PROC_SWITCH,
701
	(ArgProcP) main_handle_index,		NIL (GenericP),
702
	UB "description of index" UE
703
    }, {
704
	"show-errors", 'e',			AT_EMPTY,
705
	(ArgProcP) main_handle_show_errors,	NIL (GenericP),
706
	UB "description of show-errors" UE
707
    }, {
708
	"size", 's',				AT_PROC_SWITCH,
709
	(ArgProcP) main_handle_size,		NIL (GenericP),
710
	UB "description of size" UE
711
    }, {
712
	"tdf-version", 't',			AT_PROC_SWITCH,
713
	(ArgProcP) main_handle_tdf_version,	NIL (GenericP),
714
	UB "description of tdf-version" UE
715
    }, {
716
	"version", 'v',				AT_EMPTY,
717
	(ArgProcP) main_handle_version,		NIL (GenericP),
718
	UB "description of version" UE
719
    }, ARG_PARSE_END_LIST
720
};
721
 
722
static ArgListT main_extract_arg_list [] = {
723
    {
724
	"all", 'a',				AT_PROC_SWITCH,
725
	(ArgProcP) main_handle_all,		NIL (GenericP),
726
	UB "description of all" UE
727
    }, {
728
	"basename", 'b',			AT_PROC_SWITCH,
729
	(ArgProcP) main_handle_basename,	NIL (GenericP),
730
	UB "description of basename" UE
731
    }, {
732
	"debug-file", 'd',			AT_FOLLOWING,
733
	(ArgProcP) main_handle_debug_file,	NIL (GenericP),
734
	UB "description of debug-file" UE
735
    }, {
736
	"show-errors", 'e',			AT_EMPTY,
737
	(ArgProcP) main_handle_show_errors,	NIL (GenericP),
738
	UB "description of show-errors" UE
739
    }, {
740
	"help", '?',				AT_EMPTY,
741
	(ArgProcP) main_handle_help,		NIL (GenericP),
742
	UB "description of help" UE
743
    }, {
744
	"info", 'i',				AT_PROC_SWITCH,
745
	(ArgProcP) main_handle_info,		NIL (GenericP),
746
	UB "description of info" UE
747
    }, {
748
	"match-basename", 'm',			AT_PROC_SWITCH,
749
	(ArgProcP) main_handle_match_base,	NIL (GenericP),
750
	UB "description of match-basename" UE
751
    }, {
752
	"version", 'v',				AT_EMPTY,
753
	(ArgProcP) main_handle_version,		NIL (GenericP),
754
	UB "description of version" UE
755
    }, ARG_PARSE_END_LIST
756
};
757
 
758
static ArgListT main_linker_arg_list [] = {
759
    {
760
	"all-hide-defined", 'a',		AT_PROC_SWITCH,
761
	(ArgProcP) main_handle_all_hide_defd,	NIL (GenericP),
762
	UB "description of all-hide-defined" UE
763
    }, {
764
	"debug-file", 'd',			AT_FOLLOWING,
765
	(ArgProcP) main_handle_debug_file,	NIL (GenericP),
766
	UB "description of debug-file" UE
767
    }, {
768
	"help", '?',				AT_EMPTY,
769
	(ArgProcP) main_handle_help,		NIL (GenericP),
770
	UB "description of help" UE
771
    }, {
772
	"hide", 'h',				AT_FOLLOWING2,
773
	(ArgProcP) main_handle_hide,		NIL (GenericP),
774
	UB "description of hide" UE
775
    }, {
776
	"hide-defined", 'H',			AT_FOLLOWING,
777
	(ArgProcP) main_handle_hide_defined,	NIL (GenericP),
778
	UB "description of hide-defined" UE
779
    }, {
780
	"keep", 'k',				AT_FOLLOWING2,
781
	(ArgProcP) main_handle_keep,		NIL (GenericP),
782
	UB "description of keep" UE
783
    }, {
784
	"keep-all", 'K',			AT_FOLLOWING,
785
	(ArgProcP) main_handle_keep_all,	NIL (GenericP),
786
	UB "description of keep-all" UE
787
    }, {
788
	"library", '\0',			AT_FOLLOWING,
789
	(ArgProcP) main_handle_library_file,	NIL (GenericP),
790
	UB "description of library-file" UE
791
    }, {
792
	NIL (CStringP), 'l',			AT_EITHER,
793
	(ArgProcP) main_handle_library_file,	NIL (GenericP),
794
	UB "description of l" UE
795
    }, {
796
	"output-file", 'o',			AT_FOLLOWING,
797
	(ArgProcP) main_handle_output_file,	NIL (GenericP),
798
	UB "description of output-file" UE
799
    }, {
800
	"path", '\0',				AT_FOLLOWING,
801
	(ArgProcP) main_handle_library_path,	NIL (GenericP),
802
	UB "description of path" UE
803
    }, {
804
	NIL (CStringP), 'L',			AT_EITHER,
805
	(ArgProcP) main_handle_library_path,	NIL (GenericP),
806
	UB "description of L" UE
807
    }, {
808
	"rename", 'r',				AT_FOLLOWING3,
809
	(ArgProcP) main_handle_rename,		NIL (GenericP),
810
	UB "description of rename" UE
811
    }, {
812
	"rename-file", 'R',			AT_FOLLOWING,
813
	(ArgProcP) main_handle_rename_file,	NIL (GenericP),
814
	UB "description of rename-file" UE
815
    }, {
816
	"show-errors", 'e',			AT_EMPTY,
817
	(ArgProcP) main_handle_show_errors,	NIL (GenericP),
818
	UB "description of show-errors" UE
819
    }, {
820
	"suppress", 's',			AT_FOLLOWING2,
821
	(ArgProcP) main_handle_suppress,	NIL (GenericP),
822
	UB "description of suppress" UE
823
    }, {
824
	"suppress-all", 'S',			AT_FOLLOWING,
825
	(ArgProcP) main_handle_suppress_all,	NIL (GenericP),
826
	UB "description of suppress-all" UE
827
    }, {
828
	"suppress-mult", 'M',			AT_PROC_SWITCH,
829
	(ArgProcP) main_handle_suppress_mult,	NIL (GenericP),
830
	UB "description of suppress-mult" UE
831
    }, {
832
	"unit-file", 'u',			AT_FOLLOWING,
833
	(ArgProcP) main_handle_unit_file,	NIL (GenericP),
834
	UB "description of unit-file" UE
835
    }, {
836
	"version", 'v',				AT_EMPTY,
837
	(ArgProcP) main_handle_version,		NIL (GenericP),
838
	UB "description of version" UE
839
    }, {
840
	"warnings", 'w',			AT_PROC_SWITCH,
841
	(ArgProcP) main_handle_warning,		NIL (GenericP),
842
	UB "description of warning" UE
843
    }, ARG_PARSE_END_LIST
844
};
845
 
846
#ifdef __TenDRA__
847
#pragma TenDRA end
848
#endif
849
 
850
/*--------------------------------------------------------------------------*/
851
 
852
static ModeT
853
main_init PROTO_N ((argc, argv))
854
	  PROTO_T (int    argc X
855
		   char **argv)
856
{
857
    EStringP  usage_estring = error_define_string ("tld usage message", USAGE);
858
    ModeT     mode          = MODE_LINKER;
859
    ArgListP  arg_list      = main_linker_arg_list;
860
    CStringP  error_file;
861
    int       skip;
862
 
863
    error_init (argv [0], gen_errors_init_errors);
864
    error_intern_strings (main_description_strings);
865
    if ((error_file = getenv ("TLD_ERROR_FILE")) != NIL (CStringP)) {
866
	error_file_parse (error_file, FALSE);
867
    }
868
    argc --;
869
    argv ++;
870
  retry:
871
    if ((argc > 0) && (argv [0][0] == '-') && (argv [0][1] == 'm')) {
872
	char c = argv [0][2];
873
 
874
	argc --;
875
	argv ++;
876
	switch (c) {
877
	  case 'c':
878
	    mode     = MODE_BUILDER;
879
	    arg_list = main_builder_arg_list;
880
	    arg_data_init (&main_arg_data, "library.tl");
881
	    break;
882
	  case 't':
883
	    mode     = MODE_CONTENTS;
884
	    arg_list = main_contents_arg_list;
885
	    arg_data_init (&main_arg_data, NIL (CStringP));
886
	    break;
887
	  case 'x':
888
	    mode     = MODE_EXTRACT;
889
	    arg_list = main_extract_arg_list;
890
	    arg_data_init (&main_arg_data, NIL (CStringP));
891
	    break;
892
	  case 'l':
893
	    goto linker_case;
894
	  case 'v':
895
	    main_used_one_off = TRUE;
896
	    main_used_other   = FALSE;
897
	    main_print_version ();
898
	    goto retry;
899
	  default:
900
	    E_bad_mode (argv [0][2]);
901
	    UNREACHED;
902
	}
903
    } else {
904
      linker_case:
905
	arg_data_init (&main_arg_data, "capsule.j");
906
    }
907
    arg_parse_intern_descriptions (arg_list);
908
    skip = arg_parse_arguments (arg_list, usage_estring, argc, argv);
909
    argc -= skip;
910
    argv += skip;
911
    if (main_used_one_off && (!main_used_other) && (argc == 0)) {
912
	exit (EXIT_SUCCESS);
913
	UNREACHED;
914
    } else if (argc == 0) {
915
	E_missing_files ();
916
	UNREACHED;
917
    }
918
    arg_data_set_files (&main_arg_data, argc, argv);
919
    arg_data_vector_libraries (&main_arg_data);
920
    debug_set_file (arg_data_get_debug_file (&main_arg_data));
921
    return (mode);
922
}
923
 
924
/*--------------------------------------------------------------------------*/
925
 
926
int
927
main PROTO_N ((argc, argv))
928
     PROTO_T (int    argc X
929
	      char **argv)
930
{
931
    HANDLE {
932
	istream_setup ();
933
	ostream_setup ();
934
	switch (main_init (argc, argv)) EXHAUSTIVE {
935
	  case MODE_BUILDER:
936
	    builder_main (&main_arg_data);
937
	    break;
938
	  case MODE_CONTENTS:
939
	    contents_main (&main_arg_data);
940
	    break;
941
	  case MODE_EXTRACT:
942
	    extract_main (&main_arg_data);
943
	    break;
944
	  case MODE_LINKER:
945
	    linker_main (&main_arg_data);
946
	    break;
947
	}
948
    } WITH {
949
	ExceptionP exception = EXCEPTION_EXCEPTION ();
950
 
951
	if (exception == XX_dalloc_no_memory) {
952
	    E_no_memory ();
953
	    UNREACHED;
954
	} else if ((exception == XX_istream_read_error) ||
955
		   (exception == XX_bistream_read_error)) {
956
	    CStringP file = (CStringP) EXCEPTION_VALUE ();
957
 
958
	    E_read_error (file);
959
	    UNREACHED;
960
	} else if ((exception == XX_ostream_write_error) ||
961
		   (exception == XX_bostream_write_error)) {
962
	    CStringP file = (CStringP) EXCEPTION_VALUE ();
963
 
964
	    E_write_error (file);
965
	    UNREACHED;
966
	} else {
967
	    RETHROW ();
968
	    UNREACHED;
969
	}
970
    } END_HANDLE
971
    exit (EXIT_SUCCESS);
972
    UNREACHED;
973
}
974
 
975
/*
976
 * Local variables(smf):
977
 * compile-command: "build_tld next-cc"
978
 * eval: (include::add-path-entry "os-interface" "library" "tdf")
979
 * eval: (include::add-path-entry "frontends" "generated")
980
 * End:
981
**/