cleaned awk scripts, str escape bugfix, proper use of local variables

This commit is contained in:
2025-06-16 11:04:32 +02:00
parent ee02a7647b
commit 83beaa3ad5
12 changed files with 401 additions and 262 deletions

View File

@@ -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
}