contrib: some enhancements to the scrotps provided by Edmond Orignac
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
BEGIN {FS=":"}
|
||||
# My attempt at converting .ics files into XAPIA format for dtcm(1)
|
||||
#/usr/bin/awk -f
|
||||
# Edmond Orignac (c) 2016. This awk program
|
||||
# attempts to convert .ics/.vcs files into XAPIA format for dtcm(1) appointment.
|
||||
# It is redistributable under the terms of MIT License.
|
||||
|
||||
/^BEGIN/ {if ($2~"VEVENT") {appnt=1; rxtype=0; nxr=1; mxday=0; mxmonth=0; runtil=0}
|
||||
BEGIN {FS=":"}
|
||||
|
||||
|
||||
/^BEGIN/ {if ($2~"VEVENT") {appnt=1; rxtype=0; nxr=0; mxday=0; mxmonth=0; runtil=0; xinterval=0}
|
||||
}
|
||||
/^DTSTART/ {sdate=$2}
|
||||
/^TZ/ {if ($2~"[+-][1-9]*") {timezone=$2} else {timezone=0}}
|
||||
# Knowing the timezone, we can convert local time to UTC time.
|
||||
/^DTSTART/ {sdate=$2}
|
||||
/^DTEND/ {fdate=$2}
|
||||
/^DESCRIPTION/ {summary=summary" "substr($0,13)}
|
||||
/^SUMMARY/ {summary=summary" "substr($0,8)}
|
||||
/^LOCATION/ {summary=summary" in "substr($0,9)}
|
||||
/^SUMMARY/ {summary=summary" "substr($0,9)}
|
||||
/^LOCATION/ {summary=summary" in "substr($0,10)}
|
||||
/^RRULE/ {rrule=$2;
|
||||
|
||||
# The event will repeat forever unless we find a limit
|
||||
@@ -71,11 +78,14 @@ BEGIN {FS=":"}
|
||||
if (rdata[i]~"INTERVAL=") {xinterval=substr(rdata[i],10)
|
||||
# Weekly appointment with a 2 week interval is definec in XAPIA
|
||||
if ((xinterval==2) && (rxtype==2)) {rxtype=3}
|
||||
# Monthly appointment with a 12 week interval is really a yearly appointment
|
||||
if ((xinterval==2) && (rxtype=5)) {rxtype=6}
|
||||
# Other cases are not good. csa.h indicates that repeats with
|
||||
# an N day/week/month interval are supported by XAPIA
|
||||
# but it is not clear whether dtcm supports that
|
||||
# Monthly appointment with a 12 month interval is really a yearly appointment
|
||||
if ((xinterval==12) && (rxtype=5)) {rxtype=6}
|
||||
# Weekly appointment with N>2 interval
|
||||
if ((xinterval>2) && (rxtype==2)) {rxtype=8}
|
||||
# Monthly appointment with N>=2 interval (12 month excluded)
|
||||
if ((xinterval>=2) && (rxtype==5)) {rxtype=9}
|
||||
# Daily appointment with N>=2 interval
|
||||
if ((xinterval>=2) && (rxtype==1)) {rxtype=7}
|
||||
};
|
||||
# Repetition until a date in the future
|
||||
if (rdata[i]~"UNTIL=") {xuntil=substr(rdata[i],7); runtil=1};
|
||||
@@ -89,16 +99,19 @@ BEGIN {FS=":"}
|
||||
# We do that by using an average duration for the year and for the month
|
||||
# but obviously this is imprecise, and the last appointment may not be there.
|
||||
# Also, we must do it here since DTSTART can appear at the very end
|
||||
# of an entry.
|
||||
# of an entry. The arithmetics gets sillier with repeat every n week/day/month...
|
||||
if (runtil==1) {
|
||||
uyear=substr(xuntil,1,4)-substr(sdate,1,4);
|
||||
umonth=substr(xuntil,5,2)-substr(sdate,5,2);
|
||||
uday=substr(xuntil,7,2)-substr(sdate,7,2);
|
||||
if (rxtype==6) nxr=uyear+1;
|
||||
if ((rxtype==5)||(rxtype==4)) nxr=12*uyear+umonth+1;
|
||||
if (rxtype==1) nxr=int(365.25*uyear+30.44*umonth+uday)+1;
|
||||
if (rxtype==2) nxr=int((365.25*uyear+30.44*umonth+uday)/7.0)+1;
|
||||
if (rxtype==3) nxr=int((365.25*uyear+30.44*umonth+uday)/14.0)+1;
|
||||
if (rxtype==1) nxr=int(365.25*uyear+30.44*umonth+uday)+1;
|
||||
if ((rxtype==4)||(rxtype==5)) nxr=12*uyear+umonth+1;
|
||||
if (rxtype==6) nxr=uyear+1;
|
||||
if (rxtype==7) nxr=int((365.25*uyear+30.44*umonth+uday)/xinterval)+1;
|
||||
if (rxtype==8) nxr=int((365.25*uyear+30.44*umonth+uday)/(7*xinterval))+1;
|
||||
if (rxtype==9) nxr=int((12*uyear+umonth)/xinterval)+1;
|
||||
if (rxtype==10) nxr=int(5.0*(365.25*uyear+30.44*umonth+uday)/7.0)+1;
|
||||
if (rxtype==11) nxr=int(3.0*(365.25*uyear+30.44*umounth+uday)/7.0)+1;
|
||||
if (rxtype==12) nxr=int(3.0*(365.25*uyear+30.44*umounth+uday)/7.0)+1;
|
||||
@@ -113,8 +126,9 @@ BEGIN {FS=":"}
|
||||
|
||||
if ((rxtype==0) && (dday>0)) {rxtype=1;nxr=dday+1};
|
||||
|
||||
# Start hour and End hour have to be converted to UTC first if timezone is defined.
|
||||
|
||||
printf("\n\n")
|
||||
printf("\n\n")
|
||||
print "\t** Calendar Appointment **"
|
||||
print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN:string:begin";
|
||||
printf("-//XAPIA/CSA/ENTRYATTR//NONSGML Start Date//EN:datetime:%s\n",sdate);
|
||||
@@ -135,21 +149,29 @@ BEGIN {FS=":"}
|
||||
print "-//XAPIA/CSA/ENTRYATTR//NONSGML Audio Reminder//EN:reminder:300:";
|
||||
print "-//XAPIA/CSA/ENTRYATTR//NONSGML Popup Reminder//EN:reminder:300:";
|
||||
print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Occurrence Number//EN:sinteger:-1";
|
||||
print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Interval//EN:uinteger:0";
|
||||
printf("-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Interval//EN:uinteger:%d\n",rinterval);
|
||||
print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN:string:end";
|
||||
printf("\tDate: %s/%s/%s\n",substr(sdate,5,2),substr(sdate,7,2),substr(sdate,1,4));
|
||||
# The start/end time are in UTC and have to be converted to local time. We assume the local time is UTC+1
|
||||
shour=substr(sdate,10,2)+1;
|
||||
smin=substr(sdate,12,2);
|
||||
fhour=substr(fdate,10,2)+1;
|
||||
fmin=substr(fdate,12,2);
|
||||
printf("\tStart: %d%s\n",shour,smin)
|
||||
printf("\tEnd: %d%s\n",fhour,fmin)
|
||||
# The start/end time are in UTC and have to be converted to local time. We assume the local time is UTC+1
|
||||
shour=substr(sdate,10,2);
|
||||
smin=substr(sdate,12,2);
|
||||
fhour=substr(fdate,10,2);
|
||||
fmin=substr(fdate,12,2);
|
||||
if ((fhour+fmin+shour+smin)==0) {fhour=01;fmin=42;shour=01;smin=41}
|
||||
shour++;
|
||||
fhour++;
|
||||
printf("\tStart: %.2d%.2d\n",shour,smin)
|
||||
printf("\tEnd: %.2d%.2d\n",fhour,fmin)
|
||||
if (rxtype==0) {print "\tRepeat: One Time"};
|
||||
if (rxtype==1) {print "\tRepeat: Daily"};
|
||||
if (rxtype==2) {print "\tRepeat: Weekly"};
|
||||
if (rxtype==3) {print "\tRepeat: Every Two Weeks"};
|
||||
if (rxtype==4) {print "\tRepeat: Monthly By Weekday"};
|
||||
if (rxtype==5) {print "\tRepeat: Monthly By Date"};
|
||||
if (rxtype==6) {print "\tRepeat: Yearly"}
|
||||
if (rxtype==7) {printf("\t Repeat Every %d days\n",xinterval)}
|
||||
if (rxtype==8) {printf("\t Repeat Every %d weeks\n",xinterval)}
|
||||
if (rxtype==9) {printf("\t Repeat Every %d months\n",xinterval)}
|
||||
if (rxtype==10) {print "\tRepeat: Monday thru Friday"};
|
||||
if (rxtype==11) {print "\tRepeat: Mon, Wed, Fri"};
|
||||
if (rxtype==12) {print "\tRepeat: Tuesday, Thursday"};
|
||||
@@ -163,4 +185,4 @@ BEGIN {FS=":"}
|
||||
summary="";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user