| 502 | */ |
| 503 | |
| 504 | int /* O - 0 on success, -1 on error */ |
| 505 | _cupsRasterExecPS( |
| 506 | cups_page_header2_t *h, /* O - Page header */ |
| 507 | int *preferred_bits,/* O - Preferred bits per color */ |
| 508 | const char *code) /* I - PS code to execute */ |
| 509 | { |
| 510 | int error = 0; /* Error condition? */ |
| 511 | _cups_ps_stack_t *st; /* PostScript value stack */ |
| 512 | _cups_ps_obj_t *obj; /* Object from top of stack */ |
| 513 | char *codecopy, /* Copy of code */ |
| 514 | *codeptr; /* Pointer into copy of code */ |
| 515 | |
| 516 | |
| 517 | DEBUG_printf(("_cupsRasterExecPS(h=%p, preferred_bits=%p, code=\"%s\")\n", |
| 518 | h, preferred_bits, code)); |
| 519 | |
| 520 | /* |
| 521 | * Copy the PostScript code and create a stack... |
| 522 | */ |
| 523 | |
| 524 | if ((codecopy = strdup(code)) == NULL) |
| 525 | { |
| 526 | _cupsRasterAddError("Unable to duplicate code string.\n"); |
| 527 | return (-1); |
| 528 | } |
| 529 | |
| 530 | if ((st = new_stack()) == NULL) |
| 531 | { |
| 532 | _cupsRasterAddError("Unable to create stack.\n"); |
| 533 | free(codecopy); |
| 534 | return (-1); |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * Parse the PS string until we run out of data... |
| 539 | */ |
| 540 | |
| 541 | codeptr = codecopy; |
| 542 | |
| 543 | while ((obj = scan_ps(st, &codeptr)) != NULL) |
| 544 | { |
| 545 | #ifdef DEBUG |
| 546 | DEBUG_printf(("_cupsRasterExecPS: Stack (%d objects)", st->num_objs)); |
| 547 | DEBUG_object("_cupsRasterExecPS", obj); |
| 548 | #endif /* DEBUG */ |
| 549 | |
| 550 | switch (obj->type) |
| 551 | { |
| 552 | default : |
| 553 | /* Do nothing for regular values */ |
| 554 | break; |
| 555 | |
| 556 | case CUPS_PS_CLEARTOMARK : |
| 557 | pop_stack(st); |
| 558 | |
| 559 | if (cleartomark_stack(st)) |
| 560 | _cupsRasterAddError("cleartomark: Stack underflow.\n"); |
| 561 | |