/*
- * "$Id: pstops.c 10996 2013-05-29 11:51:34Z msweet $"
+ * "$Id: pstops.c 11558 2014-02-06 18:33:34Z msweet $"
*
- * PostScript filter for CUPS.
+ * PostScript filter for CUPS.
*
- * Copyright 2007-2012 by Apple Inc.
- * Copyright 1993-2007 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1993-2007 by Easy Software Products.
*
- * These coded instructions, statements, and computer programs are the
- * 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/".
+ * These coded instructions, statements, and computer programs are the
+ * 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.
- *
- * Contents:
- *
- * 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
- * printing.
- * copy_bytes() - Copy bytes from the input file to stdout.
- * copy_comments() - Copy all of the comments section.
- * copy_dsc() - Copy a DSC-conforming document.
- * copy_non_dsc() - Copy a document that does not conform to the DSC.
- * copy_page() - Copy a page description.
- * copy_prolog() - Copy the document prolog section.
- * copy_setup() - Copy the document setup section.
- * copy_trailer() - Copy the document trailer.
- * do_prolog() - Send the necessary document prolog commands.
- * do_setup() - Send the necessary document setup commands.
- * doc_printf() - Send a formatted string to stdout and/or the temp
- * file.
- * doc_puts() - Send a nul-terminated string to stdout and/or the
- * temp file.
- * doc_write() - Send data to stdout and/or the temp file.
- * end_nup() - End processing for N-up printing.
- * include_feature() - Include a printer option/feature command.
- * parse_text() - Parse a text value in a comment.
- * set_pstops_options() - Set pstops options.
- * skip_page() - Skip past a page that won't be printed.
- * start_nup() - Start processing for N-up printing.
- * write_label_prolog() - Write the prolog with the classification and page
- * label.
- * write_labels() - Write the actual page labels.
- * write_options() - Write options provided via %%IncludeFeature.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
int num_options; /* Number of print options */
cups_option_t *options; /* Print options */
char line[8192]; /* Line buffer */
- size_t len; /* Length of line buffer */
+ ssize_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 */
* Read the first line to see if we have DSC comments...
*/
- if ((len = cupsFileGetLine(fp, line, sizeof(line))) == 0)
+ if ((len = (ssize_t)cupsFileGetLine(fp, line, sizeof(line))) == 0)
{
fputs("DEBUG: The print file is empty.\n", stderr);
return (1);
fputs("DEBUG: Skipping PJL header...\n", stderr);
while (strstr(line, "ENTER LANGUAGE") == NULL && strncmp(line, "%!", 2))
- if ((len = cupsFileGetLine(fp, line, sizeof(line))) == 0)
+ if ((len = (ssize_t)cupsFileGetLine(fp, line, sizeof(line))) == 0)
break;
if (!strncmp(line, "%!", 2))
break;
- if ((len = cupsFileGetLine(fp, line, sizeof(line))) == 0)
+ if ((len = (ssize_t)cupsFileGetLine(fp, line, sizeof(line))) == 0)
break;
}
{
lower = 1;
range ++;
- upper = strtol(range, (char **)&range, 10);
+ upper = (int)strtol(range, (char **)&range, 10);
}
else
{
- lower = strtol(range, (char **)&range, 10);
+ lower = (int)strtol(range, (char **)&range, 10);
if (*range == '-')
{
if (!isdigit(*range & 255))
upper = 65535;
else
- upper = strtol(range, (char **)&range, 10);
+ upper = (int)strtol(range, (char **)&range, 10);
}
else
upper = lower;
if (nleft > sizeof(buffer) || length == 0)
nbytes = sizeof(buffer);
else
- nbytes = nleft;
+ nbytes = (ssize_t)nleft;
- if ((nbytes = cupsFileRead(fp, buffer, nbytes)) < 1)
+ if ((nbytes = cupsFileRead(fp, buffer, (size_t)nbytes)) < 1)
return;
- nleft -= nbytes;
+ nleft -= (size_t)nbytes;
- fwrite(buffer, 1, nbytes, stdout);
+ fwrite(buffer, 1, (size_t)nbytes, stdout);
}
}
}
else if (!strcmp(line, "%%EndComments"))
{
- linelen = cupsFileGetLine(fp, line, linesize);
+ linelen = (ssize_t)cupsFileGetLine(fp, line, linesize);
break;
}
else if (strncmp(line, "%!", 2) && strncmp(line, "%cups", 5))
doc_printf(doc, "%s\n", line);
- if ((linelen = cupsFileGetLine(fp, line, linesize)) == 0)
+ if ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) == 0)
break;
}
while (strncmp(line, "%%Page:", 7) && strncmp(line, "%%Trailer", 9))
{
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
- if ((linelen = cupsFileGetLine(fp, line, linesize)) == 0)
+ if ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) == 0)
break;
}
doc_puts(doc, "showpage\n");
end_nup(doc, doc->number_up);
- pageinfo->length = cupsFileTell(doc->temp) - pageinfo->offset;
+ pageinfo->length = (ssize_t)(cupsFileTell(doc->temp) - pageinfo->offset);
}
if (doc->slow_duplex && (doc->page & 1))
doc_puts(doc, "showpage\n");
end_nup(doc, doc->number_up);
- pageinfo->length = cupsFileTell(doc->temp) - pageinfo->offset;
+ pageinfo->length = (ssize_t)(cupsFileTell(doc->temp) - pageinfo->offset);
}
/*
if (!number)
{
pageinfo = (pstops_page_t *)cupsArrayFirst(doc->pages);
- copy_bytes(doc->temp, 0, pageinfo->offset);
+ copy_bytes(doc->temp, 0, (size_t)pageinfo->offset);
}
/*
pageinfo->bounding_box[2], pageinfo->bounding_box[3]);
}
- copy_bytes(doc->temp, pageinfo->offset, pageinfo->length);
+ copy_bytes(doc->temp, pageinfo->offset, (size_t)pageinfo->length);
pageinfo = doc->slow_order ? (pstops_page_t *)cupsArrayPrev(doc->pages) :
(pstops_page_t *)cupsArrayNext(doc->pages);
ssize_t linelen, /* I - Length of initial line */
size_t linesize) /* I - Size of line buffer */
{
- int copy; /* Current copy */
- char buffer[8192]; /* Copy buffer */
- int bytes; /* Number of bytes copied */
+ int copy; /* Current copy */
+ char buffer[8192]; /* Copy buffer */
+ ssize_t bytes; /* Number of bytes copied */
+ (void)linesize;
+
/*
* First let the user know that they are attempting to print a file
* that may not print correctly...
puts("%%EndPageSetup");
puts("%%BeginDocument: nondsc");
- fwrite(line, linelen, 1, stdout);
+ fwrite(line, (size_t)linelen, 1, stdout);
if (doc->temp)
- cupsFileWrite(doc->temp, line, linelen);
+ cupsFileWrite(doc->temp, line, (size_t)linelen);
while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
{
- fwrite(buffer, 1, bytes, stdout);
+ fwrite(buffer, 1, (size_t)bytes, stdout);
if (doc->temp)
- cupsFileWrite(doc->temp, buffer, bytes);
+ cupsFileWrite(doc->temp, buffer, (size_t)bytes);
}
puts("%%EndDocument");
memcpy(bounding_box, doc->bounding_box, sizeof(bounding_box));
- while ((linelen = cupsFileGetLine(fp, line, linesize)) > 0)
+ while ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) > 0)
{
if (!strncmp(line, "%%PageBoundingBox:", 18))
{
switch (Orientation)
{
case 1 : /* Landscape */
- bounding_box[0] = PageLength - temp_bbox[3];
+ bounding_box[0] = (int)(PageLength - temp_bbox[3]);
bounding_box[1] = temp_bbox[0];
- bounding_box[2] = PageLength - temp_bbox[1];
+ bounding_box[2] = (int)(PageLength - temp_bbox[1]);
bounding_box[3] = temp_bbox[2];
break;
case 2 : /* Reverse Portrait */
- bounding_box[0] = PageWidth - temp_bbox[2];
- bounding_box[1] = PageLength - temp_bbox[3];
- bounding_box[2] = PageWidth - temp_bbox[0];
- bounding_box[3] = PageLength - temp_bbox[1];
+ bounding_box[0] = (int)(PageWidth - temp_bbox[2]);
+ bounding_box[1] = (int)(PageLength - temp_bbox[3]);
+ bounding_box[2] = (int)(PageWidth - temp_bbox[0]);
+ bounding_box[3] = (int)(PageLength - temp_bbox[1]);
break;
case 3 : /* Reverse Landscape */
bounding_box[0] = temp_bbox[1];
- bounding_box[1] = PageWidth - temp_bbox[2];
+ bounding_box[1] = (int)(PageWidth - temp_bbox[2]);
bounding_box[2] = temp_bbox[3];
- bounding_box[3] = PageWidth - temp_bbox[0];
+ bounding_box[3] = (int)(PageWidth - temp_bbox[0]);
break;
}
{
int feature = 0; /* In a Begin/EndFeature block? */
- while ((linelen = cupsFileGetLine(fp, line, linesize)) > 0)
+ while ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) > 0)
{
if (!strncmp(line, "%%EndPageSetup", 14))
break;
break;
if (!feature || (doc->number_up == 1 && !doc->fit_to_page))
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
}
/*
*/
if (linelen > 0 && !strncmp(line, "%%EndPageSetup", 14))
- linelen = cupsFileGetLine(fp, line, linesize);
+ linelen = (ssize_t)cupsFileGetLine(fp, line, linesize);
}
if (first_page)
else if (!strncmp(line, "%%BeginDocument", 15) ||
!strncmp(line, "%ADO_BeginApplication", 21))
{
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
level ++;
}
else if ((!strncmp(line, "%%EndDocument", 13) ||
!strncmp(line, "%ADO_EndApplication", 19)) && level > 0)
{
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
level --;
}
int bytes; /* Bytes of data */
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
bytes = atoi(strchr(line, ':') + 1);
while (bytes > 0)
{
- if (bytes > linesize)
+ if ((size_t)bytes > linesize)
linelen = cupsFileRead(fp, line, linesize);
else
- linelen = cupsFileRead(fp, line, bytes);
+ linelen = cupsFileRead(fp, line, (size_t)bytes);
if (linelen < 1)
{
return (0);
}
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
bytes -= linelen;
}
}
else
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
}
- while ((linelen = cupsFileGetLine(fp, line, linesize)) > 0);
+ while ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) > 0);
/*
* Finish up this page and return...
end_nup(doc, number);
- pageinfo->length = cupsFileTell(doc->temp) - pageinfo->offset;
+ pageinfo->length = (ssize_t)(cupsFileTell(doc->temp) - pageinfo->offset);
return (linelen);
}
if (!strncmp(line, "%%BeginSetup", 12) || !strncmp(line, "%%Page:", 7))
break;
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
- if ((linelen = cupsFileGetLine(fp, line, linesize)) == 0)
+ if ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) == 0)
break;
}
if (!strncmp(line, "%%BeginProlog", 13))
{
- while ((linelen = cupsFileGetLine(fp, line, linesize)) > 0)
+ while ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) > 0)
{
if (!strncmp(line, "%%EndProlog", 11) ||
!strncmp(line, "%%BeginSetup", 12) ||
!strncmp(line, "%%Page:", 7))
break;
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
}
if (!strncmp(line, "%%EndProlog", 11))
- linelen = cupsFileGetLine(fp, line, linesize);
+ linelen = (ssize_t)cupsFileGetLine(fp, line, linesize);
else
fputs("DEBUG: The %%EndProlog comment is missing.\n", stderr);
}
if (!strncmp(line, "%%Page:", 7))
break;
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
- if ((linelen = cupsFileGetLine(fp, line, linesize)) == 0)
+ if ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) == 0)
break;
}
num_options = include_feature(ppd, line, num_options, &options);
}
else if (strncmp(line, "%%BeginSetup", 12))
- doc_write(doc, line, linelen);
+ doc_write(doc, line, (size_t)linelen);
- if ((linelen = cupsFileGetLine(fp, line, linesize)) == 0)
+ if ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) == 0)
break;
}
if (!strncmp(line, "%%EndSetup", 10))
- linelen = cupsFileGetLine(fp, line, linesize);
+ linelen = (ssize_t)cupsFileGetLine(fp, line, linesize);
else
fputs("DEBUG: The %%EndSetup comment is missing.\n", stderr);
}
* Write the trailer comments...
*/
+ (void)ppd;
+
puts("%%Trailer");
while (linelen > 0)
else if (strncmp(line, "%%Trailer", 9) &&
strncmp(line, "%%Pages:", 8) &&
strncmp(line, "%%BoundingBox:", 14))
- fwrite(line, 1, linelen, stdout);
+ fwrite(line, 1, (size_t)linelen, stdout);
- linelen = cupsFileGetLine(fp, line, linesize);
+ linelen = (ssize_t)cupsFileGetLine(fp, line, linesize);
}
fprintf(stderr, "DEBUG: Wrote %d pages...\n", number);
{
va_list ap; /* Pointer to arguments */
char buffer[1024]; /* Output buffer */
- size_t bytes; /* Number of bytes to write */
+ ssize_t bytes; /* Number of bytes to write */
va_start(ap, format);
bytes = vsnprintf(buffer, sizeof(buffer), format, ap);
va_end(ap);
- if (bytes > sizeof(buffer))
+ if ((size_t)bytes > sizeof(buffer))
{
_cupsLangPrintFilter(stderr, "ERROR",
_("Buffer overflow detected, aborting."));
exit(1);
}
- doc_write(doc, buffer, bytes);
+ doc_write(doc, buffer, (size_t)bytes);
}
level = 0;
- while ((linelen = cupsFileGetLine(fp, line, linesize)) > 0)
+ while ((linelen = (ssize_t)cupsFileGetLine(fp, line, linesize)) > 0)
{
if (level == 0 &&
(!strncmp(line, "%%Page:", 7) || !strncmp(line, "%%Trailer", 9)))
* Skip binary data...
*/
- int bytes; /* Bytes of data */
-
+ ssize_t bytes; /* Bytes of data */
bytes = atoi(strchr(line, ':') + 1);
while (bytes > 0)
{
- if (bytes > linesize)
- linelen = cupsFileRead(fp, line, linesize);
+ if ((size_t)bytes > linesize)
+ linelen = (ssize_t)cupsFileRead(fp, line, linesize);
else
- linelen = cupsFileRead(fp, line, bytes);
+ linelen = (ssize_t)cupsFileRead(fp, line, (size_t)bytes);
if (linelen < 1)
{
{
int pos; /* Position on page */
int x, y; /* Relative position of subpage */
- float w, l, /* Width and length of subpage */
+ double w, l, /* Width and length of subpage */
tx, ty; /* Translation values for subpage */
- float pagew, /* Printable width of page */
+ double pagew, /* Printable width of page */
pagel; /* Printable height of page */
int bboxx, /* BoundingBox X origin */
bboxy, /* BoundingBox Y origin */
bboxw, /* BoundingBox width */
bboxl; /* BoundingBox height */
- float margin = 0; /* Current margin for border */
+ double margin = 0; /* Current margin for border */
if (doc->number_up > 1)
{
bboxx = 0;
bboxy = 0;
- bboxw = PageWidth;
- bboxl = PageLength;
+ bboxw = (int)PageWidth;
+ bboxl = (int)PageLength;
}
fprintf(stderr, "DEBUG: pagew = %.1f, pagel = %.1f\n", pagew, pagel);
if (doc->page_border && show_border)
{
int rects; /* Number of border rectangles */
- float fscale; /* Scaling value for points */
+ double fscale; /* Scaling value for points */
rects = (doc->page_border & PSTOPS_BORDERDOUBLE) ? 2 : 1;
{
int i; /* Looping var */
ppd_option_t *option; /* PPD option */
- int min_order; /* Minimum OrderDependency value */
+ float min_order; /* Minimum OrderDependency value */
char *doc_setup, /* DocumentSetup commands to send */
*any_setup; /* AnySetup commands to send */
/*
- * End of "$Id: pstops.c 10996 2013-05-29 11:51:34Z msweet $".
+ * End of "$Id: pstops.c 11558 2014-02-06 18:33:34Z msweet $".
*/