summaryrefslogtreecommitdiff
path: root/input.c
blob: 9dc524cb97b87048603683e2d0cf5f2ef5118507 (plain)
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
33
34
/*
 * input.c: read the source form
 */

#include <stdio.h>
#include <assert.h>
#include "buttress.h"

static void unget(input *in, char c) {
    assert(in->npushback < INPUT_PUSHBACK_MAX);
    in->pushback[in->npushback++] = c;
}

/*
 * Can return EOF
 */
static int get(input *in) {
    if (in->npushback)
	return (unsigned char)in->pushback[--in->npushback];
    else if (in->currfp) {
	int c = getc(in->currfp);
	if (c == EOF) {
	    fclose(in->currfp);
	    in->currfp = NULL;
	    in->currindex++;
	}
	return c;
    } else
	return EOF;
}

paragraph *read_input(input *in) {
    /* FIXME: do some reading */
}