-
Notifications
You must be signed in to change notification settings - Fork 4
/
s.c
80 lines (65 loc) · 1.27 KB
/
s.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
/* see LICENSE file for copyright and license details */
/* command line interpreter */
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include "arg.h"
#include "region.h"
#include "reporting.h"
#include "stringport.h"
#include "tokenizer.h"
#include "variables.h"
#include "parser.h"
#include "interpreter.h"
#include "builtins.h"
#define VERSION "0.1"
char *argv0;
int debug = 0;
void
handler_sigint(int sig)
{
sig = sig; /* get rid of compiler warnings from -Wextra */
/* signal(sig, SIG_IGN); */
}
static void
usage(int eval)
{
fprintf(stderr, "usage: %s [-dvh] [SCRIPT ...]\n", argv0);
exit(eval);
}
int
main(int argc, char **argv)
{
FILE *f;
ARGBEGIN {
case 'd':
debug = 1;
break;
case 'v':
printf("%s v%s (c) 2014, 2016, 2017 s team\n", argv0, VERSION);
return 0;
case 'h':
usage(0);
return 0;
default:
usage(1);
return 1;
} ARGEND;
signal(SIGINT, handler_sigint);
setenv("SHELL", "/bin/s", 1);
if (argc == 1) {
f = stdin;
interactive_mode = isatty(fileno(stdin));
} else {
if (!(f = fopen(argv[1], "r")))
reporterr("source: %s: could not load file", argv[1]);
vars_set(argv);
interactive_mode = 0;
}
interpreter_loop(f);
return 0;
}