#!/bin/csh

#--- Decodage arguments
unset A
unset U
unset NOS
unset R
if( "$1" == '-h' ) then
  echo "usage chk_cvs.csh [-a] [-all] [-nos] [-u] [r]"
  echo "    -nos : pas de cvs status demande"
  echo "    -a   : cvs status reduit  pour tous les fichiers"
  echo "    -all : cvs status complet pour tous les fichiers"
  echo "    -u   : update demande"
  echo "    -r   : chmod a+r demande"
  exit -1
else
  while( $#argv>0 )
    if( "$1" == "-a") set A = 1
    if( "$1" == "-all") set A = 2
    if( "$1" == "-nos") set NOS
    if( "$1" == "-u") set U
    if( "$1" == "-r") set R
    shift
  end
endif
if( $?U || $?R ) set NOS

set CURDIR = `pwd`
if( $?U ) echo "attention...... UPDATE demande"

#--- Recherche des repertoires sous CVS
set fall = (`ls -1`)
set dcvs = ( )
foreach f ( $fall )
  if( -e $f/CVS ) set dcvs = ( $dcvs $f )
end

#--- Action CVS dans chacun des repertoires concernes
foreach d ( $dcvs )
  if (-e $CURDIR/$d)  then
    echo " " ; echo " "
    echo "******************************************"
    echo "   --- $d ---" ; echo " "
    cd $CURDIR/$d
    if( ! $?NOS ) then
      if( $?A ) then
        if( $A == 1 ) then
          cvs status | grep Status
        else if( $A == 2 ) then
          cvs status
        endif
      else
        cvs status | grep Status | grep -v "Up-to-date"
      endif
    endif
    if( $?U ) cvs update
    if( $?R ) then
      chmod -R a+r *
    endif
  endif
end

cd $CURDIR

exit 0
