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
Line 60... Line 90...
60
#endif
90
#endif
61
 
91
 
62
#if use_link_stuff
92
#if use_link_stuff
63
extern weak_cell *weak_list;
93
extern weak_cell *weak_list;
64
#include "out.h"
94
#include "out.h"
65
#endif
95
#endif
66
 
96
 
67
#include "xalloc.h"
97
#include "xalloc.h"
68
#include "readglob.h"
98
#include "readglob.h"
69
#include "basicread.h"
99
#include "basicread.h"
70
#include "exp.h"
100
#include "exp.h"
71
#include "expmacs.h"
101
#include "expmacs.h"
72
#include "tags.h"
102
#include "tags.h"
73
#include "machine.h"
103
#include "machine.h"
74
 
104
 
75
 
105
 
76
/* PROCEDURES */
106
/* PROCEDURES */
77
 
107
 
78
extern void out_rename PROTO_S ( ( char *, char * ) ) ;
108
extern void out_rename(char *, char *);
79
 
-
 
80
static char * id_prefix
-
 
81
    PROTO_N ( (s) )
-
 
82
    PROTO_T ( char * s )
-
 
83
{
-
 
84
  char * r;
-
 
85
  int l1, l2;
-
 
86
  l1 = (int)strlen(name_prefix);
-
 
87
  if (l1==0)
-
 
88
     return s;
-
 
89
  l2 = (int)strlen(s);
-
 
90
  r = (char *)xcalloc(l1+l2+1, sizeof(char));
-
 
91
  IGNORE strcpy(r, name_prefix);
-
 
92
  IGNORE strcpy(&r[l1], s);
-
 
93
  return r;
-
 
94
}
-
 
95
 
-
 
96
linkinfo f_make_weak_defn
-
 
97
    PROTO_N ( (e1, e2) )
-
 
98
    PROTO_T ( exp e1 X exp e2 )
-
 
99
{
-
 
100
#if use_link_stuff
-
 
101
  weak_cell * wc = (weak_cell *)xmalloc(sizeof(weak_cell));
-
 
102
 
-
 
103
  wc -> weak_id = brog(son(e1))-> dec_u.dec_val.dec_id;
-
 
104
  wc -> val_id = brog(son(e2))-> dec_u.dec_val.dec_id;
-
 
105
  brog(son(e2))-> dec_u.dec_val.isweak = 1;
-
 
106
  wc -> next = weak_list;
-
 
107
  weak_list = wc;
-
 
108
 
-
 
109
#endif
-
 
110
  kill_exp(e1, e1);
-
 
111
  kill_exp(e2, e2);
-
 
112
  return 0;
-
 
113
}
-
 
114
 
-
 
115
 
109
 
-
 
110
static char *
-
 
111
id_prefix(char *s)
-
 
112
{
-
 
113
	char *r;
-
 
114
	int l1, l2;
-
 
115
	l1 = (int)strlen(name_prefix);
-
 
116
	if (l1==0) {
-
 
117
		return s;
-
 
118
	}
-
 
119
	l2 = (int)strlen(s);
-
 
120
	r = (char *)xcalloc(l1 + l2 + 1, sizeof(char));
-
 
121
	IGNORE strcpy(r, name_prefix);
-
 
122
	IGNORE strcpy(&r[l1], s);
-
 
123
	return r;
-
 
124
}
-
 
125
 
-
 
126
 
-
 
127
linkinfo
-
 
128
f_make_weak_defn(exp e1, exp e2)
-
 
129
{
116
linkinfo f_make_weak_symbol
130
#if use_link_stuff
-
 
131
	weak_cell *wc = (weak_cell *)xmalloc(sizeof(weak_cell));
-
 
132
 
-
 
133
	wc->weak_id = brog(son(e1))->dec_u.dec_val.dec_id;
-
 
134
	wc->val_id = brog(son(e2))->dec_u.dec_val.dec_id;
-
 
135
	brog(son(e2))->dec_u.dec_val.isweak = 1;
-
 
136
	wc->next = weak_list;
-
 
137
	weak_list = wc;
-
 
138
 
-
 
139
#endif
-
 
140
	kill_exp(e1, e1);
117
    PROTO_N ( (id, e) )
141
	kill_exp(e2, e2);
-
 
142
	return 0;
-
 
143
}
-
 
144
 
-
 
145
 
-
 
146
linkinfo
118
    PROTO_T ( tdfstring id X exp e )
147
f_make_weak_symbol(tdfstring id, exp e)
119
{
148
{
120
#if use_link_stuff
149
#if use_link_stuff
121
  char * * lid = &brog(son(e))-> dec_u.dec_val.dec_id;
150
	char **lid = &brog(son(e))->dec_u.dec_val.dec_id;
122
  char * nid = id_prefix(id.ints.chars);
151
	char *nid = id_prefix(id.ints.chars);
123
  brog(son(e))-> dec_u.dec_val.isweak = 1;
152
	brog(son(e))->dec_u.dec_val.isweak = 1;
124
  brog(son(e))-> dec_u.dec_val.extnamed = 1;
153
	brog(son(e))->dec_u.dec_val.extnamed = 1;
125
  outs(".weak ");
154
	outs(".weak ");
126
  outs(nid);
155
	outs(nid);
127
  outnl();
156
	outnl();
128
  out_rename(*lid, nid);
157
	out_rename(*lid, nid);
129
  *lid = nid;
158
	*lid = nid;
130
#endif
159
#endif
131
  kill_exp(e, e);
160
	kill_exp(e, e);
132
  return 0;
161
	return 0;
133
}
162
}
134
 
163
 
-
 
164
 
135
linkinfo f_make_comment
165
linkinfo
136
    PROTO_N ( (id) )
-
 
137
    PROTO_T ( tdfstring id )
166
f_make_comment(tdfstring id)
138
{
167
{
139
#if use_link_stuff
168
#if use_link_stuff
140
  outs(".ident \"");
169
	outs(".ident \"");
141
  outs(id_prefix(id.ints.chars));
170
	outs(id_prefix(id.ints.chars));
142
  outs("\"");
171
	outs("\"");
143
  outnl();
172
	outnl();
144
#endif
173
#endif
145
  return 0;
174
	return 0;
146
}
175
}
147
 
176
 
148
linkinfo f_static_name_def
-
 
149
    PROTO_N ( (e, id) )
-
 
150
    PROTO_T ( exp e X tdfstring id )
-
 
151
{
-
 
152
  char * * oldid = &brog(son(e))-> dec_u.dec_val.dec_id;
-
 
153
  char * newid = id_prefix(id.ints.chars);
-
 
154
 
177
 
-
 
178
linkinfo
155
  if (name(e) != name_tag || !isglob(son(e)))
179
f_static_name_def(exp e, tdfstring id)
156
    {
180
{
-
 
181
	char **oldid = &brog(son(e))->dec_u.dec_val.dec_id;
-
 
182
	char *newid = id_prefix(id.ints.chars);
-
 
183
 
-
 
184
	if (name(e) != name_tag || !isglob(son(e))) {
157
      failer(ILLEGAL_STATIC);
185
		failer(ILLEGAL_STATIC);
158
      kill_exp(e, e);
186
		kill_exp(e, e);
159
      return 0;
187
		return 0;
160
    };
188
	}
161
 
189
 
162
  if (separate_units)
190
	if (separate_units) {
163
     failer(INCOMPATIBLE_U);
191
		failer(INCOMPATIBLE_U);
164
  else
192
	} else {
165
     out_rename(*oldid, newid);
193
		out_rename(*oldid, newid);
-
 
194
	}
166
 
195
 
167
  *oldid = newid;
196
	*oldid = newid;
168
  kill_exp(e, e);
197
	kill_exp(e, e);
-
 
198
	return 0;
-
 
199
}
-
 
200
 
-
 
201
 
-
 
202
void
-
 
203
init_linkinfo(void)
-
 
204
{
-
 
205
	return;
-
 
206
}
-
 
207
 
-
 
208
 
-
 
209
linkinfo f_dummy_linkinfo;
-
 
210
 
-
 
211
linkinfo_list
-
 
212
new_linkinfo_list(int n)
-
 
213
{
-
 
214
	UNUSED(n);
169
  return 0;
215
	return 0;
170
}
216
}
-
 
217
 
-
 
218
 
-
 
219
linkinfo_list
-
 
220
add_linkinfo_list(linkinfo_list list, linkinfo elem, int index)
-
 
221
{
-
 
222
	UNUSED(list);
-
 
223
	UNUSED(elem);
-
 
224
	UNUSED(index);
-
 
225
	return 0;
-
 
226
}
-
 
227
 
-
 
228
 
-
 
229
void
-
 
230
start_make_linkinfo_unit(int no_of_tokens, int no_of_tags, int no_of_als,
-
 
231
			 int no_of_diagtypes)
-
 
232
{
-
 
233
	int i;
-
 
234
	UNUSED(no_of_diagtypes);
-
 
235
 
-
 
236
	unit_no_of_tokens = no_of_tokens;
-
 
237
	unit_ind_tokens = (tok_define **)xcalloc(unit_no_of_tokens,
-
 
238
						 sizeof(tok_define *));
-
 
239
	for (i = 0; i < unit_no_of_tokens; ++i) {
-
 
240
		unit_ind_tokens[i] = (tok_define *)0;
-
 
241
	}
171
 
242
 
172
void init_linkinfo
243
	unit_no_of_tags = no_of_tags;
-
 
244
	unit_ind_tags = (dec **)xcalloc(unit_no_of_tags, sizeof(dec *));
173
    PROTO_Z ()
245
	for (i = 0; i < unit_no_of_tags; ++i) {
174
{
-
 
175
  return;
246
		unit_ind_tags[i] = (dec *)0;
176
}
247
	}
177
 
248
 
178
linkinfo f_dummy_linkinfo;
249
	unit_no_of_als = no_of_als;
-
 
250
	unit_ind_als = (aldef **)xcalloc(unit_no_of_als, sizeof(aldef *));
-
 
251
	for (i = 0; i < unit_no_of_als; ++i) {
-
 
252
		unit_ind_als[i] = (aldef *)0;
-
 
253
	}
179
 
254
 
180
linkinfo_list new_linkinfo_list
-
 
181
    PROTO_N ( (n) )
-
 
182
    PROTO_T ( int n )
-
 
183
{
-
 
184
  UNUSED(n);
-
 
185
  return 0;
255
	return;
186
}
256
}
-
 
257
 
187
 
258
 
-
 
259
int
188
linkinfo_list add_linkinfo_list
260
f_make_linkinfo_unit(void)
189
    PROTO_N ( (list, elem, index) )
-
 
190
    PROTO_T ( linkinfo_list list X linkinfo elem X int index )
-
 
191
{
261
{
192
  UNUSED(list); UNUSED(elem); UNUSED(index);
-
 
193
  return 0;
-
 
194
}
-
 
195
 
-
 
196
 
-
 
197
void start_make_linkinfo_unit
-
 
198
    PROTO_N ( (no_of_tokens, no_of_tags, no_of_als, no_of_diagtypes) )
-
 
199
    PROTO_T ( int no_of_tokens X int no_of_tags X int no_of_als X int no_of_diagtypes )
-
 
200
{
-
 
201
  int i;
-
 
202
  UNUSED(no_of_diagtypes);
-
 
203
 
-
 
204
  unit_no_of_tokens = no_of_tokens;
-
 
205
  unit_ind_tokens = (tok_define * *)xcalloc(unit_no_of_tokens,
-
 
206
                    sizeof(tok_define *));
-
 
207
  for (i = 0; i < unit_no_of_tokens; ++i)
-
 
208
    unit_ind_tokens[i] = (tok_define*)0;
-
 
209
 
-
 
210
  unit_no_of_tags = no_of_tags;
-
 
211
  unit_ind_tags = (dec * *)xcalloc(unit_no_of_tags,
-
 
212
                    sizeof(dec *));
-
 
213
  for (i = 0; i < unit_no_of_tags; ++i)
-
 
214
    unit_ind_tags[i] = (dec*)0;
-
 
215
 
-
 
216
  unit_no_of_als = no_of_als;
-
 
217
  unit_ind_als = (aldef * *)xcalloc(unit_no_of_als,
-
 
218
                    sizeof(aldef *));
-
 
219
  for (i = 0; i < unit_no_of_als; ++i)
-
 
220
    unit_ind_als[i] = (aldef*)0;
-
 
221
 
-
 
222
  return;
-
 
223
}
-
 
224
 
-
 
225
int f_make_linkinfo_unit
-
 
226
    PROTO_Z ()
-
 
227
{
-
 
228
  int i;
262
	int i;
229
  int j = 0;
263
	int j = 0;
230
  int no_of_labels;
264
	int no_of_labels;
231
  for (i = 0; i < unit_no_of_tokens; ++i)
265
	for (i = 0; i < unit_no_of_tokens; ++i) {
232
   {
-
 
233
    if (unit_ind_tokens[i] == (tok_define*)0)
266
		if (unit_ind_tokens[i] == (tok_define *)0)
234
      unit_ind_tokens[i] = &unit_toktab[j++];
267
			unit_ind_tokens[i] = &unit_toktab[j++];
235
   };
268
	}
236
  j = 0;
269
	j = 0;
237
  for (i = 0; i < unit_no_of_tags; ++i)
270
	for (i = 0; i < unit_no_of_tags; ++i) {
238
   {
-
 
239
    if (unit_ind_tags[i] == (dec*)0)
271
		if (unit_ind_tags[i] == (dec *)0)
240
      unit_ind_tags[i] = &unit_tagtab[j++];
272
			unit_ind_tags[i] = &unit_tagtab[j++];
241
   };
273
	}
242
  j = 0;
274
	j = 0;
243
  for (i = 0; i < unit_no_of_als; ++i)
275
	for (i = 0; i < unit_no_of_als; ++i) {
244
   {
-
 
245
    if (unit_ind_als[i] == (aldef*)0)
276
		if (unit_ind_als[i] == (aldef *)0)
246
      unit_ind_als[i] = &unit_altab[j++];
277
			unit_ind_als[i] = &unit_altab[j++];
247
   };
278
	}
248
  start_bytestream();
279
	start_bytestream();
249
  no_of_labels = small_dtdfint();
280
	no_of_labels = small_dtdfint();
250
  unit_no_of_labels = no_of_labels;
281
	unit_no_of_labels = no_of_labels;
251
  unit_labtab = (exp*)xcalloc(unit_no_of_labels, sizeof(exp));
282
	unit_labtab = (exp *)xcalloc(unit_no_of_labels, sizeof(exp));
252
  IGNORE d_linkinfo_list();
283
	IGNORE d_linkinfo_list();
253
  end_bytestream();
284
	end_bytestream();
-
 
285
 
-
 
286
	xfree((void *)unit_ind_tokens);
-
 
287
	xfree((void *)unit_ind_tags);
-
 
288
	xfree((void *)unit_ind_als);
-
 
289
	xfree((void *)unit_labtab);
-
 
290
	xfree((void *)unit_toktab);
-
 
291
	xfree((void *)unit_tagtab);
254
 
292
 
255
  xfree((void*)unit_ind_tokens);
-
 
256
  xfree((void*)unit_ind_tags);
-
 
257
  xfree((void*)unit_ind_als);
293
	return 0;
258
  xfree((void*)unit_labtab);
-
 
259
  xfree((void*)unit_toktab);
-
 
260
  xfree((void*)unit_tagtab);
-
 
-
 
294
}
261
 
295
 
262
  return 0;
-
 
263
}
-
 
264
 
296
 
265
linkinfo_props f_make_linkinfos
297
linkinfo_props
266
    PROTO_N ( (nl, tds) )
-
 
267
    PROTO_T ( tdfint nl X linkinfo_list tds )
298
f_make_linkinfos(tdfint nl, linkinfo_list tds)
268
{
299
{
-
 
300
	UNUSED(nl);
269
  UNUSED(nl); UNUSED(tds);
301
	UNUSED(tds);
270
  return 0;
302
	return 0;
271
}
303
}