#! /bin/awk -f ## ## ## I'm not super happy with how this code looks. Rest assured, though, ## the C version would look far, far worse. ## ## function qsort(A, left, right, i, last) { if (left >= right) return swap(A, left, left+int((right-left+1)*rand())) last = left for (i = left+1; i <= right; i++) if (A[i] < A[left]) swap(A, ++last, i) swap(A, left, last) qsort(A, left, last-1) qsort(A, last+1, right) } function swap(A, i, j, t) { t = A[i]; A[i] = A[j]; A[j] = t } function escape(s) { gsub("&", "&", s) gsub("<", "<", s) gsub(">", ">", s) return s } function head() { print "" print "
" for (ncat = 0; ncat < ncats; ncat += 1) { printf("%s\n", ncat, categories[ncat]); } print "
" for (i = nteams-1; i >= 0; i -= 1) { score = scores[i]; if (score == scores[i-1]) continue; # Skip duplicates for (hash in team_names) { if (total_score[hash] != score) { continue; } name = escape(team_names[hash]) print "" printf("%s\n", name) for (ncat = 0; ncat < ncats; ncat += 1) { cat = categories[ncat]; points = cat_points[hash, cat]; if (cat_points[hash, cat] > 0) { width = cat_score[hash, cat] / max_score * 90 printf("", cat, points, name) printf("%d", ncat, width, cat_points[hash, cat]) } } print "
" } } foot() }