summaryrefslogtreecommitdiff
path: root/usr/src/cmd/print/bsd-sysv-commands
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/print/bsd-sysv-commands')
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/common.c36
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/common.h4
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lp.c9
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lpr.c8
4 files changed, 43 insertions, 14 deletions
diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.c b/usr/src/cmd/print/bsd-sysv-commands/common.c
index fbc68459f8..92a629f776 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/common.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.c
@@ -400,8 +400,8 @@ strsplit(char *string, const char *seperators)
}
papi_status_t
-jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list,
- papi_job_t *job)
+jobSubmitSTDIN(papi_service_t svc, char *printer, char *prefetch, int len,
+ papi_attribute_t **list, papi_job_t *job)
{
papi_status_t status;
papi_stream_t stream = NULL;
@@ -409,6 +409,10 @@ jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list,
char buf[BUFSIZ];
status = papiJobStreamOpen(svc, printer, list, NULL, &stream);
+
+ if (len > 0)
+ status = papiJobStreamWrite(svc, stream, prefetch, len);
+
while ((status == PAPI_OK) && ((rc = read(0, buf, sizeof (buf))) > 0))
status = papiJobStreamWrite(svc, stream, buf, rc);
@@ -426,19 +430,12 @@ jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list,
#define PS_MAGIC "%!"
#define PC_PS_MAGIC "^D%!"
int
-is_postscript(const char *file)
+is_postscript_stream(int fd, char *buf, int *len)
{
- char buf[3];
- int fd;
-
- if ((fd = open(file, O_RDONLY)) < 0)
- return (-1);
-
- if (read(fd, buf, sizeof (buf)) < 0) {
+ if ((*len = read(fd, buf, *len)) < 0) {
close(fd);
return (-1);
}
- close(fd);
if ((strncmp(buf, PS_MAGIC, sizeof (PS_MAGIC) - 1) == 0) ||
(strncmp(buf, PC_PS_MAGIC, sizeof (PC_PS_MAGIC) - 1) == 0))
@@ -447,6 +444,23 @@ is_postscript(const char *file)
return (0);
}
+int
+is_postscript(const char *file)
+{
+ int rc = -1;
+ int fd;
+
+ if ((fd = open(file, O_RDONLY)) >= 0) {
+ char buf[3];
+ int len = sizeof (buf);
+
+ rc = is_postscript_stream(fd, buf, &len);
+ close(fd);
+ }
+
+ return (rc);
+}
+
static char **
all_list(papi_service_t svc)
{
diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.h b/usr/src/cmd/print/bsd-sysv-commands/common.h
index e8169ed0da..4a74be0abf 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/common.h
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.h
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
@@ -52,12 +52,14 @@ extern int berkeley_queue_report(papi_service_t svc, FILE *fp, char *dest,
int fmt, int ac, char *av[]);
extern papi_status_t jobSubmitSTDIN(papi_service_t svc, char *printer,
+ char *prefetch, int len,
papi_attribute_t **list, papi_job_t *job);
extern char **interest_list(papi_service_t svc);
extern char *localhostname();
extern char *lp_type_to_mime_type(char *lp_type);
extern int is_postscript(const char *file);
+extern int is_postscript_stream(int fd, char *buf, int *len);
extern int cli_auth_callback(papi_service_t svc, void *app_data);
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lp.c b/usr/src/cmd/print/bsd-sysv-commands/lp.c
index aeec532e54..c7f6b1d4a9 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/lp.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/lp.c
@@ -70,6 +70,8 @@ main(int ac, char *av[])
papi_attribute_t **list = NULL;
papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
papi_job_t job = NULL;
+ char prefetch[3];
+ int prefetch_len = sizeof (prefetch);
char *printer = NULL;
char b = PAPI_TRUE;
int copy = 0;
@@ -230,6 +232,10 @@ main(int ac, char *av[])
if (is_postscript(av[optind]) == 1)
document_format = "application/postscript";
#endif
+ } else {
+ if (is_postscript_stream(0, prefetch, &prefetch_len)
+ == 1)
+ document_format = "application/postscript";
}
papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1);
@@ -257,7 +263,8 @@ main(int ac, char *av[])
if (modify != -1)
status = papiJobModify(svc, printer, modify, list, &job);
else if (optind == ac) /* no file list, use stdin */
- status = jobSubmitSTDIN(svc, printer, list, &job);
+ status = jobSubmitSTDIN(svc, printer, prefetch, prefetch_len,
+ list, &job);
else if (validate == 1) /* validate the request can be processed */
status = papiJobValidate(svc, printer, list,
NULL, &av[optind], &job);
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lpr.c b/usr/src/cmd/print/bsd-sysv-commands/lpr.c
index fe6c24a8bc..547e0df36f 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/lpr.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpr.c
@@ -70,6 +70,8 @@ main(int ac, char *av[])
papi_job_t job = NULL;
int exit_code = 0;
char *printer = NULL;
+ char prefetch[3];
+ int prefetch_len = sizeof (prefetch);
papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
int dump = 0;
int validate = 0;
@@ -217,6 +219,9 @@ main(int ac, char *av[])
if (is_postscript(av[optind]) == 1)
document_format = "application/postscript";
#endif
+ } else {
+ if (is_postscript_stream(0, prefetch, &prefetch_len) == 1)
+ document_format = "application/postscript";
}
papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1);
@@ -238,7 +243,8 @@ main(int ac, char *av[])
status = papiJobValidate(svc, printer, list,
NULL, &av[optind], &job);
else if (optind == ac) /* no file list, use stdin */
- status = jobSubmitSTDIN(svc, printer, list, &job);
+ status = jobSubmitSTDIN(svc, printer, prefetch, prefetch_len,
+ list, &job);
else if (copy == 0) /* reference the files in the job, default */
status = papiJobSubmitByReference(svc, printer, list,
NULL, &av[optind], &job);