]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/ppd-emit.c
2 * PPD code emission routines for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
10 * PostScript is a trademark of Adobe Systems, Inc.
14 * Include necessary headers...
17 #include "cups-private.h"
19 #if defined(WIN32) || defined(__EMX__)
23 #endif /* WIN32 || __EMX__ */
30 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
31 static void ppd_handle_media(ppd_file_t
*ppd
);
38 static const char ppd_custom_code
[] =
40 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
44 * 'ppdCollect()' - Collect all marked options that reside in the specified
47 * The choices array should be freed using @code free@ when you are
51 int /* O - Number of options marked */
52 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
53 ppd_section_t section
, /* I - Section to collect */
54 ppd_choice_t
***choices
) /* O - Pointers to choices */
56 return (ppdCollect2(ppd
, section
, 0.0, choices
));
61 * 'ppdCollect2()' - Collect all marked options that reside in the
62 * specified section and minimum order.
64 * The choices array should be freed using @code free@ when you are
67 * @since CUPS 1.2/macOS 10.5@
70 int /* O - Number of options marked */
71 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
72 ppd_section_t section
, /* I - Section to collect */
73 float min_order
, /* I - Minimum OrderDependency value */
74 ppd_choice_t
***choices
) /* O - Pointers to choices */
76 ppd_choice_t
*c
; /* Current choice */
77 ppd_section_t csection
; /* Current section */
78 float corder
; /* Current OrderDependency value */
79 int count
; /* Number of choices collected */
80 ppd_choice_t
**collect
; /* Collected choices */
81 float *orders
; /* Collected order values */
84 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)",
85 ppd
, section
, min_order
, choices
));
96 * Allocate memory for up to N selected choices...
100 if ((collect
= calloc(sizeof(ppd_choice_t
*),
101 (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
107 if ((orders
= calloc(sizeof(float), (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
115 * Loop through all options and add choices as needed...
118 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
120 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
122 csection
= c
->option
->section
;
123 corder
= c
->option
->order
;
125 if (!strcmp(c
->choice
, "Custom"))
127 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
128 float aorder
; /* Order value */
129 char asection
[17], /* Section name */
130 amain
[PPD_MAX_NAME
+ 1],
131 aoption
[PPD_MAX_NAME
];
132 /* *CustomFoo and True */
135 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
137 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
139 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
141 !strncmp(amain
, "*Custom", 7) &&
142 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
145 * Use this NonUIOrderDependency...
150 if (!strcmp(asection
, "DocumentSetup"))
151 csection
= PPD_ORDER_DOCUMENT
;
152 else if (!strcmp(asection
, "ExitServer"))
153 csection
= PPD_ORDER_EXIT
;
154 else if (!strcmp(asection
, "JCLSetup"))
155 csection
= PPD_ORDER_JCL
;
156 else if (!strcmp(asection
, "PageSetup"))
157 csection
= PPD_ORDER_PAGE
;
158 else if (!strcmp(asection
, "Prolog"))
159 csection
= PPD_ORDER_PROLOG
;
161 csection
= PPD_ORDER_ANY
;
167 if (csection
== section
&& corder
>= min_order
)
170 orders
[count
] = corder
;
176 * If we have more than 1 marked choice, sort them...
181 int i
, j
; /* Looping vars */
183 for (i
= 0; i
< (count
- 1); i
++)
184 for (j
= i
+ 1; j
< count
; j
++)
185 if (orders
[i
] > orders
[j
])
189 collect
[i
] = collect
[j
];
190 orders
[i
] = orders
[j
];
198 DEBUG_printf(("2ppdCollect2: %d marked choices...", count
));
201 * Return the array and number of choices; if 0, free the array since
220 * 'ppdEmit()' - Emit code for marked options to a file.
223 int /* O - 0 on success, -1 on failure */
224 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
225 FILE *fp
, /* I - File to write to */
226 ppd_section_t section
) /* I - Section to write */
228 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
233 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
235 * When "limit" is non-zero, this function only emits options whose
236 * OrderDependency value is greater than or equal to "min_order".
238 * When "limit" is zero, this function is identical to ppdEmit().
240 * @since CUPS 1.2/macOS 10.5@
243 int /* O - 0 on success, -1 on failure */
245 ppd_file_t
*ppd
, /* I - PPD file record */
246 FILE *fp
, /* I - File to write to */
247 ppd_section_t section
, /* I - Section to write */
248 int limit
, /* I - Non-zero to use min_order */
249 float min_order
) /* I - Lowest OrderDependency */
251 char *buffer
; /* Option code */
252 int status
; /* Return status */
256 * Range check input...
266 buffer
= ppdEmitString(ppd
, section
, limit
? min_order
: 0.0f
);
269 * Write it as needed and return...
274 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
286 * 'ppdEmitFd()' - Emit code for marked options to a file.
289 int /* O - 0 on success, -1 on failure */
290 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
291 int fd
, /* I - File to write to */
292 ppd_section_t section
) /* I - Section to write */
294 char *buffer
, /* Option code */
295 *bufptr
; /* Pointer into code */
296 size_t buflength
; /* Length of option code */
297 ssize_t bytes
; /* Bytes written */
298 int status
; /* Return status */
302 * Range check input...
312 buffer
= ppdEmitString(ppd
, section
, 0.0);
315 * Write it as needed and return...
320 buflength
= strlen(buffer
);
324 while (buflength
> 0)
327 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
329 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
332 if (errno
== EAGAIN
|| errno
== EINTR
)
338 buflength
-= (size_t)bytes
;
342 status
= bytes
< 0 ? -1 : 0;
354 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
357 int /* O - 0 on success, -1 on failure */
358 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
359 FILE *fp
, /* I - File to write to */
360 int job_id
, /* I - Job ID */
361 const char *user
, /* I - Username */
362 const char *title
) /* I - Title */
364 char *ptr
; /* Pointer into JCL string */
365 char temp
[65], /* Local title string */
366 displaymsg
[33]; /* Local display string */
370 * Range check the input...
373 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
377 * See if the printer supports HP PJL...
380 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
383 * This printer uses HP PJL commands for output; filter the output
384 * so that we only have a single "@PJL JOB" command in the header...
386 * To avoid bugs in the PJL implementation of certain vendors' products
387 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
388 * of the PJL commands to initialize PJL processing.
391 ppd_attr_t
*charset
; /* PJL charset */
392 ppd_attr_t
*display
; /* PJL display command */
395 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
397 if (!charset
->value
|| _cups_strcasecmp(charset
->value
, "UTF-8"))
401 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
407 fputs("\033%-12345X@PJL\n", fp
);
408 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
409 if (!strncmp(ptr
, "@PJL JOB", 8))
412 * Skip job command...
440 * Clean up the job title...
443 if ((ptr
= strrchr(title
, '/')) != NULL
)
446 * Only show basename of file path...
452 if (!strncmp(title
, "smbprn.", 7))
455 * Skip leading smbprn.######## from Samba jobs...
458 for (title
+= 7; *title
&& isdigit(*title
& 255); title
++);
459 while (_cups_isspace(*title
))
462 if ((ptr
= strstr(title
, " - ")) != NULL
)
465 * Skip application name in "Some Application - Title of job"...
473 * Replace double quotes with single quotes and UTF-8 characters with
474 * question marks so that the title does not cause a PJL syntax error.
477 strlcpy(temp
, title
, sizeof(temp
));
479 for (ptr
= temp
; *ptr
; ptr
++)
482 else if (!charset
&& (*ptr
& 128))
486 * CUPS STR #3125: Long PJL JOB NAME causes problems with some printers
488 * Generate the display message, truncating at 32 characters + nul to avoid
489 * issues with some printer's PJL implementations...
492 snprintf(displaymsg
, sizeof(displaymsg
), "%d %s %s", job_id
, user
, temp
);
495 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
498 if (display
&& strcmp(display
->value
, "job"))
499 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
500 else if (display
&& !strcmp(display
->value
, "rdymsg"))
501 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg
);
503 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp
,
507 * Replace double quotes with single quotes and UTF-8 characters with
508 * question marks so that the user does not cause a PJL syntax error.
511 strlcpy(temp
, user
, sizeof(temp
));
513 for (ptr
= temp
; *ptr
; ptr
++)
516 else if (!charset
&& (*ptr
& 128))
519 fprintf(fp
, "@PJL SET USERNAME = \"%s\"\n", temp
);
522 fputs(ppd
->jcl_begin
, fp
);
524 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
525 fputs(ppd
->jcl_ps
, fp
);
532 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
534 * @since CUPS 1.2/macOS 10.5@
537 int /* O - 0 on success, -1 on failure */
538 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
539 FILE *fp
) /* I - File to write to */
542 * Range check the input...
550 if (ppd
->num_filters
== 0)
557 * See if the printer supports HP PJL...
560 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
563 * This printer uses HP PJL commands for output; filter the output
564 * so that we only have a single "@PJL JOB" command in the header...
566 * To avoid bugs in the PJL implementation of certain vendors' products
567 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
568 * of the PJL commands to initialize PJL processing.
571 fputs("\033%-12345X@PJL\n", fp
);
572 fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp
);
573 fputs(ppd
->jcl_end
+ 9, fp
);
576 fputs(ppd
->jcl_end
, fp
);
583 * 'ppdEmitString()' - Get a string containing the code for marked options.
585 * When "min_order" is greater than zero, this function only includes options
586 * whose OrderDependency value is greater than or equal to "min_order".
587 * Otherwise, all options in the specified section are included in the
590 * The return string is allocated on the heap and should be freed using
591 * @code free@ when you are done with it.
593 * @since CUPS 1.2/macOS 10.5@
596 char * /* O - String containing option code or @code NULL@ if there is no option code */
597 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
598 ppd_section_t section
, /* I - Section to write */
599 float min_order
) /* I - Lowest OrderDependency */
601 int i
, j
, /* Looping vars */
602 count
; /* Number of choices */
603 ppd_choice_t
**choices
; /* Choices */
604 ppd_size_t
*size
; /* Custom page size */
605 ppd_coption_t
*coption
; /* Custom option */
606 ppd_cparam_t
*cparam
; /* Custom parameter */
607 size_t bufsize
; /* Size of string buffer needed */
608 char *buffer
, /* String buffer */
609 *bufptr
, /* Pointer into buffer */
610 *bufend
; /* End of buffer */
611 struct lconv
*loc
; /* Locale data */
614 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)",
615 ppd
, section
, min_order
));
618 * Range check input...
625 * Use PageSize or PageRegion as required...
628 ppd_handle_media(ppd
);
631 * Collect the options we need to emit...
634 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
638 * Count the number of bytes that are required to hold all of the
642 for (i
= 0, bufsize
= 1; i
< count
; i
++)
644 if (section
== PPD_ORDER_JCL
)
646 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
647 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
651 * Add space to account for custom parameter substitution...
654 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
656 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
658 switch (cparam
->type
)
660 case PPD_CUSTOM_CURVE
:
661 case PPD_CUSTOM_INVCURVE
:
662 case PPD_CUSTOM_POINTS
:
663 case PPD_CUSTOM_REAL
:
664 case PPD_CUSTOM_INT
:
668 case PPD_CUSTOM_PASSCODE
:
669 case PPD_CUSTOM_PASSWORD
:
670 case PPD_CUSTOM_STRING
:
671 if (cparam
->current
.custom_string
)
672 bufsize
+= strlen(cparam
->current
.custom_string
);
678 else if (section
!= PPD_ORDER_EXIT
)
680 bufsize
+= 3; /* [{\n */
682 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
683 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
684 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
686 DEBUG_puts("2ppdEmitString: Custom size set!");
688 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
689 bufsize
+= 50; /* Five 9-digit numbers + newline */
691 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
692 (coption
= ppdFindCustomOption(ppd
,
693 choices
[i
]->option
->keyword
))
696 bufsize
+= 23 + strlen(choices
[i
]->option
->keyword
) + 6;
697 /* %%BeginFeature: *Customkeyword True\n */
700 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
702 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
704 switch (cparam
->type
)
706 case PPD_CUSTOM_CURVE
:
707 case PPD_CUSTOM_INVCURVE
:
708 case PPD_CUSTOM_POINTS
:
709 case PPD_CUSTOM_REAL
:
710 case PPD_CUSTOM_INT
:
714 case PPD_CUSTOM_PASSCODE
:
715 case PPD_CUSTOM_PASSWORD
:
716 case PPD_CUSTOM_STRING
:
718 if (cparam
->current
.custom_string
)
719 bufsize
+= 4 * strlen(cparam
->current
.custom_string
);
725 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
726 strlen(choices
[i
]->choice
) + 1;
727 /* %%BeginFeature: *keyword choice\n */
729 bufsize
+= 13; /* %%EndFeature\n */
730 bufsize
+= 22; /* } stopped cleartomark\n */
733 if (choices
[i
]->code
)
734 bufsize
+= strlen(choices
[i
]->code
) + 1;
736 bufsize
+= strlen(ppd_custom_code
);
743 DEBUG_printf(("2ppdEmitString: Allocating %d bytes for string...",
746 if ((buffer
= calloc(1, bufsize
)) == NULL
)
752 bufend
= buffer
+ bufsize
- 1;
756 * Copy the option code to the buffer...
759 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
760 if (section
== PPD_ORDER_JCL
)
762 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
764 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
768 * Handle substitutions in custom JCL options...
771 char *cptr
; /* Pointer into code */
772 int pnum
; /* Parameter number */
775 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
781 if (isdigit(*cptr
& 255))
784 * Substitute parameter...
787 pnum
= *cptr
++ - '0';
788 while (isdigit(*cptr
& 255))
789 pnum
= pnum
* 10 + *cptr
++ - '0';
791 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
793 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
794 if (cparam
->order
== pnum
)
799 switch (cparam
->type
)
801 case PPD_CUSTOM_CURVE
:
802 case PPD_CUSTOM_INVCURVE
:
803 case PPD_CUSTOM_POINTS
:
804 case PPD_CUSTOM_REAL
:
805 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
806 cparam
->current
.custom_real
,
810 case PPD_CUSTOM_INT
:
811 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%d", cparam
->current
.custom_int
);
812 bufptr
+= strlen(bufptr
);
815 case PPD_CUSTOM_PASSCODE
:
816 case PPD_CUSTOM_PASSWORD
:
817 case PPD_CUSTOM_STRING
:
818 if (cparam
->current
.custom_string
)
820 strlcpy(bufptr
, cparam
->current
.custom_string
, (size_t)(bufend
- bufptr
));
821 bufptr
+= strlen(bufptr
);
837 * Otherwise just copy the option code directly...
840 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
841 bufptr
+= strlen(bufptr
);
844 else if (section
!= PPD_ORDER_EXIT
)
847 * Add wrapper commands to prevent printer errors for unsupported
851 strlcpy(bufptr
, "[{\n", (size_t)(bufend
- bufptr
+ 1));
855 * Send DSC comments with option...
858 DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
859 choices
[i
]->option
->keyword
, choices
[i
]->choice
));
861 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
862 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
863 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
866 * Variable size; write out standard size options, using the
867 * parameter positions defined in the PPD file...
870 ppd_attr_t
*attr
; /* PPD attribute */
871 int pos
, /* Position of custom value */
872 orientation
; /* Orientation to use */
873 float values
[5]; /* Values for custom command */
876 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n", (size_t)(bufend
- bufptr
+ 1));
879 size
= ppdPageSize(ppd
, "Custom");
881 memset(values
, 0, sizeof(values
));
883 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
885 pos
= atoi(attr
->value
) - 1;
887 if (pos
< 0 || pos
> 4)
893 values
[pos
] = size
->width
;
895 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
897 pos
= atoi(attr
->value
) - 1;
899 if (pos
< 0 || pos
> 4)
905 values
[pos
] = size
->length
;
908 * According to the Adobe PPD specification, an orientation of 1
909 * will produce a print that comes out upside-down with the X
910 * axis perpendicular to the direction of feed, which is exactly
911 * what we want to be consistent with non-PS printers.
913 * We could also use an orientation of 3 to produce output that
914 * comes out rightside-up (this is the default for many large format
915 * printer PPDs), however for consistency we will stick with the
918 * If we wanted to get fancy, we could use orientations of 0 or
919 * 2 and swap the width and length, however we don't want to get
920 * fancy, we just want it to work consistently.
922 * The orientation value is range limited by the Orientation
923 * parameter definition, so certain non-PS printer drivers that
924 * only support an Orientation of 0 will get the value 0 as
930 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
931 "Orientation")) != NULL
)
933 int min_orient
, max_orient
; /* Minimum and maximum orientations */
936 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
943 if (pos
< 0 || pos
> 4)
946 if (orientation
> max_orient
)
947 orientation
= max_orient
;
948 else if (orientation
< min_orient
)
949 orientation
= min_orient
;
955 values
[pos
] = (float)orientation
;
957 for (pos
= 0; pos
< 5; pos
++)
959 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
963 if (!choices
[i
]->code
)
966 * This can happen with certain buggy PPD files that don't include
967 * a CustomPageSize command sequence... We just use a generic
968 * Level 2 command sequence...
971 strlcpy(bufptr
, ppd_custom_code
, (size_t)(bufend
- bufptr
+ 1));
972 bufptr
+= strlen(bufptr
);
975 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
976 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
983 const char *s
; /* Pointer into string value */
984 cups_array_t
*params
; /* Parameters in the correct output order */
987 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
989 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
991 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
992 cupsArrayAdd(params
, cparam
);
994 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
995 bufptr
+= strlen(bufptr
);
997 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
999 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
1001 switch (cparam
->type
)
1003 case PPD_CUSTOM_CURVE
:
1004 case PPD_CUSTOM_INVCURVE
:
1005 case PPD_CUSTOM_POINTS
:
1006 case PPD_CUSTOM_REAL
:
1007 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
1008 cparam
->current
.custom_real
, loc
);
1012 case PPD_CUSTOM_INT
:
1013 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%d\n", cparam
->current
.custom_int
);
1014 bufptr
+= strlen(bufptr
);
1017 case PPD_CUSTOM_PASSCODE
:
1018 case PPD_CUSTOM_PASSWORD
:
1019 case PPD_CUSTOM_STRING
:
1022 if (cparam
->current
.custom_string
)
1024 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1026 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1028 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "\\%03o", *s
& 255);
1029 bufptr
+= strlen(bufptr
);
1042 cupsArrayDelete(params
);
1046 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *%s %s\n", choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1047 bufptr
+= strlen(bufptr
);
1050 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1052 j
= (int)strlen(choices
[i
]->code
);
1053 memcpy(bufptr
, choices
[i
]->code
, (size_t)j
);
1056 if (choices
[i
]->code
[j
- 1] != '\n')
1060 strlcpy(bufptr
, "%%EndFeature\n"
1061 "} stopped cleartomark\n", (size_t)(bufend
- bufptr
+ 1));
1062 bufptr
+= strlen(bufptr
);
1064 DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
1065 (int)(bufptr
- buffer
)));
1069 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
1070 bufptr
+= strlen(bufptr
);
1074 * Nul-terminate, free, and return...
1086 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1089 static int /* O - Result of comparison */
1090 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1091 ppd_cparam_t
*b
) /* I - Second parameter */
1093 return (a
->order
- b
->order
);
1098 * 'ppd_handle_media()' - Handle media selection...
1102 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1104 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1105 *input_slot
; /* InputSlot choice, if any */
1106 ppd_size_t
*size
; /* Current media size */
1107 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1111 * This function determines what page size code to use, if any, for the
1112 * current media size, InputSlot, and ManualFeed selections.
1114 * We use the PageSize code if:
1116 * 1. A custom media size is selected.
1117 * 2. ManualFeed and InputSlot are not selected (or do not exist).
1118 * 3. ManualFeed is selected but is False and InputSlot is not selected or
1119 * the selection has no code - the latter check done to support "auto" or
1120 * "printer default" InputSlot options.
1122 * We use the PageRegion code if:
1124 * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
1125 * keywords, indicating this is a CUPS-based driver.
1126 * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
1127 * InputSlot or ManualFeed selection) and is True.
1129 * If none of the 5 conditions are true, no page size code is used and we
1130 * unmark any existing PageSize or PageRegion choices.
1133 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1136 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1137 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1139 if (input_slot
!= NULL
)
1140 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1145 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1147 if (!_cups_strcasecmp(size
->name
, "Custom") ||
1148 (!manual_feed
&& !input_slot
) ||
1149 (manual_feed
&& !_cups_strcasecmp(manual_feed
->choice
, "False") &&
1150 (!input_slot
|| (input_slot
->code
&& !input_slot
->code
[0]))) ||
1151 (!rpr
&& ppd
->num_filters
> 0))
1154 * Use PageSize code...
1157 ppdMarkOption(ppd
, "PageSize", size
->name
);
1159 else if (rpr
&& rpr
->value
&& !_cups_strcasecmp(rpr
->value
, "True"))
1162 * Use PageRegion code...
1165 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1170 * Do not use PageSize or PageRegion code...
1173 ppd_choice_t
*page
; /* PageSize/Region choice, if any */
1175 if ((page
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
1178 * Unmark PageSize...
1182 cupsArrayRemove(ppd
->marked
, page
);
1185 if ((page
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
1188 * Unmark PageRegion...
1192 cupsArrayRemove(ppd
->marked
, page
);