chiark / gitweb /
frontend: Use CLC rather than ASDF.
[zone] / frontend.lisp
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.
16 ;;; 
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.
21 ;;; 
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
27   (:use #:common-lisp #:mdw.optparse #:zone)
28   (:export #:main))
29 (in-package #:zone.frontend)
30
31 (defconstant version "1.0.0")
32
33 (defvar opt-zones nil
34   "Which zones to be emitted.")
35
36 (defvar options nil)
37 (defvar usage nil)
38 (defun help (arg)
39   (declare (ignore arg))
40   (show-help *program-name* version usage options)
41   (exit 0))
42 (defun version (arg)
43   (declare (ignore arg))
44   (format t "~A, version ~A~%" *program-name* version)
45   (exit 0))
46 (defun do-usage (&optional (stream *standard-output*))
47   (show-usage *program-name* usage stream))
48 (defun usage (arg)
49   (declare (ignore arg))
50   (do-usage)
51   (exit 0))
52 (setf options
53       (options
54        "Help options"
55        (#\h "help" #'help
56             "Show this help message.")
57        (#\v "version" #'version
58             ("Show the `~A' program's version number." *program-name*))
59        (#\u "usage" #'usage
60             ("Show a very brief usage summary for `~A'." *program-name*))
61
62        "Output options"
63        (#\z "zone" (:arg "NAME") (list opt-zones)
64             "Write information about zone NAME.")))
65 (setf usage (simple-usage options "ZONEDEF..."))
66
67 (defun main ()
68   (with-unix-error-reporting ()
69     (let ((seq 54)
70           (files nil)
71           (op (make-option-parser (cdr *command-line-strings*) options)))
72       (unless (option-parse-try
73                 (loop
74                    (multiple-value-bind (opt arg) (option-parse-next op)
75                      (declare (ignore arg))
76                      (unless opt
77                        (return))))
78                 (setf files (option-parse-remainder op))
79                 (when (zerop (length files))
80                   (option-parse-error "no files to read")))
81         (do-usage *error-output*)
82         (exit 1))
83       (dolist (f files)
84         (let ((*package* (make-package (format nil "zone.scratch-~A"
85                                                (incf seq))
86                                        :use '(#:common-lisp #:zone))))
87           (load f :verbose nil :print nil :if-does-not-exist :error)))
88       (zone-save opt-zones))))
89
90 ;;;----- That's all, folks --------------------------------------------------