-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfoomatic-getpjloptions.in
74 lines (67 loc) · 2.06 KB
/
foomatic-getpjloptions.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!@SH@
#
# Polls PJL options from local or network printers
#
#
# Till Kamppeter (till.kamppeter@gmail.com)
#
# Copyright 2001 Till Kamppeter
#
# This software may be freely redistributed under the terms of the GNU
# General Public License (http://www.gnu.org/).
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Modifed by Patrick Powell <papowell at astart.com>
# - error messages, fixed problem with netcat
# - increased timeout, added a job end to sequence
# as this was needed by a couple of printers
NC=@NC@
CAT=@CAT@
PRINTF=@PRINTF@
PERL=@PERL@
usage(){
cat <<EOF ;
usage: foomatic-getpjloptions <device>
foomatic-getpjloptions <hostname> <port>
<device>: Device where a local printer is connected to
examples: /dev/lp0, /dev/usb/lp0
Have your parallel port in EPP/bi-directional mode
(see your BIOS settings).
<hostname>: Host name or IP of a network printer (HP JetDirect,
Socket, ...)
<port>: Port of your network printer.
echo
Uni-directional protocols as remote LPD are not supported.
The option list is sent to standard output.
EOF
exit 1;
}
case "$1" in
-* ) usage;;
"" ) usage;;
esac
# We have at least one argument, so do the work
(
# PJL commands to request the printer information
$PRINTF "\033%%-12345X"
$PRINTF "@PJL\r\n"
$PRINTF "@PJL INFO VARIABLES\r\n"
$PRINTF "@PJL INFO ID\r\n"
$PRINTF "@PJL INFO CONFIG\r\n"
$PRINTF "\033%%-12345X"
) | if [ ${2:-X} != X ]; then
# We have two arguments, do ethernet printer request
# Poll the printer's answer and filter out the newpage characters
${NC} -w 3 ${1} ${2} 2>/dev/null | ${PERL} -p -e "s/\014//"
else
# We have one argument, do local printer request
# Send commands to printer port
${CAT} > ${1}
# Wait ten seconds for the printer to process the request
sleep 10
# Poll the printer's answer and filter out the newpage and CR characters
${CAT} < ${1} | ${PERL} -p -e "s/[\015\014]//"
fi