#!/usr/local/bin/bash #!/bin/sh #!/usr/bin/sh # ...because it's newer, more portable, and better maintained than ksh. # @(#) $Revision: 1.1 $ $Date: 2006/04/20 21:21:51 $ # @(#) $Source: /u/jer/public_html/tmp/RCS/tasks,v $ # CONVERT TEXT FORMAT TASKS FILE TO BROWSEABLE HTML FORM. # # Usage: See Usage(), or invoke with "-?" for a message. # # Enhancement ideas: # # - If details text paragraphs look like bullets (lines start with "*" or "-"), # automatically create
Webpage version updated '"$(date)"' from"; print "'"$textfile"'"; next; } # Look for and verify start of a new task section (starts with non-whitespace): ($0 ~ "^" nonspace) \ { if (NF <= 1) Error("Task start line must contain at least 2 fields.") if (length($1) != 3) { Error("Task start line must begin with three-letter code " \ "(and task detail lines must be indented)."); } pri = substr($1,1,1); eff = substr($1,2,1); stat = substr($1,3,1); if (! index("ABC", pri)) Error("Task priority must be one of A, B, C."); if (! index("LMH", eff)) Error("Task effort must be one of L, M, H."); if (! index("APDC", stat)) Error("Task status must be one of A, P, D, C."); # Get description text, save P/E/S and text less any leading whitespace; also # create a (long) hyperlink label that is hopefully safe, stable, and unique: # # Note: Not all contexts expect URLs to contain punctuation, they get # confused, so remove common punctuation marks first. priority[++tasks] = pri; effort [ tasks] = eff; status [ tasks] = stat; oneline [ tasks] = Trim(substr($0, 4)); str = oneline[tasks]; gsub("[][><|/ .,;:\"!@#$%^&*()]", "", str); label [ tasks] = pri "_" eff "_" stat "_" substr(str, 1, 20); gsub(space, "", label[tasks]); next; } # task start line. # Save task details lines, if any, for the current task: { if ((! tasks) && NF) { Error("Task start line must precede any indented task " \ "details text" IndComment($0)); } # Skip any leading blank lines, and note the last non-blank line; trim leading # whitespace except in
sections:
if ((! NF) && (! details[tasks])) next;
if ($0 ~ //) inPRE = 1;
if ($0 ~ /<\/PRE>/) inPRE = 0;
detail[tasks "." ++details[tasks]] = (inPRE ? $0 : Trim($0));
if (NF) lastnb[tasks] = details[tasks];
}
# If no errors, check that a title line and at least one task was found, then # emit the body of the HTML page:
END \
{
if (error) exit;
if (! title) Error("No page title line found.");
if (! tasks) Error("No tasks found.");
# Emit key table:
print "\n
| P = | "; print "Priority: A, B, C | "; print "
| E = | "; print "Effort: L(ow), M(edium), H(igh) | "; print "
\n
| Num | "; print "P | "; print "E | "; print "Status | "; print "One-line summary | "; print "
|---|---|---|---|---|
| " at " | "; print ColorTD(priority[at], "", ""); print ColorTD(effort [at], "", ""); print ColorTD(status [at], pre, post); print "" oneline [at] " | "; print "
sections, causes doublespacing): print "Task Details:
"; for (at = 1; at <= tasks; ++at) { if (! details[at]) continue; havedetails = 1; print "\n
" at ". (" \ priority[at] ",", effort[at] ",", status[at] ")", \ "" oneline[at] ""; for (at2 = 1; at2 <= lastnb[at]; ++at2) { text = detail[at "." at2]; if (text ~ /
/) inPRE = 1; if (text ~ /<\/PRE>/) inPRE = 0; print (text ~ nonspace) ? Hyper(text) \ : inPRE ? "" : "\n"; } } # Emit many trailing blank lines for inbound hyperlink scrolling to top of # browser window: if (havedetails) print "
"; for (at = 1; at <= 50; ++at) print "
"; print "\n\n"; }' # end awk # Check for awk error report: [[ -s $temp ]] \ && Error "$(< $temp) Invoke with \"-?\" for a format summary." } # MakeHTML ############################################################################### # M A I N # # function Main { # Check argument: [[ ($# != 1) || ("x$1" = 'x-?') ]] && Usage textfile="$1" [[ -r "$textfile" ]] \ || Error "Cannot read from text file \"$textfile\"." # Remove old HTML file if any: # # Note: Immediate recreation of the same file seems to reuse the same inode # number => some browsers refuse to refresh the file, so try to avoid this. HTMLfile="$(echo "$textfile" | sed 's/\.txt$//').htm" echo remove "$HTMLfile" rm -rf "$HTMLfile"; touch tasks_temp # Process $textfile; first blank any comment lines: sed < "$textfile" 's/^#.*//' | MakeHTML > "$HTMLfile" chmod 644 "$HTMLfile" # Skip this now that $HTMLfile is under SoftCM: # [[ -f "$HTMLfile" ]] && chmod 0444 "$HTMLfile" rm -rf tasks_temp exit 0 #} Main()