UtilCharacter.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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@yahoo.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.7 */
  34. /******************************************************************************/
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include "decl.h"
  39. /******************************************************************************/
  40. /* FindAndChangeNameToTabvars */
  41. /******************************************************************************/
  42. /* */
  43. /******************************************************************************/
  44. /* if whichone = 0 ----> Agrif_tabvars(i) % array2 */
  45. /* */
  46. /* if whichone = 1 ----> Agrif_tabvars(i) % parentvar % array2 */
  47. /* */
  48. /******************************************************************************/
  49. void FindAndChangeNameToTabvars(const char name[LONG_M],char toprint[LONG_M],
  50. listvar * listtosee, int whichone)
  51. {
  52. listvar *newvar;
  53. int out;
  54. if ( strcasecmp(name,"") )
  55. {
  56. newvar=listtosee;
  57. out=0;
  58. while( newvar && out == 0 )
  59. {
  60. if ( !strcasecmp(newvar->var->v_nomvar,name) )
  61. {
  62. if ( LookingForVariableInListName(
  63. List_SubroutineArgument_Var,name) == 0 )
  64. {
  65. out = 1;
  66. strcat(toprint,vargridcurgridtabvars(newvar->var, whichone));
  67. }
  68. else newvar=newvar->suiv;
  69. }
  70. else newvar=newvar->suiv;
  71. }
  72. if ( out == 0 ) strcat(toprint,name);
  73. }
  74. Save_Length(toprint,44);
  75. }
  76. /******************************************************************************/
  77. /* ChangeTheInitalvaluebyTabvarsName */
  78. /******************************************************************************/
  79. /* */
  80. /******************************************************************************/
  81. /* */
  82. /* */
  83. /* */
  84. /******************************************************************************/
  85. const char *ChangeTheInitalvaluebyTabvarsName(const char *nom, listvar *listtoread)
  86. {
  87. char toprinttmp[LONG_M];
  88. char chartmp[2];
  89. size_t i = 0;
  90. strcpy(toprintglob, "");
  91. strcpy(toprinttmp, "");
  92. while ( i < strlen(nom) )
  93. {
  94. if ( (nom[i] == '+') || (nom[i] == '-') || (nom[i] == '*') || (nom[i] == '/') ||
  95. (nom[i] == '(') || (nom[i] == ')') || (nom[i] == ':') || (nom[i] == ',') )
  96. {
  97. FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,0);
  98. strcpy(toprinttmp, "");
  99. sprintf(chartmp, "%c", nom[i]);
  100. strcat(toprintglob, chartmp);
  101. }
  102. else
  103. {
  104. sprintf(chartmp, "%c", nom[i]);
  105. strcat(toprinttmp, chartmp);
  106. }
  107. i += 1;
  108. }
  109. FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,0);
  110. strcpy(toprinttmp,"");
  111. Save_Length(toprinttmp,44);
  112. Save_Length(toprintglob,39);
  113. return toprintglob;
  114. }
  115. /******************************************************************************/
  116. /* IsVariableReal */
  117. /******************************************************************************/
  118. /* */
  119. /******************************************************************************/
  120. /* */
  121. /* */
  122. /* */
  123. /******************************************************************************/
  124. int IsVariableReal(const char *nom)
  125. {
  126. return ( ( nom[0] >= 'a' && nom[0] <= 'h' ) ||
  127. ( nom[0] >= 'A' && nom[0] <= 'H' ) ||
  128. ( nom[0] >= 'o' && nom[0] <= 'z' ) ||
  129. ( nom[0] >= 'O' && nom[0] <= 'Z' ) );
  130. }
  131. /******************************************************************************/
  132. /* IsVarInUseFile */
  133. /******************************************************************************/
  134. /* */
  135. /******************************************************************************/
  136. /* */
  137. /* */
  138. /* */
  139. /******************************************************************************/
  140. void IsVarInUseFile(const char *nom)
  141. {
  142. listvar *parcours;
  143. listparameter *parcoursparam;
  144. int out;
  145. out = 0;
  146. parcours = List_Global_Var;
  147. while( parcours && out == 0 )
  148. {
  149. if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out = 1 ;
  150. else parcours=parcours->suiv;
  151. }
  152. if ( out == 0 )
  153. {
  154. parcours = List_Common_Var;
  155. while( parcours && out == 0 )
  156. {
  157. if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out = 1 ;
  158. else parcours=parcours->suiv;
  159. }
  160. }
  161. if ( out == 0 )
  162. {
  163. parcours = List_GlobalParameter_Var;
  164. while( parcours && out == 0 )
  165. {
  166. if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
  167. else parcours=parcours->suiv;
  168. }
  169. }
  170. if ( out == 0 )
  171. {
  172. parcours = List_Parameter_Var;
  173. while( parcours && out == 0 )
  174. {
  175. if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out = 1 ;
  176. else parcours=parcours->suiv;
  177. }
  178. }
  179. if ( out == 0 )
  180. {
  181. parcoursparam = List_GlobParamModuleUsed_Var;
  182. while( parcoursparam && out == 0 )
  183. {
  184. if ( !strcasecmp(nom,parcoursparam->p_name) ) out = 2 ;
  185. else parcoursparam=parcoursparam->suiv;
  186. }
  187. }
  188. if ( out == 0 )
  189. {
  190. parcours = List_ModuleUsed_Var;
  191. while( parcours && out == 0 )
  192. {
  193. if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out = 2 ;
  194. else parcours=parcours->suiv;
  195. }
  196. }
  197. if ( out == 0 || out == 2 )
  198. {
  199. parcoursparam = List_GlobParamModuleUsedInModuleUsed_Var;
  200. while( parcoursparam && out != 1 )
  201. {
  202. if ( !strcasecmp(nom,parcoursparam->p_name) ) out = 1 ;
  203. else parcoursparam=parcoursparam->suiv;
  204. }
  205. if ( out == 1 )
  206. {
  207. strcpy(charusemodule,parcoursparam->p_modulename);
  208. Addmoduletothelist(parcoursparam->p_modulename);
  209. }
  210. }
  211. if ( out == 0 &&
  212. strcasecmp(nom,"MAX") &&
  213. strcasecmp(nom,"mpi_status_size")
  214. )
  215. {
  216. /* printf("--- in UtilCharacter we do not found the \n");
  217. printf("--- variable %s, the module where this \n",nom);
  218. printf("--- variable has been defined has not been\n");
  219. printf("--- found.\n");*/
  220. }
  221. }
  222. /******************************************************************************/
  223. /* DecomposeTheNameinlistnom */
  224. /******************************************************************************/
  225. /* Firstpass 0 */
  226. /******************************************************************************/
  227. /* */
  228. /* */
  229. /******************************************************************************/
  230. listnom *DecomposeTheNameinlistnom(const char *nom, listnom * listout)
  231. {
  232. char toprinttmp[LONG_M];
  233. char chartmp[2];
  234. size_t i = 0;
  235. strcpy(toprinttmp,"");
  236. while ( i < strlen(nom) )
  237. {
  238. if ( nom[i] == '+' ||
  239. nom[i] == '-' ||
  240. nom[i] == '*' ||
  241. nom[i] == '/' ||
  242. nom[i] == ')' ||
  243. nom[i] == '(' ||
  244. nom[i] == ',' ||
  245. nom[i] == ':'
  246. )
  247. {
  248. if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
  249. {
  250. listout = Addtolistnom(toprinttmp,listout,0);
  251. }
  252. strcpy(toprinttmp,"");
  253. }
  254. else
  255. {
  256. sprintf(chartmp,"%c",nom[i]);
  257. strcat(toprinttmp,chartmp);
  258. }
  259. i=i+1;
  260. }
  261. if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
  262. {
  263. listout = Addtolistnom(toprinttmp,listout,0);
  264. }
  265. Save_Length(toprinttmp,44);
  266. strcpy(toprinttmp,"");
  267. return listout;
  268. }
  269. /******************************************************************************/
  270. /* DecomposeTheName */
  271. /******************************************************************************/
  272. /* Firstpass 0 */
  273. /******************************************************************************/
  274. /* */
  275. /* Agrif_<toto>(variable) ====> Agrif_<toto>(variable) */
  276. /* */
  277. /******************************************************************************/
  278. void DecomposeTheName(const char *nom)
  279. {
  280. char toprinttmp[LONG_M];
  281. char chartmp[2];
  282. size_t i = 0;
  283. strcpy(toprinttmp,"");
  284. while ( i < strlen(nom) )
  285. {
  286. if ( nom[i] == '+' ||
  287. nom[i] == '-' ||
  288. nom[i] == '*' ||
  289. nom[i] == '/' ||
  290. nom[i] == ')' ||
  291. nom[i] == '(' ||
  292. nom[i] == ',' ||
  293. nom[i] == ':'
  294. )
  295. {
  296. if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
  297. {
  298. ajoutevarindoloop_definedimension (toprinttmp);
  299. /* Is this variable present in globvarofusefile */
  300. IsVarInUseFile(toprinttmp);
  301. }
  302. strcpy(toprinttmp,"");
  303. }
  304. else
  305. {
  306. sprintf(chartmp,"%c",nom[i]);
  307. strcat(toprinttmp,chartmp);
  308. }
  309. i=i+1;
  310. }
  311. if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
  312. {
  313. ajoutevarindoloop_definedimension (toprinttmp);
  314. /* Is this variable present in globvarofusefile */
  315. IsVarInUseFile(toprinttmp);
  316. }
  317. Save_Length(toprinttmp,44);
  318. strcpy(toprinttmp,"");
  319. }
  320. void convert2lower(char *lowername, const char* inputname)
  321. {
  322. int i, l, caractere;
  323. strcpy(lowername, inputname);
  324. l = strlen(lowername)-1;
  325. for ( i=0 ; i<=l ; i++)
  326. {
  327. caractere = lowername[i];
  328. if ( (caractere>=65 && caractere<=90) || (caractere>=192 && caractere<=221) )
  329. {
  330. lowername[i] += 32;
  331. }
  332. }
  333. }
  334. int convert2int(const char *name)
  335. {
  336. int i;
  337. int caractere;
  338. int value;
  339. int value_tmp;
  340. int longueur;
  341. value = 0;
  342. longueur = strlen(name) - 1;
  343. for (i=0;i<=longueur;i++)
  344. {
  345. caractere=name[i];
  346. value_tmp = caractere -'0';
  347. if ( value_tmp > 9 ) return 0;
  348. if ( longueur+1-i == 6 ) value = value + value_tmp *100000;
  349. else if ( longueur+1-i == 5 ) value = value + value_tmp *10000;
  350. else if ( longueur+1-i == 4 ) value = value + value_tmp *1000;
  351. else if ( longueur+1-i == 3 ) value = value + value_tmp *100;
  352. else if ( longueur+1-i == 2 ) value = value + value_tmp *10;
  353. else if ( longueur+1-i == 1 ) value = value + value_tmp *1;
  354. }
  355. return value;
  356. }