;; Generate KOTH Rankings page (lambda args (import (chicken string) (chicken pathname) srfi-1) (let* ((hill-dir "/var/koth/hill/")) (define (padded-string n s) (if (< (string-length s) n) (conc s (make-string (- n (string-length s)))) s)) (print* "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n" "- Corewar King of the Hill Rankings -\r\n" "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n" "\r\n") (let ((rankings (with-input-from-file (make-pathname hill-dir "rankings") read))) (if (= 0 (length rankings)) (print* "** Need at least two warriors on hill to list rankings **\r\n") (begin (print* (padded-string 8 "Score") " " (padded-string 20 "Warrior Name") " " (padded-string 20 "Author") " " "Submitted\r\n") (for-each (lambda (record) (let* ((name (car record)) (score (cadr record)) (info (with-input-from-file (make-pathname hill-dir name ".info") read)) (author (car info)) (submitted (cadr info))) (print* (padded-string 8 (->string score)) " " (padded-string 20 name) " " (padded-string 20 author) " " submitted"\r\n"))) (reverse rankings))))) (print* "\r\nRecent news:\r\n") (let* ((news (with-input-from-file (make-pathname hill-dir "news") read)) (recent-news (if (> (length news) 40) (take news 40) news))) (for-each (lambda (record) (let ((time (car record)) (news-item (cdr record))) (print* time " - " news-item "\r\n"))) recent-news))) (print* ".\r\n"))