#! /bin/ksh -p
PUBPATH=${STOLFIHOME}/ortho
progname=${0##*/}
REMOTE=""
ALT=""
ALLWRONG=""
LOC1=""
LOC2=""
LOC3=""
LOC4=""
if (($# > 0))
then
  if [[ $1 = "-remote" ]]
  then
    if (($# > 1))
    then
      REMOTE=$2
      shift 2
    else
      echo "  Falta de argumentos"; echo "  Uso: $progname [-remote useraddress] [-alt | -allwrong] [arq1 [arq2 [arq3 [arq4]]]] < texto > erros"
      exit
    fi
  fi
fi
#
if (($# > 0))
then
  if  [[ $1 = "-alt" || $1 = "-allwrong" ]]
  then
    ALT="-alt"
    if [[ $1 = "-allwrong" ]]
    then
      ALLWRONG="-allwrong"
    fi
    shift
  fi
fi
#
if (($# > 4))
then 
  echo "Excesso de argumentos"; echo "Uso: $progname [-remote useraddress] [-alt | -allwrong] [arq1 [arq2 [arq3 [arq4]]]] < texto > erros"
  exit
fi
#
if (($# > 0))
then
  case $# in
	1) LOC1="-1 $1";;
	2) LOC2="-2 $2";;
	3) LOC3="-3 $3";;
	4) LOC4="-4 $4";;
  esac 
fi
#
( case $progname in
  tex-ortho) $PUBPATH/texiso;;
  tt-ortho)  $PUBPATH/ttiso;;
  ortho)     cat;;
  testortho) cat;;
  esac )                                                                  |
#
/usr/local/gnu/bin/tr -cs '\\A-Za-zÀàÁÉÍÓÚáéíóúÂÊÔâêôÃÕãõÜüÇç' '\012'               |
#
/usr/bin/egrep -v '[^A-Za-zÀàÁÉÍÓÚáéíóúÂÊÔâêôÃÕãõÜüÇç]'                   |
#
/usr/local/gnu/bin/tr 'A-ZÀÁÉÍÓÚÂÊÔÃÕÇÜ'  'a-zàáéíóúâêôãõçü'                        |
#
/usr/local/gnu/bin/tee  -a $PUBPATH/notPUB/tmp-steal                                         |
#
if  [[ ${REMOTE} != "" ]]
then
  $PUBPATH/notPUB/Verif  -m 0 \
     -keyword $PUBPATH/latex -remote "$REMOTE" $ALT $ALLWRONG $LOC1 $LOC2 $LOC3 $LOC4
else
  $PUBPATH/notPUB/Verif  -m 0 \
     -keyword $PUBPATH/latex  $ALT $ALLWRONG $LOC1 $LOC2 $LOC3 $LOC4
fi |
#
( case $progname in
  tex-ortho) $PUBPATH/isotex;;
  tt-ortho)  $PUBPATH/isott;;
  ortho)     cat;;
  testortho)     cat;;
  esac )
#
# 
sort -u $PUBPATH/notPUB/tmp-steal >> $PUBPATH/notPUB/steal
cp $PUBPATH/notPUB/vazio $PUBPATH/notPUB/tmp-steal
