blob: bab5439993955407a7de08eaf31e316e9927c559 [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);
swissChili53e7cd12021-08-02 21:55:53 -070032void del_fistream(struct istream *fistream);