From 36732f9134e539867b5d84f0010b2de922830b19 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Thu, 31 Dec 2009 13:40:23 +0900 Subject: [PATCH] is-a-tty? --- lib/chibi/filesystem.module | 2 +- lib/chibi/filesystem.stub | 3 +++ tools/genstubs.scm | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/chibi/filesystem.module b/lib/chibi/filesystem.module index 38a8fab1..f7fa4e99 100644 --- a/lib/chibi/filesystem.module +++ b/lib/chibi/filesystem.module @@ -20,7 +20,7 @@ open/read open/write open/read-write open/create open/exclusive open/truncate open/append open/non-block - ) + is-a-tty?) (import-immutable (scheme)) (include-shared "filesystem") (include "filesystem.scm")) diff --git a/lib/chibi/filesystem.stub b/lib/chibi/filesystem.stub index 8c42466f..5656fcdc 100644 --- a/lib/chibi/filesystem.stub +++ b/lib/chibi/filesystem.stub @@ -113,3 +113,6 @@ (define-c-const int (open/truncate "O_TRUNC")) (define-c-const int (open/append "O_APPEND")) (define-c-const int (open/non-block "O_NONBLOCK")) + +(define-c boolean (is-a-tty? "isatty") (port-or-fd)) + diff --git a/tools/genstubs.scm b/tools/genstubs.scm index 81b07acc..fc2c18e0 100755 --- a/tools/genstubs.scm +++ b/tools/genstubs.scm @@ -507,7 +507,10 @@ (cat "sexp_concat_env_string(" val ")")) ((string-type? base) (cat "sexp_string_data(" val ")")) - ((memq base '(port input-port output-port)) + ((eq? base 'port-or-fd) + (cat "(sexp_portp(" val ") ? fileno(sexp_port_stream(" val "))" + " : sexp_unbox_fixnum(" val "))")) + ((port-type? base) (cat "sexp_port_stream(" val ")")) (else (let ((ctype (assq base *types*))) @@ -607,6 +610,9 @@ (cat " if (! sexp_nullp(res))\n" " return sexp_type_exception(ctx, \"not a list of " (type-name type) "s\", " arg ");\n"))) + ((eq? base-type 'port-or-fd) + (cat "if (! (sexp_portp(" arg ") || sexp_fixnump(" arg ")))\n" + " return sexp_type_exception(ctx, \"not a port of file descriptor\"," arg ");\n")) ((or (int-type? base-type) (float-type? base-type) (string-type? base-type)