[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 | #include "decl.h" |
---|
| 39 | |
---|
| 40 | /******************************************************************************/ |
---|
| 41 | /* tofich_reste */ |
---|
| 42 | /******************************************************************************/ |
---|
| 43 | /* This subroutine is used to write the string s into the fileout */ |
---|
| 44 | /******************************************************************************/ |
---|
[663] | 45 | void tofich_reste (FILE * filout, char *s,int returnlineornot) |
---|
[396] | 46 | { |
---|
| 47 | char temp[61]; |
---|
| 48 | char *tmp; |
---|
| 49 | int size; |
---|
[774] | 50 | int val_min; |
---|
[396] | 51 | |
---|
| 52 | if (strlen (s) <= 60) |
---|
| 53 | { |
---|
[1200] | 54 | if ( returnlineornot == 0 ) fprintf (filout, " &%s", s); |
---|
| 55 | else if ( returnlineornot == 2 ) fprintf (filout, "&%s", s); |
---|
| 56 | else if ( returnlineornot == 3 ) fprintf (filout, "&%s\n", s); |
---|
| 57 | else fprintf (filout, " &%s\n", s); |
---|
[663] | 58 | if ( returnlineornot == 0 || |
---|
| 59 | returnlineornot == 2 ) colnum=colnum+strlen(s)+6; |
---|
[396] | 60 | else colnum=0; |
---|
| 61 | } |
---|
| 62 | else |
---|
| 63 | { |
---|
[774] | 64 | val_min = 60; |
---|
[396] | 65 | strncpy (temp, s, 60); |
---|
| 66 | strcpy (&temp[60], "\0"); |
---|
| 67 | |
---|
| 68 | tmp = strrchr(temp, '+'); |
---|
| 69 | if ( tmp ) |
---|
[774] | 70 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 71 | tmp = strrchr(temp, '-'); |
---|
| 72 | if ( tmp ) |
---|
| 73 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 74 | tmp = strrchr(temp, '/'); |
---|
| 75 | if ( tmp ) |
---|
| 76 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 77 | tmp = strrchr(temp, '*'); |
---|
| 78 | if ( tmp ) |
---|
| 79 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 80 | tmp = strrchr(temp, '%'); |
---|
| 81 | if ( tmp ) |
---|
| 82 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 83 | tmp = strrchr(temp, ','); |
---|
| 84 | if ( tmp ) |
---|
| 85 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 86 | tmp = strrchr(temp, ')'); |
---|
| 87 | if ( tmp ) |
---|
| 88 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 89 | tmp = strrchr(temp, '('); |
---|
| 90 | if ( tmp ) |
---|
| 91 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
[396] | 92 | |
---|
[774] | 93 | size = val_min; |
---|
| 94 | |
---|
[396] | 95 | strcpy (&temp[60-size], "\0"); |
---|
| 96 | |
---|
[1200] | 97 | if ( retour77 == 0 ) fprintf (filout, " &%s&\n", temp); |
---|
| 98 | else fprintf (filout, " &%s\n", temp); |
---|
[396] | 99 | colnum=0; |
---|
| 100 | tofich_reste (filout, (char *) &s[60-size],returnlineornot); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /******************************************************************************/ |
---|
| 105 | /* tofich */ |
---|
| 106 | /******************************************************************************/ |
---|
| 107 | /* This subroutine is used to write the string s into the fileout */ |
---|
| 108 | /******************************************************************************/ |
---|
[663] | 109 | void tofich (FILE * filout, char *s, int returnlineornot) |
---|
[396] | 110 | { |
---|
| 111 | char temp[61]; |
---|
| 112 | char *tmp; |
---|
| 113 | int size; |
---|
[774] | 114 | int val_min; |
---|
[663] | 115 | |
---|
[396] | 116 | if (strlen (s) <= 60) |
---|
| 117 | { |
---|
| 118 | if ( returnlineornot == 0 ) fprintf (filout, " %s", s); |
---|
[663] | 119 | else if ( returnlineornot == 2 ) fprintf (filout, "%s", s); |
---|
| 120 | else if ( returnlineornot == 3 ) fprintf (filout, "%s\n", s); |
---|
| 121 | else fprintf (filout, " %s\n", s); |
---|
| 122 | if ( returnlineornot == 0 || returnlineornot == 2 ) |
---|
| 123 | colnum=colnum+strlen(s)+6; |
---|
[396] | 124 | else colnum=0; |
---|
| 125 | } |
---|
| 126 | else |
---|
| 127 | { |
---|
[774] | 128 | val_min = 60; |
---|
[396] | 129 | strncpy (temp, s, 60); |
---|
| 130 | strcpy (&temp[60], "\0"); |
---|
| 131 | |
---|
[774] | 132 | tmp = strrchr(temp, '+'); |
---|
| 133 | if ( tmp ) |
---|
| 134 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 135 | tmp = strrchr(temp, '-'); |
---|
| 136 | if ( tmp ) |
---|
| 137 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 138 | tmp = strrchr(temp, '/'); |
---|
| 139 | if ( tmp ) |
---|
| 140 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 141 | tmp = strrchr(temp, '*'); |
---|
| 142 | if ( tmp ) |
---|
| 143 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 144 | tmp = strrchr(temp, '%'); |
---|
| 145 | if ( tmp ) |
---|
| 146 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
[396] | 147 | tmp = strrchr(temp, ','); |
---|
| 148 | if ( tmp ) |
---|
[774] | 149 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 150 | tmp = strrchr(temp, ')'); |
---|
| 151 | if ( tmp ) |
---|
| 152 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
| 153 | tmp = strrchr(temp, '('); |
---|
| 154 | if ( tmp ) |
---|
| 155 | if ( strlen(tmp) < val_min ) val_min = strlen(tmp); |
---|
[396] | 156 | |
---|
[774] | 157 | size = val_min; |
---|
| 158 | |
---|
[396] | 159 | strcpy (&temp[60-size], "\0"); |
---|
| 160 | |
---|
[1200] | 161 | if ( retour77 == 0 ) fprintf (filout, " %s&\n", temp); |
---|
| 162 | else fprintf (filout, " %s\n", temp); |
---|
[396] | 163 | colnum=0; |
---|
| 164 | tofich_reste (filout, (char *) &s[60-size], returnlineornot); |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | /******************************************************************************/ |
---|
| 169 | /* tofich_blanc */ |
---|
| 170 | /******************************************************************************/ |
---|
| 171 | /* This subroutine is used to write size blank into the fileout */ |
---|
| 172 | /******************************************************************************/ |
---|
| 173 | void tofich_blanc (FILE * filout, int size) |
---|
| 174 | { |
---|
| 175 | int i; |
---|
[663] | 176 | |
---|
| 177 | if (size <= 65) fprintf (filout, "%*s\n",size,EmptyChar); |
---|
[396] | 178 | else |
---|
[663] | 179 | { |
---|
[396] | 180 | i=0; |
---|
| 181 | do |
---|
| 182 | { |
---|
| 183 | fprintf (filout, "%*s\n",65,EmptyChar); |
---|
| 184 | i = i+1; |
---|
| 185 | } while ( i <= size / 65 ); |
---|
| 186 | fprintf (filout, "%*s\n",size%65,EmptyChar); |
---|
[663] | 187 | } |
---|
| 188 | |
---|
[396] | 189 | } |
---|
[663] | 190 | /******************************************************************************/ |
---|
| 191 | /* tofich_line */ |
---|
| 192 | /******************************************************************************/ |
---|
| 193 | /* This subroutine is used to write size blank into the fileout */ |
---|
| 194 | /******************************************************************************/ |
---|
| 195 | void tofich_line (FILE * filout, int size, int long position) |
---|
| 196 | { |
---|
| 197 | int i; |
---|
| 198 | int retour; |
---|
[396] | 199 | |
---|
[663] | 200 | if (size <= 65) fprintf (filout, "%*s",size,EmptyChar); |
---|
| 201 | else |
---|
| 202 | { |
---|
| 203 | i=0; |
---|
| 204 | do |
---|
| 205 | { |
---|
| 206 | fprintf (filout, "%*s",65,EmptyChar); |
---|
| 207 | i = i+1; |
---|
| 208 | } while ( i <= size / 65 ); |
---|
| 209 | fprintf (filout, "%*s",size%65,EmptyChar); |
---|
| 210 | } |
---|
[396] | 211 | |
---|
[663] | 212 | if ( !strstr(motparse1,"\n") ) retour=0; |
---|
| 213 | else retour=1; |
---|
| 214 | |
---|
| 215 | fseek(filout,position,SEEK_SET); |
---|
| 216 | if (retour == 1 ) fprintf (filout, "\n"); |
---|
| 217 | |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | |
---|
[396] | 221 | /******************************************************************************/ |
---|
[530] | 222 | /* RemoveWordSET_0 */ |
---|
[396] | 223 | /******************************************************************************/ |
---|
| 224 | /* This subroutine is used to remove a sentence in the file filout */ |
---|
| 225 | /******************************************************************************/ |
---|
[530] | 226 | void RemoveWordSET_0(FILE * filout, long int position, long int sizetoremove) |
---|
[396] | 227 | { |
---|
[663] | 228 | if ( firstpass == 0 && couldaddvariable == 1 ) |
---|
[530] | 229 | { |
---|
| 230 | fseek(filout,position,SEEK_SET); |
---|
[663] | 231 | tofich_line(filout,sizetoremove,position); |
---|
[530] | 232 | } |
---|
[396] | 233 | } |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | /******************************************************************************/ |
---|
[530] | 237 | /* RemoveWordCUR_0 */ |
---|
[396] | 238 | /******************************************************************************/ |
---|
| 239 | /* This subroutine is used to remove a sentence in the file filout */ |
---|
| 240 | /******************************************************************************/ |
---|
[530] | 241 | void RemoveWordCUR_0(FILE * filout, long int position, long int sizetoremove) |
---|
[396] | 242 | { |
---|
[663] | 243 | if ( firstpass == 0 && couldaddvariable == 1 ) |
---|
[530] | 244 | { |
---|
| 245 | fseek(filout,position,SEEK_CUR); |
---|
| 246 | tofich_blanc(filout,sizetoremove); |
---|
| 247 | } |
---|
[396] | 248 | } |
---|