-
Notifications
You must be signed in to change notification settings - Fork 2
/
termship.c
67 lines (51 loc) · 1.43 KB
/
termship.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
#include <ncurses.h>
#include <time.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include "common.h"
#include "screen.h"
#include "connection.h"
#include "gamepieces.h"
#include "log.h"
Player *player;
void sigsegv_handler(int sig)
{
cleanup_ncurses();
printf("Whoa, we just overwrote The Grid. Cora's dumping the core of whatever's left...\n");
fflush(stdout);
signal(sig, SIG_DFL);
kill(getpid(), sig);
}
int main() {
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sa.sa_handler = sigsegv_handler;
if (sigaction(SIGSEGV, &sa, NULL) == -1) {
perror("Couldn't set up signal handler...");
exit(EXIT_FAILURE);
}
/* seed the random number generator */
srand(time(NULL));
write_to_log("\n"
"=======================\n"
"termship is starting!!!\n"
"=======================\n");
initscr(); /* Initialize screen for curses mode */
cbreak();
noecho();
start_color(); /* start color */
/* set up some color pairs: */
/* some helpful macros to use these are defined in screen.h */
init_pair(2, COLOR_YELLOW, COLOR_BLACK);
init_pair(3, COLOR_BLUE, COLOR_BLACK);
init_pair(4, COLOR_RED, COLOR_BLACK);
init_pair(5, COLOR_BLACK, COLOR_WHITE);
init_pair(6, COLOR_WHITE, COLOR_BLACK);
init_pair(7, COLOR_GREEN, COLOR_BLACK);
init_pair(8, COLOR_WHITE, COLOR_RED);
main_menu();
cleanup_ncurses();
return 0;
}