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