1
0

fax 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/rc
  2. # fax [-v] telephone-number recipient [file ...] - send files via fax
  3. rfork e
  4. view=no
  5. stdin=no
  6. fn usage {
  7. echo 'usage: fax [-v] telephone-number recipient [file ...]' >[1=2]
  8. exit usage
  9. }
  10. switch($1){
  11. case -v
  12. view=yes
  13. shift
  14. }
  15. switch ($#*) {
  16. case 0 1
  17. usage
  18. case 2
  19. stdin=yes
  20. }
  21. telno=`{echo $1|sed 's/[ \-]//g'}
  22. shift
  23. if (! ~ $telno [0-9]* +[0-9]*)
  24. usage
  25. # our old phone system needed *9 to get outside; the new one just needs 9
  26. switch($telno){
  27. case ???????
  28. telno='9,'^$telno
  29. case ??????????
  30. telno='9,1'^$telno
  31. case 1??????????
  32. telno='9,'^$telno
  33. case 011*
  34. telno='9,'^$telno
  35. case +*
  36. telno=`{echo $telno | sed 's/\+/9,011/'}
  37. }
  38. recip=$1
  39. shift
  40. script=/tmp/fax.$pid
  41. header=/tmp/faxh.$pid
  42. user=`{cat /dev/user}
  43. tmp=/tmp/fax.g3.$pid
  44. tmpin=/tmp/fax.in.$pid
  45. tmpps=/tmp/fax.ps.$pid
  46. tel=`{grep '\) '$user /lib/tel}
  47. myname=`{echo $tel | sed 's/ \(.*//'}
  48. if (~ $#myname 0)
  49. myname=''
  50. ext=`{echo $tel | sed 's/.*\) [^ ]* [^ ]* ([^ ]*).*/\1/'}
  51. fn sigexit {
  52. rm -f $tmp.* $script $header $header.* $tmpin $tmpps
  53. }
  54. fn sigint {
  55. sigexit
  56. exit interrupt
  57. }
  58. # gather input into a file
  59. switch($stdin){
  60. case yes
  61. cat >$tmpin
  62. infiles=$tmpin
  63. case *
  64. infiles=($*)
  65. }
  66. # convert to g3
  67. g3files=()
  68. a=1
  69. for(i in $infiles){
  70. switch(`{file $i}){
  71. case *:*g3* *:*fax*
  72. g3files=($g3files $i)
  73. case *:*postscript
  74. gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$tmp'.'$#a'.%03d' \
  75. -dNOPAUSE -dQUIET $i quit.ps
  76. g3files=($g3files $tmp.$#a.*)
  77. case *
  78. lp -dstdout $i >$tmpps
  79. gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$tmp'.'$#a'.%03d' \
  80. -dNOPAUSE -dQUIET $tmpps quit.ps
  81. g3files=($g3files $tmp.$#a.*)
  82. }
  83. a=($a 1) # count by increasing list length
  84. }
  85. pages=`{echo $g3files|wc -w}
  86. # use delimiters that are unlikely to be supplied in arguments
  87. {
  88. echo -n s∮FAXddd∮
  89. echo -n `{date} # treat `{} output list specially
  90. echo ∮
  91. echo s∮FAXFFF∮$"myname^∮
  92. echo s∮FAXEEE∮$"user^∮
  93. echo s∮FAXVVV∮$"ext^∮
  94. echo s∮FAXTTT∮$"recip^∮
  95. echo s∮FAXfff∮$"telno^∮
  96. echo s∮FAXPPP∮$"pages^∮
  97. } >>$script
  98. sed -f $script /sys/lib/fax/h.ps >$header
  99. gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$header'.%03d' \
  100. -dNOPAUSE -dQUIET $header quit.ps
  101. files=()
  102. for(i in $header.* $g3files){
  103. files=($files -f $i)
  104. }
  105. switch($view){
  106. case yes
  107. page $header.* $g3files
  108. case *
  109. upas/qer $files /mail/faxoutqueue fax $user $telno </dev/null
  110. rx fax /sys/lib/fax/faxgoose </dev/null
  111. }