1#!/usr/local/plan9/bin/rc
2if (! ~ $DEBUG '') flag x +
3REVFLAG=''
4if (~ $LPCLASS *reverse*) {
5	switch ($REVERSE) {
6	case '';
7		REVFLAG=1
8	case 1;
9		REVFLAG=''
10	}
11}
12if (! ~ $REVFLAG '')
13	postreverse
14
15if (~ $NOHEAD '') {
16	DATE=`{date}
17	face='FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
18FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
19FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
20FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
22FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
23FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
24FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
25FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
26FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
27FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
28FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
29FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
30FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
31FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
32FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
33FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
34FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
35	facedom=`{awk '{ if(match("'$LPMACHID'", $1)) {print $2; exit}}' $PLAN9/face/.machinelist}
36	if (~ $#facedom 0) facedom=$LPMACHID
37
38	facefile=`{awk '/^'$facedom'\/'$LPUSERID' /{print $2}' $PLAN9/face/48x48x4/.dict}
39	facedepth=4
40
41	if (~ $#facefile 0) {
42		facefile=`{awk '/^'$facedom'\/'$LPUSERID' /{print $2}' $PLAN9/face/48x48x2/.dict}
43		facedepth=2
44	}
45
46	if (~ $#facefile 0) {
47		facefile=`{awk '/^'$facedom'\/'$LPUSERID' /{print $2}' $PLAN9/face/48x48x1/.dict}
48		facedepth=1
49	}
50
51	if (~ $#facefile 0) {facefile=u/unknown.1; facedepth=1}
52	facefile=$PLAN9/face/48x48x$facedepth/$facefile
53
54	if (! ~ $#facefile 0 1)
55		facefile=$facefile(1)
56
57	if (~ $#facefile 0 || ! test -f $facefile ) {facefile=$PLAN9/face/48x48x2/u/unknown.1; facedepth=2}
58	if (test -r $facefile ) {
59		switch($facedepth){
60		case 1 2
61			face=`{cat $facefile |
62				sed -e 's/0x//g' -e 's/, *//g' |
63				tr 0123456789abcdef fedcba9876543210 };
64		case 4
65			face=`{iconv -u -c k4 $facefile |
66				dd -bs 60 -skip 1 >[2]/dev/null |
67				xd -b | sed 's/^[^ ]+ //;s/ //g'  }
68		}
69	}
70}
71
72# We have to make sure the face information is set before rc sees the HERE file
73# so the cat has to be in a separate if statement.  This is an rc bug.
74if (~ $NOHEAD '') cat <<EOF
75%!PS-Adobe-2.0	div 112 page header - research!pg
76/banner {
77	/saveobj save def
78	erasepage initgraphics
79	/#copies 1 def
80	/inch {72 mul} bind def
81	/pageborder {
82		25 747 moveto
83		590 747 lineto
84		590 25 lineto
85		25 25 lineto
86		closepath
87		2 setlinewidth
88		0 setgray
89		stroke
90	} def
91
92	/topborder {
93		25 773 moveto
94		590 773 lineto
95		590 747 lineto
96		25 747 lineto
97		closepath
98		2 setlinewidth
99		0 setgray
100		stroke
101	} def
102
103	/toptext {
104		120 756 moveto
105		/Courier-Bold findfont 14 scalefont setfont
106		($LPUSERID $DATE) show
107	} def
108
109	/prface {
110		gsave
111		translate rotate scale
112		setgray
113		48 48 $facedepth [48 0 0 -48 0 48] {<$face>} image
114		grestore
115	} def
116EOF
117if (~ $NOHEAD '') switch ($LPCLASS) {
118case *hp4simx*;
119	echo '
120%% set the default papertray to be the lower tray for HP4siMX printers
121	statusdict begin defaultpapertray end 1 ne {
122		statusdict begin
123			1 setdefaultpapertray
124		end
125	} if'
126}
127if (~ $NOHEAD '') cat <<EOF
128	statusdict /setduplexmode known {statusdict begin false setduplexmode end} if
129	statusdict begin /manualfeed false def end
130	pageborder
131	topborder
132	toptext
133	0 14 14 0 94 752 prface
134	.3 180 180 -90 3.0 inch 10.2 inch prface
135	showpage
136	saveobj
137	restore
138} bind def
139banner
140EOF
141
142if (~ $REVFLAG '') cat
143exit ''
144