[396] | 1 | /******************************************************************************/ |
---|
| 2 | /* */ |
---|
| 3 | /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */ |
---|
| 4 | /* */ |
---|
[663] | 5 | /* Copyright or or Copr. Laurent Debreu (Laurent.Debreu@imag.fr) */ |
---|
| 6 | /* Cyril Mazauric (Cyril_Mazauric@yahoo.fr) */ |
---|
[530] | 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". */ |
---|
[396] | 12 | /* */ |
---|
[530] | 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. */ |
---|
[396] | 18 | /* */ |
---|
[530] | 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. */ |
---|
[396] | 29 | /* */ |
---|
[530] | 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. */ |
---|
[396] | 32 | /******************************************************************************/ |
---|
[774] | 33 | /* version 1.7 */ |
---|
[530] | 34 | /******************************************************************************/ |
---|
[396] | 35 | #include <stdio.h> |
---|
| 36 | #include <stdlib.h> |
---|
| 37 | #include <string.h> |
---|
| 38 | |
---|
| 39 | #include "decl.h" |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | /******************************************************************************/ |
---|
| 44 | /* RecordUseModulesVariables */ |
---|
| 45 | /******************************************************************************/ |
---|
[663] | 46 | /* */ |
---|
[396] | 47 | /******************************************************************************/ |
---|
| 48 | void RecordUseModulesVariables() |
---|
| 49 | { |
---|
| 50 | listusemodule *tmplistmodule; |
---|
| 51 | |
---|
| 52 | /* we should record all variables defined in modules used in this file */ |
---|
[663] | 53 | if ( List_NameOfModuleUsed ) |
---|
[396] | 54 | { |
---|
[663] | 55 | tmplistmodule = List_NameOfModuleUsed; |
---|
[396] | 56 | while ( tmplistmodule ) |
---|
| 57 | { |
---|
[663] | 58 | if ( tmplistmodule->u_firstuse == 1 ) |
---|
[396] | 59 | { |
---|
[663] | 60 | /* check if the file .depend<u_usemodule> exist */ |
---|
| 61 | List_ModuleUsed_Var = Readthedependfile |
---|
| 62 | (tmplistmodule->u_usemodule,List_ModuleUsed_Var); |
---|
[396] | 63 | |
---|
[663] | 64 | List_GlobParamModuleUsed_Var = ReaddependParameterList |
---|
| 65 | (tmplistmodule->u_usemodule,List_GlobParamModuleUsed_Var); |
---|
[396] | 66 | |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | tmplistmodule = tmplistmodule->suiv; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | /******************************************************************************/ |
---|
| 75 | /* RecordUseModulesUseModulesVariables */ |
---|
| 76 | /******************************************************************************/ |
---|
| 77 | /******************************************************************************/ |
---|
| 78 | void RecordUseModulesUseModulesVariables() |
---|
| 79 | { |
---|
| 80 | listusemodule *tmplistmodule; |
---|
[530] | 81 | listusemodule *tmplistmodule1; |
---|
[396] | 82 | |
---|
| 83 | /* we should record all variables defined in modules used in this file */ |
---|
[663] | 84 | if ( List_NameOfModuleUsed ) |
---|
[396] | 85 | { |
---|
| 86 | /* and we should read the .depend of the module used by the module used */ |
---|
[663] | 87 | tmplistmodule = List_NameOfModuleUsed; |
---|
[396] | 88 | while ( tmplistmodule ) |
---|
| 89 | { |
---|
[663] | 90 | Readthedependlistofmoduleused(tmplistmodule->u_usemodule); |
---|
[396] | 91 | while( tmpuselocallist ) |
---|
| 92 | { |
---|
[663] | 93 | Addmoduletothelisttmp(tmpuselocallist->u_usemodule); |
---|
| 94 | tmplistmodule1 = tmpuselocallist->suiv; |
---|
| 95 | free(tmpuselocallist); |
---|
[530] | 96 | tmpuselocallist = tmplistmodule1; |
---|
[396] | 97 | } |
---|
| 98 | tmplistmodule = tmplistmodule->suiv; |
---|
| 99 | } |
---|
[663] | 100 | |
---|
[396] | 101 | tmplistmodule = listofmoduletmp; |
---|
| 102 | while ( tmplistmodule ) |
---|
| 103 | { |
---|
[663] | 104 | Readthedependlistofmoduleused(tmplistmodule->u_usemodule); |
---|
| 105 | while( tmpuselocallist ) |
---|
| 106 | { |
---|
| 107 | Addmoduletothelisttmp(tmpuselocallist->u_usemodule); |
---|
| 108 | tmplistmodule1 = tmpuselocallist->suiv; |
---|
| 109 | free(tmpuselocallist); |
---|
| 110 | tmpuselocallist = tmplistmodule1; |
---|
| 111 | } |
---|
| 112 | tmplistmodule = tmplistmodule->suiv; |
---|
| 113 | } |
---|
[396] | 114 | |
---|
[663] | 115 | |
---|
| 116 | |
---|
| 117 | tmplistmodule = listofmoduletmp; |
---|
| 118 | while ( tmplistmodule ) |
---|
| 119 | { |
---|
| 120 | /* check if the file .depend<u_usemodule> exist */ |
---|
| 121 | List_ModuleUsedInModuleUsed_Var = Readthedependfile |
---|
| 122 | (tmplistmodule->u_usemodule,List_ModuleUsedInModuleUsed_Var); |
---|
| 123 | |
---|
| 124 | List_GlobParamModuleUsedInModuleUsed_Var = ReaddependParameterList |
---|
| 125 | (tmplistmodule->u_usemodule,List_GlobParamModuleUsedInModuleUsed_Var); |
---|
[396] | 126 | tmplistmodule = tmplistmodule->suiv; |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | /******************************************************************************/ |
---|
[663] | 132 | /* Add_NameOfModuleUsed_1 */ |
---|
[530] | 133 | /******************************************************************************/ |
---|
| 134 | /* This subroutine is used to add a record to a list of struct */ |
---|
| 135 | /* listusemodule */ |
---|
| 136 | /******************************************************************************/ |
---|
| 137 | /* */ |
---|
| 138 | /* subroutine sub ... USE mod1 ===> insert in list */ |
---|
| 139 | /* _______ _______ _______ _______ _______ */ |
---|
| 140 | /* + + + + + + + + + + */ |
---|
| 141 | /* + NEW +--->+ list +--->+ list +--->+ list +--->+ list + */ |
---|
| 142 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
| 143 | /* */ |
---|
[663] | 144 | /* list = List_NameOfModuleUsed */ |
---|
[530] | 145 | /* */ |
---|
| 146 | /******************************************************************************/ |
---|
[663] | 147 | void Add_NameOfModuleUsed_1(char *name) |
---|
[530] | 148 | { |
---|
| 149 | listusemodule *newmodule; |
---|
| 150 | listusemodule *parcours; |
---|
| 151 | int out; |
---|
| 152 | |
---|
| 153 | if ( firstpass == 1 ) |
---|
| 154 | { |
---|
| 155 | newmodule =(listusemodule *)malloc(sizeof(listusemodule)); |
---|
[663] | 156 | strcpy(newmodule->u_usemodule,name); |
---|
[774] | 157 | Save_Length(name,16); |
---|
[663] | 158 | strcpy(newmodule->u_charusemodule,charusemodule); |
---|
[774] | 159 | Save_Length(charusemodule,17); |
---|
[663] | 160 | strcpy(newmodule->u_modulename,curmodulename); |
---|
[774] | 161 | Save_Length(curmodulename,19); |
---|
[663] | 162 | strcpy(newmodule->u_cursubroutine,subroutinename); |
---|
[774] | 163 | Save_Length(subroutinename,18); |
---|
[663] | 164 | newmodule->u_firstuse = 1 ; |
---|
[530] | 165 | newmodule->suiv = NULL; |
---|
| 166 | |
---|
[663] | 167 | if ( !List_NameOfModuleUsed) |
---|
[530] | 168 | { |
---|
[663] | 169 | List_NameOfModuleUsed = newmodule ; |
---|
[530] | 170 | } |
---|
| 171 | else |
---|
| 172 | { |
---|
[663] | 173 | parcours = List_NameOfModuleUsed; |
---|
| 174 | while ( parcours && newmodule->u_firstuse == 1 ) |
---|
[530] | 175 | { |
---|
[663] | 176 | if ( !strcasecmp(name,parcours->u_usemodule) ) |
---|
[530] | 177 | { |
---|
[663] | 178 | newmodule->u_firstuse = 0 ; |
---|
[530] | 179 | } |
---|
| 180 | parcours=parcours->suiv; |
---|
| 181 | } |
---|
| 182 | /* we can not add the same module twice for the same subroutine */ |
---|
[663] | 183 | parcours = List_NameOfModuleUsed; |
---|
[530] | 184 | out = 0 ; |
---|
| 185 | while ( parcours && out == 0 ) |
---|
| 186 | { |
---|
[663] | 187 | if ( !strcasecmp(name,parcours->u_usemodule) && |
---|
| 188 | !strcasecmp(subroutinename,parcours->u_cursubroutine) |
---|
[530] | 189 | ) |
---|
| 190 | { |
---|
| 191 | out = 1 ; |
---|
| 192 | free(newmodule); |
---|
| 193 | } |
---|
| 194 | else parcours=parcours->suiv; |
---|
| 195 | } |
---|
| 196 | if ( out == 0 ) |
---|
| 197 | { |
---|
[663] | 198 | newmodule->suiv = List_NameOfModuleUsed; |
---|
| 199 | List_NameOfModuleUsed = newmodule; |
---|
[530] | 200 | } |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | /******************************************************************************/ |
---|
[396] | 207 | /* Addmoduletothelist */ |
---|
| 208 | /******************************************************************************/ |
---|
| 209 | /* This subroutine is used to add a record to a list of struct */ |
---|
| 210 | /* listusemodule */ |
---|
| 211 | /******************************************************************************/ |
---|
| 212 | /* */ |
---|
| 213 | /* subroutine sub ... USE mod1 ===> insert in list */ |
---|
| 214 | /* _______ _______ _______ _______ _______ */ |
---|
| 215 | /* + + + + + + + + + + */ |
---|
| 216 | /* + NEW +--->+ list +--->+ list +--->+ list +--->+ list + */ |
---|
| 217 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
| 218 | /* */ |
---|
[663] | 219 | /* list = List_NameOfModuleUsed */ |
---|
[396] | 220 | /* */ |
---|
| 221 | /******************************************************************************/ |
---|
| 222 | void Addmoduletothelist(char *name) |
---|
| 223 | { |
---|
| 224 | listusemodule *newmodule; |
---|
| 225 | listusemodule *parcours; |
---|
| 226 | int out; |
---|
| 227 | |
---|
[530] | 228 | newmodule =(listusemodule *)malloc(sizeof(listusemodule)); |
---|
[663] | 229 | strcpy(newmodule->u_usemodule,name); |
---|
[774] | 230 | Save_Length(name,16); |
---|
[663] | 231 | strcpy(newmodule->u_charusemodule,charusemodule); |
---|
[774] | 232 | Save_Length(charusemodule,17); |
---|
[663] | 233 | strcpy(newmodule->u_cursubroutine,subroutinename); |
---|
[774] | 234 | Save_Length(subroutinename,18); |
---|
[663] | 235 | newmodule->u_firstuse = 1 ; |
---|
[530] | 236 | newmodule->suiv = NULL; |
---|
[396] | 237 | |
---|
[663] | 238 | if ( !List_NameOfModuleUsed) |
---|
[530] | 239 | { |
---|
[663] | 240 | List_NameOfModuleUsed = newmodule ; |
---|
[530] | 241 | } |
---|
| 242 | else |
---|
| 243 | { |
---|
[663] | 244 | parcours = List_NameOfModuleUsed; |
---|
| 245 | while ( parcours && newmodule->u_firstuse == 1 ) |
---|
[396] | 246 | { |
---|
[663] | 247 | if ( !strcasecmp(name,parcours->u_usemodule) ) |
---|
[396] | 248 | { |
---|
[663] | 249 | newmodule->u_firstuse = 0 ; |
---|
[396] | 250 | } |
---|
| 251 | parcours=parcours->suiv; |
---|
| 252 | } |
---|
| 253 | /* we can not add the same module twice for the same subroutine */ |
---|
[663] | 254 | parcours = List_NameOfModuleUsed; |
---|
[396] | 255 | out = 0 ; |
---|
| 256 | while ( parcours && out == 0 ) |
---|
| 257 | { |
---|
[663] | 258 | if ( !strcasecmp(name,parcours->u_usemodule) && |
---|
| 259 | !strcasecmp(subroutinename,parcours->u_cursubroutine) |
---|
[396] | 260 | ) |
---|
| 261 | { |
---|
| 262 | out = 1 ; |
---|
| 263 | free(newmodule); |
---|
| 264 | } |
---|
| 265 | else parcours=parcours->suiv; |
---|
| 266 | } |
---|
| 267 | if ( out == 0 ) |
---|
| 268 | { |
---|
[663] | 269 | newmodule->suiv = List_NameOfModuleUsed; |
---|
| 270 | List_NameOfModuleUsed = newmodule; |
---|
[396] | 271 | } |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | /******************************************************************************/ |
---|
| 277 | /* WriteUsemoduleDeclaration */ |
---|
| 278 | /******************************************************************************/ |
---|
| 279 | /* Firstpass 0 */ |
---|
| 280 | /******************************************************************************/ |
---|
| 281 | /* */ |
---|
| 282 | /******************************************************************************/ |
---|
| 283 | void WriteUsemoduleDeclaration() |
---|
| 284 | { |
---|
| 285 | listusemodule *newmodule; |
---|
| 286 | |
---|
[663] | 287 | newmodule = List_NameOfModuleUsed; |
---|
[396] | 288 | fprintf(fortranout,"\n"); |
---|
[1200] | 289 | |
---|
[396] | 290 | while ( newmodule ) |
---|
| 291 | { |
---|
[663] | 292 | if ( !strcasecmp(newmodule->u_cursubroutine,subroutinename) ) |
---|
[396] | 293 | { |
---|
[663] | 294 | fprintf(fortranout," USE %s \n" |
---|
| 295 | ,newmodule->u_charusemodule); |
---|
[396] | 296 | } |
---|
[663] | 297 | newmodule = newmodule ->suiv; |
---|
[396] | 298 | } |
---|
| 299 | } |
---|