(define LAST-ASSIGNMENT 1) #| File names are numeric, starting with 0 Each file has the format: lines To use this file to process a series of files, define TITLE-FORMAT : format-string with 2 ~a HEADER2 : string then (require "aux.ss") The string TITLE-FORMAT must contain two occurrences of ~a, where the files title will be plugged in. The string HEADER2 will be inserted below a
and should end with a
to set it aside from other material. |# ;; main : -> void ;; effect : ;; run process-file on one command-line argument ;; or on all files with numeric names (define (main) (case (vector-length argv) [(1) (let* ((name (vector-ref argv 0))) (process-file name))] [(0) (let ((LAST (max-numbered-file))) (let L ((i 0)) (unless (> i LAST) (process-file i) (L (+ i 1)))))] [else (error 'assign " or no argument")])) ;; max-numbered-file : -> nat-num ;; effect: scan current directory for file with highest number as filename (define (max-numbered-file) (let L ((i 0)) (if (file-exists? (format "~s.shtml" (+ i 1))) (L (+ i 1)) i))) ;; process-file : X -> void ;; effect: produce an HTML file X.shtml (define (process-file no) (let ((body (format "~a" no))) (unless (file-exists? body) (error 'Usage: "no such file: ~a" body)) (let* ((iport (open-input-file body)) (aline (read-line iport)) (title (format TITLE-FORMAT no (second (regexp-match TITLE-PATTERN aline)))) (oport (delete-and-open (format "~a.shtml" no)))) (current-output-port oport) (printf HEADER title title HEADER2) (file-copy iport) (close-input-port iport) (printf BOTTOM) (close-output-port oport)))) ;; file-copy : input-port -> void ;; effect: copy the port to plain output (define (file-copy iport) (let ((achar (read-char iport))) (unless (eof-object? achar) (display achar) ; (newline) (file-copy iport)))) ;; delete-and-open : str -> output-port ;; effect: delete file fname, if exists, and then open it (define (delete-and-open ofile) (when (file-exists? ofile) (delete-file ofile)) (open-output-file ofile)) ;; Matching the title in a spec file [the first rules out - in title] (define TITLE-PATTERN "") (define TITLE-PATTERN "") (define HEADER " ~a

~a



~a
    ") (define BOTTOM (format "




Kathi Fisler This page was generated on ~a.
" (read-line (car (process "date")))))