sources2web 1.0 KB

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