Author: iratqq
Date: Fri Feb 13 00:20:22 2009
New Revision: 5843

Added:
   trunk/scm/fileio.scm
   trunk/uim/fileio.c
Modified:
   trunk/scm/Makefile.am
   trunk/scm/posix.scm
   trunk/scm/socket.scm
   trunk/uim/Makefile.am
   trunk/uim/uim-posix.c

Log:
* uim/Makefile.am:
  - Add libuim-fileio.
* uim/uim-posix.c (uim_init_posix_subrs):
  - Remove fileio functions.
* uim/fileio.c:
  - New file.
* scm/Makefile.am (SCM_FILES):
  - Add fileio.scm.
* scm/posix.scm:
  - Remove fileio functions.
* scm/fileio.scm:
  - New file.
* scm/socket.scm:
  - Load "fileio.scm".

  Move fileio functions to module.
  Most modules don't need these functions.


Modified: trunk/scm/Makefile.am
==============================================================================
--- trunk/scm/Makefile.am       (original)
+++ trunk/scm/Makefile.am       Fri Feb 13 00:20:22 2009
@@ -43,7 +43,7 @@
  ajax-ime.scm ajax-ime-custom.scm ajax-ime-key-custom.scm \
  yahoo-jp.scm yahoo-jp-custom.scm yahoo-jp-key-custom.scm \
  uim-module-manager.scm \
- posix.scm socket.scm http-client.scm \
+ posix.scm fileio.scm socket.scm http-client.scm \
  input-parse.scm match.scm

 ETAGS_ARGS=$(SCM_FILES) $(GENERATED_SCM_FILES)

Added: trunk/scm/fileio.scm
==============================================================================
--- (empty file)
+++ trunk/scm/fileio.scm        Fri Feb 13 00:20:22 2009
@@ -0,0 +1,108 @@
+;;; fileio.scm: low-level file IO functions for uim.
+;;;
+;;; Copyright (c) 2009 uim Project http://code.google.com/p/uim/
+;;;
+;;; All rights reserved.
+;;;
+;;; Redistribution and use in source and binary forms, with or without
+;;; modification, are permitted provided that the following conditions
+;;; are met:
+;;; 1. Redistributions of source code must retain the above copyright
+;;;    notice, this list of conditions and the following disclaimer.
+;;; 2. Redistributions in binary form must reproduce the above copyright
+;;;    notice, this list of conditions and the following disclaimer in the
+;;;    documentation and/or other materials provided with the distribution.
+;;; 3. Neither the name of authors nor the names of its contributors
+;;; may be used to endorse or promote products derived from this software
+;;;    without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE +;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+;;; SUCH DAMAGE.
+;;;;
+
+(require-extension (srfi 9))
+(and (not (provided? "fileio"))
+     (module-load "fileio")
+     (provide "fileio"))
+
+(define file-bufsiz 16384)
+
+(define open-flags-alist (file-open-flags?))
+(define open-mode-alist (file-open-mode?))
+(define poll-flags-alist (file-poll-flags?))
+
+(define (string->file-buf str)
+  (map char->integer (string->list str)))
+(define (file-buf->string buf)
+  (list->string (map integer->char buf)))
+(define (file-read-string s len)
+    (file-buf->string (file-read s len)))
+(define (file-write-string s str)
+  (file-write s (string->file-buf str)))
+
+(define-record-type file-port
+  (make-file-port fd inbufsiz inbuf) file-port?
+  (fd       fd?       fd!)
+  (inbufsiz inbufsiz? inbufsiz!)
+  (inbuf    inbuf?    inbuf!))
+
+(define (open-file-port fd)
+  (make-file-port fd file-bufsiz '()))
+
+(define (call-with-open-file-port fd thunk)
+  (and (< 0 fd)
+       (let ((ret (thunk (open-file-port fd))))
+         (file-close fd)
+         ret)))
+
+(define (file-read-char port)
+  (if (null? (inbuf? port))
+      (inbuf! port (file-read (fd? port) (inbufsiz? port))))
+  (if (null? (inbuf? port))
+      #f
+      (let ((c (car (inbuf? port))))
+        (inbuf! port (cdr (inbuf? port)))
+        (integer->char c))))
+
+(define (file-peek-char port)
+  (if (null? (inbuf? port))
+      (inbuf! port (file-read (fd? port) (inbufsiz? port))))
+  (if (null? (inbuf? port))
+      #f
+      (let ((c (car (inbuf? port))))
+        (integer->char c))))
+
+(define (file-display str port)
+  (file-write (fd? port) (string->file-buf str)))
+
+(define (file-newline str port)
+  (file-write (fd? port) '(#\newline)))
+
+(define (file-read-line port)
+  (let loop ((c (file-read-char port))
+             (rest '()))
+    (cond ((eq? #\newline c)
+           (list->string (reverse rest)))
+          ((eq? #f c)
+           #f)
+          (else
+           (loop (file-read-char port) (cons c rest))))))
+
+(define (file-read-buffer port len)
+  (list->string (map (lambda (i) (file-read-char port)) (iota len))))
+
+(define (file-get-buffer port)
+  (file-buf->string (inbuf? port)))
+
+(define (duplicate-fileno oldd . args)
+  (let-optionals* args ((newd #f))
+     (duplicate2-fileno oldd newd)))

Modified: trunk/scm/posix.scm
==============================================================================
--- trunk/scm/posix.scm (original)
+++ trunk/scm/posix.scm Fri Feb 13 00:20:22 2009
@@ -29,77 +29,6 @@
 ;;; SUCH DAMAGE.
 ;;;;

-(require-extension (srfi 9))
-
-(define file-bufsiz 16384)
-
-(define (string->file-buf str)
-  (map char->integer (string->list str)))
-(define (file-buf->string buf)
-  (list->string (map integer->char buf)))
-(define (file-read-string s len)
-    (file-buf->string (file-read s len)))
-(define (file-write-string s str)
-  (file-write s (string->file-buf str)))
-
-(define-record-type file-port
-  (make-file-port fd inbufsiz inbuf) file-port?
-  (fd       fd?       fd!)
-  (inbufsiz inbufsiz? inbufsiz!)
-  (inbuf    inbuf?    inbuf!))
-
-(define (open-file-port fd)
-  (make-file-port fd file-bufsiz '()))
-
-(define (call-with-open-file-port fd thunk)
-  (and (< 0 fd)
-       (let ((ret (thunk (open-file-port fd))))
-         (file-close fd)
-         ret)))
-
-(define (file-read-char port)
-  (if (null? (inbuf? port))
-      (inbuf! port (file-read (fd? port) (inbufsiz? port))))
-  (if (null? (inbuf? port))
-      #f
-      (let ((c (car (inbuf? port))))
-        (inbuf! port (cdr (inbuf? port)))
-        (integer->char c))))
-
-(define (file-peek-char port)
-  (if (null? (inbuf? port))
-      (inbuf! port (file-read (fd? port) (inbufsiz? port))))
-  (if (null? (inbuf? port))
-      #f
-      (let ((c (car (inbuf? port))))
-        (integer->char c))))
-
-(define (file-display str port)
-  (file-write (fd? port) (string->file-buf str)))
-
-(define (file-newline str port)
-  (file-write (fd? port) '(#\newline)))
-
-(define (file-read-line port)
-  (let loop ((c (file-read-char port))
-             (rest '()))
-    (cond ((eq? #\newline c)
-           (list->string (reverse rest)))
-          ((eq? #f c)
-           #f)
-          (else
-           (loop (file-read-char port) (cons c rest))))))
-
-(define (file-read-buffer port len)
-  (list->string (map (lambda (i) (file-read-char port)) (iota len))))
-
-(define (file-get-buffer port)
-  (file-buf->string (inbuf? port)))
-
-(define (duplicate-fileno oldd . args)
-  (let-optionals* args ((newd #f))
-     (duplicate2-fileno oldd newd)))
-
 (define (process-execute file . args)
   (let-optionals* args ((argv (list file))
                         (envp #f))

Modified: trunk/scm/socket.scm
==============================================================================
--- trunk/scm/socket.scm        (original)
+++ trunk/scm/socket.scm        Fri Feb 13 00:20:22 2009
@@ -31,6 +31,7 @@

 (require-extension (srfi 1 2 9))
 (use util)
+(require "fileio.scm")
 (module-load "socket")

 (define addrinfo-ai-flags-alist (addrinfo-ai-flags-alist?))

Modified: trunk/uim/Makefile.am
==============================================================================
--- trunk/uim/Makefile.am       (original)
+++ trunk/uim/Makefile.am       Fri Feb 13 00:20:22 2009
@@ -53,6 +53,12 @@
                gettext.h intl.c \
                rk.c

+uim_plugin_LTLIBRARIES += libuim-fileio.la
+libuim_fileio_la_SOURCES = fileio.c
+libuim_fileio_la_LIBADD = libuim-scm.la libuim.la
+libuim_fileio_la_LDFLAGS = -rpath $(uim_plugindir) -avoid-version -module
+libuim_fileio_la_CPPFLAGS = -I$(top_srcdir)
+
 uim_plugin_LTLIBRARIES += libuim-socket.la
 libuim_socket_la_SOURCES = socket.c
 libuim_socket_la_LIBADD = libuim-scm.la libuim.la

Added: trunk/uim/fileio.c
==============================================================================
--- (empty file)
+++ trunk/uim/fileio.c  Fri Feb 13 00:20:22 2009
@@ -0,0 +1,346 @@
+/*
+
+  Copyright (c) 2009 uim Project http://code.google.com/p/uim/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+
+*/
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <errno.h>
+
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#elif defined(HAVE_SYS_POLL_H)
+#include <sys/poll.h>
+#else
+#include "bsd-poll.h"
+#endif
+
+#include "uim.h"
+#include "uim-internal.h"
+#include "uim-scm.h"
+#include "uim-scm-abbrev.h"
+#include "uim-posix.h"
+#include "uim-notify.h"
+#include "gettext.h"
+#include "dynlib.h"
+
+typedef struct {
+  int flag;
+  char *arg;
+} opt_args;
+
+static uim_lisp
+make_arg_list(const opt_args *list)
+{
+  uim_lisp ret_;
+  int i = 0;
+
+  ret_ = uim_scm_null();
+  while (list[i].arg != 0) {
+    ret_ = CONS(CONS(MAKE_SYM(list[i].arg), MAKE_INT(list[i].flag)), ret_);
+    i++;
+  }
+  return ret_;
+}
+
+const static opt_args open_flags[] = {
+  { O_RDONLY,   "$O_RDONLY" },
+  { O_WRONLY,   "$O_WRONLY" },
+  { O_RDWR,     "$O_RDWR" },
+
+#ifdef O_NONBLOCK
+  { O_NONBLOCK, "$O_NONBLOCK" },
+#endif
+#ifdef O_APPEND
+  { O_APPEND,   "$O_APPEND" },
+#endif
+
+#ifdef O_SHLOCK
+  { O_SHLOCK,   "$O_SHLOCK" },
+#endif
+#ifdef O_EXLOCK
+  { O_EXLOCK,   "$O_EXLOCK" },
+#endif
+
+#ifdef O_NOFOLLOW
+  { O_NOFOLLOW, "$O_NOFOLLOW" },
+#endif
+
+#ifdef O_SYNC
+  { O_SYNC,     "$O_SYNC" },
+#endif
+
+  { O_CREAT,    "$O_CREAT" },
+  { O_TRUNC,    "$O_TRUNC" },
+  { O_EXCL,     "$O_EXCL" },
+
+  { 0, 0 }
+};
+
+const static opt_args open_mode[] = {
+  { S_IRWXU, "$S_IRWXU" },
+  { S_IRUSR, "$S_IRUSR" },
+  { S_IWUSR, "$S_IWUSR" },
+  { S_IXUSR, "$S_IXUSR" },
+
+  { S_IRWXG, "$S_IRWXG" },
+  { S_IRGRP, "$S_IRGRP" },
+  { S_IWGRP, "$S_IWGRP" },
+  { S_IXGRP, "$S_IXGRP" },
+
+  { S_IRWXO, "$S_IRWXO" },
+  { S_IROTH, "$S_IROTH" },
+  { S_IWOTH, "$S_IWOTH" },
+  { S_IXOTH, "$S_IXOTH" },
+  { 0, 0 }
+};
+
+
+static uim_lisp uim_lisp_open_flags;
+static uim_lisp
+c_file_open_flags(void)
+{
+  return uim_lisp_open_flags;
+}
+
+static uim_lisp uim_lisp_open_mode;
+static uim_lisp
+c_file_open_mode(void)
+{
+  return uim_lisp_open_mode;
+}
+
+static uim_lisp
+c_file_open(uim_lisp path_, uim_lisp flags_, uim_lisp mode_)
+{
+  return MAKE_INT(open(REFER_C_STR(path_), C_INT(flags_), C_INT(mode_)));
+}
+
+static uim_lisp
+c_file_close(uim_lisp fd_)
+{
+  return MAKE_INT(close(C_INT(fd_)));
+}
+
+static uim_lisp
+c_file_read(uim_lisp d_, uim_lisp nbytes_)
+{
+  char *buf;
+  uim_lisp ret_;
+  int nbytes = C_INT(nbytes_);
+  int i;
+  int nr;
+  char *p;
+
+  buf = uim_malloc(nbytes);
+  if ((nr = read(C_INT(d_), buf, nbytes)) == -1) {
+    char err[BUFSIZ];
+
+    snprintf(err, sizeof(err), "file-read: %s", strerror(errno));
+    uim_notify_fatal(err);
+    ERROR_OBJ(err, d_);
+  }
+
+  p = buf;
+  ret_ = uim_scm_null();
+  for (i = 0; i < nr; i++) {
+    ret_ = CONS(MAKE_INT(*p & 0xff), ret_);
+    p++;
+  }
+  free(buf);
+  return uim_scm_callf("reverse", "o", ret_);
+}
+
+static uim_lisp
+c_file_write(uim_lisp d_, uim_lisp buf_)
+{
+  int nbytes = uim_scm_length(buf_);
+  uim_lisp ret_;
+  char *buf;
+  char *p;
+
+  buf = p = uim_malloc(nbytes);
+  while (!NULLP(buf_)) {
+    *p = (char)C_INT(CAR(buf_));
+    p++;
+    buf_ = CDR(buf_);
+  }
+  ret_ = MAKE_INT((int)write(C_INT(d_), buf, nbytes));
+  free(buf);
+  return ret_;
+}
+
+static uim_lisp
+c_duplicate2_fileno(uim_lisp oldd_, uim_lisp newd_)
+{
+  if (FALSEP(newd_))
+    return MAKE_INT(dup(C_INT(oldd_)));
+  return MAKE_INT(dup2(C_INT(oldd_), C_INT(newd_)));
+}
+
+const static opt_args poll_flags[] = {
+  { POLLIN,     "$POLLIN" },
+#ifdef POLLPRI
+  { POLLPRI,    "$POLLPRI" },
+#endif
+  { POLLOUT,    "$POLLOUT" },
+  { POLLERR,    "$POLLERR" },
+#ifdef POLLHUP
+  { POLLHUP,    "$POLLHUP"},
+#endif
+#ifdef POLLNVAL
+  { POLLNVAL,   "$POLLNVAL"},
+#endif
+#ifdef POLLRDNORM
+  { POLLRDNORM, "$POLLRDNORM"},
+#endif
+#ifdef POLLNORM
+  { POLLNORM,   "$POLLNORM"},
+#endif
+#ifdef POLLWRNORM
+  { POLLWRNORM, "$POLLWRNORM"},
+#endif
+#ifdef POLLRDBAND
+  { POLLRDBAND, "$POLLRDBAND"},
+#endif
+#ifdef POLLWRBAND
+  { POLLWRBAND, "$POLLWRBAND"},
+#endif
+  { 0, 0 }
+};
+
+static uim_lisp uim_lisp_poll_flags;
+static uim_lisp
+c_file_poll_flags(void)
+{
+  return uim_lisp_poll_flags;
+}
+
+static uim_lisp
+c_file_poll(uim_lisp fds_, uim_lisp timeout_)
+{
+  struct pollfd *fds;
+  int timeout = C_INT(timeout_);
+  int nfds = uim_scm_length(fds_);
+  uim_lisp fd_ = uim_scm_f();
+  int i;
+  int ret;
+  uim_lisp ret_;
+
+  fds = uim_calloc(nfds, sizeof(struct pollfd));
+
+  for (i = 0; i < nfds; i++) {
+    fd_ = CAR(fds_);
+    fds[i].fd = C_INT(CAR(fd_));
+    fds[i].events = C_INT(CDR(fd_));
+    fds_ = CDR(fds_);
+  }
+
+  ret = poll(fds, nfds, timeout);
+  if (ret == -1)
+    return uim_scm_f();
+  else if (ret == 0)
+    return uim_scm_null();
+
+  ret_ = uim_scm_null();
+  for (i = 0; i < ret; i++)
+    ret_ = CONS(CONS(MAKE_INT(fds[i].fd), MAKE_INT(fds[i].revents)), ret_);
+  free(fds);
+  return uim_scm_callf("reverse", "o", ret_);
+}
+
+static uim_lisp
+c_file_ready(uim_lisp fd_)
+{
+  struct pollfd pfd;
+  int ndfs;
+
+  pfd.fd = C_INT(fd_);
+  pfd.events = POLLIN;
+  ndfs = poll(&pfd, 1, 0);
+
+  if (ndfs < 0) {
+    return uim_scm_f();
+  } else if (ndfs == 0)
+    return uim_scm_f();
+  else
+    return uim_scm_t();
+}
+
+static uim_lisp
+c_create_pipe(void)
+{
+  int fildes[2];
+
+  if (pipe(fildes) == -1)
+    return uim_scm_f();
+  return CONS(MAKE_INT(fildes[0]), MAKE_INT(fildes[1]));
+}
+
+void
+uim_plugin_instance_init(void)
+{
+  uim_scm_init_proc3("file-open", c_file_open);
+  uim_scm_init_proc0("file-open-flags?", c_file_open_flags);
+  uim_scm_init_proc0("file-open-mode?", c_file_open_mode);
+  uim_scm_gc_protect(&uim_lisp_open_flags);
+  uim_scm_gc_protect(&uim_lisp_open_mode);
+  uim_lisp_open_flags = make_arg_list(open_flags);
+  uim_lisp_open_mode = make_arg_list(open_mode);
+
+  uim_scm_init_proc1("file-close", c_file_close);
+  uim_scm_init_proc2("file-read", c_file_read);
+  uim_scm_init_proc2("file-write", c_file_write);
+  uim_scm_init_proc2("duplicate2-fileno", c_duplicate2_fileno);
+
+  uim_scm_init_proc2("file-poll", c_file_poll);
+  uim_scm_init_proc0("file-poll-flags?", c_file_poll_flags);
+  uim_scm_gc_protect(&uim_lisp_poll_flags);
+  uim_lisp_poll_flags = make_arg_list(poll_flags);
+
+  uim_scm_init_proc1("file-ready?", c_file_ready);
+
+  uim_scm_init_proc0("create-pipe", c_create_pipe);
+}
+
+void
+uim_plugin_instance_quit(void)
+{
+}

Modified: trunk/uim/uim-posix.c
==============================================================================
--- trunk/uim/uim-posix.c       (original)
+++ trunk/uim/uim-posix.c       Fri Feb 13 00:20:22 2009
@@ -47,14 +47,6 @@
 #include <assert.h>
 #include <fcntl.h>

-#ifdef HAVE_POLL_H
-#include <poll.h>
-#elif defined(HAVE_SYS_POLL_H)
-#include <sys/poll.h>
-#else
-#include "bsd-poll.h"
-#endif
-
 #include "uim.h"
 #include "uim-internal.h"
 #include "uim-scm.h"
@@ -62,6 +54,7 @@
 #include "uim-posix.h"
 #include "uim-notify.h"
 #include "gettext.h"
+#include "dynlib.h"

 uim_bool
 uim_get_user_name(char *name, int len, int uid)
@@ -405,240 +398,6 @@
   return ret_;
 }

-const static opt_args open_flags[] = {
-  { O_RDONLY,   "$O_RDONLY" },
-  { O_WRONLY,   "$O_WRONLY" },
-  { O_RDWR,     "$O_RDWR" },
-
-#ifdef O_NONBLOCK
-  { O_NONBLOCK, "$O_NONBLOCK" },
-#endif
-#ifdef O_APPEND
-  { O_APPEND,   "$O_APPEND" },
-#endif
-
-#ifdef O_SHLOCK
-  { O_SHLOCK,   "$O_SHLOCK" },
-#endif
-#ifdef O_EXLOCK
-  { O_EXLOCK,   "$O_EXLOCK" },
-#endif
-
-#ifdef O_NOFOLLOW
-  { O_NOFOLLOW, "$O_NOFOLLOW" },
-#endif
-
-#ifdef O_SYNC
-  { O_SYNC,     "$O_SYNC" },
-#endif
-
-  { O_CREAT,    "$O_CREAT" },
-  { O_TRUNC,    "$O_TRUNC" },
-  { O_EXCL,     "$O_EXCL" },
-
-  { 0, 0 }
-};
-
-const static opt_args open_mode[] = {
-  { S_IRWXU, "$S_IRWXU" },
-  { S_IRUSR, "$S_IRUSR" },
-  { S_IWUSR, "$S_IWUSR" },
-  { S_IXUSR, "$S_IXUSR" },
-
-  { S_IRWXG, "$S_IRWXG" },
-  { S_IRGRP, "$S_IRGRP" },
-  { S_IWGRP, "$S_IWGRP" },
-  { S_IXGRP, "$S_IXGRP" },
-
-  { S_IRWXO, "$S_IRWXO" },
-  { S_IROTH, "$S_IROTH" },
-  { S_IWOTH, "$S_IWOTH" },
-  { S_IXOTH, "$S_IXOTH" },
-  { 0, 0 }
-};
-
-
-static uim_lisp uim_lisp_open_flags;
-static uim_lisp
-c_file_open_flags(void)
-{
-  return uim_lisp_open_flags;
-}
-
-static uim_lisp uim_lisp_open_mode;
-static uim_lisp
-c_file_open_mode(void)
-{
-  return uim_lisp_open_mode;
-}
-
-static uim_lisp
-c_file_open(uim_lisp path_, uim_lisp flags_, uim_lisp mode_)
-{
-  return MAKE_INT(open(REFER_C_STR(path_), C_INT(flags_), C_INT(mode_)));
-}
-
-static uim_lisp
-c_file_close(uim_lisp fd_)
-{
-  return MAKE_INT(close(C_INT(fd_)));
-}
-
-static uim_lisp
-c_file_read(uim_lisp d_, uim_lisp nbytes_)
-{
-  char *buf;
-  uim_lisp ret_;
-  int nbytes = C_INT(nbytes_);
-  int i;
-  int nr;
-  char *p;
-
-  buf = uim_malloc(nbytes);
-  if ((nr = read(C_INT(d_), buf, nbytes)) == -1) {
-    char err[BUFSIZ];
-
-    snprintf(err, sizeof(err), "file-read: %s", strerror(errno));
-    uim_notify_fatal(err);
-    ERROR_OBJ(err, d_);
-  }
-
-  p = buf;
-  ret_ = uim_scm_null();
-  for (i = 0; i < nr; i++) {
-    ret_ = CONS(MAKE_INT(*p & 0xff), ret_);
-    p++;
-  }
-  free(buf);
-  return uim_scm_callf("reverse", "o", ret_);
-}
-
-static uim_lisp
-c_file_write(uim_lisp d_, uim_lisp buf_)
-{
-  int nbytes = uim_scm_length(buf_);
-  uim_lisp ret_;
-  char *buf;
-  char *p;
-
-  buf = p = uim_malloc(nbytes);
-  while (!NULLP(buf_)) {
-    *p = (char)C_INT(CAR(buf_));
-    p++;
-    buf_ = CDR(buf_);
-  }
-  ret_ = MAKE_INT((int)write(C_INT(d_), buf, nbytes));
-  free(buf);
-  return ret_;
-}
-
-static uim_lisp
-c_duplicate2_fileno(uim_lisp oldd_, uim_lisp newd_)
-{
-  if (FALSEP(newd_))
-    return MAKE_INT(dup(C_INT(oldd_)));
-  return MAKE_INT(dup2(C_INT(oldd_), C_INT(newd_)));
-}
-
-const static opt_args poll_flags[] = {
-  { POLLIN,     "$POLLIN" },
-#ifdef POLLPRI
-  { POLLPRI,    "$POLLPRI" },
-#endif
-  { POLLOUT,    "$POLLOUT" },
-  { POLLERR,    "$POLLERR" },
-#ifdef POLLHUP
-  { POLLHUP,    "$POLLHUP"},
-#endif
-#ifdef POLLNVAL
-  { POLLNVAL,   "$POLLNVAL"},
-#endif
-#ifdef POLLRDNORM
-  { POLLRDNORM, "$POLLRDNORM"},
-#endif
-#ifdef POLLNORM
-  { POLLNORM,   "$POLLNORM"},
-#endif
-#ifdef POLLWRNORM
-  { POLLWRNORM, "$POLLWRNORM"},
-#endif
-#ifdef POLLRDBAND
-  { POLLRDBAND, "$POLLRDBAND"},
-#endif
-#ifdef POLLWRBAND
-  { POLLWRBAND, "$POLLWRBAND"},
-#endif
-  { 0, 0 }
-};
-
-static uim_lisp uim_lisp_poll_flags;
-static uim_lisp
-c_file_poll_flags(void)
-{
-  return uim_lisp_poll_flags;
-}
-
-static uim_lisp
-c_file_poll(uim_lisp fds_, uim_lisp timeout_)
-{
-  struct pollfd *fds;
-  int timeout = C_INT(timeout_);
-  int nfds = uim_scm_length(fds_);
-  uim_lisp fd_ = uim_scm_f();
-  int i;
-  int ret;
-  uim_lisp ret_;
-
-  fds = uim_calloc(nfds, sizeof(struct pollfd));
-
-  for (i = 0; i < nfds; i++) {
-    fd_ = CAR(fds_);
-    fds[i].fd = C_INT(CAR(fd_));
-    fds[i].events = C_INT(CDR(fd_));
-    fds_ = CDR(fds_);
-  }
-
-  ret = poll(fds, nfds, timeout);
-  if (ret == -1)
-    return uim_scm_f();
-  else if (ret == 0)
-    return uim_scm_null();
-
-  ret_ = uim_scm_null();
-  for (i = 0; i < ret; i++)
-    ret_ = CONS(CONS(MAKE_INT(fds[i].fd), MAKE_INT(fds[i].revents)), ret_);
-  free(fds);
-  return uim_scm_callf("reverse", "o", ret_);
-}
-
-static uim_lisp
-c_file_ready(uim_lisp fd_)
-{
-  struct pollfd pfd;
-  int ndfs;
-
-  pfd.fd = C_INT(fd_);
-  pfd.events = POLLIN;
-  ndfs = poll(&pfd, 1, 0);
-
-  if (ndfs < 0) {
-    return uim_scm_f();
-  } else if (ndfs == 0)
-    return uim_scm_f();
-  else
-    return uim_scm_t();
-}
-
-static uim_lisp
-c_create_pipe(void)
-{
-  int fildes[2];
-
-  if (pipe(fildes) == -1)
-    return uim_scm_f();
-  return CONS(MAKE_INT(fildes[0]), MAKE_INT(fildes[1]));
-}
-
 static uim_lisp
 c_current_process_id(void)
 {
@@ -816,31 +575,6 @@
   uim_scm_init_proc2("difftime", c_difftime);

   uim_scm_init_proc1("sleep", c_sleep);
-
-  uim_scm_init_proc3("file-open", c_file_open);
-  uim_scm_init_proc0("file-open-flags?", c_file_open_flags);
-  uim_scm_init_proc0("file-open-mode?", c_file_open_mode);
-  uim_scm_gc_protect(&uim_lisp_open_flags);
-  uim_scm_gc_protect(&uim_lisp_open_mode);
-  uim_lisp_open_flags = make_arg_list(open_flags);
-  uim_lisp_open_mode = make_arg_list(open_mode);
-  uim_scm_eval_c_string("(define open-flags-alist (file-open-flags?))");
-  uim_scm_eval_c_string("(define open-mode-alist (file-open-mode?))");
-
-  uim_scm_init_proc1("file-close", c_file_close);
-  uim_scm_init_proc2("file-read", c_file_read);
-  uim_scm_init_proc2("file-write", c_file_write);
-  uim_scm_init_proc2("duplicate2-fileno", c_duplicate2_fileno);
-
-  uim_scm_init_proc2("file-poll", c_file_poll);
-  uim_scm_init_proc0("file-poll-flags?", c_file_poll_flags);
-  uim_scm_gc_protect(&uim_lisp_poll_flags);
-  uim_lisp_poll_flags = make_arg_list(poll_flags);
-  uim_scm_eval_c_string("(define poll-flags-alist (file-poll-flags?))");
-
-  uim_scm_init_proc1("file-ready?", c_file_ready);
-
-  uim_scm_init_proc0("create-pipe", c_create_pipe);

   uim_scm_init_proc0("current-process-id", c_current_process_id);
   uim_scm_init_proc0("parent-process-id",  c_parent_process_id);

Reply via email to