Subversion Repositories tendra.SVN

Rev

Rev 6 | Details | Compare with Previous | Last modification | View Log | RSS feed

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