~swisschili/bluejay

ref: 6d02af472f6ce87ea50ff24aa77f88928dbf31bc bluejay/src/lisp/istream.h -rw-r--r-- 796 bytes
6d02af47swissChili Add detailed error reporting, remove panics 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once

#include <stdbool.h>
#include <stdio.h>

#define MIN(a, b) (a) > (b) ? (b) : (a)

/// Virtual class representing an input stream. Subclasses must implement every
/// function.
struct istream
{
	void *data;

	/// Returns -1 on error
	int (*peek)(struct istream *s);
	/// Returns -1 on error
	int (*get)(struct istream *s);

	int (*read)(struct istream *s, char *buffer, int size);

	void (*showpos)(struct istream *s, FILE *out);

	void (*getpos)(struct istream *s, int *line, char **name);
};

struct istream *new_stristream(char *str, int length);
// same as above but null terminated
struct istream *new_stristream_nt(char *str);
void del_stristream(struct istream *stristream);

struct istream *new_fistream(char *path, bool binary);
void del_fistream(struct istream *fistream);