fix: use CRLF line endings

This commit is contained in:
2025-12-01 11:38:11 +01:00
parent b5b78445e1
commit a23c20936c
9 changed files with 55 additions and 43 deletions

View File

@@ -15,21 +15,21 @@ function write_attachment( line, aline, fl) {
fl = 1
while (getline aline <file) {
line = line aline
if (fl && length(line) >= 73) {
print substr(line, 1, 73)
line = substr(line, 74)
if (fl && length(line) >= 72) {
print substr(line, 1, 72)"\r"
line = substr(line, 73)
fl = 0
}
while (length(line) >= 72) {
print " "substr(line, 1, 72)
line = substr(line, 73)
while (length(line) >= 71) {
print " "substr(line, 1, 71)"\r"
line = substr(line, 72)
}
}
if (line)
print " "line
print " "line"\r"
}
# AWK program
/^END:VEVENT$/ { write_attachment() }
/^END:VEVENT/ { write_attachment() }
{ print }

View File

@@ -1,4 +1,5 @@
BEGIN { FS="[:;]" }
{ gsub("\r", "") }
/^END:VEVENT$/ { ins = 0; exit }
/^[^ ]/ && a { a = 0 }
/^ / && a && p { print substr($0, 2); }

View File

@@ -34,6 +34,7 @@ function att_info(i, str, cnt, k, info) {
}
BEGIN { FS="[:;]"; OFS="\t" }
{ gsub("\r", "") }
/^END:VEVENT$/ { ins = 0; exit }
l && !r { att_info(i, l); l = "" }
/^ / && r { l = l substr($0, 2); r = cont_reading($0) }

View File

@@ -4,10 +4,10 @@
## @assign id: Attachment number to remove
BEGIN { FS="[:;]" }
/^END:VEVENT$/ { ins = 0 }
/^END:VEVENT/ { ins = 0 }
/^[^ ]/ && a { a = 0 }
/^ / && a { next }
/^ATTACH/ && ins { i++; }
/^ATTACH/ && ins && i == id { a = 1; next }
/^BEGIN:VEVENT$/ { ins = 1 }
/^BEGIN:VEVENT/ { ins = 1 }
{ print }

View File

@@ -5,6 +5,7 @@
# AWK program
BEGIN { FS = "[:;]" }
{ gsub("\r", "") }
/^BEGIN:VEVENT$/ { ins = 1 }
/^END:VEVENT$/ { exit 1 }
ins && $1 == field { exit 0 }

View File

@@ -83,23 +83,23 @@ END {
}
# print ical
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:CONFIRMED"
print "DTSTART;VALUE=" from_type ":" from
print "DTEND;VALUE=" to_type ":" to
print_cr("BEGIN:VCALENDAR")
print_cr("VERSION:2.0")
print_cr("CALSCALE:GREGORIAN")
print_cr("PRODID:-//fab//awk//EN")
print_cr("BEGIN:VEVENT")
print_cr("DTSTAMP:" zulu)
print_cr("UID:" uid)
print_cr("CLASS:PRIVATE")
print_cr("CREATED:" zulu)
print_cr("SEQUENCE:1")
print_cr("LAST-MODIFIED:" zulu)
print_cr("STATUS:CONFIRMED")
print_cr("DTSTART;VALUE=" from_type ":" from)
print_cr("DTEND;VALUE=" to_type ":" to)
if (summary) print_fold("SUMMARY:", summary)
if (desc) print_fold("DESCRIPTION:", desc)
if (location) print_fold("LOCATION:", location)
print "END:VEVENT"
print "END:VCALENDAR"
print_cr("END:VEVENT")
print_cr("END:VCALENDAR")
}

View File

@@ -9,19 +9,20 @@
@include "lib/awk/icalendar.awk"
BEGIN { FS = "[:;]"; zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1) }
{ gsub("\r", "") }
/^BEGIN:VEVENT$/ { inside = 1 }
/^END:VEVENT$/ {
inside = 0
if (!duplic)
print field ":" escape(value)
print_fold(field":", escape(value))
seq = seq ? seq + 1 : 1
print "SEQUENCE:" seq
print "LAST-MODIFIED:" zulu
print_cr("SEQUENCE:" seq)
print_cr("LAST-MODIFIED:" zulu)
}
$1 == field && inside { con = 1; duplic = 1; print field ":" escape(value); next }
$1 == field && inside { con = 1; duplic = 1; print_fold(field":", escape(value)); next }
$1 == field && duplic { con = 1; next }
/^ / && con { next }
/^[^ ]/ && con { con = 0 }
/^SEQUENCE/ && inside { seq = $2; next } # store sequence number and skip
/^LAST-MODIFIED/ && inside { next }
{ print }
{ print_cr($0) }

View File

@@ -84,10 +84,10 @@ NR == FNR {
{ gsub("\r", "") }
/^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_cr("SEQUENCE:" seq)
print_cr("LAST-MODIFIED:" zulu)
print_cr("DTSTART;VALUE=" from_type ":" from)
print_cr("DTEND;VALUE=" to_type ":" to)
print_fold("SUMMARY:", summary)
print_fold("DESCRIPTION:", desc)
print_fold("LOCATION:", location)
@@ -100,4 +100,4 @@ NR == FNR {
/^(DTSTART|DTEND|SUMMARY|LOCATION|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && inside { skipf = 1; next } # skip for now, we will write updated fields at the end
/^X-ALT-DESC/ && inside { skipf = 1; next } # skip
/^SEQUENCE/ && inside { seq = $2; next } # store sequence number and skip
{ print }
{ print_cr($0) }

View File

@@ -11,6 +11,14 @@ function escape(str)
return str
}
# Print line using \r\n ending, as required by the RFC
#
# @input str: String
function print_cr(str)
{
print str "\r"
}
# Print property with its content and fold according to the iCalendar
# specification.
#
@@ -19,16 +27,16 @@ function escape(str)
# @input content: Escaped content
function print_fold(nameparam, content, i, s)
{
i = 74 - length(nameparam)
i = 73 - length(nameparam)
s = substr(content, 1, i)
print nameparam s
s = substr(content, i+1, 73)
i = i + 73
print_cr(nameparam s)
s = substr(content, i+1, 72)
i = i + 72
while (s)
{
print " " s
s = substr(content, i+1, 73)
i = i + 73
print_cr(" " s)
s = substr(content, i+1, 72)
i = i + 72
}
}