6973910016ec0fc7072f65c54d7a0edcec739696
[fw/altos] / src / test / ao_lisp_test.c
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #include "ao_lisp.h"
16 #include <stdio.h>
17
18 static FILE *ao_lisp_file;
19 static int newline = 1;
20
21 int
22 ao_lisp_getc(void)
23 {
24         int c;
25
26         if (ao_lisp_file)
27                 return getc(ao_lisp_file);
28
29         if (newline) {
30                 printf("> ");
31                 newline = 0;
32         }
33         c = getchar();
34         if (c == '\n')
35                 newline = 1;
36         return c;
37 }
38
39 int
40 main (int argc, char **argv)
41 {
42         while (*++argv) {
43                 ao_lisp_file = fopen(*argv, "r");
44                 if (!ao_lisp_file) {
45                         perror(*argv);
46                         exit(1);
47                 }
48                 ao_lisp_read_eval_print();
49                 fclose(ao_lisp_file);
50                 ao_lisp_file = NULL;
51         }
52         ao_lisp_read_eval_print();
53 }