Print this page
XXX Remove nawk(1)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/print/scripts/conv_lpd
+++ new/usr/src/cmd/print/scripts/conv_lpd
1 1 #!/bin/sh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License, Version 1.0 only
7 7 # (the "License"). You may not use this file except in compliance
8 8 # with the License.
9 9 #
10 10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 11 # or http://www.opensolaris.org/os/licensing.
12 12 # See the License for the specific language governing permissions
13 13 # and limitations under the License.
14 14 #
15 15 # When distributing Covered Code, include this CDDL HEADER in each
16 16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 # If applicable, add the following below this CDDL HEADER, with the
18 18 # fields enclosed by brackets "[]" replaced with your own identifying
19 19 # information: Portions Copyright [yyyy] [name of copyright owner]
20 20 #
21 21 # CDDL HEADER END
22 22 #
23 23 #
24 24 # Copyright (c) 1994, 1995, 1996 by Sun Microsystems, Inc.
25 25 # All Rights Reserved
26 26 #
27 -# ident "%Z%%M% %I% %E% SMI"
28 -#
29 27 # Printcap <-> Printers.conf conversion utility...
30 28 #
31 29 # Usage: conv_lpd [ -c (printers|printcap) ] [ -n ] (file)
32 30 #
33 31
34 32 TEXTDOMAIN="SUNW_OST_OSCMD"
35 33 export TEXTDOMAIN
36 34
37 35 USAGE=`gettext "Usage: conv_lpd [ -c (printers|printcap) ] [ -n ] (file)\n"`
38 36
39 37 PATH=/usr/bin:/bin:/usr/sbin export PATH
40 38 conversion="printers"
41 39 namelist=0
42 40
43 41 umask 022
44 42
45 43 for i in $*
46 44 do
47 45 case $1 in
48 46 -c*)
49 47 conversion=$2;
50 48 shift ; shift ;
51 49 ;;
52 50 -n*)
53 51 namelist=1;
54 52 shift ;
55 53 ;;
56 54 *)
57 55 break ;
58 56 ;;
59 57 esac
60 58 done
61 59
62 60 TMPF1=/tmp/tinput1.$$
63 61 TMPF2=/tmp/tinput2.$$
64 62 FILE=/tmp/input.$$
65 63
66 64 # Any remaining arg is the "file" specification. It is a required arg.
67 65 if [ -z "$1" ]; then
68 66 echo $USAGE
69 67 exit 1
70 68 else
71 69 cp $1 $TMPF1
72 70 fi
73 71
74 72 echo >>$TMPF1
75 73 echo "_done" >>$TMPF1
76 74
77 75 #
78 76 # First, strip all continuation characters, leaving one, single line
79 77 # for each printer entry.
80 78 #
81 79 CONV_FIX=/usr/lib/print/conv_fix
82 80
83 81 if [ -f $CONV_FIX ]; then
84 82 $CONV_FIX -f $TMPF1 -o $TMPF2
85 83 if [ $? != 0 ]; then
86 84 echo "$0:"
87 85 gettext "Fatal Error: $CONV_FIX failed.\n"
88 86 gettext "Please contact your Sun support representative.\n"
89 87 exit 1
90 88 fi
91 89 else
92 90 gettext "$0: Fatal: Cannot locate $CONV_FIX binary.\n"
93 91 gettext "Please contact your Sun support representative.\n"
94 92 exit 1
95 93 fi
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
96 94
97 95 #
98 96 # Continuation characters are now stripped. Continue processing.
99 97 #
100 98 /bin/sed -e "s/:[ ]*:/:/g" $TMPF2 > $FILE
101 99
102 100 #
103 101 # Empty colons ":[ <TAB>]*:" are now stripped. Continue processing.
104 102 #
105 103
106 -nawk '
104 +/usr/xpg4/bin/awk '
107 105 BEGIN {
108 106 "uname -n" | getline ;
109 107 host = $0 ;
110 108 found = 0 ;
111 109 local_pr = 0;
112 110 }
113 111
114 112 {
115 113 FS=":"; OFS=":" ;
116 114 if ($0 !~ /^#/)
117 115 {
118 116 if ($0 ~ /^[_a-zA-Z0-9_]/) { # New entry
119 117 if ( found != 0 ) {
120 118 if ( "'$namelist'" == 1 )
121 119 printer = names ;
122 120 else
123 121 printer = name[1] ;
124 122
125 123 if ( "'$conversion'" == "printers" ) {
126 124 printf "\n%s:", names ;
127 125 for (key in values) {
128 126 if ((key != "rp") &&
129 127 (key != "rm")) {
130 128 printf "\\\n\t:%s=%s:",
131 129 key, values[key] ;
132 130 delete values[key];
133 131 }
134 132 }
135 133 if (values["rm"] != "") {
136 134 printf "\\\n\t:bsdaddr=%s,%s:", \
137 135 values["rm"], \
138 136 values["rp"] ;
139 137 if (values["rm"] == host) local_pr++;
140 138 } else {
141 139 printf "\\\n\t:bsdaddr=%s,%s:", \
142 140 host, printer ;
143 141 local_pr++;
144 142 }
145 143 delete values["rp"];
146 144 delete values["rm"];
147 145 } else {
148 146 printf "\n%s:", names ;
149 147 for (key in values) {
150 148 if (key == "bsdaddr") {
151 149 split(values[key],
152 150 pair, ",");
153 151 printf "\\\n\t:%s=%s:", \
154 152 "rm", pair[1] ;
155 153 if (pair[2] == "")
156 154 pair[2] = printer;
157 155 printf "\\\n\t:%s=%s:", \
158 156 "rp", pair[2] ;
159 157
160 158 } else if ((key == "br") || \
161 159 (key == "fc") || \
162 160 (key == "fs") || \
163 161 (key == "mc") || \
164 162 (key == "mx") || \
165 163 (key == "pc") || \
166 164 (key == "pl") || \
167 165 (key == "pw") || \
168 166 (key == "px") || \
169 167 (key == "py") || \
170 168 (key == "xc") || \
171 169 (key == "xs"))
172 170 printf "\\\n\t:%s#%s:", \
173 171 key, \
174 172 values[key] ;
175 173 else if (values[key] == "true")
176 174 printf "\\\n\t:%s:", \
177 175 key ;
178 176 else if (values[key] != "false")
179 177 printf "\\\n\t:%s=%s:", \
180 178 key, \
181 179 values[key] ;
182 180 delete values[key];
183 181 }
184 182 }
185 183 }
186 184 split( $1, name, "|");
187 185 names = $1 ;
188 186 found++;
189 187 }
190 188
191 189 for ( i = 1 ; i <= NF ; i++ ) {
192 190 if (($i == names) || ($i == "") || \
193 191 ($i == "\t"))
194 192 continue ;
195 193 if ((split( $i, pair, "=" ) != 2) && \
196 194 (split( $i, pair, "\#") != 2))
197 195 pair[2] = "true";
198 196
199 197 if (pair[1] != "" && pair[1] != " ")
200 198 values[pair[1]] = pair[2] ;
201 199 }
202 200 }
203 201 }
204 202 END {
205 203 printf "\n" ;
206 204 if (local_pr != 0)
207 205 printf "One or more printers are local, you may want to run lpadmin to configure LP server side operation\n" | "cat 1>&2" ;
208 206
209 207 }' ${FILE}
210 208
211 209 /bin/rm -f ${TMPF1} ${TMP2} ${FILE}
212 210
213 211 exit 0
↓ open down ↓ |
97 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX