#!/bin/sh
# normdate -- Dans une spcification de date, normalise le
#   champ du mois  trois lettres, la premire tant une majuscule.
#   Fonction d'appui du script #7, valid-date. Quitte avec
#   un code de retour nul en l'absence d'erreur.

monthnoToName() 
{
  # Positionne la variable 'month'  la bonne valeur
  case $1 in
    1 ) month="Jan"     ;;  2 ) month="Fev"     ;;
    3 ) month="Mar"     ;;  4 ) month="Avr"     ;;
    5 ) month="Mai"     ;;  6 ) month="Jun"     ;;
    7 ) month="Jul"     ;;  8 ) month="Aou"     ;;
    9 ) month="Sep"     ;;  10) month="Oct"     ;;
    11) month="Nov"     ;;  12) month="Dec"     ;;
    * ) echo "$0: Numro de mois inconnu $1" >&2; exit 1 
  esac 
  return 0
}

## Dbut du script principal

if [ $# -ne 3 ] ; then 
  echo "Syntaxe: $0 jour mois anne" >&2 
  echo "Exemples: 3 aout 1962 ou 3 8 2002" >&2 
  exit 1
fi

if [ $3 -lt 99 ] ; then 
  echo "$0: tapez une anne  quatre chiffres." >&2; 
  exit 1 
fi

if [ -z $(echo $2|sed 's/[[:digit:]]//g') ]; then 
  monthnoToName $2
else
  # Normalise vers les trois premires lettres: capitale initiale
  # puis minuscules.
  month="$(echo $2|cut -c1|tr '[:lower:]' '[:upper:]')" 
  month="$month$(echo $2|cut -c2-3 | tr '[:upper:]' '[:lower:]')"
fi

echo $1 $month $3

exit 0
