blob: 1f4c57e33d0e0938cce57f5a3a01ff64612e4924 (
plain) (
blame)
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
|
#include <acm/gfx.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <zap/mem.h>
sig_atomic_t volatile acm_gotintr;
typeof (acm_dat) acm_dat;
static char * acm_getsavloc(void) {
char const * const hmdir = getenv("HOME");
if (hmdir == nullptr) {
fprintf(stderr,"Unable to get home directory (HOME not set)\n");
acm_exit(acm_stat_err);
}
char const * const savfilnm = ".procyon-save";
zap_sz const hmdirlen = zap_strlen(hmdir);
zap_sz const savfilnmlen = zap_strlen(savfilnm);
zap_sz const savloclen = hmdirlen + 0x1u + savfilnmlen;
char * savloc = malloc(savloclen + 0x1u);
if (savloc == nullptr) {
fprintf(stderr,"Unable allocate memory\n");
acm_exit(acm_stat_err);
}
zap_memcp(hmdir,hmdirlen,savloc);
savloc[hmdirlen] = '/';
zap_memcp(savfilnm,savfilnmlen,savloc + hmdirlen + 0x1u);
savloc[savloclen] = 0x0u;
return savloc;
}
static void acm_intrhandl(int const _sig) {
signal(_sig,acm_intrhandl); /* Ignore the return value. */
acm_gotintr = 0x1;
}
void acm_init(void) {
acm_gotintr = 0x0;
acm_dat.gfxisinit = false;
acm_dat.win = nullptr;
acm_log("Initialising data\n");
acm_dat.savloc = acm_getsavloc();
acm_log("Initialising signal handlers\n");
if (signal(SIGINT,acm_intrhandl) == SIG_ERR) {
fprintf(stderr,"Unable to set SIGINT handler\n");
acm_exit(acm_stat_err);
}
acm_initgfx();
}
|