]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
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"
37 static const char *default_code
=
39 "%%BeginFeature: *InstalledDuplexer False\n"
41 "} stopped cleartomark\n"
43 "%%BeginFeature: *PageRegion Letter\n"
46 "} stopped cleartomark\n"
48 "%%BeginFeature: *InputSlot Tray\n"
51 "} stopped cleartomark\n"
53 "%%BeginFeature: *MediaType Plain\n"
56 "} stopped cleartomark\n"
58 "%%BeginFeature: *IntOption None\n"
60 "} stopped cleartomark\n"
62 "%%BeginFeature: *StringOption None\n"
64 "} stopped cleartomark\n";
66 static const char *custom_code
=
68 "%%BeginFeature: *InstalledDuplexer False\n"
70 "} stopped cleartomark\n"
72 "%%BeginFeature: *InputSlot Tray\n"
75 "} stopped cleartomark\n"
77 "%%BeginFeature: *MediaType Plain\n"
80 "} stopped cleartomark\n"
82 "%%BeginFeature: *IntOption None\n"
84 "} stopped cleartomark\n"
86 "%%BeginFeature: *CustomStringOption True\n"
87 "(value\\0502\\051)\n"
89 "StringOption=Custom\n"
91 "} stopped cleartomark\n"
93 "%%BeginFeature: *CustomPageSize True\n"
101 "} stopped cleartomark\n";
103 static const char *default2_code
=
105 "%%BeginFeature: *InstalledDuplexer False\n"
107 "} stopped cleartomark\n"
109 "%%BeginFeature: *InputSlot Tray\n"
112 "} stopped cleartomark\n"
114 "%%BeginFeature: *Quality Normal\n"
117 "} stopped cleartomark\n"
119 "%%BeginFeature: *IntOption None\n"
121 "} stopped cleartomark\n"
123 "%%BeginFeature: *StringOption None\n"
125 "} stopped cleartomark\n";
129 * 'main()' - Main entry.
132 int /* O - Exit status */
133 main(int argc
, /* I - Number of command-line arguments */
134 char *argv
[]) /* I - Command-line arguments */
136 int i
; /* Looping var */
137 ppd_file_t
*ppd
; /* PPD file loaded from disk */
138 int status
; /* Status of tests (0 = success, 1 = fail) */
139 int conflicts
; /* Number of conflicts */
140 char *s
; /* String */
141 char buffer
[8192]; /* String buffer */
142 const char *text
, /* Localized text */
143 *val
; /* Option value */
144 int num_options
; /* Number of options */
145 cups_option_t
*options
; /* Options */
146 ppd_size_t minsize
, /* Minimum size */
147 maxsize
, /* Maximum size */
148 *size
; /* Current size */
149 ppd_attr_t
*attr
; /* Current attribute */
150 _ppd_cache_t
*pc
; /* PPD cache */
158 * Setup directories for locale stuff...
161 if (access("locale", 0))
163 mkdir("locale", 0777);
164 mkdir("locale/fr", 0777);
165 symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po");
166 mkdir("locale/zh_TW", 0777);
167 symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po");
170 putenv("LOCALEDIR=locale");
171 putenv("SOFTWARE=CUPS");
174 * Do tests with test.ppd...
177 fputs("ppdOpenFile(test.ppd): ", stdout
);
179 if ((ppd
= _ppdOpenFile("test.ppd", _PPD_LOCALIZATION_ALL
)) != NULL
)
183 ppd_status_t err
; /* Last error in file */
184 int line
; /* Line number in file */
188 err
= ppdLastError(&line
);
190 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
193 fputs("ppdFindAttr(wildcard): ", stdout
);
194 if ((attr
= ppdFindAttr(ppd
, "cupsTest", NULL
)) == NULL
)
197 puts("FAIL (not found)");
199 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Foo"))
202 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
207 fputs("ppdFindNextAttr(wildcard): ", stdout
);
208 if ((attr
= ppdFindNextAttr(ppd
, "cupsTest", NULL
)) == NULL
)
211 puts("FAIL (not found)");
213 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Bar"))
216 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
221 fputs("ppdFindAttr(Foo): ", stdout
);
222 if ((attr
= ppdFindAttr(ppd
, "cupsTest", "Foo")) == NULL
)
225 puts("FAIL (not found)");
227 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Foo"))
230 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
235 fputs("ppdFindNextAttr(Foo): ", stdout
);
236 if ((attr
= ppdFindNextAttr(ppd
, "cupsTest", "Foo")) != NULL
)
239 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
244 fputs("ppdMarkDefaults: ", stdout
);
245 ppdMarkDefaults(ppd
);
247 if ((conflicts
= ppdConflicts(ppd
)) == 0)
252 printf("FAIL (%d conflicts)\n", conflicts
);
255 fputs("ppdEmitString (defaults): ", stdout
);
256 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
257 !strcmp(s
, default_code
))
262 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
263 (int)strlen(default_code
));
272 fputs("ppdEmitString (custom size and string): ", stdout
);
273 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
274 ppdMarkOption(ppd
, "StringOption", "{String1=\"value 1\" String2=value(2)}");
276 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
277 !strcmp(s
, custom_code
))
282 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
283 (int)strlen(custom_code
));
293 * Test constraints...
296 fputs("cupsGetConflicts(InputSlot=Envelope): ", stdout
);
297 ppdMarkOption(ppd
, "PageSize", "Letter");
299 num_options
= cupsGetConflicts(ppd
, "InputSlot", "Envelope", &options
);
300 if (num_options
!= 2 ||
301 (val
= cupsGetOption("PageRegion", num_options
, options
)) == NULL
||
302 _cups_strcasecmp(val
, "Letter") ||
303 (val
= cupsGetOption("PageSize", num_options
, options
)) == NULL
||
304 _cups_strcasecmp(val
, "Letter"))
306 printf("FAIL (%d options:", num_options
);
307 for (i
= 0; i
< num_options
; i
++)
308 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
315 fputs("ppdConflicts(): ", stdout
);
316 ppdMarkOption(ppd
, "InputSlot", "Envelope");
318 if ((conflicts
= ppdConflicts(ppd
)) == 2)
322 printf("FAIL (%d)\n", conflicts
);
326 fputs("cupsResolveConflicts(InputSlot=Envelope): ", stdout
);
329 if (!cupsResolveConflicts(ppd
, "InputSlot", "Envelope", &num_options
,
332 puts("FAIL (Unable to resolve)");
335 else if (num_options
!= 2 ||
336 !cupsGetOption("PageSize", num_options
, options
))
338 printf("FAIL (%d options:", num_options
);
339 for (i
= 0; i
< num_options
; i
++)
340 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
345 puts("PASS (Resolved by changing PageSize)");
347 cupsFreeOptions(num_options
, options
);
349 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
352 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
353 num_options
== 1 && !_cups_strcasecmp(options
[0].name
, "InputSlot") &&
354 !_cups_strcasecmp(options
[0].value
, "Tray"))
355 puts("PASS (Resolved by changing InputSlot)");
356 else if (num_options
> 0)
358 printf("FAIL (%d options:", num_options
);
359 for (i
= 0; i
< num_options
; i
++)
360 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
366 puts("FAIL (Unable to resolve)");
369 cupsFreeOptions(num_options
, options
);
371 fputs("ppdInstallableConflict(): ", stdout
);
372 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
373 !ppdInstallableConflict(ppd
, "Duplex", "None"))
375 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
377 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
382 puts("FAIL (Duplex=None conflicted)");
390 fputs("ppdPageSizeLimits: ", stdout
);
391 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
393 if (fabs(minsize
.width
- 36.0) > 0.001 || fabs(minsize
.length
- 36.0) > 0.001 ||
394 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
396 printf("FAIL (got min=%.3fx%.3f, max=%.3fx%.3f, "
397 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
398 minsize
.length
, maxsize
.width
, maxsize
.length
);
406 puts("FAIL (returned 0)");
411 * cupsMarkOptions with PWG and IPP size names.
414 fputs("cupsMarkOptions(media=iso-a4): ", stdout
);
415 num_options
= cupsAddOption("media", "iso-a4", 0, &options
);
416 cupsMarkOptions(ppd
, num_options
, options
);
417 cupsFreeOptions(num_options
, options
);
419 size
= ppdPageSize(ppd
, NULL
);
420 if (!size
|| strcmp(size
->name
, "A4"))
422 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
428 fputs("cupsMarkOptions(media=na_letter_8.5x11in): ", stdout
);
429 num_options
= cupsAddOption("media", "na_letter_8.5x11in", 0, &options
);
430 cupsMarkOptions(ppd
, num_options
, options
);
431 cupsFreeOptions(num_options
, options
);
433 size
= ppdPageSize(ppd
, NULL
);
434 if (!size
|| strcmp(size
->name
, "Letter"))
436 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
442 fputs("cupsMarkOptions(media=oe_letter-fullbleed_8.5x11in): ", stdout
);
443 num_options
= cupsAddOption("media", "oe_letter-fullbleed_8.5x11in", 0,
445 cupsMarkOptions(ppd
, num_options
, options
);
446 cupsFreeOptions(num_options
, options
);
448 size
= ppdPageSize(ppd
, NULL
);
449 if (!size
|| strcmp(size
->name
, "Letter.Fullbleed"))
451 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
457 fputs("cupsMarkOptions(media=A4): ", stdout
);
458 num_options
= cupsAddOption("media", "A4", 0, &options
);
459 cupsMarkOptions(ppd
, num_options
, options
);
460 cupsFreeOptions(num_options
, options
);
462 size
= ppdPageSize(ppd
, NULL
);
463 if (!size
|| strcmp(size
->name
, "A4"))
465 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
475 fputs("cupsMarkOptions(media=Custom.8x10in): ", stdout
);
476 num_options
= cupsAddOption("media", "Custom.8x10in", 0, &options
);
477 cupsMarkOptions(ppd
, num_options
, options
);
478 cupsFreeOptions(num_options
, options
);
480 size
= ppdPageSize(ppd
, NULL
);
481 if (!size
|| strcmp(size
->name
, "Custom") ||
482 fabs(size
->width
- 576.0) > 0.001 ||
483 fabs(size
->length
- 720.0) > 0.001)
485 printf("FAIL (%s - %gx%g)\n", size
? size
->name
: "unknown",
486 size
? size
->width
: 0.0, size
? size
->length
: 0.0);
493 * Test localization...
496 fputs("ppdLocalizeIPPReason(text): ", stdout
);
497 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
498 !strcmp(buffer
, "Foo Reason"))
503 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
506 fputs("ppdLocalizeIPPReason(http): ", stdout
);
507 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
508 !strcmp(buffer
, "http://foo/bar.html"))
513 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
516 fputs("ppdLocalizeIPPReason(help): ", stdout
);
517 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
518 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
523 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
526 fputs("ppdLocalizeIPPReason(file): ", stdout
);
527 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
528 !strcmp(buffer
, "/help/foo/bar.html"))
533 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
538 putenv("LC_CTYPE=fr");
539 putenv("LC_MESSAGES=fr");
541 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
542 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
543 !strcmp(buffer
, "La Long Foo Reason"))
548 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
551 putenv("LANG=zh_TW");
552 putenv("LC_ALL=zh_TW");
553 putenv("LC_CTYPE=zh_TW");
554 putenv("LC_MESSAGES=zh_TW");
556 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
557 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
558 !strcmp(buffer
, "Number 1 Foo Reason"))
563 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
567 * cupsMarkerName localization...
572 putenv("LC_CTYPE=en");
573 putenv("LC_MESSAGES=en");
575 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
577 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
580 printf("FAIL (\"%s\" instead of NULL)\n", text
);
585 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
587 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
588 !strcmp(text
, "Cyan Toner"))
593 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
594 text
? text
: "(null)");
599 putenv("LC_CTYPE=fr");
600 putenv("LC_MESSAGES=fr");
602 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
603 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
604 !strcmp(text
, "La Toner Cyan"))
609 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
610 text
? text
: "(null)");
613 putenv("LANG=zh_TW");
614 putenv("LC_ALL=zh_TW");
615 putenv("LC_CTYPE=zh_TW");
616 putenv("LC_MESSAGES=zh_TW");
618 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
619 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
620 !strcmp(text
, "Number 1 Cyan Toner"))
625 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
626 text
? text
: "(null)");
632 * Test new constraints...
635 fputs("ppdOpenFile(test2.ppd): ", stdout
);
637 if ((ppd
= ppdOpenFile("test2.ppd")) != NULL
)
641 ppd_status_t err
; /* Last error in file */
642 int line
; /* Line number in file */
646 err
= ppdLastError(&line
);
648 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
651 fputs("ppdMarkDefaults: ", stdout
);
652 ppdMarkDefaults(ppd
);
654 if ((conflicts
= ppdConflicts(ppd
)) == 0)
659 printf("FAIL (%d conflicts)\n", conflicts
);
662 fputs("ppdEmitString (defaults): ", stdout
);
663 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
664 !strcmp(s
, default2_code
))
669 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
670 (int)strlen(default2_code
));
679 fputs("ppdConflicts(): ", stdout
);
680 ppdMarkOption(ppd
, "PageSize", "Env10");
681 ppdMarkOption(ppd
, "InputSlot", "Envelope");
682 ppdMarkOption(ppd
, "Quality", "Photo");
684 if ((conflicts
= ppdConflicts(ppd
)) == 1)
688 printf("FAIL (%d)\n", conflicts
);
692 fputs("cupsResolveConflicts(Quality=Photo): ", stdout
);
695 if (cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
698 printf("FAIL (%d options:", num_options
);
699 for (i
= 0; i
< num_options
; i
++)
700 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
705 puts("PASS (Unable to resolve)");
706 cupsFreeOptions(num_options
, options
);
708 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
711 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
712 num_options
== 1 && !_cups_strcasecmp(options
->name
, "Quality") &&
713 !_cups_strcasecmp(options
->value
, "Normal"))
715 else if (num_options
> 0)
717 printf("FAIL (%d options:", num_options
);
718 for (i
= 0; i
< num_options
; i
++)
719 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
725 puts("FAIL (Unable to resolve!)");
728 cupsFreeOptions(num_options
, options
);
730 fputs("cupsResolveConflicts(loop test): ", stdout
);
731 ppdMarkOption(ppd
, "PageSize", "A4");
732 ppdMarkOption(ppd
, "InputSlot", "Tray");
733 ppdMarkOption(ppd
, "Quality", "Photo");
736 if (!cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
))
738 else if (num_options
> 0)
740 printf("FAIL (%d options:", num_options
);
741 for (i
= 0; i
< num_options
; i
++)
742 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
746 puts("FAIL (No conflicts!)");
748 fputs("ppdInstallableConflict(): ", stdout
);
749 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
750 !ppdInstallableConflict(ppd
, "Duplex", "None"))
752 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
754 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
759 puts("FAIL (Duplex=None conflicted)");
767 ppdMarkDefaults(ppd
);
769 fputs("ppdPageSizeLimits(default): ", stdout
);
770 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
772 if (fabs(minsize
.width
- 36.0) > 0.001 || fabs(minsize
.length
- 36.0) > 0.001 ||
773 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
775 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
776 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
777 minsize
.length
, maxsize
.width
, maxsize
.length
);
785 puts("FAIL (returned 0)");
789 ppdMarkOption(ppd
, "InputSlot", "Manual");
791 fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout
);
792 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
794 if (fabs(minsize
.width
- 100.0) > 0.001 || fabs(minsize
.length
- 100.0) > 0.001 ||
795 fabs(maxsize
.width
- 1000.0) > 0.001 || fabs(maxsize
.length
- 1000.0) > 0.001)
797 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
798 "expected min=100x100, max=1000x1000)\n", minsize
.width
,
799 minsize
.length
, maxsize
.width
, maxsize
.length
);
807 puts("FAIL (returned 0)");
811 ppdMarkOption(ppd
, "Quality", "Photo");
813 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
814 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
816 if (fabs(minsize
.width
- 200.0) > 0.001 || fabs(minsize
.length
- 200.0) > 0.001 ||
817 fabs(maxsize
.width
- 1000.0) > 0.001 || fabs(maxsize
.length
- 1000.0) > 0.001)
819 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
820 "expected min=200x200, max=1000x1000)\n", minsize
.width
,
821 minsize
.length
, maxsize
.width
, maxsize
.length
);
829 puts("FAIL (returned 0)");
833 ppdMarkOption(ppd
, "InputSlot", "Tray");
835 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
836 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
838 if (fabs(minsize
.width
- 300.0) > 0.001 || fabs(minsize
.length
- 300.0) > 0.001 ||
839 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
841 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
842 "expected min=300x300, max=1080x86400)\n", minsize
.width
,
843 minsize
.length
, maxsize
.width
, maxsize
.length
);
851 puts("FAIL (returned 0)");
857 const char *filename
; /* PPD filename */
858 struct stat fileinfo
; /* File information */
861 if (!strncmp(argv
[1], "-d", 2))
863 const char *printer
; /* Printer name */
866 printer
= argv
[1] + 2;
871 puts("Usage: ./testppd -d printer");
875 filename
= cupsGetPPD(printer
);
879 printf("%s: %s\n", printer
, cupsLastErrorString());
886 if (lstat(filename
, &fileinfo
))
888 printf("%s: %s\n", filename
, strerror(errno
));
892 if (S_ISLNK(fileinfo
.st_mode
))
894 char realfile
[1024]; /* Real file path */
895 ssize_t realsize
; /* Size of real file path */
898 if ((realsize
= readlink(filename
, realfile
, sizeof(realfile
) - 1)) < 0)
899 strlcpy(realfile
, "Unknown", sizeof(realfile
));
901 realfile
[realsize
] = '\0';
903 if (stat(realfile
, &fileinfo
))
904 printf("%s: symlink to \"%s\", %s\n", filename
, realfile
,
907 printf("%s: symlink to \"%s\", %ld bytes\n", filename
, realfile
,
908 (long)fileinfo
.st_size
);
911 printf("%s: regular file, %ld bytes\n", filename
, (long)fileinfo
.st_size
);
913 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
915 ppd_status_t err
; /* Last error in file */
916 int line
; /* Line number in file */
920 err
= ppdLastError(&line
);
922 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
926 int j
, k
; /* Looping vars */
927 ppd_group_t
*group
; /* Option group */
928 ppd_option_t
*option
; /* Option */
929 ppd_coption_t
*coption
; /* Custom option */
930 ppd_cparam_t
*cparam
; /* Custom parameter */
931 ppd_const_t
*c
; /* UIConstraints */
932 char lang
[255], /* LANG environment variable */
933 lc_all
[255], /* LC_ALL environment variable */
934 lc_ctype
[255], /* LC_CTYPE environment variable */
935 lc_messages
[255];/* LC_MESSAGES environment variable */
940 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
942 snprintf(lc_all
, sizeof(lc_all
), "LC_ALL=%s", argv
[2]);
944 snprintf(lc_ctype
, sizeof(lc_ctype
), "LC_CTYPE=%s", argv
[2]);
946 snprintf(lc_messages
, sizeof(lc_messages
), "LC_MESSAGES=%s", argv
[2]);
951 ppdMarkDefaults(ppd
);
955 text
= ppdLocalizeIPPReason(ppd
, argv
[3], NULL
, buffer
, sizeof(buffer
));
956 printf("ppdLocalizeIPPReason(%s)=%s\n", argv
[3],
957 text
? text
: "(null)");
958 return (text
== NULL
);
961 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
965 printf("%s (%s):\n", group
->name
, group
->text
);
967 for (j
= group
->num_options
, option
= group
->options
;
971 printf(" %s (%s):\n", option
->keyword
, option
->text
);
973 for (k
= 0; k
< option
->num_choices
; k
++)
974 printf(" - %s%s (%s)\n",
975 option
->choices
[k
].marked
? "*" : "",
976 option
->choices
[k
].choice
, option
->choices
[k
].text
);
978 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
980 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
982 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
984 switch (cparam
->type
)
986 case PPD_CUSTOM_CURVE
:
987 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
988 cparam
->name
, cparam
->text
,
989 cparam
->minimum
.custom_curve
,
990 cparam
->maximum
.custom_curve
);
993 case PPD_CUSTOM_INT
:
994 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
995 cparam
->name
, cparam
->text
,
996 cparam
->minimum
.custom_int
,
997 cparam
->maximum
.custom_int
);
1000 case PPD_CUSTOM_INVCURVE
:
1001 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
1002 cparam
->name
, cparam
->text
,
1003 cparam
->minimum
.custom_invcurve
,
1004 cparam
->maximum
.custom_invcurve
);
1007 case PPD_CUSTOM_PASSCODE
:
1008 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
1009 cparam
->name
, cparam
->text
,
1010 cparam
->minimum
.custom_passcode
,
1011 cparam
->maximum
.custom_passcode
);
1014 case PPD_CUSTOM_PASSWORD
:
1015 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
1016 cparam
->name
, cparam
->text
,
1017 cparam
->minimum
.custom_password
,
1018 cparam
->maximum
.custom_password
);
1021 case PPD_CUSTOM_POINTS
:
1022 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
1023 cparam
->name
, cparam
->text
,
1024 cparam
->minimum
.custom_points
,
1025 cparam
->maximum
.custom_points
);
1028 case PPD_CUSTOM_REAL
:
1029 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
1030 cparam
->name
, cparam
->text
,
1031 cparam
->minimum
.custom_real
,
1032 cparam
->maximum
.custom_real
);
1035 case PPD_CUSTOM_STRING
:
1036 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
1037 cparam
->name
, cparam
->text
,
1038 cparam
->minimum
.custom_string
,
1039 cparam
->maximum
.custom_string
);
1048 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
1049 printf(" %s = %gx%g, [%g %g %g %g]\n", size
->name
, size
->width
,
1050 size
->length
, size
->left
, size
->bottom
, size
->right
, size
->top
);
1052 puts("\nConstraints:");
1054 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
1055 printf(" *UIConstraints: *%s %s *%s %s\n", c
->option1
, c
->choice1
,
1056 c
->option2
, c
->choice2
);
1057 if (ppd
->num_consts
== 0)
1058 puts(" NO CONSTRAINTS");
1062 for (i
= 0; i
< ppd
->num_filters
; i
++)
1063 printf(" %s\n", ppd
->filters
[i
]);
1065 if (ppd
->num_filters
== 0)
1066 puts(" NO FILTERS");
1068 puts("\nAttributes:");
1070 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
1072 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
1073 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
1074 attr
->text
, attr
->value
? attr
->value
: "");
1076 puts("\nPPD Cache:");
1077 if ((pc
= _ppdCacheCreateWithPPD(ppd
)) == NULL
)
1078 printf(" Unable to create: %s\n", cupsLastErrorString());
1081 _ppdCacheWriteFile(pc
, "t.cache", NULL
);
1082 puts(" Wrote t.cache.");
1086 if (!strncmp(argv
[1], "-d", 2))
1091 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
1093 char command
[1024]; /* malloc_history command */
1095 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
1100 #endif /* __APPLE__ */