Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 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) 1996
32
    		 Crown Copyright (c) 1996
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 14... Line 44...
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
Line 75... Line 105...
75
#include "installglob.h"
105
#include "installglob.h"
76
#include "check.h"
106
#include "check.h"
77
#include "glopt.h"
107
#include "glopt.h"
78
 
108
 
79
 
109
 
80
void glopt
110
void
81
    PROTO_N ( (dp) )
-
 
82
    PROTO_T ( dec * dp )
111
glopt(dec *dp)
83
{
112
{
84
  if (!writable_strings && !strcmp(dp -> dec_u.dec_val.dec_id, "_strcpy"))
113
  if (!writable_strings && !strcmp(dp->dec_u.dec_val.dec_id, "_strcpy")) {
85
   {
-
 
86
     exp i = dp -> dec_u.dec_val.dec_exp;
114
     exp i = dp->dec_u.dec_val.dec_exp;
87
     exp t = pt(i);
115
     exp t = pt(i);
88
     if (t == nilexp)
116
     if (t == nilexp) {
89
       return;
117
       return;
-
 
118
     }
90
 
119
 
91
     while (1)
120
     while (1) {
92
      {
-
 
93
        if (!last(t) && !last(bro(t)) && last(bro(bro(t))) &&
121
        if (!last(t) && !last(bro(t)) && last(bro(bro(t))) &&
94
            name(bro(bro(bro(t)))) == apply_tag &&
122
            name(bro(bro(bro(t)))) == apply_tag &&
95
            son(bro(bro(bro(t)))) == t)
123
            son(bro(bro(bro(t)))) == t) {
96
          {
-
 
97
            exp dest = bro(t);
124
            exp dest = bro(t);
98
            exp source = bro(dest);
125
            exp source = bro(dest);
99
 
126
 
100
            if (name(source) == name_tag && isglob(son(source)) &&
127
            if (name(source) == name_tag && isglob(son(source)) &&
101
                isvar(son(source)) && no(son(source)) == 1)
128
                isvar(son(source)) && no(son(source)) == 1) {
102
              {
-
 
103
                dec * source_dec = brog(son(source));
129
                dec * source_dec = brog(son(source));
104
                if (!source_dec -> dec_u.dec_val.extnamed &&
130
                if (!source_dec->dec_u.dec_val.extnamed &&
105
                    son(source_dec -> dec_u.dec_val.dec_exp) != nilexp)
131
                    son(source_dec->dec_u.dec_val.dec_exp) != nilexp) {
106
                  {
-
 
107
                    exp source_def = son(son(source));
132
                    exp source_def = son(son(source));
108
                    shape sha = sh(source_def);
133
                    shape sha = sh(source_def);
109
                    if (name(source_def) == string_tag &&
134
                    if (name(source_def) == string_tag &&
110
                         ptno(source_def) == 8)
135
                         ptno(source_def) == 8) {
111
                     {
-
 
112
                       char * s = nostr(source_def);
136
                       char * s = nostr(source_def);
113
                       long n, j;
137
                       long n, j;
114
                       int l = shape_size(sha) / 8;
138
                       int l = shape_size(sha) / 8;
115
                       for (j=0; j < l && s[j] != 0; ++j);
139
                       for (j=0; j < l && s[j] != 0; ++j){
116
                       if (j < l)
140
			       ;
-
 
141
		       }
117
                        {
142
                       if (j < l) {
118
	                   exp q;
143
	                   exp q;
119
                           exp to_change = bro(source);
144
                           exp to_change = bro(source);
120
	                   exp idsc = getexp(sh(bro(source)), nilexp, 0,
145
			   exp idsc = getexp(sh(bro(source)), nilexp, 0, dest,
121
                                              dest, nilexp,
-
 
122
                                              0, 2, ident_tag);
146
					     nilexp, 0, 2, ident_tag);
123
	                   exp n1 = getexp(sh(dest), nilexp, 0, idsc,
147
			   exp n1 = getexp(sh(dest), nilexp, 0, idsc, nilexp,
124
                                             nilexp, 0, 0, name_tag);
148
					   0, 0, name_tag);
125
	                   exp n2 = getexp(sh(dest), nilexp, 0, idsc, n1,
149
			   exp n2 = getexp(sh(dest), nilexp, 0, idsc, n1, 0, 0,
126
                                             0, 0, name_tag);
150
					   name_tag);
127
                           exp_list el;
151
                           exp_list el;
128
 
152
 
129
                           pt(idsc) = n2;
153
                           pt(idsc) = n2;
130
 
154
 
131
                           q = f_assign(n1, f_contents(sha, source));
155
                           q = f_assign(n1, f_contents(sha, source));
Line 137... Line 161...
137
                           bro(dest) = q;
161
                           bro(dest) = q;
138
                           setfather(idsc, q);
162
                           setfather(idsc, q);
139
                           kill_exp(t, t);
163
                           kill_exp(t, t);
140
                           replace(to_change, idsc, idsc);
164
                           replace(to_change, idsc, idsc);
141
                           t = i;
165
                           t = i;
142
                        };
166
                        }
143
                     };
167
                     }
144
                  };
168
                  }
145
              };
169
              }
146
          };
170
          }
147
 
171
 
148
        if (pt(t) == nilexp)
172
        if (pt(t) == nilexp) {
149
          return;
173
          return;
-
 
174
	}
150
        t = pt(t);
175
        t = pt(t);
151
      };
176
      }
152
   };
177
   }
153
 
178
 
154
  if (!writable_strings && !strcmp(dp -> dec_u.dec_val.dec_id, "_strlen"))
179
  if (!writable_strings && !strcmp(dp->dec_u.dec_val.dec_id, "_strlen")) {
155
   {
-
 
156
     exp i = dp -> dec_u.dec_val.dec_exp;
180
     exp i = dp->dec_u.dec_val.dec_exp;
157
     exp t = pt(i);
181
     exp t = pt(i);
158
     if (t == nilexp)
182
     if (t == nilexp) {
159
       return;
183
       return;
-
 
184
     }
160
 
185
 
161
     while (1)
186
     while (1) {
162
      {
-
 
163
        if (!last(t) && last(bro(t)) &&
-
 
164
            name(bro(bro(t))) == apply_tag &&
187
        if (!last(t) && last(bro(t)) && name(bro(bro(t))) == apply_tag &&
165
            son(bro(bro(t))) == t)
188
	    son(bro(bro(t))) == t) {
166
          {
-
 
167
            exp st = bro(t);
189
            exp st = bro(t);
168
 
190
 
169
            if (name(st) == name_tag && isglob(son(st)) &&
191
            if (name(st) == name_tag && isglob(son(st)) &&
170
                isvar(son(st)) && no(son(st)) == 1)
192
                isvar(son(st)) && no(son(st)) == 1) {
171
              {
-
 
172
                dec * source_dec = brog(son(st));
193
                dec * source_dec = brog(son(st));
173
                if (!source_dec -> dec_u.dec_val.extnamed &&
194
                if (!source_dec->dec_u.dec_val.extnamed &&
174
                    son(source_dec -> dec_u.dec_val.dec_exp) != nilexp)
195
                    son(source_dec->dec_u.dec_val.dec_exp) != nilexp) {
175
                  {
-
 
176
                    exp st_def = son(son(st));
196
                    exp st_def = son(son(st));
177
                    shape sha = sh(st_def);
197
                    shape sha = sh(st_def);
178
                    if (name(st_def) == string_tag &&
198
                    if (name(st_def) == string_tag && ptno(st_def) == 8) {
179
                         ptno(st_def) == 8)
-
 
180
                     {
-
 
181
                       char * s = nostr(st_def);
199
                       char * s = nostr(st_def);
182
                       long n, j;
200
                       long n, j;
183
                       int l = shape_size(sha) / 8;
201
                       int l = shape_size(sha) / 8;
184
                       for (j=0; j < l && s[j] != 0; ++j);
202
                       for (j=0; j < l && s[j] != 0; ++j) {
185
                       if (j < l)
203
			       ;
-
 
204
		       }
186
                        {
205
                       if (j < l) {
187
                           exp to_change = bro(st);
206
                           exp to_change = bro(st);
188
                           exp res = getexp(sh(to_change), nilexp, 0,
207
			   exp res = getexp(sh(to_change), nilexp, 0, nilexp,
189
                               nilexp, nilexp, 0, j, val_tag);
208
					    nilexp, 0, j, val_tag);
190
                           kill_exp(t, t);
209
                           kill_exp(t, t);
191
                           replace(to_change, res, nilexp);
210
                           replace(to_change, res, nilexp);
192
                           t = i;
211
                           t = i;
193
                        };
212
                       }
194
                     };
213
                    }
195
                  };
214
                }
196
              };
215
            }
197
          };
216
        }
198
 
217
 
199
        if (pt(t) == nilexp)
218
        if (pt(t) == nilexp) {
200
          return;
219
          return;
-
 
220
	}
201
        t = pt(t);
221
        t = pt(t);
202
      };
222
     }
203
   };
223
  }
204
 
-
 
205
 
-
 
206
 
224
 
207
  return;
225
  return;
208
}
226
}