]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/emit.c
f3b32e666b0e3d9ddc60cd9d78701c7f9e1fc16b
2 * "$Id: emit.c 7863 2008-08-26 03:39:59Z mike $"
4 * PPD code emission routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * PostScript is a trademark of Adobe Systems, Inc.
17 * This file is subject to the Apple OS-Developed Software exception.
21 * ppdCollect() - Collect all marked options that reside in the
23 * ppdCollect2() - Collect all marked options that reside in the
24 * specified section and minimum order.
25 * ppdEmit() - Emit code for marked options to a file.
26 * ppdEmitAfterOrder() - Emit a subset of the code for marked options to a
28 * ppdEmitFd() - Emit code for marked options to a file.
29 * ppdEmitJCL() - Emit code for JCL options to a file.
30 * ppdEmitJCLEnd() - Emit JCLEnd code to a file.
31 * ppdEmitString() - Get a string containing the code for marked
33 * ppd_compare_cparams() - Compare the order of two custom parameters.
34 * ppd_handle_media() - Handle media selection...
38 * Include necessary headers...
47 #if defined(WIN32) || defined(__EMX__)
51 #endif /* WIN32 || __EMX__ */
58 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
59 static void ppd_handle_media(ppd_file_t
*ppd
);
66 static const char ppd_custom_code
[] =
68 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
72 * 'ppdCollect()' - Collect all marked options that reside in the specified
75 * The choices array should be freed using @code free@ when you are
79 int /* O - Number of options marked */
80 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
81 ppd_section_t section
, /* I - Section to collect */
82 ppd_choice_t
***choices
) /* O - Pointers to choices */
84 return (ppdCollect2(ppd
, section
, 0.0, choices
));
89 * 'ppdCollect2()' - Collect all marked options that reside in the
90 * specified section and minimum order.
92 * The choices array should be freed using @code free@ when you are
98 int /* O - Number of options marked */
99 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
100 ppd_section_t section
, /* I - Section to collect */
101 float min_order
, /* I - Minimum OrderDependency value */
102 ppd_choice_t
***choices
) /* O - Pointers to choices */
104 ppd_choice_t
*c
; /* Current choice */
105 ppd_section_t csection
; /* Current section */
106 float corder
; /* Current OrderDependency value */
107 int count
; /* Number of choices collected */
108 ppd_choice_t
**collect
; /* Collected choices */
109 float *orders
; /* Collected order values */
112 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)\n",
113 ppd
, section
, min_order
, choices
));
115 if (!ppd
|| !choices
)
124 * Allocate memory for up to N selected choices...
128 if ((collect
= calloc(sizeof(ppd_choice_t
*),
129 cupsArrayCount(ppd
->marked
))) == NULL
)
135 if ((orders
= calloc(sizeof(float), cupsArrayCount(ppd
->marked
))) == NULL
)
143 * Loop through all options and add choices as needed...
146 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
148 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
150 csection
= c
->option
->section
;
151 corder
= c
->option
->order
;
153 if (!strcmp(c
->choice
, "Custom"))
155 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
156 float aorder
; /* Order value */
157 char asection
[17], /* Section name */
158 amain
[PPD_MAX_NAME
+ 1],
159 aoption
[PPD_MAX_NAME
];
160 /* *CustomFoo and True */
163 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
165 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
167 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
169 !strncmp(amain
, "*Custom", 7) &&
170 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
173 * Use this NonUIOrderDependency...
178 if (!strcmp(asection
, "DocumentSetup"))
179 csection
= PPD_ORDER_DOCUMENT
;
180 else if (!strcmp(asection
, "ExitServer"))
181 csection
= PPD_ORDER_EXIT
;
182 else if (!strcmp(asection
, "JCLSetup"))
183 csection
= PPD_ORDER_JCL
;
184 else if (!strcmp(asection
, "PageSetup"))
185 csection
= PPD_ORDER_PAGE
;
186 else if (!strcmp(asection
, "Prolog"))
187 csection
= PPD_ORDER_PROLOG
;
189 csection
= PPD_ORDER_ANY
;
195 if (csection
== section
&& corder
>= min_order
)
198 orders
[count
] = corder
;
204 * If we have more than 1 marked choice, sort them...
209 int i
, j
; /* Looping vars */
211 for (i
= 0; i
< (count
- 1); i
++)
212 for (j
= i
+ 1; j
< count
; j
++)
213 if (orders
[i
] > orders
[j
])
217 collect
[i
] = collect
[j
];
218 orders
[i
] = orders
[j
];
226 DEBUG_printf(("ppdCollect2: %d marked choices...\n", count
));
229 * Return the array and number of choices; if 0, free the array since
248 * 'ppdEmit()' - Emit code for marked options to a file.
251 int /* O - 0 on success, -1 on failure */
252 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
253 FILE *fp
, /* I - File to write to */
254 ppd_section_t section
) /* I - Section to write */
256 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
261 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
263 * When "limit" is non-zero, this function only emits options whose
264 * OrderDependency value is greater than or equal to "min_order".
266 * When "limit" is zero, this function is identical to ppdEmit().
271 int /* O - 0 on success, -1 on failure */
273 ppd_file_t
*ppd
, /* I - PPD file record */
274 FILE *fp
, /* I - File to write to */
275 ppd_section_t section
, /* I - Section to write */
276 int limit
, /* I - Non-zero to use min_order */
277 float min_order
) /* I - Lowest OrderDependency */
279 char *buffer
; /* Option code */
280 int status
; /* Return status */
284 * Range check input...
294 buffer
= ppdEmitString(ppd
, section
, min_order
);
297 * Write it as needed and return...
302 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
314 * 'ppdEmitFd()' - Emit code for marked options to a file.
317 int /* O - 0 on success, -1 on failure */
318 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
319 int fd
, /* I - File to write to */
320 ppd_section_t section
) /* I - Section to write */
322 char *buffer
, /* Option code */
323 *bufptr
; /* Pointer into code */
324 size_t buflength
; /* Length of option code */
325 ssize_t bytes
; /* Bytes written */
326 int status
; /* Return status */
330 * Range check input...
340 buffer
= ppdEmitString(ppd
, section
, 0.0);
343 * Write it as needed and return...
348 buflength
= strlen(buffer
);
352 while (buflength
> 0)
355 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
357 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
360 if (errno
== EAGAIN
|| errno
== EINTR
)
370 status
= bytes
< 0 ? -1 : 0;
382 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
385 int /* O - 0 on success, -1 on failure */
386 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
387 FILE *fp
, /* I - File to write to */
388 int job_id
, /* I - Job ID */
389 const char *user
, /* I - Username */
390 const char *title
) /* I - Title */
392 char *ptr
; /* Pointer into JCL string */
393 char temp
[81]; /* Local title string */
397 * Range check the input...
400 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
404 * See if the printer supports HP PJL...
407 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
410 * This printer uses HP PJL commands for output; filter the output
411 * so that we only have a single "@PJL JOB" command in the header...
413 * To avoid bugs in the PJL implementation of certain vendors' products
414 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
415 * of the PJL commands to initialize PJL processing.
418 ppd_attr_t
*charset
; /* PJL charset */
419 ppd_attr_t
*display
; /* PJL display command */
422 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
424 if (!charset
->value
|| strcasecmp(charset
->value
, "UTF-8"))
428 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
434 fputs("\033%-12345X@PJL\n", fp
);
435 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
436 if (!strncmp(ptr
, "@PJL JOB", 8))
439 * Skip job command...
467 * Eliminate any path info from the job title...
470 if ((ptr
= strrchr(title
, '/')) != NULL
)
474 * Replace double quotes with single quotes and 8-bit characters with
475 * question marks so that the title does not cause a PJL syntax error.
478 strlcpy(temp
, title
, sizeof(temp
));
480 for (ptr
= temp
; *ptr
; ptr
++)
483 else if (charset
&& (*ptr
& 128))
487 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
490 if (display
&& strcmp(display
->value
, "job"))
492 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
494 if (display
&& !strcmp(display
->value
, "rdymsg"))
495 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%d %s %s\"\n", job_id
, user
, temp
);
498 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%d %s %s\"\n", temp
,
502 fputs(ppd
->jcl_begin
, fp
);
504 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
505 fputs(ppd
->jcl_ps
, fp
);
512 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
517 int /* O - 0 on success, -1 on failure */
518 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
519 FILE *fp
) /* I - File to write to */
522 * Range check the input...
530 if (ppd
->num_filters
== 0)
537 * See if the printer supports HP PJL...
540 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
543 * This printer uses HP PJL commands for output; filter the output
544 * so that we only have a single "@PJL JOB" command in the header...
546 * To avoid bugs in the PJL implementation of certain vendors' products
547 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
548 * of the PJL commands to initialize PJL processing.
551 fputs("\033%-12345X@PJL\n", fp
);
552 fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp
);
553 fputs(ppd
->jcl_end
+ 9, fp
);
556 fputs(ppd
->jcl_end
, fp
);
563 * 'ppdEmitString()' - Get a string containing the code for marked options.
565 * When "min_order" is greater than zero, this function only includes options
566 * whose OrderDependency value is greater than or equal to "min_order".
567 * Otherwise, all options in the specified section are included in the
570 * The return string is allocated on the heap and should be freed using
571 * @code free@ when you are done with it.
576 char * /* O - String containing option code or @code NULL@ if there is no option code */
577 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
578 ppd_section_t section
, /* I - Section to write */
579 float min_order
) /* I - Lowest OrderDependency */
581 int i
, j
, /* Looping vars */
582 count
; /* Number of choices */
583 ppd_choice_t
**choices
; /* Choices */
584 ppd_size_t
*size
; /* Custom page size */
585 ppd_coption_t
*coption
; /* Custom option */
586 ppd_cparam_t
*cparam
; /* Custom parameter */
587 size_t bufsize
; /* Size of string buffer needed */
588 char *buffer
, /* String buffer */
589 *bufptr
, /* Pointer into buffer */
590 *bufend
; /* End of buffer */
591 struct lconv
*loc
; /* Locale data */
594 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)\n",
595 ppd
, section
, min_order
));
598 * Range check input...
605 * Use PageSize or PageRegion as required...
608 ppd_handle_media(ppd
);
611 * Collect the options we need to emit...
614 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
618 * Count the number of bytes that are required to hold all of the
622 for (i
= 0, bufsize
= 1; i
< count
; i
++)
624 if (section
== PPD_ORDER_JCL
)
626 if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
627 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
631 * Add space to account for custom parameter substitution...
634 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
636 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
638 switch (cparam
->type
)
640 case PPD_CUSTOM_CURVE
:
641 case PPD_CUSTOM_INVCURVE
:
642 case PPD_CUSTOM_POINTS
:
643 case PPD_CUSTOM_REAL
:
644 case PPD_CUSTOM_INT
:
648 case PPD_CUSTOM_PASSCODE
:
649 case PPD_CUSTOM_PASSWORD
:
650 case PPD_CUSTOM_STRING
:
651 bufsize
+= strlen(cparam
->current
.custom_string
);
657 else if (section
!= PPD_ORDER_EXIT
)
659 bufsize
+= 3; /* [{\n */
661 if ((!strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
662 !strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
663 !strcasecmp(choices
[i
]->choice
, "Custom"))
665 DEBUG_puts("ppdEmitString: Custom size set!");
667 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
668 bufsize
+= 50; /* Five 9-digit numbers + newline */
670 else if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
671 (coption
= ppdFindCustomOption(ppd
,
672 choices
[i
]->option
->keyword
))
675 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 6;
676 /* %%BeginFeature: *keyword True\n */
679 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
681 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
683 switch (cparam
->type
)
685 case PPD_CUSTOM_CURVE
:
686 case PPD_CUSTOM_INVCURVE
:
687 case PPD_CUSTOM_POINTS
:
688 case PPD_CUSTOM_REAL
:
689 case PPD_CUSTOM_INT
:
693 case PPD_CUSTOM_PASSCODE
:
694 case PPD_CUSTOM_PASSWORD
:
695 case PPD_CUSTOM_STRING
:
696 bufsize
+= 3 + 4 * strlen(cparam
->current
.custom_string
);
702 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
703 strlen(choices
[i
]->choice
) + 1;
704 /* %%BeginFeature: *keyword choice\n */
706 bufsize
+= 13; /* %%EndFeature\n */
707 bufsize
+= 22; /* } stopped cleartomark\n */
710 if (choices
[i
]->code
)
711 bufsize
+= strlen(choices
[i
]->code
) + 1;
713 bufsize
+= strlen(ppd_custom_code
);
720 DEBUG_printf(("ppdEmitString: Allocating %d bytes for string...\n",
723 if ((buffer
= calloc(1, bufsize
)) == NULL
)
729 bufend
= buffer
+ bufsize
- 1;
733 * Copy the option code to the buffer...
736 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
737 if (section
== PPD_ORDER_JCL
)
739 if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
740 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
744 * Handle substitutions in custom JCL options...
747 char *cptr
; /* Pointer into code */
748 int pnum
; /* Parameter number */
751 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
757 if (isdigit(*cptr
& 255))
760 * Substitute parameter...
763 pnum
= *cptr
++ - '0';
764 while (isalnum(*cptr
& 255))
765 pnum
= pnum
* 10 + *cptr
- '0';
767 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
769 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
770 if (cparam
->order
== pnum
)
775 switch (cparam
->type
)
777 case PPD_CUSTOM_CURVE
:
778 case PPD_CUSTOM_INVCURVE
:
779 case PPD_CUSTOM_POINTS
:
780 case PPD_CUSTOM_REAL
:
781 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
782 cparam
->current
.custom_real
,
786 case PPD_CUSTOM_INT
:
787 snprintf(bufptr
, bufend
- bufptr
, "%d",
788 cparam
->current
.custom_int
);
789 bufptr
+= strlen(bufptr
);
792 case PPD_CUSTOM_PASSCODE
:
793 case PPD_CUSTOM_PASSWORD
:
794 case PPD_CUSTOM_STRING
:
795 strlcpy(bufptr
, cparam
->current
.custom_string
,
797 bufptr
+= strlen(bufptr
);
812 * Otherwise just copy the option code directly...
815 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
816 bufptr
+= strlen(bufptr
);
819 else if (section
!= PPD_ORDER_EXIT
)
822 * Add wrapper commands to prevent printer errors for unsupported
826 strlcpy(bufptr
, "[{\n", bufend
- bufptr
+ 1);
830 * Send DSC comments with option...
833 DEBUG_printf(("Adding code for %s=%s...\n", choices
[i
]->option
->keyword
,
834 choices
[i
]->choice
));
836 if ((!strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
837 !strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
838 !strcasecmp(choices
[i
]->choice
, "Custom"))
841 * Variable size; write out standard size options, using the
842 * parameter positions defined in the PPD file...
845 ppd_attr_t
*attr
; /* PPD attribute */
846 int pos
, /* Position of custom value */
847 orientation
; /* Orientation to use */
848 float values
[5]; /* Values for custom command */
851 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n",
852 bufend
- bufptr
+ 1);
855 size
= ppdPageSize(ppd
, "Custom");
857 memset(values
, 0, sizeof(values
));
859 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
861 pos
= atoi(attr
->value
) - 1;
863 if (pos
< 0 || pos
> 4)
869 values
[pos
] = size
->width
;
871 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
873 pos
= atoi(attr
->value
) - 1;
875 if (pos
< 0 || pos
> 4)
881 values
[pos
] = size
->length
;
884 * According to the Adobe PPD specification, an orientation of 1
885 * will produce a print that comes out upside-down with the X
886 * axis perpendicular to the direction of feed, which is exactly
887 * what we want to be consistent with non-PS printers.
889 * We could also use an orientation of 3 to produce output that
890 * comes out rightside-up (this is the default for many large format
891 * printer PPDs), however for consistency we will stick with the
894 * If we wanted to get fancy, we could use orientations of 0 or
895 * 2 and swap the width and length, however we don't want to get
896 * fancy, we just want it to work consistently.
898 * The orientation value is range limited by the Orientation
899 * parameter definition, so certain non-PS printer drivers that
900 * only support an Orientation of 0 will get the value 0 as
906 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
907 "Orientation")) != NULL
)
909 int min_orient
, max_orient
; /* Minimum and maximum orientations */
912 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
919 if (pos
< 0 || pos
> 4)
922 if (orientation
> max_orient
)
923 orientation
= max_orient
;
924 else if (orientation
< min_orient
)
925 orientation
= min_orient
;
931 values
[pos
] = (float)orientation
;
933 for (pos
= 0; pos
< 5; pos
++)
935 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
939 if (!choices
[i
]->code
)
942 * This can happen with certain buggy PPD files that don't include
943 * a CustomPageSize command sequence... We just use a generic
944 * Level 2 command sequence...
947 strlcpy(bufptr
, ppd_custom_code
, bufend
- bufptr
+ 1);
948 bufptr
+= strlen(bufptr
);
951 else if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
952 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
959 const char *s
; /* Pointer into string value */
960 cups_array_t
*params
; /* Parameters in the correct output order */
963 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
965 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
967 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
968 cupsArrayAdd(params
, cparam
);
970 snprintf(bufptr
, bufend
- bufptr
+ 1,
971 "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
972 bufptr
+= strlen(bufptr
);
974 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
976 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
978 switch (cparam
->type
)
980 case PPD_CUSTOM_CURVE
:
981 case PPD_CUSTOM_INVCURVE
:
982 case PPD_CUSTOM_POINTS
:
983 case PPD_CUSTOM_REAL
:
984 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
985 cparam
->current
.custom_real
, loc
);
989 case PPD_CUSTOM_INT
:
990 snprintf(bufptr
, bufend
- bufptr
+ 1, "%d\n",
991 cparam
->current
.custom_int
);
992 bufptr
+= strlen(bufptr
);
995 case PPD_CUSTOM_PASSCODE
:
996 case PPD_CUSTOM_PASSWORD
:
997 case PPD_CUSTOM_STRING
:
1000 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1001 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1003 snprintf(bufptr
, bufend
- bufptr
+ 1, "\\%03o", *s
& 255);
1004 bufptr
+= strlen(bufptr
);
1015 cupsArrayDelete(params
);
1019 snprintf(bufptr
, bufend
- bufptr
+ 1, "%%%%BeginFeature: *%s %s\n",
1020 choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1021 bufptr
+= strlen(bufptr
);
1024 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1026 j
= (int)strlen(choices
[i
]->code
);
1027 memcpy(bufptr
, choices
[i
]->code
, j
);
1030 if (choices
[i
]->code
[j
- 1] != '\n')
1034 strlcpy(bufptr
, "%%EndFeature\n"
1035 "} stopped cleartomark\n", bufend
- bufptr
+ 1);
1036 bufptr
+= strlen(bufptr
);
1038 DEBUG_printf(("ppdEmitString: Offset in string is %d...\n",
1039 (int)(bufptr
- buffer
)));
1043 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
1044 bufptr
+= strlen(bufptr
);
1048 * Nul-terminate, free, and return...
1060 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1063 static int /* O - Result of comparison */
1064 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1065 ppd_cparam_t
*b
) /* I - Second parameter */
1067 return (a
->order
- b
->order
);
1072 * 'ppd_handle_media()' - Handle media selection...
1076 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1078 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1079 *input_slot
, /* InputSlot choice, if any */
1080 *page
; /* PageSize/PageRegion */
1081 ppd_size_t
*size
; /* Current media size */
1082 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1086 * This function determines if the user has selected a media source
1087 * via the InputSlot or ManualFeed options; if so, it marks the
1088 * PageRegion option corresponding to the current media size.
1089 * Otherwise it marks the PageSize option.
1092 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1095 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1096 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1098 if (input_slot
!= NULL
)
1099 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1104 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1106 if (!strcasecmp(size
->name
, "Custom") || (!manual_feed
&& !input_slot
) ||
1107 !((manual_feed
&& !strcasecmp(manual_feed
->choice
, "True")) ||
1108 (input_slot
&& input_slot
->code
&& input_slot
->code
[0])))
1111 * Manual feed was not selected and/or the input slot selection does
1112 * not contain any PostScript code. Use the PageSize option...
1115 ppdMarkOption(ppd
, "PageSize", size
->name
);
1120 * Manual feed was selected and/or the input slot selection contains
1121 * PostScript code. Use the PageRegion option...
1124 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1127 * RequiresPageRegion does not apply to manual feed so we need to
1128 * check that we are not doing manual feed before unmarking PageRegion.
1131 if (!(manual_feed
&& !strcasecmp(manual_feed
->choice
, "True")) &&
1132 ((rpr
&& rpr
->value
&& !strcmp(rpr
->value
, "False")) ||
1133 (!rpr
&& !ppd
->num_filters
)))
1136 * Either the PPD file specifies no PageRegion code or the PPD file
1137 * not for a CUPS raster driver and thus defaults to no PageRegion
1138 * code... Unmark the PageRegion choice so that we don't output the
1142 page
= ppdFindMarkedChoice(ppd
, "PageRegion");
1152 * End of "$Id: emit.c 7863 2008-08-26 03:39:59Z mike $".