#!/bin/csh -f
#(ie run the cshell on this but don't read the .cshrc)

echo version = 1.04 of atchange 1995 Dec 22

echo atchange: at a change of file $1 do script $2

# Tom Schneider
# toms@alum.mit.edu
# https://alum.mit.edu/www/toms/

# The atchange script waits for a change of a file and then executes a command
# or script.  For example,
#
# atchange x logout
#
# would log one out when file x changes.
#
# The program can also accept a command string inside quotes:
#
# atchange scan.p "pc scan"
#
# watches for the change of the pascal program scan.p.  When the source code
# changes (ie, I write a change out from an editor) the program is
# automatically compiled.  Atchange uses an infinite loop, so it will repeat
# the compile at the next change.
#
# If we open another window with:
#
# atchange scan scan
#
# Then the program will automatically be run after it has been
# compiled.
#
# With both of these running, this makes program development much easier.
#
# see further documentation in waitforchange.

switch ($#argv)
  case 2:
#    while(1)
     while (-e $1)
        $2
        echo -n "waiting for change of file $1 ... "
        waitforchange $1 0
    end
  breaksw

  default:
     echo usege: atchange file script
  breaksw
endsw
