# file-monitor.pl
# Check the status of some file

sub get_file_status
{
local @st = stat($_[0]->{'file'});
if ($_[0]->{'test'} == 0) {
	$up = @st ? 1 : 0;
	}
elsif ($_[0]->{'test'} == 1) {
	$up = @st ? 0 : 1;
	}
elsif ($_[0]->{'test'} == 2) {
	$up = $st[7] > $_[0]->{'greater'} ? 1 : 0;
	}
elsif ($_[0]->{'test'} == 3) {
	$up = $st[7] < $_[0]->{'lesser'} ? 1 : 0;
	}
return { 'up' => $up };
}

sub show_file_dialog
{
print "<tr> <td><b>$text{'file_file'}</b></td>\n";
print "<td colspan=3><input name=file size=50 ",
      "value='$_[0]->{'file'}'></td> </tr>\n";

print "<tr> <td valign=top><b>$text{'file_test'}</b></td>\n";
printf "<td colspan=3><input type=radio name=test value=0 %s> %s<br>\n",
	$_[0]->{'test'} == 0 ? 'checked' : '', $text{'file_test_0'};
printf "<input type=radio name=test value=1 %s> %s<br>\n",
	$_[0]->{'test'} == 1 ? 'checked' : '', $text{'file_test_1'};
printf "<input type=radio name=test value=2 %s> %s\n",
	$_[0]->{'test'} == 2 ? 'checked' : '', $text{'file_test_2'};
printf "<input name=greater size=8 value='%s'> %s<br>\n",
	$_[0]->{'greater'}, $text{'file_bytes'};
printf "<input type=radio name=test value=3 %s> %s\n",
	$_[0]->{'test'} == 3 ? 'checked' : '', $text{'file_test_3'};
printf "<input name=lesser size=8 value='%s'> %s<br>\n",
	$_[0]->{'lesser'}, $text{'file_bytes'};
print "</td> </tr>\n";
}

sub parse_file_dialog
{
$in{'file'} || &error($text{'file_efile'});
$_[0]->{'file'} = $in{'file'};
$_[0]->{'test'} = $in{'test'};
$in{'greater'} =~ /^\d*$/ && $in{'lesser'} =~ /^\d*$/ ||
	&error($text{'file_esize'});
$_[0]->{'greater'} = $in{'greater'};
$_[0]->{'lesser'} = $in{'lesser'};
}

