#!/bin/sh
 
#    Jan 14/92 - E. Chan 

#id  fixdiag  - replaces all calls to decks gpq.dk, gpt.dk, and gpz.dk in a job
#id             with a single call to gpqtz.dk and replaces all calls
#id             to decks gpu.dk and gpv.dk with a call to gpuv.dk. 

#    AUTHOR  - E. Chan (Oct 29/91)

#hd  PURPOSE - "fixdiag" processes a user's job by replacing all calls to the deck 
#hd            gpq.dk (i.e. all ". gpq.dk" lines) with a call to gpqtz.dk and strips
#hd            out all calls to gpt.dk and gpz.dk.
#hd
#hd            The script also replaces all calls to gpu.dk with gpuv.dk and strips
#hd            all calls to gpv.dk.

#pr  PARAMETERS:
#pr 
#pr    POSITIONAL
#pr 
#pr      fn1 fn2 ... fnm = list of m files that require fixing

#ex  EXAMPLE
#ex  
#ex   fixdiag *
#ex  
#ex   The above example fixes all files in the current directory. 

#  * Loop over all files in the input list.

for file
do

  # Ensure that only existing ascii text files are operated on.

  info=`file $file 2>/dev/null `
  file_status=`expr "$info" : '.*\(script\).*'`

  if [ ! -f "$file" ] ; then
    echo "file $file does not exist: resuming execution with next file in list"
  elif [ -z "$file_status" ] ; then
    echo "file $file is not an ascii text file: file skipped"
  else
    sed 's/^ *\.  *gpq.dk/. gpqtz.dk/
         /^ *\.  *gpt.dk/d
         /^ *\.  *gpz.dk/d
         s/^ *\.  *gpu.dk/. gpuv.dk/
         /^ *\.  *gpv.dk/d
        '                             $file > tmpfile$$
    mv tmpfile$$ $file
  fi 
done

exit
