From 3d052e433049a9cd5a7a1b7934b8a39badc8102b Mon Sep 17 00:00:00 2001 From: msweet Date: Fri, 4 Jan 2008 02:32:38 +0000 Subject: Import CUPS 1.4svn-r7170. git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@567 a1ca3aef-8c08-0410-bb20-df032aa958be --- berkeley/lpr.c | 136 +++++++++++---------------------------------------------- 1 file changed, 26 insertions(+), 110 deletions(-) (limited to 'berkeley') diff --git a/berkeley/lpr.c b/berkeley/lpr.c index de01906bc..a1388be7e 100644 --- a/berkeley/lpr.c +++ b/berkeley/lpr.c @@ -1,5 +1,5 @@ /* - * "$Id: lpr.c 7017 2007-10-10 22:09:57Z mike $" + * "$Id: lpr.c 7170 2008-01-04 02:21:30Z mike $" * * "lpr" command for the Common UNIX Printing System (CUPS). * @@ -14,8 +14,7 @@ * * Contents: * - * main() - Parse options and send files for printing. - * sighandler() - Signal catcher for when we print from stdin... + * main() - Parse options and send files for printing. */ /* @@ -30,25 +29,6 @@ #include #include -#ifndef WIN32 -# include -# include - - -/* - * Local functions. - */ - -void sighandler(int); -#endif /* !WIN32 */ - - -/* - * Globals... - */ - -char tempfile[1024]; /* Temporary file for printing from stdin */ - /* * 'main()' - Parse options and send files for printing. @@ -73,13 +53,6 @@ main(int argc, /* I - Number of command-line arguments */ cups_option_t *options; /* Options */ int deletefile; /* Delete file after print? */ char buffer[8192]; /* Copy buffer */ - ssize_t bytes; /* Bytes copied */ - off_t filesize; /* Size of temp file */ - int temp; /* Temporary file descriptor */ -#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) - struct sigaction action; /* Signal action */ - struct sigaction oldaction; /* Old signal action */ -#endif /* HAVE_SIGACTION && !HAVE_SIGSET */ _cupsSetLocale(argv); @@ -409,72 +382,38 @@ main(int argc, /* I - Number of command-line arguments */ unlink(files[i]); } } - else + else if ((job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, printer, + title ? title : "(stdin)", + num_options, options)) > 0) { - num_files = 1; - -#ifndef WIN32 -# if defined(HAVE_SIGSET) - sigset(SIGHUP, sighandler); - if (sigset(SIGINT, sighandler) == SIG_IGN) - sigset(SIGINT, SIG_IGN); - sigset(SIGTERM, sighandler); -# elif defined(HAVE_SIGACTION) - memset(&action, 0, sizeof(action)); - action.sa_handler = sighandler; - - sigaction(SIGHUP, &action, NULL); - sigaction(SIGINT, NULL, &oldaction); - if (oldaction.sa_handler != SIG_IGN) - sigaction(SIGINT, &action, NULL); - sigaction(SIGTERM, &action, NULL); -# else - signal(SIGHUP, sighandler); - if (signal(SIGINT, sighandler) == SIG_IGN) - signal(SIGINT, SIG_IGN); - signal(SIGTERM, sighandler); -# endif -#endif /* !WIN32 */ - - if ((temp = cupsTempFd(tempfile, sizeof(tempfile))) < 0) - { - _cupsLangPrintf(stderr, - _("%s: Error - unable to create temporary file " - "\"%s\" - %s\n"), - argv[0], tempfile, strerror(errno)); - return (1); - } + http_status_t status; /* Write status */ + const char *format; /* Document format */ + ssize_t bytes; /* Bytes read */ - while ((bytes = read(0, buffer, sizeof(buffer))) > 0) - if (write(temp, buffer, bytes) < 0) - { - _cupsLangPrintf(stderr, - _("%s: Error - unable to write to temporary file " - "\"%s\" - %s\n"), - argv[0], tempfile, strerror(errno)); - close(temp); - unlink(tempfile); - return (1); - } - filesize = lseek(temp, 0, SEEK_CUR); - close(temp); + if (cupsGetOption("raw", num_options, options)) + format = CUPS_FORMAT_RAW; + else if ((format = cupsGetOption("document-format", num_options, + options)) == NULL) + format = CUPS_FORMAT_AUTO; + + status = cupsStartDocument(CUPS_HTTP_DEFAULT, printer, job_id, NULL, + format, 1); - if (filesize <= 0) + while (status == HTTP_CONTINUE && + (bytes = read(0, buffer, sizeof(buffer))) > 0) + status = cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, bytes); + + if (status != HTTP_CONTINUE) { _cupsLangPrintf(stderr, - _("%s: Error - stdin is empty, so no job has been sent.\n"), - argv[0]); - unlink(tempfile); + _("%s: Error - unable to queue from stdin - %s\n"), + argv[0], httpStatus(status)); return (1); } - if (title) - job_id = cupsPrintFile(printer, tempfile, title, num_options, options); - else - job_id = cupsPrintFile(printer, tempfile, "(stdin)", num_options, options); - - unlink(tempfile); + if (cupsFinishDocument(CUPS_HTTP_DEFAULT, printer) != IPP_OK) + job_id = 0; } if (job_id < 1) @@ -487,29 +426,6 @@ main(int argc, /* I - Number of command-line arguments */ } -#ifndef WIN32 -/* - * 'sighandler()' - Signal catcher for when we print from stdin... - */ - -void -sighandler(int s) /* I - Signal number */ -{ - /* - * Remove the temporary file we're using to print from stdin... - */ - - unlink(tempfile); - - /* - * Exit... - */ - - exit(s); -} -#endif /* !WIN32 */ - - /* - * End of "$Id: lpr.c 7017 2007-10-10 22:09:57Z mike $". + * End of "$Id: lpr.c 7170 2008-01-04 02:21:30Z mike $". */ -- cgit v1.2.1