Subversion Repositories tendra.SVN

Rev

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

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