#!/usr/local/bin/perl # # make my page # # stdin format: # # everything is copied in verbatim except items between @@table and @@endtable # tags, which are treated thusly: # # @@table headercolor entrycolor # [title text on a line] # @@header # [header] # @@entry # [url, description] # @@header # (... etc ...) # @@endtable # # breaks them up into $ENTRIES_PER_ROW entries per "row". # # also replaces "@@date" with the date and time. # $S_NONE = 0; $S_TABLE = 1; $S_ENTRY = 3; $SEPARATOR = "--------"; $ENTRIES_PER_ROW = 3; &ResetState; while(<>) { chop(); next if (/^\s*#/); if (/\@\@date/i) { $t = localtime; s/\@\@date/$t/g; } if (/\@\@table/i) { warn("Going from state $STATE to table") if ($STATE != $S_NONE); ($junk, $HEADERCOLOR, $ENTRYCOLOR) = split(/\s+/); $STATE = $S_TABLE; next; } if (/\@\@entry/i) { warn("Going from state $STATE to entry") if (($STATE != $S_TABLE) && ($STATE != $S_ENTRY)); $HEADERCOUNT++; $HEADER[$HEADERCOUNT] = ""; $STATE = $S_ENTRY; next; } if (/\@\@endtable/i) { warn("Dumping table from state $STATE") if ($STATE != $S_ENTRY); &DumpTable; # print STDERR "Table dumped\n"; &ResetState; next; } if ($STATE == $S_NONE) { print $_,"\n"; } elsif ($STATE == $S_TABLE) { $TITLE = $_; } elsif ($STATE == $S_ENTRY) { if ($HEADER[$HEADERCOUNT] eq "") { $HEADER[$HEADERCOUNT] = $_; $ENTRIES[$HEADERCOUNT] = ""; } else { $ENTRIES[$HEADERCOUNT] .= $_ .= $SEPARATOR; } } else { warn("Unknown state $STATE"); } } sub ResetState { $STATE = $S_NONE; $HEADERCOUNT = -1; } sub DumpTable { print "
| $HEADER[$j] | \n"; } print "
| \n";
if (($i+1 % $ENTRIES_PER_ROW == 0) || ($i == $HEADERCOUNT)) {
print "