Browse Source

zio should not care about how a user creates a FILE (pipe, socket, popen,
etc).

Roberto Ierusalimschy 28 years ago
parent
commit
f97307b548
2 changed files with 2 additions and 46 deletions
  1. 1 39
      zio.c
  2. 1 7
      zio.h

+ 1 - 39
zio.c

@@ -1,7 +1,7 @@
 /*
 /*
 * zio.c
 * zio.c
 * a generic input stream interface
 * a generic input stream interface
-* $Id: zio.c,v 1.5 1997/06/13 13:49:16 lhf Exp $
+* $Id: zio.c,v 1.1 1997/06/16 16:50:22 roberto Exp roberto $
 */
 */
 
 
 #include <stdio.h>
 #include <stdio.h>
@@ -9,13 +9,6 @@
 #include <string.h>
 #include <string.h>
 #include "zio.h"
 #include "zio.h"
 
 
-#ifdef POPEN
-FILE *popen();
-int pclose();
-#else
-#define popen(x,y) NULL  /* that is, popen always fails */
-#define pclose(x)  (-1)
-#endif
 
 
 /* ----------------------------------------------------- memory buffers --- */
 /* ----------------------------------------------------- memory buffers --- */
 
 
@@ -24,18 +17,12 @@ static int zmfilbuf(ZIO* z)
  return EOZ;
  return EOZ;
 }
 }
 
 
-static int zmclose(ZIO* z)
-{
- return 1; 
-}
-
 ZIO* zmopen(ZIO* z, char* b, int size)
 ZIO* zmopen(ZIO* z, char* b, int size)
 {
 {
  if (b==NULL) return NULL;
  if (b==NULL) return NULL;
  z->n=size;
  z->n=size;
  z->p= (unsigned char *)b;
  z->p= (unsigned char *)b;
  z->filbuf=zmfilbuf;
  z->filbuf=zmfilbuf;
- z->close=zmclose;
  z->u=NULL;
  z->u=NULL;
  return z;
  return z;
 }
 }
@@ -59,11 +46,6 @@ static int zffilbuf(ZIO* z)
  return *(z->p++);
  return *(z->p++);
 }
 }
 
 
-static int zfclose(ZIO* z)
-{
- if (z->u==stdin) return 0;
- return fclose(z->u);
-}
 
 
 ZIO* zFopen(ZIO* z, FILE* f)
 ZIO* zFopen(ZIO* z, FILE* f)
 {
 {
@@ -71,30 +53,10 @@ ZIO* zFopen(ZIO* z, FILE* f)
  z->n=0;
  z->n=0;
  z->p=z->buffer;
  z->p=z->buffer;
  z->filbuf=zffilbuf;
  z->filbuf=zffilbuf;
- z->close=zfclose;
  z->u=f;
  z->u=f;
  return z;
  return z;
 }
 }
 
 
-ZIO* zfopen(ZIO* z, char* s, char* m)
-{
- return zFopen(z,fopen(s,m)); 
-}
-
-/* -------------------------------------------------------------- pipes --- */
-
-static int zpclose(ZIO* z)
-{
- return pclose(z->u);
-}
-
-ZIO* zpopen(ZIO* z, char* s, char* m)
-{
- z=zFopen(z,popen(s,m)); 
- if (z==NULL) return NULL;
- z->close=zpclose;
- return z;
-}
 
 
 /* --------------------------------------------------------------- read --- */
 /* --------------------------------------------------------------- read --- */
 int zread(ZIO *z, void *b, int n)
 int zread(ZIO *z, void *b, int n)

+ 1 - 7
zio.h

@@ -1,7 +1,7 @@
 /*
 /*
 * zio.h
 * zio.h
 * a generic input stream interface
 * a generic input stream interface
-* $Id: zio.h,v 1.3 1997/06/18 21:39:56 roberto Exp roberto $
+* $Id: zio.h,v 1.4 1997/06/19 18:55:28 roberto Exp roberto $
 */
 */
 
 
 #ifndef zio_h
 #ifndef zio_h
@@ -13,8 +13,6 @@
 
 
 /* For Lua only */
 /* For Lua only */
 #define zFopen	luaZ_Fopen
 #define zFopen	luaZ_Fopen
-#define zfopen	luaZ_fopen
-#define zpopen	luaZ_popen
 #define zsopen	luaZ_sopen
 #define zsopen	luaZ_sopen
 #define zmopen	luaZ_mopen
 #define zmopen	luaZ_mopen
 #define zread	luaZ_read
 #define zread	luaZ_read
@@ -24,8 +22,6 @@
 typedef struct zio ZIO;
 typedef struct zio ZIO;
 
 
 ZIO* zFopen(ZIO* z, FILE* f);		/* open FILEs */
 ZIO* zFopen(ZIO* z, FILE* f);		/* open FILEs */
-ZIO* zfopen(ZIO* z, char* s, char* m);	/* file by name */
-ZIO* zpopen(ZIO* z, char* s, char* m);	/* pipe */
 ZIO* zsopen(ZIO* z, char* s);		/* string */
 ZIO* zsopen(ZIO* z, char* s);		/* string */
 ZIO* zmopen(ZIO* z, char* b, int size);	/* memory */
 ZIO* zmopen(ZIO* z, char* b, int size);	/* memory */
 
 
@@ -33,7 +29,6 @@ int zread(ZIO* z, void* b, int n);	/* read next n bytes */
 
 
 #define zgetc(z)	(--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
 #define zgetc(z)	(--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
 #define zungetc(z)	(++(z)->n,--(z)->p)
 #define zungetc(z)	(++(z)->n,--(z)->p)
-#define zclose(z)	(*(z)->close)(z)
 
 
 
 
 
 
@@ -45,7 +40,6 @@ struct zio {
  int n;					/* bytes still unread */
  int n;					/* bytes still unread */
  unsigned char* p;			/* current position in buffer */
  unsigned char* p;			/* current position in buffer */
  int (*filbuf)(ZIO* z);
  int (*filbuf)(ZIO* z);
- int (*close)(ZIO* z);
  void* u;				/* additional data */
  void* u;				/* additional data */
  unsigned char buffer[ZBSIZE];		/* buffer */
  unsigned char buffer[ZBSIZE];		/* buffer */
 };
 };