Update domain name to kpe.io
[umlisp-orf.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 ;;;; Author:   Kevin M. Rosenberg
8 ;;;; Created:  Apr 2000
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of UMLisp, is
13 ;;;;    Copyright (c) 2000-2004 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-orf)
20
21 (defmacro with-umls-file ((line filename) &body body)
22 "Opens a UMLS and processes each parsed line with (body) argument"
23   (let ((ustream (gensym "STRM-"))
24         (eof (gensym "EOF-")))
25     `(let ((,eof (gensym "EOFSYM-")))
26       (with-open-file
27           (,ustream (umls-pathname ,filename) :direction :input)
28         (do ((,line (read-umls-line ,ustream ,eof)
29                     (read-umls-line ,ustream ,eof)))
30             ((eq ,line ,eof) t)
31           ,@body)))))
32
33 (defmacro with-buffered-umls-file ((line filename) &body body)
34   "Opens a UMLS and processes each parsed line with (body) argument"
35   (let ((ustream (gensym "STRM-"))
36         (buffer (gensym "BUF-"))
37         (eof (gensym "EOF-")))
38     `(let ((,buffer (make-fields-buffer))
39            (,eof (gensym "EOFSYM-")))
40       (with-open-file
41           (,ustream (umls-pathname ,filename) :direction :input)
42         (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof)
43                     (read-buffered-fields ,buffer ,ustream #\| ,eof)))
44             ((eq ,line ,eof) t)
45           ,@body)))))
46
47 (defmacro with-buffered2-umls-file ((line filename) &body body)
48   "Opens a UMLS and processes each parsed line with (body) argument"
49   (let ((ustream (gensym "STRM-"))
50         (buffer (gensym "BUF-"))
51         (eof (gensym "EOF-")))
52     `(let ((,buffer (make-fields-buffer2))
53            (,eof (gensym "EOFSYM-")))
54       (with-open-file
55           (,ustream (umls-pathname ,filename)
56            :direction :input :if-exists :overwrite)
57         (do ((,line (read-buffered-fields ,buffer ,ustream #\| ,eof)
58                     (read-buffered-fields ,buffer ,ustream #\| ,eof)))
59             ((eq ,line ,eof) t)
60           ,@body)))))