[7541] | 1 | # codedox.awk - filter of ORCHIDEE f90 files |
---|
| 2 | # command : gawk -f codedox.awk [-d] file.f90 |
---|
| 3 | # create a file.f90_preproc_codedox filtered |
---|
| 4 | |
---|
| 5 | #************************************************************** |
---|
| 6 | # Author: Martial.Mancip |
---|
| 7 | # Contact: Martial.Mancip__at__ipsl.jussieu.fr |
---|
| 8 | # $Revision:: $ Revision of last commit |
---|
| 9 | # $Author:: $ Author of last commit |
---|
| 10 | # $Date:: |
---|
| 11 | # IPSL (2006) |
---|
| 12 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
| 13 | # Modification: |
---|
| 14 | # |
---|
| 15 | #************************************************************** |
---|
| 16 | #========================== |
---|
| 17 | function debugprint(str) { |
---|
| 18 | if (debug) { |
---|
| 19 | if ( ldebug ) { |
---|
| 20 | print "-> " str | "cat 1>&2" |
---|
| 21 | } else { |
---|
| 22 | print str | "cat 1>&2" |
---|
| 23 | } |
---|
| 24 | } |
---|
| 25 | } |
---|
| 26 | function myprint(str) { |
---|
| 27 | if ( ldebug ) { |
---|
| 28 | print str | "cat 1>&2" |
---|
| 29 | } else { |
---|
| 30 | print str >> output_file |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | function flush_line() { |
---|
| 36 | if ( nblc > 0 ) { |
---|
| 37 | debugprint("==> flush") |
---|
| 38 | for ( i=0; i < nblc; i++ ) { |
---|
| 39 | myprint(line[i]) |
---|
| 40 | } |
---|
| 41 | nblc=0 |
---|
| 42 | iblc=0 |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | function code_intent(iblc) { |
---|
| 47 | debugprint("line with intent") |
---|
| 48 | if (match(line[iblc], "intent *\\(in\\)")) { |
---|
| 49 | sub(/.*\!+>*\-*/, " !> [in]",line[iblc]) |
---|
| 50 | } else if (match(line[iblc], "intent *\\(out\\)")) { |
---|
| 51 | sub(/.*\!+>*\-*/, " !> [out]",line[iblc]) |
---|
| 52 | } else if (match(line[iblc], "intent *\\(inout\\)")) { |
---|
| 53 | sub(/.*\!+>*\-*/, " !> [in,out]",line[iblc]) |
---|
| 54 | } else { |
---|
| 55 | print "unknown intent error : " line[iblc] |
---|
| 56 | debugprint("unknown intent error : " line[iblc]) |
---|
| 57 | exit 1 |
---|
| 58 | } |
---|
| 59 | if ( icont == 1 ) { |
---|
| 60 | line[iblc]=line[iblc] "\\n" |
---|
| 61 | } |
---|
| 62 | debugprint("line after Doxygen intent :" line[iblc]) |
---|
| 63 | |
---|
| 64 | sub(/\!.*/, "") |
---|
| 65 | line[nblc]=$0 |
---|
| 66 | nblc++ |
---|
| 67 | debugprint("Only code intent :" $0) |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | function code_INTENT_ (iblc) { |
---|
| 71 | debugprint("line with INTENT") |
---|
| 72 | if (match(line[iblc], "INTENT *\\(in\\)")) { |
---|
| 73 | sub(/.*\!+>*\-*/, " !> [in]",line[iblc]) |
---|
| 74 | } else if (match(line[iblc], "INTENT *\\(out\\)")) { |
---|
| 75 | sub(/.*\!+>*\-*/, " !> [out]",line[iblc]) |
---|
| 76 | } else if (match(line[iblc], "INTENT *\\(inout\\)")) { |
---|
| 77 | sub(/.*\!+>*\-*/, " !> [in,out]",line[iblc]) |
---|
| 78 | } else if (match(line[iblc], "INTENT *\\(IN\\)")) { |
---|
| 79 | sub(/.*\!+>*\-*/, " !> [in]",line[iblc]) |
---|
| 80 | } else if (match(line[iblc], "INTENT *\\(OUT\\)")) { |
---|
| 81 | sub(/.*\!+>*\-*/, " !> [out]",line[iblc]) |
---|
| 82 | } else if (match(line[iblc], "INTENT *\\(INOUT\\)")) { |
---|
| 83 | sub(/.*\!+>*\-*/, " !> [in,out]",line[iblc]) |
---|
| 84 | } else { |
---|
| 85 | print "unknown INTENT error : " line[iblc] |
---|
| 86 | debugprint("unknown INTENT error : " line[iblc]) |
---|
| 87 | exit 1 |
---|
| 88 | } |
---|
| 89 | if ( icont == 1 ) { |
---|
| 90 | line[iblc]=line[iblc] "\\n" |
---|
| 91 | } |
---|
| 92 | debugprint("line after Doxygen INTENT :" line[iblc]) |
---|
| 93 | |
---|
| 94 | sub(/\!.*/, "") |
---|
| 95 | line[nblc]=$0 |
---|
| 96 | nblc++ |
---|
| 97 | debugprint("Only code intent :" $0) |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | #========================== |
---|
| 101 | BEGIN { |
---|
| 102 | ldebug=0 |
---|
| 103 | debug=0 |
---|
| 104 | if (ARGV[1] == "-d") { |
---|
| 105 | debug=1 |
---|
| 106 | file=ARGV[2] |
---|
| 107 | delete ARGV[1] |
---|
| 108 | } else if (ARGV[1] == "-dd") { |
---|
| 109 | debug=1 |
---|
| 110 | ldebug=1 |
---|
| 111 | file=ARGV[2] |
---|
| 112 | delete ARGV[1] |
---|
| 113 | } else { |
---|
| 114 | file=ARGV[1] |
---|
| 115 | } |
---|
| 116 | debugprint("traitement de " file) |
---|
| 117 | |
---|
| 118 | output_file=file "_preproc_codedox" |
---|
| 119 | if (debug) { |
---|
| 120 | if ( ! ldebug ) { |
---|
| 121 | lscommand=("ls " output_file) |
---|
| 122 | outsys=system(lscommand) |
---|
| 123 | debugprint("output of ls : " outsys) |
---|
| 124 | if ( outsys == 0 ) { |
---|
| 125 | debugprint("Already find " output_file) |
---|
| 126 | outsys=system("rm " output_file) |
---|
| 127 | debugprint("output of rm : " outsys) |
---|
| 128 | system("touch " output_file) |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | # When exit statement, 'END' rule is always executed, so defined a exit_value to manage this |
---|
| 134 | exit_value=0 |
---|
| 135 | if ( ARGV[1] == "-h" ) { |
---|
| 136 | debugprint("Usage: codedox.awk [-h] [-d|-dd] file.f90") |
---|
| 137 | debugprint("") |
---|
| 138 | debugprint("Args:") |
---|
| 139 | debugprint(" file.f90 = source code to be parsed") |
---|
| 140 | debugprint("") |
---|
| 141 | debugprint("Options:" ) |
---|
| 142 | debugprint(" -h = this usage") |
---|
| 143 | debugprint(" -d = debug mode") |
---|
| 144 | debugprint(" -dd = debug mode stdout") |
---|
| 145 | debugprint("") |
---|
| 146 | exit_value=1 |
---|
| 147 | exit |
---|
| 148 | } |
---|
| 149 | # Number of previous lines commented |
---|
| 150 | nblc=0 |
---|
| 151 | |
---|
| 152 | # Flag to point indented declaration |
---|
| 153 | idecl=0 |
---|
| 154 | # index of first declaration comment |
---|
| 155 | icdecl=0 |
---|
| 156 | # Flag to point a continuation line inside a declaration |
---|
| 157 | icont=0 |
---|
| 158 | # Number of the first line of declaration group inside line tab |
---|
| 159 | nicont=0 |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | #========================== |
---|
| 163 | { |
---|
| 164 | debugprint($0) |
---|
| 165 | |
---|
| 166 | # Divers modification de la ligne pour la compatibilité Doxygen |
---|
| 167 | if (match($0, "!+")) { |
---|
| 168 | |
---|
| 169 | if (match($0, "!\\?")) { |
---|
| 170 | debugprint("Wrong comment") |
---|
| 171 | sub(/\!\?/, "!") |
---|
| 172 | debugprint("Correct wrong comment" $0) |
---|
| 173 | } else if (match($0, "f90doc")) { |
---|
| 174 | debugprint("suppression de la ligne") |
---|
| 175 | next |
---|
| 176 | } else if (match($0, "@call")) { |
---|
| 177 | debugprint("line with @call") |
---|
| 178 | sub(/@call/, "@see",$0) |
---|
| 179 | debugprint("line after correct call :" $0) |
---|
| 180 | } else if (match($0, "@Version")) { |
---|
| 181 | debugprint("line with @Version") |
---|
| 182 | sub(/@Version/, "@version") |
---|
| 183 | debugprint("line after Doxygen @version :" $0) |
---|
| 184 | } else if (match($0, "@tex")) { |
---|
| 185 | match($0,"@tex([^@]+)@endtex",math) |
---|
| 186 | debugprint("line with formula :" math[1]) |
---|
| 187 | $0 = substr($0,1,match($0,"@tex")-1) "@htmlonly" math[1] "@endhtmlonly @latexonly" math[1] "@endlatexonly" substr($0,match($0,"@endtex")+7) |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | # traitement des simples cotes |
---|
| 191 | if (match($0, "'") && ! match($0, "'.*'") ) { |
---|
| 192 | debugprint("line with single cote") |
---|
| 193 | sub(/'/, "''",$0) |
---|
| 194 | debugprint("line without single cote : " $0) |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | if (match($0, "!+")) { |
---|
| 199 | debugprint("line with comment") |
---|
| 200 | |
---|
| 201 | if ( idecl == 1 ) { |
---|
| 202 | debugprint("inside a decl " (match($0,"^[[:space:]]+!")) " " match($0,"!") " " icdecl ".") |
---|
| 203 | if ( (match($0,"^[[:space:]]+!")) && (match($0,"!") == icdecl) ) { |
---|
| 204 | line[nblc]=line[nblc-1] |
---|
| 205 | sub(/^[[:space:]]+\!+>*/," !>") |
---|
| 206 | # on écrit le nouveau commentaire avant le précédant |
---|
| 207 | line[nblc-1]=$0 "\\n" |
---|
| 208 | nblc++ |
---|
| 209 | debugprint("continuation of declaration") |
---|
| 210 | next |
---|
| 211 | } else if ( icont == 1 ) { |
---|
| 212 | if (match($0,"!")) { |
---|
| 213 | debugprint("continuation of declaration with &" nicont) |
---|
| 214 | for ( i=nblc; i > nicont; i-- ) { |
---|
| 215 | line[i]=line[i-1] |
---|
| 216 | } |
---|
| 217 | nblc++ |
---|
| 218 | |
---|
| 219 | line[nblc]=substr($0,1,icdecl-1) |
---|
| 220 | nblc++ |
---|
| 221 | |
---|
| 222 | line[nicont+1]=line[nicont] |
---|
| 223 | |
---|
| 224 | line[nicont]=substr($0,icdecl) |
---|
| 225 | sub(/^\!+>*/," !>",line[nicont]) |
---|
| 226 | line[nicont]=line[nicont] "\\n" |
---|
| 227 | for ( i=nicont-1; i < nblc; i++ ) { |
---|
| 228 | debugprint(":" i line[i]) |
---|
| 229 | } |
---|
| 230 | } else { |
---|
| 231 | line[nblc]=$0 |
---|
| 232 | nblc++ |
---|
| 233 | debugprint("no comment in continuation of declaration with &") |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | if ( match(line[nblc-1], "&") ) { |
---|
| 237 | if ( match(line[nblc-1], "&.*&") ) { |
---|
| 238 | icont = 1 |
---|
| 239 | nicont=nicont+1 |
---|
| 240 | debugprint("next line with &") |
---|
| 241 | } else if ( match(line[nblc-1], "^[[:space:]]*&") ) { |
---|
| 242 | icont = 0 |
---|
| 243 | nicont = 0 |
---|
| 244 | debugprint("next line without &") |
---|
| 245 | } else { |
---|
| 246 | icont = 1 |
---|
| 247 | nicont=nicont+1 |
---|
| 248 | debugprint("next line with &") |
---|
| 249 | } |
---|
| 250 | } else { |
---|
| 251 | icont = 0 |
---|
| 252 | nicont = 0 |
---|
| 253 | debugprint(match(line[nblc-1], "^[[:space:]]+&*[^!]+&") match(line[nblc-1], "^[[:space:]]+[^!]+&[[:space:]]*!*")) |
---|
| 254 | } |
---|
| 255 | next |
---|
| 256 | } else { |
---|
| 257 | idecl=0 |
---|
| 258 | icont = 0 |
---|
| 259 | nicont = 0 |
---|
| 260 | flush_line() |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | iblc=nblc |
---|
| 265 | line[nblc]=$0 |
---|
| 266 | nblc++ |
---|
| 267 | |
---|
| 268 | # commentary after a parameter documentation : need flush previous lines without Doxygen doc |
---|
| 269 | if (match(line[iblc], "^[^!]+intent *\\(.*\\).*::")) { |
---|
| 270 | idecl=1 |
---|
| 271 | icdecl=match($0,"!") |
---|
| 272 | if ( match(line[iblc], "[^!]*::[^!]*&") ) { |
---|
| 273 | icont = 1 |
---|
| 274 | nicont=nblc |
---|
| 275 | debugprint("next line with &") |
---|
| 276 | } |
---|
| 277 | code_intent(iblc) |
---|
| 278 | |
---|
| 279 | } else if (match(line[iblc], "^[^!]+INTENT *\\(.*\\).*::")) { |
---|
| 280 | idecl=1 |
---|
| 281 | icdecl=match($0,"!") |
---|
| 282 | if ( match(line[iblc], "[^!]*::[^!]*&") ) { |
---|
| 283 | icont = 1 |
---|
| 284 | nicont=nblc |
---|
| 285 | debugprint("next line with &") |
---|
| 286 | } |
---|
| 287 | code_INTENT_(iblc) |
---|
| 288 | |
---|
| 289 | } else if (match(line[iblc], "^[^!]+::")) { |
---|
| 290 | debugprint("line with declaration") |
---|
| 291 | |
---|
| 292 | idecl=1 |
---|
| 293 | icdecl=match($0,"!") |
---|
| 294 | if ( match(line[iblc], "[^!]*::[^!]*&") ) { |
---|
| 295 | icont = 1 |
---|
| 296 | nicont=nblc |
---|
| 297 | debugprint("next line with &") |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | sub(/.*\!+>*/, " !>",line[iblc]) |
---|
| 301 | debugprint("line after Doxygen declaration :" line[iblc]) |
---|
| 302 | |
---|
| 303 | sub(/\!.*/, "") |
---|
| 304 | debugprint("Only code declaration :" $0) |
---|
| 305 | line[nblc]=$0 |
---|
| 306 | nblc++ |
---|
| 307 | |
---|
| 308 | } |
---|
| 309 | next |
---|
| 310 | } else if (match($0, "^[^!]*subroutine.*\\(.*") || match($0, "^[^!]*SUBROUTINE.*\\(.*") || |
---|
| 311 | ( match($0, "^[^!]*subroutine ") && ! (match($0, "^[[:space:]]+end ")) ) || |
---|
| 312 | ( match($0, "^[^!]*SUBROUTINE ") && ! (match($0, "^[[:space:]]+END ")) ) || |
---|
| 313 | match($0, "^[^!]*function.*\\(.*") || match($0, "^[^!]*FUNCTION.*\\(.*") || |
---|
| 314 | match($0, "^[^!]*module *") || match($0, "^[^!]*MODULE *") || |
---|
| 315 | match($0, "^[^!]*interface *") || match($0, "^[^!]*INTERFACE *") || |
---|
| 316 | match($0, "^[^!]+::")) { |
---|
| 317 | |
---|
| 318 | debugprint("f90 declaration") |
---|
| 319 | |
---|
| 320 | if ( idecl == 1 ) { |
---|
| 321 | idecl=0 |
---|
| 322 | icont=0 |
---|
| 323 | flush_line() |
---|
| 324 | } |
---|
| 325 | if (nblc > 0 && ( match($0, "^[^!]+intent *\\(.*\\).*::") || |
---|
| 326 | match($0, "^[^!]+INTENT *\\(.*\\).*::") )) { |
---|
| 327 | if (match($0, "\\(in\\)") || match($0, "\\(IN\\)")) { |
---|
| 328 | sub(/.*\!+>*\-*/, " !> [in]",line[iblc]) |
---|
| 329 | } else if (match($0, "\\(out\\)") || match($0, "\\(OUT\\)")) { |
---|
| 330 | sub(/.*\!+>*\-*/, " !> [out]",line[iblc]) |
---|
| 331 | } else if (match($0, "\\(inout\\)") || match($0, "\\(INOUT\\)")) { |
---|
| 332 | sub(/.*\!+>*\-*/, " !> [in,out]",line[iblc]) |
---|
| 333 | } else { |
---|
| 334 | print "unknown INTENT error : " $0 |
---|
| 335 | debugprint("unknown INTENT error : " $0) |
---|
| 336 | exit 1 |
---|
| 337 | } |
---|
| 338 | } else { |
---|
| 339 | |
---|
| 340 | for ( i=0; i < nblc; i++ ) { |
---|
| 341 | # : ajout des commentaires Doxygen |
---|
| 342 | if (match(line[i], "!<")) { |
---|
| 343 | sub(/\^ *\!+</, " !>",line[i]) |
---|
| 344 | } else { |
---|
| 345 | sub(/^ *\!\!/, " !>",line[i]) |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | debugprint("traitement des lignes précédentes : " line[i]) |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | flush_line() |
---|
| 352 | myprint($0) |
---|
| 353 | next |
---|
| 354 | } else { |
---|
| 355 | debugprint("normal line") |
---|
| 356 | |
---|
| 357 | if ( idecl == 1 ) idecl=0 |
---|
| 358 | |
---|
| 359 | flush_line() |
---|
| 360 | myprint($0) |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | END { |
---|
| 365 | if ( ! ldebug ) close(output_file) |
---|
| 366 | } |
---|