#!/bin/sh

if (test -f $1) then
    echo "Testing file $1 for prompt integrity";
else
    cat <<END_OF_HELP
name: lk_test_app
synopsis: lk_test_app config_file [coding]
descr: test the prompt files in a data collection application
example: lk_test_app config/config_file_0.dcol ulaw

options:
 coding: this is an optionanl sphere coding string to be matched

This program tests to make sure that all of the prompt files in a data
collection application exist, are readable, and optionaly are of the
right format.
END_OF_HELP
    exit;
fi

A=`grep filename $1 |grep -v \# |grep -v template|cut -d'=' -f2 |cut -d\; -f1`;

ERRORS="";
for FILE in $A

 do

#    echo "         FILE = $FILE";
    FILE=`echo $FILE|cut -d\" -f2| cut -d\" -f1`;
    FILE=`echo "echo $FILE"|sh`;

   if (test -f $FILE) then

	if (test -r $FILE) then

	    if (test -s $FILE) then

		B=`head -1 $FILE|grep NIST_1A`;
		if (test -z "$B") then
		    echo "ERROR: File >$FILE< is not a sphere file";
		    ERRORS="1";
		else
		    B=`head -20 $FILE|grep "sample_coding.*$2"`;
		    if(test -z "$B") then
			echo "ERROR: File >$FILE< is not of format $2";
			ERRORS="1";
		    fi
		fi
	    else
		echo "ERROR: File >$FILE< is size 0";
		ERRORS="1";
	    fi


	else
	    echo "ERROR: File >$FILE< is not readable";
	    ERRORS="1";
	fi


    else
	echo "ERROR: File >$FILE< does not exist";
	ERRORS="1";
    fi
    
 done

if (test -z "$ERRORS") then
    echo "No file reference errors found in configuration file $1";
fi
