Commit | Line | Data |
---|---|---|
7e282fb5 | 1 | ;;; -*-lisp-*- |
2 | ;;; | |
3 | ;;; $Id$ | |
4 | ;;; | |
5 | ;;; Zone generator frontend | |
6 | ;;; | |
7 | ;;; (c) 2005 Straylight/Edgeware | |
8 | ;;; | |
9 | ||
10 | ;;;----- Licensing notice --------------------------------------------------- | |
11 | ;;; | |
12 | ;;; This program is free software; you can redistribute it and/or modify | |
13 | ;;; it under the terms of the GNU General Public License as published by | |
14 | ;;; the Free Software Foundation; either version 2 of the License, or | |
15 | ;;; (at your option) any later version. | |
7fff3797 | 16 | ;;; |
7e282fb5 | 17 | ;;; This program is distributed in the hope that it will be useful, |
18 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;;; GNU General Public License for more details. | |
7fff3797 | 21 | ;;; |
7e282fb5 | 22 | ;;; You should have received a copy of the GNU General Public License |
23 | ;;; along with this program; if not, write to the Free Software Foundation, | |
24 | ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
25 | ||
26 | (defpackage #:zone.frontend | |
9c44003b | 27 | (:use #:common-lisp #:optparse #:net #:zone) |
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.") | |
7e282fb5 | 35 | |
122041a0 MW |
36 | (eval-when (:compile-toplevel :load-toplevel) |
37 | (defopthandler dir (var arg) () | |
38 | (let ((path (probe-file arg))) | |
39 | (if (and path | |
40 | (not (pathname-name path))) | |
41 | (setf var path) | |
42 | (option-parse-error "path `~A' doesn't name a directory." arg))))) | |
43 | ||
f41a8783 MW |
44 | (define-program |
45 | :version "1.0.0" :usage "ZONEDEF..." | |
46 | :help "Generates BIND zone files from Lisp descriptions." | |
884a01ff | 47 | :options (options help-options |
122041a0 MW |
48 | "Parsing options" |
49 | (#\f "feature" (:arg "KEYWORD") | |
50 | (list *features* 'keyword) | |
51 | "Insert KEYWORD in *features* list.") | |
52 | (#\s "subnet" (:arg "NET") | |
53 | (list zone:*preferred-subnets*) | |
54 | "Designate NET as a preferred subnet.") | |
f41a8783 | 55 | "Output options" |
122041a0 MW |
56 | (#\d "directory" (:arg "DIRECTORY") |
57 | (dir *zone-output-path*) | |
58 | "Write zone and serial files to DIRECTORY.") | |
a567a3bc MW |
59 | (#\F "format" (:arg "FORMAT") |
60 | (keyword opt-format | |
61 | (delete-duplicates | |
62 | (loop for method in | |
63 | (pcl:generic-function-methods | |
64 | #'zone:zone-write) | |
65 | for specs = | |
66 | (pcl:method-specializers method) | |
67 | if (typep (car specs) | |
68 | 'pcl:eql-specializer) | |
69 | collect | |
70 | (pcl:eql-specializer-object | |
71 | (car specs))))) | |
72 | "Format to use for output.") | |
f41a8783 MW |
73 | (#\z "zone" (:arg "NAME") (list opt-zones) |
74 | "Write information about zone NAME."))) | |
7e282fb5 | 75 | |
76 | (defun main () | |
77 | (with-unix-error-reporting () | |
ee983904 | 78 | (let ((files nil)) |
7e282fb5 | 79 | (unless (option-parse-try |
f41a8783 MW |
80 | (do-options () |
81 | (nil (rest) | |
82 | (when (zerop (length rest)) | |
83 | (option-parse-error "no files to read")) | |
84 | (setf files rest)))) | |
85 | (die-usage)) | |
7e282fb5 | 86 | (dolist (f files) |
ee983904 | 87 | (let ((*package* (make-package "ZONE.SCRATCH" |
9c44003b | 88 | :use '(#:common-lisp #:net #:zone)))) |
ee983904 MW |
89 | (load f :verbose nil :print nil :if-does-not-exist :error) |
90 | (delete-package *package*))) | |
a567a3bc | 91 | (zone-save opt-zones :format opt-format)))) |
7e282fb5 | 92 | |
93 | ;;;----- That's all, folks -------------------------------------------------- |