-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathicsfiltercalendars.awk
More file actions
92 lines (80 loc) · 1.57 KB
/
icsfiltercalendars.awk
File metadata and controls
92 lines (80 loc) · 1.57 KB
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
#
# Combine all of the VCALENDARs on the standard input
# into one VCALENDAR.
#
BEGIN {
eventIndex=0
inVcalendar = 0
}
function filter(line,inCalendar) {
if (0 == inCalendar) {
event[eventIndex] = line
eventIndex ++
}
}
#
# Whenever we see the beginning of a VCALENDAR, we store subsequent
# lines in the vcal array.
#
# When we see the beginning of a VEVENT, we store it and all
# subsequent lines, including the end of the VEVENT in the event
# array.
#
# A boolean, inVcalendar, remembers whether we are processing a
# VCALENDAR or a VEVENT. We use its value to choose the array in which
# to store a line of input. When inVcalendar is non-zero, we're
# processing a VCALENDAR. When it's zero, we're processing a VEVENT.
#
# We output all lines in one big VCALENDAR: First the start of the
# calendar; then the entries from the vcal array in FIFO order; then
# the entries from the event array in FIFO order; finally, the end of
# the calendar.
#
/^BEGIN:VCALENDAR/ {
inVcalendar = 1
next
}
/^END:VCALENDAR/ {
inVcalendar = 0
next
}
/^BEGIN:VEVENT/ {
inVcalendar = 0
filter($0, inVcalendar)
next
}
/^END:VEVENT/ {
filter($0, inVcalendar)
inVcalendar = 1
next
}
/^BEGIN:VTODO/ {
inVcalendar = 0
filter($0, inVcalendar)
next
}
/^END:VTODO/ {
filter($0, inVcalendar)
inVcalendar = 1
next
}
/^BEGIN:VJOURNAL/ {
inVcalendar = 0
filter($0, inVcalendar)
next
}
/^END:VJOURNAL/ {
filter($0, inVcalendar)
inVcalendar = 1
next
}
{
filter($0, inVcalendar)
}
END {
print "BEGIN:VCALENDAR"
for (i=0; i < eventIndex; i++) {
print event[i]
}
print "END:VCALENDAR"
}