224496bc58efca1dc3f15a7523f508860e6457e7
[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.5 2003/05/06 02:19:46 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
22 (defmacro with-umls-file ((line filename) &body body)
23 "Opens a UMLS and processes each parsed line with (body) argument"
24   (let ((ustream (gensym "STRM-"))
25         (eof (gensym "EOF-")))
26     `(let ((,eof (gensym "EOFSYM-")))
27       (with-open-file
28           (,ustream (umls-pathname ,filename) :direction :input)
29         (do ((,line (read-umls-line ,ustream ,eof)
30                     (read-umls-line ,ustream ,eof)))
31             ((eq ,line ,eof) t)
32           ,@body)))))
33
34 (defmacro with-buffered-umls-file ((line filename) &body body)
35   "Opens a UMLS and processes each parsed line with (body) argument"
36   (let ((ustream (gensym "STRM-"))
37         (buffer (gensym "BUF-"))
38         (eof (gensym "EOF-")))
39     `(let ((,buffer (make-fields-buffer))
40            (,eof (gensym "EOFSYM-")))
41       (with-open-file
42           (,ustream (umls-pathname ,filename) :direction :input)
43         (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof)
44                     (read-buffered-fields ,buffer ,ustream #\| ,eof)))
45             ((eq ,line ,eof) t)
46           ,@body)))))
47
48 (defmacro with-buffered2-umls-file ((line filename) &body body)
49   "Opens a UMLS and processes each parsed line with (body) argument"
50   (let ((ustream (gensym "STRM-"))
51         (buffer (gensym "BUF-"))
52         (eof (gensym "EOF-")))
53     `(let ((,buffer (make-fields-buffer2))
54            (,eof (gensym "EOFSYM-")))
55       (with-open-file
56           (,ustream (umls-pathname ,filename)
57            :direction :input :if-exists :overwrite)
58         (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof)
59                     (read-buffered-fields ,buffer ,ustream #\| ,eof)))
60             ((eq ,line ,eof) t)
61           ,@body)))))