2 * "$Id: cupstestppd.c 7807 2008-07-28 21:54:24Z mike $"
4 * PPD test program for CUPS.
6 * Copyright 2007-2011 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 * main() - Main entry for test program.
22 * check_basics() - Check for CR LF, mixed line endings, and blank
24 * check_constraints() - Check UIConstraints in the PPD file.
25 * check_case() - Check that there are no duplicate groups, options,
26 * or choices that differ only by case.
27 * check_defaults() - Check default option keywords in the PPD file.
28 * check_duplex() - Check duplex keywords in the PPD file.
29 * check_filters() - Check filters in the PPD file.
30 * check_profiles() - Check ICC color profiles in the PPD file.
31 * check_sizes() - Check media sizes in the PPD file.
32 * check_translations() - Check translations in the PPD file.
33 * show_conflicts() - Show option conflicts in a PPD file.
34 * test_raster() - Test PostScript commands for raster printers.
35 * usage() - Show program usage...
36 * valid_path() - Check whether a path has the correct capitalization.
37 * valid_utf8() - Check whether a string contains valid UTF-8 text.
41 * Include necessary headers...
44 #include <cups/cups-private.h>
46 #include <cups/ppd-private.h>
47 #include <cups/raster.h>
55 * Error warning overrides...
65 WARN_TRANSLATIONS
= 16,
101 * File permissions...
104 #define MODE_WRITE 0022 /* Group/other write */
105 #define MODE_MASK 0555 /* Owner/group/other read+exec/search */
106 #define MODE_DATAFILE 0444 /* Owner/group/other read */
107 #define MODE_DIRECTORY 0555 /* Owner/group/other read+search */
108 #define MODE_PROGRAM 0555 /* Owner/group/other read+exec */
115 static void check_basics(const char *filename
);
116 static int check_constraints(ppd_file_t
*ppd
, int errors
, int verbose
,
118 static int check_case(ppd_file_t
*ppd
, int errors
, int verbose
);
119 static int check_defaults(ppd_file_t
*ppd
, int errors
, int verbose
,
121 static int check_duplex(ppd_file_t
*ppd
, int errors
, int verbose
,
123 static int check_filters(ppd_file_t
*ppd
, const char *root
, int errors
,
124 int verbose
, int warn
);
125 static int check_profiles(ppd_file_t
*ppd
, const char *root
, int errors
,
126 int verbose
, int warn
);
127 static int check_sizes(ppd_file_t
*ppd
, int errors
, int verbose
, int warn
);
128 static int check_translations(ppd_file_t
*ppd
, int errors
, int verbose
,
130 static void show_conflicts(ppd_file_t
*ppd
);
131 static int test_raster(ppd_file_t
*ppd
, int verbose
);
132 static void usage(void);
133 static int valid_path(const char *keyword
, const char *path
, int errors
,
134 int verbose
, int warn
);
135 static int valid_utf8(const char *s
);
139 * 'main()' - Main entry for test program.
142 int /* O - Exit status */
143 main(int argc
, /* I - Number of command-line args */
144 char *argv
[]) /* I - Command-line arguments */
146 int i
, j
, k
, m
, n
; /* Looping vars */
147 int len
; /* Length of option name */
148 char *opt
; /* Option character */
149 const char *ptr
; /* Pointer into string */
150 int files
; /* Number of files */
151 int verbose
; /* Want verbose output? */
152 int warn
; /* Which errors to just warn about */
153 int ignore
; /* Which errors to ignore */
154 int status
; /* Exit status */
155 int errors
; /* Number of conformance errors */
156 int ppdversion
; /* PPD spec version in PPD file */
157 ppd_status_t error
; /* Status of ppdOpen*() */
158 int line
; /* Line number for error */
159 char *root
; /* Root directory */
160 int xdpi
, /* X resolution */
161 ydpi
; /* Y resolution */
162 ppd_file_t
*ppd
; /* PPD file record */
163 ppd_attr_t
*attr
; /* PPD attribute */
164 ppd_size_t
*size
; /* Size record */
165 ppd_group_t
*group
; /* UI group */
166 ppd_option_t
*option
; /* Standard UI option */
167 ppd_group_t
*group2
; /* UI group */
168 ppd_option_t
*option2
; /* Standard UI option */
169 ppd_choice_t
*choice
; /* Standard UI option choice */
170 struct lconv
*loc
; /* Locale data */
171 static char *uis
[] = { "BOOLEAN", "PICKONE", "PICKMANY" };
172 static char *sections
[] = { "ANY", "DOCUMENT", "EXIT",
173 "JCL", "PAGE", "PROLOG" };
176 _cupsSetLocale(argv
);
180 * Display PPD files for each file listed on the command-line...
183 ppdSetConformance(PPD_CONFORM_STRICT
);
193 for (i
= 1; i
< argc
; i
++)
194 if (argv
[i
][0] == '-' && argv
[i
][1])
196 for (opt
= argv
[i
] + 1; *opt
; opt
++)
199 case 'I' : /* Ignore errors */
205 if (!strcmp(argv
[i
], "none"))
207 else if (!strcmp(argv
[i
], "filename"))
208 ignore
|= WARN_FILENAME
;
209 else if (!strcmp(argv
[i
], "filters"))
210 ignore
|= WARN_FILTERS
;
211 else if (!strcmp(argv
[i
], "profiles"))
212 ignore
|= WARN_PROFILES
;
213 else if (!strcmp(argv
[i
], "all"))
214 ignore
= WARN_FILTERS
| WARN_PROFILES
;
219 case 'R' : /* Alternate root directory */
228 case 'W' : /* Turn errors into warnings */
234 if (!strcmp(argv
[i
], "none"))
236 else if (!strcmp(argv
[i
], "constraints"))
237 warn
|= WARN_CONSTRAINTS
;
238 else if (!strcmp(argv
[i
], "defaults"))
239 warn
|= WARN_DEFAULTS
;
240 else if (!strcmp(argv
[i
], "duplex"))
242 else if (!strcmp(argv
[i
], "filters"))
243 warn
|= WARN_FILTERS
;
244 else if (!strcmp(argv
[i
], "profiles"))
245 warn
|= WARN_PROFILES
;
246 else if (!strcmp(argv
[i
], "sizes"))
248 else if (!strcmp(argv
[i
], "translations"))
249 warn
|= WARN_TRANSLATIONS
;
250 else if (!strcmp(argv
[i
], "all"))
256 case 'q' : /* Quiet mode */
259 _cupsLangPuts(stderr
,
260 _("cupstestppd: The -q option is incompatible "
261 "with the -v option."));
268 case 'r' : /* Relaxed mode */
269 ppdSetConformance(PPD_CONFORM_RELAXED
);
272 case 'v' : /* Verbose mode */
275 _cupsLangPuts(stderr
,
276 _("cupstestppd: The -v option is incompatible "
277 "with the -q option."));
292 * Open the PPD file...
295 if (files
&& verbose
>= 0)
300 if (argv
[i
][0] == '-')
306 ppd
= ppdOpen(stdin
);
309 printf("%s:", (ppd
&& ppd
->pcfilename
) ? ppd
->pcfilename
: "(stdin)");
314 * Read from a file...
318 printf("%s:", argv
[i
]);
320 ppd
= ppdOpenFile(argv
[i
]);
325 error
= ppdLastError(&line
);
327 if (error
<= PPD_ALLOC_ERROR
)
329 status
= ERROR_FILE_OPEN
;
333 _cupsLangPuts(stdout
, _(" FAIL"));
334 _cupsLangPrintf(stdout
,
335 _(" **FAIL** Unable to open PPD file - %s"),
341 status
= ERROR_PPD_FORMAT
;
345 _cupsLangPuts(stdout
, _(" FAIL"));
346 _cupsLangPrintf(stdout
,
347 _(" **FAIL** Unable to open PPD file - "
349 ppdErrorString(error
), line
);
353 case PPD_MISSING_PPDADOBE4
:
354 _cupsLangPuts(stdout
,
355 _(" REF: Page 42, section "
358 case PPD_MISSING_VALUE
:
359 _cupsLangPuts(stdout
,
360 _(" REF: Page 20, section "
363 case PPD_BAD_OPEN_GROUP
:
364 case PPD_NESTED_OPEN_GROUP
:
365 _cupsLangPuts(stdout
,
366 _(" REF: Pages 45-46, section "
369 case PPD_BAD_OPEN_UI
:
370 case PPD_NESTED_OPEN_UI
:
371 _cupsLangPuts(stdout
,
372 _(" REF: Pages 42-45, section "
375 case PPD_BAD_ORDER_DEPENDENCY
:
376 _cupsLangPuts(stdout
,
377 _(" REF: Pages 48-49, section "
380 case PPD_BAD_UI_CONSTRAINTS
:
381 _cupsLangPuts(stdout
,
382 _(" REF: Pages 52-54, section "
385 case PPD_MISSING_ASTERISK
:
386 _cupsLangPuts(stdout
,
387 _(" REF: Page 15, section "
390 case PPD_LINE_TOO_LONG
:
391 _cupsLangPuts(stdout
,
392 _(" REF: Page 15, section "
395 case PPD_ILLEGAL_CHARACTER
:
396 _cupsLangPuts(stdout
,
397 _(" REF: Page 15, section "
400 case PPD_ILLEGAL_MAIN_KEYWORD
:
401 _cupsLangPuts(stdout
,
402 _(" REF: Pages 16-17, section "
405 case PPD_ILLEGAL_OPTION_KEYWORD
:
406 _cupsLangPuts(stdout
,
407 _(" REF: Page 19, section "
410 case PPD_ILLEGAL_TRANSLATION
:
411 _cupsLangPuts(stdout
,
412 _(" REF: Page 27, section "
419 check_basics(argv
[i
]);
427 * Show the header and then perform basic conformance tests (limited
428 * only by what the CUPS PPD functions actually load...)
435 _cupsLangPuts(stdout
,
436 _("\n DETAILED CONFORMANCE TEST RESULTS"));
438 if ((attr
= ppdFindAttr(ppd
, "FormatVersion", NULL
)) != NULL
&&
440 ppdversion
= (int)(10 * _cupsStrScand(attr
->value
, NULL
, loc
) + 0.5);
442 for (j
= 0; j
< ppd
->num_filters
; j
++)
443 if (strstr(ppd
->filters
[j
], "application/vnd.cups-raster"))
445 if (!test_raster(ppd
, verbose
))
451 * Look for default keywords with no matching option...
454 if (!(warn
& WARN_DEFAULTS
))
455 errors
= check_defaults(ppd
, errors
, verbose
, 0);
457 if ((attr
= ppdFindAttr(ppd
, "DefaultImageableArea", NULL
)) == NULL
)
461 if (!errors
&& !verbose
)
462 _cupsLangPuts(stdout
, _(" FAIL"));
464 _cupsLangPuts(stdout
,
465 _(" **FAIL** REQUIRED DefaultImageableArea\n"
466 " REF: Page 102, section 5.15."));
471 else if (ppdPageSize(ppd
, attr
->value
) == NULL
&&
472 strcmp(attr
->value
, "Unknown"))
476 if (!errors
&& !verbose
)
477 _cupsLangPuts(stdout
, _(" FAIL"));
479 _cupsLangPrintf(stdout
,
480 _(" **FAIL** BAD DefaultImageableArea %s\n"
481 " REF: Page 102, section 5.15."),
490 _cupsLangPuts(stdout
, _(" PASS DefaultImageableArea"));
493 if ((attr
= ppdFindAttr(ppd
, "DefaultPaperDimension", NULL
)) == NULL
)
497 if (!errors
&& !verbose
)
498 _cupsLangPuts(stdout
, _(" FAIL"));
500 _cupsLangPuts(stdout
,
501 _(" **FAIL** REQUIRED DefaultPaperDimension\n"
502 " REF: Page 103, section 5.15."));
507 else if (ppdPageSize(ppd
, attr
->value
) == NULL
&&
508 strcmp(attr
->value
, "Unknown"))
512 if (!errors
&& !verbose
)
513 _cupsLangPuts(stdout
, _(" FAIL"));
515 _cupsLangPrintf(stdout
,
516 _(" **FAIL** BAD DefaultPaperDimension %s\n"
517 " REF: Page 103, section 5.15."),
523 else if (verbose
> 0)
524 _cupsLangPuts(stdout
, _(" PASS DefaultPaperDimension"));
526 for (j
= 0, group
= ppd
->groups
; j
< ppd
->num_groups
; j
++, group
++)
527 for (k
= 0, option
= group
->options
;
528 k
< group
->num_options
;
532 * Verify that we have a default choice...
535 if (option
->defchoice
[0])
537 if (ppdFindChoice(option
, option
->defchoice
) == NULL
&&
538 strcmp(option
->defchoice
, "Unknown"))
542 if (!errors
&& !verbose
)
543 _cupsLangPuts(stdout
, _(" FAIL"));
545 _cupsLangPrintf(stdout
,
546 _(" **FAIL** BAD Default%s %s\n"
547 " REF: Page 40, section 4.5."),
548 option
->keyword
, option
->defchoice
);
553 else if (verbose
> 0)
554 _cupsLangPrintf(stdout
,
555 _(" PASS Default%s"),
562 if (!errors
&& !verbose
)
563 _cupsLangPuts(stdout
, _(" FAIL"));
565 _cupsLangPrintf(stdout
,
566 _(" **FAIL** REQUIRED Default%s\n"
567 " REF: Page 40, section 4.5."),
575 if ((attr
= ppdFindAttr(ppd
, "FileVersion", NULL
)) != NULL
)
577 for (ptr
= attr
->value
; *ptr
; ptr
++)
578 if (!isdigit(*ptr
& 255) && *ptr
!= '.')
585 if (!errors
&& !verbose
)
586 _cupsLangPuts(stdout
, _(" FAIL"));
588 _cupsLangPrintf(stdout
,
589 _(" **FAIL** Bad FileVersion \"%s\"\n"
590 " REF: Page 56, section 5.3."),
596 else if (verbose
> 0)
597 _cupsLangPuts(stdout
, _(" PASS FileVersion"));
603 if (!errors
&& !verbose
)
604 _cupsLangPuts(stdout
, _(" FAIL"));
606 _cupsLangPuts(stdout
,
607 _(" **FAIL** REQUIRED FileVersion\n"
608 " REF: Page 56, section 5.3."));
614 if ((attr
= ppdFindAttr(ppd
, "FormatVersion", NULL
)) != NULL
)
617 if (*ptr
== '4' && ptr
[1] == '.')
620 for (ptr
+= 2; *ptr
; ptr
++)
621 if (!isdigit(*ptr
& 255))
629 if (!errors
&& !verbose
)
630 _cupsLangPuts(stdout
, _(" FAIL"));
632 _cupsLangPrintf(stdout
,
633 _(" **FAIL** Bad FormatVersion \"%s\"\n"
634 " REF: Page 56, section 5.3."),
640 else if (verbose
> 0)
641 _cupsLangPuts(stdout
, _(" PASS FormatVersion"));
647 if (!errors
&& !verbose
)
648 _cupsLangPuts(stdout
, _(" FAIL"));
650 _cupsLangPuts(stdout
,
651 _(" **FAIL** REQUIRED FormatVersion\n"
652 " REF: Page 56, section 5.3."));
658 if (ppd
->lang_encoding
!= NULL
)
661 _cupsLangPuts(stdout
, _(" PASS LanguageEncoding"));
663 else if (ppdversion
> 40)
667 if (!errors
&& !verbose
)
668 _cupsLangPuts(stdout
, _(" FAIL"));
670 _cupsLangPuts(stdout
,
671 _(" **FAIL** REQUIRED LanguageEncoding\n"
672 " REF: Pages 56-57, section 5.3."));
678 if (ppd
->lang_version
!= NULL
)
681 _cupsLangPuts(stdout
, _(" PASS LanguageVersion"));
687 if (!errors
&& !verbose
)
688 _cupsLangPuts(stdout
, _(" FAIL"));
690 _cupsLangPuts(stdout
,
691 _(" **FAIL** REQUIRED LanguageVersion\n"
692 " REF: Pages 57-58, section 5.3."));
698 if (ppd
->manufacturer
!= NULL
)
700 if (!strncasecmp(ppd
->manufacturer
, "Hewlett-Packard", 15) ||
701 !strncasecmp(ppd
->manufacturer
, "Hewlett Packard", 15))
705 if (!errors
&& !verbose
)
706 _cupsLangPuts(stdout
, _(" FAIL"));
708 _cupsLangPuts(stdout
,
709 _(" **FAIL** BAD Manufacturer (should be "
711 " REF: Page 211, table D.1."));
716 else if (!strncasecmp(ppd
->manufacturer
, "OkiData", 7) ||
717 !strncasecmp(ppd
->manufacturer
, "Oki Data", 8))
721 if (!errors
&& !verbose
)
722 _cupsLangPuts(stdout
, _(" FAIL"));
724 _cupsLangPuts(stdout
,
725 _(" **FAIL** BAD Manufacturer (should be "
727 " REF: Page 211, table D.1."));
732 else if (verbose
> 0)
733 _cupsLangPuts(stdout
, _(" PASS Manufacturer"));
735 else if (ppdversion
>= 43)
739 if (!errors
&& !verbose
)
740 _cupsLangPuts(stdout
, _(" FAIL"));
742 _cupsLangPuts(stdout
,
743 _(" **FAIL** REQUIRED Manufacturer\n"
744 " REF: Pages 58-59, section 5.3."));
750 if (ppd
->modelname
!= NULL
)
752 for (ptr
= ppd
->modelname
; *ptr
; ptr
++)
753 if (!isalnum(*ptr
& 255) && !strchr(" ./-+", *ptr
))
760 if (!errors
&& !verbose
)
761 _cupsLangPuts(stdout
, _(" FAIL"));
763 _cupsLangPrintf(stdout
,
764 _(" **FAIL** BAD ModelName - \"%c\" not "
765 "allowed in string.\n"
766 " REF: Pages 59-60, section 5.3."),
772 else if (verbose
> 0)
773 _cupsLangPuts(stdout
, _(" PASS ModelName"));
779 if (!errors
&& !verbose
)
780 _cupsLangPuts(stdout
, _(" FAIL"));
782 _cupsLangPuts(stdout
,
783 _(" **FAIL** REQUIRED ModelName\n"
784 " REF: Pages 59-60, section 5.3."));
790 if (ppd
->nickname
!= NULL
)
793 _cupsLangPuts(stdout
, _(" PASS NickName"));
799 if (!errors
&& !verbose
)
800 _cupsLangPuts(stdout
, _(" FAIL"));
802 _cupsLangPuts(stdout
,
803 _(" **FAIL** REQUIRED NickName\n"
804 " REF: Page 60, section 5.3."));
810 if (ppdFindOption(ppd
, "PageSize") != NULL
)
813 _cupsLangPuts(stdout
, _(" PASS PageSize"));
819 if (!errors
&& !verbose
)
820 _cupsLangPuts(stdout
, _(" FAIL"));
822 _cupsLangPuts(stdout
,
823 _(" **FAIL** REQUIRED PageSize\n"
824 " REF: Pages 99-100, section 5.14."));
830 if (ppdFindOption(ppd
, "PageRegion") != NULL
)
833 _cupsLangPuts(stdout
, _(" PASS PageRegion"));
839 if (!errors
&& !verbose
)
840 _cupsLangPuts(stdout
, _(" FAIL"));
842 _cupsLangPuts(stdout
,
843 _(" **FAIL** REQUIRED PageRegion\n"
844 " REF: Page 100, section 5.14."));
850 if (ppd
->pcfilename
!= NULL
)
853 _cupsLangPuts(stdout
, _(" PASS PCFileName"));
855 else if (!(ignore
& WARN_FILENAME
))
859 if (!errors
&& !verbose
)
860 _cupsLangPuts(stdout
, _(" FAIL"));
862 _cupsLangPuts(stdout
,
863 _(" **FAIL** REQUIRED PCFileName\n"
864 " REF: Pages 61-62, section 5.3."));
870 if (ppd
->product
!= NULL
)
872 if (ppd
->product
[0] != '(' ||
873 ppd
->product
[strlen(ppd
->product
) - 1] != ')')
877 if (!errors
&& !verbose
)
878 _cupsLangPuts(stdout
, _(" FAIL"));
880 _cupsLangPuts(stdout
,
881 _(" **FAIL** BAD Product - not \"(string)\".\n"
882 " REF: Page 62, section 5.3."));
887 else if (verbose
> 0)
888 _cupsLangPuts(stdout
, _(" PASS Product"));
894 if (!errors
&& !verbose
)
895 _cupsLangPuts(stdout
, _(" FAIL"));
897 _cupsLangPuts(stdout
,
898 _(" **FAIL** REQUIRED Product\n"
899 " REF: Page 62, section 5.3."));
905 if ((attr
= ppdFindAttr(ppd
, "PSVersion", NULL
)) != NULL
&&
908 char junkstr
[255]; /* Temp string */
909 int junkint
; /* Temp integer */
912 if (sscanf(attr
->value
, "(%[^)])%d", junkstr
, &junkint
) != 2)
916 if (!errors
&& !verbose
)
917 _cupsLangPuts(stdout
, _(" FAIL"));
919 _cupsLangPuts(stdout
,
920 _(" **FAIL** BAD PSVersion - not \"(string) "
922 " REF: Pages 62-64, section 5.3."));
927 else if (verbose
> 0)
928 _cupsLangPuts(stdout
, _(" PASS PSVersion"));
934 if (!errors
&& !verbose
)
935 _cupsLangPuts(stdout
, _(" FAIL"));
937 _cupsLangPuts(stdout
,
938 _(" **FAIL** REQUIRED PSVersion\n"
939 " REF: Pages 62-64, section 5.3."));
945 if (ppd
->shortnickname
!= NULL
)
947 if (strlen(ppd
->shortnickname
) > 31)
951 if (!errors
&& !verbose
)
952 _cupsLangPuts(stdout
, _(" FAIL"));
954 _cupsLangPuts(stdout
,
955 _(" **FAIL** BAD ShortNickName - longer "
957 " REF: Pages 64-65, section 5.3."));
962 else if (verbose
> 0)
963 _cupsLangPuts(stdout
, _(" PASS ShortNickName"));
965 else if (ppdversion
>= 43)
969 if (!errors
&& !verbose
)
970 _cupsLangPuts(stdout
, _(" FAIL"));
972 _cupsLangPuts(stdout
,
973 _(" **FAIL** REQUIRED ShortNickName\n"
974 " REF: Page 64-65, section 5.3."));
980 if (ppd
->patches
!= NULL
&& strchr(ppd
->patches
, '\"') &&
981 strstr(ppd
->patches
, "*End"))
985 if (!errors
&& !verbose
)
986 _cupsLangPuts(stdout
, _(" FAIL"));
988 _cupsLangPuts(stdout
,
989 _(" **FAIL** BAD JobPatchFile attribute in file\n"
990 " REF: Page 24, section 3.4."));
997 * Check for page sizes without the corresponding ImageableArea or
998 * PaperDimension values...
1001 if (ppd
->num_sizes
== 0)
1005 if (!errors
&& !verbose
)
1006 _cupsLangPuts(stdout
, _(" FAIL"));
1008 _cupsLangPuts(stdout
,
1009 _(" **FAIL** REQUIRED PageSize\n"
1010 " REF: Page 41, section 5.\n"
1011 " REF: Page 99, section 5.14."));
1018 for (j
= 0, size
= ppd
->sizes
; j
< ppd
->num_sizes
; j
++, size
++)
1021 * Don't check custom size...
1024 if (!strcmp(size
->name
, "Custom"))
1028 * Check for ImageableArea...
1031 if (size
->left
== 0.0 && size
->bottom
== 0.0 &&
1032 size
->right
== 0.0 && size
->top
== 0.0)
1036 if (!errors
&& !verbose
)
1037 _cupsLangPuts(stdout
, _(" FAIL"));
1039 _cupsLangPrintf(stdout
,
1040 _(" **FAIL** REQUIRED ImageableArea for "
1042 " REF: Page 41, section 5.\n"
1043 " REF: Page 102, section 5.15."),
1051 * Check for PaperDimension...
1054 if (size
->width
== 0.0 && size
->length
== 0.0)
1058 if (!errors
&& !verbose
)
1059 _cupsLangPuts(stdout
, _(" FAIL"));
1061 _cupsLangPrintf(stdout
,
1062 _(" **FAIL** REQUIRED PaperDimension "
1064 " REF: Page 41, section 5.\n"
1065 " REF: Page 103, section 5.15."),
1075 * Check for valid Resolution, JCLResolution, or SetResolution values...
1078 if ((option
= ppdFindOption(ppd
, "Resolution")) == NULL
)
1079 if ((option
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
1080 option
= ppdFindOption(ppd
, "SetResolution");
1084 for (j
= option
->num_choices
, choice
= option
->choices
;
1089 * Verify that all resolution options are of the form NNNdpi
1093 xdpi
= strtol(choice
->choice
, (char **)&ptr
, 10);
1094 if (ptr
> choice
->choice
&& xdpi
> 0)
1097 ydpi
= strtol(ptr
+ 1, (char **)&ptr
, 10);
1104 if (xdpi
<= 0 || xdpi
> 99999 || ydpi
<= 0 || ydpi
> 99999 ||
1109 if (!errors
&& !verbose
)
1110 _cupsLangPuts(stdout
, _(" FAIL"));
1112 _cupsLangPrintf(stdout
,
1113 _(" **FAIL** Bad %s choice %s\n"
1114 " REF: Page 84, section 5.9"),
1115 option
->keyword
, choice
->choice
);
1123 if ((attr
= ppdFindAttr(ppd
, "1284DeviceID", NULL
)) &&
1124 strcmp(attr
->name
, "1284DeviceID"))
1128 if (!errors
&& !verbose
)
1129 _cupsLangPuts(stdout
, _(" FAIL"));
1131 _cupsLangPrintf(stdout
,
1132 _(" **FAIL** %s must be 1284DeviceID\n"
1133 " REF: Page 72, section 5.5"),
1140 errors
= check_case(ppd
, errors
, verbose
);
1142 if (!(warn
& WARN_CONSTRAINTS
))
1143 errors
= check_constraints(ppd
, errors
, verbose
, 0);
1145 if (!(warn
& WARN_FILTERS
) && !(ignore
& WARN_FILTERS
))
1146 errors
= check_filters(ppd
, root
, errors
, verbose
, 0);
1148 if (!(warn
& WARN_PROFILES
) && !(ignore
& WARN_PROFILES
))
1149 errors
= check_profiles(ppd
, root
, errors
, verbose
, 0);
1151 if (!(warn
& WARN_SIZES
))
1152 errors
= check_sizes(ppd
, errors
, verbose
, 0);
1154 if (!(warn
& WARN_TRANSLATIONS
))
1155 errors
= check_translations(ppd
, errors
, verbose
, 0);
1157 if (!(warn
& WARN_DUPLEX
))
1158 errors
= check_duplex(ppd
, errors
, verbose
, 0);
1160 if ((attr
= ppdFindAttr(ppd
, "cupsLanguages", NULL
)) != NULL
&&
1164 * This file contains localizations, check for conformance of the
1165 * base translation...
1168 if ((attr
= ppdFindAttr(ppd
, "LanguageEncoding", NULL
)) != NULL
)
1170 if (!attr
->value
|| strcmp(attr
->value
, "ISOLatin1"))
1172 if (!errors
&& !verbose
)
1173 _cupsLangPuts(stdout
, _(" FAIL"));
1176 _cupsLangPrintf(stdout
,
1177 _(" **FAIL** Bad LanguageEncoding %s - "
1178 "must be ISOLatin1."),
1179 attr
->value
? attr
->value
: "(null)");
1184 if (!ppd
->lang_version
|| strcmp(ppd
->lang_version
, "English"))
1186 if (!errors
&& !verbose
)
1187 _cupsLangPuts(stdout
, _(" FAIL"));
1190 _cupsLangPrintf(stdout
,
1191 _(" **FAIL** Bad LanguageVersion %s - "
1192 "must be English."),
1193 ppd
->lang_version
? ppd
->lang_version
: "(null)");
1199 * Loop through all options and choices...
1202 for (option
= ppdFirstOption(ppd
);
1204 option
= ppdNextOption(ppd
))
1207 * Check for special characters outside A0 to BF, F7, or F8
1208 * that are used for languages other than English.
1211 for (ptr
= option
->text
; *ptr
; ptr
++)
1212 if ((*ptr
& 0x80) && (*ptr
& 0xe0) != 0xa0 &&
1213 (*ptr
& 0xff) != 0xf7 && (*ptr
& 0xff) != 0xf8)
1218 if (!errors
&& !verbose
)
1219 _cupsLangPuts(stdout
, _(" FAIL"));
1222 _cupsLangPrintf(stdout
,
1223 _(" **FAIL** Default translation "
1224 "string for option %s contains 8-bit "
1231 for (j
= 0; j
< option
->num_choices
; j
++)
1234 * Check for special characters outside A0 to BF, F7, or F8
1235 * that are used for languages other than English.
1238 for (ptr
= option
->choices
[j
].text
; *ptr
; ptr
++)
1239 if ((*ptr
& 0x80) && (*ptr
& 0xe0) != 0xa0 &&
1240 (*ptr
& 0xff) != 0xf7 && (*ptr
& 0xff) != 0xf8)
1245 if (!errors
&& !verbose
)
1246 _cupsLangPuts(stdout
, _(" FAIL"));
1249 _cupsLangPrintf(stdout
,
1250 _(" **FAIL** Default translation "
1251 "string for option %s choice %s contains "
1252 "8-bit characters."),
1254 option
->choices
[j
].choice
);
1264 * Final pass/fail notification...
1268 status
= ERROR_CONFORMANCE
;
1270 _cupsLangPuts(stdout
, _(" PASS"));
1274 check_basics(argv
[i
]);
1276 if (warn
& WARN_DEFAULTS
)
1277 errors
= check_defaults(ppd
, errors
, verbose
, 1);
1279 if (warn
& WARN_CONSTRAINTS
)
1280 errors
= check_constraints(ppd
, errors
, verbose
, 1);
1282 if ((warn
& WARN_FILTERS
) && !(ignore
& WARN_FILTERS
))
1283 errors
= check_filters(ppd
, root
, errors
, verbose
, 1);
1285 if ((warn
& WARN_PROFILES
) && !(ignore
& WARN_PROFILES
))
1286 errors
= check_profiles(ppd
, root
, errors
, verbose
, 1);
1288 if (warn
& WARN_SIZES
)
1289 errors
= check_sizes(ppd
, errors
, verbose
, 1);
1291 errors
= check_sizes(ppd
, errors
, verbose
, 2);
1293 if (warn
& WARN_TRANSLATIONS
)
1294 errors
= check_translations(ppd
, errors
, verbose
, 1);
1296 if (warn
& WARN_DUPLEX
)
1297 errors
= check_duplex(ppd
, errors
, verbose
, 1);
1300 * Look for legacy duplex keywords...
1303 if ((option
= ppdFindOption(ppd
, "JCLDuplex")) == NULL
)
1304 if ((option
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
1305 option
= ppdFindOption(ppd
, "KD03Duplex");
1308 _cupsLangPrintf(stdout
,
1309 _(" WARN Duplex option keyword %s may not "
1310 "work as expected and should be named Duplex.\n"
1311 " REF: Page 122, section 5.17"),
1315 * Look for default keywords with no corresponding option...
1318 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1320 attr
= ppd
->attrs
[j
];
1322 if (!strcmp(attr
->name
, "DefaultColorSpace") ||
1323 !strcmp(attr
->name
, "DefaultColorSep") ||
1324 !strcmp(attr
->name
, "DefaultFont") ||
1325 !strcmp(attr
->name
, "DefaultHalftoneType") ||
1326 !strcmp(attr
->name
, "DefaultImageableArea") ||
1327 !strcmp(attr
->name
, "DefaultLeadingEdge") ||
1328 !strcmp(attr
->name
, "DefaultOutputOrder") ||
1329 !strcmp(attr
->name
, "DefaultPaperDimension") ||
1330 !strcmp(attr
->name
, "DefaultResolution") ||
1331 !strcmp(attr
->name
, "DefaultScreenProc") ||
1332 !strcmp(attr
->name
, "DefaultTransfer"))
1335 if (!strncmp(attr
->name
, "Default", 7) &&
1336 !ppdFindOption(ppd
, attr
->name
+ 7))
1337 _cupsLangPrintf(stdout
,
1338 _(" WARN %s has no corresponding "
1343 ppdMarkDefaults(ppd
);
1344 if (ppdConflicts(ppd
))
1346 _cupsLangPuts(stdout
,
1347 _(" WARN Default choices conflicting."));
1349 show_conflicts(ppd
);
1352 if (ppdversion
< 43)
1354 _cupsLangPrintf(stdout
,
1355 _(" WARN Obsolete PPD version %.1f.\n"
1356 " REF: Page 42, section 5.2."),
1360 if (!ppd
->lang_encoding
&& ppdversion
< 41)
1362 _cupsLangPuts(stdout
,
1363 _(" WARN LanguageEncoding required by PPD "
1365 " REF: Pages 56-57, section 5.3."));
1368 if (!ppd
->manufacturer
&& ppdversion
< 43)
1370 _cupsLangPuts(stdout
,
1371 _(" WARN Manufacturer required by PPD "
1373 " REF: Pages 58-59, section 5.3."));
1377 * Treat a PCFileName attribute longer than 12 characters as
1378 * a warning and not a hard error...
1381 if (!(ignore
& WARN_FILENAME
) && ppd
->pcfilename
)
1383 if (strlen(ppd
->pcfilename
) > 12)
1385 _cupsLangPuts(stdout
,
1386 _(" WARN PCFileName longer than 8.3 in "
1387 "violation of PPD spec.\n"
1388 " REF: Pages 61-62, section "
1392 if (!strcasecmp(ppd
->pcfilename
, "unused.ppd"))
1393 _cupsLangPuts(stdout
,
1394 _(" WARN PCFileName should contain a "
1395 "unique filename.\n"
1396 " REF: Pages 61-62, section "
1400 if (!ppd
->shortnickname
&& ppdversion
< 43)
1402 _cupsLangPuts(stdout
,
1403 _(" WARN ShortNickName required by PPD "
1405 " REF: Pages 64-65, section 5.3."));
1409 * Check the Protocols line and flag PJL + BCP since TBCP is
1410 * usually used with PJL...
1415 if (strstr(ppd
->protocols
, "PJL") &&
1416 strstr(ppd
->protocols
, "BCP") &&
1417 !strstr(ppd
->protocols
, "TBCP"))
1419 _cupsLangPuts(stdout
,
1420 _(" WARN Protocols contains both PJL "
1421 "and BCP; expected TBCP.\n"
1422 " REF: Pages 78-79, section 5.7."));
1425 if (strstr(ppd
->protocols
, "PJL") &&
1426 (!ppd
->jcl_begin
|| !ppd
->jcl_end
|| !ppd
->jcl_ps
))
1428 _cupsLangPuts(stdout
,
1429 _(" WARN Protocols contains PJL but JCL "
1430 "attributes are not set.\n"
1431 " REF: Pages 78-79, section 5.7."));
1436 * Check for options with a common prefix, e.g. Duplex and Duplexer,
1437 * which are errors according to the spec but won't cause problems
1438 * with CUPS specifically...
1441 for (j
= 0, group
= ppd
->groups
; j
< ppd
->num_groups
; j
++, group
++)
1442 for (k
= 0, option
= group
->options
;
1443 k
< group
->num_options
;
1446 len
= (int)strlen(option
->keyword
);
1448 for (m
= 0, group2
= ppd
->groups
;
1449 m
< ppd
->num_groups
;
1451 for (n
= 0, option2
= group2
->options
;
1452 n
< group2
->num_options
;
1454 if (option
!= option2
&&
1455 len
< (int)strlen(option2
->keyword
) &&
1456 !strncmp(option
->keyword
, option2
->keyword
, len
))
1458 _cupsLangPrintf(stdout
,
1459 _(" WARN %s shares a common "
1461 " REF: Page 15, section "
1463 option
->keyword
, option2
->keyword
);
1471 _cupsLangPrintf(stdout
, _(" %d ERRORS FOUND"), errors
);
1473 _cupsLangPuts(stdout
, _(" NO ERRORS FOUND"));
1477 * Then list the options, if "-v" was provided...
1482 _cupsLangPrintf(stdout
,
1484 " language_level = %d\n"
1485 " color_device = %s\n"
1486 " variable_sizes = %s\n"
1488 ppd
->language_level
,
1489 ppd
->color_device
? "TRUE" : "FALSE",
1490 ppd
->variable_sizes
? "TRUE" : "FALSE",
1493 switch (ppd
->colorspace
)
1496 _cupsLangPuts(stdout
, " colorspace = PPD_CS_CMYK");
1499 _cupsLangPuts(stdout
, " colorspace = PPD_CS_CMY");
1502 _cupsLangPuts(stdout
, " colorspace = PPD_CS_GRAY");
1505 _cupsLangPuts(stdout
, " colorspace = PPD_CS_RGB");
1508 _cupsLangPuts(stdout
, " colorspace = <unknown>");
1512 _cupsLangPrintf(stdout
, " num_emulations = %d",
1513 ppd
->num_emulations
);
1514 for (j
= 0; j
< ppd
->num_emulations
; j
++)
1515 _cupsLangPrintf(stdout
, " emulations[%d] = %s",
1516 j
, ppd
->emulations
[j
].name
);
1518 _cupsLangPrintf(stdout
, " lang_encoding = %s",
1519 ppd
->lang_encoding
);
1520 _cupsLangPrintf(stdout
, " lang_version = %s",
1522 _cupsLangPrintf(stdout
, " modelname = %s", ppd
->modelname
);
1523 _cupsLangPrintf(stdout
, " ttrasterizer = %s",
1524 ppd
->ttrasterizer
== NULL
? "None" : ppd
->ttrasterizer
);
1525 _cupsLangPrintf(stdout
, " manufacturer = %s",
1527 _cupsLangPrintf(stdout
, " product = %s", ppd
->product
);
1528 _cupsLangPrintf(stdout
, " nickname = %s", ppd
->nickname
);
1529 _cupsLangPrintf(stdout
, " shortnickname = %s",
1530 ppd
->shortnickname
);
1531 _cupsLangPrintf(stdout
, " patches = %d bytes",
1532 ppd
->patches
== NULL
? 0 : (int)strlen(ppd
->patches
));
1534 _cupsLangPrintf(stdout
, " num_groups = %d", ppd
->num_groups
);
1535 for (j
= 0, group
= ppd
->groups
; j
< ppd
->num_groups
; j
++, group
++)
1537 _cupsLangPrintf(stdout
, " group[%d] = %s",
1540 for (k
= 0, option
= group
->options
; k
< group
->num_options
; k
++, option
++)
1542 _cupsLangPrintf(stdout
,
1543 " options[%d] = %s (%s) %s %s %.0f "
1545 k
, option
->keyword
, option
->text
, uis
[option
->ui
],
1546 sections
[option
->section
], option
->order
,
1547 option
->num_choices
);
1549 if (!strcmp(option
->keyword
, "PageSize") ||
1550 !strcmp(option
->keyword
, "PageRegion"))
1552 for (m
= option
->num_choices
, choice
= option
->choices
;
1556 size
= ppdPageSize(ppd
, choice
->choice
);
1559 _cupsLangPrintf(stdout
,
1560 " %s (%s) = ERROR%s",
1561 choice
->choice
, choice
->text
,
1562 !strcmp(option
->defchoice
, choice
->choice
)
1565 _cupsLangPrintf(stdout
,
1566 " %s (%s) = %.2fx%.2fin "
1567 "(%.1f,%.1f,%.1f,%.1f)%s",
1568 choice
->choice
, choice
->text
,
1569 size
->width
/ 72.0, size
->length
/ 72.0,
1570 size
->left
/ 72.0, size
->bottom
/ 72.0,
1571 size
->right
/ 72.0, size
->top
/ 72.0,
1572 !strcmp(option
->defchoice
, choice
->choice
)
1578 for (m
= option
->num_choices
, choice
= option
->choices
;
1582 _cupsLangPrintf(stdout
, " %s (%s)%s",
1583 choice
->choice
, choice
->text
,
1584 !strcmp(option
->defchoice
, choice
->choice
)
1591 _cupsLangPrintf(stdout
, " num_consts = %d",
1593 for (j
= 0; j
< ppd
->num_consts
; j
++)
1594 _cupsLangPrintf(stdout
,
1595 " consts[%d] = *%s %s *%s %s",
1596 j
, ppd
->consts
[j
].option1
, ppd
->consts
[j
].choice1
,
1597 ppd
->consts
[j
].option2
, ppd
->consts
[j
].choice2
);
1599 _cupsLangPrintf(stdout
, " num_profiles = %d",
1601 for (j
= 0; j
< ppd
->num_profiles
; j
++)
1602 _cupsLangPrintf(stdout
,
1603 " profiles[%d] = %s/%s %.3f %.3f "
1604 "[ %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f ]",
1605 j
, ppd
->profiles
[j
].resolution
,
1606 ppd
->profiles
[j
].media_type
,
1607 ppd
->profiles
[j
].gamma
, ppd
->profiles
[j
].density
,
1608 ppd
->profiles
[j
].matrix
[0][0],
1609 ppd
->profiles
[j
].matrix
[0][1],
1610 ppd
->profiles
[j
].matrix
[0][2],
1611 ppd
->profiles
[j
].matrix
[1][0],
1612 ppd
->profiles
[j
].matrix
[1][1],
1613 ppd
->profiles
[j
].matrix
[1][2],
1614 ppd
->profiles
[j
].matrix
[2][0],
1615 ppd
->profiles
[j
].matrix
[2][1],
1616 ppd
->profiles
[j
].matrix
[2][2]);
1618 _cupsLangPrintf(stdout
, " num_fonts = %d", ppd
->num_fonts
);
1619 for (j
= 0; j
< ppd
->num_fonts
; j
++)
1620 _cupsLangPrintf(stdout
, " fonts[%d] = %s",
1623 _cupsLangPrintf(stdout
, " num_attrs = %d", ppd
->num_attrs
);
1624 for (j
= 0; j
< ppd
->num_attrs
; j
++)
1625 _cupsLangPrintf(stdout
,
1626 " attrs[%d] = %s %s%s%s: \"%s\"", j
,
1627 ppd
->attrs
[j
]->name
, ppd
->attrs
[j
]->spec
,
1628 ppd
->attrs
[j
]->text
[0] ? "/" : "",
1629 ppd
->attrs
[j
]->text
,
1630 ppd
->attrs
[j
]->value
?
1631 ppd
->attrs
[j
]->value
: "(null)");
1645 * 'check_basics()' - Check for CR LF, mixed line endings, and blank lines.
1649 check_basics(const char *filename
) /* I - PPD file to check */
1651 cups_file_t
*fp
; /* File pointer */
1652 int ch
; /* Current character */
1653 int col
, /* Current column */
1654 whitespace
; /* Only seen whitespace? */
1655 int eol
; /* Line endings */
1656 int linenum
; /* Line number */
1657 int mixed
; /* Mixed line endings? */
1660 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
1669 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
1671 if (ch
== '\r' || ch
== '\n')
1675 if (eol
== EOL_NONE
)
1677 else if (eol
!= EOL_LF
)
1680 else if (ch
== '\r')
1682 if (cupsFilePeekChar(fp
) == '\n')
1684 cupsFileGetChar(fp
);
1686 if (eol
== EOL_NONE
)
1688 else if (eol
!= EOL_CRLF
)
1691 else if (eol
== EOL_NONE
)
1693 else if (eol
!= EOL_CR
)
1697 if (col
> 0 && whitespace
)
1698 _cupsLangPrintf(stdout
,
1699 _(" WARN Line %d only contains whitespace."),
1708 if (ch
!= ' ' && ch
!= '\t')
1716 _cupsLangPuts(stdout
,
1717 _(" WARN File contains a mix of CR, LF, and "
1718 "CR LF line endings."));
1720 if (eol
== EOL_CRLF
)
1721 _cupsLangPuts(stdout
,
1722 _(" WARN Non-Windows PPD files should use lines "
1723 "ending with only LF, not CR LF."));
1730 * 'check_constraints()' - Check UIConstraints in the PPD file.
1733 static int /* O - Errors found */
1734 check_constraints(ppd_file_t
*ppd
, /* I - PPD file */
1735 int errors
, /* I - Errors found */
1736 int verbose
, /* I - Verbosity level */
1737 int warn
) /* I - Warnings only? */
1739 int i
; /* Looping var */
1740 const char *prefix
; /* WARN/FAIL prefix */
1741 ppd_const_t
*c
; /* Current UIConstraints data */
1742 ppd_attr_t
*constattr
; /* Current cupsUIConstraints attribute */
1743 const char *vptr
; /* Pointer into constraint value */
1744 char option
[PPD_MAX_NAME
],
1745 /* Option name/MainKeyword */
1746 choice
[PPD_MAX_NAME
],
1747 /* Choice/OptionKeyword */
1748 *ptr
; /* Pointer into option or choice */
1749 int num_options
; /* Number of options */
1750 cups_option_t
*options
; /* Options */
1751 ppd_option_t
*o
; /* PPD option */
1754 prefix
= warn
? " WARN " : "**FAIL**";
1758 * See what kind of constraint data we have in the PPD...
1761 if ((constattr
= ppdFindAttr(ppd
, "cupsUIConstraints", NULL
)) != NULL
)
1764 * Check new-style cupsUIConstraints data...
1768 constattr
= ppdFindNextAttr(ppd
, "cupsUIConstraints", NULL
))
1770 if (!constattr
->value
)
1772 if (!warn
&& !errors
&& !verbose
)
1773 _cupsLangPuts(stdout
, _(" FAIL"));
1775 _cupsLangPrintf(stdout
,
1776 _(" %s Empty cupsUIConstraints %s"),
1777 prefix
, constattr
->spec
);
1785 for (i
= 0, vptr
= strchr(constattr
->value
, '*');
1787 i
++, vptr
= strchr(vptr
+ 1, '*'));
1791 if (!warn
&& !errors
&& !verbose
)
1792 _cupsLangPuts(stdout
, _(" FAIL"));
1794 _cupsLangPrintf(stdout
,
1795 _(" %s Bad cupsUIConstraints %s: \"%s\""),
1796 prefix
, constattr
->spec
, constattr
->value
);
1804 cupsArraySave(ppd
->sorted_attrs
);
1806 if (constattr
->spec
[0] &&
1807 !ppdFindAttr(ppd
, "cupsUIResolver", constattr
->spec
))
1809 if (!warn
&& !errors
&& !verbose
)
1810 _cupsLangPuts(stdout
, _(" FAIL"));
1812 _cupsLangPrintf(stdout
,
1813 _(" %s Missing cupsUIResolver %s"),
1814 prefix
, constattr
->spec
);
1820 cupsArrayRestore(ppd
->sorted_attrs
);
1825 for (vptr
= strchr(constattr
->value
, '*');
1827 vptr
= strchr(vptr
, '*'))
1830 * Extract "*Option Choice" or just "*Option"...
1833 for (vptr
++, ptr
= option
; *vptr
&& !isspace(*vptr
& 255); vptr
++)
1834 if (ptr
< (option
+ sizeof(option
) - 1))
1839 while (isspace(*vptr
& 255))
1846 for (ptr
= choice
; *vptr
&& !isspace(*vptr
& 255); vptr
++)
1847 if (ptr
< (choice
+ sizeof(choice
) - 1))
1853 if (!strncasecmp(option
, "Custom", 6) && !strcasecmp(choice
, "True"))
1855 _cups_strcpy(option
, option
+ 6);
1856 strcpy(choice
, "Custom");
1859 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
1861 if (!warn
&& !errors
&& !verbose
)
1862 _cupsLangPuts(stdout
, _(" FAIL"));
1864 _cupsLangPrintf(stdout
,
1865 _(" %s Missing option %s in "
1866 "cupsUIConstraints %s: \"%s\""),
1867 prefix
, option
, constattr
->spec
, constattr
->value
);
1875 if (choice
[0] && !ppdFindChoice(o
, choice
))
1877 if (!warn
&& !errors
&& !verbose
)
1878 _cupsLangPuts(stdout
, _(" FAIL"));
1880 _cupsLangPrintf(stdout
,
1881 _(" %s Missing choice *%s %s in "
1882 "cupsUIConstraints %s: \"%s\""),
1883 prefix
, option
, choice
, constattr
->spec
,
1893 num_options
= cupsAddOption(option
, choice
, num_options
, &options
);
1896 for (i
= 0; i
< o
->num_choices
; i
++)
1897 if (strcasecmp(o
->choices
[i
].choice
, "None") &&
1898 strcasecmp(o
->choices
[i
].choice
, "Off") &&
1899 strcasecmp(o
->choices
[i
].choice
, "False"))
1901 num_options
= cupsAddOption(option
, o
->choices
[i
].choice
,
1902 num_options
, &options
);
1909 * Resolvers must list at least two options...
1912 if (num_options
< 2)
1914 if (!warn
&& !errors
&& !verbose
)
1915 _cupsLangPuts(stdout
, _(" FAIL"));
1917 _cupsLangPrintf(stdout
,
1918 _(" %s cupsUIResolver %s does not list at least "
1919 "two different options."),
1920 prefix
, constattr
->spec
);
1927 * Test the resolver...
1930 if (!cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
))
1932 if (!warn
&& !errors
&& !verbose
)
1933 _cupsLangPuts(stdout
, _(" FAIL"));
1935 _cupsLangPrintf(stdout
,
1936 _(" %s cupsUIResolver %s causes a loop."),
1937 prefix
, constattr
->spec
);
1943 cupsFreeOptions(num_options
, options
);
1949 * Check old-style [Non]UIConstraints data...
1952 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
1954 if (!strncasecmp(c
->option1
, "Custom", 6) &&
1955 !strcasecmp(c
->choice1
, "True"))
1957 strcpy(option
, c
->option1
+ 6);
1958 strcpy(choice
, "Custom");
1962 strcpy(option
, c
->option1
);
1963 strcpy(choice
, c
->choice1
);
1966 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
1968 if (!warn
&& !errors
&& !verbose
)
1969 _cupsLangPuts(stdout
, _(" FAIL"));
1971 _cupsLangPrintf(stdout
,
1972 _(" %s Missing option %s in "
1973 "UIConstraints \"*%s %s *%s %s\"."),
1975 c
->option1
, c
->choice1
, c
->option2
, c
->choice2
);
1980 else if (choice
[0] && !ppdFindChoice(o
, choice
))
1982 if (!warn
&& !errors
&& !verbose
)
1983 _cupsLangPuts(stdout
, _(" FAIL"));
1985 _cupsLangPrintf(stdout
,
1986 _(" %s Missing choice *%s %s in "
1987 "UIConstraints \"*%s %s *%s %s\"."),
1988 prefix
, c
->option1
, c
->choice1
,
1989 c
->option1
, c
->choice1
, c
->option2
, c
->choice2
);
1995 if (!strncasecmp(c
->option2
, "Custom", 6) &&
1996 !strcasecmp(c
->choice2
, "True"))
1998 strcpy(option
, c
->option2
+ 6);
1999 strcpy(choice
, "Custom");
2003 strcpy(option
, c
->option2
);
2004 strcpy(choice
, c
->choice2
);
2007 if ((o
= ppdFindOption(ppd
, option
)) == NULL
)
2009 if (!warn
&& !errors
&& !verbose
)
2010 _cupsLangPuts(stdout
, _(" FAIL"));
2012 _cupsLangPrintf(stdout
,
2013 _(" %s Missing option %s in "
2014 "UIConstraints \"*%s %s *%s %s\"."),
2016 c
->option1
, c
->choice1
, c
->option2
, c
->choice2
);
2021 else if (choice
[0] && !ppdFindChoice(o
, choice
))
2023 if (!warn
&& !errors
&& !verbose
)
2024 _cupsLangPuts(stdout
, _(" FAIL"));
2026 _cupsLangPrintf(stdout
,
2027 _(" %s Missing choice *%s %s in "
2028 "UIConstraints \"*%s %s *%s %s\"."),
2029 prefix
, c
->option2
, c
->choice2
,
2030 c
->option1
, c
->choice1
, c
->option2
, c
->choice2
);
2043 * 'check_case()' - Check that there are no duplicate groups, options,
2044 * or choices that differ only by case.
2047 static int /* O - Errors found */
2048 check_case(ppd_file_t
*ppd
, /* I - PPD file */
2049 int errors
, /* I - Errors found */
2050 int verbose
) /* I - Verbosity level */
2052 int i
, j
; /* Looping vars */
2053 ppd_group_t
*groupa
, /* First group */
2054 *groupb
; /* Second group */
2055 ppd_option_t
*optiona
, /* First option */
2056 *optionb
; /* Second option */
2057 ppd_choice_t
*choicea
, /* First choice */
2058 *choiceb
; /* Second choice */
2062 * Check that the groups do not have any duplicate names...
2065 for (i
= ppd
->num_groups
, groupa
= ppd
->groups
; i
> 1; i
--, groupa
++)
2066 for (j
= i
- 1, groupb
= groupa
+ 1; j
> 0; j
--, groupb
++)
2067 if (!strcasecmp(groupa
->name
, groupb
->name
))
2069 if (!errors
&& !verbose
)
2070 _cupsLangPuts(stdout
, _(" FAIL"));
2073 _cupsLangPrintf(stdout
,
2074 _(" **FAIL** Group names %s and %s differ only "
2076 groupa
->name
, groupb
->name
);
2082 * Check that the options do not have any duplicate names...
2085 for (optiona
= ppdFirstOption(ppd
); optiona
; optiona
= ppdNextOption(ppd
))
2087 cupsArraySave(ppd
->options
);
2088 for (optionb
= ppdNextOption(ppd
); optionb
; optionb
= ppdNextOption(ppd
))
2089 if (!strcasecmp(optiona
->keyword
, optionb
->keyword
))
2091 if (!errors
&& !verbose
)
2092 _cupsLangPuts(stdout
, _(" FAIL"));
2095 _cupsLangPrintf(stdout
,
2096 _(" **FAIL** Option names %s and %s differ only "
2098 optiona
->keyword
, optionb
->keyword
);
2102 cupsArrayRestore(ppd
->options
);
2105 * Then the choices...
2108 for (i
= optiona
->num_choices
, choicea
= optiona
->choices
;
2111 for (j
= i
- 1, choiceb
= choicea
+ 1; j
> 0; j
--, choiceb
++)
2112 if (!strcmp(choicea
->choice
, choiceb
->choice
))
2114 if (!errors
&& !verbose
)
2115 _cupsLangPuts(stdout
, _(" FAIL"));
2118 _cupsLangPrintf(stdout
,
2119 _(" **FAIL** Multiple occurrences of %s "
2121 optiona
->keyword
, choicea
->choice
);
2129 else if (!strcasecmp(choicea
->choice
, choiceb
->choice
))
2131 if (!errors
&& !verbose
)
2132 _cupsLangPuts(stdout
, _(" FAIL"));
2135 _cupsLangPrintf(stdout
,
2136 _(" **FAIL** %s choice names %s and %s "
2137 "differ only by case."),
2138 optiona
->keyword
, choicea
->choice
, choiceb
->choice
);
2145 * Return the number of errors found...
2153 * 'check_defaults()' - Check default option keywords in the PPD file.
2156 static int /* O - Errors found */
2157 check_defaults(ppd_file_t
*ppd
, /* I - PPD file */
2158 int errors
, /* I - Errors found */
2159 int verbose
, /* I - Verbosity level */
2160 int warn
) /* I - Warnings only? */
2162 int j
, k
; /* Looping vars */
2163 ppd_attr_t
*attr
; /* PPD attribute */
2164 ppd_option_t
*option
; /* Standard UI option */
2165 const char *prefix
; /* WARN/FAIL prefix */
2168 prefix
= warn
? " WARN " : "**FAIL**";
2170 for (j
= 0; j
< ppd
->num_attrs
; j
++)
2172 attr
= ppd
->attrs
[j
];
2174 if (!strcmp(attr
->name
, "DefaultColorSpace") ||
2175 !strcmp(attr
->name
, "DefaultFont") ||
2176 !strcmp(attr
->name
, "DefaultHalftoneType") ||
2177 !strcmp(attr
->name
, "DefaultImageableArea") ||
2178 !strcmp(attr
->name
, "DefaultLeadingEdge") ||
2179 !strcmp(attr
->name
, "DefaultOutputOrder") ||
2180 !strcmp(attr
->name
, "DefaultPaperDimension") ||
2181 !strcmp(attr
->name
, "DefaultResolution") ||
2182 !strcmp(attr
->name
, "DefaultTransfer"))
2185 if (!strncmp(attr
->name
, "Default", 7))
2187 if ((option
= ppdFindOption(ppd
, attr
->name
+ 7)) != NULL
&&
2188 strcmp(attr
->value
, "Unknown"))
2191 * Check that the default option value matches a choice...
2194 for (k
= 0; k
< option
->num_choices
; k
++)
2195 if (!strcmp(option
->choices
[k
].choice
, attr
->value
))
2198 if (k
>= option
->num_choices
)
2200 if (!warn
&& !errors
&& !verbose
)
2201 _cupsLangPuts(stdout
, _(" FAIL"));
2204 _cupsLangPrintf(stdout
,
2205 _(" %s %s %s does not exist."),
2206 prefix
, attr
->name
, attr
->value
);
2220 * 'check_duplex()' - Check duplex keywords in the PPD file.
2223 static int /* O - Errors found */
2224 check_duplex(ppd_file_t
*ppd
, /* I - PPD file */
2225 int errors
, /* I - Error found */
2226 int verbose
, /* I - Verbosity level */
2227 int warn
) /* I - Warnings only? */
2229 int i
; /* Looping var */
2230 ppd_option_t
*option
; /* PPD option */
2231 ppd_choice_t
*choice
; /* Current choice */
2232 const char *prefix
; /* Message prefix */
2235 prefix
= warn
? " WARN " : "**FAIL**";
2238 * Check for a duplex option, and for standard values...
2241 if ((option
= ppdFindOption(ppd
, "Duplex")) != NULL
)
2243 if (!ppdFindChoice(option
, "None"))
2247 if (!warn
&& !errors
&& !verbose
)
2248 _cupsLangPuts(stdout
, _(" FAIL"));
2250 _cupsLangPrintf(stdout
,
2251 _(" %s REQUIRED %s does not define "
2253 " REF: Page 122, section 5.17"),
2254 prefix
, option
->keyword
);
2261 for (i
= option
->num_choices
, choice
= option
->choices
;
2264 if (strcmp(choice
->choice
, "None") &&
2265 strcmp(choice
->choice
, "DuplexNoTumble") &&
2266 strcmp(choice
->choice
, "DuplexTumble") &&
2267 strcmp(choice
->choice
, "SimplexTumble"))
2271 if (!warn
&& !errors
&& !verbose
)
2272 _cupsLangPuts(stdout
, _(" FAIL"));
2274 _cupsLangPrintf(stdout
,
2275 _(" %s Bad %s choice %s.\n"
2276 " REF: Page 122, section 5.17"),
2277 prefix
, option
->keyword
, choice
->choice
);
2290 * 'check_filters()' - Check filters in the PPD file.
2293 static int /* O - Errors found */
2294 check_filters(ppd_file_t
*ppd
, /* I - PPD file */
2295 const char *root
, /* I - Root directory */
2296 int errors
, /* I - Errors found */
2297 int verbose
, /* I - Verbosity level */
2298 int warn
) /* I - Warnings only? */
2300 int i
; /* Looping var */
2301 ppd_attr_t
*attr
; /* PPD attribute */
2302 const char *ptr
; /* Pointer into string */
2303 char super
[16], /* Super-type for filter */
2304 type
[256], /* Type for filter */
2305 program
[1024], /* Program/filter name */
2306 pathprog
[1024]; /* Complete path to program/filter */
2307 int cost
; /* Cost of filter */
2308 const char *prefix
; /* WARN/FAIL prefix */
2309 struct stat fileinfo
; /* File information */
2312 prefix
= warn
? " WARN " : "**FAIL**";
2318 for (i
= 0; i
< ppd
->num_filters
; i
++)
2320 if (sscanf(ppd
->filters
[i
], "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
,
2321 &cost
, program
) != 4)
2323 if (!warn
&& !errors
&& !verbose
)
2324 _cupsLangPuts(stdout
, _(" FAIL"));
2327 _cupsLangPrintf(stdout
,
2328 _(" %s Bad cupsFilter value \"%s\"."),
2329 prefix
, ppd
->filters
[i
]);
2334 else if (strcmp(program
, "-"))
2336 if (program
[0] == '/')
2337 snprintf(pathprog
, sizeof(pathprog
), "%s%s", root
, program
);
2340 if ((ptr
= getenv("CUPS_SERVERBIN")) == NULL
)
2341 ptr
= CUPS_SERVERBIN
;
2343 if (*ptr
== '/' || !*root
)
2344 snprintf(pathprog
, sizeof(pathprog
), "%s%s/filter/%s", root
, ptr
,
2347 snprintf(pathprog
, sizeof(pathprog
), "%s/%s/filter/%s", root
, ptr
,
2351 if (stat(pathprog
, &fileinfo
))
2353 if (!warn
&& !errors
&& !verbose
)
2354 _cupsLangPuts(stdout
, _(" FAIL"));
2357 _cupsLangPrintf(stdout
, _(" %s Missing %s file \"%s\"."),
2358 prefix
, "cupsFilter", pathprog
);
2363 else if (fileinfo
.st_uid
!= 0 ||
2364 (fileinfo
.st_mode
& MODE_WRITE
) ||
2365 (fileinfo
.st_mode
& MODE_MASK
) != MODE_PROGRAM
)
2367 if (!warn
&& !errors
&& !verbose
)
2368 _cupsLangPuts(stdout
, _(" FAIL"));
2371 _cupsLangPrintf(stdout
,
2372 _(" %s Bad permissions on %s file \"%s\"."),
2373 prefix
, "cupsFilter", pathprog
);
2379 errors
= valid_path("cupsFilter", pathprog
, errors
, verbose
, warn
);
2387 for (attr
= ppdFindAttr(ppd
, "cupsPreFilter", NULL
);
2389 attr
= ppdFindNextAttr(ppd
, "cupsPreFilter", NULL
))
2391 if (strcmp(attr
->name
, "cupsPreFilter"))
2393 if (!warn
&& !errors
&& !verbose
)
2394 _cupsLangPuts(stdout
, _(" FAIL"));
2397 _cupsLangPrintf(stdout
,
2398 _(" %s Bad spelling of %s - should be %s."),
2399 prefix
, attr
->name
, "cupsPreFilter");
2406 sscanf(attr
->value
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
,
2407 &cost
, program
) != 4)
2409 if (!warn
&& !errors
&& !verbose
)
2410 _cupsLangPuts(stdout
, _(" FAIL"));
2413 _cupsLangPrintf(stdout
,
2414 _(" %s Bad cupsPreFilter value \"%s\"."),
2415 prefix
, attr
->value
? attr
->value
: "");
2420 else if (strcmp(program
, "-"))
2422 if (program
[0] == '/')
2423 snprintf(pathprog
, sizeof(pathprog
), "%s%s", root
, program
);
2426 if ((ptr
= getenv("CUPS_SERVERBIN")) == NULL
)
2427 ptr
= CUPS_SERVERBIN
;
2429 if (*ptr
== '/' || !*root
)
2430 snprintf(pathprog
, sizeof(pathprog
), "%s%s/filter/%s", root
, ptr
,
2433 snprintf(pathprog
, sizeof(pathprog
), "%s/%s/filter/%s", root
, ptr
,
2437 if (stat(pathprog
, &fileinfo
))
2439 if (!warn
&& !errors
&& !verbose
)
2440 _cupsLangPuts(stdout
, _(" FAIL"));
2443 _cupsLangPrintf(stdout
, _(" %s Missing %s file \"%s\"."),
2444 prefix
, "cupsPreFilter", pathprog
);
2449 else if (fileinfo
.st_uid
!= 0 ||
2450 (fileinfo
.st_mode
& MODE_WRITE
) ||
2451 (fileinfo
.st_mode
& MODE_MASK
) != MODE_PROGRAM
)
2453 if (!warn
&& !errors
&& !verbose
)
2454 _cupsLangPuts(stdout
, _(" FAIL"));
2457 _cupsLangPrintf(stdout
,
2458 _(" %s Bad permissions on %s file \"%s\"."),
2459 prefix
, "cupsPreFilter", pathprog
);
2465 errors
= valid_path("cupsPreFilter", pathprog
, errors
, verbose
, warn
);
2474 for (attr
= ppdFindAttr(ppd
, "APDialogExtension", NULL
);
2476 attr
= ppdFindNextAttr(ppd
, "APDialogExtension", NULL
))
2478 if (strcmp(attr
->name
, "APDialogExtension"))
2480 if (!warn
&& !errors
&& !verbose
)
2481 _cupsLangPuts(stdout
, _(" FAIL"));
2484 _cupsLangPrintf(stdout
,
2485 _(" %s Bad spelling of %s - should be %s."),
2486 prefix
, attr
->name
, "APDialogExtension");
2492 snprintf(pathprog
, sizeof(pathprog
), "%s%s", root
,
2493 attr
->value
? attr
->value
: "(null)");
2495 if (!attr
->value
|| stat(pathprog
, &fileinfo
))
2497 if (!warn
&& !errors
&& !verbose
)
2498 _cupsLangPuts(stdout
, _(" FAIL"));
2501 _cupsLangPrintf(stdout
, _(" %s Missing %s file \"%s\"."),
2502 prefix
, "APDialogExtension", pathprog
);
2507 else if (fileinfo
.st_uid
!= 0 ||
2508 (fileinfo
.st_mode
& MODE_WRITE
) ||
2509 (fileinfo
.st_mode
& MODE_MASK
) != MODE_DIRECTORY
)
2511 if (!warn
&& !errors
&& !verbose
)
2512 _cupsLangPuts(stdout
, _(" FAIL"));
2515 _cupsLangPrintf(stdout
,
2516 _(" %s Bad permissions on %s file \"%s\"."),
2517 prefix
, "APDialogExtension", pathprog
);
2523 errors
= valid_path("APDialogExtension", pathprog
, errors
, verbose
,
2531 if ((attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
)
2533 if (strcmp(attr
->name
, "APPrinterIconPath"))
2535 if (!warn
&& !errors
&& !verbose
)
2536 _cupsLangPuts(stdout
, _(" FAIL"));
2539 _cupsLangPrintf(stdout
,
2540 _(" %s Bad spelling of %s - should be %s."),
2541 prefix
, attr
->name
, "APPrinterIconPath");
2547 snprintf(pathprog
, sizeof(pathprog
), "%s%s", root
,
2548 attr
->value
? attr
->value
: "(null)");
2550 if (!attr
->value
|| stat(pathprog
, &fileinfo
))
2552 if (!warn
&& !errors
&& !verbose
)
2553 _cupsLangPuts(stdout
, _(" FAIL"));
2556 _cupsLangPrintf(stdout
, _(" %s Missing %s file \"%s\"."),
2557 prefix
, "APPrinterIconPath", pathprog
);
2562 else if (fileinfo
.st_uid
!= 0 ||
2563 (fileinfo
.st_mode
& MODE_WRITE
) ||
2564 (fileinfo
.st_mode
& MODE_MASK
) != MODE_DATAFILE
)
2566 if (!warn
&& !errors
&& !verbose
)
2567 _cupsLangPuts(stdout
, _(" FAIL"));
2570 _cupsLangPrintf(stdout
,
2571 _(" %s Bad permissions on %s file \"%s\"."),
2572 prefix
, "APPrinterIconPath", pathprog
);
2578 errors
= valid_path("APPrinterIconPath", pathprog
, errors
, verbose
,
2583 * APPrinterLowInkTool
2586 if ((attr
= ppdFindAttr(ppd
, "APPrinterLowInkTool", NULL
)) != NULL
)
2588 if (strcmp(attr
->name
, "APPrinterLowInkTool"))
2590 if (!warn
&& !errors
&& !verbose
)
2591 _cupsLangPuts(stdout
, _(" FAIL"));
2594 _cupsLangPrintf(stdout
,
2595 _(" %s Bad spelling of %s - should be %s."),
2596 prefix
, attr
->name
, "APPrinterLowInkTool");
2602 snprintf(pathprog
, sizeof(pathprog
), "%s%s", root
,
2603 attr
->value
? attr
->value
: "(null)");
2605 if (!attr
->value
|| stat(pathprog
, &fileinfo
))
2607 if (!warn
&& !errors
&& !verbose
)
2608 _cupsLangPuts(stdout
, _(" FAIL"));
2611 _cupsLangPrintf(stdout
, _(" %s Missing %s file \"%s\"."),
2612 prefix
, "APPrinterLowInkTool", pathprog
);
2617 else if (fileinfo
.st_uid
!= 0 ||
2618 (fileinfo
.st_mode
& MODE_WRITE
) ||
2619 (fileinfo
.st_mode
& MODE_MASK
) != MODE_DIRECTORY
)
2621 if (!warn
&& !errors
&& !verbose
)
2622 _cupsLangPuts(stdout
, _(" FAIL"));
2625 _cupsLangPrintf(stdout
,
2626 _(" %s Bad permissions on %s file \"%s\"."),
2627 prefix
, "APPrinterLowInkTool", pathprog
);
2633 errors
= valid_path("APPrinterLowInkTool", pathprog
, errors
, verbose
,
2638 * APPrinterUtilityPath
2641 if ((attr
= ppdFindAttr(ppd
, "APPrinterUtilityPath", NULL
)) != NULL
)
2643 if (strcmp(attr
->name
, "APPrinterUtilityPath"))
2645 if (!warn
&& !errors
&& !verbose
)
2646 _cupsLangPuts(stdout
, _(" FAIL"));
2649 _cupsLangPrintf(stdout
,
2650 _(" %s Bad spelling of %s - should be %s."),
2651 prefix
, attr
->name
, "APPrinterUtilityPath");
2657 snprintf(pathprog
, sizeof(pathprog
), "%s%s", root
,
2658 attr
->value
? attr
->value
: "(null)");
2660 if (!attr
->value
|| stat(pathprog
, &fileinfo
))
2662 if (!warn
&& !errors
&& !verbose
)
2663 _cupsLangPuts(stdout
, _(" FAIL"));
2666 _cupsLangPrintf(stdout
, _(" %s Missing %s file \"%s\"."),
2667 prefix
, "APPrinterUtilityPath", pathprog
);
2672 else if (fileinfo
.st_uid
!= 0 ||
2673 (fileinfo
.st_mode
& MODE_WRITE
) ||
2674 (fileinfo
.st_mode
& MODE_MASK
) != MODE_DIRECTORY
)
2676 if (!warn
&& !errors
&& !verbose
)
2677 _cupsLangPuts(stdout
, _(" FAIL"));
2680 _cupsLangPrintf(stdout
,
2681 _(" %s Bad permissions on %s file \"%s\"."),
2682 prefix
, "APPrinterUtilityPath", pathprog
);
2688 errors
= valid_path("APPrinterUtilityPath", pathprog
, errors
, verbose
,
2693 * APScanAppBundleID and APScanAppPath
2696 if ((attr
= ppdFindAttr(ppd
, "APScanAppPath", NULL
)) != NULL
)
2698 if (strcmp(attr
->name
, "APScanAppPath"))
2700 if (!warn
&& !errors
&& !verbose
)
2701 _cupsLangPuts(stdout
, _(" FAIL"));
2704 _cupsLangPrintf(stdout
,
2705 _(" %s Bad spelling of %s - should be %s."),
2706 prefix
, attr
->name
, "APScanAppPath");
2712 if (!attr
->value
|| stat(attr
->value
, &fileinfo
))
2714 if (!warn
&& !errors
&& !verbose
)
2715 _cupsLangPuts(stdout
, _(" FAIL"));
2718 _cupsLangPrintf(stdout
, _(" %s Missing %s file \"%s\"."),
2719 prefix
, "APScanAppPath",
2720 attr
->value
? attr
->value
: "<NULL>");
2725 else if (fileinfo
.st_uid
!= 0 ||
2726 (fileinfo
.st_mode
& MODE_WRITE
) ||
2727 (fileinfo
.st_mode
& MODE_MASK
) != MODE_DIRECTORY
)
2729 if (!warn
&& !errors
&& !verbose
)
2730 _cupsLangPuts(stdout
, _(" FAIL"));
2733 _cupsLangPrintf(stdout
,
2734 _(" %s Bad permissions on %s file \"%s\"."),
2735 prefix
, "APScanAppPath", attr
->value
);
2741 errors
= valid_path("APScanAppPath", attr
->value
, errors
, verbose
,
2744 if (ppdFindAttr(ppd
, "APScanAppBundleID", NULL
))
2746 if (!warn
&& !errors
&& !verbose
)
2747 _cupsLangPuts(stdout
, _(" FAIL"));
2750 _cupsLangPrintf(stdout
, _(" %s Cannot provide both "
2751 "APScanAppPath and APScanAppBundleID."),
2758 #endif /* __APPLE__ */
2765 * 'check_profiles()' - Check ICC color profiles in the PPD file.
2768 static int /* O - Errors found */
2769 check_profiles(ppd_file_t
*ppd
, /* I - PPD file */
2770 const char *root
, /* I - Root directory */
2771 int errors
, /* I - Errors found */
2772 int verbose
, /* I - Verbosity level */
2773 int warn
) /* I - Warnings only? */
2775 int i
; /* Looping var */
2776 ppd_attr_t
*attr
; /* PPD attribute */
2777 const char *ptr
; /* Pointer into string */
2778 const char *prefix
; /* WARN/FAIL prefix */
2779 char filename
[1024]; /* Profile filename */
2780 struct stat fileinfo
; /* File information */
2781 int num_profiles
= 0; /* Number of profiles */
2782 unsigned hash
, /* Current hash value */
2783 hashes
[1000]; /* Hash values of profile names */
2784 const char *specs
[1000]; /* Specifiers for profiles */
2787 prefix
= warn
? " WARN " : "**FAIL**";
2789 for (attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
2791 attr
= ppdFindNextAttr(ppd
, "cupsICCProfile", NULL
))
2794 * Check for valid selector...
2797 for (i
= 0, ptr
= strchr(attr
->spec
, '.'); ptr
; ptr
= strchr(ptr
+ 1, '.'))
2800 if (!attr
->value
|| i
< 2)
2802 if (!warn
&& !errors
&& !verbose
)
2803 _cupsLangPuts(stdout
, _(" FAIL"));
2806 _cupsLangPrintf(stdout
,
2807 _(" %s Bad cupsICCProfile %s."),
2808 prefix
, attr
->spec
);
2817 * Check for valid profile filename...
2820 if (attr
->value
[0] == '/')
2821 snprintf(filename
, sizeof(filename
), "%s%s", root
, attr
->value
);
2824 if ((ptr
= getenv("CUPS_DATADIR")) == NULL
)
2827 if (*ptr
== '/' || !*root
)
2828 snprintf(filename
, sizeof(filename
), "%s%s/profiles/%s", root
, ptr
,
2831 snprintf(filename
, sizeof(filename
), "%s/%s/profiles/%s", root
, ptr
,
2835 if (stat(filename
, &fileinfo
))
2837 if (!warn
&& !errors
&& !verbose
)
2838 _cupsLangPuts(stdout
, _(" FAIL"));
2841 _cupsLangPrintf(stdout
, _(" %s Missing %s file \"%s\"."),
2842 prefix
, "cupsICCProfile", filename
);
2847 else if (fileinfo
.st_uid
!= 0 ||
2848 (fileinfo
.st_mode
& MODE_WRITE
) ||
2849 (fileinfo
.st_mode
& MODE_MASK
) != MODE_DATAFILE
)
2851 if (!warn
&& !errors
&& !verbose
)
2852 _cupsLangPuts(stdout
, _(" FAIL"));
2855 _cupsLangPrintf(stdout
,
2856 _(" %s Bad permissions on %s file \"%s\"."),
2857 prefix
, "cupsICCProfile", filename
);
2863 errors
= valid_path("cupsICCProfile", filename
, errors
, verbose
, warn
);
2866 * Check for hash collisions...
2869 hash
= _ppdHashName(attr
->spec
);
2871 if (num_profiles
> 0)
2873 for (i
= 0; i
< num_profiles
; i
++)
2874 if (hashes
[i
] == hash
)
2877 if (i
< num_profiles
)
2879 if (!warn
&& !errors
&& !verbose
)
2880 _cupsLangPuts(stdout
, _(" FAIL"));
2883 _cupsLangPrintf(stdout
,
2884 _(" %s cupsICCProfile %s hash value "
2885 "collides with %s."), prefix
, attr
->spec
,
2894 * Remember up to 1000 profiles...
2897 if (num_profiles
< 1000)
2899 hashes
[num_profiles
] = hash
;
2900 specs
[num_profiles
] = attr
->spec
;
2910 * 'check_sizes()' - Check media sizes in the PPD file.
2913 static int /* O - Errors found */
2914 check_sizes(ppd_file_t
*ppd
, /* I - PPD file */
2915 int errors
, /* I - Errors found */
2916 int verbose
, /* I - Verbosity level */
2917 int warn
) /* I - Warnings only? */
2919 int i
; /* Looping vars */
2920 ppd_size_t
*size
; /* Current size */
2921 int width
, /* Custom width */
2922 length
; /* Custom length */
2923 const char *prefix
; /* WARN/FAIL prefix */
2924 ppd_option_t
*page_size
, /* PageSize option */
2925 *page_region
; /* PageRegion option */
2928 prefix
= warn
? " WARN " : "**FAIL**";
2930 if ((page_size
= ppdFindOption(ppd
, "PageSize")) == NULL
&& warn
!= 2)
2932 if (!warn
&& !errors
&& !verbose
)
2933 _cupsLangPuts(stdout
, _(" FAIL"));
2936 _cupsLangPrintf(stdout
,
2937 _(" %s Missing REQUIRED PageSize option.\n"
2938 " REF: Page 99, section 5.14."),
2945 if ((page_region
= ppdFindOption(ppd
, "PageRegion")) == NULL
&& warn
!= 2)
2947 if (!warn
&& !errors
&& !verbose
)
2948 _cupsLangPuts(stdout
, _(" FAIL"));
2951 _cupsLangPrintf(stdout
,
2952 _(" %s Missing REQUIRED PageRegion option.\n"
2953 " REF: Page 100, section 5.14."),
2960 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
2963 * Check that the size name is standard...
2966 if (!strcmp(size
->name
, "Custom"))
2969 * Skip custom page size...
2974 else if (warn
!= 2 && size
->name
[0] == 'w' &&
2975 sscanf(size
->name
, "w%dh%d", &width
, &length
) == 2)
2978 * Validate device-specific size wNNNhNNN should have proper width and
2982 if (fabs(width
- size
->width
) >= 1.0 ||
2983 fabs(length
- size
->length
) >= 1.0)
2985 if (!warn
&& !errors
&& !verbose
)
2986 _cupsLangPuts(stdout
, _(" FAIL"));
2989 _cupsLangPrintf(stdout
,
2990 _(" %s Size \"%s\" has unexpected dimensions "
2992 prefix
, size
->name
, size
->width
, size
->length
);
3000 * Verify that the size is defined for both PageSize and PageRegion...
3003 if (warn
!= 2 && !ppdFindChoice(page_size
, size
->name
))
3005 if (!warn
&& !errors
&& !verbose
)
3006 _cupsLangPuts(stdout
, _(" FAIL"));
3009 _cupsLangPrintf(stdout
,
3010 _(" %s Size \"%s\" defined for %s but not for "
3012 prefix
, size
->name
, "PageRegion", "PageSize");
3017 else if (warn
!= 2 && !ppdFindChoice(page_region
, size
->name
))
3019 if (!warn
&& !errors
&& !verbose
)
3020 _cupsLangPuts(stdout
, _(" FAIL"));
3023 _cupsLangPrintf(stdout
,
3024 _(" %s Size \"%s\" defined for %s but not for "
3026 prefix
, size
->name
, "PageSize", "PageRegion");
3038 * 'check_translations()' - Check translations in the PPD file.
3041 static int /* O - Errors found */
3042 check_translations(ppd_file_t
*ppd
, /* I - PPD file */
3043 int errors
, /* I - Errors found */
3044 int verbose
, /* I - Verbosity level */
3045 int warn
) /* I - Warnings only? */
3047 int j
; /* Looping var */
3048 ppd_attr_t
*attr
; /* PPD attribute */
3049 cups_array_t
*languages
; /* Array of languages */
3050 int langlen
; /* Length of language */
3051 char *language
, /* Current language */
3052 keyword
[PPD_MAX_NAME
], /* Localization keyword (full) */
3053 llkeyword
[PPD_MAX_NAME
],/* Localization keyword (base) */
3054 ckeyword
[PPD_MAX_NAME
], /* Custom option keyword (full) */
3055 cllkeyword
[PPD_MAX_NAME
];
3056 /* Custom option keyword (base) */
3057 ppd_option_t
*option
; /* Standard UI option */
3058 ppd_coption_t
*coption
; /* Custom option */
3059 ppd_cparam_t
*cparam
; /* Custom parameter */
3060 char ll
[3]; /* Base language */
3061 const char *prefix
; /* WARN/FAIL prefix */
3062 const char *text
; /* Pointer into UI text */
3065 prefix
= warn
? " WARN " : "**FAIL**";
3067 if ((languages
= _ppdGetLanguages(ppd
)) != NULL
)
3070 * This file contains localizations, check them...
3073 for (language
= (char *)cupsArrayFirst(languages
);
3075 language
= (char *)cupsArrayNext(languages
))
3077 langlen
= (int)strlen(language
);
3078 if (langlen
!= 2 && langlen
!= 5)
3080 if (!warn
&& !errors
&& !verbose
)
3081 _cupsLangPuts(stdout
, _(" FAIL"));
3084 _cupsLangPrintf(stdout
,
3085 _(" %s Bad language \"%s\"."),
3094 if (!strcmp(language
, "en"))
3097 strlcpy(ll
, language
, sizeof(ll
));
3100 * Loop through all options and choices...
3103 for (option
= ppdFirstOption(ppd
);
3105 option
= ppdNextOption(ppd
))
3107 if (!strcmp(option
->keyword
, "PageRegion"))
3110 snprintf(keyword
, sizeof(keyword
), "%s.Translation", language
);
3111 snprintf(llkeyword
, sizeof(llkeyword
), "%s.Translation", ll
);
3113 if ((attr
= ppdFindAttr(ppd
, keyword
, option
->keyword
)) == NULL
&&
3114 (attr
= ppdFindAttr(ppd
, llkeyword
, option
->keyword
)) == NULL
)
3116 if (!warn
&& !errors
&& !verbose
)
3117 _cupsLangPuts(stdout
, _(" FAIL"));
3120 _cupsLangPrintf(stdout
,
3121 _(" %s Missing \"%s\" translation "
3122 "string for option %s."),
3123 prefix
, language
, option
->keyword
);
3128 else if (!valid_utf8(attr
->text
))
3130 if (!warn
&& !errors
&& !verbose
)
3131 _cupsLangPuts(stdout
, _(" FAIL"));
3134 _cupsLangPrintf(stdout
,
3135 _(" %s Bad UTF-8 \"%s\" translation "
3136 "string for option %s."),
3137 prefix
, language
, option
->keyword
);
3143 snprintf(keyword
, sizeof(keyword
), "%s.%s", language
,
3145 snprintf(llkeyword
, sizeof(llkeyword
), "%s.%s", ll
,
3148 for (j
= 0; j
< option
->num_choices
; j
++)
3151 * First see if this choice is a number; if so, don't require
3155 for (text
= option
->choices
[j
].text
; *text
; text
++)
3156 if (!strchr("0123456789-+.", *text
))
3163 * Check custom choices differently...
3166 if (!strcasecmp(option
->choices
[j
].choice
, "Custom") &&
3167 (coption
= ppdFindCustomOption(ppd
,
3168 option
->keyword
)) != NULL
)
3170 snprintf(ckeyword
, sizeof(ckeyword
), "%s.Custom%s",
3171 language
, option
->keyword
);
3173 if ((attr
= ppdFindAttr(ppd
, ckeyword
, "True")) != NULL
&&
3174 !valid_utf8(attr
->text
))
3176 if (!warn
&& !errors
&& !verbose
)
3177 _cupsLangPuts(stdout
, _(" FAIL"));
3180 _cupsLangPrintf(stdout
,
3181 _(" %s Bad UTF-8 \"%s\" "
3182 "translation string for option %s, "
3185 ckeyword
+ 1 + strlen(language
),
3192 if (strcasecmp(option
->keyword
, "PageSize"))
3194 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
3196 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
3198 snprintf(ckeyword
, sizeof(ckeyword
), "%s.ParamCustom%s",
3199 language
, option
->keyword
);
3200 snprintf(cllkeyword
, sizeof(cllkeyword
), "%s.ParamCustom%s",
3201 ll
, option
->keyword
);
3203 if ((attr
= ppdFindAttr(ppd
, ckeyword
,
3204 cparam
->name
)) == NULL
&&
3205 (attr
= ppdFindAttr(ppd
, cllkeyword
,
3206 cparam
->name
)) == NULL
)
3208 if (!warn
&& !errors
&& !verbose
)
3209 _cupsLangPuts(stdout
, _(" FAIL"));
3212 _cupsLangPrintf(stdout
,
3213 _(" %s Missing \"%s\" "
3214 "translation string for option %s, "
3217 ckeyword
+ 1 + strlen(language
),
3223 else if (!valid_utf8(attr
->text
))
3225 if (!warn
&& !errors
&& !verbose
)
3226 _cupsLangPuts(stdout
, _(" FAIL"));
3229 _cupsLangPrintf(stdout
,
3230 _(" %s Bad UTF-8 \"%s\" "
3231 "translation string for option %s, "
3234 ckeyword
+ 1 + strlen(language
),
3243 else if ((attr
= ppdFindAttr(ppd
, keyword
,
3244 option
->choices
[j
].choice
)) == NULL
&&
3245 (attr
= ppdFindAttr(ppd
, llkeyword
,
3246 option
->choices
[j
].choice
)) == NULL
)
3248 if (!warn
&& !errors
&& !verbose
)
3249 _cupsLangPuts(stdout
, _(" FAIL"));
3252 _cupsLangPrintf(stdout
,
3253 _(" %s Missing \"%s\" "
3254 "translation string for option %s, "
3256 prefix
, language
, option
->keyword
,
3257 option
->choices
[j
].choice
);
3262 else if (!valid_utf8(attr
->text
))
3264 if (!warn
&& !errors
&& !verbose
)
3265 _cupsLangPuts(stdout
, _(" FAIL"));
3268 _cupsLangPrintf(stdout
,
3269 _(" %s Bad UTF-8 \"%s\" "
3270 "translation string for option %s, "
3272 prefix
, language
, option
->keyword
,
3273 option
->choices
[j
].choice
);
3283 * Verify that we have the base language for each localized one...
3286 for (language
= (char *)cupsArrayFirst(languages
);
3288 language
= (char *)cupsArrayNext(languages
))
3292 * Lookup the base language...
3295 cupsArraySave(languages
);
3297 strlcpy(ll
, language
, sizeof(ll
));
3299 if (!cupsArrayFind(languages
, ll
) &&
3300 strcmp(ll
, "zh") && strcmp(ll
, "en"))
3302 if (!warn
&& !errors
&& !verbose
)
3303 _cupsLangPuts(stdout
, _(" FAIL"));
3306 _cupsLangPrintf(stdout
,
3307 _(" %s No base translation \"%s\" "
3308 "is included in file."), prefix
, ll
);
3314 cupsArrayRestore(languages
);
3318 * Free memory used for the languages...
3321 _ppdFreeLanguages(languages
);
3329 * 'show_conflicts()' - Show option conflicts in a PPD file.
3333 show_conflicts(ppd_file_t
*ppd
) /* I - PPD to check */
3335 int i
, j
; /* Looping variables */
3336 ppd_const_t
*c
; /* Current constraint */
3337 ppd_option_t
*o1
, *o2
; /* Options */
3338 ppd_choice_t
*c1
, *c2
; /* Choices */
3342 * Loop through all of the UI constraints and report any options
3346 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
3349 * Grab pointers to the first option...
3352 o1
= ppdFindOption(ppd
, c
->option1
);
3356 else if (c
->choice1
[0] != '\0')
3359 * This constraint maps to a specific choice.
3362 c1
= ppdFindChoice(o1
, c
->choice1
);
3367 * This constraint applies to any choice for this option.
3370 for (j
= o1
->num_choices
, c1
= o1
->choices
; j
> 0; j
--, c1
++)
3375 !strcasecmp(c1
->choice
, "None") ||
3376 !strcasecmp(c1
->choice
, "Off") ||
3377 !strcasecmp(c1
->choice
, "False"))
3382 * Grab pointers to the second option...
3385 o2
= ppdFindOption(ppd
, c
->option2
);
3389 else if (c
->choice2
[0] != '\0')
3392 * This constraint maps to a specific choice.
3395 c2
= ppdFindChoice(o2
, c
->choice2
);
3400 * This constraint applies to any choice for this option.
3403 for (j
= o2
->num_choices
, c2
= o2
->choices
; j
> 0; j
--, c2
++)
3408 !strcasecmp(c2
->choice
, "None") ||
3409 !strcasecmp(c2
->choice
, "Off") ||
3410 !strcasecmp(c2
->choice
, "False"))
3415 * If both options are marked then there is a conflict...
3418 if (c1
!= NULL
&& c1
->marked
&& c2
!= NULL
&& c2
->marked
)
3419 _cupsLangPrintf(stdout
,
3420 _(" WARN \"%s %s\" conflicts with \"%s %s\"\n"
3421 " (constraint=\"%s %s %s %s\")."),
3422 o1
->keyword
, c1
->choice
, o2
->keyword
, c2
->choice
,
3423 c
->option1
, c
->choice1
, c
->option2
, c
->choice2
);
3429 * 'test_raster()' - Test PostScript commands for raster printers.
3432 static int /* O - 1 on success, 0 on failure */
3433 test_raster(ppd_file_t
*ppd
, /* I - PPD file */
3434 int verbose
) /* I - Verbosity */
3436 cups_page_header2_t header
; /* Page header */
3439 ppdMarkDefaults(ppd
);
3440 if (cupsRasterInterpretPPD(&header
, ppd
, 0, NULL
, 0))
3443 _cupsLangPuts(stdout
, _(" FAIL"));
3446 _cupsLangPrintf(stdout
,
3447 _(" **FAIL** Default option code cannot be "
3448 "interpreted: %s"), cupsRasterErrorString());
3454 * Try a test of custom page size code, if available...
3457 if (!ppdPageSize(ppd
, "Custom.612x792"))
3460 ppdMarkOption(ppd
, "PageSize", "Custom.612x792");
3462 if (cupsRasterInterpretPPD(&header
, ppd
, 0, NULL
, 0))
3465 _cupsLangPuts(stdout
, _(" FAIL"));
3468 _cupsLangPrintf(stdout
,
3469 _(" **FAIL** Default option code cannot be "
3470 "interpreted: %s"), cupsRasterErrorString());
3480 * 'usage()' - Show program usage...
3486 _cupsLangPuts(stdout
, _("Usage: cupstestppd [options] filename1.ppd[.gz] "
3487 "[... filenameN.ppd[.gz]]"));
3488 _cupsLangPuts(stdout
, _(" program | cupstestppd [options] -"));
3489 _cupsLangPuts(stdout
, "");
3490 _cupsLangPuts(stdout
, _("Options:"));
3491 _cupsLangPuts(stdout
, "");
3492 _cupsLangPuts(stdout
, _(" -I {filename,filters,none,profiles}"));
3493 _cupsLangPuts(stdout
, _(" Ignore specific warnings."));
3494 _cupsLangPuts(stdout
, _(" -R root-directory Set alternate root."));
3495 _cupsLangPuts(stdout
, _(" -W {all,none,constraints,defaults,duplex,"
3496 "filters,profiles,sizes,translations}"));
3497 _cupsLangPuts(stdout
, _(" Issue warnings instead of "
3499 _cupsLangPuts(stdout
, _(" -q Run silently."));
3500 _cupsLangPuts(stdout
, _(" -r Use 'relaxed' open mode."));
3501 _cupsLangPuts(stdout
, _(" -v Be slightly verbose."));
3502 _cupsLangPuts(stdout
, _(" -vv Be very verbose."));
3509 * 'valid_path()' - Check whether a path has the correct capitalization.
3512 static int /* O - Errors found */
3513 valid_path(const char *keyword
, /* I - Keyword using path */
3514 const char *path
, /* I - Path to check */
3515 int errors
, /* I - Errors found */
3516 int verbose
, /* I - Verbosity level */
3517 int warn
) /* I - Warnings only? */
3519 cups_dir_t
*dir
; /* Current directory */
3520 cups_dentry_t
*dentry
; /* Current directory entry */
3521 char temp
[1024], /* Temporary path */
3522 *ptr
; /* Pointer into temporary path */
3523 const char *prefix
; /* WARN/FAIL prefix */
3526 prefix
= warn
? " WARN " : "**FAIL**";
3529 * Loop over the components of the path, checking that the entry exists with
3530 * the same capitalization...
3533 strlcpy(temp
, path
, sizeof(temp
));
3535 while ((ptr
= strrchr(temp
, '/')) != NULL
)
3538 * Chop off the trailing component so temp == dirname and ptr == basename.
3544 * Try opening the directory containing the base name...
3548 dir
= cupsDirOpen(temp
);
3550 dir
= cupsDirOpen("/");
3556 while ((dentry
= cupsDirRead(dir
)) != NULL
)
3558 if (!strcmp(dentry
->filename
, ptr
))
3566 * Display an error if the filename doesn't exist with the same
3572 if (!warn
&& !errors
&& !verbose
)
3573 _cupsLangPuts(stdout
, _(" FAIL"));
3576 _cupsLangPrintf(stdout
,
3577 _(" %s %s file \"%s\" has the wrong "
3578 "capitalization."), prefix
, keyword
, path
);
3592 * 'valid_utf8()' - Check whether a string contains valid UTF-8 text.
3595 static int /* O - 1 if valid, 0 if not */
3596 valid_utf8(const char *s
) /* I - String to check */
3603 * Check for valid UTF-8 sequence...
3606 if ((*s
& 0xc0) == 0x80)
3607 return (0); /* Illegal suffix byte */
3608 else if ((*s
& 0xe0) == 0xc0)
3611 * 2-byte sequence...
3616 if ((*s
& 0xc0) != 0x80)
3617 return (0); /* Missing suffix byte */
3619 else if ((*s
& 0xf0) == 0xe0)
3622 * 3-byte sequence...
3627 if ((*s
& 0xc0) != 0x80)
3628 return (0); /* Missing suffix byte */
3632 if ((*s
& 0xc0) != 0x80)
3633 return (0); /* Missing suffix byte */
3635 else if ((*s
& 0xf8) == 0xf0)
3638 * 4-byte sequence...
3643 if ((*s
& 0xc0) != 0x80)
3644 return (0); /* Missing suffix byte */
3648 if ((*s
& 0xc0) != 0x80)
3649 return (0); /* Missing suffix byte */
3653 if ((*s
& 0xc0) != 0x80)
3654 return (0); /* Missing suffix byte */
3657 return (0); /* Bad sequence */
3668 * End of "$Id: cupstestppd.c 7807 2008-07-28 21:54:24Z mike $".