Blame


1 b2cfc4e2 2003-09-30 devnull #ifndef _BIOH_
2 b2cfc4e2 2003-09-30 devnull #define _BIOH_ 1
3 b2cfc4e2 2003-09-30 devnull
4 b2cfc4e2 2003-09-30 devnull #include <sys/types.h> /* for off_t */
5 b2cfc4e2 2003-09-30 devnull #include <fcntl.h> /* for O_RDONLY, O_WRONLY */
6 b2cfc4e2 2003-09-30 devnull
7 b2cfc4e2 2003-09-30 devnull typedef struct Biobuf Biobuf;
8 b2cfc4e2 2003-09-30 devnull
9 b2cfc4e2 2003-09-30 devnull enum
10 b2cfc4e2 2003-09-30 devnull {
11 b2cfc4e2 2003-09-30 devnull Bsize = 8*1024,
12 b2cfc4e2 2003-09-30 devnull Bungetsize = 4, /* space for ungetc */
13 b2cfc4e2 2003-09-30 devnull Bmagic = 0x314159,
14 b2cfc4e2 2003-09-30 devnull Beof = -1,
15 b2cfc4e2 2003-09-30 devnull Bbad = -2,
16 b2cfc4e2 2003-09-30 devnull
17 b2cfc4e2 2003-09-30 devnull Binactive = 0, /* states */
18 b2cfc4e2 2003-09-30 devnull Bractive,
19 b2cfc4e2 2003-09-30 devnull Bwactive,
20 b2cfc4e2 2003-09-30 devnull Bracteof,
21 b2cfc4e2 2003-09-30 devnull
22 b2cfc4e2 2003-09-30 devnull Bend
23 b2cfc4e2 2003-09-30 devnull };
24 b2cfc4e2 2003-09-30 devnull
25 b2cfc4e2 2003-09-30 devnull struct Biobuf
26 b2cfc4e2 2003-09-30 devnull {
27 b2cfc4e2 2003-09-30 devnull int icount; /* neg num of bytes at eob */
28 b2cfc4e2 2003-09-30 devnull int ocount; /* num of bytes at bob */
29 b2cfc4e2 2003-09-30 devnull int rdline; /* num of bytes after rdline */
30 b2cfc4e2 2003-09-30 devnull int runesize; /* num of bytes of last getrune */
31 b2cfc4e2 2003-09-30 devnull int state; /* r/w/inactive */
32 b2cfc4e2 2003-09-30 devnull int fid; /* open file */
33 b2cfc4e2 2003-09-30 devnull int flag; /* magic if malloc'ed */
34 b2cfc4e2 2003-09-30 devnull off_t offset; /* offset of buffer in file */
35 b2cfc4e2 2003-09-30 devnull int bsize; /* size of buffer */
36 b2cfc4e2 2003-09-30 devnull unsigned char* bbuf; /* pointer to beginning of buffer */
37 b2cfc4e2 2003-09-30 devnull unsigned char* ebuf; /* pointer to end of buffer */
38 b2cfc4e2 2003-09-30 devnull unsigned char* gbuf; /* pointer to good data in buf */
39 b2cfc4e2 2003-09-30 devnull unsigned char b[Bungetsize+Bsize];
40 b2cfc4e2 2003-09-30 devnull };
41 b2cfc4e2 2003-09-30 devnull
42 b2cfc4e2 2003-09-30 devnull #define BGETC(bp)\
43 b2cfc4e2 2003-09-30 devnull ((bp)->icount?(bp)->bbuf[(bp)->bsize+(bp)->icount++]:Bgetc((bp)))
44 b2cfc4e2 2003-09-30 devnull #define BPUTC(bp,c)\
45 b2cfc4e2 2003-09-30 devnull ((bp)->ocount?(bp)->bbuf[(bp)->bsize+(bp)->ocount++]=(c),0:Bputc((bp),(c)))
46 b2cfc4e2 2003-09-30 devnull #define BOFFSET(bp)\
47 b2cfc4e2 2003-09-30 devnull (((bp)->state==Bractive)?\
48 b2cfc4e2 2003-09-30 devnull (bp)->offset + (bp)->icount:\
49 b2cfc4e2 2003-09-30 devnull (((bp)->state==Bwactive)?\
50 b2cfc4e2 2003-09-30 devnull (bp)->offset + ((bp)->bsize + (bp)->ocount):\
51 b2cfc4e2 2003-09-30 devnull -1))
52 b2cfc4e2 2003-09-30 devnull #define BLINELEN(bp)\
53 b2cfc4e2 2003-09-30 devnull (bp)->rdline
54 b2cfc4e2 2003-09-30 devnull #define BFILDES(bp)\
55 b2cfc4e2 2003-09-30 devnull (bp)->fid
56 b2cfc4e2 2003-09-30 devnull
57 b2cfc4e2 2003-09-30 devnull int Bbuffered(Biobuf*);
58 b2cfc4e2 2003-09-30 devnull int Bfildes(Biobuf*);
59 b2cfc4e2 2003-09-30 devnull int Bflush(Biobuf*);
60 b2cfc4e2 2003-09-30 devnull int Bgetc(Biobuf*);
61 b2cfc4e2 2003-09-30 devnull int Bgetd(Biobuf*, double*);
62 b2cfc4e2 2003-09-30 devnull int Binit(Biobuf*, int, int);
63 b2cfc4e2 2003-09-30 devnull int Binits(Biobuf*, int, int, unsigned char*, int);
64 b2cfc4e2 2003-09-30 devnull int Blinelen(Biobuf*);
65 b2cfc4e2 2003-09-30 devnull off_t Boffset(Biobuf*);
66 b2cfc4e2 2003-09-30 devnull Biobuf* Bopen(char*, int);
67 b2cfc4e2 2003-09-30 devnull int Bprint(Biobuf*, char*, ...);
68 b2cfc4e2 2003-09-30 devnull int Bputc(Biobuf*, int);
69 b2cfc4e2 2003-09-30 devnull void* Brdline(Biobuf*, int);
70 b2cfc4e2 2003-09-30 devnull long Bread(Biobuf*, void*, long);
71 b2cfc4e2 2003-09-30 devnull off_t Bseek(Biobuf*, off_t, int);
72 b2cfc4e2 2003-09-30 devnull int Bterm(Biobuf*);
73 b2cfc4e2 2003-09-30 devnull int Bungetc(Biobuf*);
74 522b0689 2003-09-30 devnull int Bungetrune(Biobuf*);
75 b2cfc4e2 2003-09-30 devnull long Bwrite(Biobuf*, void*, long);
76 b2cfc4e2 2003-09-30 devnull char* Brdstr(Biobuf*, int, int);
77 b2cfc4e2 2003-09-30 devnull long Bgetrune(Biobuf*);
78 b2cfc4e2 2003-09-30 devnull int Bputrune(Biobuf*, long);
79 b2cfc4e2 2003-09-30 devnull
80 b2cfc4e2 2003-09-30 devnull #endif