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