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
/*
7 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
7 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:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 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;
7 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;
7 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
/**** arg-data.c --- Command line argument data ADT.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 **** Commentary:
66
 *
67
 * This file implements the ADT that stores the information on the various
68
 * command line options that were given to the TDF linker.
69
 *
70
 **** Change Log:
71
 * $Log: arg-data.c,v $
72
 * Revision 1.1.1.1  1998/01/17  15:57:16  release
73
 * First version to be checked into rolling release.
74
 *
75
 * Revision 1.4  1995/09/22  08:36:58  smf
76
 * Fixed problems with incomplete structures (to shut "tcc" up).
77
 *
78
 * Revision 1.3  1995/07/07  15:31:54  smf
79
 * Updated to support TDF specification 4.0.
80
 *
81
 * Revision 1.2  1994/12/12  11:43:52  smf
82
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
83
 * OSSG C Coding Standards.
84
 *
85
 * Revision 1.1.1.1  1994/07/25  16:03:22  smf
86
 * Initial import of TDF linker 3.5 non shared files.
87
 *
88
**/
89
 
90
/****************************************************************************/
91
 
92
#include "arg-data.h"
93
#include "capsule.h"
94
#include "gen-errors.h"
95
 
96
#include "solve-cycles.h"
97
 
98
/*--------------------------------------------------------------------------*/
99
 
100
static void
7 7u83 101
shape_control_init(ShapeControlP control)
2 7u83 102
{
7 7u83 103
    control->head = NIL(ShapeControlEntryP);
2 7u83 104
}
105
 
106
static ShapeControlEntryP
7 7u83 107
shape_control_find(ShapeControlP control,			    CStringP      shape)
2 7u83 108
{
109
    NStringT           nstring;
110
    ShapeControlEntryP entry;
111
 
7 7u83 112
    nstring_copy_cstring(&nstring, shape);
2 7u83 113
    for (entry = control->head; entry; entry = entry->next) {
7 7u83 114
	if (nstring_equal(&nstring, & (entry->shape))) {
115
	    nstring_destroy(&nstring);
116
	    return(entry);
2 7u83 117
	}
118
    }
7 7u83 119
    entry             = ALLOCATE(ShapeControlEntryT);
2 7u83 120
    entry->next       = control->head;
7 7u83 121
    nstring_assign(& (entry->shape), &nstring);
2 7u83 122
    entry->all        = FALSE;
7 7u83 123
    name_key_list_init(& (entry->names));
2 7u83 124
    control->head     = entry;
7 7u83 125
    return(entry);
2 7u83 126
}
127
 
128
static void
7 7u83 129
shape_control_entry_add_name(ShapeControlEntryP entry,				      CStringP           name)
2 7u83 130
{
131
    NameKeyT key;
132
 
7 7u83 133
    if (name_key_parse_cstring(&key, name)) {
134
	name_key_list_add(& (entry->names), &key);
2 7u83 135
    } else {
7 7u83 136
	E_illegal_external_name(name);
2 7u83 137
    }
138
}
139
 
140
static void
7 7u83 141
shape_control_entry_set(ShapeControlEntryP entry)
2 7u83 142
{
143
    entry->all = TRUE;
144
}
145
 
146
/*--------------------------------------------------------------------------*/
147
 
148
static void
7 7u83 149
rename_control_init(RenameControlP control)
2 7u83 150
{
7 7u83 151
    control->head = NIL(RenameControlEntryP);
2 7u83 152
}
153
 
154
static RenameControlEntryP
7 7u83 155
rename_control_find(RenameControlP control,			     NStringP       shape)
2 7u83 156
{
157
    RenameControlEntryP entry;
158
 
159
    for (entry = control->head; entry; entry = entry->next) {
7 7u83 160
	if (nstring_equal(shape, & (entry->shape))) {
161
	    return(entry);
2 7u83 162
	}
163
    }
7 7u83 164
    entry             = ALLOCATE(RenameControlEntryT);
2 7u83 165
    entry->next       = control->head;
7 7u83 166
    nstring_copy(& (entry->shape), shape);
167
    name_key_pair_list_init(& (entry->names));
2 7u83 168
    control->head     = entry;
7 7u83 169
    return(entry);
2 7u83 170
}
171
 
172
static NameKeyPairListP
7 7u83 173
rename_control_entry_names(RenameControlEntryP entry)
2 7u83 174
{
7 7u83 175
    return(& (entry->names));
2 7u83 176
}
177
 
178
static void
7 7u83 179
rename_control_entry_parse_pair(RenameControlEntryP entry,					 CStringP            from ,
2 7u83 180
					 CStringP            to)
181
{
7 7u83 182
    NStringP shape = & (entry->shape);
2 7u83 183
    NameKeyT from_key;
184
    NameKeyT to_key;
185
 
7 7u83 186
    if (!name_key_parse_cstring(&from_key, from)) {
187
	E_illegal_external_name(from);
188
    } else if (!name_key_parse_cstring(&to_key, to)) {
189
	E_illegal_external_name(to);
190
    } else if (!name_key_pair_list_add(& (entry->names), &from_key, &to_key)) {
191
	E_multiply_renamed_name(shape, &from_key);
192
	name_key_destroy(&from_key);
193
	name_key_destroy(&to_key);
2 7u83 194
    }
195
}
196
 
197
/*--------------------------------------------------------------------------*/
198
 
199
void
7 7u83 200
shape_control_iter(ShapeControlP control,			    void       (*proc)(NStringP, BoolT,
2 7u83 201
							  NameKeyListP,
7 7u83 202
							  GenericP),
2 7u83 203
			    GenericP      closure)
204
{
205
    ShapeControlEntryP entry;
206
 
207
    for (entry = control->head; entry; entry = entry->next) {
7 7u83 208
	(*proc)(& (entry->shape), entry->all, & (entry->names), closure);
2 7u83 209
    }
210
}
211
 
212
void
7 7u83 213
rename_control_iter(RenameControlP control,			     void        (*proc)(NStringP,
2 7u83 214
							    NameKeyPairListP,
7 7u83 215
							    GenericP),
2 7u83 216
			     GenericP       closure)
217
{
218
    RenameControlEntryP entry;
219
 
220
    for (entry = control->head; entry; entry = entry->next) {
7 7u83 221
	(*proc)(& (entry->shape), & (entry->names), closure);
2 7u83 222
    }
223
}
224
 
225
/*--------------------------------------------------------------------------*/
226
 
227
void
7 7u83 228
arg_data_init(ArgDataP arg_data,		       CStringP default_output_file)
2 7u83 229
{
230
    arg_data->all_hide_defined    = FALSE;
231
    arg_data->suppress_mult       = FALSE;
7 7u83 232
    shape_control_init(& (arg_data->hides));
233
    shape_control_init(& (arg_data->keeps));
234
    shape_control_init(& (arg_data->suppresses));
235
    rename_control_init(& (arg_data->renames));
2 7u83 236
    arg_data->extract_all         = FALSE;
237
    arg_data->extract_basename    = FALSE;
238
    arg_data->extract_match_base  = FALSE;
239
    arg_data->content_index       = FALSE;
240
    arg_data->content_size        = FALSE;
241
    arg_data->content_version     = FALSE;
7 7u83 242
    ostream_init(& (arg_data->debug_file));
2 7u83 243
    arg_data->default_output_file = default_output_file;
7 7u83 244
    arg_data->output_file         = NIL(CStringP);
2 7u83 245
    arg_data->num_library_files   = 0;
246
    arg_data->num_library_paths   = 0;
7 7u83 247
    cstring_list_init(&arg_data->library.list.file);
248
    cstring_list_init(& (arg_data->library.list.path));
249
    arg_data->unit_file           = NIL(CStringP);
2 7u83 250
    arg_data->num_files           = 0;
251
}
252
 
253
void
7 7u83 254
arg_data_set_all_hide_defd(ArgDataP arg_data,				    BoolT    enable)
2 7u83 255
{
256
    arg_data->all_hide_defined = enable;
257
}
258
 
259
BoolT
7 7u83 260
arg_data_get_all_hide_defd(ArgDataP arg_data)
2 7u83 261
{
7 7u83 262
    return(arg_data->all_hide_defined);
2 7u83 263
}
264
 
265
void
7 7u83 266
arg_data_set_suppress_mult(ArgDataP arg_data,				    BoolT    enable)
2 7u83 267
{
268
    arg_data->suppress_mult = enable;
269
}
270
 
271
BoolT
7 7u83 272
arg_data_get_suppress_mult(ArgDataP arg_data)
2 7u83 273
{
7 7u83 274
    return(arg_data->suppress_mult);
2 7u83 275
}
276
 
277
void
7 7u83 278
arg_data_add_hide(ArgDataP arg_data,			   CStringP shape ,
2 7u83 279
			   CStringP name)
280
{
7 7u83 281
    ShapeControlEntryP entry = shape_control_find(& (arg_data->hides), shape);
2 7u83 282
 
7 7u83 283
    shape_control_entry_add_name(entry, name);
2 7u83 284
}
285
 
286
void
7 7u83 287
arg_data_add_hide_defined(ArgDataP arg_data,				   CStringP shape)
2 7u83 288
{
7 7u83 289
    ShapeControlEntryP entry = shape_control_find(& (arg_data->hides), shape);
2 7u83 290
 
7 7u83 291
    shape_control_entry_set(entry);
2 7u83 292
}
293
 
294
ShapeControlP
7 7u83 295
arg_data_get_hides(ArgDataP arg_data)
2 7u83 296
{
7 7u83 297
    return(& (arg_data->hides));
2 7u83 298
}
299
 
300
void
7 7u83 301
arg_data_add_keep(ArgDataP arg_data,			   CStringP shape ,
2 7u83 302
			   CStringP name)
303
{
7 7u83 304
    ShapeControlEntryP entry = shape_control_find(& (arg_data->keeps), shape);
2 7u83 305
 
7 7u83 306
    shape_control_entry_add_name(entry, name);
2 7u83 307
}
308
 
309
void
7 7u83 310
arg_data_add_keep_all(ArgDataP arg_data,			       CStringP shape)
2 7u83 311
{
7 7u83 312
    ShapeControlEntryP entry = shape_control_find(& (arg_data->keeps), shape);
2 7u83 313
 
7 7u83 314
    shape_control_entry_set(entry);
2 7u83 315
}
316
 
317
ShapeControlP
7 7u83 318
arg_data_get_keeps(ArgDataP arg_data)
2 7u83 319
{
7 7u83 320
    return(& (arg_data->keeps));
2 7u83 321
}
322
 
323
void
7 7u83 324
arg_data_add_suppress(ArgDataP arg_data,			       CStringP shape ,
2 7u83 325
			       CStringP name)
326
{
7 7u83 327
    ShapeControlEntryP entry = shape_control_find(& (arg_data->suppresses),
2 7u83 328
						   shape);
329
 
7 7u83 330
    shape_control_entry_add_name(entry, name);
2 7u83 331
}
332
 
333
void
7 7u83 334
arg_data_add_suppress_all(ArgDataP arg_data,				   CStringP shape)
2 7u83 335
{
7 7u83 336
    ShapeControlEntryP entry = shape_control_find(& (arg_data->suppresses),
2 7u83 337
						   shape);
338
 
7 7u83 339
    shape_control_entry_set(entry);
2 7u83 340
}
341
 
342
ShapeControlP
7 7u83 343
arg_data_get_suppresses(ArgDataP arg_data)
2 7u83 344
{
7 7u83 345
    return(& (arg_data->suppresses));
2 7u83 346
}
347
 
348
void
7 7u83 349
arg_data_add_rename(ArgDataP arg_data,			     NStringP shape ,
350
			     NameKeyP from ,
2 7u83 351
			     NameKeyP to)
352
{
353
    RenameControlEntryP entry;
354
    NameKeyPairListP    names;
355
 
7 7u83 356
    entry = rename_control_find(& (arg_data->renames), shape);
357
    names = rename_control_entry_names(entry);
358
    if (!name_key_pair_list_add(names, from, to)) {
359
	E_multiply_renamed_name(shape, from);
360
	name_key_destroy(from);
361
	name_key_destroy(to);
2 7u83 362
    }
363
}
364
 
365
void
7 7u83 366
arg_data_parse_rename(ArgDataP arg_data,			       CStringP shape ,
367
			       CStringP from ,
2 7u83 368
			       CStringP to)
369
{
370
    NStringT            nstring;
371
    RenameControlEntryP entry;
372
 
7 7u83 373
    nstring_copy_cstring(&nstring, shape);
374
    entry = rename_control_find(& (arg_data->renames), &nstring);
375
    nstring_destroy(&nstring);
376
    rename_control_entry_parse_pair(entry, from, to);
2 7u83 377
}
378
 
379
RenameControlP
7 7u83 380
arg_data_get_renames(ArgDataP arg_data)
2 7u83 381
{
7 7u83 382
    return(& (arg_data->renames));
2 7u83 383
}
384
 
385
void
7 7u83 386
arg_data_set_extract_all(ArgDataP arg_data,				  BoolT    enable)
2 7u83 387
{
388
    arg_data->extract_all = enable;
389
}
390
 
391
BoolT
7 7u83 392
arg_data_get_extract_all(ArgDataP arg_data)
2 7u83 393
{
7 7u83 394
    return(arg_data->extract_all);
2 7u83 395
}
396
 
397
void
7 7u83 398
arg_data_set_extract_basename(ArgDataP arg_data,				       BoolT    enable)
2 7u83 399
{
400
    arg_data->extract_basename = enable;
401
}
402
 
403
BoolT
7 7u83 404
arg_data_get_extract_basename(ArgDataP arg_data)
2 7u83 405
{
7 7u83 406
    return(arg_data->extract_basename);
2 7u83 407
}
408
 
409
void
7 7u83 410
arg_data_set_extract_match_base(ArgDataP arg_data,					 BoolT    enable)
2 7u83 411
{
412
    arg_data->extract_match_base = enable;
413
}
414
 
415
BoolT
7 7u83 416
arg_data_get_extract_match_base(ArgDataP arg_data)
2 7u83 417
{
7 7u83 418
    return(arg_data->extract_match_base);
2 7u83 419
}
420
 
421
void
7 7u83 422
arg_data_set_content_index(ArgDataP arg_data,				    BoolT    enable)
2 7u83 423
{
424
    arg_data->content_index = enable;
425
}
426
 
427
BoolT
7 7u83 428
arg_data_get_content_index(ArgDataP arg_data)
2 7u83 429
{
7 7u83 430
    return(arg_data->content_index);
2 7u83 431
}
432
 
433
void
7 7u83 434
arg_data_set_content_size(ArgDataP arg_data,				   BoolT    enable)
2 7u83 435
{
436
    arg_data->content_size = enable;
437
}
438
 
439
BoolT
7 7u83 440
arg_data_get_content_size(ArgDataP arg_data)
2 7u83 441
{
7 7u83 442
    return(arg_data->content_size);
2 7u83 443
}
444
 
445
void
7 7u83 446
arg_data_set_content_version(ArgDataP arg_data,				      BoolT    enable)
2 7u83 447
{
448
    arg_data->content_version = enable;
449
}
450
 
451
BoolT
7 7u83 452
arg_data_get_content_version(ArgDataP arg_data)
2 7u83 453
{
7 7u83 454
    return(arg_data->content_version);
2 7u83 455
}
456
 
457
void
7 7u83 458
arg_data_set_debug_file(ArgDataP arg_data,				 CStringP debug_file)
2 7u83 459
{
7 7u83 460
    if (ostream_is_open(& (arg_data->debug_file))) {
461
	E_tld_multiple_debug_files();
2 7u83 462
	UNREACHED;
463
    }
7 7u83 464
    if (!ostream_open(& (arg_data->debug_file), debug_file)) {
465
	E_tld_cannot_open_debug_file(debug_file);
2 7u83 466
	UNREACHED;
467
    }
468
}
469
 
470
OStreamP
7 7u83 471
arg_data_get_debug_file(ArgDataP arg_data)
2 7u83 472
{
7 7u83 473
    return(& (arg_data->debug_file));
2 7u83 474
}
475
 
476
void
7 7u83 477
arg_data_set_output_file(ArgDataP arg_data,				  CStringP output_file)
2 7u83 478
{
479
    if (arg_data->output_file) {
7 7u83 480
	E_tld_multiple_output_files();
2 7u83 481
	UNREACHED;
482
    }
483
    arg_data->output_file = output_file;
484
}
485
 
486
CStringP
7 7u83 487
arg_data_get_output_file(ArgDataP arg_data)
2 7u83 488
{
489
    if (arg_data->output_file) {
7 7u83 490
	return(arg_data->output_file);
2 7u83 491
    } else {
7 7u83 492
	return(arg_data->default_output_file);
2 7u83 493
    }
494
}
495
 
496
void
7 7u83 497
arg_data_add_library_file(ArgDataP arg_data,				   CStringP library_file)
2 7u83 498
{
7 7u83 499
    CStringListP libraries = & (arg_data->library.list.file);
500
    if (!cstring_list_contains(libraries, library_file)) {
501
	arg_data->num_library_files++;
502
	cstring_list_append(libraries, library_file);
2 7u83 503
    }
504
}
505
 
506
void
7 7u83 507
arg_data_add_library_path(ArgDataP arg_data,				   CStringP directory)
2 7u83 508
{
7 7u83 509
    arg_data->num_library_paths++;
510
    cstring_list_append(& (arg_data->library.list.path), directory);
2 7u83 511
}
512
 
513
void
7 7u83 514
arg_data_vector_libraries(ArgDataP arg_data)
2 7u83 515
{
516
    unsigned          num_files = arg_data->num_library_files;
517
    unsigned          num_paths = arg_data->num_library_paths;
7 7u83 518
    CStringP         *files     = ALLOCATE_VECTOR(CStringP, num_files);
519
    CStringP         *paths     = ALLOCATE_VECTOR(CStringP, num_paths);
2 7u83 520
    CStringListEntryP entry;
521
    unsigned          i;
522
 
7 7u83 523
    for (i = 0, entry = cstring_list_head(& (arg_data->library.list.file));
524
	 i < num_files; i++, entry = cstring_list_entry_deallocate(entry)) {
525
	files[i] = cstring_list_entry_string(entry);
2 7u83 526
    }
7 7u83 527
    for (i = 0, entry = cstring_list_head(& (arg_data->library.list.path));
528
	 i < num_paths; i++, entry = cstring_list_entry_deallocate(entry)) {
529
	paths[i] = cstring_list_entry_string(entry);
2 7u83 530
    }
531
    arg_data->library.vector.file = files;
532
    arg_data->library.vector.path = paths;
533
}
534
 
535
unsigned
7 7u83 536
arg_data_num_library_files(ArgDataP arg_data)
2 7u83 537
{
7 7u83 538
    return(arg_data->num_library_files);
2 7u83 539
}
540
 
541
unsigned
7 7u83 542
arg_data_num_library_paths(ArgDataP arg_data)
2 7u83 543
{
7 7u83 544
    return(arg_data->num_library_paths);
2 7u83 545
}
546
 
547
CStringP *
7 7u83 548
arg_data_library_files(ArgDataP arg_data)
2 7u83 549
{
7 7u83 550
    return(arg_data->library.vector.file);
2 7u83 551
}
552
 
553
CStringP *
7 7u83 554
arg_data_library_paths(ArgDataP arg_data)
2 7u83 555
{
7 7u83 556
    return(arg_data->library.vector.path);
2 7u83 557
}
558
 
559
void
7 7u83 560
arg_data_set_unit_file(ArgDataP arg_data,				CStringP unit_file)
2 7u83 561
{
562
    if (arg_data->unit_file) {
7 7u83 563
	E_tld_multiple_unit_files();
2 7u83 564
	UNREACHED;
565
    }
566
    arg_data->unit_file = unit_file;
7 7u83 567
    capsule_read_unit_set_file(unit_file);
2 7u83 568
}
569
 
570
void
7 7u83 571
arg_data_set_files(ArgDataP  arg_data,			    int       num_files ,
2 7u83 572
			    CStringP *files)
573
{
7 7u83 574
    arg_data->num_files = (unsigned)num_files;
2 7u83 575
    arg_data->files     = files;
576
}
577
 
578
unsigned
7 7u83 579
arg_data_get_num_files(ArgDataP arg_data)
2 7u83 580
{
7 7u83 581
    return(arg_data->num_files);
2 7u83 582
}
583
 
584
CStringP *
7 7u83 585
arg_data_get_files(ArgDataP arg_data)
2 7u83 586
{
7 7u83 587
    return(arg_data->files);
2 7u83 588
}
589
 
590
/*
591
 * Local variables(smf):
592
 * eval: (include::add-path-entry "../os-interface" "../library" "../tdf")
593
 * eval: (include::add-path-entry "../generated")
594
 * End:
595
**/