Compare commits

...

2 Commits

Author SHA1 Message Date
b356b557c2 fix \r\n 2025-12-01 11:16:39 +01:00
efcf39b890 demo: typo fixed 2025-08-22 09:43:11 +02:00
11 changed files with 70 additions and 53 deletions

View File

@@ -28,10 +28,10 @@ cat <<EOF | $FVJ --add-task "Respond to referee report" "yesterday" --collection
- [x] Report 1: Answer prepared - [x] Report 1: Answer prepared
- [ ] Report 2: Write response, revise manuscript - [ ] Report 2: Write response, revise manuscript
EOF EOF
echo "Chinese" | $FVJ --add-task "Reserve dinner table" "next Sunday" echo "for 5 pax" | $FVJ --add-task "Reserve dinner table" "next Sunday"
cat <<EOF | $FVJ --add-jour "Demo Coding" cat <<EOF | $FVJ --add-jour "Demo Coding"
### Demo code ### Demo code
Our demo now contains a script that self-generets the demo. Our demo now contains a script that generates this demo.
It's located in \`./scripts/\` It's located in \`./scripts/\`
There are some upcoming steps: There are some upcoming steps:

View File

@@ -3,39 +3,43 @@
# If `delta` is specified using `-v`, then the priority value is increased by # If `delta` is specified using `-v`, then the priority value is increased by
# `delta.` If `delta` is unspecified (or equal to 0), then the completeness # `delta.` If `delta` is unspecified (or equal to 0), then the completeness
# status is toggled. # status is toggled.
@include "lib/awk/icalendar.awk"
BEGIN { BEGIN {
FS=":"; FS=":";
zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1); zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1);
delta = delta + 0; # cast as integer delta = delta + 0; # cast as integer
} }
{ gsub("\r", "") }
/^END:VTODO/ && inside { /^END:VTODO/ && inside {
# Print sequence and last-modified, if not yet printed # Print sequence and last-modified, if not yet printed
if (!seq) print "SEQUENCE:1"; if (!seq) print_cr("SEQUENCE:1");
if (!lm) print "LAST-MODIFIED:" zulu; if (!lm) print_cr("LAST-MODIFIED:" zulu);
# Print priority # Print priority
prio = prio ? prio + delta : 0 + delta; prio = prio ? prio + delta : 0 + delta;
prio = prio < 0 ? 0 : prio; prio = prio < 0 ? 0 : prio;
prio = prio > 9 ? 9 : prio; prio = prio > 9 ? 9 : prio;
print "PRIORITY:" prio; print_cr("PRIORITY:" prio);
# Print status (toggle if needed) # Print status (toggle if needed)
bit_status = status == "COMPLETED" ? 1 : 0; bit_status = status == "COMPLETED" ? 1 : 0;
bit_toggle = delta ? 0 : 1; bit_toggle = delta ? 0 : 1;
percent = xor(bit_status, bit_toggle) ? 100 : 0; percent = xor(bit_status, bit_toggle) ? 100 : 0;
status = xor(bit_status, bit_toggle) ? "COMPLETED" : "NEEDS-ACTION"; status = xor(bit_status, bit_toggle) ? "COMPLETED" : "NEEDS-ACTION";
print "STATUS:" status print_cr("STATUS:" status)
print "PERCENT-COMPLETE:" percent print_cr("PERCENT-COMPLETE:" percent)
# print rest # print rest
inside = ""; inside = "";
print $0; print_cr($0);
next next
} }
/^BEGIN:VTODO/ { inside = 1; print; next } /^BEGIN:VTODO/ { inside = 1; print_cr($0); next }
/^SEQUENCE/ && inside { seq = 1; print "SEQUENCE:" $2+1; next } /^SEQUENCE/ && inside { seq = 1; print_cr("SEQUENCE:" $2+1); next }
/^LAST-MODIFIED/ && inside { lm = 1; print "LAST-MODIFIED:" zulu; next } /^LAST-MODIFIED/ && inside { lm = 1; print_cr("LAST-MODIFIED:" zulu); next }
/^PRIORITY:/ && inside { prio = $2; next } /^PRIORITY:/ && inside { prio = $2; next }
/^STATUS/ && inside { status = $2; next } /^STATUS/ && inside { status = $2; next }
/^PERCENT-COMPLETE/ && inside { next } # ignore, we take STATUS:COMPLETED as reference /^PERCENT-COMPLETE/ && inside { next } # ignore, we take STATUS:COMPLETED as reference
{ print } { print_cr($0) }

View File

@@ -15,21 +15,21 @@ function write_attachment( line, aline, fl) {
fl = 1 fl = 1
while (getline aline <file) { while (getline aline <file) {
line = line aline line = line aline
if (fl && length(line) >= 73) { if (fl && length(line) >= 72) {
print substr(line, 1, 73) print substr(line, 1, 72)"\r"
line = substr(line, 74) line = substr(line, 73)
fl = 0 fl = 0
} }
while (length(line) >= 72) { while (length(line) >= 71) {
print " "substr(line, 1, 72) print " "substr(line, 1, 71)"\r"
line = substr(line, 73) line = substr(line, 72)
} }
} }
if (line) if (line)
print " "line print " "line"\r"
} }
# AWK program # AWK program
/^END:(VTODO|VJOURNAL)$/ { write_attachment() } /^END:(VTODO|VJOURNAL)/ { write_attachment() }
{ print } { print }

View File

@@ -1,4 +1,5 @@
BEGIN { FS="[:;]" } BEGIN { FS="[:;]" }
{ gsub("\r", "") }
/^END:(VTODO|VJOURNAL)$/ { ins = 0; exit } /^END:(VTODO|VJOURNAL)$/ { ins = 0; exit }
/^[^ ]/ && a { a = 0 } /^[^ ]/ && a { a = 0 }
/^ / && a && p { print substr($0, 2); } /^ / && a && p { print substr($0, 2); }

View File

@@ -34,6 +34,7 @@ function att_info(i, str, cnt, k, info) {
} }
BEGIN { FS="[:;]"; OFS="\t" } BEGIN { FS="[:;]"; OFS="\t" }
{ gsub("\r", "") }
/^END:(VTODO|VJOURNAL)$/ { ins = 0; exit } /^END:(VTODO|VJOURNAL)$/ { ins = 0; exit }
l && !r { att_info(i, l); l = "" } l && !r { att_info(i, l); l = "" }
/^ / && r { l = l substr($0, 2); r = cont_reading($0) } /^ / && r { l = l substr($0, 2); r = cont_reading($0) }

View File

@@ -4,10 +4,10 @@
## @assign id: Attachment number to remove ## @assign id: Attachment number to remove
BEGIN { FS="[:;]" } BEGIN { FS="[:;]" }
/^END:(VTODO|VJOURNAL)$/ { ins = 0 } /^END:(VTODO|VJOURNAL)/ { ins = 0 }
/^[^ ]/ && a { a = 0 } /^[^ ]/ && a { a = 0 }
/^ / && a { next } /^ / && a { next }
/^ATTACH/ && ins { i++; } /^ATTACH/ && ins { i++; }
/^ATTACH/ && ins && i == id { a = 1; next } /^ATTACH/ && ins && i == id { a = 1; next }
/^BEGIN:(VTODO|VJOURNAL)$/ { ins = 1 } /^BEGIN:(VTODO|VJOURNAL)/ { ins = 1 }
{ print } { print }

View File

@@ -16,6 +16,7 @@
# print content of field `field` # print content of field `field`
BEGIN { FS = ":"; regex = "^" field; } BEGIN { FS = ":"; regex = "^" field; }
BEGINFILE { type = ""; line = ""; } BEGINFILE { type = ""; line = ""; }
{ gsub("\r", "") }
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 } /^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
/^END:/ && $2 == type { nextfile } /^END:/ && $2 == type { nextfile }
$0 ~ regex { line = $0; next; } $0 ~ regex { line = $0; next; }

View File

@@ -81,6 +81,8 @@ BEGINFILE {
delete c; delete c;
} }
{ gsub("\r", "") }
/^BEGIN:(VJOURNAL|VTODO)/ { /^BEGIN:(VJOURNAL|VTODO)/ {
type = $2 type = $2
} }

View File

@@ -37,33 +37,33 @@ END {
} }
# print ical # print ical
print "BEGIN:VCALENDAR"; print_cr("BEGIN:VCALENDAR")
print "VERSION:2.0"; print_cr("VERSION:2.0")
print "CALSCALE:GREGORIAN"; print_cr("CALSCALE:GREGORIAN")
print "PRODID:-//fzf-vjour//awk//EN"; print_cr("PRODID:-//fzf-vjour//awk//EN")
print "BEGIN:" type; print_cr("BEGIN:" type)
print "DTSTAMP:" zulu; print_cr("DTSTAMP:" zulu)
print "UID:" uid; print_cr("UID:" uid)
print "CLASS:PRIVATE"; print_cr("CLASS:PRIVATE")
print "CREATED:" zulu; print_cr("CREATED:" zulu)
print "SEQUENCE:1"; print_cr("SEQUENCE:1")
print "LAST-MODIFIED:" zulu; print_cr("LAST-MODIFIED:" zulu)
if (type == "VTODO") if (type == "VTODO")
{ {
print "STATUS:NEEDS-ACTION"; print_cr("STATUS:NEEDS-ACTION")
print "PERCENT-COMPLETE:0"; print_cr("PERCENT-COMPLETE:0")
if (due) if (due)
print "DUE;VALUE=DATE:" due; print_cr("DUE;VALUE=DATE:" due)
} }
else else
{ {
print "STATUS:FINAL"; print_cr("STATUS:FINAL")
if (start) if (start)
print "DTSTART;VALUE=DATE:" start; print_cr("DTSTART;VALUE=DATE:" start)
} }
if (summary) print_fold("SUMMARY:", summary); if (summary) print_fold("SUMMARY:", summary);
if (categories) print_fold("CATEGORIES:", categories); if (categories) print_fold("CATEGORIES:", categories);
if (desc) print_fold("DESCRIPTION:", desc); if (desc) print_fold("DESCRIPTION:", desc);
print "END:" type; print_cr("END:" type)
print "END:VCALENDAR" print_cr("END:VCALENDAR")
} }

View File

@@ -46,9 +46,9 @@ due && type == "VJOURNAL" { print "Notes and journal entries do not have
/^SEQUENCE/ && type { seq = $2; next; } # store sequence number and skip /^SEQUENCE/ && type { seq = $2; next; } # store sequence number and skip
/^END:/ && type == $2 { /^END:/ && type == $2 {
seq = seq ? seq + 1 : 1; seq = seq ? seq + 1 : 1;
print "SEQUENCE:" seq; print_cr("SEQUENCE:" seq);
print "LAST-MODIFIED:" zulu; print_cr("LAST-MODIFIED:" zulu);
if (due) print "DUE;VALUE=DATE:" due; if (due) print_cr("DUE;VALUE=DATE:" due);
print_fold("SUMMARY:", summary); print_fold("SUMMARY:", summary);
print_fold("CATEGORIES:", categories); print_fold("CATEGORIES:", categories);
print_fold("DESCRIPTION:", desc); print_fold("DESCRIPTION:", desc);

View File

@@ -33,6 +33,14 @@ function escape_but_commas(str)
return str return str
} }
# Print line using \r\n ending, as required by the RFC
#
# @input str: String
function print_cr(str)
{
print str "\r"
}
# Print property with its content and fold according to the iCalendar # Print property with its content and fold according to the iCalendar
# specification. # specification.
# #
@@ -41,16 +49,16 @@ function escape_but_commas(str)
# @input content: Escaped content # @input content: Escaped content
function print_fold(nameparam, content, i, s) function print_fold(nameparam, content, i, s)
{ {
i = 74 - length(nameparam) i = 73 - length(nameparam)
s = substr(content, 1, i) s = substr(content, 1, i)
print nameparam s print_cr(nameparam s)
s = substr(content, i+1, 73) s = substr(content, i+1, 72)
i = i + 73 i = i + 72
while (s) while (s)
{ {
print " " s print_cr(" " s)
s = substr(content, i+1, 73) s = substr(content, i+1, 72)
i = i + 73 i = i + 72
} }
} }