+ if ((-e $localfn && -M $localfn < $mtime) || (-e $fn && -M $fn < $mtime) || $mtime == 0) {
+ my $t;
+
+ # first read in the standard one
+ if (-e $fn) {
+ $t = -M $fn;
+
+ @scrontab = cread($fn);
+ $mtime = $t if !$mtime || $t <= $mtime;
+ }
+
+ # then read in any local ones
+ if (-e $localfn) {
+ $t = -M $localfn;
+
+ @lcrontab = cread($localfn);
+ $mtime = $t if $t <= $mtime;
+ }
+ @crontab = (@scrontab, @lcrontab);
+ }
+}
+
+# read in a cron file
+sub cread
+{
+ my $fn = shift;
+ my $fh = new IO::File;
+ my $line = 0;
+ my @out;
+
+ dbg("cron: reading $fn\n") if isdbg('cron');
+ open($fh, $fn) or confess("cron: can't open $fn $!");
+ while (<$fh>) {
+ $line++;
+ chomp;
+ next if /^\s*#/o or /^\s*$/o;
+ my ($min, $hour, $mday, $month, $wday, $cmd) = /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$/o;
+ next unless defined $min;
+ my $ref = bless {};
+ my $err;
+
+ $err |= parse($ref, 'min', $min, 0, 60);
+ $err |= parse($ref, 'hour', $hour, 0, 23);
+ $err |= parse($ref, 'mday', $mday, 1, 31);
+ $err |= parse($ref, 'month', $month, 1, 12, "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
+ $err |= parse($ref, 'wday', $wday, 0, 6, "sun", "mon", "tue", "wed", "thu", "fri", "sat");
+ if (!$err) {
+ $ref->{cmd} = $cmd;
+ push @out, $ref;
+ dbg("cron: adding $_\n") if isdbg('cron');
+ } else {
+ dbg("cron: error on line $line '$_'\n") if isdbg('cron');
+ }
+ }
+ close($fh);
+ return @out;
+}
+
+sub parse
+{
+ my $ref = shift;
+ my $sort = shift;
+ my $val = shift;
+ my $low = shift;
+ my $high = shift;
+ my @req;
+
+ # handle '*' values
+ if ($val eq '*') {
+ $ref->{$sort} = 0;
+ return 0;
+ }