Print this page
8485 Remove set but unused variables in usr/src/cmd
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/print/bsd-sysv-commands/lpr.c
+++ new/usr/src/cmd/print/bsd-sysv-commands/lpr.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 + * Copyright 2017 Gary Mills
23 24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 25 * Use is subject to license terms.
25 26 *
26 27 */
27 28
28 29 /* $Id: lpr.c 146 2006-03-24 00:26:54Z njacobs $ */
29 30
30 -#pragma ident "%Z%%M% %I% %E% SMI"
31 -
32 31 #include <stdio.h>
33 32 #include <stdlib.h>
34 33 #include <unistd.h>
35 34 #include <string.h>
36 35 #include <locale.h>
37 36 #include <libintl.h>
38 37 #include <papi.h>
39 38 #include "common.h"
40 39
41 40 #ifdef HAVE_LIBMAGIC /* for mimetype auto-detection */
42 41 #include <magic.h>
43 42 #endif /* HAVE_LIBMAGIC */
44 43
45 44 static void
46 45 usage(char *program)
47 46 {
48 47 char *name;
49 48
50 49 if ((name = strrchr(program, '/')) == NULL)
51 50 name = program;
52 51 else
53 52 name++;
54 53
55 54 fprintf(stdout,
56 55 gettext("Usage: %s [-P printer] [-# copies] [-C class] "
57 56 "[-J job] [-T title] "
58 57 "[-p [-i indent] [-w width]] "
59 58 "[-1|-2|-3|-4 font] [-m] [-h] [-s] "
60 59 "[-filter_option] [file ..]\n"), name);
61 60 exit(1);
62 61 }
63 62
64 63 int
65 64 main(int ac, char *av[])
66 65 {
67 66 papi_status_t status;
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
68 67 papi_service_t svc = NULL;
69 68 papi_attribute_t **list = NULL;
70 69 papi_job_t job = NULL;
71 70 int exit_code = 0;
72 71 char *printer = NULL;
73 72 char prefetch[3];
74 73 int prefetch_len = sizeof (prefetch);
75 74 papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
76 75 int dump = 0;
77 76 int validate = 0;
78 - int remove = 0;
79 77 int copy = 1; /* default is to copy the data */
80 78 char *document_format = "text/plain";
81 79 int c;
82 80
83 81 (void) setlocale(LC_ALL, "");
84 82 (void) textdomain("SUNW_OST_OSCMD");
85 83
86 84 while ((c = getopt(ac, av,
87 85 "EP:#:C:DVJ:T:w:i:hplrstdgvcfmn1:2:3:4:")) != EOF)
88 86 switch (c) {
89 87 case 'E':
90 88 encryption = PAPI_ENCRYPT_REQUIRED;
91 89 break;
92 90 case 'P':
93 91 printer = optarg;
94 92 break;
95 93 case '#':
96 94 papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
97 95 "copies", atoi(optarg));
98 96 break;
99 97 case 'C':
100 98 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
101 99 "rfc-1179-class", optarg);
102 100 break;
103 101 case 'D':
104 102 dump = 1;
105 103 break;
106 104 case 'J':
107 105 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
108 106 "job-name", optarg);
109 107 break;
110 108 case 'T':
111 109 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
112 110 "pr-title", optarg);
113 111 break;
114 112 case 'p':
115 113 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
116 114 "document-format", "application/x-pr");
117 115 papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
118 116 "pr-filter", 1);
119 117 break;
120 118 case 'i':
121 119 papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
122 120 "pr-indent", atoi(optarg));
123 121 break;
124 122 case 'w':
125 123 papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
126 124 "pr-width", atoi(optarg));
127 125 break;
128 126 case 'h':
129 127 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
130 128 "job-sheets", "none");
131 129 break;
132 130 case 'l':
133 131 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
134 132 "document-format", "application/octet-stream");
135 133 break;
136 134 case 'o':
137 135 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
138 136 "document-format", "application/postscript");
139 137 break;
140 138 case 'c':
141 139 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
142 140 "document-format", "application/x-cif");
143 141 break;
144 142 case 'd':
145 143 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
146 144 "document-format", "application/x-dvi");
147 145 break;
148 146 case 'f':
149 147 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
150 148 "document-format", "application/x-fortran");
151 149 break;
152 150 case 'g':
153 151 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
154 152 "document-format", "application/x-plot");
155 153 break;
156 154 case 'n':
157 155 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
158 156 "document-format", "application/x-ditroff");
159 157 break;
160 158 case 't':
161 159 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
162 160 "document-format", "application/x-troff");
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
163 161 break;
164 162 case 'v':
165 163 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
166 164 "document-format", "application/x-raster");
167 165 break;
168 166 case 'm':
169 167 papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL,
170 168 "rfc-1179-mail", 1);
171 169 break;
172 170 case 'r':
173 - remove = 1;
174 171 break;
175 172 case 's':
176 173 copy = 0;
177 174 break;
178 175 case 'V': /* validate */
179 176 validate = 1;
180 177 break;
181 178 case '1':
182 179 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
183 180 "rfc-1179-font-r", optarg);
184 181 break;
185 182 case '2':
186 183 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
187 184 "rfc-1179-font-i", optarg);
188 185 break;
189 186 case '3':
190 187 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
191 188 "rfc-1179-font-b", optarg);
192 189 break;
193 190 case '4':
194 191 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
195 192 "rfc-1179-font-s", optarg);
196 193 break;
197 194 default:
198 195 usage(av[0]);
199 196 }
200 197
201 198 if ((printer == NULL) &&
202 199 ((printer = getenv("PRINTER")) == NULL) &&
203 200 ((printer = getenv("LPDEST")) == NULL))
204 201 printer = DEFAULT_DEST;
205 202
206 203 if (((optind + 1) == ac) && (strcmp(av[optind], "-") == 0))
207 204 optind = ac;
208 205
209 206 if (optind != ac) {
210 207 /* get the mime type of the file data */
211 208 #ifdef MAGIC_MIME
212 209 magic_t ms;
213 210
214 211 if ((ms = magic_open(MAGIC_MIME)) != NULL) {
215 212 document_format = magic_file(ms, av[optind]);
216 213 magic_close(ms);
217 214 }
218 215 #else
219 216 if (is_postscript(av[optind]) == 1)
220 217 document_format = "application/postscript";
221 218 #endif
222 219 } else {
223 220 if (is_postscript_stream(0, prefetch, &prefetch_len) == 1)
224 221 document_format = "application/postscript";
225 222 }
226 223
227 224 papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1);
228 225 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
229 226 "document-format", document_format);
230 227 papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
231 228 "job-sheets", "standard");
232 229
233 230 status = papiServiceCreate(&svc, printer, NULL, NULL, cli_auth_callback,
234 231 encryption, NULL);
235 232 if (status != PAPI_OK) {
236 233 fprintf(stderr, gettext(
237 234 "Failed to contact service for %s: %s\n"), printer,
238 235 verbose_papi_message(svc, status));
239 236 exit(1);
240 237 }
241 238
242 239 if (validate == 1) /* validate the request can be processed */
243 240 status = papiJobValidate(svc, printer, list,
244 241 NULL, &av[optind], &job);
245 242 else if (optind == ac) /* no file list, use stdin */
246 243 status = jobSubmitSTDIN(svc, printer, prefetch, prefetch_len,
247 244 list, &job);
248 245 else if (copy == 0) /* reference the files in the job, default */
249 246 status = papiJobSubmitByReference(svc, printer, list,
250 247 NULL, &av[optind], &job);
251 248 else /* copy the files before return, -c */
252 249 status = papiJobSubmit(svc, printer, list,
253 250 NULL, &av[optind], &job);
254 251
255 252 papiAttributeListFree(list);
256 253
257 254 if (status != PAPI_OK) {
258 255 fprintf(stderr, gettext("%s: %s\n"), printer,
259 256 verbose_papi_message(svc, status));
260 257 papiJobFree(job);
261 258 papiServiceDestroy(svc);
262 259 exit(1);
263 260 }
264 261
265 262 if (dump != 0) {
266 263 list = papiJobGetAttributeList(job);
267 264 printf("job attributes:\n");
268 265 papiAttributeListPrint(stdout, list, "\t");
269 266 printf("\n");
270 267 }
271 268
272 269 papiJobFree(job);
273 270 papiServiceDestroy(svc);
274 271
275 272 return (exit_code);
276 273 }
↓ open down ↓ |
93 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX