# Copyright 1989, 1990 Michael DeCorte


# check to see if there is another cronscript going already
if [ -f ${queue}/lock.parser ]
then
        exit
else
        touch ${queue}/lock.parser
fi

trap "rm -f ${queue}/lock.parser ${TMPDIR}/$$.* ${work_dir}/$$.* ; exit" 0 1 2 3 15

# init the seq if necessary
if [ ! -f ${queue}/seq ]
then
        echo 0 > ${queue}/seq
fi

# if the load avg is too high exit
if [ `load-average.sh` -gt ${maxload} ]
then
        exit
fi

# lower the process priority 
/etc/renice +20 $$ > /dev/null 2>&1

# go parse all the stuff
for f in ${queue}/in.*
do
    if [ ! -r $f ]
    then
            continue
    fi
    num=`cat ${queue}/seq`
    num=`expr ${num} + 1`
    if [ $? != 0 ]
    then
            mail -s "seq is broken" ${mailer} < /dev/null > /dev/null 2>&1
            exit
    fi
    echo ${num} > ${queue}/seq
    file=${queue}/done.${num}
    mv ${f} ${file}
    (convert-message.sh ${file} > ${queue}/working.${num}) 2>&1 | grep . 
    if [ $? = 0 ]
    then
            echo convert-message.sh
            echo ${file}
            echo
    fi
done


