4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* $Id: lpr.c 146 2006-03-24 00:26:54Z njacobs $ */
30 #pragma ident "%Z%%M% %I% %E% SMI"
41 #ifdef HAVE_LIBMAGIC /* for mimetype auto-detection */
43 #endif /* HAVE_LIBMAGIC */
50 if ((name
= strrchr(program
, '/')) == NULL
)
56 gettext("Usage: %s [-P printer] [-# copies] [-C class] "
57 "[-J job] [-T title] "
58 "[-p [-i indent] [-w width]] "
59 "[-1|-2|-3|-4 font] [-m] [-h] [-s] "
60 "[-filter_option] [file ..]\n"), name
);
65 main(int ac
, char *av
[])
68 papi_service_t svc
= NULL
;
69 papi_attribute_t
**list
= NULL
;
70 papi_job_t job
= NULL
;
74 int prefetch_len
= sizeof (prefetch
);
75 papi_encryption_t encryption
= PAPI_ENCRYPT_NEVER
;
79 int copy
= 1; /* default is to copy the data */
80 char *document_format
= "text/plain";
83 (void) setlocale(LC_ALL
, "");
84 (void) textdomain("SUNW_OST_OSCMD");
86 while ((c
= getopt(ac
, av
,
87 "EP:#:C:DVJ:T:w:i:hplrstdgvcfmn1:2:3:4:")) != EOF
)
90 encryption
= PAPI_ENCRYPT_REQUIRED
;
96 papiAttributeListAddInteger(&list
, PAPI_ATTR_EXCL
,
97 "copies", atoi(optarg
));
100 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
101 "rfc-1179-class", optarg
);
107 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
111 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
115 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
116 "document-format", "application/x-pr");
117 papiAttributeListAddBoolean(&list
, PAPI_ATTR_EXCL
,
121 papiAttributeListAddInteger(&list
, PAPI_ATTR_EXCL
,
122 "pr-indent", atoi(optarg
));
125 papiAttributeListAddInteger(&list
, PAPI_ATTR_EXCL
,
126 "pr-width", atoi(optarg
));
129 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
130 "job-sheets", "none");
133 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
134 "document-format", "application/octet-stream");
137 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
138 "document-format", "application/postscript");
141 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
142 "document-format", "application/x-cif");
145 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
146 "document-format", "application/x-dvi");
149 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
150 "document-format", "application/x-fortran");
153 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
154 "document-format", "application/x-plot");
157 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
158 "document-format", "application/x-ditroff");
161 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
162 "document-format", "application/x-troff");
165 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
166 "document-format", "application/x-raster");
169 papiAttributeListAddBoolean(&list
, PAPI_ATTR_EXCL
,
178 case 'V': /* validate */
182 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
183 "rfc-1179-font-r", optarg
);
186 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
187 "rfc-1179-font-i", optarg
);
190 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
191 "rfc-1179-font-b", optarg
);
194 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
195 "rfc-1179-font-s", optarg
);
201 if ((printer
== NULL
) &&
202 ((printer
= getenv("PRINTER")) == NULL
) &&
203 ((printer
= getenv("LPDEST")) == NULL
))
204 printer
= DEFAULT_DEST
;
206 if (((optind
+ 1) == ac
) && (strcmp(av
[optind
], "-") == 0))
210 /* get the mime type of the file data */
214 if ((ms
= magic_open(MAGIC_MIME
)) != NULL
) {
215 document_format
= magic_file(ms
, av
[optind
]);
219 if (is_postscript(av
[optind
]) == 1)
220 document_format
= "application/postscript";
223 if (is_postscript_stream(0, prefetch
, &prefetch_len
) == 1)
224 document_format
= "application/postscript";
227 papiAttributeListAddInteger(&list
, PAPI_ATTR_EXCL
, "copies", 1);
228 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
229 "document-format", document_format
);
230 papiAttributeListAddString(&list
, PAPI_ATTR_EXCL
,
231 "job-sheets", "standard");
233 status
= papiServiceCreate(&svc
, printer
, NULL
, NULL
, cli_auth_callback
,
235 if (status
!= PAPI_OK
) {
236 fprintf(stderr
, gettext(
237 "Failed to contact service for %s: %s\n"), printer
,
238 verbose_papi_message(svc
, status
));
242 if (validate
== 1) /* validate the request can be processed */
243 status
= papiJobValidate(svc
, printer
, list
,
244 NULL
, &av
[optind
], &job
);
245 else if (optind
== ac
) /* no file list, use stdin */
246 status
= jobSubmitSTDIN(svc
, printer
, prefetch
, prefetch_len
,
248 else if (copy
== 0) /* reference the files in the job, default */
249 status
= papiJobSubmitByReference(svc
, printer
, list
,
250 NULL
, &av
[optind
], &job
);
251 else /* copy the files before return, -c */
252 status
= papiJobSubmit(svc
, printer
, list
,
253 NULL
, &av
[optind
], &job
);
255 papiAttributeListFree(list
);
257 if (status
!= PAPI_OK
) {
258 fprintf(stderr
, gettext("%s: %s\n"), printer
,
259 verbose_papi_message(svc
, status
));
261 papiServiceDestroy(svc
);
266 list
= papiJobGetAttributeList(job
);
267 printf("job attributes:\n");
268 papiAttributeListPrint(stdout
, list
, "\t");
273 papiServiceDestroy(svc
);