blob: 882a740f72aa218ca1f156c1873a4362241f7447 [file] [log] [blame]
swissChili923b5362021-05-09 20:31:43 -07001#pragma once
2
3#include <stdbool.h>
4#include <stdio.h>
5
6#define MIN(a, b) (a) > (b) ? (b) : (a)
7
swissChilid24cd202021-07-02 13:30:58 -07008/// Virtual class representing an input stream. Subclasses must implement every
9/// function.
swissChili923b5362021-05-09 20:31:43 -070010struct istream
11{
12 void *data;
13
swissChilid24cd202021-07-02 13:30:58 -070014 /// Returns -1 on error
swissChili923b5362021-05-09 20:31:43 -070015 int (*peek)(struct istream *s);
swissChilid24cd202021-07-02 13:30:58 -070016 /// Returns -1 on error
swissChili923b5362021-05-09 20:31:43 -070017 int (*get)(struct istream *s);
18
19 int (*read)(struct istream *s, char *buffer, int size);
20
21 void (*showpos)(struct istream *s, FILE *out);
swissChilid24cd202021-07-02 13:30:58 -070022
23 void (*getpos)(struct istream *s, int *line, char **name);
swissChili923b5362021-05-09 20:31:43 -070024};
25
26struct istream *new_stristream(char *str, int length);
27// same as above but null terminated
28struct istream *new_stristream_nt(char *str);
29void del_stristream(struct istream *stristream);
30
31struct istream *new_fistream(char *path, bool binary);
32void del_fistream(struct istream *fistream);