chiark / gitweb /
zone.lisp: Stringify the zone name at construction time.
[zone] / frontend.lisp
index b920aa9a89994f0d3919cabb1ed560ff54a2fb7e..f9576019504077e2a0b95f52ef87242f98b0a625 100644 (file)
@@ -1,7 +1,5 @@
 ;;; -*-lisp-*-
 ;;;
 ;;; -*-lisp-*-
 ;;;
-;;; $Id$
-;;;
 ;;; Zone generator frontend
 ;;;
 ;;; (c) 2005 Straylight/Edgeware
 ;;; Zone generator frontend
 ;;;
 ;;; (c) 2005 Straylight/Edgeware
 ;;; it under the terms of the GNU General Public License as published by
 ;;; the Free Software Foundation; either version 2 of the License, or
 ;;; (at your option) any later version.
 ;;; it under the terms of the GNU General Public License as published by
 ;;; the Free Software Foundation; either version 2 of the License, or
 ;;; (at your option) any later version.
-;;; 
+;;;
 ;;; This program is distributed in the hope that it will be useful,
 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;;; GNU General Public License for more details.
 ;;; This program is distributed in the hope that it will be useful,
 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;;; GNU General Public License for more details.
-;;; 
+;;;
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with this program; if not, write to the Free Software Foundation,
 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 (defpackage #:zone.frontend
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with this program; if not, write to the Free Software Foundation,
 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 (defpackage #:zone.frontend
-  (:use #:common-lisp #:optparse #:zone)
+  (:use #:common-lisp #:mdw.sys-base #:optparse #:net #:zone
+       #+cmu #:mop
+       #+sbcl #:sb-mop)
   (:export #:main))
 (in-package #:zone.frontend)
 
 (defvar opt-zones nil
   "Which zones to be emitted.")
   (:export #:main))
 (in-package #:zone.frontend)
 
 (defvar opt-zones nil
   "Which zones to be emitted.")
+(defvar opt-format :bind
+  "Which format to use on output.")
+
+(defun directory-exists-p (name)
+
+  ;; Make a pathname for NAME which has the right form for a directory.
+  (let ((dirpath
+        (let ((path (pathname name)))
+          (if (null (pathname-name path))
+              path
+              (make-pathname :directory
+                             (append (or (pathname-directory path)
+                                         (list :relative))
+                                     (list (pathname-name path)))
+                             :name nil
+                             :type nil
+                             :defaults path)))))
+
+    ;; Now check that it exists.
+    #+clisp (and (ext:probe-directory dirpath) (truename dirpath))
+    #-clisp (probe-file dirpath)))
+
+(eval-when (:compile-toplevel :load-toplevel)
+  (defopthandler dir (var arg) ()
+    (let ((path (directory-exists-p arg)))
+      (if (and path
+              (not (pathname-name path)))
+         (setf var path)
+         (option-parse-error "path `~A' doesn't name a directory." arg)))))
 
 (define-program
     :version "1.0.0" :usage "ZONEDEF..."
     :help "Generates BIND zone files from Lisp descriptions."
 
 (define-program
     :version "1.0.0" :usage "ZONEDEF..."
     :help "Generates BIND zone files from Lisp descriptions."
-    :options (options help-opts
+    :options (options help-options
+                     "Parsing options"
+                     (#\f "feature" (:arg "KEYWORD")
+                          (list *features* 'keyword)
+                          "Insert KEYWORD in *features* list.")
+                     (#\s "subnet" (:arg "NET")
+                          (list zone:*preferred-subnets*)
+                          "Designate NET as a preferred subnet.")
                      "Output options"
                      "Output options"
+                     (#\d "directory" (:arg "DIRECTORY")
+                          (dir *zone-output-path*)
+                          "Write zone and serial files to DIRECTORY.")
+                     (#\F "format" (:arg "FORMAT")
+                          (keyword opt-format
+                                   (delete-duplicates
+                                    (loop for method in
+                                          (generic-function-methods
+                                           #'zone:zone-write)
+                                          for specs =
+                                          (method-specializers method)
+                                          if (typep (car specs)
+                                                    'eql-specializer)
+                                          collect
+                                          (eql-specializer-object
+                                           (car specs)))))
+                          "Format to use for output.")
                      (#\z "zone" (:arg "NAME") (list opt-zones)
                           "Write information about zone NAME.")))
 
 (defun main ()
                      (#\z "zone" (:arg "NAME") (list opt-zones)
                           "Write information about zone NAME.")))
 
 (defun main ()
+  (set-command-line-arguments)
   (with-unix-error-reporting ()
   (with-unix-error-reporting ()
-    (let ((seq 54)
-         (files nil))
+    (let ((files nil))
       (unless (option-parse-try
                (do-options ()
                  (nil (rest)
       (unless (option-parse-try
                (do-options ()
                  (nil (rest)
@@ -51,10 +104,10 @@ (defun main ()
                    (setf files rest))))
        (die-usage))
       (dolist (f files)
                    (setf files rest))))
        (die-usage))
       (dolist (f files)
-       (let ((*package* (make-package (format nil "zone.scratch-~A"
-                                              (incf seq))
-                                      :use '(#:common-lisp #:zone))))
-         (load f :verbose nil :print nil :if-does-not-exist :error)))
-      (zone-save opt-zones))))
+       (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))))
 
 ;;;----- That's all, folks --------------------------------------------------
 
 ;;;----- That's all, folks --------------------------------------------------