51 lines
1.7 KiB
Scheme
51 lines
1.7 KiB
Scheme
;;; Gash -- Guile As SHell
|
|
;;; Copyright © 2022 Timothy Sample <samplet@ngyro.com>
|
|
;;;
|
|
;;; This file is part of Gash.
|
|
;;;
|
|
;;; Gash is free software: you can redistribute it and/or modify
|
|
;;; it under the terms of the GNU General Public License as published by
|
|
;;; the Free Software Foundation, either version 3 of the License, or
|
|
;;; (at your option) any later version.
|
|
;;;
|
|
;;; Gash is distributed in the hope that it will be useful,
|
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;;; GNU General Public License for more details.
|
|
;;;
|
|
;;; You should have received a copy of the GNU General Public License
|
|
;;; along with Gash. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
(define-module (gash compat rdelim)
|
|
#:use-module (gash compat textual-ports))
|
|
|
|
;;; Commentary
|
|
;;;
|
|
;;; This module provides a shim for 'read-line' on Mes. We need this to
|
|
;;; make sure that 'read-line' is aware of our soft port shim.
|
|
;;;
|
|
;;; Code:
|
|
|
|
(cond-expand
|
|
(guile
|
|
(use-modules (ice-9 rdelim))
|
|
(re-export read-line))
|
|
(mes
|
|
(export read-line)
|
|
(define* (read-line #:optional (port (current-input-port))
|
|
(handle-delim 'trim))
|
|
(let loop ((acc '()))
|
|
(define c (get-char port))
|
|
(cond
|
|
((eof-object? c)
|
|
(if (null? acc) c (list->string (reverse! acc))))
|
|
((eq? c #\newline)
|
|
(case handle-delim
|
|
((trim) (list->string (reverse! acc)))
|
|
((concat) (list->string (reverse! (cons c acc))))
|
|
((peek) (begin (unget-char port c) (list->string (reverse! acc))))
|
|
((split) (cons (list->string (reverse! acc)) c))
|
|
(else (error "read-line: Invalid handle-delim" handle-delim))))
|
|
(else
|
|
(loop (cons c acc))))))))
|