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 fl = 1
while (getline aline <file) { while (getline aline <file) {
line = line aline line = line aline
if (fl && length(line) >= 73) { if (fl && length(line) >= 72) {
print substr(line, 1, 73) print substr(line, 1, 72)"\r"
line = substr(line, 74) line = substr(line, 73)
fl = 0 fl = 0
} }
while (length(line) >= 72) { while (length(line) >= 71) {
print " "substr(line, 1, 72) print " "substr(line, 1, 71)"\r"
line = substr(line, 73) line = substr(line, 72)
} }
} }
if (line) if (line)
print " "line print " "line"\r"
} }
# AWK program # AWK program
/^END:VEVENT$/ { write_attachment() } /^END:VEVENT/ { write_attachment() }
{ print } { print }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -84,10 +84,10 @@ NR == FNR {
{ gsub("\r", "") } { gsub("\r", "") }
/^END:VEVENT$/ { /^END:VEVENT$/ {
seq = seq ? seq + 1 : 1 seq = seq ? seq + 1 : 1
print "SEQUENCE:" seq print_cr("SEQUENCE:" seq)
print "LAST-MODIFIED:" zulu print_cr("LAST-MODIFIED:" zulu)
print "DTSTART;VALUE=" from_type ":" from print_cr("DTSTART;VALUE=" from_type ":" from)
print "DTEND;VALUE=" to_type ":" to print_cr("DTEND;VALUE=" to_type ":" to)
print_fold("SUMMARY:", summary) print_fold("SUMMARY:", summary)
print_fold("DESCRIPTION:", desc) print_fold("DESCRIPTION:", desc)
print_fold("LOCATION:", location) 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 /^(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 /^X-ALT-DESC/ && inside { skipf = 1; next } # skip
/^SEQUENCE/ && inside { seq = $2; next } # store sequence number and 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 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 # Print property with its content and fold according to the iCalendar
# specification. # specification.
# #
@@ -19,16 +27,16 @@ function escape(str)
# @input content: Escaped content # @input content: Escaped content
function print_fold(nameparam, content, i, s) function print_fold(nameparam, content, i, s)
{ {
i = 74 - length(nameparam) i = 73 - length(nameparam)
s = substr(content, 1, i) s = substr(content, 1, i)
print nameparam s print_cr(nameparam s)
s = substr(content, i+1, 73) s = substr(content, i+1, 72)
i = i + 73 i = i + 72
while (s) while (s)
{ {
print " " s print_cr(" " s)
s = substr(content, i+1, 73) s = substr(content, i+1, 72)
i = i + 73 i = i + 72
} }
} }