#!/bin/sh
string=? ; exec mzscheme -g -l core.ss -r $0 "$@"

(require "../aux.ss")

(define (main)
  (case (vector-length argv)
    [(1)
     (let* ((name (vector-ref argv 0)))
       (assignment name))]
    [(0)
     (let L ((i 1))
       (unless (> i LAST-LECTURE)
	 (assignment i)
	 (L (+ i 1))))]
    [else 
      (error 'assign "<number:name of file> or no argument")]))

;; assignment : X -> void
;; effect: prepare an assignment file based on its index
(define (assignment no)
  (let ((body (format "~a" no)))
    (unless (file-exists? body)
      (error 'assign "no such file: ~a" body))
    (let* ((iport (open-input-file body))
	   (aline (read-line iport))
	   (title (format "Lecture ~a: ~a" no
		    (second (regexp-match TITLE aline))))
	   (oport (delete-and-open (format "~a.shtml" no))))
      (current-output-port oport)
      (printf ASSIGNMENT title title)
      (file-copy iport)
      (close-input-port iport)
      (printf BOTTOM)
      (close-output-port oport))))

(define ASSIGNMENT "<!-- generated by a MzScheme script # edit the source -->
<html>
<title>~a</title>

<body bgcolor=#ffffff>
<br>
<h3><center>~a</center></h3>
<br>

<hr>

<ol>
<!-- ------------------------------------------------------------- -->
")

(define BOTTOM "
<!-- ------------------------------------------------------------- -->
</ol>
<hr>
<table width=100%>
<tr>
<td align=left>Matthias Felleisen</td>
<td align=right>
<small>Last modified at <!--#echo var=\"LAST_MODIFIED\" --></small>
</td>
</tr>
</table>

</body>
</html>
")

(main)
