]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
5d6ffa94e32d0502600fb8a4ce1c50344085fd83
4 * PPD test program for CUPS.
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
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 * This file is subject to the Apple OS-Developed Software exception.
19 * Include necessary headers...
22 #undef _CUPS_NO_DEPRECATED
23 #include "cups-private.h"
38 static const char *default_code
=
40 "%%BeginFeature: *InstalledDuplexer False\n"
42 "} stopped cleartomark\n"
44 "%%BeginFeature: *PageRegion Letter\n"
47 "} stopped cleartomark\n"
49 "%%BeginFeature: *InputSlot Tray\n"
52 "} stopped cleartomark\n"
54 "%%BeginFeature: *OutputBin Tray1\n"
57 "} stopped cleartomark\n"
59 "%%BeginFeature: *MediaType Plain\n"
62 "} stopped cleartomark\n"
64 "%%BeginFeature: *IntOption None\n"
66 "} stopped cleartomark\n"
68 "%%BeginFeature: *StringOption None\n"
70 "} stopped cleartomark\n";
72 static const char *custom_code
=
74 "%%BeginFeature: *InstalledDuplexer False\n"
76 "} stopped cleartomark\n"
78 "%%BeginFeature: *InputSlot Tray\n"
81 "} stopped cleartomark\n"
83 "%%BeginFeature: *MediaType Plain\n"
86 "} stopped cleartomark\n"
88 "%%BeginFeature: *OutputBin Tray1\n"
91 "} stopped cleartomark\n"
93 "%%BeginFeature: *IntOption None\n"
95 "} stopped cleartomark\n"
97 "%%BeginFeature: *CustomStringOption True\n"
98 "(value\\0502\\051)\n"
100 "StringOption=Custom\n"
102 "} stopped cleartomark\n"
104 "%%BeginFeature: *CustomPageSize True\n"
112 "} stopped cleartomark\n";
114 static const char *default2_code
=
116 "%%BeginFeature: *InstalledDuplexer False\n"
118 "} stopped cleartomark\n"
120 "%%BeginFeature: *InputSlot Tray\n"
123 "} stopped cleartomark\n"
125 "%%BeginFeature: *Quality Normal\n"
128 "} stopped cleartomark\n"
130 "%%BeginFeature: *IntOption None\n"
132 "} stopped cleartomark\n"
134 "%%BeginFeature: *StringOption None\n"
136 "} stopped cleartomark\n";
140 * 'main()' - Main entry.
143 int /* O - Exit status */
144 main(int argc
, /* I - Number of command-line arguments */
145 char *argv
[]) /* I - Command-line arguments */
147 int i
; /* Looping var */
148 ppd_file_t
*ppd
; /* PPD file loaded from disk */
149 int status
; /* Status of tests (0 = success, 1 = fail) */
150 int conflicts
; /* Number of conflicts */
151 char *s
; /* String */
152 char buffer
[8192]; /* String buffer */
153 const char *text
, /* Localized text */
154 *val
; /* Option value */
155 int num_options
; /* Number of options */
156 cups_option_t
*options
; /* Options */
157 ppd_size_t minsize
, /* Minimum size */
158 maxsize
, /* Maximum size */
159 *size
; /* Current size */
160 ppd_attr_t
*attr
; /* Current attribute */
161 _ppd_cache_t
*pc
; /* PPD cache */
169 * Setup directories for locale stuff...
172 if (access("locale", 0))
174 mkdir("locale", 0777);
175 mkdir("locale/fr", 0777);
176 symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po");
177 mkdir("locale/zh_TW", 0777);
178 symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po");
181 putenv("LOCALEDIR=locale");
182 putenv("SOFTWARE=CUPS");
185 * Do tests with test.ppd...
188 fputs("ppdOpenFile(test.ppd): ", stdout
);
190 if ((ppd
= _ppdOpenFile("test.ppd", _PPD_LOCALIZATION_ALL
)) != NULL
)
194 ppd_status_t err
; /* Last error in file */
195 int line
; /* Line number in file */
199 err
= ppdLastError(&line
);
201 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
204 fputs("ppdFindAttr(wildcard): ", stdout
);
205 if ((attr
= ppdFindAttr(ppd
, "cupsTest", NULL
)) == NULL
)
208 puts("FAIL (not found)");
210 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Foo"))
213 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
218 fputs("ppdFindNextAttr(wildcard): ", stdout
);
219 if ((attr
= ppdFindNextAttr(ppd
, "cupsTest", NULL
)) == NULL
)
222 puts("FAIL (not found)");
224 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Bar"))
227 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
232 fputs("ppdFindAttr(Foo): ", stdout
);
233 if ((attr
= ppdFindAttr(ppd
, "cupsTest", "Foo")) == NULL
)
236 puts("FAIL (not found)");
238 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Foo"))
241 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
246 fputs("ppdFindNextAttr(Foo): ", stdout
);
247 if ((attr
= ppdFindNextAttr(ppd
, "cupsTest", "Foo")) != NULL
)
250 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
255 fputs("ppdMarkDefaults: ", stdout
);
256 ppdMarkDefaults(ppd
);
258 if ((conflicts
= ppdConflicts(ppd
)) == 0)
263 printf("FAIL (%d conflicts)\n", conflicts
);
266 fputs("ppdEmitString (defaults): ", stdout
);
267 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
268 !strcmp(s
, default_code
))
273 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
274 (int)strlen(default_code
));
283 fputs("ppdEmitString (custom size and string): ", stdout
);
284 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
285 ppdMarkOption(ppd
, "StringOption", "{String1=\"value 1\" String2=value(2)}");
287 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
288 !strcmp(s
, custom_code
))
293 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
294 (int)strlen(custom_code
));
304 * Test constraints...
307 fputs("cupsGetConflicts(InputSlot=Envelope): ", stdout
);
308 ppdMarkOption(ppd
, "PageSize", "Letter");
310 num_options
= cupsGetConflicts(ppd
, "InputSlot", "Envelope", &options
);
311 if (num_options
!= 2 ||
312 (val
= cupsGetOption("PageRegion", num_options
, options
)) == NULL
||
313 _cups_strcasecmp(val
, "Letter") ||
314 (val
= cupsGetOption("PageSize", num_options
, options
)) == NULL
||
315 _cups_strcasecmp(val
, "Letter"))
317 printf("FAIL (%d options:", num_options
);
318 for (i
= 0; i
< num_options
; i
++)
319 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
326 fputs("ppdConflicts(): ", stdout
);
327 ppdMarkOption(ppd
, "InputSlot", "Envelope");
329 if ((conflicts
= ppdConflicts(ppd
)) == 2)
333 printf("FAIL (%d)\n", conflicts
);
337 fputs("cupsResolveConflicts(InputSlot=Envelope): ", stdout
);
340 if (!cupsResolveConflicts(ppd
, "InputSlot", "Envelope", &num_options
,
343 puts("FAIL (Unable to resolve)");
346 else if (num_options
!= 2 ||
347 !cupsGetOption("PageSize", num_options
, options
))
349 printf("FAIL (%d options:", num_options
);
350 for (i
= 0; i
< num_options
; i
++)
351 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
356 puts("PASS (Resolved by changing PageSize)");
358 cupsFreeOptions(num_options
, options
);
360 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
363 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
364 num_options
== 1 && !_cups_strcasecmp(options
[0].name
, "InputSlot") &&
365 !_cups_strcasecmp(options
[0].value
, "Tray"))
366 puts("PASS (Resolved by changing InputSlot)");
367 else if (num_options
> 0)
369 printf("FAIL (%d options:", num_options
);
370 for (i
= 0; i
< num_options
; i
++)
371 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
377 puts("FAIL (Unable to resolve)");
380 cupsFreeOptions(num_options
, options
);
382 fputs("ppdInstallableConflict(): ", stdout
);
383 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
384 !ppdInstallableConflict(ppd
, "Duplex", "None"))
386 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
388 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
393 puts("FAIL (Duplex=None conflicted)");
401 fputs("ppdPageSizeLimits: ", stdout
);
402 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
404 if (fabs(minsize
.width
- 36.0) > 0.001 || fabs(minsize
.length
- 36.0) > 0.001 ||
405 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
407 printf("FAIL (got min=%.3fx%.3f, max=%.3fx%.3f, "
408 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
409 minsize
.length
, maxsize
.width
, maxsize
.length
);
417 puts("FAIL (returned 0)");
422 * cupsMarkOptions with PWG and IPP size names.
425 fputs("cupsMarkOptions(media=iso-a4): ", stdout
);
426 num_options
= cupsAddOption("media", "iso-a4", 0, &options
);
427 cupsMarkOptions(ppd
, num_options
, options
);
428 cupsFreeOptions(num_options
, options
);
430 size
= ppdPageSize(ppd
, NULL
);
431 if (!size
|| strcmp(size
->name
, "A4"))
433 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
439 fputs("cupsMarkOptions(media=na_letter_8.5x11in): ", stdout
);
440 num_options
= cupsAddOption("media", "na_letter_8.5x11in", 0, &options
);
441 cupsMarkOptions(ppd
, num_options
, options
);
442 cupsFreeOptions(num_options
, options
);
444 size
= ppdPageSize(ppd
, NULL
);
445 if (!size
|| strcmp(size
->name
, "Letter"))
447 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
453 fputs("cupsMarkOptions(media=oe_letter-fullbleed_8.5x11in): ", stdout
);
454 num_options
= cupsAddOption("media", "oe_letter-fullbleed_8.5x11in", 0,
456 cupsMarkOptions(ppd
, num_options
, options
);
457 cupsFreeOptions(num_options
, options
);
459 size
= ppdPageSize(ppd
, NULL
);
460 if (!size
|| strcmp(size
->name
, "Letter.Fullbleed"))
462 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
468 fputs("cupsMarkOptions(media=A4): ", stdout
);
469 num_options
= cupsAddOption("media", "A4", 0, &options
);
470 cupsMarkOptions(ppd
, num_options
, options
);
471 cupsFreeOptions(num_options
, options
);
473 size
= ppdPageSize(ppd
, NULL
);
474 if (!size
|| strcmp(size
->name
, "A4"))
476 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
486 fputs("cupsMarkOptions(media=Custom.8x10in): ", stdout
);
487 num_options
= cupsAddOption("media", "Custom.8x10in", 0, &options
);
488 cupsMarkOptions(ppd
, num_options
, options
);
489 cupsFreeOptions(num_options
, options
);
491 size
= ppdPageSize(ppd
, NULL
);
492 if (!size
|| strcmp(size
->name
, "Custom") ||
493 fabs(size
->width
- 576.0) > 0.001 ||
494 fabs(size
->length
- 720.0) > 0.001)
496 printf("FAIL (%s - %gx%g)\n", size
? size
->name
: "unknown",
497 size
? size
->width
: 0.0, size
? size
->length
: 0.0);
504 * Test localization...
507 fputs("ppdLocalizeIPPReason(text): ", stdout
);
508 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
509 !strcmp(buffer
, "Foo Reason"))
514 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
517 fputs("ppdLocalizeIPPReason(http): ", stdout
);
518 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
519 !strcmp(buffer
, "http://foo/bar.html"))
524 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
527 fputs("ppdLocalizeIPPReason(help): ", stdout
);
528 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
529 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
534 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
537 fputs("ppdLocalizeIPPReason(file): ", stdout
);
538 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
539 !strcmp(buffer
, "/help/foo/bar.html"))
544 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
549 putenv("LC_CTYPE=fr");
550 putenv("LC_MESSAGES=fr");
552 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
553 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
554 !strcmp(buffer
, "La Long Foo Reason"))
559 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
562 putenv("LANG=zh_TW");
563 putenv("LC_ALL=zh_TW");
564 putenv("LC_CTYPE=zh_TW");
565 putenv("LC_MESSAGES=zh_TW");
567 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
568 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
569 !strcmp(buffer
, "Number 1 Foo Reason"))
574 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
578 * cupsMarkerName localization...
583 putenv("LC_CTYPE=en");
584 putenv("LC_MESSAGES=en");
586 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
588 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
591 printf("FAIL (\"%s\" instead of NULL)\n", text
);
596 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
598 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
599 !strcmp(text
, "Cyan Toner"))
604 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
605 text
? text
: "(null)");
610 putenv("LC_CTYPE=fr");
611 putenv("LC_MESSAGES=fr");
613 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
614 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
615 !strcmp(text
, "La Toner Cyan"))
620 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
621 text
? text
: "(null)");
624 putenv("LANG=zh_TW");
625 putenv("LC_ALL=zh_TW");
626 putenv("LC_CTYPE=zh_TW");
627 putenv("LC_MESSAGES=zh_TW");
629 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
630 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
631 !strcmp(text
, "Number 1 Cyan Toner"))
636 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
637 text
? text
: "(null)");
643 * Test new constraints...
646 fputs("ppdOpenFile(test2.ppd): ", stdout
);
648 if ((ppd
= ppdOpenFile("test2.ppd")) != NULL
)
652 ppd_status_t err
; /* Last error in file */
653 int line
; /* Line number in file */
657 err
= ppdLastError(&line
);
659 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
662 fputs("ppdMarkDefaults: ", stdout
);
663 ppdMarkDefaults(ppd
);
665 if ((conflicts
= ppdConflicts(ppd
)) == 0)
670 printf("FAIL (%d conflicts)\n", conflicts
);
673 fputs("ppdEmitString (defaults): ", stdout
);
674 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
675 !strcmp(s
, default2_code
))
680 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
681 (int)strlen(default2_code
));
690 fputs("ppdConflicts(): ", stdout
);
691 ppdMarkOption(ppd
, "PageSize", "Env10");
692 ppdMarkOption(ppd
, "InputSlot", "Envelope");
693 ppdMarkOption(ppd
, "Quality", "Photo");
695 if ((conflicts
= ppdConflicts(ppd
)) == 1)
699 printf("FAIL (%d)\n", conflicts
);
703 fputs("cupsResolveConflicts(Quality=Photo): ", stdout
);
706 if (cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
709 printf("FAIL (%d options:", num_options
);
710 for (i
= 0; i
< num_options
; i
++)
711 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
716 puts("PASS (Unable to resolve)");
717 cupsFreeOptions(num_options
, options
);
719 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
722 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
723 num_options
== 1 && !_cups_strcasecmp(options
->name
, "Quality") &&
724 !_cups_strcasecmp(options
->value
, "Normal"))
726 else if (num_options
> 0)
728 printf("FAIL (%d options:", num_options
);
729 for (i
= 0; i
< num_options
; i
++)
730 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
736 puts("FAIL (Unable to resolve!)");
739 cupsFreeOptions(num_options
, options
);
741 fputs("cupsResolveConflicts(loop test): ", stdout
);
742 ppdMarkOption(ppd
, "PageSize", "A4");
743 ppdMarkOption(ppd
, "InputSlot", "Tray");
744 ppdMarkOption(ppd
, "Quality", "Photo");
747 if (!cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
))
749 else if (num_options
> 0)
751 printf("FAIL (%d options:", num_options
);
752 for (i
= 0; i
< num_options
; i
++)
753 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
757 puts("FAIL (No conflicts!)");
759 fputs("ppdInstallableConflict(): ", stdout
);
760 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
761 !ppdInstallableConflict(ppd
, "Duplex", "None"))
763 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
765 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
770 puts("FAIL (Duplex=None conflicted)");
778 ppdMarkDefaults(ppd
);
780 fputs("ppdPageSizeLimits(default): ", stdout
);
781 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
783 if (fabs(minsize
.width
- 36.0) > 0.001 || fabs(minsize
.length
- 36.0) > 0.001 ||
784 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
786 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
787 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
788 minsize
.length
, maxsize
.width
, maxsize
.length
);
796 puts("FAIL (returned 0)");
800 ppdMarkOption(ppd
, "InputSlot", "Manual");
802 fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout
);
803 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
805 if (fabs(minsize
.width
- 100.0) > 0.001 || fabs(minsize
.length
- 100.0) > 0.001 ||
806 fabs(maxsize
.width
- 1000.0) > 0.001 || fabs(maxsize
.length
- 1000.0) > 0.001)
808 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
809 "expected min=100x100, max=1000x1000)\n", minsize
.width
,
810 minsize
.length
, maxsize
.width
, maxsize
.length
);
818 puts("FAIL (returned 0)");
822 ppdMarkOption(ppd
, "Quality", "Photo");
824 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
825 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
827 if (fabs(minsize
.width
- 200.0) > 0.001 || fabs(minsize
.length
- 200.0) > 0.001 ||
828 fabs(maxsize
.width
- 1000.0) > 0.001 || fabs(maxsize
.length
- 1000.0) > 0.001)
830 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
831 "expected min=200x200, max=1000x1000)\n", minsize
.width
,
832 minsize
.length
, maxsize
.width
, maxsize
.length
);
840 puts("FAIL (returned 0)");
844 ppdMarkOption(ppd
, "InputSlot", "Tray");
846 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
847 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
849 if (fabs(minsize
.width
- 300.0) > 0.001 || fabs(minsize
.length
- 300.0) > 0.001 ||
850 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
852 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
853 "expected min=300x300, max=1080x86400)\n", minsize
.width
,
854 minsize
.length
, maxsize
.width
, maxsize
.length
);
862 puts("FAIL (returned 0)");
868 const char *filename
; /* PPD filename */
869 struct stat fileinfo
; /* File information */
872 if (!strncmp(argv
[1], "-d", 2))
874 const char *printer
; /* Printer name */
877 printer
= argv
[1] + 2;
882 puts("Usage: ./testppd -d printer");
886 filename
= cupsGetPPD(printer
);
890 printf("%s: %s\n", printer
, cupsLastErrorString());
897 if (lstat(filename
, &fileinfo
))
899 printf("%s: %s\n", filename
, strerror(errno
));
903 if (S_ISLNK(fileinfo
.st_mode
))
905 char realfile
[1024]; /* Real file path */
906 ssize_t realsize
; /* Size of real file path */
909 if ((realsize
= readlink(filename
, realfile
, sizeof(realfile
) - 1)) < 0)
910 strlcpy(realfile
, "Unknown", sizeof(realfile
));
912 realfile
[realsize
] = '\0';
914 if (stat(realfile
, &fileinfo
))
915 printf("%s: symlink to \"%s\", %s\n", filename
, realfile
,
918 printf("%s: symlink to \"%s\", %ld bytes\n", filename
, realfile
,
919 (long)fileinfo
.st_size
);
922 printf("%s: regular file, %ld bytes\n", filename
, (long)fileinfo
.st_size
);
924 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
926 ppd_status_t err
; /* Last error in file */
927 int line
; /* Line number in file */
931 err
= ppdLastError(&line
);
933 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
937 int j
, k
; /* Looping vars */
938 ppd_group_t
*group
; /* Option group */
939 ppd_option_t
*option
; /* Option */
940 ppd_coption_t
*coption
; /* Custom option */
941 ppd_cparam_t
*cparam
; /* Custom parameter */
942 ppd_const_t
*c
; /* UIConstraints */
943 char lang
[255], /* LANG environment variable */
944 lc_all
[255], /* LC_ALL environment variable */
945 lc_ctype
[255], /* LC_CTYPE environment variable */
946 lc_messages
[255];/* LC_MESSAGES environment variable */
951 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
953 snprintf(lc_all
, sizeof(lc_all
), "LC_ALL=%s", argv
[2]);
955 snprintf(lc_ctype
, sizeof(lc_ctype
), "LC_CTYPE=%s", argv
[2]);
957 snprintf(lc_messages
, sizeof(lc_messages
), "LC_MESSAGES=%s", argv
[2]);
962 ppdMarkDefaults(ppd
);
966 text
= ppdLocalizeIPPReason(ppd
, argv
[3], NULL
, buffer
, sizeof(buffer
));
967 printf("ppdLocalizeIPPReason(%s)=%s\n", argv
[3],
968 text
? text
: "(null)");
969 return (text
== NULL
);
972 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
976 printf("%s (%s):\n", group
->name
, group
->text
);
978 for (j
= group
->num_options
, option
= group
->options
;
982 printf(" %s (%s):\n", option
->keyword
, option
->text
);
984 for (k
= 0; k
< option
->num_choices
; k
++)
985 printf(" - %s%s (%s)\n",
986 option
->choices
[k
].marked
? "*" : "",
987 option
->choices
[k
].choice
, option
->choices
[k
].text
);
989 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
991 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
993 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
995 switch (cparam
->type
)
997 case PPD_CUSTOM_CURVE
:
998 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
999 cparam
->name
, cparam
->text
,
1000 cparam
->minimum
.custom_curve
,
1001 cparam
->maximum
.custom_curve
);
1004 case PPD_CUSTOM_INT
:
1005 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
1006 cparam
->name
, cparam
->text
,
1007 cparam
->minimum
.custom_int
,
1008 cparam
->maximum
.custom_int
);
1011 case PPD_CUSTOM_INVCURVE
:
1012 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
1013 cparam
->name
, cparam
->text
,
1014 cparam
->minimum
.custom_invcurve
,
1015 cparam
->maximum
.custom_invcurve
);
1018 case PPD_CUSTOM_PASSCODE
:
1019 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
1020 cparam
->name
, cparam
->text
,
1021 cparam
->minimum
.custom_passcode
,
1022 cparam
->maximum
.custom_passcode
);
1025 case PPD_CUSTOM_PASSWORD
:
1026 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
1027 cparam
->name
, cparam
->text
,
1028 cparam
->minimum
.custom_password
,
1029 cparam
->maximum
.custom_password
);
1032 case PPD_CUSTOM_POINTS
:
1033 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
1034 cparam
->name
, cparam
->text
,
1035 cparam
->minimum
.custom_points
,
1036 cparam
->maximum
.custom_points
);
1039 case PPD_CUSTOM_REAL
:
1040 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
1041 cparam
->name
, cparam
->text
,
1042 cparam
->minimum
.custom_real
,
1043 cparam
->maximum
.custom_real
);
1046 case PPD_CUSTOM_STRING
:
1047 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
1048 cparam
->name
, cparam
->text
,
1049 cparam
->minimum
.custom_string
,
1050 cparam
->maximum
.custom_string
);
1059 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
1060 printf(" %s = %gx%g, [%g %g %g %g]\n", size
->name
, size
->width
,
1061 size
->length
, size
->left
, size
->bottom
, size
->right
, size
->top
);
1063 puts("\nConstraints:");
1065 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
1066 printf(" *UIConstraints: *%s %s *%s %s\n", c
->option1
, c
->choice1
,
1067 c
->option2
, c
->choice2
);
1068 if (ppd
->num_consts
== 0)
1069 puts(" NO CONSTRAINTS");
1073 for (i
= 0; i
< ppd
->num_filters
; i
++)
1074 printf(" %s\n", ppd
->filters
[i
]);
1076 if (ppd
->num_filters
== 0)
1077 puts(" NO FILTERS");
1079 puts("\nAttributes:");
1081 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
1083 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
1084 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
1085 attr
->text
, attr
->value
? attr
->value
: "");
1087 puts("\nPPD Cache:");
1088 if ((pc
= _ppdCacheCreateWithPPD(ppd
)) == NULL
)
1089 printf(" Unable to create: %s\n", cupsLastErrorString());
1092 _ppdCacheWriteFile(pc
, "t.cache", NULL
);
1093 puts(" Wrote t.cache.");
1097 if (!strncmp(argv
[1], "-d", 2))
1102 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
1104 char command
[1024]; /* malloc_history command */
1106 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
1111 #endif /* __APPLE__ */