-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
58 lines (52 loc) · 1.07 KB
/
main.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
#include <stdlib.h>
#include <setjmp.h>
#include <stdio.h>
#include "ll.h"
#include "ed.h"
#include "parse.h"
#include "undo.h"
#include "io.h"
jmp_buf to_repl;
static char *repl_line = NULL;
static void free_repl_line() {
free(repl_line);
}
void repl() {
size_t linecap;
if (!opt_readline) {
atexit(free_repl_line);
}
setjmp(to_repl);
while (io_read_line(&repl_line, &linecap, stdin, get_prompt()) > 0) {
eval(parse(repl_line));
if (opt_readline) {
free(repl_line);
repl_line = NULL;
}
if (opt_history && repl_line[0] != '\0') {
}
}
}
int main(int argc, char *argv[]) {
int optindex = parse_args(argc, argv);
ll_init();
fptr_init();
un_fptr_init();
gbl_buffers_init();
/* The FILE argument was provided */
if (optindex < argc) {
/* FILE is a shell command, prepare the string */
if (argv[optindex][0] == '!') {
set_command_buf(argv[optindex]);
for (int i = optindex+1; i < argc; ++i) {
append_command_buf(" ");
append_command_buf(argv[i]);
}
edit_aux(get_command_buf());
}
else {
edit_aux(argv[optindex]);
}
}
repl();
}