summaryrefslogtreecommitdiff
path: root/lisp/file
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/file')
-rw-r--r--lisp/file/file-utils.lisp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lisp/file/file-utils.lisp b/lisp/file/file-utils.lisp
new file mode 100644
index 0000000..1d463fd
--- /dev/null
+++ b/lisp/file/file-utils.lisp
@@ -0,0 +1,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))))