#!/usr/bin/perl

# latexwatch.pl
# Copyright (C) 2000 Florian Schaefer 
#
# Permission to use, copy, and distribute this software and its documentation
# for any non-commercial purpose and without fee is granted
# provided that the above copyright notice appears in all copies.
# Commercial use will likely be granted but requires explicit permission,
# which may be gotten by the author. See http://www.netego.de/hpc?p=contact
# for contact information.
#
# This, and the accompanying scripts, is provided "as is" without any express
# or implied warranty.
#
# Use this script at your own risk.  It's guaranteed to do nothing but
# occupy space...unless your disk crashes, in which case it does nothing
# at all.

$file      = $ARGV[0];
$intervall = $ARGV[1];

if ($file =~ /.*\.tex/) {
	if (! ($intervall =~ /[1-9][0-9]*/) ) {
		$intervall = 3;
	}

	$lastchange = (stat($file))[9];
	while ( 1 ) {
		$tmp = (stat($file))[9];
		if ( $tmp ne $lastchange ) {
			system("/usr/bin/latex $file");
			$lastchange = $tmp;
		}
		sleep($intervall);
	}
}
else {
	print "Usage: latexwatch.pl \<file.tex\> [\<intervall\>]\n";
}
