impr: externaliezed and two little bug fixes

This commit is contained in:
2025-07-03 09:55:22 +02:00
parent 0dd0a81a64
commit a9bdca55b5
6 changed files with 29 additions and 65 deletions

View File

@@ -11,8 +11,8 @@ END {
exit
# Process content lines, force CATEGORIES and SUMMARY as single-line
c["CATEGORIES"] = singleline(getcontent(c["CATEGORIES"]))
c["DESCRIPTION"] = singleline(getcontent(c["DESCRIPTION"]))
c["SUMMARY"] = getcontent(c["SUMMARY"])
c["DESCRIPTION"] = getcontent(c["DESCRIPTION"])
c["SUMMARY"] = singleline(getcontent(c["SUMMARY"]))
c["DUE"] = getcontent(c["DUE"])
# Print
if (c["DUE"])

View File

@@ -5,7 +5,6 @@
@include "lib/awk/icalendar.awk"
# formatdate
# Generate kind-of-pretty date strings.
#
# @local variables: ts, ts_y, ts_m, ts_d, delta
@@ -86,7 +85,7 @@ BEGINFILE {
nextfile
}
/^(CATEGORIES|DESCRIPTION|PRIORITY|STATUS|SUMMARY|COMPLETED|DUE|DTSTART|DURATION|CREATED|DTSTAMP|LAST-MODIFIED)/ {
/^(CATEGORIES|PRIORITY|STATUS|SUMMARY|COMPLETED|DUE|DTSTART|DURATION|CREATED|DTSTAMP|LAST-MODIFIED)/ {
prop = $1;
c[prop] = $0;
next;
@@ -122,7 +121,6 @@ ENDFILE {
# Process content lines
# strings
cat = singleline(unescape(getcontent(c["CATEGORIES"])))
des = singleline(unescape(getcontent(c["DESCRIPTION"])))
sta = singleline(unescape(getcontent(c["STATUS"])))
sum = singleline(unescape(getcontent(c["SUMMARY"])))

View File

@@ -20,10 +20,10 @@ desc { desc = desc "\\n" escape($0); next; }
}
summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
getline;
categories = substr($0, 1, 1) != ">" ? "" : escape(substr($0, 3));
categories = substr($0, 1, 1) != ">" ? "" : escape_but_commas(substr($0, 3));
getline; # This line should be empty
getline; # First line of description
desc = escape($0);
desc = "D" escape($0);
next;
}
END {
@@ -39,7 +39,7 @@ END {
print "BEGIN:VCALENDAR";
print "VERSION:2.0";
print "CALSCALE:GREGORIAN";
print "PRODID:-//fab//awk//EN";
print "PRODID:-//fzf-vjour//awk//EN";
print "BEGIN:" type;
print "DTSTAMP:" zulu;
print "UID:" uid;
@@ -62,7 +62,7 @@ END {
}
if (summary) print_fold("SUMMARY:", summary);
if (categories) print_fold("CATEGORIES:", categories);
if (desc) print_fold("DESCRIPTION:", desc);
if (desc) print_fold("DESCRIPTION:", substr(desc, 2));
print "END:" type;
print "END:VCALENDAR"
}

View File

@@ -1,46 +1,4 @@
# 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)
return str
}
# Escape string to be used as content in iCalendar files.
#
# @input str: String to escape
# @return: Escaped string
function escape_categories(str)
{
gsub("\\\\", "\\\\", str)
gsub(";", "\\;", str)
return str
}
# 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
while (s)
{
print " " s
s = substr(content, i+1, 73)
i = i + 73
}
}
@include "lib/awk/icalendar.awk"
BEGIN {
FS=":";
@@ -69,10 +27,10 @@ NR == FNR {
}
summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
getline;
categories = substr($0, 1, 1) != ">" ? "" : escape_categories(substr($0, 3));
categories = substr($0, 1, 1) != ">" ? "" : escape_but_commas(substr($0, 3));
getline; # This line should be empty
getline; # First line of description
desc = escape($0);
desc = "D" escape($0);
next;
}
@@ -88,7 +46,7 @@ NR == FNR {
if (due) print "DUE;VALUE=DATE:" due;
print_fold("SUMMARY:", summary);
print_fold("CATEGORIES:", categories);
print_fold("DESCRIPTION:", desc);
print_fold("DESCRIPTION:", substr(desc, 2));
type = "";
}
{ print }