#!/bin/sh

string=? ; exec /home/mflatt/plt/bin/mzscheme -r $0 "$@"

(let loop ([l (directory-list)])
  (when (null? l) (exit))
  (when (regexp-match "\\.html$" (car l))
	(let* ([file (car l)]
	       [new (regexp-replace "\\.html$" file ".htm")]
	       [in (open-input-file file)]
	       [out (open-output-file new)])
	  (printf "~a~n"  file)
	  (let loop ()
	    (let ([line (read-line in)])
	      (unless (eof-object? line)
		      (let rloop ([old line][recent ""])
			(if (string=? old recent)
			    (begin
			      (display old out)
			      (newline out)
			      (loop))
			    (rloop (regexp-replace "\\.html" old ".htm")
				   old)))
		      (loop))))
	  (close-input-port in)
	  (close-output-port out)))
  (loop (cdr l)))
