get_dates() { #Parameter: Calendarfile
calendarfile="$_DATA/ical/$course"
- unset key
- declare -A tags
declare -A values
- ics_parse "$calendarfile" |while read -r line; do
- declare -A tag
- case "$line" in
- value*) eval "$line";;
- tag*) eval "$line";;
- key*)
- if [ -z "$key" ]; then
- eval "$line"
- else
- values[$key]="$(tex_clean "$value")"
- for t in ${(k)tag}; do
- tags[${key}_$t]="$tag[$t]"
- done
- eval "$line"
- if [ -n "$values[$key]" ]; then
- n=0
- while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
- key=$key$n
- fi
- unset value
- unset tag
- fi
- ;;
- esac
- done
+ ics_parse "$calendarfile"
dtstart="$values[DTSTART]"
[ -z "$dtstart" ] && dtstart=$(date +%Y%m%dT%H%M%S)
}
ics_parse() {
- tr -d '\n' <"$1" |sed -r 's:\r ::g;s:\r:\n:g' |tr -d '\r' \
- | sed -r 's:^([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:key="\1"\nvalue="\3"\ntag=\2:g' \
+ unset key
+ sed -r ':X;N;$!bX; s;\r\n[ \t];;g; s;\r\n;\n;g;' "$1" \
+ | sed -rn '
+ # === turn property names to upper case, strip group names ===
+ h; s;^([^;:]+);;;
+ x; s;^([^;:\.]+\.)?([^;:]+).*$;\2;;
+ y;abcdefghijklmnopqrstuvwxyz;ABCDEFGHIJKLMNOPQRSTUVWXYZ;
+ G; s;\n;;;
+
+ /^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$/{
+ h;
+ s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;key='\''\1'\'';;
+ H; g;
+
+ s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\2;;
+ s;'\'';'\'\\\\\'\'';g
+ s;\;([A-Z0-9-]+)(=|=(([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*))?;\ntag[\1]='\''\3'\'';g
+ s;^\n+;;; s;\n+$;;;
+ /^.+$/H; g;
+
+ s;^([A-Z0-9-]+)((\;[a-Z0-9-]+=?|\;[a-Z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\6;;
+ # :X s;((^|[^\\])(\\\\)*)[;,];\1\n;g; s;((^|[^\\])(\\\\)*)\\([;,]);\4;g; tX;
+ s;'\'';'\'\\\\\'\'';g
+ s;^.*$;value='\''&'\'';
+ H; g;
+
+ s;^[^\n]*[\n ]+;;
+ s;\n+$;;;
+
+ p;
+ }
+ ' \
| while read -r line; do
+ declare -A tag
case "$line" in
- key=*) echo -E "$line"
- ;;
- value=*) echo -E "$line"
- ;;
- tag=*) ot=''
- echo -E "$line" \
- | sed -r 's:^tag=::;s:\;([A-Z+_-]+="[^"]+"|[A-Z+_-]+=[^\;]+):\n\1:g;' \
- | sed -r 's:([A-Z+_-]+)="?(.*)"?:tag\[\1\]="\2":g' \
- | sed -r '/^ *$/d' \
- | sort |while read -r tag; do
- nt="$(echo -E "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\1:')"
- nv="$(echo -E "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\2:')"
- [ "$nt" = "$ot" ] && vl="$nv,$vl" || vl="$nv"
- echo -E "tag[$nt]=\"$vl\""
- ot="$nt"
- done
- ;;
+ value*) eval "$line";;
+ tag*) eval "$line";;
+ key*)
+ if [ -z "$key" ]; then
+ eval "$line"
+ else
+ values[$key]="$value"
+ for t in ${(k)tag}; do
+ values[${key}_$t]="$tag[$t]"
+ done
+ eval "$line"
+ if [ -n "$values[$key]" ]; then
+ n=0
+ while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
+ key=$key$n
+ fi
+ unset value
+ unset tag
+ fi
+ ;;
esac
done
}
if [ "$cachefile" -nt "$calendarfile" ]; then
cat "$cachefile"
else
- declare -A tags
declare -A values
- ics_parse "$calendarfile" |while read -r line; do
- declare -A tag
- case "$line" in
- value*) eval "$line";;
- tag*) eval "$line";;
- key*)
- if [ -z "$key" ]; then
- eval "$line"
- else
- values[$key]="$value"
- for t in ${(k)tag}; do
- tags[${key}_$t]="$tag[$t]"
- done
- eval "$line"
- if [ -n "$values[$key]" ]; then
- n=0
- while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
- key=$key$n
- fi
- unset value
- unset tag
- fi
- ;;
- esac
- done
+ ics_parse "$calendarfile"
. ${_EXEC}/templates/view_course.sh |tee "$cachefile"
fi
}
[ -f "$tempfile" ] && calendarfile="$tempfile"
unset key
- declare -A tags
declare -A values
- ics_parse "$calendarfile" |while read -r line; do
- declare -A tag
- case "$line" in
- value*) eval "$line";;
- tag*) eval "$line";;
- key*)
- if [ -z "$key" ]; then
- eval "$line"
- else
- [ -n "$value" ] && values[$key]="$value" || values[$key]='\r'
- for t in ${(k)tag}; do
- tags[${key}_$t]="$tag[$t]"
- done
- eval "$line"
- if [ -n "$values[$key]" ]; then
- n=0
- while [ -n "$values[${key}${n}]" ]; do n=$(($n + 1)); done
- key=$key$n
- fi
- unset value
- unset tag
- fi
- ;;
- esac
- done
+ ics_parse "$calendarfile"
. ${_EXEC}/templates/edit_course.sh
}