From e97c8c469db0aa27985dab2879dc1f14905c7387 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Sat, 20 Nov 2021 11:55:55 -0800 Subject: chore: simplify makefiles --- include/base/io.h | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'include/base') diff --git a/include/base/io.h b/include/base/io.h index f8c0bcc..5e0f1e0 100644 --- a/include/base/io.h +++ b/include/base/io.h @@ -96,46 +96,46 @@ int io·flush(io·Stream *s); int io·seek(io·Stream *s, long off, enum SeekPos whence); long io·tell(io·Stream *s); -/* basic os helpers */ - -int os·exists(byte *path, int flag); -byte *os·dirname(byte *path); -byte *os·basename(byte *path); -int os·sep(void); - -/* io interfaces */ /* buffered i/o */ typedef struct io·Buffer io·Buffer; +#define iota(x) (1 << (x)) enum { - bufio·size = 2*4096, - bufio·ungets = 8, - bufio·eof = -1, - bufio·err = -2, - - bufio·nil = 1 << 0, - bufio·rdr = 1 << 1, - bufio·wtr = 1 << 2, - bufio·end = 1 << 3, + io·BufEof = -1, + io·BufErr = -2, + io·BufUngets = 8, + io·BufMagic = 0x314159, + io·BufLen = 2*4096, + + /* state */ + io·BufNil = iota(0), + io·BufRdr = iota(1), + io·BufWtr = iota(2), + io·BufEnd = iota(3) }; +#undef iota struct io·Buffer { - int state; - int runesize; - void *h; - union { - io·Reader rdr; - io·Writer wtr; - }; - vlong size; - byte *beg, *pos, *end; - byte buf[bufio·size + bufio·ungets]; + int state, id, flag; + struct{ + int in; /* negative number of bytes at end */ + int out; /* number of bytes at start */ + int line; /* number of bytes after last readline */ + } off; + intptr pos, cap; /* position in file, capacity of buffer */ + uchar *b,*g,*e; /* start, good bytes, end of byte pointers */ + uchar bytes[]; }; -int bufio·initreader(io·Buffer *buf, io·Reader rdr, void *h); -void bufio·finireader(io·Buffer *buf); -int bufio·getbyte(io·Buffer *buf); -int bufio·ungetbyte(io·Buffer *buf, byte c); -int bufio·read(io·Buffer *buf, int sz, int n, void *out); +int bio·init(io·Buffer *io, int fd, int mode); +int bio·initcap(io·Buffer *io, int fd, int mode, int cap); + +/* basic os helpers */ +/* XXX: find a better location for this */ +int os·exists(byte *path, int flag); +byte *os·dirname(byte *path); +byte *os·basename(byte *path); +int os·sep(void); + -- cgit v1.2.1