2009-03-06 09:32:33 -07:00
|
|
|
fn conf_enable_wman {
|
|
|
|
wman_base_uri=$conf_wd
|
|
|
|
wman_man_path=$*
|
|
|
|
if(~ $#wman_man_path 0)
|
|
|
|
wman_man_path=$wman_base_uri
|
|
|
|
conf_enable_app wman
|
|
|
|
}
|
|
|
|
|
2009-03-13 04:51:07 -06:00
|
|
|
wman_junk_filter='/(\/(INDEX|\.cvsignore)|\.9p|\.html)$/d; s!/man([0-9]+/[^/]+)$!/\1!; '
|
|
|
|
fn wman_ls_pages {
|
|
|
|
ls $* \
|
|
|
|
| sed $dirfilter^$wman_junk_filter^' s/\.([0-9]|9p)$//; s!/0intro$!/intro!' \
|
|
|
|
| sort -u
|
|
|
|
}
|
2009-03-06 09:32:33 -07:00
|
|
|
fn wman_init {
|
2009-03-09 19:16:13 -06:00
|
|
|
ifs=$ifs^'/' { p=`{echo $req_path | sed 's!^'^$wman_base_uri^'!!'} }
|
|
|
|
wman_cat=$p(1)
|
|
|
|
wman_page=$p(2)
|
|
|
|
if(~ $#wman_unix_mode 1) {
|
|
|
|
wman_cp='man'
|
|
|
|
wman_pe=.^$"wman_cat
|
|
|
|
}
|
|
|
|
if(! ~ $"wman_cat '')
|
|
|
|
wman_cat_path=$wman_man_path^/^$"wman_cp^$p(1)
|
|
|
|
|
|
|
|
wman_cat_list=`{ls -F $wman_man_path/*/ \
|
2009-03-13 04:51:07 -06:00
|
|
|
| sed -e $wman_junk_filter -e 's!.*/([^/]+)/[^/]+$!\1!; /[0-9]+/!d' \
|
2009-03-09 19:16:13 -06:00
|
|
|
| sort -un}
|
|
|
|
|
|
|
|
synth_paths=($wman_base_uri$wman_cat_list'/')
|
2009-03-06 09:32:33 -07:00
|
|
|
|
|
|
|
if(~ $req_path $wman_base_uri)
|
2009-03-09 19:16:13 -06:00
|
|
|
handler_body_main=(tpl_handler apps/wman/section_list.tpl)
|
2009-03-06 09:32:33 -07:00
|
|
|
if not if(~ $req_path $wman_base_uri^*) {
|
2009-03-09 19:16:13 -06:00
|
|
|
#^*/[a-z0-9]*[a-z]* $wman_base_uri^*/*[a-z]*[a-z0-9] $wman_base_uri^*/[a-z])
|
2009-03-13 04:51:07 -06:00
|
|
|
if(echo $req_path | grep -s '^'^$wman_base_uri^'/*[0-9]+/[0-9a-z\-\+\.]+$')
|
2009-03-09 19:16:13 -06:00
|
|
|
handler_body_main=(tpl_handler apps/wman/man_page.tpl)
|
2009-03-06 09:32:33 -07:00
|
|
|
if not if(~ $req_path $wman_base_uri^*/)
|
2009-03-09 19:16:13 -06:00
|
|
|
handler_body_main=(tpl_handler apps/wman/page_list.tpl)
|
|
|
|
if not if(~ $p(2) [A-Z]* [0-9][A-Z]*) # Correct badly capitalized links
|
2009-04-19 17:56:05 -06:00
|
|
|
perm_redirect $wman_base_uri^$p(1)^/^`{echo $p(2) |tr 'A-Z' 'a-z'}
|
2009-03-06 09:32:33 -07:00
|
|
|
}
|
2009-03-13 04:51:07 -06:00
|
|
|
|
|
|
|
# Search
|
|
|
|
ll_add handlers_body_head tpl_handler apps/wman/search.tpl
|
2009-03-16 17:42:44 -06:00
|
|
|
if(! ~ $"post_arg_wman_search '') {
|
|
|
|
s=`{echo $post_arg_wman_search | sed 's/[^a-zA-Z0-9\-\.]+//g; s/\.+/./g; 1q'}
|
|
|
|
ifs='' { wman_search_results=`{wman_ls_pages $wman_man_path/*/*^$"s^*} }
|
|
|
|
if(! ~ $"post_arg_go '' && ~ `{echo -n $wman_search_results|wc -l} 1)
|
|
|
|
post_redirect $wman_base_uri^`{echo $wman_search_results|awk -F/ '{print $(NF-1)"/"$NF}'}
|
|
|
|
}
|
2009-03-13 04:51:07 -06:00
|
|
|
|
2009-03-06 09:32:33 -07:00
|
|
|
}
|
|
|
|
|
2009-03-13 04:51:07 -06:00
|
|
|
fn wman_get_section_desc {
|
|
|
|
cat $wman_man_path/^$"wman_cp^$1/0intro* >[2]/dev/null| sed '1,2d; s!intro \\- introduction to !!; 3q;'
|
|
|
|
}
|
2009-03-09 16:16:39 -06:00
|
|
|
|
2009-03-09 19:16:13 -06:00
|
|
|
fn wman_page_gen {
|
|
|
|
#troff -manhtml $1| troff2html -t 'Plan 9 from User Space'
|
|
|
|
nroff -man $1 \
|
|
|
|
| escape_html \
|
2009-03-13 04:51:07 -06:00
|
|
|
| sed 's!([\.\-a-zA-Z0-9]+)\(('^`{echo $wman_cat_list|tr ' ' '|'}^')\)!<a href="../\2/\1">&</a>!g' \
|
2009-03-09 19:16:13 -06:00
|
|
|
| awk '/^$/ {if(n != 1) print; n=1; next} /./ {n=0; print}'
|
2009-03-06 09:32:33 -07:00
|
|
|
}
|