#! /usr/common/bin/gawk -f # # usage: testterm.awk EIS.file > NEW.file # or : testterm.awk EIS.file > /dev/null # # - this is version 1.3 renaming "unsigned.awk" to "testterm.awk": # - unnecessary leading zeros in any (un)signed term are removed # - copies additional abs( %V %W %X ) terms to ( %S %T %U ) if the # terms in ( %S %T %U ) match abs( %V %W %X ), resp. reports any # conflict # - all errors, changes, and unsolved problems reported in LOGFILE, # see below BEGIN (use e.g. file ./report_term or /dev/tty etc.) # #### report error ################################################# function ERROR( BAD ) { print BAD ; ++MM # copy erroneous line print "ignored error near: " substr( BAD, 1, 58 ) > LOGFILE } #### print items collected in BUF and reset it #################### function EJECT( ID ) { for ( K = 1 ; K <= 6 ; ++K ) { KEY = KEYS[ K ] if ( BUF[ KEY ] != "" ) print KEY, ID, BUF[ KEY ] BUF[ KEY ] = "" } return "" # caller resets ID } #### initialize KEYS ############################################## BEGIN { LOGFILE = "report_term" # keep error messages split( "%S %T %U %V %W %X", KEYS ) } #### note ID ###################################################### /^%I A/ { ID = $2 print ; next # copy anything else } #### unknown or empty BUF ######################################### ID == "" { print ; next # copy anything else } #### save %S, %T, %U, %V, %W, %X ################################## /^%[S-X] A/ { if ( $2 != ID || $4 != "" || BUF[ $1 ] != "" ) { ID = EJECT( ID ) # error if new id. $2 ERROR( $0 ) ; next } # or if blank in terms $4, or multiple $1 LINE = $3 while ( match( LINE, /( |-|,)0[0-9]/ )) { HEAD = substr( LINE, 1, RSTART ) LINE = HEAD substr( LINE, RSTART + 2 ) } if ( $3 != LINE ) { NN++ # count changed lines print "patch: " $1, $2, $3 > LOGFILE } BUF[ $1 ] = LINE ; next } #### patch missing unsigned terms ################################# { if ( $2 != ID ) # error if new id. $2 { ID = EJECT( ID ) # print lines in BUF ERROR( $0 ) ; next } UNS = BUF[ "%S" ] BUF[ "%T" ] BUF[ "%U" ] V = BUF[ "%V" ] ; gsub( /-/, "", V ) W = BUF[ "%W" ] ; gsub( /-/, "", W ) X = BUF[ "%X" ] ; gsub( /-/, "", X ) SIG = V W X # removed signs if ( SIG == substr( UNS, 1, length( SIG ))) { ID = EJECT( ID ) # no missing terms print ; next } if ( UNS != substr( SIG, 1, length( UNS ))) { ID = EJECT( ID ) # report mismatch ERROR( $0 ) ; next } print "patch STU " $2 ": " ++NN > LOGFILE BUF[ "%S" ] = V ; BUF[ "%T" ] = W BUF[ "%U" ] = X ; ID = EJECT( ID ) print ; next # copy anything else } #### 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" }