| 1 | #!/usr/bin/env bash |
|---|
| 2 | # prints all files in SOURCE that have incomplete variable descriptions to console. |
|---|
| 3 | # in each file, prints corresponding subroutine, function or module with its line. |
|---|
| 4 | |
|---|
| 5 | # returns the line-number of the last line matching $3 in file $1 before line $2 |
|---|
| 6 | get_prev_regex_line_number () { |
|---|
| 7 | local search_end=$(expr ${2} - 1) |
|---|
| 8 | line_number_prev=$(sed -n 1,${search_end}p ${1} | grep -n ${3} | grep -vP ': *!' | cut -f1 -d: | tail -n1) |
|---|
| 9 | # line_number_prev=$(sed -n "/${3}/{1,${search_end}=}" ${1} | tail -n1) |
|---|
| 10 | echo $line_number_prev |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | # searches file $1 for the closest expression SUBROUTINE, FUNCTION or MODULE to each uncommented declaration and returns that line number |
|---|
| 14 | foo () { |
|---|
| 15 | # all lines that have doxygen comment (!<) ready but end after that and are not a comment (don' start with !) |
|---|
| 16 | for uncommented_linenumber in $(grep -nP '!< *$' ${1} | grep -vP ': *!' | grep -oP '^\d{1,5}:' | grep -oP '^\d{1,5}'); do |
|---|
| 17 | rout=-999 |
|---|
| 18 | func=-999 |
|---|
| 19 | mod=-999 |
|---|
| 20 | rout=$(get_prev_regex_line_number ${1} ${uncommented_linenumber} 'SUBROUTINE') |
|---|
| 21 | func=$(get_prev_regex_line_number ${1} ${uncommented_linenumber} 'FUNCTION') |
|---|
| 22 | mod=$(get_prev_regex_line_number ${1} ${uncommented_linenumber} 'MODULE') |
|---|
| 23 | # return only the largest of the found line numbers as this is the closest to the uncommented declaration |
|---|
| 24 | if [[ ${rout} -gt ${func} ]]; then |
|---|
| 25 | if [[ ${rout} -gt ${mod} ]]; then |
|---|
| 26 | echo ${rout} |
|---|
| 27 | else |
|---|
| 28 | echo ${mod} |
|---|
| 29 | fi |
|---|
| 30 | else |
|---|
| 31 | if [[ ${func} -gt ${mod} ]]; then |
|---|
| 32 | echo ${func} |
|---|
| 33 | else |
|---|
| 34 | echo ${mod} |
|---|
| 35 | fi |
|---|
| 36 | fi |
|---|
| 37 | done |
|---|
| 38 | # all lines that contain declarations (::) but no comment at the end and are no comments themselves |
|---|
| 39 | for uncommented_linenumber in $(grep -nP '::' ${1} | grep -vP '!<' | grep -vP 'INTRINSIC' | grep -vP ': *!' | grep -oP '^\d{1,5}:' | grep -oP '^\d{1,5}'); do |
|---|
| 40 | rout=-999 |
|---|
| 41 | func=-999 |
|---|
| 42 | mod=-999 |
|---|
| 43 | rout=$(get_prev_regex_line_number ${1} ${uncommented_linenumber} 'SUBROUTINE') |
|---|
| 44 | func=$(get_prev_regex_line_number ${1} ${uncommented_linenumber} 'FUNCTION') |
|---|
| 45 | mod=$(get_prev_regex_line_number ${1} ${uncommented_linenumber} 'MODULE') |
|---|
| 46 | # return only the largest of the found line numbers as this is the closest to the uncommented declaration |
|---|
| 47 | if [[ ${rout} -gt ${func} ]]; then |
|---|
| 48 | if [[ ${rout} -gt ${mod} ]]; then |
|---|
| 49 | echo ${rout} |
|---|
| 50 | else |
|---|
| 51 | echo ${mod} |
|---|
| 52 | fi |
|---|
| 53 | else |
|---|
| 54 | if [[ ${func} -gt ${mod} ]]; then |
|---|
| 55 | echo ${func} |
|---|
| 56 | else |
|---|
| 57 | echo ${mod} |
|---|
| 58 | fi |
|---|
| 59 | fi |
|---|
| 60 | done |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | wd=~/palm/current_version/trunk/SOURCE |
|---|
| 64 | for filename in ${wd}/*.f90; do |
|---|
| 65 | #give each line only once and none if they still have initial values |
|---|
| 66 | routine_lines=$(foo ${filename} | sort -n | uniq | sed "s/-999//" ) |
|---|
| 67 | #print filename if there are uncommented declarations |
|---|
| 68 | if [[ ${routine_lines} != "" ]]; then |
|---|
| 69 | echo $(basename ${filename} ) |
|---|
| 70 | fi |
|---|
| 71 | #print each SUBROUTINE, FUNCTION or MODULE with line and name that contains uncommented declarations |
|---|
| 72 | for linenumber in ${routine_lines}; do |
|---|
| 73 | sed -n "${linenumber}{p;q}" ${filename} | sed "s/^ */ ${linenumber} /" | sed "s/([^)]*) *$//" | sed "s/([^&]*& *$//" | sed "s/(.* result//" | sed "s/(.* RESULT//" |
|---|
| 74 | done |
|---|
| 75 | done |
|---|