chiark / gitweb /
zone.lisp: New utility for hashing files.
[zone] / frontend.lisp
index 9d62d299368b1e0e0c6f8c4153053063eadf8cc8..0764c3f7cd43beea6ae526059cca40d75fbbb9e5 100644 (file)
@@ -22,8 +22,8 @@
 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 (defpackage #:zone.frontend
-  (:use #:common-lisp #:optparse #:net #:zone
-       #+cmu #:mop
+  (:use #:common-lisp #:mdw.sys-base #:optparse #:net #:zone
+       #+(or cmu clisp) #:mop
        #+sbcl #:sb-mop)
   (:export #:main))
 (in-package #:zone.frontend)
@@ -32,6 +32,8 @@ (defvar opt-zones nil
   "Which zones to be emitted.")
 (defvar opt-format :bind
   "Which format to use on output.")
+(defvar opt-debug nil
+  "Whether to emit stack backtraces on error.")
 
 (defun directory-exists-p (name)
 
@@ -71,6 +73,8 @@ (define-program
                      (#\s "subnet" (:arg "NET")
                           (list zone:*preferred-subnets*)
                           "Designate NET as a preferred subnet.")
+                     (#\D "debug" (set opt-debug)
+                          "Produce stack backtrace on error.")
                      "Output options"
                      (#\d "directory" (:arg "DIRECTORY")
                           (dir *zone-output-path*)
@@ -79,8 +83,11 @@ (define-program
                           (keyword opt-format
                                    (delete-duplicates
                                     (loop for method in
-                                          (generic-function-methods
-                                           #'zone:zone-write)
+                                          (append
+                                           (generic-function-methods
+                                            #'zone:zone-write)
+                                           (generic-function-methods
+                                            #'zone:zone-write-header))
                                           for specs =
                                           (method-specializers method)
                                           if (typep (car specs)
@@ -93,20 +100,26 @@ (define-program
                           "Write information about zone NAME.")))
 
 (defun main ()
-  (with-unix-error-reporting ()
-    (let ((files nil))
-      (unless (option-parse-try
-               (do-options ()
-                 (nil (rest)
-                   (when (zerop (length rest))
-                     (option-parse-error "no files to read"))
-                   (setf files rest))))
-       (die-usage))
-      (dolist (f files)
-       (let ((*package* (make-package "ZONE.SCRATCH"
-                                      :use '(#:common-lisp #:net #:zone))))
-         (load f :verbose nil :print nil :if-does-not-exist :error)
-         (delete-package *package*)))
-      (zone-save opt-zones :format opt-format))))
+  (set-command-line-arguments)
+  (let ((files nil))
+    (flet ((run ()
+            (dolist (f files)
+              (let ((*package* (make-package "ZONE.SCRATCH"
+                                             :use '(#:common-lisp
+                                                    #:net #:zone))))
+                (load f :verbose nil :print nil :if-does-not-exist :error)
+                (delete-package *package*)))
+            (zone-save opt-zones :format opt-format)))
+      (with-unix-error-reporting ()
+       (unless (option-parse-try
+                 (do-options ()
+                   (nil (rest)
+                        (when (zerop (length rest))
+                          (option-parse-error "no files to read"))
+                        (setf files rest))))
+         (die-usage)))
+      (if opt-debug
+         (run)
+         (with-unix-error-reporting () (run))))))
 
 ;;;----- That's all, folks --------------------------------------------------