This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

here-strings a la SCSH



yes, I know it's in guile-scsh.  to my defence, I wrote it, like, ten
minutes before it occured to me to check guile-scsh ;).

so here it is, maybe you will find it useful anyway.

benefits: you don't need guile-scsh for it, it's better optimized for
Guile, it's in public domain.  enjoy.

;;; here-strings.scm --- SCSH-like here-strings
;; -*- Scheme -*-
; Copyright (C) 1999 Michael Livshin
; This code is in public domain, do with it what you want.

(define-module (util here-strings))

(define (read-here-string c port)

  (define (assert-non-eof c)
    (if (eof-object? c)
        (error 'eof "end of file in here-string")))

  (with-input-from-port port
    (lambda ()
      (let ((d (read-char)))

        (if (char=? d #\<)

            (let ((delim (read-line)))
              (if (string=? "" delim)
                  (error 'empty-delimiter "empty here-string delimiter line"))
              (with-output-to-string
                (lambda ()
                  (let loop ((l (read-line)) (newline ""))
                    (assert-non-eof l)
                    (or (string=? l delim)
                        (begin
                          (display newline)
                          (display l)
                          (loop (read-line) #\newline)))))))

            (read-delimited (make-string 1 d)))))))

(read-hash-extend #\< read-here-string)

;;; here-strings.scm ends here


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]