Subversion Repositories tendra.SVN

Rev

Rev 6 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 7u83 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
 */
31
/*
32
    		 Crown Copyright (c) 1997
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/* 80x86/glopt.c */
62
 
63
/**********************************************************************
64
$Author: release $
65
$Date: 1998/01/17 15:55:51 $
66
$Revision: 1.1.1.1 $
67
$Log: glopt.c,v $
68
 * Revision 1.1.1.1  1998/01/17  15:55:51  release
69
 * First version to be checked into rolling release.
70
 *
71
 * Revision 1.3  1996/01/17  11:24:28  pwe
72
 * resurrect performance
73
 *
74
 * Revision 1.2  1995/01/30  12:56:13  pwe
75
 * Ownership -> PWE, tidy banners
76
 *
77
 * Revision 1.1  1994/10/27  14:15:22  jmf
78
 * Initial revision
79
 *
80
 * Revision 1.1  1994/07/12  14:32:29  jmf
81
 * Initial revision
82
 *
83
**********************************************************************/
84
 
85
 
86
 
87
#include "config.h"
88
#include "common_types.h"
89
#include "tags.h"
90
#include "externs.h"
91
#include "expmacs.h"
92
#include "shapemacs.h"
93
#include "exp.h"
94
#include "basicread.h"
95
#include "flags.h"
96
#include "table_fns.h"
97
#include "installglob.h"
98
#include "check.h"
99
#include "glopt.h"
100
 
101
 
102
/* PROCEDURES */
103
 
104
void glopt
105
(dec * dp)
106
{
107
  if (!writable_strings && !strcmp(dp -> dec_u.dec_val.dec_id, "strcpy"))
108
   {
109
     exp i = dp -> dec_u.dec_val.dec_exp;
110
     exp t = pt(i);
111
     if (t == nilexp)
112
       return;
113
 
114
     while (1)
115
      {
116
        if (!last(t) && !last(bro(t)) && last(bro(bro(t))) &&
117
            name(bro(bro(bro(t)))) == apply_tag &&
118
            son(bro(bro(bro(t)))) == t)
119
          {
120
            exp dest = bro(t);
121
            exp source = bro(dest);
122
 
123
            if (name(source) == name_tag && isglob(son(source)) &&
124
                isvar(son(source)) && no(son(source)) == 1)
125
              {
126
                dec * source_dec = brog(son(source));
127
                if (!source_dec -> dec_u.dec_val.extnamed &&
128
                    son(source_dec -> dec_u.dec_val.dec_exp)!= nilexp)
129
                  {
130
                    exp source_def = son(son(source));
131
                    shape sha = sh(source_def);
132
                    if (name(source_def) == string_tag &&
133
                         props(source_def) == 8)
134
                     {
135
                       char * s = nostr(source_def);
136
                       int j;
137
                       int l = shape_size(sha) / 8;
138
                       for (j=0; j < l && s[j]!= 0; ++j);
139
                       if (j < l)
140
                        {
141
	                   exp q;
142
                           exp to_change = bro(source);
143
	                   exp idsc = getexp(sh(bro(source)), nilexp, 0,
144
                                              dest, nilexp,
145
                                              0, 2, ident_tag);
146
	                   exp n1 = getexp(sh(dest), nilexp, 0, idsc,
147
                                             nilexp, 0, 0,
148
						 name_tag);
149
	                   exp n2 = getexp(sh(dest), nilexp, 0, idsc, n1,
150
                                             0, 0, name_tag);
151
                           exp_list el;
152
 
153
                           pt(idsc) = n2;
154
 
155
                           q = f_assign(n1, f_contents(sha, source));
156
                           el.start = q;
157
                           el.end = q;
158
                           el.number = 1;
159
                           q = f_sequence(el, n2);
160
                           clearlast(dest);
161
                           bro(dest) = q;
162
                           setfather(idsc, q);
163
                           kill_exp(t, t);
164
                           replace(to_change, idsc, idsc);
165
                           t = i;
166
                        };
167
                     };
168
                  };
169
              };
170
          };
171
 
172
        if (pt(t) == nilexp)
173
          return;
174
        t = pt(t);
175
      };
176
   };
177
 
178
  if (!writable_strings && !strcmp(dp -> dec_u.dec_val.dec_id, "strlen"))
179
   {
180
     exp i = dp -> dec_u.dec_val.dec_exp;
181
     exp t = pt(i);
182
     if (t == nilexp)
183
       return;
184
 
185
     while (1)
186
      {
187
        if (!last(t) && last(bro(t)) &&
188
            name(bro(bro(t))) == apply_tag &&
189
            son(bro(bro(t))) == t)
190
          {
191
            exp st = bro(t);
192
 
193
            if (name(st) == name_tag && isglob(son(st)) &&
194
                isvar(son(st)) && no(son(st)) == 1)
195
              {
196
                dec * source_dec = brog(son(st));
197
                if (!source_dec -> dec_u.dec_val.extnamed &&
198
                    son(source_dec -> dec_u.dec_val.dec_exp)!= nilexp)
199
                  {
200
                    exp st_def = son(son(st));
201
                    shape sha = sh(st_def);
202
                    if (name(st_def) == string_tag &&
203
                         props(st_def) == 8)
204
                     {
205
                       char * s = nostr(st_def);
206
                       int j;
207
                       int l = shape_size(sha) / 8;
208
                       for (j=0; j < l && s[j]!= 0; ++j);
209
                       if (j < l)
210
                        {
211
                           exp to_change = bro(st);
212
                           exp res = getexp(sh(to_change), nilexp, 0,
213
                               nilexp, nilexp, 0, j, val_tag);
214
                           kill_exp(t, t);
215
                           replace(to_change, res, nilexp);
216
                           t = i;
217
                        };
218
                     };
219
                  };
220
              };
221
          };
222
 
223
        if (pt(t) == nilexp)
224
          return;
225
        t = pt(t);
226
      };
227
   };
228
 
229
 
230
 
231
  return;
232
}