/*
- * "$Id: pstops.c 6578 2007-06-20 17:46:04Z mike $"
+ * "$Id: pstops.c 6759 2007-08-02 04:10:23Z mike $"
*
* PostScript filter for the Common UNIX Printing System (CUPS).
*
+ * Copyright 2007 by Apple Inc.
* Copyright 1993-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*
*
* main() - Main entry...
* add_page() - Add a page to the pages array...
+ * cancel_job() - Flag the job as canceled.
* check_range() - Check to see if the current page is selected for
* copy_bytes() - Copy bytes from the input file to stdout...
* copy_comments() - Copy all of the comments section...
#include <cups/file.h>
#include <cups/array.h>
#include <cups/i18n.h>
+#include <signal.h>
/*
((p) % doc->number_up) != 0)
+/*
+ * Local globals...
+ */
+
+static int JobCanceled = 0;/* Set to 1 on SIGTERM */
+
+
/*
* Local functions...
*/
static pstops_page_t *add_page(pstops_doc_t *doc, const char *label);
+static void cancel_job(int sig);
static int check_range(pstops_doc_t *doc, int page);
static void copy_bytes(cups_file_t *fp, off_t offset,
size_t length);
cups_option_t *options; /* Print options */
char line[8192]; /* Line buffer */
size_t len; /* Length of line buffer */
+#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
+ struct sigaction action; /* Actions for POSIX signals */
+#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
/*
return (1);
}
+ /*
+ * Register a signal handler to cleanly cancel a job.
+ */
+
+#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
+ sigset(SIGTERM, cancel_job);
+#elif defined(HAVE_SIGACTION)
+ memset(&action, 0, sizeof(action));
+
+ sigemptyset(&action.sa_mask);
+ action.sa_handler = cancel_job;
+ sigaction(SIGTERM, &action, NULL);
+#else
+ signal(SIGTERM, cancel_job);
+#endif /* HAVE_SIGSET */
+
/*
* If we have 7 arguments, print the file named on the command-line.
* Otherwise, send stdin instead...
}
+/*
+ * 'cancel_job()' - Flag the job as canceled.
+ */
+
+static void
+cancel_job(int sig) /* I - Signal number (unused) */
+{
+ (void)sig;
+
+ JobCanceled = 1;
+}
+
+
/*
* 'check_range()' - Check to see if the current page is selected for
* printing.
fprintf(stderr, "DEBUG: Before page loop - %s", line);
while (!strncmp(line, "%%Page:", 7))
{
+ if (JobCanceled)
+ break;
+
number ++;
if (check_range(doc, (number - 1) / doc->number_up + 1))
number = doc->slow_order ? 0 : doc->page;
- if (doc->temp)
+ if (doc->temp && !JobCanceled)
{
int copy; /* Current copy */
for (copy = !doc->slow_order; copy < doc->copies; copy ++)
{
+ if (JobCanceled)
+ break;
+
/*
* Send end-of-job stuff followed by any start-of-job stuff required
* for the JCL options...
while (pageinfo)
{
+ if (JobCanceled)
+ break;
+
number ++;
if (!ppd || !ppd->num_filters)
* Write/copy the trailer...
*/
- linelen = copy_trailer(fp, doc, ppd, number, line, linelen, linesize);
+ if (!JobCanceled)
+ linelen = copy_trailer(fp, doc, ppd, number, line, linelen, linesize);
}
puts("ESPshowpage");
}
- if (doc->temp)
+ if (doc->temp && !JobCanceled)
{
/*
* Reopen the temporary file for reading...
for (copy = 1; copy < doc->copies; copy ++)
{
+ if (JobCanceled)
+ break;
+
if (!ppd || !ppd->num_filters)
fputs("PAGE: 1 1\n", stderr);
/*
- * End of "$Id: pstops.c 6578 2007-06-20 17:46:04Z mike $".
+ * End of "$Id: pstops.c 6759 2007-08-02 04:10:23Z mike $".
*/