From ea9fc30d4bbe511bc6403d9f0a6a1d1725414ffa Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 9 Oct 1998 10:01:12 +0000 Subject: [PATCH] Change the definition of the functions in scm_ptobfuns so that they get passed the port object, not the port's stream. * ports.h (scm_ptobfuns): Rename all `stream' arguments to `port'. * gc.c (scm_gc_sweep): Pass the port itself to the free function. * genio.c (scm_putc, scm_puts, scm_lfwrite, scm_fflush, scm_getc): Pass the port itself to the scm_ptobs function. * ports.c (scm_close_port, scm_force_output, scm_flush_all_ports, scm_generic_fgets): Same. (putc_void_port, puts_void_port, write_void_port, flush_void_port, getc_void_port, fgets_void_port, close_void_port): Just change the argument names; these functions don't really do anything. * fports.c (local_fgetc, local_fgets, local_fclose, local_fflush, local_fputc, local_fputs, local_ffwrite, local_pclose): Take the port as an argument, and use SCM_STREAM to get the stdio FILE *. Also, use prototyped definitions, and get rid of the extra declarations. (scm_fptob, scm_pipob): We don't need casts here any more. * strports.c (prinstpt): Use prototype declarations. (stputc, stwrite, stputs, stgetc): Take the port as an argument, and use SCM_STREAM to get the string info. Also, use prototyped definitions, and get rid of the extra declarations. * vports.c (sfputc, sfwrite, sfputs, sfflush, sfgetc, sfclose, noop0): Same. * fports.c (local_fgetc, local_fgets): Renamed from scm_fgetc and scm_fgets, for consistency. (scm_fptop, scm_pipob): References updated. --- libguile/fports.c | 104 +++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 67 deletions(-) diff --git a/libguile/fports.c b/libguile/fports.c index ec87bda8e..01a8d81f8 100644 --- a/libguile/fports.c +++ b/libguile/fports.c @@ -273,33 +273,19 @@ prinfport (exp, port, pstate) -static int scm_fgetc SCM_P ((FILE * s)); - static int -scm_fgetc (s) - FILE * s; +local_fgetc (SCM port) { + FILE *s = (FILE *) SCM_STREAM (port); if (feof (s)) return EOF; else return fgetc (s); } -/* - * The fgets method must take a port as its argument, rather than - * the underlying file handle. The reason is that we also provide - * a generic fgets method for ports which can't use fgets(3) (e.g. - * string ports). This generic method calls the port's own - * fgetc method. In order for it to know how to get that method, - * we must pass the original Scheme port object. - */ - -static char * scm_fgets SCM_P ((SCM port, int *len)); static char * -scm_fgets (port, len) - SCM port; - int *len; +local_fgets (SCM port, int *len) { FILE *f; @@ -384,53 +370,43 @@ pwrite (ptr, size, nitems, port) * crippled C compilers cope with life. */ -static int local_fclose SCM_P ((FILE *fp)); - static int -local_fclose (fp) - FILE * fp; +local_fclose (SCM port) { + FILE *fp = (FILE *) SCM_STREAM (port); + return fclose (fp); } -static int local_fflush SCM_P ((FILE *fp)); - static int -local_fflush (fp) - FILE * fp; +local_fflush (SCM port) { + FILE *fp = (FILE *) SCM_STREAM (port); return fflush (fp); } -static int local_fputc SCM_P ((int c, FILE *fp)); - static int -local_fputc (c, fp) - int c; - FILE * fp; +local_fputc (int c, SCM port) { + FILE *fp = (FILE *) SCM_STREAM (port); + return fputc (c, fp); } -static int local_fputs SCM_P ((char *s, FILE *fp)); - static int -local_fputs (s, fp) - char * s; - FILE * fp; +local_fputs (char *s, SCM port) { + FILE *fp = (FILE *) SCM_STREAM (port); return fputs (s, fp); } -static scm_sizet local_ffwrite SCM_P ((void *ptr, int size, int nitems, FILE *fp)); - static scm_sizet -local_ffwrite (ptr, size, nitems, fp) - void * ptr; - int size; - int nitems; - FILE * fp; +local_ffwrite (char *ptr, + scm_sizet size, + scm_sizet nitems, + SCM port) { + FILE *fp = (FILE *) SCM_STREAM (port); return ffwrite (ptr, size, nitems, fp); } @@ -441,17 +417,11 @@ print_pipe_port (SCM exp, SCM port, scm_print_state *pstate) return 1; } - - -/* On SunOS, there's no declaration for pclose in the headers, so - putting it directly in the initializer for scm_pipob doesn't really - fly. We could add an extern declaration for it, but then it'll - mismatch on some systems that do have a declaration. So we just - wrap it up this way. */ static int -local_pclose (fp) - FILE * fp; +local_pclose (SCM port) { + FILE *fp = (FILE *) SCM_STREAM (port); + return pclose (fp); } @@ -459,32 +429,32 @@ local_pclose (fp) scm_ptobfuns scm_fptob = { 0, - (int (*) SCM_P ((SCM))) local_fclose, + local_fclose, prinfport, 0, - (int (*) SCM_P ((int, SCM))) local_fputc, - (int (*) SCM_P ((char *, SCM))) local_fputs, - (scm_sizet (*) SCM_P ((char *, scm_sizet, scm_sizet, SCM))) local_ffwrite, - (int (*) SCM_P ((SCM))) local_fflush, - (int (*) SCM_P ((SCM))) scm_fgetc, - (char * (*) SCM_P ((SCM, int *))) scm_fgets, - (int (*) SCM_P ((SCM))) local_fclose + local_fputc, + local_fputs, + local_ffwrite, + local_fflush, + local_fgetc, + local_fgets, + local_fclose }; /* {Pipe ports} */ scm_ptobfuns scm_pipob = { 0, - (int (*) SCM_P ((SCM))) local_pclose, + local_pclose, print_pipe_port, 0, - (int (*) SCM_P ((int, SCM))) local_fputc, - (int (*) SCM_P ((char *, SCM))) local_fputs, - (scm_sizet (*) SCM_P ((char *, scm_sizet, scm_sizet, SCM))) local_ffwrite, - (int (*) SCM_P ((SCM))) local_fflush, - (int (*) SCM_P ((SCM))) scm_fgetc, - (char * (*) SCM_P ((SCM, int *))) scm_generic_fgets, - (int (*) SCM_P ((SCM))) local_pclose + local_fputc, + local_fputs, + local_ffwrite, + local_fflush, + local_fgetc, + scm_generic_fgets, + local_pclose }; void