Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | 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
#include "config.h"
32
#include "types.h"
33
#include "fetch.h"
34
#include "read_types.h"
35
#include "analyser.h"
36
#include "utility.h"
37
 
38
 
39
/*
40
    LIST OF DIRECTORIES
41
 
42
    This is the list of all directories to be searched for included files.
43
*/
44
 
45
static directory *search_path = null ;
46
 
47
 
48
/*
49
    INPUT FILE
50
 
51
    The current input file, together with its name.
52
*/
53
 
54
FILE *input ;
55
char *input_file = null ;
56
 
57
 
58
/*
59
    OPEN INPUT FILE
60
 
61
    This routine opens the file nm.  If search is true it will search
62
    for it along search_path.
63
*/
64
 
65
void open_input
66
    PROTO_N ( ( nm, search ) )
67
    PROTO_T ( char *nm X int search )
68
{
69
    input = fopen ( nm, ( text_input ? "r" : "rb" ) ) ;
70
    if ( search && input == null ) {
71
	directory *d = search_path ;
72
	while ( input == null && d ) {
73
	    char buff [1000] ;
74
	    IGNORE sprintf ( buff, "%s/%s", d->dirname, nm ) ;
75
	    input = fopen ( buff, ( text_input ? "r" : "rb" ) ) ;
76
	    d = d->next ;
77
	}
78
    }
79
    if ( input == null ) fatal_error ( "Can't open input file, %s", nm ) ;
80
    input_file = nm ;
81
    bits_in_buff = 0 ;
82
    bytes_read = 0 ;
83
    crt_line_no = 1 ;
84
    line_no = 1 ;
85
    looked_ahead = 0 ;
86
    return ;
87
}
88
 
89
 
90
/*
91
    ADD A DIRECTORY TO THE SEARCH PATH
92
 
93
    The directory nm is added to search_path.
94
*/
95
 
96
void add_directory
97
    PROTO_N ( ( nm ) )
98
    PROTO_T ( char *nm )
99
{
100
    directory *d = alloc_nof ( directory, 1 ) ;
101
    d->dirname = nm ;
102
    d->next = null ;
103
    if ( search_path == null ) {
104
	search_path = d ;
105
    } else {
106
	directory *p = search_path ;
107
	while ( p->next ) p = p->next ;
108
	p->next = d ;
109
    }
110
    return ;
111
}
112
 
113
 
114
/*
115
    OUTPUT FILE
116
 
117
    The current output file.
118
*/
119
 
120
FILE *output /* = stdout */ ;
121
 
122
 
123
/*
124
    OPEN OUTPUT FILE
125
 
126
    The output file nm is opened.
127
*/
128
 
129
void open_output
130
    PROTO_N ( ( nm ) )
131
    PROTO_T ( char *nm )
132
{
133
    static char *opened = null ;
134
    if ( opened ) {
135
	warning ( "Multiple output files given, using %s", opened ) ;
136
	return ;
137
    }
138
    output = fopen ( nm, ( text_output ? "w" : "wb" ) ) ;
139
    if ( output == null ) fatal_error ( "Can't open output file, %s", nm ) ;
140
    opened = nm ;
141
    return ;
142
}