guile-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

guile/guile-core/libguile ChangeLog ports.c por...


From: Mikael Djurfeldt
Subject: guile/guile-core/libguile ChangeLog ports.c por...
Date: Sun, 25 Feb 2001 19:06:58 -0800

CVSROOT:        /cvs
Module name:    guile
Changes by:     Mikael Djurfeldt <address@hidden>       01/02/25 19:06:57

Modified files:
        guile-core/libguile: ChangeLog ports.c ports.h 

Log message:
        ports.c, ports.h (scm_c_read, scm_c_write): New functions.
        
        ports.h (SCM_READ_BUFFER_EMPTY_P): New macro.

CVSWeb URLs:
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-core/libguile/ChangeLog.diff?r1=1.1283&r2=1.1284
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-core/libguile/ports.c.diff?r1=1.131&r2=1.132
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-core/libguile/ports.h.diff?r1=1.71&r2=1.72

Patches:
Index: guile/guile-core/libguile/ChangeLog
diff -u guile/guile-core/libguile/ChangeLog:1.1283 
guile/guile-core/libguile/ChangeLog:1.1284
--- guile/guile-core/libguile/ChangeLog:1.1283  Sat Feb 24 15:46:03 2001
+++ guile/guile-core/libguile/ChangeLog Sun Feb 25 19:06:57 2001
@@ -1,3 +1,9 @@
+2001-02-23  Mikael Djurfeldt  <address@hidden>
+
+       * ports.c, ports.h (scm_c_read, scm_c_write): New functions.
+
+       * ports.h (SCM_READ_BUFFER_EMPTY_P): New macro.
+
 2001-02-24  Neil Jerram  <address@hidden>
 
        * numbers.c (scm_two_doubles, scm_sys_expt, scm_sys_atan2,
Index: guile/guile-core/libguile/ports.c
diff -u guile/guile-core/libguile/ports.c:1.131 
guile/guile-core/libguile/ports.c:1.132
--- guile/guile-core/libguile/ports.c:1.131     Sat Feb 17 03:33:42 2001
+++ guile/guile-core/libguile/ports.c   Sun Feb 25 19:06:57 2001
@@ -1,4 +1,4 @@
-/*     Copyright (C) 1995,1996,1997,1998,1999, 2000 Free Software Foundation, 
Inc.
+/*     Copyright (C) 1995,1996,1997,1998,1999, 2000, 2001 Free Software 
Foundation, Inc.
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -963,6 +963,14 @@
   scm_lfwrite (s, strlen (s), port);
 }
 
+/* scm_lfwrite
+ *
+ * Currently, this function has an identical implementation to
+ * scm_c_write.  We could have turned it into a macro expanding into a
+ * call to scm_c_write.  However, the implementation is small and
+ * might differ in the future.
+ */
+
 void 
 scm_lfwrite (const char *ptr, scm_sizet size, SCM port)
 {
@@ -978,6 +986,81 @@
     pt->rw_active = SCM_PORT_WRITE;
 }
 
+/* scm_c_read
+ *
+ * Used by an application to read arbitrary number of bytes from an
+ * SCM port.  Same semantics as libc read, except that scm_c_read only
+ * returns less than SIZE bytes if at end-of-file.
+ *
+ * Warning: Doesn't update port line and column counts!  */
+
+scm_sizet
+scm_c_read (SCM port, void *buffer, scm_sizet size)
+{
+  scm_port *pt = SCM_PTAB_ENTRY (port);
+  scm_sizet n_read = 0, n_available;
+
+  if (pt->rw_active == SCM_PORT_WRITE)
+    scm_ptobs[SCM_PTOBNUM (port)].flush (port);
+
+  if (pt->rw_random)
+    pt->rw_active = SCM_PORT_READ;
+
+  if (SCM_READ_BUFFER_EMPTY_P (pt))
+    {
+      if (scm_fill_input (port) == EOF)
+       return 0;
+    }
+  
+  n_available = pt->read_end - pt->read_pos;
+  
+  while (n_available < size)
+    {
+      memcpy (buffer, pt->read_pos, n_available);
+      buffer += n_available;
+      pt->read_pos += n_available;
+      n_read += n_available;
+      
+      if (SCM_READ_BUFFER_EMPTY_P (pt))
+       {
+         if (scm_fill_input (port) == EOF)
+           return n_read;
+       }
+
+      size -= n_available;
+      n_available = pt->read_end - pt->read_pos;
+    }
+
+  memcpy (buffer, pt->read_pos, size);
+  pt->read_pos += size;
+
+  return n_read + size;
+}
+
+/* scm_c_write
+ *
+ * Used by an application to write arbitrary number of bytes to an SCM
+ * port.  Similar semantics as libc write.  However, unlike libc
+ * write, scm_c_write writes the requested number of bytes and has no
+ * return value.
+ *
+ * Warning: Doesn't update port line and column counts!
+ */
+
+void 
+scm_c_write (SCM port, const void *ptr, scm_sizet size)
+{
+  scm_port *pt = SCM_PTAB_ENTRY (port);
+  scm_ptob_descriptor *ptob = &scm_ptobs[SCM_PTOBNUM (port)];
+
+  if (pt->rw_active == SCM_PORT_READ)
+    scm_end_input (port);
+
+  ptob->write (port, ptr, size);
+
+  if (pt->rw_random)
+    pt->rw_active = SCM_PORT_WRITE;
+}
 
 void 
 scm_flush (SCM port)
@@ -1199,8 +1282,8 @@
 
   object = SCM_COERCE_OUTPORT (object);
 
-  off = SCM_NUM2LONG (2,offset);
-  SCM_VALIDATE_INUM_COPY (3,whence,how);
+  off = SCM_NUM2LONG (2, offset);
+  SCM_VALIDATE_INUM_COPY (3, whence, how);
   if (how != SEEK_SET && how != SEEK_CUR && how != SEEK_END)
     SCM_OUT_OF_RANGE (3, whence);
   if (SCM_OPPORTP (object))
Index: guile/guile-core/libguile/ports.h
diff -u guile/guile-core/libguile/ports.h:1.71 
guile/guile-core/libguile/ports.h:1.72
--- guile/guile-core/libguile/ports.h:1.71      Thu Jan 25 09:18:41 2001
+++ guile/guile-core/libguile/ports.h   Sun Feb 25 19:06:57 2001
@@ -2,7 +2,7 @@
 
 #ifndef PORTSH
 #define PORTSH
-/*     Copyright (C) 1995,1996,1997,1998,1999, 2000 Free Software Foundation, 
Inc.
+/*     Copyright (C) 1995,1996,1997,1998,1999, 2000, 2001 Free Software 
Foundation, Inc.
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -135,6 +135,7 @@
 extern scm_port **scm_port_table;
 extern int scm_port_table_size; /* Number of ports in scm_port_table.  */
 
+#define SCM_READ_BUFFER_EMPTY_P(c_port) (c_port->read_pos >= c_port->read_end)
 
 
 
@@ -279,6 +280,8 @@
 extern SCM scm_read_char (SCM port);
 extern void scm_putc (char c, SCM port);
 extern void scm_puts (const char *str_data, SCM port);
+extern scm_sizet scm_c_read (SCM port, void *buffer, scm_sizet size);
+extern void scm_c_write (SCM port, const void *buffer, scm_sizet size);
 extern void scm_lfwrite (const char *ptr, scm_sizet size, SCM port);
 extern void scm_flush (SCM port);
 extern void scm_end_input (SCM port);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]