cleaned awk scripts, str escape bugfix, proper use of local variables
This commit is contained in:
@@ -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 }
|
||||
|
Reference in New Issue
Block a user