source: trunk/packs/glue/os/solaris/lp.sh @ 15064

Revision 15064, 3.2 KB checked in by rbasch, 24 years ago (diff)
Read from standard input when no input file is specified. Set the default title correctly when multiple input files are specified. Set the "-h" option correctly (fix a typo).
Line 
1#!/bin/sh
2# $Id: lp.sh,v 1.2 2000-08-30 22:30:16 rbasch Exp $
3
4# This script emulates the System V lp command using the Athena lpr
5# command.  The emulation is not perfect; the known imperfections are:
6#
7#       * The -s option is ignored, since lpr doesn't normally print
8#         output and doesn't have an option to suppress it when it
9#         does.
10#
11#       * The -m and -w options, which cause mail to be sent or a
12#         message to be written to the user when the print job is
13#         done, are both replaced with -z, which causes a zephyr to be
14#         sent to the user when the print job is done.
15#
16#       * All -o options are ignored (normally they are
17#         printer-specific options) except for "nobanner".
18#
19#       * Arguments to some options may be expanded twice for words and
20#         globbing.
21
22lpr=/usr/athena/bin/lpr
23
24# Parse command-line flags.
25opts=""
26suppress_s=no
27content=""
28pages=""
29title=""
30usage="lp [-P pagerange] [-T content-type] [-c] [-d dest] [-m] [-n number]
31   [-o option] [-t title] [-w] [file ...]"
32while getopts H:P:S:T:cd:fmn:o:pq:rst:wy: opt; do
33        case "$opt" in
34        H)
35                echo "lp: Spooling system does not support special handling." \
36                        1>&2
37                ;;
38        P)
39                pages="$OPTARG"
40                ;;
41        S)
42                echo "lp: Spooling system does not support print wheels." 1>&2
43                ;;
44        T)
45                content="$OPTARG"
46                ;;
47        c)
48                suppress_s=yes
49                ;;
50        d)
51                opts="$opts -P $OPTARG"
52                ;;
53        f)
54                echo "lp: Spooling system does not support forms." 1>&2
55                exit 1
56                ;;
57        m)
58                opts="$opts -z"
59                ;;
60        n)
61                opts="$opts -#$OPTARG"
62                ;;
63        o)
64                case "$OPTARG" in
65                nobanner|*,nobanner|nobanner,*|*,nobanner,*)
66                        opts="$opts -h"
67                        ;;
68                esac
69                ;;
70        p|q|r|s)
71                ;;
72        t)
73                title="$OPTARG"
74                ;;
75        w)
76                opts="$opts -z"
77                ;;
78        y)
79                echo "lp: Spooling system does not support mode list." 1>&2
80                ;;
81        \?)
82                echo "$usage" 1>&2
83                exit 1
84                ;;
85        esac
86done
87if [ "$suppress_s" = no ]; then
88        opts="$opts -s"
89fi
90
91# Find filter to use for content type, if any.
92filter=""
93case ${content:-simple} in
94troff)
95        filter=/usr/lib/lp/postscript/dpost
96        ;;
97daisy|dmd|plot)
98        filter=/usr/lib/lp/postscript/post$content
99        ;;
100matrix)
101        filter=/usr/lib/lp/postscript/postmd
102        ;;
103tek4014)
104        filter=/usr/lib/lp/postscript/posttek
105        ;;
106simple|postscript)
107        ;;
108*)
109        echo "lp: Spooling system does not support content-type" \
110                " $content" 1>&2
111        ;;
112esac
113
114# If a page range was specified, see if the filter supports it, and
115# switch to using a filter if the content type is simple or
116# postscript.  Page ranges won't work if no content type is specified,
117# since we don't know if files are text or postscript and there's no
118# filter which does automatic recognition.
119case "$pages" in
120"")
121        ;;
122*)
123        case "$content" in
124        troff|daisy|dmd|matrix|plot|tek4014)
125                filter="$filter -o$pages"
126                ;;
127        simple)
128                filter="/usr/lib/lp/postscript/postprint -o$pages"
129                ;;
130        postscript)
131                filter="/usr/lib/lp/postscript/postpages -o$pages"
132                ;;
133        *)
134                echo "lp: Spooling system does not support page ranges." 1>&2
135                exit
136                ;;
137        esac
138esac
139
140shift `expr $OPTIND - 1`
141
142if [ -n "$filter" ]; then
143        # This option may not work with all lpr options.
144        if [ -z "$title" -a $# -eq 0 ]; then
145                title="(stdin)"
146        fi
147        for file in "${@:--}"; do
148                $filter $file | $lpr -J "${title:-$file}" $opts
149        done
150else
151        if [ -z "$title" ]; then
152                title="${@:-(stdin)}"
153        fi
154        exec $lpr -J "$title" $opts "$@"
155fi
Note: See TracBrowser for help on using the repository browser.