1#!/bin/rc 2# sources2web source-file - massage source file into html 3rfork e 4contrib=`{cat /sys/lib/dist/contrib.note} 5contrib=`{echo $contrib | sed 's;/;\\/;g'} 6ifs=' 7' 8file=$1 9safefile=`{cleanname -d `{pwd} $file | sed 's;/;\\/;g'} # safe for sed 10if(! ~ $safefile *contrib*) 11 contrib='' 12 13fn html { 14 echo Content-Type: text/html 15 echo 16} 17fn head { 18 sed -n '1,/END HEADER/p' /usr/web/plan9/sources.html | translate 19} 20fn tail { 21 sed -n '/BEGIN TAIL/,$p' /usr/web/plan9/sources.html | translate 22} 23fn translate { 24 sed 's/PATH/'$safefile'/g; s/CONTRIB/'$"contrib'/g;' $* 25} 26 27if(test -f $1){ 28 type=`{file -m $1} 29 if(! ~ $type text/*){ 30 len=`{ls -l $1 | awk '{print $6}'} 31 echo Content-Type: $type 32 echo Content-Length: $len 33 echo 34 cat $1 35 exit 0 36 } 37 html 38 head 39 cat $1 | aux/htmlsanitize 40 tail 41 exit 0 42} 43if(test -d $1){ 44 html 45 head 46 # exclude stuff that we don't want to publish with grep -v 47 ls -lp $1 | grep -v ' _| snap$| (9k|nix|pac)' | 48 sed 's/ . [0-9]+ / /' | 49 aux/htmlsanitize | 50 sed 's; ([^ /]+)$; <a href="\1">\1</a>;' 51 tail 52 exit 0 53} 54 55echo not found 56exit 0 57