Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /branches/tendra5/src/tools/tcc/filename.c – Rev 5 and 6

Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 37... Line 67...
37
#include "suffix.h"
67
#include "suffix.h"
38
#include "utility.h"
68
#include "utility.h"
39
 
69
 
40
 
70
 
41
/*
71
/*
285
 
339
 
286
    This routine converts a file type, t, into the corresponding file
-
 
287
    suffix.  It needs to be kept in step with Table 1 and Table 2.
-
 
288
*/
-
 
289
 
-
 
290
static char *file_suffix
340
static char *
291
    PROTO_N ( ( t ) )
-
 
292
    PROTO_T ( int t )
341
file_suffix(int t)
293
{
342
{
294
    static char suff [3] ;
343
	static char suff[3];
295
    suff [0] = 0 ;
344
	suff[0] = 0;
296
    suff [1] = 0 ;
345
	suff[1] = 0;
297
    suff [2] = 0 ;
346
	suff[2] = 0;
298
    switch ( t ) {
347
	switch (t) {
-
 
348
	case C_SOURCE:
299
	case C_SOURCE : suff [0] = C_SOURCE_KEY ; break ;
349
		suff[0] = C_SOURCE_KEY;
-
 
350
		break;
-
 
351
	case PREPROC_C:
300
	case PREPROC_C : suff [0] = PREPROC_C_KEY ; break ;
352
		suff[0] = PREPROC_C_KEY;
-
 
353
		break;
-
 
354
	case CPP_SOURCE:
301
	case CPP_SOURCE : suff [0] = CPP_SOURCE_KEY ; break ;
355
		suff[0] = CPP_SOURCE_KEY;
-
 
356
		break;
-
 
357
	case PREPROC_CPP:
302
	case PREPROC_CPP : suff [0] = PREPROC_CPP_KEY ; break ;
358
		suff[0] = PREPROC_CPP_KEY;
-
 
359
		break;
-
 
360
	case INDEP_TDF:
303
	case INDEP_TDF : suff [0] = INDEP_TDF_KEY ; break ;
361
		suff[0] = INDEP_TDF_KEY;
-
 
362
		break;
304
	case INDEP_TDF_AUX : {
363
	case INDEP_TDF_AUX:
305
	    suff [0] = INDEP_TDF_KEY ;
364
		suff[0] = INDEP_TDF_KEY;
306
	    suff [1] = EXTRA_KEY ;
365
		suff[1] = EXTRA_KEY;
307
	    break ;
366
		break;
308
	}
367
	case DEP_TDF:
309
	case DEP_TDF : suff [0] = DEP_TDF_KEY ; break ;
368
		suff[0] = DEP_TDF_KEY;
-
 
369
		break;
-
 
370
	case AS_SOURCE:
310
	case AS_SOURCE : suff [0] = AS_SOURCE_KEY ; break ;
371
		suff[0] = AS_SOURCE_KEY;
-
 
372
		break;
-
 
373
	case BINARY_OBJ:
311
	case BINARY_OBJ : suff [0] = BINARY_OBJ_KEY ; break ;
374
		suff[0] = BINARY_OBJ_KEY;
-
 
375
		break;
312
	case BINARY_OBJ_AUX : {
376
	case BINARY_OBJ_AUX:
313
	    if ( ( use_sparc_cc == 1 ) && use_system_cc ) {
377
		if ((use_sparc_cc == 1) && use_system_cc) {
314
		suff [0] = '.' ;
378
			suff[0] = '.';
315
		suff [1] = BINARY_OBJ_KEY ;
379
			suff[1] = BINARY_OBJ_KEY;
316
	    } else {
380
		} else {
317
		suff [0] = BINARY_OBJ_AUX_KEY ;
381
			suff[0] = BINARY_OBJ_AUX_KEY;
318
	    }
382
		}
319
	    break ;
383
		break;
320
	}
384
	case PRETTY_TDF:
321
	case PRETTY_TDF : suff [0] = PRETTY_TDF_KEY ; break ;
385
		suff[0] = PRETTY_TDF_KEY;
-
 
386
		break;
-
 
387
	case PL_TDF:
322
	case PL_TDF : suff [0] = PL_TDF_KEY ; break ;
388
		suff[0] = PL_TDF_KEY;
-
 
389
		break;
-
 
390
	case MIPS_G_FILE:
323
	case MIPS_G_FILE : suff [0] = MIPS_G_FILE_KEY ; break ;
391
		suff[0] = MIPS_G_FILE_KEY;
-
 
392
		break;
-
 
393
	case MIPS_T_FILE:
324
	case MIPS_T_FILE : suff [0] = MIPS_T_FILE_KEY ; break ;
394
		suff[0] = MIPS_T_FILE_KEY;
-
 
395
		break;
-
 
396
	case C_SPEC:
325
	case C_SPEC : suff [0] = C_SPEC_KEY ; break ;
397
		suff[0] = C_SPEC_KEY;
-
 
398
		break;
-
 
399
	case CPP_SPEC:
326
	case CPP_SPEC : suff [0] = CPP_SPEC_KEY ; break ;
400
		suff[0] = CPP_SPEC_KEY;
-
 
401
		break;
327
    }
402
	}
328
    if ( suff [0] ) {
403
	if (suff[0]) {
329
	if ( case_insensitive && is_upper_case ( suff [0] ) ) {
404
		if (case_insensitive && is_upper_case(suff[0])) {
330
	    /* Make allowances for case insensitive systems */
405
			/* Make allowances for case insensitive systems */
331
	    to_lower_case ( suff ) ;
406
			to_lower_case(suff);
332
	    suff [1] = suff [0] ;
407
			suff[1] = suff[0];
-
 
408
		}
-
 
409
		return (suff);
333
	}
410
	}
334
	return ( suff ) ;
-
 
335
    }
-
 
336
    error ( SERIOUS, "Illegal file type" ) ;
411
	error(SERIOUS, "Illegal file type");
337
    return ( file_suffix ( DEFAULT_TYPE ) ) ;
412
	return (file_suffix(DEFAULT_TYPE));
338
}
413
}
483
 
562
 
484
/*
563
/*
485
    CREATE A FILENAME FROM ANOTHER FILENAME
564
 * CREATE A FILENAME FROM ANOTHER FILENAME
486
 
565
 *
487
    This routine creates a new filename structure by forming the file
566
 * This routine creates a new filename structure by forming the file derived
488
    derived from p which has type t and storage s.  This routine needs
567
 * from p which has type t and storage s. This routine needs to be kept in step
489
    to be kept in step with Table 1 and Table 2.
568
 * with Table 1 and Table 2.
490
*/
569
 */
491
 
570
 
492
filename *make_filename
571
filename *
493
    PROTO_N ( ( p, t, s ) )
-
 
494
    PROTO_T ( filename *p X int t X int s )
572
make_filename(filename *p, int t, int s)
495
{
573
{
496
    boolean f = 0 ;
574
	boolean f = 0;
497
    char *b, *d, *e ;
575
	char *b, *d, *e;
498
    char *nm = null ;
576
	char *nm = null;
499
    filename *q = new_filename () ;
577
	filename *q = new_filename();
500
 
578
 
501
    /* Examine the storage class */
579
	/* Examine the storage class */
502
    switch ( s ) {
580
	switch (s) {
503
	case INPUT_FILE :
581
	case INPUT_FILE:
504
	case INPUT_OPTION : {
582
	case INPUT_OPTION:
505
	    /* This shouldn't occur */
583
		/* This shouldn't occur */
506
	    d = null ;
584
		d = null;
507
	    break ;
585
		break;
508
	}
-
 
509
	case OUTPUT_FILE : {
586
	case OUTPUT_FILE:
510
	    /* Check output file name */
587
		/* Check output file name */
511
	    if ( final_name ) {
588
		if (final_name) {
512
		static boolean used_final_name = 0 ;
589
			static boolean used_final_name = 0;
513
		if ( used_final_name ) {
590
			if (used_final_name) {
-
 
591
				error(WARNING,
514
		    error ( WARNING, "Can only name one file with '-o'" ) ;
592
				      "Can only name one file with '-o'");
515
		} else {
593
			} else {
516
		    nm = final_name ;
594
				nm = final_name;
517
		    b = find_basename ( nm ) ;
595
				b = find_basename(nm);
518
#ifdef EXECUTABLE_SUFFIX
596
#ifdef EXECUTABLE_SUFFIX
-
 
597
				if (t == EXECUTABLE &&
519
		    if ( t == EXECUTABLE && strchr ( b, '.' ) == null ) {
598
				    strchr(b, '.') == null) {
520
			/* Add '.exe' suffix if necessary */
599
					/* Add '.exe' suffix if necessary */
-
 
600
					nm = string_concat(nm,
521
			nm = string_concat ( nm, EXECUTABLE_SUFFIX ) ;
601
							   EXECUTABLE_SUFFIX);
522
			b = string_concat ( b, EXECUTABLE_SUFFIX ) ;
602
					b = string_concat(b, EXECUTABLE_SUFFIX);
523
		    }
603
				}
524
#endif
604
#endif
525
		    used_final_name = 1 ;
605
				used_final_name = 1;
526
		    f = 1 ;
606
				f = 1;
-
 
607
			}
527
		}
608
		}
-
 
609
		d = workdir;
528
	    }
610
		break;
-
 
611
	case PRESERVED_FILE:
-
 
612
		/* Preserved files are turned into output files */
529
	    d = workdir ;
613
		d = workdir;
-
 
614
		s = OUTPUT_FILE;
-
 
615
		break;
-
 
616
	case TEMP_FILE:
-
 
617
		/* Temporary files */
-
 
618
		d = tempdir;
-
 
619
		break;
-
 
620
	default:
-
 
621
		error(INTERNAL, "Illegal storage type");
-
 
622
		d = null;
530
	    break ;
623
		break;
531
	}
624
	}
532
	case PRESERVED_FILE : {
-
 
533
	    /* Preserved files are turned into output files */
-
 
534
	    d = workdir ;
-
 
535
	    s = OUTPUT_FILE ;
-
 
536
	    break ;
-
 
537
	}
-
 
538
	case TEMP_FILE : {
-
 
539
	    /* Temporary files */
-
 
540
	    d = tempdir ;
-
 
541
	    break ;
-
 
542
	}
-
 
543
	default : {
-
 
544
	    error ( INTERNAL, "Illegal storage type" ) ;
-
 
545
	    d = null ;
-
 
546
	    break ;
-
 
547
	}
-
 
548
    }
-
 
549
 
-
 
550
    /* Find the file name */
-
 
551
    if ( nm == null ) {
-
 
552
	if ( p != null && p->type == t ) {
-
 
553
	    nm = find_basename ( p->name ) ;
-
 
554
	    if ( d != null ) {
-
 
555
		IGNORE sprintf ( buffer, "%s/%s", d, nm ) ;
-
 
556
		nm = string_copy ( buffer ) ;
-
 
557
	    }
-
 
558
	    b = p->bname ;
-
 
559
	} else if ( s == TEMP_FILE && p != null && !verbose ) {
-
 
560
	    switch ( t ) {
-
 
561
		case BINARY_OBJ_AUX :
-
 
562
		case BINARY_OBJ : break ;
-
 
563
		case C_SPEC : break ;
-
 
564
		case CPP_SPEC : break ;
-
 
565
		case INDEP_TDF_AUX :
-
 
566
		case INDEP_TDF : {
-
 
567
		    if ( make_archive || make_complex || tokdef_name ) {
-
 
568
			break ;
-
 
569
		    }
-
 
570
		    goto default_lab ;
-
 
571
		}
-
 
572
		default :
-
 
573
		default_lab : {
-
 
574
		    b = p->bname ;
-
 
575
		    e = file_suffix ( t ) ;
-
 
576
		    IGNORE sprintf ( buffer, "%s/%s.%s", d, TEMP_NAME, e ) ;
-
 
577
		    nm = string_copy ( buffer ) ;
-
 
578
		    break ;
-
 
579
		}
-
 
580
	    }
-
 
581
	}
-
 
582
    }
-
 
583
 
625
 
584
    /* Find the file name */
626
	/* Find the file name */
585
    if ( nm == null ) {
627
	if (nm == null) {
586
	if ( p == null || make_up_names ) {
628
		if (p != null && p->type == t) {
587
	    static int seq = 0 ;
629
			nm = find_basename(p->name);
-
 
630
			if (d != null) {
588
	    IGNORE sprintf ( buffer, MADE_UP_NAME, seq++ ) ;
631
				IGNORE sprintf(buffer, "%s/%s", d, nm);
589
	    b = string_copy ( buffer ) ;
632
				nm = string_copy(buffer);
-
 
633
			}
-
 
634
			b = p->bname;
-
 
635
		} else if (s == TEMP_FILE && p != null && !verbose) {
-
 
636
			switch (t) {
-
 
637
			case BINARY_OBJ_AUX:
-
 
638
			case BINARY_OBJ:
-
 
639
				break;
-
 
640
			case C_SPEC:
-
 
641
				break;
-
 
642
			case CPP_SPEC:
590
	} else {
643
				break;
-
 
644
			case INDEP_TDF_AUX:
-
 
645
			case INDEP_TDF:
-
 
646
				if (make_archive || make_complex ||
-
 
647
				    tokdef_name) {
-
 
648
					break;
-
 
649
				}
-
 
650
				goto default_lab;
-
 
651
			default:
-
 
652
default_lab:
591
	    b = p->bname ;
653
				b = p->bname;
-
 
654
				e = file_suffix(t);
-
 
655
				IGNORE sprintf(buffer, "%s/%s.%s", d,
-
 
656
					       TEMP_NAME, e);
-
 
657
				nm = string_copy(buffer);
-
 
658
				break;
-
 
659
			}
-
 
660
		}
592
	}
661
	}
-
 
662
 
-
 
663
	/* Find the file name */
-
 
664
	if (nm == null) {
-
 
665
		if (p == null || make_up_names) {
-
 
666
			static int seq = 0;
-
 
667
			IGNORE sprintf(buffer, MADE_UP_NAME, seq++);
-
 
668
			b = string_copy(buffer);
-
 
669
		} else {
-
 
670
			b = p->bname;
-
 
671
		}
593
	e = file_suffix ( t ) ;
672
		e = file_suffix(t);
594
	if ( d == null ) {
673
		if (d == null) {
595
	    IGNORE sprintf ( buffer, "%s.%s", b, e ) ;
674
			IGNORE sprintf(buffer, "%s.%s", b, e);
596
	} else {
675
		} else {
597
	    IGNORE sprintf ( buffer, "%s/%s.%s", d, b, e ) ;
676
			IGNORE sprintf(buffer, "%s/%s.%s", d, b, e);
-
 
677
		}
-
 
678
		nm = string_copy(buffer);
598
	}
679
	}
599
	nm = string_copy ( buffer ) ;
-
 
600
    }
-
 
601
 
680
 
602
    /* Fill in the fields of the result */
681
	/* Fill in the fields of the result */
603
    SET ( b ) ;
682
	SET(b);
604
    q->name = nm ;
683
	q->name = nm;
605
    q->bname = b ;
684
	q->bname = b;
606
    q->uniq = ( p ? p->uniq : new_unique () ) ;
685
	q->uniq = (p ? p->uniq : new_unique());
607
    q->type = t ;
686
	q->type = t;
608
    q->storage = s ;
687
	q->storage = s;
609
    q->final = f ;
688
	q->final = f;
610
    q->aux = null ;
689
	q->aux = null;
611
    q->next = null ;
690
	q->next = null;
612
    return ( q ) ;
691
	return (q);
613
}
692
}