*
* Raster error handling for CUPS.
*
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2015 by Apple Inc.
* Copyright 2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* Initialize the global data exactly once...
*/
- DEBUG_puts("get_error_buffer()");
+ DEBUG_puts("3get_error_buffer()");
pthread_once(&raster_key_once, raster_init);
if ((buf = (_cups_raster_error_t *)pthread_getspecific(raster_key))
== NULL)
{
- DEBUG_puts("get_error_buffer: allocating memory for thread...");
+ DEBUG_puts("4get_error_buffer: allocating memory for thread.");
/*
* No, allocate memory as set the pointer for the key...
buf = calloc(1, sizeof(_cups_raster_error_t));
pthread_setspecific(raster_key, buf);
- DEBUG_printf((" buf=%p\n", buf));
+ DEBUG_printf(("4get_error_buffer: buf=%p", buf));
}
/*
{
pthread_key_create(&raster_key, raster_destructor);
- DEBUG_printf(("raster_init(): raster_key=%x(%u)\n", (unsigned)raster_key,
- (unsigned)raster_key));
+ DEBUG_printf(("3raster_init(): raster_key=%x(%u)", (unsigned)raster_key, (unsigned)raster_key));
}
/* Error buffer */
- DEBUG_printf(("raster_destructor(value=%p)\n", value));
+ DEBUG_printf(("3raster_destructor(value=%p)", value));
if (buf->start)
free(buf->start);
*
* PPD command interpreter for CUPS.
*
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2015 by Apple Inc.
* Copyright 1993-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
cups_page_header2_t *h,
int *preferred_bits);
#ifdef DEBUG
-static void DEBUG_object(_cups_ps_obj_t *obj);
-static void DEBUG_stack(_cups_ps_stack_t *st);
+static void DEBUG_object(const char *prefix, _cups_ps_obj_t *obj);
+static void DEBUG_stack(const char *prefix, _cups_ps_stack_t *st);
#endif /* DEBUG */
while ((obj = scan_ps(st, &codeptr)) != NULL)
{
#ifdef DEBUG
- DEBUG_printf(("_cupsRasterExecPS: Stack (%d objects)\n", st->num_objs));
- DEBUG_object(obj);
+ DEBUG_printf(("_cupsRasterExecPS: Stack (%d objects)", st->num_objs));
+ DEBUG_object("_cupsRasterExecPS", obj);
#endif /* DEBUG */
switch (obj->type)
pop_stack(st);
if (cleartomark_stack(st))
- _cupsRasterAddError("cleartomark: Stack underflow!\n");
+ _cupsRasterAddError("cleartomark: Stack underflow.\n");
#ifdef DEBUG
- DEBUG_puts(" dup: ");
- DEBUG_stack(st);
+ DEBUG_puts("1_cupsRasterExecPS: dup");
+ DEBUG_stack("_cupsRasterExecPS", st);
#endif /* DEBUG */
break;
#ifdef DEBUG
DEBUG_puts("_cupsRasterExecPS: copy");
- DEBUG_stack(st);
+ DEBUG_stack("_cupsRasterExecPS", st);
#endif /* DEBUG */
}
break;
#ifdef DEBUG
DEBUG_puts("_cupsRasterExecPS: dup");
- DEBUG_stack(st);
+ DEBUG_stack("_cupsRasterExecPS", st);
#endif /* DEBUG */
break;
#ifdef DEBUG
DEBUG_puts("_cupsRasterExecPS: index");
- DEBUG_stack(st);
+ DEBUG_stack("_cupsRasterExecPS", st);
#endif /* DEBUG */
}
break;
#ifdef DEBUG
DEBUG_puts("_cupsRasterExecPS: pop");
- DEBUG_stack(st);
+ DEBUG_stack("_cupsRasterExecPS", st);
#endif /* DEBUG */
break;
#ifdef DEBUG
DEBUG_puts("_cupsRasterExecPS: roll");
- DEBUG_stack(st);
+ DEBUG_stack("_cupsRasterExecPS", st);
#endif /* DEBUG */
}
}
#ifdef DEBUG
DEBUG_puts("_cupsRasterExecPS: setpagedevice");
- DEBUG_stack(st);
+ DEBUG_stack("_cupsRasterExecPS", st);
#endif /* DEBUG */
break;
break;
case CUPS_PS_OTHER :
- _cupsRasterAddError("Unknown operator \"%s\"!\n", obj->value.other);
+ _cupsRasterAddError("Unknown operator \"%s\".\n", obj->value.other);
error = 1;
- DEBUG_printf(("_cupsRasterExecPS: Unknown operator \"%s\"!\n",
- obj->value.other));
+ DEBUG_printf(("_cupsRasterExecPS: Unknown operator \"%s\".", obj->value.other));
break;
}
error_stack(st, "Stack not empty:");
#ifdef DEBUG
- DEBUG_puts("_cupsRasterExecPS: Stack not empty:");
- DEBUG_stack(st);
+ DEBUG_puts("_cupsRasterExecPS: Stack not empty");
+ DEBUG_stack("_cupsRasterExecPS", st);
#endif /* DEBUG */
delete_stack(st);
int n; /* Index into array */
- DEBUG_printf((" roll_stack(st=%p, s=%d, c=%d)\n", st, s, c));
+ DEBUG_printf(("3roll_stack(st=%p, s=%d, c=%d)", st, s, c));
/*
* Range check input...
* Now pull /name and value pairs from the dictionary...
*/
- DEBUG_puts("setpagedevice: Dictionary:");
+ DEBUG_puts("3setpagedevice: Dictionary:");
for (obj ++; obj < end; obj ++)
{
obj ++;
#ifdef DEBUG
- DEBUG_printf(("setpagedevice: /%s ", name));
- DEBUG_object(obj);
+ DEBUG_printf(("4setpagedevice: /%s ", name));
+ DEBUG_object("setpagedevice", obj);
#endif /* DEBUG */
/*
* Ignore unknown name+value...
*/
- DEBUG_printf((" Unknown name (\"%s\") or value...\n", name));
+ DEBUG_printf(("4setpagedevice: Unknown name (\"%s\") or value...\n", name));
while (obj[1].type != CUPS_PS_NAME && obj < end)
obj ++;
*/
static void
-DEBUG_object(_cups_ps_obj_t *obj) /* I - Object to print */
+DEBUG_object(const char *prefix, /* I - Prefix string */
+ _cups_ps_obj_t *obj) /* I - Object to print */
{
switch (obj->type)
{
case CUPS_PS_NAME :
- DEBUG_printf(("/%s\n", obj->value.name));
+ DEBUG_printf(("4%s: /%s\n", prefix, obj->value.name));
break;
case CUPS_PS_NUMBER :
- DEBUG_printf(("%g\n", obj->value.number));
+ DEBUG_printf(("4%s: %g\n", prefix, obj->value.number));
break;
case CUPS_PS_STRING :
- DEBUG_printf(("(%s)\n", obj->value.string));
+ DEBUG_printf(("4%s: (%s)\n", prefix, obj->value.string));
break;
case CUPS_PS_BOOLEAN :
if (obj->value.boolean)
- DEBUG_puts("true");
+ DEBUG_printf(("4%s: true", prefix));
else
- DEBUG_puts("false");
+ DEBUG_printf(("4%s: false", prefix));
break;
case CUPS_PS_NULL :
- DEBUG_puts("null");
+ DEBUG_printf(("4%s: null", prefix));
break;
case CUPS_PS_START_ARRAY :
- DEBUG_puts("[");
+ DEBUG_printf(("4%s: [", prefix));
break;
case CUPS_PS_END_ARRAY :
- DEBUG_puts("]");
+ DEBUG_printf(("4%s: ]", prefix));
break;
case CUPS_PS_START_DICT :
- DEBUG_puts("<<");
+ DEBUG_printf(("4%s: <<", prefix));
break;
case CUPS_PS_END_DICT :
- DEBUG_puts(">>");
+ DEBUG_printf(("4%s: >>", prefix));
break;
case CUPS_PS_START_PROC :
- DEBUG_puts("{");
+ DEBUG_printf(("4%s: {", prefix));
break;
case CUPS_PS_END_PROC :
- DEBUG_puts("}");
+ DEBUG_printf(("4%s: }", prefix));
break;
case CUPS_PS_CLEARTOMARK :
- DEBUG_puts("--cleartomark--");
+ DEBUG_printf(("4%s: --cleartomark--", prefix));
break;
case CUPS_PS_COPY :
- DEBUG_puts("--copy--");
+ DEBUG_printf(("4%s: --copy--", prefix));
break;
case CUPS_PS_DUP :
- DEBUG_puts("--dup--");
+ DEBUG_printf(("4%s: --dup--", prefix));
break;
case CUPS_PS_INDEX :
- DEBUG_puts("--index--");
+ DEBUG_printf(("4%s: --index--", prefix));
break;
case CUPS_PS_POP :
- DEBUG_puts("--pop--");
+ DEBUG_printf(("4%s: --pop--", prefix));
break;
case CUPS_PS_ROLL :
- DEBUG_puts("--roll--");
+ DEBUG_printf(("4%s: --roll--", prefix));
break;
case CUPS_PS_SETPAGEDEVICE :
- DEBUG_puts("--setpagedevice--");
+ DEBUG_printf(("4%s: --setpagedevice--", prefix));
break;
case CUPS_PS_STOPPED :
- DEBUG_puts("--stopped--");
+ DEBUG_printf(("4%s: --stopped--", prefix));
break;
case CUPS_PS_OTHER :
- DEBUG_printf(("--%s--\n", obj->value.other));
+ DEBUG_printf(("4%s: --%s--", prefix, obj->value.other));
break;
}
}
*/
static void
-DEBUG_stack(_cups_ps_stack_t *st) /* I - Stack */
+DEBUG_stack(const char *prefix, /* I - Prefix string */
+ _cups_ps_stack_t *st) /* I - Stack */
{
int c; /* Looping var */
_cups_ps_obj_t *obj; /* Current object on stack */
for (obj = st->objs, c = st->num_objs; c > 0; c --, obj ++)
- DEBUG_object(obj);
+ DEBUG_object(prefix, obj);
}
#endif /* DEBUG */
*bufptr, /* Current (read) position in buffer */
*bufend; /* End of current (read) buffer */
size_t bufsize; /* Buffer size */
+#ifdef DEBUG
+ size_t iocount; /* Number of bytes read/written */
+#endif /* DEBUG */
};
r->sync == CUPS_RASTER_REVSYNCv2)
r->swapped = 1;
- DEBUG_printf(("r->swapped=%d, r->sync=%08x\n", r->swapped, r->sync));
+ DEBUG_printf(("1cupsRasterOpenIO: r->swapped=%d, r->sync=%08x\n", r->swapped, r->sync));
}
else
{
if (r == NULL || r->mode != CUPS_RASTER_READ)
return (0);
+ DEBUG_printf(("4cups_raster_read_header: r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount));
+
/*
* Get the length of the raster header...
*/
if (cups_raster_read(r, (unsigned char *)&(r->header), len) < (ssize_t)len)
{
- DEBUG_puts("4cups_raster_read_header: EOF");
+ DEBUG_printf(("4cups_raster_read_header: EOF, r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount));
return (0);
}
return (0);
else if (count < 0)
return (-1);
+
+#ifdef DEBUG
+ r->iocount += (size_t)count;
+#endif /* DEBUG */
}
return (total);
*/
count = (ssize_t)(2 * r->header.cupsBytesPerLine);
+ if (count < 65536)
+ count = 65536;
if ((size_t)count > r->bufsize)
{
r->bufptr = r->buffer;
r->bufend = r->buffer + remaining;
+
+#ifdef DEBUG
+ r->iocount += (size_t)remaining;
+#endif /* DEBUG */
}
else
{
if (count <= 0)
return (0);
+#ifdef DEBUG
+ r->iocount += (size_t)count;
+#endif /* DEBUG */
+
continue;
}
}
while ((count = read(fd, buf, bytes)) < 0)
#endif /* WIN32 */
if (errno != EINTR && errno != EAGAIN)
+ {
+ DEBUG_printf(("4cups_read_fd: %s", strerror(errno)));
return (-1);
+ }
+
+ DEBUG_printf(("4cups_read_fd: Returning %d bytes.", (int)count));
return (count);
}