2 |
7u83 |
1 |
/*
|
|
|
2 |
Copyright (c) 1993 Open Software Foundation, Inc.
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
All Rights Reserved
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
Permission to use, copy, modify, and distribute this software
|
|
|
9 |
and its documentation for any purpose and without fee is hereby
|
|
|
10 |
granted, provided that the above copyright notice appears in all
|
|
|
11 |
copies and that both the copyright notice and this permission
|
|
|
12 |
notice appear in supporting documentation.
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
|
|
|
16 |
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
17 |
PARTICULAR PURPOSE.
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
|
|
|
21 |
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
22 |
LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
|
|
|
23 |
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
24 |
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
/*
|
|
|
28 |
Crown Copyright (c) 1997
|
|
|
29 |
|
|
|
30 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
31 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
32 |
acting through the Defence Evaluation and Research Agency
|
|
|
33 |
(DERA). It is made available to Recipients with a
|
|
|
34 |
royalty-free licence for its use, reproduction, transfer
|
|
|
35 |
to other parties and amendment for any purpose not excluding
|
|
|
36 |
product development provided that any such use et cetera
|
|
|
37 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
38 |
|
|
|
39 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
40 |
reproduced upon any copies or amended versions of it;
|
|
|
41 |
|
|
|
42 |
(2) Any amended version of it shall be clearly marked to
|
|
|
43 |
show both the nature of and the organisation responsible
|
|
|
44 |
for the relevant amendment or amendments;
|
|
|
45 |
|
|
|
46 |
(3) Its onward transfer from a recipient to another
|
|
|
47 |
party shall be deemed to be that party's acceptance of
|
|
|
48 |
these conditions;
|
|
|
49 |
|
|
|
50 |
(4) DERA gives no warranty or assurance as to its
|
|
|
51 |
quality or suitability for any purpose and DERA accepts
|
|
|
52 |
no liability whatsoever in relation to any use to which
|
|
|
53 |
it may be put.
|
|
|
54 |
*/
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/**********************************************************************
|
|
|
59 |
$Author: release $
|
|
|
60 |
$Date: 1998/02/04 15:48:48 $
|
|
|
61 |
$Revision: 1.2 $
|
|
|
62 |
$Log: glopt.c,v $
|
|
|
63 |
* Revision 1.2 1998/02/04 15:48:48 release
|
|
|
64 |
* Added OSF copyright message.
|
|
|
65 |
*
|
|
|
66 |
* Revision 1.1.1.1 1998/01/17 15:55:56 release
|
|
|
67 |
* First version to be checked into rolling release.
|
|
|
68 |
*
|
|
|
69 |
* Revision 1.2 1996/10/04 16:01:08 pwe
|
|
|
70 |
* add banners and mod for PWE ownership
|
|
|
71 |
*
|
|
|
72 |
**********************************************************************/
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
#include "config.h"
|
|
|
76 |
#include "common_types.h"
|
|
|
77 |
#include "tags.h"
|
|
|
78 |
#include "externs.h"
|
|
|
79 |
#include "expmacs.h"
|
|
|
80 |
#include "shapemacs.h"
|
|
|
81 |
#include "exp.h"
|
|
|
82 |
#include "basicread.h"
|
|
|
83 |
#include "flags.h"
|
|
|
84 |
#include "table_fns.h"
|
|
|
85 |
#include "installglob.h"
|
|
|
86 |
#include "check.h"
|
|
|
87 |
#include "glopt.h"
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
#define MAX_STRCPY_INLINE_LEN 4
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
void glopt PROTO_N ((dp)) PROTO_T (dec * dp)
|
|
|
94 |
{
|
|
|
95 |
char *id = dp -> dec_u.dec_val.dec_id;
|
|
|
96 |
|
|
|
97 |
if (!writable_strings && (strcmp(id, "__strcpy") == 0 || strcmp(id, "__builtin_strcpy") == 0))
|
|
|
98 |
{
|
|
|
99 |
exp i = dp -> dec_u.dec_val.dec_exp;
|
|
|
100 |
exp t = pt(i);
|
|
|
101 |
if (t == nilexp)
|
|
|
102 |
return;
|
|
|
103 |
|
|
|
104 |
while (1)
|
|
|
105 |
{
|
|
|
106 |
if (!last(t) && !last(bro(t)) && last(bro(bro(t))) &&
|
|
|
107 |
name(bro(bro(bro(t)))) == apply_tag &&
|
|
|
108 |
son(bro(bro(bro(t)))) == t)
|
|
|
109 |
{
|
|
|
110 |
exp dest = bro(t);
|
|
|
111 |
exp source = bro(dest);
|
|
|
112 |
|
|
|
113 |
if (name(source) == name_tag && isglob(son(source)) &&
|
|
|
114 |
isvar(son(source)) && no(son(source)) == 1)
|
|
|
115 |
{
|
|
|
116 |
dec * source_dec = brog(son(source));
|
|
|
117 |
if (!source_dec -> dec_u.dec_val.extnamed &&
|
|
|
118 |
son(source_dec -> dec_u.dec_val.dec_exp) != nilexp)
|
|
|
119 |
{
|
|
|
120 |
exp source_def = son(son(source));
|
|
|
121 |
shape sha = sh(source_def);
|
|
|
122 |
if (name(source_def) == string_tag &&
|
|
|
123 |
ptno(source_def) == 8)
|
|
|
124 |
{
|
|
|
125 |
char * s = nostr(source_def);
|
|
|
126 |
int j;
|
|
|
127 |
int l = shape_size(sha) / 8;
|
|
|
128 |
for (j=0; j < l && s[j] != 0; ++j);
|
|
|
129 |
if (j < MAX_STRCPY_INLINE_LEN && j < l)
|
|
|
130 |
{
|
|
|
131 |
exp q;
|
|
|
132 |
exp to_change = bro(source);
|
|
|
133 |
exp idsc = getexp(sh(bro(source)), nilexp, 0,
|
|
|
134 |
dest, nilexp,
|
|
|
135 |
0, 2, ident_tag);
|
|
|
136 |
exp n1 = getexp(sh(dest), nilexp, 0, idsc,
|
|
|
137 |
nilexp, 0, 0, name_tag);
|
|
|
138 |
exp n2 = getexp(sh(dest), nilexp, 0, idsc, n1,
|
|
|
139 |
0, 0, name_tag);
|
|
|
140 |
exp_list el;
|
|
|
141 |
|
|
|
142 |
pt(idsc) = n2;
|
|
|
143 |
|
|
|
144 |
q = f_assign(n1, f_contents(sha, source));
|
|
|
145 |
el.start = q;
|
|
|
146 |
el.end = q;
|
|
|
147 |
el.number = 1;
|
|
|
148 |
q = f_sequence(el, n2);
|
|
|
149 |
clearlast(dest);
|
|
|
150 |
bro(dest) = q;
|
|
|
151 |
setfather(idsc, q);
|
|
|
152 |
kill_exp(t, t);
|
|
|
153 |
replace(to_change, idsc, idsc);
|
|
|
154 |
t = i;
|
|
|
155 |
};
|
|
|
156 |
};
|
|
|
157 |
};
|
|
|
158 |
};
|
|
|
159 |
};
|
|
|
160 |
|
|
|
161 |
if (pt(t) == nilexp)
|
|
|
162 |
return;
|
|
|
163 |
t = pt(t);
|
|
|
164 |
};
|
|
|
165 |
};
|
|
|
166 |
|
|
|
167 |
if (!writable_strings && (strcmp(id, "__strlen") == 0 || strcmp(id, "__builtin_strlen") == 0))
|
|
|
168 |
{
|
|
|
169 |
exp i = dp -> dec_u.dec_val.dec_exp;
|
|
|
170 |
exp t = pt(i);
|
|
|
171 |
if (t == nilexp)
|
|
|
172 |
return;
|
|
|
173 |
|
|
|
174 |
while (1)
|
|
|
175 |
{
|
|
|
176 |
if (!last(t) && last(bro(t)) &&
|
|
|
177 |
name(bro(bro(t))) == apply_tag &&
|
|
|
178 |
son(bro(bro(t))) == t)
|
|
|
179 |
{
|
|
|
180 |
exp st = bro(t);
|
|
|
181 |
|
|
|
182 |
if (name(st) == name_tag && isglob(son(st)) &&
|
|
|
183 |
isvar(son(st)) && no(son(st)) == 1)
|
|
|
184 |
{
|
|
|
185 |
dec * source_dec = brog(son(st));
|
|
|
186 |
if (!source_dec -> dec_u.dec_val.extnamed &&
|
|
|
187 |
son(source_dec -> dec_u.dec_val.dec_exp) != nilexp)
|
|
|
188 |
{
|
|
|
189 |
exp st_def = son(son(st));
|
|
|
190 |
shape sha = sh(st_def);
|
|
|
191 |
if (name(st_def) == string_tag &&
|
|
|
192 |
ptno(st_def) == 8)
|
|
|
193 |
{
|
|
|
194 |
char * s = nostr(st_def);
|
|
|
195 |
long j;
|
|
|
196 |
int l = shape_size(sha) / 8;
|
|
|
197 |
for (j=0; j < l && s[j] != 0; ++j);
|
|
|
198 |
if (j < l)
|
|
|
199 |
{
|
|
|
200 |
exp to_change = bro(st);
|
|
|
201 |
exp res = getexp(sh(to_change), nilexp, 0,
|
|
|
202 |
nilexp, nilexp, 0, j, val_tag);
|
|
|
203 |
kill_exp(t, t);
|
|
|
204 |
replace(to_change, res, nilexp);
|
|
|
205 |
t = i;
|
|
|
206 |
};
|
|
|
207 |
};
|
|
|
208 |
};
|
|
|
209 |
};
|
|
|
210 |
};
|
|
|
211 |
|
|
|
212 |
if (pt(t) == nilexp)
|
|
|
213 |
return;
|
|
|
214 |
t = pt(t);
|
|
|
215 |
};
|
|
|
216 |
};
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
return;
|
|
|
221 |
}
|