Replace ios_t with struct

This commit is contained in:
Lassi Kortela 2019-08-09 19:26:20 +03:00
parent 41cf0e7b2c
commit f2fb37e520
11 changed files with 189 additions and 180 deletions

View File

@ -574,7 +574,7 @@ void to_sized_ptr(value_t v, char *fname, char **pdata, size_t *psz)
{ {
if (iscvalue(v)) { if (iscvalue(v)) {
cvalue_t *pcv = (cvalue_t *)ptr(v); cvalue_t *pcv = (cvalue_t *)ptr(v);
ios_t *x = value2c(ios_t *, v); struct ios *x = value2c(struct ios *, v);
if (cv_class(pcv) == iostreamtype && (x->bm == bm_mem)) { if (cv_class(pcv) == iostreamtype && (x->bm == bm_mem)) {
*pdata = x->buf; *pdata = x->buf;
*psz = x->size; *psz = x->size;

View File

@ -11,7 +11,8 @@ static char hexdig[] = "0123456789abcdef";
display a given number of bytes from a buffer, with the first display a given number of bytes from a buffer, with the first
address label being startoffs address label being startoffs
*/ */
void hexdump(ios_t *dest, const char *buffer, size_t len, size_t startoffs) void hexdump(struct ios *dest, const char *buffer, size_t len,
size_t startoffs)
{ {
size_t offs = 0; size_t offs = 0;
size_t i, pos; size_t i, pos;

View File

@ -2608,7 +2608,7 @@ int fl_load_system_image(value_t sys_image_iostream)
{ {
while (1) { while (1) {
e = fl_read_sexpr(Stack[SP - 1]); e = fl_read_sexpr(Stack[SP - 1]);
if (ios_eof(value2c(ios_t *, Stack[SP - 1]))) if (ios_eof(value2c(struct ios *, Stack[SP - 1])))
break; break;
if (isfunction(e)) { if (isfunction(e)) {
// stage 0 format: series of thunks // stage 0 format: series of thunks
@ -2635,7 +2635,7 @@ int fl_load_system_image(value_t sys_image_iostream)
ios_putc('\n', ios_stderr); ios_putc('\n', ios_stderr);
return 1; return 1;
} }
ios_close(value2c(ios_t *, Stack[SP - 1])); ios_close(value2c(struct ios *, Stack[SP - 1]));
POPN(1); POPN(1);
return 0; return 0;
} }

View File

@ -133,7 +133,7 @@ extern value_t FL_NIL, FL_T, FL_F, FL_EOF;
/* read, eval, print main entry points */ /* read, eval, print main entry points */
value_t fl_read_sexpr(value_t f); value_t fl_read_sexpr(value_t f);
void fl_print(ios_t *f, value_t v); void fl_print(struct ios *f, value_t v);
value_t fl_toplevel_eval(value_t expr); value_t fl_toplevel_eval(value_t expr);
value_t fl_apply(value_t f, value_t l); value_t fl_apply(value_t f, value_t l);
value_t fl_applyn(uint32_t n, value_t f, ...); value_t fl_applyn(uint32_t n, value_t f, ...);
@ -212,7 +212,7 @@ static inline void argcount(char *fname, uint32_t nargs, uint32_t c)
} }
typedef struct { typedef struct {
void (*print)(value_t self, ios_t *f); void (*print)(value_t self, struct ios *f);
void (*relocate)(value_t oldv, value_t newv); void (*relocate)(value_t oldv, value_t newv);
void (*finalize)(value_t self); void (*finalize)(value_t self);
void (*print_traverse)(value_t self); void (*print_traverse)(value_t self);
@ -244,9 +244,9 @@ typedef enum {
value_t relocate_lispvalue(value_t v); value_t relocate_lispvalue(value_t v);
void print_traverse(value_t v); void print_traverse(value_t v);
void fl_print_chr(char c, ios_t *f); void fl_print_chr(char c, struct ios *f);
void fl_print_str(char *s, ios_t *f); void fl_print_str(char *s, struct ios *f);
void fl_print_child(ios_t *f, value_t v); void fl_print_child(struct ios *f, value_t v);
typedef int (*cvinitfunc_t)(struct _fltype_t *, value_t, void *); typedef int (*cvinitfunc_t)(struct _fltype_t *, value_t, void *);
@ -367,7 +367,7 @@ int fl_isstring(value_t v);
int fl_isnumber(value_t v); int fl_isnumber(value_t v);
int fl_isgensym(value_t v); int fl_isgensym(value_t v);
int fl_isiostream(value_t v); int fl_isiostream(value_t v);
ios_t *fl_toiostream(value_t v, char *fname); struct ios *fl_toiostream(value_t v, char *fname);
value_t cvalue_compare(value_t a, value_t b); value_t cvalue_compare(value_t a, value_t b);
int numeric_compare(value_t a, value_t b, int eq, int eqnans, char *fname); int numeric_compare(value_t a, value_t b, int eq, int eqnans, char *fname);

100
c/ios.c
View File

@ -147,7 +147,7 @@ static int _os_write_all(long fd, void *buf, size_t n, size_t *nwritten)
/* internal utility functions */ /* internal utility functions */
static char *_buf_realloc(ios_t *s, size_t sz) static char *_buf_realloc(struct ios *s, size_t sz)
{ {
char *temp; char *temp;
@ -186,7 +186,7 @@ static char *_buf_realloc(ios_t *s, size_t sz)
// write a block of data into the buffer at the current position, resizing // write a block of data into the buffer at the current position, resizing
// if necessary. returns # written. // if necessary. returns # written.
static size_t _write_grow(ios_t *s, char *data, size_t n) static size_t _write_grow(struct ios *s, char *data, size_t n)
{ {
size_t amt; size_t amt;
size_t newsize; size_t newsize;
@ -222,7 +222,7 @@ static size_t _write_grow(ios_t *s, char *data, size_t n)
/* interface functions, low level */ /* interface functions, low level */
static size_t _ios_read(ios_t *s, char *dest, size_t n, int all) static size_t _ios_read(struct ios *s, char *dest, size_t n, int all)
{ {
size_t tot = 0; size_t tot = 0;
size_t got, avail; size_t got, avail;
@ -283,17 +283,17 @@ static size_t _ios_read(ios_t *s, char *dest, size_t n, int all)
return tot; return tot;
} }
size_t ios_read(ios_t *s, char *dest, size_t n) size_t ios_read(struct ios *s, char *dest, size_t n)
{ {
return _ios_read(s, dest, n, 0); return _ios_read(s, dest, n, 0);
} }
size_t ios_readall(ios_t *s, char *dest, size_t n) size_t ios_readall(struct ios *s, char *dest, size_t n)
{ {
return _ios_read(s, dest, n, 1); return _ios_read(s, dest, n, 1);
} }
size_t ios_readprep(ios_t *s, size_t n) size_t ios_readprep(struct ios *s, size_t n)
{ {
if (s->state == bst_wr && s->bm != bm_mem) { if (s->state == bst_wr && s->bm != bm_mem) {
ios_flush(s); ios_flush(s);
@ -324,7 +324,7 @@ size_t ios_readprep(ios_t *s, size_t n)
return s->size - s->bpos; return s->size - s->bpos;
} }
static void _write_update_pos(ios_t *s) static void _write_update_pos(struct ios *s)
{ {
if (s->bpos > s->ndirty) if (s->bpos > s->ndirty)
s->ndirty = s->bpos; s->ndirty = s->bpos;
@ -332,7 +332,7 @@ static void _write_update_pos(ios_t *s)
s->size = s->bpos; s->size = s->bpos;
} }
size_t ios_write(ios_t *s, char *data, size_t n) size_t ios_write(struct ios *s, char *data, size_t n)
{ {
if (s->readonly) if (s->readonly)
return 0; return 0;
@ -388,7 +388,7 @@ size_t ios_write(ios_t *s, char *data, size_t n)
return wrote; return wrote;
} }
off_t ios_seek(ios_t *s, off_t pos) off_t ios_seek(struct ios *s, off_t pos)
{ {
s->_eof = 0; s->_eof = 0;
if (s->bm == bm_mem) { if (s->bm == bm_mem) {
@ -405,7 +405,7 @@ off_t ios_seek(ios_t *s, off_t pos)
return 0; return 0;
} }
off_t ios_seek_end(ios_t *s) off_t ios_seek_end(struct ios *s)
{ {
s->_eof = 1; s->_eof = 1;
if (s->bm == bm_mem) { if (s->bm == bm_mem) {
@ -420,7 +420,7 @@ off_t ios_seek_end(ios_t *s)
return 0; return 0;
} }
off_t ios_skip(ios_t *s, off_t offs) off_t ios_skip(struct ios *s, off_t offs)
{ {
if (offs != 0) { if (offs != 0) {
if (offs > 0) { if (offs > 0) {
@ -454,7 +454,7 @@ off_t ios_skip(ios_t *s, off_t offs)
return 0; return 0;
} }
off_t ios_pos(ios_t *s) off_t ios_pos(struct ios *s)
{ {
if (s->bm == bm_mem) if (s->bm == bm_mem)
return (off_t)s->bpos; return (off_t)s->bpos;
@ -474,7 +474,7 @@ off_t ios_pos(ios_t *s)
return fdpos; return fdpos;
} }
size_t ios_trunc(ios_t *s, size_t size) size_t ios_trunc(struct ios *s, size_t size)
{ {
if (s->bm == bm_mem) { if (s->bm == bm_mem) {
if (size == s->size) if (size == s->size)
@ -493,7 +493,7 @@ size_t ios_trunc(ios_t *s, size_t size)
return 0; return 0;
} }
int ios_eof(ios_t *s) int ios_eof(struct ios *s)
{ {
if (s->bm == bm_mem) if (s->bm == bm_mem)
return (s->_eof ? 1 : 0); return (s->_eof ? 1 : 0);
@ -504,7 +504,7 @@ int ios_eof(ios_t *s)
return 0; return 0;
} }
int ios_flush(ios_t *s) int ios_flush(struct ios *s)
{ {
if (s->ndirty == 0 || s->bm == bm_mem || s->buf == NULL) if (s->ndirty == 0 || s->bm == bm_mem || s->buf == NULL)
return 0; return 0;
@ -548,7 +548,7 @@ int ios_flush(ios_t *s)
return 0; return 0;
} }
void ios_close(ios_t *s) void ios_close(struct ios *s)
{ {
ios_flush(s); ios_flush(s);
if (s->fd != -1 && s->ownfd) if (s->fd != -1 && s->ownfd)
@ -560,7 +560,7 @@ void ios_close(ios_t *s)
s->size = s->maxsize = s->bpos = 0; s->size = s->maxsize = s->bpos = 0;
} }
static void _buf_init(ios_t *s, bufmode_t bm) static void _buf_init(struct ios *s, bufmode_t bm)
{ {
s->bm = bm; s->bm = bm;
if (s->bm == bm_mem || s->bm == bm_none) { if (s->bm == bm_mem || s->bm == bm_none) {
@ -573,7 +573,7 @@ static void _buf_init(ios_t *s, bufmode_t bm)
s->size = s->bpos = 0; s->size = s->bpos = 0;
} }
char *ios_takebuf(ios_t *s, size_t *psize) char *ios_takebuf(struct ios *s, size_t *psize)
{ {
char *buf; char *buf;
@ -598,7 +598,7 @@ char *ios_takebuf(ios_t *s, size_t *psize)
return buf; return buf;
} }
int ios_setbuf(ios_t *s, char *buf, size_t size, int own) int ios_setbuf(struct ios *s, char *buf, size_t size, int own)
{ {
ios_flush(s); ios_flush(s);
size_t nvalid = 0; size_t nvalid = 0;
@ -620,7 +620,7 @@ int ios_setbuf(ios_t *s, char *buf, size_t size, int own)
return 0; return 0;
} }
int ios_bufmode(ios_t *s, bufmode_t mode) int ios_bufmode(struct ios *s, bufmode_t mode)
{ {
// no fd; can only do mem-only buffering // no fd; can only do mem-only buffering
if (s->fd == -1 && mode != bm_mem) if (s->fd == -1 && mode != bm_mem)
@ -629,7 +629,7 @@ int ios_bufmode(ios_t *s, bufmode_t mode)
return 0; return 0;
} }
void ios_set_readonly(ios_t *s) void ios_set_readonly(struct ios *s)
{ {
if (s->readonly) if (s->readonly)
return; return;
@ -638,7 +638,8 @@ void ios_set_readonly(ios_t *s)
s->readonly = 1; s->readonly = 1;
} }
static size_t ios_copy_(ios_t *to, ios_t *from, size_t nbytes, bool_t all) static size_t ios_copy_(struct ios *to, struct ios *from, size_t nbytes,
bool_t all)
{ {
size_t total = 0, avail; size_t total = 0, avail;
if (!ios_eof(from)) { if (!ios_eof(from)) {
@ -666,19 +667,19 @@ static size_t ios_copy_(ios_t *to, ios_t *from, size_t nbytes, bool_t all)
return total; return total;
} }
size_t ios_copy(ios_t *to, ios_t *from, size_t nbytes) size_t ios_copy(struct ios *to, struct ios *from, size_t nbytes)
{ {
return ios_copy_(to, from, nbytes, 0); return ios_copy_(to, from, nbytes, 0);
} }
size_t ios_copyall(ios_t *to, ios_t *from) size_t ios_copyall(struct ios *to, struct ios *from)
{ {
return ios_copy_(to, from, 0, 1); return ios_copy_(to, from, 0, 1);
} }
#define LINE_CHUNK_SIZE 160 #define LINE_CHUNK_SIZE 160
size_t ios_copyuntil(ios_t *to, ios_t *from, char delim) size_t ios_copyuntil(struct ios *to, struct ios *from, char delim)
{ {
size_t total = 0, avail = from->size - from->bpos; size_t total = 0, avail = from->size - from->bpos;
int first = 1; int first = 1;
@ -708,7 +709,7 @@ size_t ios_copyuntil(ios_t *to, ios_t *from, char delim)
return total; return total;
} }
static void _ios_init(ios_t *s) static void _ios_init(struct ios *s)
{ {
// put all fields in a sane initial state // put all fields in a sane initial state
s->bm = bm_block; s->bm = bm_block;
@ -731,7 +732,8 @@ static void _ios_init(ios_t *s)
/* stream object initializers. we do no allocation. */ /* stream object initializers. we do no allocation. */
ios_t *ios_file(ios_t *s, char *fname, int rd, int wr, int create, int trunc) struct ios *ios_file(struct ios *s, char *fname, int rd, int wr, int create,
int trunc)
{ {
int fd; int fd;
if (!(rd || wr)) if (!(rd || wr))
@ -754,7 +756,7 @@ open_file_err:
return NULL; return NULL;
} }
ios_t *ios_mem(ios_t *s, size_t initsize) struct ios *ios_mem(struct ios *s, size_t initsize)
{ {
_ios_init(s); _ios_init(s);
s->bm = bm_mem; s->bm = bm_mem;
@ -762,7 +764,7 @@ ios_t *ios_mem(ios_t *s, size_t initsize)
return s; return s;
} }
ios_t *ios_str(ios_t *s, char *str) struct ios *ios_str(struct ios *s, char *str)
{ {
size_t n = strlen(str); size_t n = strlen(str);
if (ios_mem(s, n + 1) == NULL) if (ios_mem(s, n + 1) == NULL)
@ -772,7 +774,7 @@ ios_t *ios_str(ios_t *s, char *str)
return s; return s;
} }
ios_t *ios_static_buffer(ios_t *s, char *buf, size_t sz) struct ios *ios_static_buffer(struct ios *s, char *buf, size_t sz)
{ {
ios_mem(s, 0); ios_mem(s, 0);
ios_setbuf(s, buf, sz, 0); ios_setbuf(s, buf, sz, 0);
@ -781,7 +783,7 @@ ios_t *ios_static_buffer(ios_t *s, char *buf, size_t sz)
return s; return s;
} }
ios_t *ios_fd(ios_t *s, long fd, int isfile, int own) struct ios *ios_fd(struct ios *s, long fd, int isfile, int own)
{ {
_ios_init(s); _ios_init(s);
s->fd = fd; s->fd = fd;
@ -794,27 +796,27 @@ ios_t *ios_fd(ios_t *s, long fd, int isfile, int own)
return s; return s;
} }
ios_t *ios_stdin = NULL; struct ios *ios_stdin = NULL;
ios_t *ios_stdout = NULL; struct ios *ios_stdout = NULL;
ios_t *ios_stderr = NULL; struct ios *ios_stderr = NULL;
void ios_init_stdstreams() void ios_init_stdstreams()
{ {
ios_stdin = LLT_ALLOC(sizeof(ios_t)); ios_stdin = LLT_ALLOC(sizeof(struct ios));
ios_fd(ios_stdin, STDIN_FILENO, 0, 0); ios_fd(ios_stdin, STDIN_FILENO, 0, 0);
ios_stdout = LLT_ALLOC(sizeof(ios_t)); ios_stdout = LLT_ALLOC(sizeof(struct ios));
ios_fd(ios_stdout, STDOUT_FILENO, 0, 0); ios_fd(ios_stdout, STDOUT_FILENO, 0, 0);
ios_stdout->bm = bm_line; ios_stdout->bm = bm_line;
ios_stderr = LLT_ALLOC(sizeof(ios_t)); ios_stderr = LLT_ALLOC(sizeof(struct ios));
ios_fd(ios_stderr, STDERR_FILENO, 0, 0); ios_fd(ios_stderr, STDERR_FILENO, 0, 0);
ios_stderr->bm = bm_none; ios_stderr->bm = bm_none;
} }
/* higher level interface */ /* higher level interface */
int ios_putc(int c, ios_t *s) int ios_putc(int c, struct ios *s)
{ {
char ch = (char)c; char ch = (char)c;
@ -828,7 +830,7 @@ int ios_putc(int c, ios_t *s)
return (int)ios_write(s, &ch, 1); return (int)ios_write(s, &ch, 1);
} }
int ios_getc(ios_t *s) int ios_getc(struct ios *s)
{ {
char ch; char ch;
if (s->state == bst_rd && s->bpos < s->size) { if (s->state == bst_rd && s->bpos < s->size) {
@ -844,7 +846,7 @@ int ios_getc(ios_t *s)
return (unsigned char)ch; return (unsigned char)ch;
} }
int ios_peekc(ios_t *s) int ios_peekc(struct ios *s)
{ {
if (s->bpos < s->size) if (s->bpos < s->size)
return (unsigned char)s->buf[s->bpos]; return (unsigned char)s->buf[s->bpos];
@ -856,7 +858,7 @@ int ios_peekc(ios_t *s)
return (unsigned char)s->buf[s->bpos]; return (unsigned char)s->buf[s->bpos];
} }
int ios_ungetc(int c, ios_t *s) int ios_ungetc(int c, struct ios *s)
{ {
if (s->state == bst_wr) if (s->state == bst_wr)
return IOS_EOF; return IOS_EOF;
@ -877,7 +879,7 @@ int ios_ungetc(int c, ios_t *s)
return c; return c;
} }
int ios_getutf8(ios_t *s, uint32_t *pwc) int ios_getutf8(struct ios *s, uint32_t *pwc)
{ {
int c; int c;
size_t sz; size_t sz;
@ -904,7 +906,7 @@ int ios_getutf8(ios_t *s, uint32_t *pwc)
return 1; return 1;
} }
int ios_peekutf8(ios_t *s, uint32_t *pwc) int ios_peekutf8(struct ios *s, uint32_t *pwc)
{ {
int c; int c;
size_t sz; size_t sz;
@ -926,7 +928,7 @@ int ios_peekutf8(ios_t *s, uint32_t *pwc)
return 1; return 1;
} }
int ios_pututf8(ios_t *s, uint32_t wc) int ios_pututf8(struct ios *s, uint32_t wc)
{ {
char buf[8]; char buf[8];
if (wc < 0x80) if (wc < 0x80)
@ -935,16 +937,16 @@ int ios_pututf8(ios_t *s, uint32_t wc)
return ios_write(s, buf, n); return ios_write(s, buf, n);
} }
void ios_purge(ios_t *s) void ios_purge(struct ios *s)
{ {
if (s->state == bst_rd) { if (s->state == bst_rd) {
s->bpos = s->size; s->bpos = s->size;
} }
} }
char *ios_readline(ios_t *s) char *ios_readline(struct ios *s)
{ {
ios_t dest; struct ios dest;
ios_mem(&dest, 0); ios_mem(&dest, 0);
ios_copyuntil(&dest, s, '\n'); ios_copyuntil(&dest, s, '\n');
size_t n; size_t n;
@ -953,7 +955,7 @@ char *ios_readline(ios_t *s)
int vasprintf(char **strp, const char *fmt, va_list ap); int vasprintf(char **strp, const char *fmt, va_list ap);
int ios_vprintf(ios_t *s, const char *format, va_list args) int ios_vprintf(struct ios *s, const char *format, va_list args)
{ {
char *str = NULL; char *str = NULL;
int c; int c;
@ -989,7 +991,7 @@ int ios_vprintf(ios_t *s, const char *format, va_list args)
return c; return c;
} }
int ios_printf(ios_t *s, const char *format, ...) int ios_printf(struct ios *s, const char *format, ...)
{ {
va_list args; va_list args;
int c; int c;

117
c/ios.h
View File

@ -11,7 +11,7 @@ typedef enum { bst_none, bst_rd, bst_wr } bufstate_t;
#define IOS_INLSIZE 54 #define IOS_INLSIZE 54
#define IOS_BUFSIZE 131072 #define IOS_BUFSIZE 131072
typedef struct { struct ios {
bufmode_t bm; bufmode_t bm;
// the state only indicates where the underlying file position is relative // the state only indicates where the underlying file position is relative
@ -54,82 +54,85 @@ typedef struct {
// todo: mutex // todo: mutex
char local[IOS_INLSIZE]; char local[IOS_INLSIZE];
} ios_t; };
/* low-level interface functions */ /* low-level interface functions */
size_t ios_read(ios_t *s, char *dest, size_t n); size_t ios_read(struct ios *s, char *dest, size_t n);
size_t ios_readall(ios_t *s, char *dest, size_t n); size_t ios_readall(struct ios *s, char *dest, size_t n);
size_t ios_write(ios_t *s, char *data, size_t n); size_t ios_write(struct ios *s, char *data, size_t n);
off_t ios_seek(ios_t *s, off_t pos); // absolute seek off_t ios_seek(struct ios *s, off_t pos); // absolute seek
off_t ios_seek_end(ios_t *s); off_t ios_seek_end(struct ios *s);
off_t ios_skip(ios_t *s, off_t offs); // relative seek off_t ios_skip(struct ios *s, off_t offs); // relative seek
off_t ios_pos(ios_t *s); // get current position off_t ios_pos(struct ios *s); // get current position
size_t ios_trunc(ios_t *s, size_t size); size_t ios_trunc(struct ios *s, size_t size);
int ios_eof(ios_t *s); int ios_eof(struct ios *s);
int ios_flush(ios_t *s); int ios_flush(struct ios *s);
void ios_close(ios_t *s); void ios_close(struct ios *s);
char *ios_takebuf(ios_t *s, size_t *psize); // release buffer to caller char *ios_takebuf(struct ios *s,
size_t *psize); // release buffer to caller
// set buffer space to use // set buffer space to use
int ios_setbuf(ios_t *s, char *buf, size_t size, int own); int ios_setbuf(struct ios *s, char *buf, size_t size, int own);
int ios_bufmode(ios_t *s, bufmode_t mode); int ios_bufmode(struct ios *s, bufmode_t mode);
void ios_set_readonly(ios_t *s); void ios_set_readonly(struct ios *s);
size_t ios_copy(ios_t *to, ios_t *from, size_t nbytes); size_t ios_copy(struct ios *to, struct ios *from, size_t nbytes);
size_t ios_copyall(ios_t *to, ios_t *from); size_t ios_copyall(struct ios *to, struct ios *from);
size_t ios_copyuntil(ios_t *to, ios_t *from, char delim); size_t ios_copyuntil(struct ios *to, struct ios *from, char delim);
// ensure at least n bytes are buffered if possible. returns # available. // ensure at least n bytes are buffered if possible. returns # available.
size_t ios_readprep(ios_t *from, size_t n); size_t ios_readprep(struct ios *from, size_t n);
// void ios_lock(ios_t *s); // void ios_lock(struct ios *s);
// int ios_trylock(ios_t *s); // int struct iosrylock(struct ios *s);
// int ios_unlock(ios_t *s); // int ios_unlock(struct ios *s);
/* stream creation */ /* stream creation */
ios_t *ios_file(ios_t *s, char *fname, int rd, int wr, int create, int trunc); struct ios *ios_file(struct ios *s, char *fname, int rd, int wr, int create,
ios_t *ios_mem(ios_t *s, size_t initsize); int trunc);
ios_t *ios_str(ios_t *s, char *str); struct ios *ios_mem(struct ios *s, size_t initsize);
ios_t *ios_static_buffer(ios_t *s, char *buf, size_t sz); struct ios *ios_str(struct ios *s, char *str);
ios_t *ios_fd(ios_t *s, long fd, int isfile, int own); struct ios *ios_static_buffer(struct ios *s, char *buf, size_t sz);
struct ios *ios_fd(struct ios *s, long fd, int isfile, int own);
// todo: ios_socket // todo: ios_socket
extern ios_t *ios_stdin; extern struct ios *ios_stdin;
extern ios_t *ios_stdout; extern struct ios *ios_stdout;
extern ios_t *ios_stderr; extern struct ios *ios_stderr;
void ios_init_stdstreams(); void ios_init_stdstreams();
/* high-level functions - output */ /* high-level functions - output */
int ios_putnum(ios_t *s, char *data, uint32_t type); int ios_putnum(struct ios *s, char *data, uint32_t type);
int ios_putint(ios_t *s, int n); int ios_putint(struct ios *s, int n);
int ios_pututf8(ios_t *s, uint32_t wc); int ios_pututf8(struct ios *s, uint32_t wc);
int ios_putstringz(ios_t *s, char *str, bool_t do_write_nulterm); int ios_putstringz(struct ios *s, char *str, bool_t do_write_nulterm);
int ios_printf(ios_t *s, const char *format, ...); int ios_printf(struct ios *s, const char *format, ...);
int ios_vprintf(ios_t *s, const char *format, va_list args); int ios_vprintf(struct ios *s, const char *format, va_list args);
void hexdump(ios_t *dest, const char *buffer, size_t len, size_t startoffs); void hexdump(struct ios *dest, const char *buffer, size_t len,
size_t startoffs);
/* high-level stream functions - input */ /* high-level stream functions - input */
int ios_getnum(ios_t *s, char *data, uint32_t type); int ios_getnum(struct ios *s, char *data, uint32_t type);
int ios_getutf8(ios_t *s, uint32_t *pwc); int ios_getutf8(struct ios *s, uint32_t *pwc);
int ios_peekutf8(ios_t *s, uint32_t *pwc); int ios_peekutf8(struct ios *s, uint32_t *pwc);
int ios_ungetutf8(ios_t *s, uint32_t wc); int ios_ungetutf8(struct ios *s, uint32_t wc);
int ios_getstringz(ios_t *dest, ios_t *src); int ios_getstringz(struct ios *dest, struct ios *src);
int ios_getstringn(ios_t *dest, ios_t *src, size_t nchars); int ios_getstringn(struct ios *dest, struct ios *src, size_t nchars);
int ios_getline(ios_t *s, char **pbuf, size_t *psz); int ios_getline(struct ios *s, char **pbuf, size_t *psz);
char *ios_readline(ios_t *s); char *ios_readline(struct ios *s);
// discard data buffered for reading // discard data buffered for reading
void ios_purge(ios_t *s); void ios_purge(struct ios *s);
// seek by utf8 sequence increments // seek by utf8 sequence increments
int ios_nextutf8(ios_t *s); int ios_nextutf8(struct ios *s);
int ios_prevutf8(ios_t *s); int ios_prevutf8(struct ios *s);
/* stdio-style functions */ /* stdio-style functions */
#define IOS_EOF (-1) #define IOS_EOF (-1)
int ios_putc(int c, ios_t *s); int ios_putc(int c, struct ios *s);
// wint_t ios_putwc(ios_t *s, wchar_t wc); // wint_t ios_putwc(struct ios *s, wchar_t wc);
int ios_getc(ios_t *s); int ios_getc(struct ios *s);
int ios_peekc(ios_t *s); int ios_peekc(struct ios *s);
// wint_t ios_getwc(ios_t *s); // wint_t ios_getwc(struct ios *s);
int ios_ungetc(int c, ios_t *s); int ios_ungetc(int c, struct ios *s);
// wint_t ios_ungetwc(ios_t *s, wint_t wc); // wint_t ios_ungetwc(struct ios *s, wint_t wc);
#define ios_puts(str, s) ios_write(s, str, strlen(str)) #define ios_puts(str, s) ios_write(s, str, strlen(str))
/* /*

View File

@ -27,7 +27,7 @@ static value_t iostreamsym, rdsym, wrsym, apsym, crsym, truncsym;
static value_t instrsym, outstrsym; static value_t instrsym, outstrsym;
fltype_t *iostreamtype; fltype_t *iostreamtype;
void print_iostream(value_t v, ios_t *f) void print_iostream(value_t v, struct ios *f)
{ {
(void)v; (void)v;
fl_print_str("#<io stream>", f); fl_print_str("#<io stream>", f);
@ -35,14 +35,14 @@ void print_iostream(value_t v, ios_t *f)
void free_iostream(value_t self) void free_iostream(value_t self)
{ {
ios_t *s = value2c(ios_t *, self); struct ios *s = value2c(struct ios *, self);
ios_close(s); ios_close(s);
} }
void relocate_iostream(value_t oldv, value_t newv) void relocate_iostream(value_t oldv, value_t newv)
{ {
ios_t *olds = value2c(ios_t *, oldv); struct ios *olds = value2c(struct ios *, oldv);
ios_t *news = value2c(ios_t *, newv); struct ios *news = value2c(struct ios *, newv);
if (news->buf == &olds->local[0]) { if (news->buf == &olds->local[0]) {
news->buf = &news->local[0]; news->buf = &news->local[0];
} }
@ -75,14 +75,17 @@ value_t fl_eof_objectp(value_t *args, uint32_t nargs)
return (FL_EOF == args[0]) ? FL_T : FL_F; return (FL_EOF == args[0]) ? FL_T : FL_F;
} }
static ios_t *toiostream(value_t v, char *fname) static struct ios *toiostream(value_t v, char *fname)
{ {
if (!fl_isiostream(v)) if (!fl_isiostream(v))
type_error(fname, "iostream", v); type_error(fname, "iostream", v);
return value2c(ios_t *, v); return value2c(struct ios *, v);
} }
ios_t *fl_toiostream(value_t v, char *fname) { return toiostream(v, fname); } struct ios *fl_toiostream(value_t v, char *fname)
{
return toiostream(v, fname);
}
value_t fl_file(value_t *args, uint32_t nargs) value_t fl_file(value_t *args, uint32_t nargs)
{ {
@ -106,9 +109,9 @@ value_t fl_file(value_t *args, uint32_t nargs)
} }
if ((r | w | c | t | a) == 0) if ((r | w | c | t | a) == 0)
r = 1; // default to reading r = 1; // default to reading
value_t f = cvalue(iostreamtype, sizeof(ios_t)); value_t f = cvalue(iostreamtype, sizeof(struct ios));
char *fname = tostring(args[0], "file"); char *fname = tostring(args[0], "file");
ios_t *s = value2c(ios_t *, f); struct ios *s = value2c(struct ios *, f);
if (ios_file(s, fname, r, w, c, t) == NULL) if (ios_file(s, fname, r, w, c, t) == NULL)
lerrorf(IOError, "file: could not open \"%s\"", fname); lerrorf(IOError, "file: could not open \"%s\"", fname);
if (a) if (a)
@ -120,8 +123,8 @@ value_t fl_buffer(value_t *args, u_int32_t nargs)
{ {
argcount("buffer", nargs, 0); argcount("buffer", nargs, 0);
(void)args; (void)args;
value_t f = cvalue(iostreamtype, sizeof(ios_t)); value_t f = cvalue(iostreamtype, sizeof(struct ios));
ios_t *s = value2c(ios_t *, f); struct ios *s = value2c(struct ios *, f);
if (ios_mem(s, 0) == NULL) if (ios_mem(s, 0) == NULL)
lerror(MemoryError, "buffer: could not allocate stream"); lerror(MemoryError, "buffer: could not allocate stream");
return f; return f;
@ -141,7 +144,7 @@ value_t fl_read(value_t *args, u_int32_t nargs)
fl_gc_handle(&arg); fl_gc_handle(&arg);
value_t v = fl_read_sexpr(arg); value_t v = fl_read_sexpr(arg);
fl_free_gc_handles(1); fl_free_gc_handles(1);
if (ios_eof(value2c(ios_t *, arg))) if (ios_eof(value2c(struct ios *, arg)))
return FL_EOF; return FL_EOF;
return v; return v;
} }
@ -149,7 +152,7 @@ value_t fl_read(value_t *args, u_int32_t nargs)
value_t fl_iogetc(value_t *args, u_int32_t nargs) value_t fl_iogetc(value_t *args, u_int32_t nargs)
{ {
argcount("io.getc", nargs, 1); argcount("io.getc", nargs, 1);
ios_t *s = toiostream(args[0], "io.getc"); struct ios *s = toiostream(args[0], "io.getc");
uint32_t wc; uint32_t wc;
if (ios_getutf8(s, &wc) == IOS_EOF) if (ios_getutf8(s, &wc) == IOS_EOF)
// lerror(IOError, "io.getc: end of file reached"); // lerror(IOError, "io.getc: end of file reached");
@ -160,7 +163,7 @@ value_t fl_iogetc(value_t *args, u_int32_t nargs)
value_t fl_iopeekc(value_t *args, u_int32_t nargs) value_t fl_iopeekc(value_t *args, u_int32_t nargs)
{ {
argcount("io.peekc", nargs, 1); argcount("io.peekc", nargs, 1);
ios_t *s = toiostream(args[0], "io.peekc"); struct ios *s = toiostream(args[0], "io.peekc");
uint32_t wc; uint32_t wc;
if (ios_peekutf8(s, &wc) == IOS_EOF) if (ios_peekutf8(s, &wc) == IOS_EOF)
return FL_EOF; return FL_EOF;
@ -170,7 +173,7 @@ value_t fl_iopeekc(value_t *args, u_int32_t nargs)
value_t fl_ioputc(value_t *args, u_int32_t nargs) value_t fl_ioputc(value_t *args, u_int32_t nargs)
{ {
argcount("io.putc", nargs, 2); argcount("io.putc", nargs, 2);
ios_t *s = toiostream(args[0], "io.putc"); struct ios *s = toiostream(args[0], "io.putc");
if (!iscprim(args[1]) || ((cprim_t *)ptr(args[1]))->type != wchartype) if (!iscprim(args[1]) || ((cprim_t *)ptr(args[1]))->type != wchartype)
type_error("io.putc", "wchar", args[1]); type_error("io.putc", "wchar", args[1]);
uint32_t wc = *(uint32_t *)cp_data((cprim_t *)ptr(args[1])); uint32_t wc = *(uint32_t *)cp_data((cprim_t *)ptr(args[1]));
@ -180,7 +183,7 @@ value_t fl_ioputc(value_t *args, u_int32_t nargs)
value_t fl_ioungetc(value_t *args, u_int32_t nargs) value_t fl_ioungetc(value_t *args, u_int32_t nargs)
{ {
argcount("io.ungetc", nargs, 2); argcount("io.ungetc", nargs, 2);
ios_t *s = toiostream(args[0], "io.ungetc"); struct ios *s = toiostream(args[0], "io.ungetc");
if (!iscprim(args[1]) || ((cprim_t *)ptr(args[1]))->type != wchartype) if (!iscprim(args[1]) || ((cprim_t *)ptr(args[1]))->type != wchartype)
type_error("io.ungetc", "wchar", args[1]); type_error("io.ungetc", "wchar", args[1]);
uint32_t wc = *(uint32_t *)cp_data((cprim_t *)ptr(args[1])); uint32_t wc = *(uint32_t *)cp_data((cprim_t *)ptr(args[1]));
@ -193,7 +196,7 @@ value_t fl_ioungetc(value_t *args, u_int32_t nargs)
value_t fl_ioflush(value_t *args, u_int32_t nargs) value_t fl_ioflush(value_t *args, u_int32_t nargs)
{ {
argcount("io.flush", nargs, 1); argcount("io.flush", nargs, 1);
ios_t *s = toiostream(args[0], "io.flush"); struct ios *s = toiostream(args[0], "io.flush");
if (ios_flush(s) != 0) if (ios_flush(s) != 0)
return FL_F; return FL_F;
return FL_T; return FL_T;
@ -202,7 +205,7 @@ value_t fl_ioflush(value_t *args, u_int32_t nargs)
value_t fl_ioclose(value_t *args, u_int32_t nargs) value_t fl_ioclose(value_t *args, u_int32_t nargs)
{ {
argcount("io.close", nargs, 1); argcount("io.close", nargs, 1);
ios_t *s = toiostream(args[0], "io.close"); struct ios *s = toiostream(args[0], "io.close");
ios_close(s); ios_close(s);
return FL_T; return FL_T;
} }
@ -210,7 +213,7 @@ value_t fl_ioclose(value_t *args, u_int32_t nargs)
value_t fl_iopurge(value_t *args, u_int32_t nargs) value_t fl_iopurge(value_t *args, u_int32_t nargs)
{ {
argcount("io.discardbuffer", nargs, 1); argcount("io.discardbuffer", nargs, 1);
ios_t *s = toiostream(args[0], "io.discardbuffer"); struct ios *s = toiostream(args[0], "io.discardbuffer");
ios_purge(s); ios_purge(s);
return FL_T; return FL_T;
} }
@ -218,14 +221,14 @@ value_t fl_iopurge(value_t *args, u_int32_t nargs)
value_t fl_ioeof(value_t *args, u_int32_t nargs) value_t fl_ioeof(value_t *args, u_int32_t nargs)
{ {
argcount("io.eof?", nargs, 1); argcount("io.eof?", nargs, 1);
ios_t *s = toiostream(args[0], "io.eof?"); struct ios *s = toiostream(args[0], "io.eof?");
return (ios_eof(s) ? FL_T : FL_F); return (ios_eof(s) ? FL_T : FL_F);
} }
value_t fl_ioseek(value_t *args, u_int32_t nargs) value_t fl_ioseek(value_t *args, u_int32_t nargs)
{ {
argcount("io.seek", nargs, 2); argcount("io.seek", nargs, 2);
ios_t *s = toiostream(args[0], "io.seek"); struct ios *s = toiostream(args[0], "io.seek");
size_t pos = toulong(args[1], "io.seek"); size_t pos = toulong(args[1], "io.seek");
off_t res = ios_seek(s, (off_t)pos); off_t res = ios_seek(s, (off_t)pos);
if (res == -1) if (res == -1)
@ -236,7 +239,7 @@ value_t fl_ioseek(value_t *args, u_int32_t nargs)
value_t fl_iopos(value_t *args, u_int32_t nargs) value_t fl_iopos(value_t *args, u_int32_t nargs)
{ {
argcount("io.pos", nargs, 1); argcount("io.pos", nargs, 1);
ios_t *s = toiostream(args[0], "io.pos"); struct ios *s = toiostream(args[0], "io.pos");
off_t res = ios_pos(s); off_t res = ios_pos(s);
if (res == -1) if (res == -1)
return FL_F; return FL_F;
@ -247,7 +250,7 @@ value_t fl_write(value_t *args, u_int32_t nargs)
{ {
if (nargs < 1 || nargs > 2) if (nargs < 1 || nargs > 2)
argcount("write", nargs, 1); argcount("write", nargs, 1);
ios_t *s; struct ios *s;
if (nargs == 2) if (nargs == 2)
s = toiostream(args[1], "write"); s = toiostream(args[1], "write");
else else
@ -279,7 +282,7 @@ value_t fl_ioread(value_t *args, u_int32_t nargs)
data = cv_data((cvalue_t *)ptr(cv)); data = cv_data((cvalue_t *)ptr(cv));
else else
data = cp_data((cprim_t *)ptr(cv)); data = cp_data((cprim_t *)ptr(cv));
size_t got = ios_read(value2c(ios_t *, args[0]), data, n); size_t got = ios_read(value2c(struct ios *, args[0]), data, n);
if (got < n) if (got < n)
// lerror(IOError, "io.read: end of input reached"); // lerror(IOError, "io.read: end of input reached");
return FL_EOF; return FL_EOF;
@ -305,7 +308,7 @@ value_t fl_iowrite(value_t *args, u_int32_t nargs)
{ {
if (nargs < 2 || nargs > 4) if (nargs < 2 || nargs > 4)
argcount("io.write", nargs, 2); argcount("io.write", nargs, 2);
ios_t *s = toiostream(args[0], "io.write"); struct ios *s = toiostream(args[0], "io.write");
if (iscprim(args[1]) && ((cprim_t *)ptr(args[1]))->type == wchartype) { if (iscprim(args[1]) && ((cprim_t *)ptr(args[1]))->type == wchartype) {
if (nargs > 2) if (nargs > 2)
lerror(ArgError, lerror(ArgError,
@ -328,7 +331,7 @@ value_t fl_dump(value_t *args, u_int32_t nargs)
{ {
if (nargs < 1 || nargs > 3) if (nargs < 1 || nargs > 3)
argcount("dump", nargs, 1); argcount("dump", nargs, 1);
ios_t *s = toiostream(symbol_value(outstrsym), "dump"); struct ios *s = toiostream(symbol_value(outstrsym), "dump");
char *data; char *data;
size_t sz, offs = 0; size_t sz, offs = 0;
to_sized_ptr(args[0], "dump", &data, &sz); to_sized_ptr(args[0], "dump", &data, &sz);
@ -359,11 +362,11 @@ value_t fl_ioreaduntil(value_t *args, u_int32_t nargs)
value_t str = cvalue_string(80); value_t str = cvalue_string(80);
cvalue_t *cv = (cvalue_t *)ptr(str); cvalue_t *cv = (cvalue_t *)ptr(str);
char *data = cv_data(cv); char *data = cv_data(cv);
ios_t dest; struct ios dest;
ios_mem(&dest, 0); ios_mem(&dest, 0);
ios_setbuf(&dest, data, 80, 0); ios_setbuf(&dest, data, 80, 0);
char delim = get_delim_arg(args[1], "io.readuntil"); char delim = get_delim_arg(args[1], "io.readuntil");
ios_t *src = toiostream(args[0], "io.readuntil"); struct ios *src = toiostream(args[0], "io.readuntil");
size_t n = ios_copyuntil(&dest, src, delim); size_t n = ios_copyuntil(&dest, src, delim);
cv->len = n; cv->len = n;
if (dest.buf != data) { if (dest.buf != data) {
@ -382,8 +385,8 @@ value_t fl_ioreaduntil(value_t *args, u_int32_t nargs)
value_t fl_iocopyuntil(value_t *args, u_int32_t nargs) value_t fl_iocopyuntil(value_t *args, u_int32_t nargs)
{ {
argcount("io.copyuntil", nargs, 3); argcount("io.copyuntil", nargs, 3);
ios_t *dest = toiostream(args[0], "io.copyuntil"); struct ios *dest = toiostream(args[0], "io.copyuntil");
ios_t *src = toiostream(args[1], "io.copyuntil"); struct ios *src = toiostream(args[1], "io.copyuntil");
char delim = get_delim_arg(args[2], "io.copyuntil"); char delim = get_delim_arg(args[2], "io.copyuntil");
return size_wrap(ios_copyuntil(dest, src, delim)); return size_wrap(ios_copyuntil(dest, src, delim));
} }
@ -392,8 +395,8 @@ value_t fl_iocopy(value_t *args, u_int32_t nargs)
{ {
if (nargs < 2 || nargs > 3) if (nargs < 2 || nargs > 3)
argcount("io.copy", nargs, 2); argcount("io.copy", nargs, 2);
ios_t *dest = toiostream(args[0], "io.copy"); struct ios *dest = toiostream(args[0], "io.copy");
ios_t *src = toiostream(args[1], "io.copy"); struct ios *src = toiostream(args[1], "io.copy");
if (nargs == 3) { if (nargs == 3) {
size_t n = toulong(args[2], "io.copy"); size_t n = toulong(args[2], "io.copy");
return size_wrap(ios_copy(dest, src, n)); return size_wrap(ios_copy(dest, src, n));
@ -405,12 +408,12 @@ value_t stream_to_string(value_t *ps)
{ {
value_t str; value_t str;
size_t n; size_t n;
ios_t *st = value2c(ios_t *, *ps); struct ios *st = value2c(struct ios *, *ps);
if (st->buf == &st->local[0]) { if (st->buf == &st->local[0]) {
n = st->size; n = st->size;
str = cvalue_string(n); str = cvalue_string(n);
memcpy(cvalue_data(str), value2c(ios_t *, *ps)->buf, n); memcpy(cvalue_data(str), value2c(struct ios *, *ps)->buf, n);
ios_trunc(value2c(ios_t *, *ps), 0); ios_trunc(value2c(struct ios *, *ps), 0);
} else { } else {
char *b = ios_takebuf(st, &n); char *b = ios_takebuf(st, &n);
n--; n--;
@ -426,7 +429,7 @@ value_t stream_to_string(value_t *ps)
value_t fl_iotostring(value_t *args, u_int32_t nargs) value_t fl_iotostring(value_t *args, u_int32_t nargs)
{ {
argcount("io.tostring!", nargs, 1); argcount("io.tostring!", nargs, 1);
ios_t *src = toiostream(args[0], "io.tostring!"); struct ios *src = toiostream(args[0], "io.tostring!");
if (src->bm != bm_mem) if (src->bm != bm_mem)
lerror(ArgError, "io.tostring!: requires memory stream"); lerror(ArgError, "io.tostring!: requires memory stream");
return stream_to_string(&args[0]); return stream_to_string(&args[0]);
@ -471,14 +474,14 @@ void iostream_init(void)
truncsym = symbol(":truncate"); truncsym = symbol(":truncate");
instrsym = symbol("*input-stream*"); instrsym = symbol("*input-stream*");
outstrsym = symbol("*output-stream*"); outstrsym = symbol("*output-stream*");
iostreamtype = iostreamtype = define_opaque_type(iostreamsym, sizeof(struct ios),
define_opaque_type(iostreamsym, sizeof(ios_t), &iostream_vtable, NULL); &iostream_vtable, NULL);
assign_global_builtins(iostreamfunc_info); assign_global_builtins(iostreamfunc_info);
setc(symbol("*stdout*"), setc(symbol("*stdout*"), cvalue_from_ref(iostreamtype, ios_stdout,
cvalue_from_ref(iostreamtype, ios_stdout, sizeof(ios_t), FL_NIL)); sizeof(struct ios), FL_NIL));
setc(symbol("*stderr*"), setc(symbol("*stderr*"), cvalue_from_ref(iostreamtype, ios_stderr,
cvalue_from_ref(iostreamtype, ios_stderr, sizeof(ios_t), FL_NIL)); sizeof(struct ios), FL_NIL));
setc(symbol("*stdin*"), setc(symbol("*stdin*"), cvalue_from_ref(iostreamtype, ios_stdin,
cvalue_from_ref(iostreamtype, ios_stdin, sizeof(ios_t), FL_NIL)); sizeof(struct ios), FL_NIL));
} }

View File

@ -10,7 +10,7 @@ static fixnum_t P_LEVEL;
static int SCR_WIDTH = 80; static int SCR_WIDTH = 80;
static int HPOS = 0, VPOS; static int HPOS = 0, VPOS;
static void outc(char c, ios_t *f) static void outc(char c, struct ios *f)
{ {
ios_putc(c, f); ios_putc(c, f);
if (c == '\n') if (c == '\n')
@ -18,17 +18,17 @@ static void outc(char c, ios_t *f)
else else
HPOS++; HPOS++;
} }
static void outs(char *s, ios_t *f) static void outs(char *s, struct ios *f)
{ {
ios_puts(s, f); ios_puts(s, f);
HPOS += u8_strwidth(s); HPOS += u8_strwidth(s);
} }
static void outsn(char *s, ios_t *f, size_t n) static void outsn(char *s, struct ios *f, size_t n)
{ {
ios_write(f, s, n); ios_write(f, s, n);
HPOS += u8_strwidth(s); HPOS += u8_strwidth(s);
} }
static int outindent(int n, ios_t *f) static int outindent(int n, struct ios *f)
{ {
// move back to left margin if we get too indented // move back to left margin if we get too indented
if (n > SCR_WIDTH - 12) if (n > SCR_WIDTH - 12)
@ -44,9 +44,9 @@ static int outindent(int n, ios_t *f)
return n0; return n0;
} }
void fl_print_chr(char c, ios_t *f) { outc(c, f); } void fl_print_chr(char c, struct ios *f) { outc(c, f); }
void fl_print_str(char *s, ios_t *f) { outs(s, f); } void fl_print_str(char *s, struct ios *f) { outs(s, f); }
void print_traverse(value_t v) void print_traverse(value_t v)
{ {
@ -96,7 +96,7 @@ void print_traverse(value_t v)
} }
} }
static void print_symbol_name(ios_t *f, char *name) static void print_symbol_name(struct ios *f, char *name)
{ {
int i, escape = 0, charescape = 0; int i, escape = 0, charescape = 0;
@ -243,7 +243,7 @@ static int blockindent(value_t v)
return (allsmallp(v) > 9); return (allsmallp(v) > 9);
} }
static void print_pair(ios_t *f, value_t v) static void print_pair(struct ios *f, value_t v)
{ {
value_t cd; value_t cd;
char *op = NULL; char *op = NULL;
@ -334,9 +334,9 @@ static void print_pair(ios_t *f, value_t v)
} }
} }
static void cvalue_print(ios_t *f, value_t v); static void cvalue_print(struct ios *f, value_t v);
static int print_circle_prefix(ios_t *f, value_t v) static int print_circle_prefix(struct ios *f, value_t v)
{ {
value_t label; value_t label;
if ((label = (value_t)ptrhash_get(&printconses, (void *)v)) != if ((label = (value_t)ptrhash_get(&printconses, (void *)v)) !=
@ -352,7 +352,7 @@ static int print_circle_prefix(ios_t *f, value_t v)
return 0; return 0;
} }
void fl_print_child(ios_t *f, value_t v) void fl_print_child(struct ios *f, value_t v)
{ {
char *name; char *name;
if (print_level >= 0 && P_LEVEL >= print_level && if (print_level >= 0 && P_LEVEL >= print_level &&
@ -469,7 +469,7 @@ void fl_print_child(ios_t *f, value_t v)
P_LEVEL--; P_LEVEL--;
} }
static void print_string(ios_t *f, char *str, size_t sz) static void print_string(struct ios *f, char *str, size_t sz)
{ {
char buf[512]; char buf[512];
size_t i = 0; size_t i = 0;
@ -593,8 +593,8 @@ static numerictype_t sym_to_numtype(value_t type);
// for example #int32(0) can be printed as just 0. this is used // for example #int32(0) can be printed as just 0. this is used
// printing in a context where a type is already implied, e.g. inside // printing in a context where a type is already implied, e.g. inside
// an array. // an array.
static void cvalue_printdata(ios_t *f, void *data, size_t len, value_t type, static void cvalue_printdata(struct ios *f, void *data, size_t len,
int weak) value_t type, int weak)
{ {
if (type == bytesym) { if (type == bytesym) {
unsigned char ch = *(unsigned char *)data; unsigned char ch = *(unsigned char *)data;
@ -778,7 +778,7 @@ static void cvalue_printdata(ios_t *f, void *data, size_t len, value_t type,
} }
} }
static void cvalue_print(ios_t *f, value_t v) static void cvalue_print(struct ios *f, value_t v)
{ {
cvalue_t *cv = (cvalue_t *)ptr(v); cvalue_t *cv = (cvalue_t *)ptr(v);
void *data = cptr(v); void *data = cptr(v);
@ -817,7 +817,7 @@ static void set_print_width(void)
SCR_WIDTH = numval(pw); SCR_WIDTH = numval(pw);
} }
void fl_print(ios_t *f, value_t v) void fl_print(struct ios *f, value_t v)
{ {
print_pretty = (symbol_value(printprettysym) != FL_F); print_pretty = (symbol_value(printprettysym) != FL_F);
if (print_pretty) if (print_pretty)

View File

@ -22,7 +22,7 @@ enum {
TOK_DOUBLEQUOTE TOK_DOUBLEQUOTE
}; };
#define F value2c(ios_t *, readstate->source) #define F value2c(struct ios *, readstate->source)
// defines which characters are ordinary symbol characters. // defines which characters are ordinary symbol characters.
// exceptions are '.', which is an ordinary symbol character // exceptions are '.', which is an ordinary symbol character
@ -121,7 +121,7 @@ static char nextchar(void)
{ {
int ch; int ch;
char c; char c;
ios_t *f = F; struct ios *f = F;
do { do {
if (f->bpos < f->size) { if (f->bpos < f->size) {

View File

@ -144,7 +144,7 @@ value_t fl_string(value_t *args, u_int32_t nargs)
return args[0]; return args[0];
value_t arg, buf = fl_buffer(NULL, 0); value_t arg, buf = fl_buffer(NULL, 0);
fl_gc_handle(&buf); fl_gc_handle(&buf);
ios_t *s = value2c(ios_t *, buf); struct ios *s = value2c(struct ios *, buf);
uint32_t i; uint32_t i;
value_t oldpr = symbol_value(printreadablysym); value_t oldpr = symbol_value(printreadablysym);
value_t oldpp = symbol_value(printprettysym); value_t oldpp = symbol_value(printprettysym);

View File

@ -27,7 +27,7 @@
static value_t tablesym; static value_t tablesym;
static fltype_t *tabletype; static fltype_t *tabletype;
void print_htable(value_t v, ios_t *f) void print_htable(value_t v, struct ios *f)
{ {
struct htable *h = (struct htable *)cv_data((cvalue_t *)ptr(v)); struct htable *h = (struct htable *)cv_data((cvalue_t *)ptr(v));
size_t i; size_t i;