]> git.plutz.net Git - clickslide/blob - autoslide.sh
a7d08bcd86e3d72433e49a35e0a42a467272c56c
[clickslide] / autoslide.sh
1 #!/bin/sh
2
3 last='' curr='' next=''
4 idoff=1
5
6 line="$(line)"
7 while :; do 
8   tag="${tag}${line%%>*}"
9
10   if [ "$line" = "${line%%>*}" ]; then
11     # $line did not contain ">" and thus was added to $tag entirely
12     if ! line="$(line)"; then
13       printf %s\\n "$tag"
14       break
15     fi
16     tag="${tag}
17 "
18   else
19     # $line is shortened by segment added to $tag
20     line="${line#*>}"
21     tag="${tag}>"
22   fi
23
24   case $tag in
25     *\<slide\ *id=\"?*\"*\>*)
26       prev="$curr" curr="$next"
27       next="${tag#*<slide }"
28       next="${next#*id=\"}"
29       next="${next%\"*}"
30       printf '%s<a href="#%s">previous</a><a href="#%s">next</a><slide %s' \
31         "${tag%<slide *}" "$prev" "$next" "${tag#*<slide }"
32       tag=''
33       ;;
34     *\<slide\ *\>*)
35       prev="$curr" curr="$next"
36       next="autoslide${idoff}"
37       idoff="$((idoff + 1))"
38       printf '%s<a href="#%s">previous</a><a href="#%s">next</a><slide %s' \
39         "${tag%<slide *}" "$prev" "$next" "${tag#*<slide }"
40       tag=''
41       ;;
42     *\<*\>*)
43       printf %s "$tag"
44       tag=''
45       ;;
46     *) :
47       ;;
48   esac
49 done