]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/psfax
Remove ap(1)
[plan9front.git] / rc / bin / psfax
1 #!/bin/rc
2 view=no
3 stdin=no
4
5 switch($1){
6 case -v
7         view=yes
8         shift
9 }
10
11 switch($#*){
12 case 0 1
13         echo usage: $0 telephone-number recipient '[files]' >[1=2]
14         exit usage
15 case 2
16         stdin=yes
17 }
18
19 telno=$1
20 shift
21
22 recip=$1
23 shift
24
25 script=/tmp/fax.$pid
26 header=/tmp/faxh.$pid
27 tmp=/tmp/page.$pid
28 tmpin=/tmp/page.in.$pid
29 tel=`{grep '\) '$user /lib/tel}
30 myname=`{echo $tel | sed 's/ \(.*//'}
31 ext=`{echo $tel | sed 's/.*\) [^ ]* [^ ]* ([^ ]*).*/\1/'}
32
33 fn sigint{
34         #rm -f $tmp.* $tmpin.* $script $header $header.*
35         exit interrupt
36         
37 }
38
39 # gs insists on reading its standard input, so we read quit.ps to cut it off.
40 switch($stdin){
41 case yes
42         cat > $tmpin
43         gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$tmp'.%.3d' -dNOPAUSE -dQUIET $tmpin quit.ps
44 case *
45         gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$tmp'.%.3d' -dNOPAUSE -dQUIET $* quit.ps
46 }
47
48 pages=`{echo $tmp.*|wc -w}
49
50 # use delimiters that are unlikely to be supplied in arguments
51 echo -n s∮FAXddd∮    >$script
52 echo -n `{date}         >>$script
53 echo ∮                        >>$script
54 echo -n s∮FAXFFF∮   >>$script
55 echo -n $myname         >>$script
56 echo ∮                        >>$script
57 echo -n s∮FAXEEE∮   >>$script
58 echo -n $user           >>$script
59 echo ∮                        >>$script
60 echo -n s∮FAXVVV∮   >>$script
61 echo -n $ext            >>$script
62 echo ∮                        >>$script
63 echo -n s∮FAXTTT∮   >>$script
64 echo -n $recip          >>$script
65 echo ∮                        >>$script
66 echo -n s∮FAXfff∮   >>$script
67 echo -n $telno          >>$script
68 echo ∮                        >>$script
69 echo -n s∮FAXPPP∮   >>$script
70 echo -n $pages          >>$script
71 echo ∮                        >>$script
72 sed -f $script /sys/lib/fax/h.ps > $header
73
74 gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$header'.%.3d' -dNOPAUSE -dQUIET $header quit.ps
75
76 files=()
77 for(i in $header.* $tmp.*){
78         files=($files -f $i)
79 }
80
81 switch($view){
82 case no
83         upas/qer $files /mail/faxoutqueue fax $user $telno < /dev/null
84         rx fax /sys/lib/fax/faxgoose
85 case yes
86         page $header.* $tmp.*
87 }
88
89 #rm -f $tmp.* $header $script $header.* $tmpin