Contents: Themes

July 16, 2010

Here’s our program:

export PRAXIS=/home/phil/praxis

awk ' # themes (page "themes")

BEGIN { FS = "\t"
        while (bash !~ /^number\t[1-9][0-9]*$/)
            getline
        split("Jan:Feb:Mar:Apr:May:Jun:Jul:Aug:Sep:Oct:Nov:Dec",
              monthname, ":") }

/^number\t/  { number = $2 }
/^file\t/    { file = $2 }
/^pubmon\t/  { pubmon = $2 }
/^pubday\t/  { pubday = $2 }
/^pubyear\t/ { pubyear = $2 }
/^title\t/   { title = $2 }
/^ptitle\t/  { ptitle = $2 }
/^blurb\t/   { blurb = $2 }
/^pblurb\t/  { pblurb = $2 }
/^exer\t/    { exer = $2 }
/^soln\t/    { soln = $2 }
/^extra\t/   { extra = $2 }
/^codepad\t/ { codepad = $2 }

# names[1..nthemes]              = sorted theme names
# counts[theme]                  = number of items in theme
# themes[theme,1..counts[theme]] = output line by theme/number

/^theme/ {
    counts[$2]++
    themes[$2,counts[$2]] =
    sprintf("<tr><td>&nbsp;</td><td>%d</td><td>%02d %s %d</td>" \
            "<td><a href=\"/%d/%02d/%02d/%s/\">%s</a>: \%s</td>"\
            "<td><a href=\"/%d/%02d/%02d/%s/\">exercise</a>" \
            "<a href=\"/%d/%02d/%02d/%s/%d/\">solution</a> "\
            "<a href=\"http://programmingpraxis.codepad.org/" \
            "%s\">codepad</a></td></tr>",
            number, pubday, monthname[pubmon], pubyear, pubyear,
            pubmon, pubday, file, title, blurb, pubyear, pubmon,
            pubday, file, pubyear, pubmon, pubday, file, soln, codepad) }

END {
    for (i in counts)
        names[++j] = i
    printf "<a name=\"top\" /><big><big>"
    n = asort(names)
    for (i=1; i<=n; i++)
        printf "<a href=\"#%s\">%s</a> (%d)%s",
               names[i], names[i], counts[names[i]],
               (i==n) ? "</big></big>\n" : " &middot; "
    printf "\n<table cellpadding=\"10\">\n"

    for (i=1; i<=n; i++) {
        printf "\n<tr><td colspan=\"6\"><a name=\"%s\" /><a href=\"#top\">" \
               "<big><big>%s</big></big></a></tr>\n", names[i], names[i]
        for (j=1; j<=counts[names[i]]; j++)
            printf "\n%s\n", themes[names[i],j] }
    printf "\n</table>\n" }

' $PRAXIS/praxis.info >$PRAXIS/pages/themes

This program differs somewhat from the earlier ones. The input is taken one line at a time, instead of one record at a time, and one output line is saved each time a theme line is encountered. Output is in two parts: first, the directory information at the top of the page, then one set of output lines for each theme. The data structures are documented in comments in the code.

The code is available at http://programmingpraxis.codepad.org/DXzbpli1.

Advertisement

Pages: 1 2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: