-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudolisp.c
88 lines (74 loc) · 1.38 KB
/
pseudolisp.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdlib.h>
#include "parser.h"
extern void test();
#ifndef VERSION
#define VERSION "?.?.?"
#endif
static int prompt = 1;
static int cmd = 1;
void cmd_not_needed() { cmd &= ~1; }
void init()
{
set_prompt(prompt);
set_input(stdin);
}
void runargs(char *arg)
{
switch (arg[0]) {
case 't':
test();
cmd_not_needed();
break;
case 'v':
printf("PseudoLISP " VERSION ", made by Jakl Tomas.\n");
break;
case 'c':
cmd |= 2;
break;
case 'q':
set_quiet(1);
break;
case 'p':
prompt = 0;
break;
case 'h': printf(
"Usage: pseudolisp [options] [filenames]\n"
"Options:\n"
" -v\tprint version\n"
" -t\trun tests\n"
" -c\trun console\n"
" -q\tquiet (only forced ouptut)\n"
" -p\tdisable prompt\n"
" -h\tprint this help\n\n");
cmd_not_needed();
break;
default:
fprintf(stderr, "Invalid argument. Use -h for help.\n");
exit(1);
break;
}
if (*(++arg) != '\0') runargs(arg);
}
int main(int argc, char *argv[])
{
init();
char *word;
for (int i=1; i<argc; i++) {
word = argv[i];
if (word[0] == '-') runargs(++word);
else {
cmd_not_needed();
FILE *f = fopen(word, "r");
if (f == NULL) {
fprintf(stderr, "Cannot read file '%s'\n", word);
continue;
}
set_prompt(0); set_input(f);
play();
fclose(f);
}
}
if (cmd) { init(); play(); }
return 0;
}