-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.a68
137 lines (106 loc) · 2.94 KB
/
globals.a68
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- coding: utf-8 -*- #
PR include "types/task.a68" PR
PR include "types/group.a68" PR
PR include "quick sort.a68" PR
PR include "unix.a68" PR
PR include "csv.a68" PR;
STRING
data path = "/home/" + whoami + "/.local/share/pastel",
tasks data path = data path + "/tasks.csv",
notes data path = data path + "/notes.csv",
weeks data path = data path + "/weeks.csv",
groups data path = data path + "/groups.csv",
last id data path = data path + "/last id.txt";
CHAR esc = REPR 27;
PROC get argv = (INT argi, STRING err msg) STRING: (
IF argi > a68g argc THEN
putf(stand error, ($g"[31m"gg"[m"ll$, esc, err msg, esc));
stop
FI;
a68g argv(argi)
);
PROC read csv slowly = (STRING path, PROC (FLEXCSVFIELDS) VOID callback) VOID: (
FILE f;
openf(f, path, stand in channel);
read csv(f, callback);
close(f)
);
PROC get all tasks = (PROC (TASK) VOID callback) VOID:
read csv slowly(tasks data path, (FLEXCSVFIELDS fields) VOID:
callback(csv to task(fields))
);
PROC get all notes = (PROC (NOTE) VOID callback) VOID:
read csv slowly(notes data path, (FLEXCSVFIELDS fields) VOID:
callback(csv to note(fields))
);
PROC get all groups = (PROC (GROUP) VOID callback) VOID:
read csv slowly(groups data path, (FLEXCSVFIELDS fields) VOID:
callback(csv to group(fields))
);
PROC get all weeks = (PROC (WEEK) VOID callback) VOID:
read csv slowly(weeks data path, (FLEXCSVFIELDS fields) VOID:
callback(csv to week(fields))
);
PROC find weeks = (PROC (WEEK) BOOL callback) WEEK: (
WEEK week;
get all weeks((WEEK w) VOID: (
week := w;
IF callback(w) THEN
done
FI
));
done: week
);
PROC get today tasks = [] TASK: (
FLEX [0] TASK tasks;
get all tasks((TASK task) VOID:
IF date OF task = today date THEN
tasks +:= task
FI
);
tasks
);
PROC get today notes = [] NOTE: (
FLEX [0] NOTE notes;
get all notes((NOTE note) VOID:
IF date OF note = today date THEN
notes +:= note
FI
);
notes
);
PROC get today groups = [] GROUP: (
FLEX [0] GROUP groups;
read csv slowly(groups data path, (FLEXCSVFIELDS fields) VOID: (
GROUP group = csv to group(fields);
IF date OF group = today date THEN
groups +:= group
FI
));
groups
);
PROC get today items = [] ITEM: (
[] TASK tasks = get today tasks;
[] NOTE notes = get today notes;
[] GROUP groups = get today groups;
FLEX [0] ITEM items;
FOR i TO UPB tasks DO items +:= ITEM(tasks[i]) OD;
FOR i TO UPB notes DO items +:= ITEM(notes[i]) OD;
quick sort(items, 1, UPB items);
FOR i TO UPB groups DO
FLEX [0] ITEM these items;
FLEX [0] ITEM other items;
INT append index := 1;
FOR j TO UPB items DO
ITEM item = items[j];
INT id = get item id(item);
BOOL in group = includes(ids OF groups[i], id);
(in group | these items | other items) +:= item;
IF in group AND append index = 1 AND (get item time(item) :/=: REF TIME(NIL)) THEN
append index := j
FI
OD;
items := other items[:append index] + these items + other items[append index + 1:]
OD;
items
)