Add shell command record type.
[scratchy.git] / burrow.scm
index 899edae..c258311 100644 (file)
@@ -8,7 +8,7 @@
         (chicken condition)
         (chicken process)
         (chicken process-context)
-        srfi-13 matchable)
+        srfi-1 srfi-13 matchable)
 
 (define gopher-index-file-name "index")
 
 ;;; Index rendering
 
 (define (serve-info-record info-string)
-  (print "i" info-string "\tfake\tfake\t1\r"))
+  (print* "i")
+  (for-each (lambda (char)
+              (print* (if (eq? char #\tab)
+                          "    "
+                          char)))
+            (string->list info-string))
+  (print "\tfake\tfake\t1\r"))
 
 (define (serve-record record path config)
   (match record
+    (('shell command) (serve-shell-command command))
     ((type display-string selector host port)
      (print type display-string "\t" selector "\t" host "\t" port "\r"))
     ((type display-string selector host)
      (serve-record (list (infer-selector-type selector) display-string selector)
                    path config))
     ((selector)
-     (serve-record (list (infer-selector-type selector) selector)
+     (serve-record (list (infer-selecto-type selector) selector)
                    path config))
     (else (error "Unknown record type."))))
 
+(define (serve-shell-command command)
+  (let-values (((in-port out-port id) (process command)))
+    (for-each serve-info-record (read-lines in-port))))
 
 ;;; main
 
               (run-server (make-server-config root hostname port))
               (error "Invalid port argument." port))))))
 
-;; (main)
+(main)
 
-(define (test)
-  (run-server (make-server-config "gopher-root" "localhost" 70)))
+;; (define (test)
+;;   (run-server (make-server-config "gopher-root" "localhost" 70)))
 
 ;; (test)