r4837: Auto commit for Debian build
[umlisp.git] / parse-macros.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          parse-macros.lisp
6 ;;;; Purpose:       Macros for UMLS file parsing
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2000
9 ;;;;
10 ;;;; $Id: parse-macros.lisp,v 1.6 2003/05/06 06:09:29 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UMLisp, is
13 ;;;;    Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D.
14 ;;;;
15 ;;;; UMLisp users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the GNU General Public License.
17 ;;;; *************************************************************************
18
19 (in-package #:umlisp)
20
21 (eval-when (:compile-toplevel)
22   (declaim (optimize (speed 3) (safety 1) (compilation-speed 0) (debug 3))))
23
24 (defmacro with-umls-file ((line filename) &body body)
25 "Opens a UMLS and processes each parsed line with (body) argument"
26   (let ((ustream (gensym "STRM-"))
27         (eof (gensym "EOF-")))
28     `(let ((,eof (gensym "EOFSYM-")))
29       (with-open-file
30           (,ustream (umls-pathname ,filename) :direction :input)
31         (do ((,line (read-umls-line ,ustream ,eof)
32                     (read-umls-line ,ustream ,eof)))
33             ((eq ,line ,eof) t)
34           ,@body)))))
35
36 (defmacro with-buffered-umls-file ((line filename) &body body)
37   "Opens a UMLS and processes each parsed line with (body) argument"
38   (let ((ustream (gensym "STRM-"))
39         (buffer (gensym "BUF-"))
40         (eof (gensym "EOF-")))
41     `(let ((,buffer (make-fields-buffer))
42            (,eof (gensym "EOFSYM-")))
43       (with-open-file
44           (,ustream (umls-pathname ,filename) :direction :input)
45         (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof)
46                     (read-buffered-fields ,buffer ,ustream #\| ,eof)))
47             ((eq ,line ,eof) t)
48           ,@body)))))
49
50 (defmacro with-buffered2-umls-file ((line filename) &body body)
51   "Opens a UMLS and processes each parsed line with (body) argument"
52   (let ((ustream (gensym "STRM-"))
53         (buffer (gensym "BUF-"))
54         (eof (gensym "EOF-")))
55     `(let ((,buffer (make-fields-buffer2))
56            (,eof (gensym "EOFSYM-")))
57       (with-open-file
58           (,ustream (umls-pathname ,filename)
59            :direction :input :if-exists :overwrite)
60         (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof)
61                     (read-buffered-fields ,buffer ,ustream #\| ,eof)))
62             ((eq ,line ,eof) t)
63           ,@body)))))