Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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