#!/bin/sh
 
my_echo()
{
        echo ' '
        echo $n "$*" $c
}

if [ "`echo -n qq`" = "-n qq" ]; then
 n=''
 c='\c'
else
 n='-n'
 c=''
fi

FB=$BDA/bibliographie/biblio
FK=$BDA/bibliographie/key
BIBO=$BTP/bib.out

a1=95 
a2=95

case $LNG in
fr) MOT="Mot cle"
    MOTS="Mots cle";;
eng)MOT="Keyword"
    MOTS="Keywords" ;;
esac

case $1 in
-n) name=$2 ; shift ; shift 
    case $1 in
      -a|-eq) a1=$2 ; a2=$2 ; shift ; shift ;;
      -i) a1=$2 ; a2=$3 ; shift ; shift ; shift ;;
      -g|-gt) a1=$2 ; a2=96 ; shift ; shift ;;
      -p|-lt) a1=69 ; a2=$2 ; shift ; shift ;;
    esac
    until test $a1 -gt $a2 
    do
    echo ' '
    echo  " Bibliography 19$a1 " 
    zex $FB.$a1 | grep $name | awkpr1 > $BIBO
    nref=`grep -c $a1 $BIBO`
    case $nref in
     0) echo '  Nothing!' ; echo ' ' ;;
     *) zex $FB.$a1 | bibg ;;
    esac
    a1=`expr $a1 + 1` 
    done | more 
    exit 0 ;;    
-eq) a1=$2 ; a2=$2 ; shift ; shift ;;
 -i) a1=$2 ; a2=$3 ; shift ; shift ; shift ;;
-gt) a1=$2 ; a2=93 ; shift ; shift ;;
-lt) a1=69 ; a2=$2 ; shift ; shift ;;
-k) zex $BDA/bibliographie/mot.cle | pr -t -3 | page
    echo ' ' ; exit 0 ;;
-ki) echo ' ' ; echo 'Liste des mots cle ' ; echo ' '
     zex $BDA/bibliographie/mot.cle | grep "^$2" 
     echo ' ' ; exit 0 ;;
-ke) echo ' ' ; echo 'Liste des mots cle ' ; echo ' '
     zex $BDA/bibliographie/mot.cle | grep "$2$" 
     echo ' ' ; exit 0 ;;
-km) echo ' ' ; echo 'Liste des mots cle ' ; echo ' '
     zex $BDA/bibliographie/mot.cle | grep "$2" 
     echo ' ' ; exit 0 ;;
-t) zex $FK.$2 | awkpr1 | sort -n -u | wc -l
    exit 0 ;;
-w) case $# in
    3) zex $FK.$2 | grep $3 | awkpr1 > $BIBO ; echo ' '
       echo "$MOT (19$2) : $3 : `cat $BIBO | wc -l` references" 
       echo ' ' ; exit 0 ;;
    4) zex $FK.$2 | grep $3 | grep $4 | awkpr1 > $BIBO ; echo ' '
       echo "$MOTS (19$2) : $3 $4 : `cat $BIBO | wc -l` references" 
       echo ' ' ; exit 0 ;;
    5) zex $FK.$2 | grep $3 | grep $4 | grep $5 | awkpr1 > $BIBO ; echo ' '
       echo "$MOTS (19$2) : $3 $4 $5 : `cat $BIBO | wc -l` references" 
       echo ' ' ; exit 0 ;;
    esac ;;
-h) emploi bib ; exit 0 ;;
-c) echo ' '
    for i in `cat $BIBO | awk ' {print $1} '`
      do 
      zex $FK.$2 | grep $i
      done 
    echo ' '
    exit ;;
esac

case $# in
0) case $LNG in
   fr) my_echo '  Quelle annee?  ' ; read ann 
       my_echo '  Quel sujet?    ' ; read suj ;;
   eng) my_echo '	 Which year?     ' ; read ann
        my_echo '	 Which subject?  ' ; read suj ;;
   esac 

   while :
   do
   zex $FK.$ann | fgrep -i $suj | awkpr1 > $BIBO
   nre=`grep -c $ann $BIBO`
   case $nre in
    0) clear ; echo " Bibliography 19$ann "
       echo ' ' ; echo " Nothing!"
       echo ' ' ;;
    *) clear  
      (echo " Bibliography 19$ann " ; zex $FB.$ann | bibg ) | more ;;
   esac

   case $LNG in
   fr) my_echo " Une autre annee?  " ;;
   eng) my_echo " Another year?  " ;;
   esac
   read ans
   case $ans in
    0|n|fin|end) echo ' ' ; exit 0 ;;
    "") ;;
    *) ann=$ans ;;
   esac

   case $LNG in
   fr) my_echo " Un autre sujet?  " ;;
   eng) my_echo " Another subject?  " ;;
   esac
   read suk
   case $suk in
    "") ;;
    *) suj=$suk ;;
   esac

   done 
   echo ' ' ; exit 0 ;;

*) until test $a1 -gt $a2 
   do
   echo  " Bibliography 19$a1 " 
   case $# in
    1) zex $FK.$a1 | grep -i $1 > $BIBO ;;
    2) zex $FK.$a1 | grep -i $1 | grep -i $2 > $BIBO ;; 
    3) zex $FK.$a1 | grep -i $1 | grep -i $2 | grep -i $3 > $BIBO ;; 
   esac
   nref=`grep -c $a1 $BIBO`
   case $nref in
     0) echo '  Nothing!' ; echo ' ' ;;
     *) zex $FB.$a1 | bibg ;;
   esac
   a1=`expr $a1 + 1` 
   done | more 
   exit 0 ;;
esac
echo ' '
