aboutsummaryrefslogtreecommitdiff
path: root/main.c
blob: d6d8b1bf6e3e43eff53cab66cdd2396297b7d0d6 (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
#include "getln.h"
#include "sloth.h"
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv)
{
	(void)argc, (void)argv;
	/* Initialize sloth. */
	Sloth *const sloth = calloc(1, sizeof(Sloth));
	SlothError err;
	if (sloth == NULL)
		return 1;
	/* Read stdin line by line until exhaustion. */
	char *line = NULL;
	while ((line = getln(stdin)) != NULL) {
		err = sloth_exec_line(sloth, line);
		free(line);
		if (err != NULL) {
			fprintf(stderr, "%s\n", err);
			break;
		}
	}
	/* Free everything. */
	getln_cleanup();
	sloth_deinit(sloth);
	free(sloth);
	return 0;
}