chiark / gitweb /
zone.lisp: New utility for hashing files.
[zone] / frontend.lisp
CommitLineData
7e282fb5 1;;; -*-lisp-*-
2;;;
7e282fb5 3;;; Zone generator frontend
4;;;
5;;; (c) 2005 Straylight/Edgeware
6;;;
7
8;;;----- Licensing notice ---------------------------------------------------
9;;;
10;;; This program is free software; you can redistribute it and/or modify
11;;; it under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 2 of the License, or
13;;; (at your option) any later version.
7fff3797 14;;;
7e282fb5 15;;; This program is distributed in the hope that it will be useful,
16;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
7fff3797 19;;;
7e282fb5 20;;; You should have received a copy of the GNU General Public License
21;;; along with this program; if not, write to the Free Software Foundation,
22;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24(defpackage #:zone.frontend
10b8955c 25 (:use #:common-lisp #:mdw.sys-base #:optparse #:net #:zone
3f0a7127 26 #+(or cmu clisp) #:mop
8e7c1366 27 #+sbcl #:sb-mop)
7e282fb5 28 (:export #:main))
29(in-package #:zone.frontend)
30
7e282fb5 31(defvar opt-zones nil
32 "Which zones to be emitted.")
a567a3bc
MW
33(defvar opt-format :bind
34 "Which format to use on output.")
9d6fbc71
MW
35(defvar opt-debug nil
36 "Whether to emit stack backtraces on error.")
7e282fb5 37
afb5d9e6 38(defun directory-exists-p (name)
da455301 39
afb5d9e6
MW
40 ;; Make a pathname for NAME which has the right form for a directory.
41 (let ((dirpath
42 (let ((path (pathname name)))
43 (if (null (pathname-name path))
44 path
da455301 45 (make-pathname :directory
afb5d9e6
MW
46 (append (or (pathname-directory path)
47 (list :relative))
48 (list (pathname-name path)))
49 :name nil
50 :type nil
51 :defaults path)))))
52
53 ;; Now check that it exists.
54 #+clisp (and (ext:probe-directory dirpath) (truename dirpath))
55 #-clisp (probe-file dirpath)))
56
122041a0
MW
57(eval-when (:compile-toplevel :load-toplevel)
58 (defopthandler dir (var arg) ()
afb5d9e6 59 (let ((path (directory-exists-p arg)))
122041a0
MW
60 (if (and path
61 (not (pathname-name path)))
62 (setf var path)
63 (option-parse-error "path `~A' doesn't name a directory." arg)))))
64
f41a8783
MW
65(define-program
66 :version "1.0.0" :usage "ZONEDEF..."
67 :help "Generates BIND zone files from Lisp descriptions."
884a01ff 68 :options (options help-options
122041a0
MW
69 "Parsing options"
70 (#\f "feature" (:arg "KEYWORD")
71 (list *features* 'keyword)
72 "Insert KEYWORD in *features* list.")
73 (#\s "subnet" (:arg "NET")
74 (list zone:*preferred-subnets*)
75 "Designate NET as a preferred subnet.")
9d6fbc71
MW
76 (#\D "debug" (set opt-debug)
77 "Produce stack backtrace on error.")
f41a8783 78 "Output options"
122041a0
MW
79 (#\d "directory" (:arg "DIRECTORY")
80 (dir *zone-output-path*)
81 "Write zone and serial files to DIRECTORY.")
a567a3bc
MW
82 (#\F "format" (:arg "FORMAT")
83 (keyword opt-format
84 (delete-duplicates
85 (loop for method in
146571da
MW
86 (append
87 (generic-function-methods
88 #'zone:zone-write)
89 (generic-function-methods
90 #'zone:zone-write-header))
a567a3bc 91 for specs =
8e7c1366 92 (method-specializers method)
a567a3bc 93 if (typep (car specs)
8e7c1366 94 'eql-specializer)
a567a3bc 95 collect
8e7c1366 96 (eql-specializer-object
a567a3bc
MW
97 (car specs)))))
98 "Format to use for output.")
f41a8783
MW
99 (#\z "zone" (:arg "NAME") (list opt-zones)
100 "Write information about zone NAME.")))
7e282fb5 101
102(defun main ()
10b8955c 103 (set-command-line-arguments)
9d6fbc71
MW
104 (let ((files nil))
105 (flet ((run ()
106 (dolist (f files)
107 (let ((*package* (make-package "ZONE.SCRATCH"
108 :use '(#:common-lisp
109 #:net #:zone))))
110 (load f :verbose nil :print nil :if-does-not-exist :error)
111 (delete-package *package*)))
112 (zone-save opt-zones :format opt-format)))
113 (with-unix-error-reporting ()
114 (unless (option-parse-try
115 (do-options ()
116 (nil (rest)
117 (when (zerop (length rest))
118 (option-parse-error "no files to read"))
119 (setf files rest))))
120 (die-usage)))
121 (if opt-debug
122 (run)
123 (with-unix-error-reporting () (run))))))
7e282fb5 124
125;;;----- That's all, folks --------------------------------------------------