#! /bin/gawk -f 

# keysquawker
# gawk program to set mdl keys for an incoming file of SMILES output is 
# TDT
#
BEGIN {
        EOM = "Qwerty: Over."
        #These could be command line arguments
        TDT = "$SMI<%s>\nFPK<%s>\n|\n"
        command = "./filter_fingertalk"
        key_set = "../data/mdl_keys.sma"
        # Ignore any welcome message
                while ( results !~ EOM ) {
                        command |& getline results
                }
        # Read in key_set ignore return message
                printf "%s\n%s\n", key_set, EOM |& command
                        command |& getline results
                while ( results !~ EOM ) {
                        command |& getline results
                }
        }
# Process incoming SMILES file
{
        do {
                printf "%s\n%s\n", $0, EOM |& command
                        command |& getline results
                while ( results !~ EOM ) {
                        printf TDT, $0, results
                        command |& getline results
                }
            } while ( getline )
            close ( command )
}