2007年 10月 22日

Emacs で CGI 書く

#!/bin/sh
#@56
exec /usr/bin/emacs -Q --batch --no-unibyte --kill -l $0
; #@count は count 文文字をよみとばす elisp の機能
; vim:ft=scheme:expandtab:
; ↑ vim で elisp かよぷぷぷ scheme モードのほうがインデントがいい

(require 'cl)

(defun list-files (dir)
  (let ((ret '()))
    (loop for f in (directory-files dir t) do
          (let* ((attr (file-attributes f))
                 (dir?  (eq (car attr) t))
                 (file? (null (car attr)))
                 (mtime (nth 5 attr)))
            ;(print (list f dir? file?))
            (if (null (string-match "\\(\\.\\|\\.\\.\\)$" f))
              (progn
                (if dir?  (setf ret (append ret (list-files f))))
                (if file? (setf ret (append ret (list f)))))
              )
            )
          )
    ret)
  )

(princ "Content-Type: text/html; charset=utf-8\n\n")

(princ "<h1>aaaa</h1>")
(princ "<pre>")

(princ "Hello\n\n")

(print (pwd))
(print (list-files "data"))

(print system-configuration)
(print system-name)
(print (emacs-version))

(print (format-time-string "%Y-%m-%d %H:%M:%S" (current-time)))

(print (getenv "PATH_INFO"))
(print invocation-name)
(print process-environment)

(princ "</pre>")

Scheme と同じノリで書けるかと思ったら全然違う。Blosxom クローンつくろうとおもったけど途中までしか書いてない。続き書くかわからない。