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