-
Notifications
You must be signed in to change notification settings - Fork 0
/
reminder.c
122 lines (103 loc) · 2.57 KB
/
reminder.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* DON'T FUCKING FORGET SHIT
*
* by: Damon Getsman
*
*/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <err.h>
#include "my-ncurses.h"
#include "my-general.h"
#include "event_edit.h"
#include "notify_daemon.h"
#define SHORTMAX 40
#define FULLMAX 255
#ifndef CL_OPTS
# define CL_OPTS 1
#endif
#define DOTFILE ".reminderrc"
/* External Functions (prototypes) */
extern int *pcline(int ac, char *opts);
extern void *read_events(void *);
extern int event_editor(void *events, bool *fullscreen);
/* extern void *read_events(void *events); */
extern void list_events(void *events);
extern void add_events(void *events);
extern void del_events(void *events);
extern void ed_event(void *events);
/* primary routines */
extern int notifyd(void *events);
/* ncurses/display */
extern bool init_ncurses(void);
void *read_events(void *evnts) {
FILE *dfile;
void *buf;
int cntr = 0;
size_t chowSize;
ChowFormation tmp;
chowSize = sizeof(ChowFormation);
buf = malloc(chowSize);
strcpy(tmp.title, EOR);
if ((dfile = fopen(DOTFILE, "r")) == NULL) {
/* need to create? */
if ((dfile = fopen(DOTFILE, "w")) == NULL) {
return NULL;
} else {
err(1, "Unable to open config file for writing!");
}
} else {
while (fread(&tmp, chowSize, 1, dfile) != 0) {
memcpy(buf, &tmp, chowSize);
realloc(buf, (++cntr * chowSize));
tmp.severity = '\0';
strcpy(tmp.title, "\0");
strcpy(tmp.msg, "\0");
}
fclose(dfile);
}
#ifdef DEBUGGING
warn("\n\nFell through the bottom of read_events();");
warn("\nWTF-f-f :-?(beep)\n");
#endif
}
int main(int argc, char *argv) {
void *options, *events;
bool fullscr = false;
int tmp;
/* parse command line here */
options = pcline(argc, argv);
if (options == NULL) { /* oopthspthspthsie! */
prinf("\nUnable to allocate memory!\n");
return 1;
}
if (((bool) *options) == true) { /* we're editing */
fullscr = init_ncurses();
/* TODO: Implement non-fullscreen functionality */
while ((tmp = event_editor(events, fullscr)) != 5) {
switch (event_editor(events, fullscr)) {
case 1: /* list events */
list_events(*events);
break;
case 2: /* delete event(s) */
delete_events(*events);
break;
case 3: /* add event(s) */
add_events(*events);
break;
case 4: /* edit event */
ed_event(*events);
break;
case 5: /* exit */
return 0;
break;
default:
err("\n\nWTF?\nFell through main loop: %s\n");
}
}
} else if (((bool) *(options + 1)) == true) { /* fork & notify */
if (notifyd != 0) return 2;
}
}