#! /usr/bin/awk -f # Public Domain # # gcc/testsuite$ find gfortran.*/ -name "*.[fF]" -o -name "*.[fF]90" -o -name "*.[fF]95" -o -name "*.[fF]03" -type f | xargs ../../contrib/gfortran.dg-final.cleanup-mods.awk 2> ERR > OUT # /[eE][nN][dD][ \t]*[mM][oO][dD][uU][lL][eE]/ { next; } /^[ \t]*[mM][oO][dD][uU][lL][eE][ \t]/ { if (tolower($2) == "procedure") next; pos++; tmp = tolower($2); gsub(/[ \t\x0D]*/, "", tmp); mod[pos] = tmp; file[pos] = FILENAME; # printf("%s:%d saw module '%s'\n", FILENAME, FNR, $2); } /{[ \t]*cleanup-modules/ { cleanup = tolower($0); sub(/.*{[ \t]*cleanup-modules/, "", cleanup); gsub(/[ \t][ \t]*/, " ", cleanup); gsub(/(^[ \t]+|["{}])/, "", cleanup); gsub(/[ \t]*$/, "", cleanup); split(cleanup, mods); for (i in mods) { cleaned++; clean[cleaned] = mods[i]; } } /\x0D/ { if (warned_encoding[FILENAME] != 1) { warned_encoding[FILENAME] = 1; print "Wrong encoding in file "FILENAME" \x21" > "/dev/stderr"; print "sed -i -e 's/\\x0D//g' "FILENAME; } } BEGIN { pos = -1; cleaned = -1; fixup = 1; } END { for (i = 0; i <= pos; i++) { for (j in clean) { if (mod[i] == clean[j]) { delete mod[i]; } } } for (i = 0; i <= pos; i++) { if (length(mod[i])) { printf("%s: no cleanup for module '%s'\n", file[i], mod[i]) > "/dev/stderr"; if (fixup) { emit[file[i]] = emit[file[i]] " " mod[i]; gsub(/^[ ]*/, "", emit[file[i]]); } } } if (fixup) { for (i = 0; i <= pos; i++) { if (length(emit[file[i]])) { printf("sed -i -e '/cleanup-modules/s/\\(\"[[:space:]]*}\\)/ %s\\1/' %s\n", emit[file[i]], file[i]); } } } }