cvsuser 03/10/09 18:38:57
Modified: io io.c io_buf.c
Log:
Add pioctl op and PIO_pioctl API call. General purpose op for IO manipulation
in tradition of UNIX ioctl call.
Also add record separator to IO object and allow changing from default \n.
Revision Changes Path
1.56 +36 -1 parrot/io/io.c
Index: io.c
===================================================================
RCS file: /cvs/public/parrot/io/io.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -w -r1.55 -r1.56
--- io.c 1 Oct 2003 16:43:54 -0000 1.55
+++ io.c 10 Oct 2003 01:38:57 -0000 1.56
@@ -1,7 +1,7 @@
/* io.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: io.c,v 1.55 2003/10/01 16:43:54 boemmels Exp $
+ * $Id: io.c,v 1.56 2003/10/10 01:38:57 mrjoltcola Exp $
* Overview:
* This is the Parrot IO subsystem API. Generic IO stuff
* goes here, each specific layer goes in its own file...
@@ -465,6 +465,41 @@
}
return flags;
+}
+
+/*
+ * General purpose interface for manipulation of IO objects and
+ * layer attributes.
+ *
+ * Refer to PIOCTL* values in io.h
+ *
+ * All "set" operations return 0 on success and a negative value on error.
+ * "get" operations will use the return value as the value requested, but
+ * should always be >= 0. A negative value indicates an error.
+ * This may be too limited but we will see. --Melvin
+ */
+INTVAL
+PIO_pioctl(theINTERP, PMC *pmc, INTVAL cmd, INTVAL arg)
+{
+
+ /* Temporary arbitrary negative return vals for debugging */
+ ParrotIO * io = PMC_data(pmc);
+ ParrotIOBuf * b = &io->b;
+ if(!io) return -1;
+
+ switch(cmd) {
+ case PIOCTL_CMDSETRECSEP: io->recsep = arg;
+ case PIOCTL_CMDGETRECSEP: return io->recsep;
+ case PIOCTL_CMDSETBUFTYPE: return -3; /* XXX FIXME */
+ case PIOCTL_CMDGETBUFTYPE: return -4; /* XXX FIXME */
+ case PIOCTL_CMDSETBUFSIZE: return -5; /* XXX FIXME */
+ case PIOCTL_CMDGETBUFSIZE:
+ if(b) return b->size;
+ else return -6;
+ default: return -100;
+ }
+
+ return 0;
}
1.13 +12 -3 parrot/io/io_buf.c
Index: io_buf.c
===================================================================
RCS file: /cvs/public/parrot/io/io_buf.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -r1.12 -r1.13
--- io_buf.c 5 Sep 2003 12:31:43 -0000 1.12
+++ io_buf.c 10 Oct 2003 01:38:57 -0000 1.13
@@ -1,7 +1,7 @@
/* io_buf.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: io_buf.c,v 1.12 2003/09/05 12:31:43 boemmels Exp $
+ * $Id: io_buf.c,v 1.13 2003/10/10 01:38:57 mrjoltcola Exp $
* Overview:
* The "buf" layer of Parrot IO. Buffering and all the fun stuff.
*
@@ -58,7 +58,12 @@
/* XXX: This is not portable */
-#define IS_EOL(c) ((*c) == '\n')
+#define DEFAULT_RECSEP '\n'
+#define IS_EOL(io,c) (io->recsep == (*c))
+/*
+#define IS_EOL(io,c) ((*c) == '\n')
+*/
+
static INTVAL
PIO_buf_init(theINTERP, ParrotIOLayer *layer)
@@ -88,7 +93,9 @@
/*
* We have an IO stream. Now setup stuff
* for our layer before returning it.
+ * XXX: Make default behaviour linebuffered?
*/
+ /*PIO_buf_setlinebuf(interpreter, l, io);*/
PIO_buf_setbuf(interpreter, l, io, PIO_UNBOUND);
return io;
}
@@ -152,6 +159,7 @@
/* Then switch to linebuf */
io->flags &= ~PIO_F_BLKBUF;
io->flags |= PIO_F_LINEBUF;
+ io->recsep = DEFAULT_RECSEP;
return 0;
}
return err;
@@ -343,8 +351,9 @@
buf_start = b->next;
while (l++ < len) {
- if (IS_EOL(b->next++))
+ if (IS_EOL(io, b->next++)) {
break;
+ }
/* buffer completed; copy out and refill */
if (b->next == b->endb) {
memcpy(out_buf, buf_start, b->endb - buf_start);