blob: 1d463fd3fcdcf0178fb9eb5b420185e711bd5386 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(declaim (optimize (speed 0) (safety 3) (debug 3)))
(in-package #:dns-admin)
(defun compile-and-load (filename)
"Compiles and then loads a file. `filename' should not have an
extension, such as .fasl or .lisp."
(compile-file filename)
(load filename))
(defun file-to-list (infile)
"Reads `infile' and returns a list, where each atom is a single line
of the file. `infile' can be a string or a pathname object."
(let ((infile-list ()))
(with-open-file (filehandle infile :if-does-not-exist nil)
(if (streamp filehandle)
(progn
(loop for line = (read-line filehandle nil)
while line do
(push line infile-list))
(nreverse infile-list))
nil))))
(defmacro dofile ((line filename) &body body)
"Wrapper for the common task of opening a file and reading it one
line at a time."
(let ((stream (gensym)))
`(with-open-file (,stream ,filename)
(loop for ,line = (read-line ,stream nil nil)
while ,line do ,@body))))
|