From 18aec29c5dfc267fbf1c457d563869adf34ced28 Mon Sep 17 00:00:00 2001 From: Didier Verna Date: Fri, 9 Mar 2012 20:26:06 +0100 Subject: [PATCH] Simplify termio module. ChangeLog entries: 2012-03-09 Didier Verna * termio/sbcl/util.lisp: Removed. * termio/clisp/util.lisp: Removed. * termio/termio.lisp (stream-line-width): Incorporate here. * com.dvlsoft.clon.asd (:com.dvlsoft.clon): Update accordingly. --- com.dvlsoft.clon.asd | 10 +++------- termio/clisp/util.lisp | 54 -------------------------------------------------- termio/sbcl/util.lisp | 47 ------------------------------------------- termio/termio.lisp | 37 +++++++++++++++++++++++++++------- 4 files changed, 33 insertions(+), 115 deletions(-) delete mode 100644 termio/clisp/util.lisp delete mode 100644 termio/sbcl/util.lisp diff --git a/com.dvlsoft.clon.asd b/com.dvlsoft.clon.asd index fd08d53..acd44ff 100644 --- a/com.dvlsoft.clon.asd +++ b/com.dvlsoft.clon.asd @@ -232,15 +232,11 @@ The most important features of Clon are: :components (#+sbcl (:module "sbcl" - :serial t - :components ((sb-grovel:grovel-constants-file - "constants" :package :com.dvlsoft.clon) - (:file "util"))) + :components ((sb-grovel:grovel-constants-file "constants" + :package :com.dvlsoft.clon))) #+clisp (:module "clisp" - :serial t - :components ((cffi-grovel:grovel-file "constants") - (:file "util"))) + :components ((cffi-grovel:grovel-file "constants"))) (:file "termio"))) (:module "src" :depends-on (#+com.dvlsoft.clon.termio "termio") diff --git a/termio/clisp/util.lisp b/termio/clisp/util.lisp deleted file mode 100644 index c048c49..0000000 --- a/termio/clisp/util.lisp +++ /dev/null @@ -1,54 +0,0 @@ -;;; util.lisp --- CLISP specific utilities - -;; Copyright (C) 2011 Didier Verna - -;; Author: Didier Verna -;; Maintainer: Didier Verna - -;; This file is part of Clon. - -;; Permission to use, copy, modify, and distribute this software for any -;; purpose with or without fee is hereby granted, provided that the above -;; copyright notice and this permission notice appear in all copies. - -;; THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - - -;;; Commentary: - - -;;; Code: - -(in-package :com.dvlsoft.clon) -(in-readtable :com.dvlsoft.clon) - - -(defun clisp/stream-line-width (stream) - "CLISP specific version of STREAM-LINE-WIDTH. -This function relies on CFFI." - (multiple-value-bind (input-fd output-fd) - (ext:stream-handles stream) - (declare (ignore input-fd)) - (when output-fd - (cffi:with-foreign-object (winsize 'winsize) - (let ((result (cffi:foreign-funcall "ioctl" - :int output-fd - :int +tiocgwinsz+ - :pointer winsize - :int))) - (if (= result -1) - (unless (= +errno+ +enotty+) - (values nil - (cffi:foreign-funcall "strerror" - :int +errno+ :string))) - (cffi:with-foreign-slots ((ws-col) winsize winsize) - ws-col))))))) - - -;;; util.lisp ends here diff --git a/termio/sbcl/util.lisp b/termio/sbcl/util.lisp deleted file mode 100644 index cd7a7c3..0000000 --- a/termio/sbcl/util.lisp +++ /dev/null @@ -1,47 +0,0 @@ -;;; util.lisp --- SBCL specific utilities - -;; Copyright (C) 2011 Didier Verna - -;; Author: Didier Verna -;; Maintainer: Didier Verna - -;; This file is part of Clon. - -;; Permission to use, copy, modify, and distribute this software for any -;; purpose with or without fee is hereby granted, provided that the above -;; copyright notice and this permission notice appear in all copies. - -;; THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - - -;;; Commentary: - - -;;; Code: - -(in-package :com.dvlsoft.clon) -(in-readtable :com.dvlsoft.clon) - - -(defun sbcl/stream-line-width (stream) - "SBCL specific version of STREAM-LINE-WIDTH. -This function relies on SB-GROVEL." - (declare (sb-ext:muffle-conditions sb-ext:compiler-note)) - (handler-case - (with-winsize winsize () - (sb-posix:ioctl (stream-file-stream stream :output) - +tiocgwinsz+ - winsize) - (winsize-ws-col winsize)) - (sb-posix:syscall-error (error) - (unless (= (sb-posix:syscall-errno error) sb-posix:enotty) - (values nil error))))) - - -;;; util.lisp ends here diff --git a/termio/termio.lisp b/termio/termio.lisp index 0d3993a..050a775 100644 --- a/termio/termio.lisp +++ b/termio/termio.lisp @@ -37,6 +37,7 @@ #include #include ") + ;; Thanks Nikodemus! (defgeneric stream-file-stream (stream &optional direction) (:documentation "Convert STREAM to a file-stream.") @@ -83,10 +84,8 @@ Return two values: @(return 1) = msg; }")) -;; #### NOTE: SBCL and CLISP have their specific, not "inlined" version of -;; this function elsewhere because they both use a separate ASDF module. The -;; SBCL one depends on SB-GROVEL and the CLISP one depends on CFFI. Also, ABCL -;; doesn't appear below because this module (termio) is never loaded with it. +;; #### NOTE: ABCL doesn't appear below because this module (termio) is never +;; loaded with it. (defun stream-line-width (stream) "Get STREAM's line width. Return two values: @@ -100,7 +99,16 @@ Return two values: ;; and the other which are real errors and need to be reported. ;; #### PORTME. #+sbcl - (sbcl/stream-line-width stream) + (locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note)) + (handler-case + (with-winsize winsize () + (sb-posix:ioctl (stream-file-stream stream :output) + +tiocgwinsz+ + winsize) + (winsize-ws-col winsize)) + (sb-posix:syscall-error (error) + (unless (= (sb-posix:syscall-errno error) sb-posix:enotty) + (values nil error))))) #+cmu (locally (declare (optimize (ext:inhibit-warnings 3))) (alien:with-alien ((winsize (alien:struct unix:winsize))) @@ -129,7 +137,22 @@ Return two values: (fd-line-width (ext:file-stream-fd stream)) (values (unless (= cols -1) cols) msg)) #+clisp - (clisp/stream-line-width stream)) - + (multiple-value-bind (input-fd output-fd) + (ext:stream-handles stream) + (declare (ignore input-fd)) + (when output-fd + (cffi:with-foreign-object (winsize 'winsize) + (let ((result (cffi:foreign-funcall "ioctl" + :int output-fd + :int +tiocgwinsz+ + :pointer winsize + :int))) + (if (= result -1) + (unless (= +errno+ +enotty+) + (values nil + (cffi:foreign-funcall "strerror" + :int +errno+ :string))) + (cffi:with-foreign-slots ((ws-col) winsize winsize) + ws-col))))))) ;;; termio.lisp ends here -- 2.11.4.GIT