From 83beaa3ad50a6c0f51660bfa0a60a832f3f85475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Mon, 16 Jun 2025 11:04:32 +0200 Subject: [PATCH] cleaned awk scripts, str escape bugfix, proper use of local variables --- src/awk/approx.awk | 123 +++++++++++++++++++++++++------------------ src/awk/calannot.awk | 6 +++ src/awk/calshift.awk | 4 ++ src/awk/dayview.awk | 62 +++++++++++++++++++--- src/awk/get.awk | 33 +++++++----- src/awk/merge.awk | 14 +++-- src/awk/new.awk | 107 ++++++++++++++++++++++--------------- src/awk/parse.awk | 109 +++++++++++++++++++++++--------------- src/awk/set.awk | 28 ++++++++-- src/awk/update.awk | 95 +++++++++++++++++++-------------- src/awk/weeks.awk | 44 ---------------- src/awk/weekview.awk | 38 ++++++++----- 12 files changed, 401 insertions(+), 262 deletions(-) delete mode 100644 src/awk/weeks.awk diff --git a/src/awk/approx.awk b/src/awk/approx.awk index 4478d11..2708044 100644 --- a/src/awk/approx.awk +++ b/src/awk/approx.awk @@ -1,79 +1,102 @@ +## src/awk/approx.awk +## Generate single-line approximate information for every iCalendar argument. +## +## @assign collection_labels: See configuration of the current program. + +# Functions + +# parse +# Time-zone aware parsing of the date/date-time entry at the current record. +# +# @local variables: dt +# @return: date or date-time string that can be used in date (1) function parse( dt) { # Get timezone information - dt = ""; for (i=2; i 1 ? path[depth-1] : ""; - collection = collection in collection2label ? collection2label[collection] : collection; + summary = substr(summary, index(summary, ":") + 1) + gsub("\\\\n", " ", summary) + gsub("\\\\N", " ", summary) + gsub("\\\\,", ",", summary) + gsub("\\\\;", ";", summary) + gsub("\\\\\\\\", "\\", summary) + gsub("\\|", ":", summary) # we use "|" as delimiter + depth = split(FILENAME, path, "/") + collection = depth > 1 ? path[depth-1] : "" + collection = collection in collection2label ? collection2label[collection] : collection return FAINT "~ " collection " " gensub(/^[^0-9]*([0-9]{4})([0-9]{2}).*$/, "\\1-\\2", "1", start) " " summary OFF } -BEGIN { - FS="[:;=]"; - OFS="|" - split(collection_labels, mapping, ";"); +# AWK program +BEGIN { + FS="[:;=]" + OFS="|" + split(collection_labels, mapping, ";") for (map in mapping) { - split(mapping[map], m, "="); - collection2label[m[1]] = m[2]; + split(mapping[map], m, "=") + collection2label[m[1]] = m[2] } # Colors - GREEN = "\033[1;32m"; - RED = "\033[1;31m"; - WHITE = "\033[1;97m"; - CYAN = "\033[1;36m"; - FAINT = "\033[2m"; - OFF = "\033[m"; + FAINT = "\033[2m" + OFF = "\033[m" } BEGINFILE { inside = 0; rs = 0; dur = 0; summary = ""; start = "ERROR"; end = "ERROR" } -/^END:VEVENT/ { print "~", start, dur ? start " " end : end, title(start, summary), fn(FILENAME, n, a); nextfile } -/^DTSTART/ && inside { start = parse( dt) } -/^DTEND/ && inside { end = parse( dt) } -/^DURATION/ && inside { end = parse_duration( dt, dta, i, n, a, seps); dur = 1 } +/^END:VEVENT/ { print "~", start, dur ? start " " end : end, title(start, summary), fn(FILENAME); nextfile } +/^DTSTART/ && inside { start = parse() } +/^DTEND/ && inside { end = parse() } +/^DURATION/ && inside { end = parse_duration($NF); dur = 1 } /^[^ ]/ && rs { rs = 0 } -/^ / && rs { summary = summary substr($0, 2); } -/^SUMMARY/ && inside { rs = 1; summary = $0; } +/^ / && rs { summary = summary substr($0, 2) } +/^SUMMARY/ && inside { rs = 1; summary = $0 } /^BEGIN:VEVENT/ { inside = 1 } diff --git a/src/awk/calannot.awk b/src/awk/calannot.awk index 31ab8ab..47473eb 100644 --- a/src/awk/calannot.awk +++ b/src/awk/calannot.awk @@ -1,3 +1,9 @@ +## src/awk/calannot.awk +## Annotate monthly calendar +## +## @assign cur: Day-of-month to mark as `today` +## @assign day: Day-of-month to highlight + BEGIN { BLACK = "\033[1;30m" GREEN = "\033[1;32m" diff --git a/src/awk/calshift.awk b/src/awk/calshift.awk index a945404..d0f1e4a 100644 --- a/src/awk/calshift.awk +++ b/src/awk/calshift.awk @@ -1,3 +1,7 @@ +## src/awk/calshift.awk +## Rearrange days of a monthly output from cal (1), such that Monday is the +## first day of the week. + BEGIN { ORS = "" W3 = " " diff --git a/src/awk/dayview.awk b/src/awk/dayview.awk index f360b64..718aaa6 100644 --- a/src/awk/dayview.awk +++ b/src/awk/dayview.awk @@ -1,20 +1,69 @@ -# $s|$e|$starttime|$endtime|$fpath|$collection|$description +## src/awk/dayview.awk +## Generate the view of a day from lines of the form +## ``` +## |||||| +## ```. +## +## @assign today: Date of `today` in the format %D (%m/%d/%y) +## @assign daystart: Hour of start of the day +## @assign dayend: Hour of end of the day + +# Functions + +# allday +# Return line for all-day event. +# +# @input collection: Collection symbol +# @input desc: Event description +# @return: Single-line string function allday(collection, desc) { return collection " " ITALIC FAINT " (allday) " OFF desc } + +# endstoday +# Return line for multi-day event, or event that starts at midnight, which ends today. +# +# @input stop: Time at which the event ends +# @input collection: Collection symbol +# @input desc: Event description +# @return: Single-line string function endstoday(stop, collection, desc) { return collection " " CYAN " -- " stop OFF ": " desc } + +# slice +# Return line for event that starts sometime today. +# +# @input start: Time at which the event starts +# @input stop: Time at which the event ends +# @input collection: Collection symbol +# @input desc: Event description +# @return: Single-line string function slice(start, stop, collection, desc) { if (stop == "00:00") return collection " " CYAN start " -- " OFF ": " desc else return collection " " CYAN start OFF " -- " CYAN stop OFF ": " desc } + +# hrline +# Print line for a single hour entry. +# +# @input hour: Hour of the entry function hrline(hour) { hour = hour < 10 ? "0"hour : hour print today, hour, "", "", "", " " FAINT hour ":00 ----------------------" OFF } + +# hrlines +# Print lines for hour entries before an event that starts at `start` and stops +# at `stop`. +# +# @local variables: starth, stoph, tmp, i +# @input start: Time at which the event starts +# @input stop: Time at which the event ends +# @input h: Last event-free hour +# @return: Hour of now last event-free hour function hrlines(start, stop, h, starth, stoph, tmp, i) { starth = substr(start, 1, 2) stoph = substr(stop, 1, 2) @@ -27,11 +76,10 @@ function hrlines(start, stop, h, starth, stoph, tmp, i) { else return stoph + tmp } + +# AWK program BEGIN { FS = "|" - GREEN = "\033[1;32m" - RED = "\033[1;31m" - WHITE = "\033[1;97m" CYAN = "\033[1;36m" ITALIC = "\033[3m" FAINT = "\033[2m" @@ -41,9 +89,7 @@ BEGIN { $1 == "00:00" && $2 == "00:00" { print today, $1, $3, $4, $5, allday($6, $7); next } $1 == "00:00" { print today, $1, $3, $4, $5, endstoday($2, $6, $7); next } $1 ~ /^[0-9]{2}:[0-9]{2}$/ { - daystart = hrlines($1, $2, daystart, starth, stoph, tmp, i) + daystart = hrlines($1, $2, daystart) print today, $1, $3, $4, $5, slice($1, $2, $6, $7) } -END { - hrlines(dayend":00", 0, daystart, starth, stoph, tmp, i) -} +END { hrlines(dayend":00", 0, daystart) } diff --git a/src/awk/get.awk b/src/awk/get.awk index b8f9cec..d858dc8 100644 --- a/src/awk/get.awk +++ b/src/awk/get.awk @@ -1,18 +1,23 @@ -# print content of field `field` -BEGIN { FS = ":"; regex = "^" field; } -/^BEGIN:VEVENT$/ { inside = 1 } -/^END:VEVENT$/ { exit } -$0 ~ regex { content = $0; next; } -/^ / && content { content = content substr($0, 2); next; } -/^[^ ]/ && content { exit } +## src/awk/get.awk +## Print content of a field of an iCalendar file. +## +## @assign field: Field name + +# AWK program +BEGIN { FS = ":"; regex = "^" field } +/^BEGIN:VEVENT$/ { inside = 1 } +/^END:VEVENT$/ { exit } +$0 ~ regex { content = $0; next } +/^ / && content { content = content substr($0, 2); next } +/^[^ ]/ && content { exit } END { if (!inside) { exit } # Process content line - content = substr(content, index(content, ":") + 1); - gsub("\\\\n", "\n", content); - gsub("\\\\N", "\n", content); - gsub("\\\\,", ",", content); - gsub("\\\\;", ";", content); - gsub("\\\\\\\\", "\\", content); - print content; + content = substr(content, index(content, ":") + 1) + gsub("\\\\n", "\n", content) + gsub("\\\\N", "\n", content) + gsub("\\\\,", ",", content) + gsub("\\\\;", ";", content) + gsub("\\\\\\\\", "\\", content) + print content } diff --git a/src/awk/merge.awk b/src/awk/merge.awk index edd5034..49f46a3 100644 --- a/src/awk/merge.awk +++ b/src/awk/merge.awk @@ -1,9 +1,15 @@ +## src/awk/merge.awk +## Merge a file that contains pairs of lines for start and end dates of events +## with the approximate data file, and group the iCalendar file paths according +## to the weeks at which the events take place. + +# AWK program BEGIN { FS="|" } NR == FNR { - i = i + 1; + i = i + 1 from_year[i] = $1 from_week[i] = $2 - getline; + getline to_year[i] = $1 to_week[i] = $2 next @@ -19,9 +25,9 @@ NR == FNR { week[label] = week[label] " " $5 week_i++ if (week_i > 53) { - week_ = 1 + week_i = 1 year_i++ } } } -END { for (label in week) print label week[label]; } +END { for (label in week) print label week[label] } diff --git a/src/awk/new.awk b/src/awk/new.awk index 1759827..545d0bd 100644 --- a/src/awk/new.awk +++ b/src/awk/new.awk @@ -1,36 +1,57 @@ +## src/awk/new.awk +## Generate iCalendar file from markdown description. +## +## @assign uid: UID to use + +# Functions + +# escape +# Escape string to be used as content in iCalendar files. +# +# @input str: String to escape +# @return: Escaped string function escape(str) { - gsub("\\\\", "\\\\", str); - gsub(";", "\\\\;", str); - gsub(",", "\\\\,", str); + gsub("\\\\", "\\\\", str) + gsub(";", "\\\\;", str) + gsub(",", "\\\\,", str) + return str } +# print_fold +# Print property with its content and fold according to the iCalendar +# specification. +# +# @local variables: i, s +# @input nameparam: Property name with optional parameters +# @input content: Escaped content function print_fold(nameparam, content, i, s) { - i = 74 - length(nameparam); - s = substr(content, 1, i); - print nameparam s; - s = substr(content, i+1, 73); - i = i + 73; + i = 74 - length(nameparam) + s = substr(content, 1, i) + print nameparam s + s = substr(content, i+1, 73) + i = i + 73 while (s) { - print " " s; - s = substr(content, i+1, 73); - i = i + 73; + print " " s + s = substr(content, i+1, 73) + i = i + 73 } } +# AWK program BEGIN { - FS=":"; - zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1); + FS=":" + zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1) } -desc { desc = desc "\\n" $0; next; } +desc { desc = desc "\\n" $0; next } { - from = substr($0, 1, 6) == "::: |>" ? substr($0, 8) : ""; + from = substr($0, 1, 6) == "::: |>" ? substr($0, 8) : "" if (!from) exit 1 getline - to = substr($0, 1, 6) == "::: <|" ? substr($0, 8) : ""; + to = substr($0, 1, 6) == "::: <|" ? substr($0, 8) : "" if (!to) exit 1 getline @@ -41,28 +62,28 @@ desc { desc = desc "\\n" $0; next; } exit 1 getline # This line should be empty getline # First line of description - desc = $0; - next; + desc = $0 + next } END { # Sanitize input - # If nanoseconds are not 0, then we assume user enterd "tomorrow" or + # If nanoseconds are not 0, then we assume user entered "tomorrow" or # something the like, and we make this a date entry, as opposed to a # date-time entry. - # Similalry, if the time is 00:00, we make this a date, as opposed to a + # Similarly, if the time is 00:00, we make this a date, as opposed to a # date-time entry. gsub("\"", "\\\"", from) - cmd = "date -d \"" from "\" +\"%N\""; + cmd = "date -d \"" from "\" +\"%N\"" cmd | getline n close(cmd) n = n + 0 - cmd = "date -d \"" from "\" +\"%H%M\""; + cmd = "date -d \"" from "\" +\"%H%M\"" cmd | getline t close(cmd) t = t + 0 if (n != 0 || t == 0) { from_type = "DATE" - cmd = "date -d \"" from "\" +\"%Y%m%d\""; + cmd = "date -d \"" from "\" +\"%Y%m%d\"" } else { from_type = "DATE-TIME" cmd = "date -d \"" from "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d" @@ -74,17 +95,17 @@ END { } # gsub("\"", "\\\"", to) - cmd = "date -d \"" to "\" +\"%N\""; + cmd = "date -d \"" to "\" +\"%N\"" cmd | getline n close(cmd) n = n + 0 - cmd = "date -d \"" to "\" +\"%H%M\""; + cmd = "date -d \"" to "\" +\"%H%M\"" cmd | getline t close(cmd) t = t + 0 if (n != 0 || t == 0) { to_type = "DATE" - cmd = "date -d \"" to "\" +\"%Y%m%d\""; + cmd = "date -d \"" to "\" +\"%Y%m%d\"" } else { to_type = "DATE-TIME" cmd = "date -d \"" to "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d" @@ -94,28 +115,28 @@ END { if (suc != 1) { exit 1 } - escape(summary); - escape(location); - escape(desc); + summary = escape(summary) + location = escape(location) + desc = escape(desc) # print ical - print "BEGIN:VCALENDAR"; - print "VERSION:2.0"; - print "CALSCALE:GREGORIAN"; - print "PRODID:-//fab//awk//EN"; + print "BEGIN:VCALENDAR" + print "VERSION:2.0" + print "CALSCALE:GREGORIAN" + print "PRODID:-//fab//awk//EN" print "BEGIN:VEVENT" - print "DTSTAMP:" zulu; - print "UID:" uid; - print "CLASS:PRIVATE"; - print "CREATED:" zulu; - print "SEQUENCE:1"; - print "LAST-MODIFIED:" zulu; - print "STATUS:VEVENT"; + print "DTSTAMP:" zulu + print "UID:" uid + print "CLASS:PRIVATE" + print "CREATED:" zulu + print "SEQUENCE:1" + print "LAST-MODIFIED:" zulu + print "STATUS:VEVENT" print "DTSTART;VALUE=" from_type ":" from print "DTEND;VALUE=" to_type ":" to - if (summary) print_fold("SUMMARY:", summary, i, s); - if (desc) print_fold("DESCRIPTION:", desc, i, s); - if (location) print_fold("LOCATION:", location, i, s); + if (summary) print_fold("SUMMARY:", summary) + if (desc) print_fold("DESCRIPTION:", desc) + if (location) print_fold("LOCATION:", location) print "END:VEVENT" print "END:VCALENDAR" } diff --git a/src/awk/parse.awk b/src/awk/parse.awk index 020d6e5..fbb0c16 100644 --- a/src/awk/parse.awk +++ b/src/awk/parse.awk @@ -1,46 +1,72 @@ +## src/awk/parse.awk +## Parse iCalendar file and print its key aspects: +## ``` +## +## ```. +## +## @assign collection_labels: See configuration of the current program. + +# Functions + +# parse +# Time-zone aware parsing of the date/date-time entry at the current record. +# +# @local variables: dt +# @return: date or date-time string that can be used in date (1) function parse( dt) { # Get timezone information - dt = ""; for (i=2; i 1 ? path[depth-1] : ""; - collection = collection in collection2label ? collection2label[collection] : collection; + collection = depth > 1 ? path[depth-1] : "" + collection = collection in collection2label ? collection2label[collection] : collection collection = collection2label[path[depth-1]] end = dur ? start " " end : end cmd = "date -d '" start "' +\"%s\"" @@ -52,20 +78,21 @@ function print_data(start, dur, end, summary, cmd, collection) { print start, end, fpath, collection, summary } -BEGIN { - FS="[:;=]"; - split(collection_labels, mapping, ";"); +# AWK program +BEGIN { + FS="[:;=]" + split(collection_labels, mapping, ";") for (map in mapping) { - split(mapping[map], m, "="); - collection2label[m[1]] = m[2]; + split(mapping[map], m, "=") + collection2label[m[1]] = m[2] } } -/^END:VEVENT/ && inside { print_data(start, dur, end, summary, cmd, collection); exit } -/^DTSTART/ && inside { start = parse( dt) } -/^DTEND/ && inside { end = parse( dt) } -/^DURATION/ && inside { end = parse_duration( dt, dta, i, n, a, seps); dur = 1 } -/^[^ ]/ && rs { rs = 0 } -/^ / && rs { summary = summary substr($0, 2); } -/^SUMMARY/ && inside { rs = 1; summary = $0; } -/^BEGIN:VEVENT/ { inside = 1 } +/^END:VEVENT/ && inside { print_data(start, dur, end, summary); exit } +/^DTSTART/ && inside { start = parse() } +/^DTEND/ && inside { end = parse() } +/^DURATION/ && inside { end = parse_duration($NF); dur = 1 } +/^[^ ]/ && rs { rs = 0 } +/^ / && rs { summary = summary substr($0, 2) } +/^SUMMARY/ && inside { rs = 1; summary = $0 } +/^BEGIN:VEVENT/ { inside = 1 } diff --git a/src/awk/set.awk b/src/awk/set.awk index be7ff49..5c899f6 100644 --- a/src/awk/set.awk +++ b/src/awk/set.awk @@ -1,13 +1,31 @@ +## src/awk/set.awk +## Set or replace the content of a specified field in the iCalendar file. +## +## @assign field: iCalendar field +## @assign value: Content to set it to +## +## LIMITATION: This program does not fold long content lines. + +# Functions + +# escape +# Escape string to be used as content. +# +# @input str: Content string +# @return: Escaped string function escape(str) { - gsub("\\\\", "\\\\", str) - gsub(";", "\\\\;", str) - gsub(",", "\\\\,", str) + gsub("\\\\", "\\\\", str) + gsub(";", "\\\\;", str) + gsub(",", "\\\\,", str) return str } -BEGIN { FS = "[:;]"; } + +# AWK program + +BEGIN { FS = "[:;]" } /^BEGIN:VEVENT$/ { inside = 1 } -/^END:VEVENT$/ { inside = 0 } +/^END:VEVENT$/ { inside = 0; if (!duplic) print field ":" escape(value) } $1 == field && inside { con = 1; duplic = 1; print field ":" escape(value); next } $1 == field && duplic { con = 1; next } /^ / && con { next } diff --git a/src/awk/update.awk b/src/awk/update.awk index 8cc99dd..1a4170f 100644 --- a/src/awk/update.awk +++ b/src/awk/update.awk @@ -1,53 +1,68 @@ -function getcontent(content_line, prop) -{ - return substr(content_line[prop], index(content_line[prop], ":") + 1); -} +## src/awk/update.awk +## Update iCalendar file from markdown file. +# Functions + +# escape +# Escape string to be used as content in iCalendar files. +# +# @input str: String to escape +# @return: Escaped string function escape(str) { - gsub("\\\\", "\\\\", str); - gsub(";", "\\\\;", str); - gsub(",", "\\\\,", str); + gsub("\\\\", "\\\\", str) + gsub(";", "\\\\;", str) + gsub(",", "\\\\,", str) + return str } +# print_fold +# Print property with its content and fold according to the iCalendar +# specification. +# +# @local variables: i, s +# @input nameparam: Property name with optional parameters +# @input content: Escaped content function print_fold(nameparam, content, i, s) { - i = 74 - length(nameparam); - s = substr(content, 1, i); - print nameparam s; - s = substr(content, i+1, 73); - i = i + 73; + i = 74 - length(nameparam) + s = substr(content, 1, i) + print nameparam s + s = substr(content, i+1, 73) + i = i + 73 while (s) { - print " " s; - s = substr(content, i+1, 73); - i = i + 73; + print " " s + s = substr(content, i+1, 73) + i = i + 73 } } +# AWK program + BEGIN { - FS=":"; - zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1); + FS=":" + zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1) } -ENDFILE { +ENDFILE { if (NR == FNR) { - # If nanoseconds are not 0, then we assume user enterd "tomorrow" or + # If nanoseconds are not 0, then we assume user entered "tomorrow" or # something the like, and we make this a date entry, as opposed to a # date-time entry. gsub("\"", "\\\"", from) - cmd = "date -d \"" from "\" +\"%N\""; + cmd = "date -d \"" from "\" +\"%N\"" cmd | getline n close(cmd) n = n + 0 - cmd = "date -d \"" from "\" +\"%H%M\""; + cmd = "date -d \"" from "\" +\"%H%M\"" cmd | getline t close(cmd) t = t + 0 if (n != 0 || t == 0) { from_type = "DATE" - cmd = "date -d \"" from "\" +\"%Y%m%d\""; + cmd = "date -d \"" from "\" +\"%Y%m%d\"" } else { from_type = "DATE-TIME" cmd = "date -d \"" from "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d" @@ -59,17 +74,17 @@ ENDFILE { } # gsub("\"", "\\\"", to) - cmd = "date -d \"" to "\" +\"%N\""; + cmd = "date -d \"" to "\" +\"%N\"" cmd | getline n close(cmd) n = n + 0 - cmd = "date -d \"" to "\" +\"%H%M\""; + cmd = "date -d \"" to "\" +\"%H%M\"" cmd | getline t close(cmd) t = t + 0 if (n != 0 || t == 0) { to_type = "DATE" - cmd = "date -d \"" to "\" +\"%Y%m%d\""; + cmd = "date -d \"" to "\" +\"%Y%m%d\"" } else { to_type = "DATE-TIME" cmd = "date -d \"" to "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d" @@ -79,19 +94,19 @@ ENDFILE { if (suc != 1) { exit 1 } - escape(summary); - escape(location); - escape(desc); + summary = escape(summary) + location = escape(location) + desc = escape(desc) } } -NR == FNR && desc { desc = desc "\\n" $0; next; } +NR == FNR && desc { desc = desc "\\n" $0; next } NR == FNR { - from = substr($0, 1, 6) == "::: |>" ? substr($0, 8) : ""; + from = substr($0, 1, 6) == "::: |>" ? substr($0, 8) : "" if (!from) exit 1 getline - to = substr($0, 1, 6) == "::: <|" ? substr($0, 8) : ""; + to = substr($0, 1, 6) == "::: <|" ? substr($0, 8) : "" if (!to) exit 1 getline @@ -102,24 +117,24 @@ NR == FNR { exit 1 getline # This line should be empty getline # First line of description - desc = $0; - next; + desc = $0 + next } -/^BEGIN:VEVENT$/ { inside = 1; print; next } -/^X-ALT-DESC/ && inside { next } # drop this alternative description -/^ / && inside { next } # drop this folded line (the only content with folded lines will be updated) +/^BEGIN:VEVENT$/ { inside = 1; print; next } +/^X-ALT-DESC/ && inside { next } # drop this alternative description +/^ / && inside { next } # drop this folded line (the only content with folded lines will be updated) /^(DTSTART|DTEND|SUMMARY|LOCATION|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && inside { next } # skip for now, we will write updated fields at the end -/^SEQUENCE/ && inside { seq = $2; next } # store sequence number and skip +/^SEQUENCE/ && inside { seq = $2; next } # store sequence number and skip /^END:VEVENT$/ { seq = seq ? seq + 1 : 1 print "SEQUENCE:" seq print "LAST-MODIFIED:" zulu print "DTSTART;VALUE=" from_type ":" from print "DTEND;VALUE=" to_type ":" to - print_fold("SUMMARY:", summary, i, s) - print_fold("DESCRIPTION:", desc, i, s) - print_fold("LOCATION:", location, i, s) + print_fold("SUMMARY:", summary) + print_fold("DESCRIPTION:", desc) + print_fold("LOCATION:", location) inside = "" } { print } diff --git a/src/awk/weeks.awk b/src/awk/weeks.awk deleted file mode 100644 index ee55b88..0000000 --- a/src/awk/weeks.awk +++ /dev/null @@ -1,44 +0,0 @@ -function parse( dt) { - # Get timezone information - dt = ""; - for (i=2; i") + 1) OFF " " RED "/" OFF } + +# AWK program + BEGIN { - GREEN = "\033[1;32m"; - RED = "\033[1;31m"; - WHITE = "\033[1;97m"; - CYAN = "\033[1;36m"; - FAINT = "\033[2m"; - OFF = "\033[m"; + GREEN = "\033[1;32m" + RED = "\033[1;31m" + CYAN = "\033[1;36m" + OFF = "\033[m" OFS = "|" } -/^[0-7] 00:00 -- 00:00/ { dayline = dayline " " c(); next } -/^[0-7] 00:00 -- / { dayline = dayline " <--" $4 " " c(); next } -/^[0-7] [0-9]{2}:[0-9]{2} -- 00:00/ { dayline = dayline " " $2 "→" c(); next } +/^[0-7] 00:00 -- 00:00/ { dayline = dayline " " c(); next } +/^[0-7] 00:00 -- / { dayline = dayline " <--" $4 " " c(); next } +/^[0-7] [0-9]{2}:[0-9]{2} -- 00:00/ { dayline = dayline " " $2 "→" c(); next } /^[0-7] [0-9]{2}:[0-9]{2} -- [0-9]{2}:[0-9]{2}/ { dayline = dayline " " $2 " - " $4 " " c(); next } -/^[0-7]$/ && dayline { print "+", startofweek " +" $0-1 " days", "", dayline; } +/^[0-7]$/ && dayline { print "+", startofweek " +" $0-1 " days", "", dayline } /^[0-7]$/ { - cmd = "date -d '" startofweek " +" $0 " days' +\"%a %e %b %Y\""; - cmd | getline dayline; - close(cmd); + cmd = "date -d '" startofweek " +" $0 " days' +\"%a %e %b %Y\"" + cmd | getline dayline + close(cmd) dayline = GREEN dayline ": " OFF }