#!/opt/p9p/bin/rc rfork en foundit='no' if (~ $#* 0) { echo 'usage: wiki [-l | article [article...]]' >[1=2] exit usage } if (! 9p stat wiki >/dev/null >[2=1]) 9fs wiki || exit mount if (~ $1 '-l') { for (i in `{9p ls wiki}) { if (9p ls wiki/^$i^/index.txt >/dev/null >[2=1]) echo $i } exit } # Check if the argument list is an unescaped page title. name=`{echo $"* | tr 'A-Z ' 'a-z_'} if (9p stat wiki/$name/index.txt >/dev/null >[2=1]) 9p read wiki/$name/index.txt && exit # Check if the argument list matches a page with -s for spaces. name=`{echo $"* | tr 'A-Z ' 'a-z\-'} if (9p stat wiki/$name/index.txt >/dev/null >[2=1]) 9p read wiki/$name/index.txt && exit # Check if each argument is a page title. for (i in $*) { name=`{echo $i | tr 'A-Z ' 'a-z_'} if (9p stat wiki/$name/index.txt >/dev/null >[2=1]) 9p read wiki/$name/index.txt && foundit='yes' if not echo 'No article named '$i' could be found.' >[1=2] } # All our earlier attempts have failed. if(~ $foundit 'no') { echo 'No article with that name could be found.' >[1=2] exit badname }