bugfix: escape, again
This commit is contained in:
parent
1d92534ffd
commit
648ff6c016
@ -5,6 +5,40 @@
|
|||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
|
# Unescape string
|
||||||
|
#
|
||||||
|
# @local variables: i, c, c2, res
|
||||||
|
# @input str: String
|
||||||
|
# @return: Unescaped string
|
||||||
|
function unescape(str, i, c, c2, res) {
|
||||||
|
for(i=1; i<=length(str);i++) {
|
||||||
|
c = substr(str, i, 1)
|
||||||
|
if (c != "\\") {
|
||||||
|
res = res c
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
c2 = substr(str, i, 1)
|
||||||
|
if (c2 == "n" || c2 == "N") {
|
||||||
|
res = res "\n"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
# Alternatively, c2 is "\\" or "," or ";". In each case, append res with
|
||||||
|
# c2. If the strings has been escaped correctly, then the character c2
|
||||||
|
# cannot be anything else. To be fail-safe, simply append res with c2.
|
||||||
|
res = res c2
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
# Isolate content part of an iCalendar line, and unescape.
|
||||||
|
#
|
||||||
|
# @input str: String
|
||||||
|
# @return: Unescaped content part
|
||||||
|
function getcontent(str) {
|
||||||
|
return unescape(substr(str, index(str, ":") + 1))
|
||||||
|
}
|
||||||
|
|
||||||
# Time-zone aware parsing of the date/date-time entry at the current record.
|
# Time-zone aware parsing of the date/date-time entry at the current record.
|
||||||
#
|
#
|
||||||
# @local variables: dt
|
# @local variables: dt
|
||||||
@ -60,13 +94,9 @@ function fn(path, n, a) {
|
|||||||
# @input summary: Content of SUMMARY field
|
# @input summary: Content of SUMMARY field
|
||||||
# @return: colorized single-line title string
|
# @return: colorized single-line title string
|
||||||
function title(start, summary) {
|
function title(start, summary) {
|
||||||
summary = substr(summary, index(summary, ":") + 1)
|
summary = getcontent(summary)
|
||||||
gsub("\\\\n", " ", summary)
|
gsub("\n", " ", summary) # This will be put on a single line
|
||||||
gsub("\\\\N", " ", summary)
|
gsub("|", ":", summary) # we use "|" as delimiter
|
||||||
gsub("\\\\,", ",", summary)
|
|
||||||
gsub("\\\\;", ";", summary)
|
|
||||||
gsub("\\\\\\\\", "\\", summary)
|
|
||||||
gsub("\\|", ":", summary) # we use "|" as delimiter
|
|
||||||
depth = split(FILENAME, path, "/")
|
depth = split(FILENAME, path, "/")
|
||||||
collection = depth > 1 ? path[depth-1] : ""
|
collection = depth > 1 ? path[depth-1] : ""
|
||||||
collection = collection in collection2label ? collection2label[collection] : collection
|
collection = collection in collection2label ? collection2label[collection] : collection
|
||||||
|
@ -3,6 +3,40 @@
|
|||||||
##
|
##
|
||||||
## @assign field: Field name
|
## @assign field: Field name
|
||||||
|
|
||||||
|
# Unescape string
|
||||||
|
#
|
||||||
|
# @local variables: i, c, c2, res
|
||||||
|
# @input str: String
|
||||||
|
# @return: Unescaped string
|
||||||
|
function unescape(str, i, c, c2, res) {
|
||||||
|
for(i=1; i<=length(str);i++) {
|
||||||
|
c = substr(str, i, 1)
|
||||||
|
if (c != "\\") {
|
||||||
|
res = res c
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
c2 = substr(str, i, 1)
|
||||||
|
if (c2 == "n" || c2 == "N") {
|
||||||
|
res = res "\n"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
# Alternatively, c2 is "\\" or "," or ";". In each case, append res with
|
||||||
|
# c2. If the strings has been escaped correctly, then the character c2
|
||||||
|
# cannot be anything else. To be fail-safe, simply append res with c2.
|
||||||
|
res = res c2
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
# Isolate content part of an iCalendar line, and unescape.
|
||||||
|
#
|
||||||
|
# @input str: String
|
||||||
|
# @return: Unescaped content part
|
||||||
|
function getcontent(str) {
|
||||||
|
return unescape(substr(str, index(str, ":") + 1))
|
||||||
|
}
|
||||||
|
|
||||||
# AWK program
|
# AWK program
|
||||||
BEGIN { FS = ":"; regex = "^" field }
|
BEGIN { FS = ":"; regex = "^" field }
|
||||||
/^BEGIN:VEVENT$/ { inside = 1 }
|
/^BEGIN:VEVENT$/ { inside = 1 }
|
||||||
@ -13,11 +47,5 @@ $0 ~ regex { content = $0; next }
|
|||||||
END {
|
END {
|
||||||
if (!inside) { exit }
|
if (!inside) { exit }
|
||||||
# Process content line
|
# Process content line
|
||||||
content = substr(content, index(content, ":") + 1)
|
print getcontent(content)
|
||||||
gsub("\\\\n", "\n", content)
|
|
||||||
gsub("\\\\N", "\n", content)
|
|
||||||
gsub("\\\\,", ",", content)
|
|
||||||
gsub("\\\\;", ";", content)
|
|
||||||
gsub("\\\\\\\\", "\\", content)
|
|
||||||
print content
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,40 @@
|
|||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
|
# Unescape string
|
||||||
|
#
|
||||||
|
# @local variables: i, c, c2, res
|
||||||
|
# @input str: String
|
||||||
|
# @return: Unescaped string
|
||||||
|
function unescape(str, i, c, c2, res) {
|
||||||
|
for(i=1; i<=length(str);i++) {
|
||||||
|
c = substr(str, i, 1)
|
||||||
|
if (c != "\\") {
|
||||||
|
res = res c
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
c2 = substr(str, i, 1)
|
||||||
|
if (c2 == "n" || c2 == "N") {
|
||||||
|
res = res "\n"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
# Alternatively, c2 is "\\" or "," or ";". In each case, append res with
|
||||||
|
# c2. If the strings has been escaped correctly, then the character c2
|
||||||
|
# cannot be anything else. To be fail-safe, simply append res with c2.
|
||||||
|
res = res c2
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
# Isolate content part of an iCalendar line, and unescape.
|
||||||
|
#
|
||||||
|
# @input str: String
|
||||||
|
# @return: Unescaped content part
|
||||||
|
function getcontent(str) {
|
||||||
|
return unescape(substr(str, index(str, ":") + 1))
|
||||||
|
}
|
||||||
|
|
||||||
# Time-zone aware parsing of the date/date-time entry at the current record.
|
# Time-zone aware parsing of the date/date-time entry at the current record.
|
||||||
#
|
#
|
||||||
# @local variables: dt
|
# @local variables: dt
|
||||||
@ -54,12 +88,8 @@ function parse_duration(duration, dt, dta, i, n, a, seps) {
|
|||||||
# @input end: End time of event, or event duration (see `dur`)
|
# @input end: End time of event, or event duration (see `dur`)
|
||||||
# @input summary: Content of SUMMARY field of the event
|
# @input summary: Content of SUMMARY field of the event
|
||||||
function print_data(start, dur, end, summary, cmd, collection, depth, path) {
|
function print_data(start, dur, end, summary, cmd, collection, depth, path) {
|
||||||
summary = substr(summary, index(summary, ":") + 1)
|
summary = getcontent(summary)
|
||||||
gsub("\\\\n", " ", summary) # one-liner
|
gsub("\n", " ", summary) # This will be put on a single line
|
||||||
gsub("\\\\N", " ", summary) # one-liner
|
|
||||||
gsub("\\\\,", ",", summary)
|
|
||||||
gsub("\\\\;", ";", summary)
|
|
||||||
gsub("\\\\\\\\", "\\", summary)
|
|
||||||
depth = split(FILENAME, path, "/")
|
depth = split(FILENAME, path, "/")
|
||||||
fpath = path[depth-1] "/" path[depth]
|
fpath = path[depth-1] "/" path[depth]
|
||||||
collection = depth > 1 ? path[depth-1] : ""
|
collection = depth > 1 ? path[depth-1] : ""
|
||||||
|
@ -35,7 +35,6 @@ BEGIN { FS = "[:;]"; zulu = strftime("%Y%m%dT%H%M%SZ", systime()
|
|||||||
$1 == field && inside { con = 1; duplic = 1; print field ":" escape(value); next }
|
$1 == field && inside { con = 1; duplic = 1; print field ":" escape(value); next }
|
||||||
$1 == field && duplic { con = 1; next }
|
$1 == field && duplic { con = 1; next }
|
||||||
/^ / && con { 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 }
|
||||||
|
@ -126,11 +126,12 @@ NR == FNR {
|
|||||||
print_fold("DESCRIPTION:", desc)
|
print_fold("DESCRIPTION:", desc)
|
||||||
print_fold("LOCATION:", location)
|
print_fold("LOCATION:", location)
|
||||||
inside = ""
|
inside = ""
|
||||||
|
skipf = 0
|
||||||
}
|
}
|
||||||
/^BEGIN:VEVENT$/ { inside = 1 }
|
/^BEGIN:VEVENT$/ { inside = 1 }
|
||||||
/^ / && skipf { next } # drop this folded line
|
/^ / && skipf { next } # drop this folded line
|
||||||
/^[^ ]/ && skipf { skipf = 0 }
|
/^[^ ]/ && skipf { skipf = 0 }
|
||||||
/^(DTSTART|DTEND|SUMMARY|LOCATION|CATEGORIES|DESCRIPTION|LAST-MODIFIED|X-ALT-DESC)/ && 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 }
|
||||||
|
13
src/main.sh
13
src/main.sh
@ -705,18 +705,11 @@ __edit() {
|
|||||||
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$fpath")
|
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$fpath")
|
||||||
description=$(awk -v field="DESCRIPTION" "$AWK_GET" "$fpath")
|
description=$(awk -v field="DESCRIPTION" "$AWK_GET" "$fpath")
|
||||||
filetmp=$(mktemp --suffix='.md')
|
filetmp=$(mktemp --suffix='.md')
|
||||||
(
|
printf "::: |> %s\n::: <| %s\n" "$start" "$end" >"$filetmp"
|
||||||
echo "::: |> $start"
|
|
||||||
echo "::: <| $end"
|
|
||||||
) >"$filetmp"
|
|
||||||
if [ -n "$location" ]; then
|
if [ -n "$location" ]; then
|
||||||
echo "@ $location" >>"$filetmp"
|
printf "@ %s\n" "$location" >>"$filetmp"
|
||||||
fi
|
fi
|
||||||
(
|
printf "# %s\n\n%s\n" "$summary" "$description" >>"$filetmp"
|
||||||
echo "# $summary"
|
|
||||||
echo ""
|
|
||||||
echo "$description"
|
|
||||||
) >>"$filetmp"
|
|
||||||
checksum=$(cksum "$filetmp")
|
checksum=$(cksum "$filetmp")
|
||||||
$EDITOR "$filetmp" >/dev/tty
|
$EDITOR "$filetmp" >/dev/tty
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user