1 | /******************************************************************************/ |
---|
2 | /* */ |
---|
3 | /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */ |
---|
4 | /* */ |
---|
5 | /* Copyright or © or Copr. Laurent Debreu (Laurent.Debreu@imag.fr) */ |
---|
6 | /* Cyril Mazauric (Cyril.Mazauric@imag.fr) */ |
---|
7 | /* This software is governed by the CeCILL-C license under French law and */ |
---|
8 | /* abiding by the rules of distribution of free software. You can use, */ |
---|
9 | /* modify and/ or redistribute the software under the terms of the CeCILL-C */ |
---|
10 | /* license as circulated by CEA, CNRS and INRIA at the following URL */ |
---|
11 | /* "http://www.cecill.info". */ |
---|
12 | /* */ |
---|
13 | /* As a counterpart to the access to the source code and rights to copy, */ |
---|
14 | /* modify and redistribute granted by the license, users are provided only */ |
---|
15 | /* with a limited warranty and the software's author, the holder of the */ |
---|
16 | /* economic rights, and the successive licensors have only limited */ |
---|
17 | /* liability. */ |
---|
18 | /* */ |
---|
19 | /* In this respect, the user's attention is drawn to the risks associated */ |
---|
20 | /* with loading, using, modifying and/or developing or reproducing the */ |
---|
21 | /* software by the user in light of its specific status of free software, */ |
---|
22 | /* that may mean that it is complicated to manipulate, and that also */ |
---|
23 | /* therefore means that it is reserved for developers and experienced */ |
---|
24 | /* professionals having in-depth computer knowledge. Users are therefore */ |
---|
25 | /* encouraged to load and test the software's suitability as regards their */ |
---|
26 | /* requirements in conditions enabling the security of their systems and/or */ |
---|
27 | /* data to be ensured and, more generally, to use and operate it in the */ |
---|
28 | /* same conditions as regards security. */ |
---|
29 | /* */ |
---|
30 | /* The fact that you are presently reading this means that you have had */ |
---|
31 | /* knowledge of the CeCILL-C license and that you accept its terms. */ |
---|
32 | /******************************************************************************/ |
---|
33 | /* version 1.0 */ |
---|
34 | /******************************************************************************/ |
---|
35 | #include <stdio.h> |
---|
36 | #include <stdlib.h> |
---|
37 | #include <string.h> |
---|
38 | #include "decl.h" |
---|
39 | |
---|
40 | /******************************************************************************/ |
---|
41 | /* CompareNewparsingandoldone */ |
---|
42 | /******************************************************************************/ |
---|
43 | /* this subroutine is used to compare the old treatement with */ |
---|
44 | /* the new one */ |
---|
45 | /******************************************************************************/ |
---|
46 | /* _______ _______ _______ _______ _______ */ |
---|
47 | /* + + + + + + + + + + */ |
---|
48 | /* + glob +--->+ glob +--->+ glob +--->+ glob +--->+ glob + */ |
---|
49 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
50 | /* */ |
---|
51 | /* = not= = */ |
---|
52 | /* _______ _______ _______ */ |
---|
53 | /* + + + + + + */ |
---|
54 | /* + tmp +--->+ tmp +--->+ tmp + */ |
---|
55 | /* +______+ +______+ +______+ */ |
---|
56 | /* */ |
---|
57 | /******************************************************************************/ |
---|
58 | void CompareNewparsingandoldone() |
---|
59 | { |
---|
60 | listvar *NewTreated; |
---|
61 | listvar *OldTreated; |
---|
62 | listvar *OldTreatedPrec; |
---|
63 | int Out; |
---|
64 | listindice *newindice; |
---|
65 | |
---|
66 | OldTreatedPrec = (listvar *)NULL; |
---|
67 | NewTreated = globliste; |
---|
68 | while ( NewTreated ) |
---|
69 | { |
---|
70 | /* we are going to compare the two treatement */ |
---|
71 | /* each time that we meet in the oldlist the same record we */ |
---|
72 | /* remove it from the tmplocallist */ |
---|
73 | OldTreated = tmplocallist; |
---|
74 | Out = 0; |
---|
75 | while ( OldTreated && Out == 0 ) |
---|
76 | { |
---|
77 | if ( !strcasecmp(NewTreated->var->nomvar, OldTreated->var->nomvar)) |
---|
78 | { |
---|
79 | /* We should keep the same indice for tabvars table than */ |
---|
80 | /* the old one */ |
---|
81 | NewTreated->var->indicetabvars = OldTreated->var->indicetabvars; |
---|
82 | /* we remove it from the tmplocallist */ |
---|
83 | if ( OldTreated == tmplocallist ) |
---|
84 | { |
---|
85 | tmplocallist = tmplocallist -> suiv; |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | OldTreatedPrec->suiv = OldTreated -> suiv; |
---|
90 | } |
---|
91 | /* We go out of the loop because we find two variables */ |
---|
92 | /* with the same name in the same file */ |
---|
93 | Out = 1; |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | OldTreatedPrec = OldTreated; |
---|
98 | OldTreated = OldTreated -> suiv; |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | if ( !OldTreated && Out == 0) |
---|
103 | { |
---|
104 | /* if this tmplocallist has been readed without finding the */ |
---|
105 | /* variable of the globliste */ |
---|
106 | /* it means that this variable has been added */ |
---|
107 | /* in this case we choose a new tabvars indice */ |
---|
108 | /* for this variable */ |
---|
109 | if ( Listofavailableindices ) |
---|
110 | { |
---|
111 | NewTreated->var->indicetabvars = Listofavailableindices -> indice; |
---|
112 | Listofavailableindices = Listofavailableindices ->suiv; |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | indicemaxtabvars = indicemaxtabvars + 1; |
---|
117 | NewTreated->var->indicetabvars = indicemaxtabvars; |
---|
118 | } |
---|
119 | } |
---|
120 | /* On passe a l'enregistrement suivant */ |
---|
121 | NewTreated = NewTreated -> suiv; |
---|
122 | } |
---|
123 | if ( tmplocallist ) |
---|
124 | { |
---|
125 | /* if the tmplocallist is not empty it means that some variables */ |
---|
126 | /* has been removed in the new version of the filetoparse */ |
---|
127 | /* in this case we should record the indice of the tabvars */ |
---|
128 | /* to know that this field is empty */ |
---|
129 | while (tmplocallist) |
---|
130 | { |
---|
131 | if ( tmplocallist -> var -> indicetabvars != 0 ) |
---|
132 | { |
---|
133 | newindice=(listindice *) malloc (sizeof (listindice)); |
---|
134 | newindice -> indice = tmplocallist -> var -> indicetabvars; |
---|
135 | newindice -> suiv = Listofavailableindices; |
---|
136 | Listofavailableindices = newindice; |
---|
137 | } |
---|
138 | tmplocallist = tmplocallist -> suiv; |
---|
139 | } |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | /******************************************************************************/ |
---|
145 | /* ajoutevar_1 */ |
---|
146 | /******************************************************************************/ |
---|
147 | /* Firstpass 1 */ |
---|
148 | /* We should add this declaration to the globliste */ |
---|
149 | /******************************************************************************/ |
---|
150 | void ajoutevar_1(listvar *listtoadd) |
---|
151 | { |
---|
152 | if ( firstpass == 1 && VariableIsParameter == 0 ) |
---|
153 | if ( aftercontainsdeclare == 0 || fortran77 == 1 ) |
---|
154 | { |
---|
155 | globliste = AddListvarToListvar(listtoadd,globliste,1); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | /******************************************************************************/ |
---|
160 | /* ajoutevarsave_1 */ |
---|
161 | /******************************************************************************/ |
---|
162 | /* Firstpass 1 */ |
---|
163 | /* We should add this declaration to the globliste. case SAVE */ |
---|
164 | /******************************************************************************/ |
---|
165 | void ajoutevarsave_1(listvar *listtoadd) |
---|
166 | { |
---|
167 | if ( VariableIsParameter == 0 && SaveDeclare == 1 && firstpass == 1 ) |
---|
168 | { |
---|
169 | globliste = AddListvarToListvar(listtoadd,globliste,1); |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | /******************************************************************************/ |
---|
174 | /* UpdateIndiceTabvarsofGlobliste */ |
---|
175 | /******************************************************************************/ |
---|
176 | /* */ |
---|
177 | /******************************************************************************/ |
---|
178 | /* */ |
---|
179 | /******************************************************************************/ |
---|
180 | void UpdateIndiceTabvarsofGlobliste() |
---|
181 | { |
---|
182 | |
---|
183 | int indicetmp; |
---|
184 | listvar *NewTreated; |
---|
185 | listvar *OldTreated; |
---|
186 | listvar *OldTreatedPrec; |
---|
187 | int Out; |
---|
188 | FILE *dependglobaloutput; |
---|
189 | |
---|
190 | |
---|
191 | if ( Did_filetoparse_treated == 1 ) |
---|
192 | { |
---|
193 | |
---|
194 | tmplocallist = Readthedependfile( NameTamponfile , tmplocallist); |
---|
195 | |
---|
196 | if ((dependglobaloutput=fopen(".dependglobal","r"))!=NULL) |
---|
197 | { |
---|
198 | fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars); |
---|
199 | fclose(dependglobaloutput); |
---|
200 | oldindicemaxtabvars = indicemaxtabvars; |
---|
201 | } |
---|
202 | /* Read the list of available indice */ |
---|
203 | Readthedependavailablefile(); |
---|
204 | /* */ |
---|
205 | indicetmp = indicemaxtabvars; |
---|
206 | OldTreatedPrec = (listvar *)NULL; |
---|
207 | NewTreated = globliste; |
---|
208 | while ( NewTreated ) |
---|
209 | { |
---|
210 | /* we are going to compare the two treatement */ |
---|
211 | /* each time that we meet in the oldlist the same record we */ |
---|
212 | /* remove it from the tmplocallist */ |
---|
213 | OldTreated = tmplocallist; |
---|
214 | Out = 0; |
---|
215 | while ( OldTreated && Out == 0 ) |
---|
216 | { |
---|
217 | if ( !strcasecmp(NewTreated->var->nomvar, OldTreated->var->nomvar)) |
---|
218 | { |
---|
219 | /* We should keep the same indice for tabvars table than */ |
---|
220 | /* the old one */ |
---|
221 | NewTreated->var->indicetabvars = OldTreated->var->indicetabvars; |
---|
222 | /* we remove it from the tmplocallist */ |
---|
223 | if ( OldTreated == tmplocallist ) |
---|
224 | { |
---|
225 | tmplocallist = tmplocallist -> suiv; |
---|
226 | } |
---|
227 | else |
---|
228 | { |
---|
229 | OldTreatedPrec->suiv = OldTreated -> suiv; |
---|
230 | } |
---|
231 | /* We go out of the loop because we find two variables */ |
---|
232 | /* with the same name in the same file */ |
---|
233 | Out = 1; |
---|
234 | } |
---|
235 | else |
---|
236 | { |
---|
237 | OldTreatedPrec = OldTreated; |
---|
238 | OldTreated = OldTreated -> suiv; |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | if ( !OldTreated && Out == 0) |
---|
243 | { |
---|
244 | /* if this tmplocallist has been readed without finding the */ |
---|
245 | /* variable of the globliste */ |
---|
246 | /* it means that this variable has been added */ |
---|
247 | /* in this case we choose a new tabvars indice */ |
---|
248 | /* for this variable */ |
---|
249 | if ( Listofavailableindices ) |
---|
250 | { |
---|
251 | NewTreated->var->indicetabvars = Listofavailableindices -> indice; |
---|
252 | Listofavailableindices = Listofavailableindices ->suiv; |
---|
253 | } |
---|
254 | else |
---|
255 | { |
---|
256 | indicetmp = indicetmp + 1; |
---|
257 | NewTreated->var->indicetabvars = indicetmp; |
---|
258 | } |
---|
259 | } |
---|
260 | /* On passe a l'enregistrement suivant */ |
---|
261 | NewTreated = NewTreated -> suiv; |
---|
262 | } |
---|
263 | tmplocallist = NULL; |
---|
264 | |
---|
265 | } /* end of Did_filetoparse_treated == 1 */ |
---|
266 | } |
---|
267 | |
---|
268 | /******************************************************************************/ |
---|
269 | /* UpdateIndiceTabvarsofGloblisteFromCommon */ |
---|
270 | /******************************************************************************/ |
---|
271 | /* */ |
---|
272 | /******************************************************************************/ |
---|
273 | /* */ |
---|
274 | /******************************************************************************/ |
---|
275 | void UpdateIndiceTabvarsofGloblisteFromCommon() |
---|
276 | { |
---|
277 | |
---|
278 | listnom *parcours; |
---|
279 | listvar *parcours2; |
---|
280 | listvar *listtmp; |
---|
281 | listvar *parcoursglob; |
---|
282 | listvar *parcoursglob2; |
---|
283 | int find; |
---|
284 | int NumberofNewVar; |
---|
285 | int NumberofVar; |
---|
286 | |
---|
287 | listtmp = ( listvar *)NULL ; |
---|
288 | NumberofNewVar=0; |
---|
289 | NumberofVar=0; |
---|
290 | parcours = modulelist; |
---|
291 | while( parcours ) |
---|
292 | { |
---|
293 | listtmp = Readthedependfile( parcours->nom , listtmp); |
---|
294 | parcours=parcours->suiv; |
---|
295 | } |
---|
296 | /* */ |
---|
297 | parcoursglob = globliste; |
---|
298 | /* if this common has been ever read, we should update the tabvars */ |
---|
299 | /* indices */ |
---|
300 | while ( parcoursglob ) |
---|
301 | { |
---|
302 | NumberofVar = NumberofVar +1 ; |
---|
303 | parcours2 = listtmp; |
---|
304 | find = 0 ; |
---|
305 | while ( parcours2 && find == 0 ) |
---|
306 | { |
---|
307 | if ( !strcasecmp(parcoursglob->var->nomvar,parcours2->var->nomvar) && |
---|
308 | !strcasecmp(parcoursglob->var->commonname, |
---|
309 | parcours2->var->commonname) |
---|
310 | ) |
---|
311 | { |
---|
312 | parcoursglob->var->indicetabvars = parcours2->var->indicetabvars; |
---|
313 | strcpy(parcoursglob->var->commoninfile, |
---|
314 | parcours2->var->commoninfile); |
---|
315 | find = 1; |
---|
316 | } |
---|
317 | parcours2 = parcours2->suiv; |
---|
318 | } |
---|
319 | /* if we did not find it, it means that it is a new variable */ |
---|
320 | /* we should see if this variable has not been defined twice later */ |
---|
321 | if ( find == 0 && (parcoursglob->var->indicetabvars > |
---|
322 | (oldindicemaxtabvars + NumberofNewVar)) ) |
---|
323 | { |
---|
324 | NumberofNewVar = NumberofNewVar +1 ; |
---|
325 | parcoursglob->var->indicetabvars = oldindicemaxtabvars |
---|
326 | + NumberofNewVar; |
---|
327 | parcoursglob2 = parcoursglob; |
---|
328 | while ( parcoursglob2 ) |
---|
329 | { |
---|
330 | if ( !strcasecmp(parcoursglob->var->nomvar, |
---|
331 | parcoursglob2->var->nomvar) && |
---|
332 | !strcasecmp(parcoursglob->var->commonname, |
---|
333 | parcoursglob2->var->commonname) |
---|
334 | ) |
---|
335 | { |
---|
336 | parcoursglob2->var->indicetabvars = oldindicemaxtabvars |
---|
337 | + NumberofNewVar; |
---|
338 | } |
---|
339 | parcoursglob2 = parcoursglob2->suiv; |
---|
340 | } |
---|
341 | } |
---|
342 | /* */ |
---|
343 | parcoursglob = parcoursglob ->suiv; |
---|
344 | } |
---|
345 | indicemaxtabvars = oldindicemaxtabvars + NumberofNewVar; |
---|
346 | } |
---|
347 | |
---|
348 | |
---|
349 | /******************************************************************************/ |
---|
350 | /* UpdateGloblisteWithcommonlist_1 */ |
---|
351 | /******************************************************************************/ |
---|
352 | /* This subroutines is used to add the variable defined in common in the */ |
---|
353 | /* commonlist */ |
---|
354 | /******************************************************************************/ |
---|
355 | /* */ |
---|
356 | /******************************************************************************/ |
---|
357 | void UpdateGloblisteWithcommonlist_1() |
---|
358 | { |
---|
359 | listvarcommon *parcours; |
---|
360 | listvar *parcoursindic; |
---|
361 | listvar *parcoursvar; |
---|
362 | listvar *parcoursvarprec; |
---|
363 | int out; |
---|
364 | |
---|
365 | parcoursvarprec = (listvar *)NULL; |
---|
366 | parcoursvar = globliste; |
---|
367 | while ( parcoursvar ) |
---|
368 | { |
---|
369 | /* We should look in the commonlist if this variable is present */ |
---|
370 | parcours=commonlist; |
---|
371 | out=0; |
---|
372 | while( parcours && out == 0 ) |
---|
373 | { |
---|
374 | if ( !strcasecmp(parcoursvar->var->nomvar,parcours->nomvar) && |
---|
375 | !strcasecmp(parcoursvar->var->subroutinename, |
---|
376 | parcours->subroutinename) |
---|
377 | ) |
---|
378 | { |
---|
379 | out = 1 ; |
---|
380 | /* we should update the globliste */ |
---|
381 | strcpy(parcoursvar->var->commonname,parcours->commonname); |
---|
382 | parcoursvar->var->positioninblock = parcours->positioninblock; |
---|
383 | parcoursvar->var->common = 1; |
---|
384 | } |
---|
385 | else |
---|
386 | { |
---|
387 | parcours = parcours->suiv; |
---|
388 | } |
---|
389 | } |
---|
390 | if ( out == 0 ) |
---|
391 | { |
---|
392 | /* We should update the tabvarsindic of the following variable */ |
---|
393 | /* present in the globliste */ |
---|
394 | parcoursindic = parcoursvar; |
---|
395 | indicemaxtabvars=indicemaxtabvars-1; |
---|
396 | while(parcoursindic) |
---|
397 | { |
---|
398 | parcoursindic->var->indicetabvars = |
---|
399 | parcoursindic->var->indicetabvars-1; |
---|
400 | parcoursindic = parcoursindic->suiv; |
---|
401 | } |
---|
402 | /* we did not find it */ |
---|
403 | /* we should remove the variable from the globliste */ |
---|
404 | if ( parcoursvar == globliste ) |
---|
405 | { |
---|
406 | globliste = globliste->suiv; |
---|
407 | parcoursvar = globliste; |
---|
408 | } |
---|
409 | else |
---|
410 | { |
---|
411 | parcoursvarprec->suiv = parcoursvar->suiv; |
---|
412 | parcoursvar = parcoursvarprec->suiv; |
---|
413 | } |
---|
414 | } |
---|
415 | else |
---|
416 | { |
---|
417 | parcoursvarprec = parcoursvar; |
---|
418 | parcoursvar = parcoursvar->suiv; |
---|
419 | } |
---|
420 | } |
---|
421 | } |
---|