This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
main.c
89 lines (70 loc) · 1.67 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
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
89
#include <signal.h>
#include <execinfo.h>
#include "src/editor.h"
#ifdef __unix__
#ifdef gnome
#include <gtk/gtk.h>
#endif
#endif
#define STRINGIFY2(X) #X
#define STRINGIFY(X) STRINGIFY2(X)
e_context* GLOB;
syntax** stx;
// This does not free.
// After a segfault we shouldn't be messing with memory
void handler(int sig) {
disable_raw_mode(GLOB);
void* array[10];
size_t size;
size = backtrace(array, 10);
fputs("e has crashed. If you want to file a bug report, please attach the following:\n", stderr);
fprintf(stderr, "Signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
exit(1);
}
void exitf() {
disable_raw_mode(GLOB);
e_context_free(GLOB);
if (stx) syntaxes_free(stx);
#ifdef WITH_LUA
if (l) e_lua_free();
#endif
}
int main(int argc, char** argv) {
#ifdef __unix__
#ifdef gnome
gtk_init(&argc, &argv);
#endif
#endif
stx = syntax_init((char*) STXDIR);
if (!stx) {
fputs("Failed to initialize e: couldn’t read syntax files.\n", stderr);
return 1;
}
GLOB = e_setup();
signal(SIGSEGV, handler);
signal(SIGABRT, handler);
atexit(exitf);
e_set_highlighting(GLOB, stx);
if (argc > 1) {
e_open(GLOB, argv[1]);
}
if (!GLOB->nrows) {
e_append_row(GLOB, (char*) "", 0);
GLOB->dirty = 0;
}
e_set_status_msg(GLOB, "HELP: :q = quit");
#ifdef WITH_LUA
char* evald = e_lua_run_file(GLOB, (char*) STRINGIFY(ERC));
if (evald) e_set_status_msg(GLOB, evald);
free(evald);
#endif
while(1) {
e_clear_screen(GLOB);
GLOB = e_process_key(GLOB);
// for reasons I'm not quite certain of this fixes the screen flicker.
// TODO: investigate better technique
msleep(20);
}
return 0;
}