Assorted away-tpope updates
[tpope-extra.git] / perl / schedproc
index 1c94288ff28fe949b1380ec8e0edfcb3843ebaa0..2a80bc3df745f296e61985445c172f254d6c1f81 100755 (executable)
@@ -82,7 +82,7 @@ undef $opts{'out'} if(($opts{'out'}||"") eq "-");
 sub generate_id {
     my ($section, $number) = split("-", shift);
     my $id = 0;
-    foreach (split //, $section) {$id=26*$id+(ord($_)-1)%32;}
+    foreach my $c (split //, $section) {$id=26*$id+(ord($c)-1)%32;}
     $id=10000*$id+$number;
     return $id;
 }
@@ -96,8 +96,8 @@ sub first_class {
     my $lastday = Date::Calc->new($4,$5,$6);
     my $today;
     my @days=();
-    foreach(split("",$class{'days'})) {
-       push @days, $days{$_};
+    foreach my $d (split("",$class{'days'})) {
+       push @days, $days{$d};
     }
     my @off = ();
     @off = @{$class{'off'}} if ($class{'off'});
@@ -118,8 +118,8 @@ sub next_class {
     my $lastday = Date::Calc->new($4,$5,$6);
     my $today = Date::Calc->new(Date::Calc->localtime(time+3600*6)->date);
     my @days=();
-    foreach(split("",$class{'days'})) {
-       push @days, $days{$_};
+    foreach my $d(split("",$class{'days'})) {
+       push @days, $days{$d};
     }
     my @off = ();
     @off = @{$class{'off'}} if ($class{'off'});
@@ -219,9 +219,8 @@ sub load_faculty {
     if(($opts{'faculty'}) && ! %faculty) {
        $faculty{'done'} = "true";
        $content = read_fileurl($opts{'faculty'},1);
-       foreach $_ (split("\n", $content)) {
-           m/"([^"]*)",([^,]*),([^,]*)/; # "
-           ($name, $email, $url) = ($1, $2, $3);
+       foreach my $f (split("\n", $content)) {
+           ($name, $email, $url) = $f =~ m/"([^"]*)",([^,]*),([^,]*)/; # "
            next unless ($name);
            $name =~ s/ [A-Z]\.//g;
            $name = lc $name;
@@ -277,10 +276,11 @@ sub do_mhc_schedule {
     @mhc = get_mhc_header;
     if(defined($file) && (-d $file)) {
        my @mhc2;
+       local $_;
        foreach (@mhc) {
-           $_ =~ s/X-SC-Subject: ([^\n]*)/X-SC-Subject: $1\nSubject: $1/;
-           $_ =~ s/X-SC-Category: ([^\n]*)/X-SC-Category: $1\nFrom: $1/;
-           $_ =~ s/X-SC-Duration: (\d\d\d\d)(\d\d)(\d\d)-/"X-SC-Duration: $1$2$3-\nDate: $3 " . $mon[$2-1] . " 1970 12:00:00 +0000"/e;
+           s/X-SC-Subject: ([^\n]*)/X-SC-Subject: $1\nSubject: $1/;
+           s/X-SC-Category: ([^\n]*)/X-SC-Category: $1\nFrom: $1/;
+           s/X-SC-Duration: (\d\d\d\d)(\d\d)(\d\d)-/"X-SC-Duration: $1$2$3-\nDate: $3 " . $mon[$2-1] . " 1970 12:00:00 +0000"/e;
            push @mhc2, $_;
        }
        @mhc = @mhc2;
@@ -293,7 +293,7 @@ sub do_mhc_schedule {
        $row->{'days'} =~ s/^ //;
        #$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
        my @day = ();
-       @day = map { "!" . $_ } (@{$row->{'off'}}) if ($row->{'off'});
+       @day = map { "!$_" } (@{$row->{'off'}}) if ($row->{'off'});
        $current = "";
        #print "# $id\n";
        $current .= "X-SC-Subject: " . $row->{'title'} . "\n";
@@ -330,10 +330,10 @@ sub do_mhc_schedule {
            }
        }
        my $i=0;
-       foreach (@mhc) {
+       foreach my $h (@mhc) {
            while(-f ++$i) {}
            open (FH, ">$file/$i") || die $!;
-           print FH $_;
+           print FH $h;
            close FH;
        }
     } else {
@@ -453,7 +453,7 @@ EOF
     my @schedule = get_schedule(@_);
     open(STDOUT, ">" . $file) || die $! if(defined($file) && (! -d $file));
     open(STDOUT, ">/dev/null") || die $! if(defined($file) && (-d $file));
-    print "BEGIN:VCALENDAR$r\nVERSION:2.0$r\nMETHOD:PUBLISH$r\n$timezone";
+    print "BEGIN:VCALENDAR$r\nPRODID:-//Tim Pope//NONSGML Schedproc//EN$r\nVERSION:2.0$r\nMETHOD:PUBLISH$r\n$timezone";
     foreach my $row (@schedule) {
        map { s/\n/-/g; $_} %$row;
        my ($starttime, $stoptime)=($row->{'begin'}, $row->{'end'});
@@ -471,7 +471,7 @@ EOF
        if(defined($file) && (-d $file)) {
            open FH, ">$file/" . $row->{'id'} . ".vcs" or die "$!";
            select FH;
-           print "BEGIN:VCALENDAR$r\nVERSION:2.0$r\nMETHOD:PUBLISH$r\n$timezone";
+           print "BEGIN:VCALENDAR$r\nPRODID:-//Tim Pope//NONSGML Schedproc//EN$r\nVERSION:2.0$r\nMETHOD:PUBLISH$r\n$timezone";
        }
        print "BEGIN:VEVENT$r\n";
        print "ORGANIZER:mailto:" . $opts{'email'} . "$r\n" if $opts{'email'};
@@ -551,7 +551,7 @@ sub do_html_schedule {
            $b=~s/(1[3-9]|2\d|00):(\d\d)AM/sprintf "%d:%02dPM",abs $1-12,$2/e;
            print "<td>$a-<wbr />$b</td>";
            print "<td>" . $row->{'duration'} . "</td>";
-           print "<td>" . $row->{'location'} . "</td>";
+           print "<td>" . (ref($row->{'location'})?"":$row->{'location'}) . "</td>";
            print "</tr>\n";
        }
     print "</table>\n";
@@ -586,13 +586,15 @@ sub do_html_grades {
            print "</td></tr>\n";
        }
     }
-    my $lastrow = $grades->{'cumulative'}->[scalar @{$grades->{'cumulative'}}-1];
-    print '<tr class="cumulative '.$shade.'"><td id="cumulative" colspan="2">Cumulative: through ', capitalize($lastrow->{'term'});
-    print '</td><td align="center" id="gpa" class="grade">';
-    print $lastrow->{'gpa'};
-    print '</td><td align="right" class="right-number">';
-    print join('</td><td align="right" class="right-number">', ($lastrow->{'earned'}, $lastrow->{'hours'}, $lastrow->{'points'}));
-    print "</td></tr>\n";
+    if(exists($grades->{'cumulative'})) {
+        my $lastrow = $grades->{'cumulative'}->[scalar @{$grades->{'cumulative'}}-1];
+        print '<tr class="cumulative '.$shade.'"><td id="cumulative" colspan="2">Cumulative: through ', capitalize($lastrow->{'term'});
+        print '</td><td align="center" id="gpa" class="grade">';
+        print $lastrow->{'gpa'};
+        print '</td><td align="right" class="right-number">';
+        print join('</td><td align="right" class="right-number">', ($lastrow->{'earned'}, $lastrow->{'hours'}, $lastrow->{'points'}));
+        print "</td></tr>\n";
+    }
     print "</table>\n";
     select STDOUT;
 }