#! /usr/common/bin/gawk -f # # usage: testsign.awk EIS.file > NEW.file # or : testsign.awk EIS.file > /dev/null # # - this is version 1.3 ignoring obsolete keywords "done" / "look": # - testsign ignores dead or dupe sequences (i.e. %K not modified) # - all errors, changes, and unsolved problems reported in LOGFILE, # see below BEGIN (use e.g. file ./report_sign or /dev/tty etc.) # - the order of the following changes is generally significant... # 1: %V +nonn => -nonn , 3: no %V +nonn +sign => -sign # 2: %V -sign => +sign , 4: no %V -nonn -sign => +nonn # 5; no %V -nonn +sign => reported as potential special case # #### report error ################################################# function ERROR( BAD ) { BAD = substr( BAD, 1, 48 ) ; MM++ # problem counter (MM) print "ignored error near line " NR ": " BAD > LOGFILE return "" # caller resets bad ID } #### add %K key ################################################### function FORCE( KEY ) { $3 = ( $3 == "" ? KEY : $3 "," KEY ) # add at end of %K $3 X = X " +" KEY ; return 1 # note all %K changes } #### delete key ################################################### function ERASE( KEY ) { gsub( KEY, "" ) # comma removed later X = X " -" KEY ; return 0 # note all %K changes } #### LOGFILE ###################################################### BEGIN { LOGFILE = "report_sign" # keep error messages } #### note ID ###################################################### /^%I A/ { PLUS = 1 ; ID = $2 print ; next # copy anything else } #### wait for %I ################################################## ID == "" { print ; next # after error or %K } #### test ID ###################################################### ID != $2 { ID = ERROR( $0 ) print ; next # report missing %I } #### note %V ###################################################### /^%V A/ { PLUS = 0 print ; next # copy anything else } #### test %W and %X ############################################### /^%[W-X] A/ { if ( PLUS ) ID = ERROR( $0 ) print ; next # report missing %V } #### skip dupe or dead ############################################ /^%K A.*d(upe|ead)/ { ID = "" # found %K: reset ID print ; next # copy dupe or dead } #### test %K ###################################################### /^%K A/ { X = "" ; ID = "" # collect all changes NONN = 0 < index( $0, "nonn" ) SIGN = 0 < index( $0, "sign" ) if ( ! PLUS ) # in sequence with %V { if ( NONN ) NONN = ERASE( "nonn" ) if ( ! SIGN ) SIGN = FORCE( "sign" ) } else if ( NONN && SIGN ) SIGN = ERASE( "sign" ) else if ( NONN == SIGN ) NONN = FORCE( "nonn" ) else if ( SIGN ) # in sequence w/out %V { OOPS = "no %V in " $2 ": " $3 " ?!?" MM++ ; print OOPS > LOGFILE } if ( X != "" ) # clean up comma etc. { gsub( /,,/, "," ) ; NN++ if ( match( $3, /^,/ )) $3 = substr( $3, 2 ) if ( match( $3, /,$/ )) $3 = substr( $3, 1, RSTART - 1 ) print "patch %K " $2 ":" X > LOGFILE } # report modifications print ; next # copy (patched) line } #### wait for %K ################################################## { print ; next # copy %N etc. } #### report number of patched sequences ########################### END { print NN++ " sequences patched" > LOGFILE print MM++ " unsolved problems" > LOGFILE if ( LOGFILE == "/dev/tty" ) exit print "see report in " LOGFILE ":" > "/dev/tty" print --NN " sequences patched" > "/dev/tty" print --MM " unsolved problems" > "/dev/tty" }