# mkArts.awk - Generate sample Arts Sitar page from data with format: # select descr course1 course2... # where select is "All" or the number of courses to display BEGIN { OFS = FS = "\t" MAX = 5 # number of courses (full width) MID = 2 # number of courses (half width) copyfile("Arts.pro") printf "\n", MAX+1 newline = 1 } $1 ~ /^0*$/ { next } { nc = $1 if (nc ~ /[Aa]ll/) { nc = NF while (nc > 2 && $nc !~ /[A-Z][0-9]/) nc-- nc -= 2 } ncspan = nc # spanned columns don't look very good :(- if (nc > MID) ncspan = MAX else if (nc < MID) ncspan = MID if (!newline) { # see if this course fits if (ncspan == MAX) { term() newline++ } } if (newline) { print "" } printf "\n", tohtml($2) # description for (i=1; i <= ncspan; i++) { course = $(i+2) # printf "%s\n", \ # (i == nc && nc < ncspan)? " colspan=\"" ncspan-nc+1 "\"" : "", # course ~ /[A-Z][0-9]/? course : " " if (course ~ /[A-Z][0-9]/) printf "\n", course else print "" } if (!newline || ncspan == MAX) { print "" newline = 1 } else newline = 0 } END { print "
Session 1
%s %s 
" copyfile("Arts.epi") } function term() { # end row for (i=0; i <= MID; i++) print " " print "" } function tohtml(s) { gsub(/ and /, " \\& ", s) gsub(/^"|"$/, "", s) if (sub(/B: */, "", s)) return colour(s, "#004080") else if (sub(/C: */, "", s)) return colour(s, "#804040") return s; } function copyfile(fin, line) { while (getline line 0) print line } function colour(s, col) { return sprintf("%s", col, s) }