swissChili | 923b536 | 2021-05-09 20:31:43 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdbool.h> |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | #define MIN(a, b) (a) > (b) ? (b) : (a) |
| 7 | |
| 8 | struct istream |
| 9 | { |
| 10 | void *data; |
| 11 | |
| 12 | // These two return -1 on error |
| 13 | int (*peek)(struct istream *s); |
| 14 | int (*get)(struct istream *s); |
| 15 | |
| 16 | int (*read)(struct istream *s, char *buffer, int size); |
| 17 | |
| 18 | void (*showpos)(struct istream *s, FILE *out); |
| 19 | }; |
| 20 | |
| 21 | struct istream *new_stristream(char *str, int length); |
| 22 | // same as above but null terminated |
| 23 | struct istream *new_stristream_nt(char *str); |
| 24 | void del_stristream(struct istream *stristream); |
| 25 | |
| 26 | struct istream *new_fistream(char *path, bool binary); |
| 27 | void del_fistream(struct istream *fistream); |