]> git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestppd.c
Merge changes from CUPS 1.4svn-r7791.
[thirdparty/cups.git] / systemv / cupstestppd.c
1 /*
2 * "$Id: cupstestppd.c 7637 2008-06-11 17:25:36Z mike $"
3 *
4 * PPD test program for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 *
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/".
14 *
15 * PostScript is a trademark of Adobe Systems, Inc.
16 *
17 * This file is subject to the Apple OS-Developed Software exception.
18 *
19 * Contents:
20 *
21 * main() - Main entry for test program.
22 * check_basics() - Check for CR LF, mixed line endings, and blank
23 * lines.
24 * check_constraints() - Check UIConstraints in the PPD file.
25 * check_defaults() - Check default option keywords in the PPD file.
26 * check_filters() - Check filters in the PPD file.
27 * check_profiles() - Check ICC color profiles in the PPD file.
28 * check_translations() - Check translations in the PPD file.
29 * show_conflicts() - Show option conflicts in a PPD file.
30 * test_raster() - Test PostScript commands for raster printers.
31 * usage() - Show program usage...
32 * valid_utf8() - Check whether a string contains valid UTF-8 text.
33 */
34
35 /*
36 * Include necessary headers...
37 */
38
39 #include <cups/string.h>
40 #include <cups/cups.h>
41 #include <cups/ppd-private.h>
42 #include <cups/i18n.h>
43 #include <cups/raster.h>
44 #include <errno.h>
45 #include <stdlib.h>
46 #include <sys/stat.h>
47
48
49 /*
50 * Error warning overrides...
51 */
52
53 enum
54 {
55 WARN_NONE = 0,
56 WARN_CONSTRAINTS = 1,
57 WARN_DEFAULTS = 2,
58 WARN_FILTERS = 4,
59 WARN_PROFILES = 8,
60 WARN_TRANSLATIONS = 16,
61 WARN_ALL = 31
62 };
63
64
65 /*
66 * Error codes...
67 */
68
69 enum
70 {
71 ERROR_NONE = 0,
72 ERROR_USAGE,
73 ERROR_FILE_OPEN,
74 ERROR_PPD_FORMAT,
75 ERROR_CONFORMANCE
76 };
77
78
79 /*
80 * Line endings...
81 */
82
83 enum
84 {
85 EOL_NONE = 0,
86 EOL_CR,
87 EOL_LF,
88 EOL_CRLF
89 };
90
91
92 /*
93 * Local functions...
94 */
95
96 static void check_basics(const char *filename);
97 static int check_constraints(ppd_file_t *ppd, int errors, int verbose,
98 int warn);
99 static int check_defaults(ppd_file_t *ppd, int errors, int verbose,
100 int warn);
101 static int check_filters(ppd_file_t *ppd, const char *root, int errors,
102 int verbose, int warn);
103 static int check_profiles(ppd_file_t *ppd, const char *root, int errors,
104 int verbose, int warn);
105 static int check_translations(ppd_file_t *ppd, int errors, int verbose,\
106 int warn);
107 static void show_conflicts(ppd_file_t *ppd);
108 static int test_raster(ppd_file_t *ppd, int verbose);
109 static void usage(void);
110 static int valid_utf8(const char *s);
111
112
113 /*
114 * 'main()' - Main entry for test program.
115 */
116
117 int /* O - Exit status */
118 main(int argc, /* I - Number of command-line args */
119 char *argv[]) /* I - Command-line arguments */
120 {
121 int i, j, k, m, n; /* Looping vars */
122 int len; /* Length of option name */
123 char *opt; /* Option character */
124 const char *ptr; /* Pointer into string */
125 int files; /* Number of files */
126 int verbose; /* Want verbose output? */
127 int warn; /* Which errors to just warn about */
128 int status; /* Exit status */
129 int errors; /* Number of conformance errors */
130 int ppdversion; /* PPD spec version in PPD file */
131 ppd_status_t error; /* Status of ppdOpen*() */
132 int line; /* Line number for error */
133 char *root; /* Root directory */
134 int xdpi, /* X resolution */
135 ydpi; /* Y resolution */
136 ppd_file_t *ppd; /* PPD file record */
137 ppd_attr_t *attr; /* PPD attribute */
138 ppd_size_t *size; /* Size record */
139 ppd_group_t *group; /* UI group */
140 ppd_option_t *option; /* Standard UI option */
141 ppd_group_t *group2; /* UI group */
142 ppd_option_t *option2; /* Standard UI option */
143 ppd_choice_t *choice; /* Standard UI option choice */
144 struct lconv *loc; /* Locale data */
145 static char *uis[] = { "BOOLEAN", "PICKONE", "PICKMANY" };
146 static char *sections[] = { "ANY", "DOCUMENT", "EXIT",
147 "JCL", "PAGE", "PROLOG" };
148
149
150 _cupsSetLocale(argv);
151 loc = localeconv();
152
153 /*
154 * Display PPD files for each file listed on the command-line...
155 */
156
157 ppdSetConformance(PPD_CONFORM_STRICT);
158
159 verbose = 0;
160 ppd = NULL;
161 files = 0;
162 status = ERROR_NONE;
163 root = "";
164 warn = WARN_NONE;
165
166 for (i = 1; i < argc; i ++)
167 if (argv[i][0] == '-' && argv[i][1])
168 {
169 for (opt = argv[i] + 1; *opt; opt ++)
170 switch (*opt)
171 {
172 case 'R' : /* Alternate root directory */
173 i ++;
174
175 if (i >= argc)
176 usage();
177
178 root = argv[i];
179 break;
180
181 case 'W' : /* Turn errors into warnings */
182 i ++;
183
184 if (i >= argc)
185 usage();
186
187 if (!strcmp(argv[i], "none"))
188 warn = WARN_NONE;
189 else if (!strcmp(argv[i], "constraints"))
190 warn |= WARN_CONSTRAINTS;
191 else if (!strcmp(argv[i], "defaults"))
192 warn |= WARN_DEFAULTS;
193 else if (!strcmp(argv[i], "filters"))
194 warn |= WARN_FILTERS;
195 else if (!strcmp(argv[i], "profiles"))
196 warn |= WARN_PROFILES;
197 else if (!strcmp(argv[i], "translations"))
198 warn |= WARN_TRANSLATIONS;
199 else if (!strcmp(argv[i], "all"))
200 warn = WARN_ALL;
201 else
202 usage();
203 break;
204
205 case 'q' : /* Quiet mode */
206 if (verbose > 0)
207 {
208 _cupsLangPuts(stderr,
209 _("cupstestppd: The -q option is incompatible "
210 "with the -v option.\n"));
211 return (1);
212 }
213
214 verbose --;
215 break;
216
217 case 'r' : /* Relaxed mode */
218 ppdSetConformance(PPD_CONFORM_RELAXED);
219 break;
220
221 case 'v' : /* Verbose mode */
222 if (verbose < 0)
223 {
224 _cupsLangPuts(stderr,
225 _("cupstestppd: The -v option is incompatible "
226 "with the -q option.\n"));
227 return (1);
228 }
229
230 verbose ++;
231 break;
232
233 default :
234 usage();
235 break;
236 }
237 }
238 else
239 {
240 /*
241 * Open the PPD file...
242 */
243
244 if (files && verbose >= 0)
245 _cupsLangPuts(stdout, "\n");
246
247 files ++;
248
249 if (argv[i][0] == '-')
250 {
251 /*
252 * Read from stdin...
253 */
254
255 ppd = ppdOpen(stdin);
256
257 if (verbose >= 0)
258 printf("%s:", (ppd && ppd->pcfilename) ? ppd->pcfilename : "(stdin)");
259 }
260 else
261 {
262 /*
263 * Read from a file...
264 */
265
266 if (verbose >= 0)
267 printf("%s:", argv[i]);
268
269 ppd = ppdOpenFile(argv[i]);
270 }
271
272 if (ppd == NULL)
273 {
274 error = ppdLastError(&line);
275
276 if (error <= PPD_ALLOC_ERROR)
277 {
278 status = ERROR_FILE_OPEN;
279
280 if (verbose >= 0)
281 _cupsLangPrintf(stdout,
282 _(" FAIL\n"
283 " **FAIL** Unable to open PPD file - %s\n"),
284 strerror(errno));
285 }
286 else
287 {
288 status = ERROR_PPD_FORMAT;
289
290 if (verbose >= 0)
291 {
292 _cupsLangPrintf(stdout,
293 _(" FAIL\n"
294 " **FAIL** Unable to open PPD file - "
295 "%s on line %d.\n"),
296 ppdErrorString(error), line);
297
298 switch (error)
299 {
300 case PPD_MISSING_PPDADOBE4 :
301 _cupsLangPuts(stdout,
302 _(" REF: Page 42, section 5.2.\n"));
303 break;
304 case PPD_MISSING_VALUE :
305 _cupsLangPuts(stdout,
306 _(" REF: Page 20, section 3.4.\n"));
307 break;
308 case PPD_BAD_OPEN_GROUP :
309 case PPD_NESTED_OPEN_GROUP :
310 _cupsLangPuts(stdout,
311 _(" REF: Pages 45-46, section 5.2.\n"));
312 break;
313 case PPD_BAD_OPEN_UI :
314 case PPD_NESTED_OPEN_UI :
315 _cupsLangPuts(stdout,
316 _(" REF: Pages 42-45, section 5.2.\n"));
317 break;
318 case PPD_BAD_ORDER_DEPENDENCY :
319 _cupsLangPuts(stdout,
320 _(" REF: Pages 48-49, section 5.2.\n"));
321 break;
322 case PPD_BAD_UI_CONSTRAINTS :
323 _cupsLangPuts(stdout,
324 _(" REF: Pages 52-54, section 5.2.\n"));
325 break;
326 case PPD_MISSING_ASTERISK :
327 _cupsLangPuts(stdout,
328 _(" REF: Page 15, section 3.2.\n"));
329 break;
330 case PPD_LINE_TOO_LONG :
331 _cupsLangPuts(stdout,
332 _(" REF: Page 15, section 3.1.\n"));
333 break;
334 case PPD_ILLEGAL_CHARACTER :
335 _cupsLangPuts(stdout,
336 _(" REF: Page 15, section 3.1.\n"));
337 break;
338 case PPD_ILLEGAL_MAIN_KEYWORD :
339 _cupsLangPuts(stdout,
340 _(" REF: Pages 16-17, section 3.2.\n"));
341 break;
342 case PPD_ILLEGAL_OPTION_KEYWORD :
343 _cupsLangPuts(stdout,
344 _(" REF: Page 19, section 3.3.\n"));
345 break;
346 case PPD_ILLEGAL_TRANSLATION :
347 _cupsLangPuts(stdout,
348 _(" REF: Page 27, section 3.5.\n"));
349 break;
350 default :
351 break;
352 }
353
354 check_basics(argv[i]);
355 }
356 }
357
358 continue;
359 }
360
361 /*
362 * Show the header and then perform basic conformance tests (limited
363 * only by what the CUPS PPD functions actually load...)
364 */
365
366 errors = 0;
367 ppdversion = 43;
368
369 if (verbose > 0)
370 _cupsLangPuts(stdout,
371 _("\n DETAILED CONFORMANCE TEST RESULTS\n"));
372
373 if ((attr = ppdFindAttr(ppd, "FormatVersion", NULL)) != NULL &&
374 attr->value)
375 ppdversion = (int)(10 * _cupsStrScand(attr->value, NULL, loc) + 0.5);
376
377 for (j = 0; j < ppd->num_filters; j ++)
378 if (strstr(ppd->filters[j], "application/vnd.cups-raster"))
379 {
380 if (!test_raster(ppd, verbose))
381 errors ++;
382 break;
383 }
384
385 /*
386 * Look for default keywords with no matching option...
387 */
388
389 if (!(warn & WARN_DEFAULTS))
390 errors = check_defaults(ppd, errors, verbose, 0);
391
392 if ((attr = ppdFindAttr(ppd, "DefaultImageableArea", NULL)) == NULL)
393 {
394 if (verbose >= 0)
395 {
396 if (!errors && !verbose)
397 _cupsLangPuts(stdout, _(" FAIL\n"));
398
399 _cupsLangPuts(stdout,
400 _(" **FAIL** REQUIRED DefaultImageableArea\n"
401 " REF: Page 102, section 5.15.\n"));
402 }
403
404 errors ++;
405 }
406 else if (ppdPageSize(ppd, attr->value) == NULL &&
407 strcmp(attr->value, "Unknown"))
408 {
409 if (verbose >= 0)
410 {
411 if (!errors && !verbose)
412 _cupsLangPuts(stdout, _(" FAIL\n"));
413
414 _cupsLangPrintf(stdout,
415 _(" **FAIL** BAD DefaultImageableArea %s!\n"
416 " REF: Page 102, section 5.15.\n"),
417 attr->value);
418 }
419
420 errors ++;
421 }
422 else
423 {
424 if (verbose > 0)
425 _cupsLangPuts(stdout, _(" PASS DefaultImageableArea\n"));
426 }
427
428 if ((attr = ppdFindAttr(ppd, "DefaultPaperDimension", NULL)) == NULL)
429 {
430 if (verbose >= 0)
431 {
432 if (!errors && !verbose)
433 _cupsLangPuts(stdout, _(" FAIL\n"));
434
435 _cupsLangPuts(stdout,
436 _(" **FAIL** REQUIRED DefaultPaperDimension\n"
437 " REF: Page 103, section 5.15.\n"));
438 }
439
440 errors ++;
441 }
442 else if (ppdPageSize(ppd, attr->value) == NULL &&
443 strcmp(attr->value, "Unknown"))
444 {
445 if (verbose >= 0)
446 {
447 if (!errors && !verbose)
448 _cupsLangPuts(stdout, _(" FAIL\n"));
449
450 _cupsLangPrintf(stdout,
451 _(" **FAIL** BAD DefaultPaperDimension %s!\n"
452 " REF: Page 103, section 5.15.\n"),
453 attr->value);
454 }
455
456 errors ++;
457 }
458 else if (verbose > 0)
459 _cupsLangPuts(stdout, _(" PASS DefaultPaperDimension\n"));
460
461 for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++)
462 for (k = 0, option = group->options; k < group->num_options; k ++, option ++)
463 {
464 /*
465 * Verify that we have a default choice...
466 */
467
468 if (option->defchoice[0])
469 {
470 if (ppdFindChoice(option, option->defchoice) == NULL &&
471 strcmp(option->defchoice, "Unknown"))
472 {
473 if (verbose >= 0)
474 {
475 if (!errors && !verbose)
476 _cupsLangPuts(stdout, _(" FAIL\n"));
477
478 _cupsLangPrintf(stdout,
479 _(" **FAIL** BAD Default%s %s\n"
480 " REF: Page 40, section 4.5.\n"),
481 option->keyword, option->defchoice);
482 }
483
484 errors ++;
485 }
486 else if (verbose > 0)
487 _cupsLangPrintf(stdout,
488 _(" PASS Default%s\n"),
489 option->keyword);
490 }
491 else
492 {
493 if (verbose >= 0)
494 {
495 if (!errors && !verbose)
496 _cupsLangPuts(stdout, _(" FAIL\n"));
497
498 _cupsLangPrintf(stdout,
499 _(" **FAIL** REQUIRED Default%s\n"
500 " REF: Page 40, section 4.5.\n"),
501 option->keyword);
502 }
503
504 errors ++;
505 }
506 }
507
508 if (ppdFindAttr(ppd, "FileVersion", NULL) != NULL)
509 {
510 if (verbose > 0)
511 _cupsLangPuts(stdout, _(" PASS FileVersion\n"));
512 }
513 else
514 {
515 if (verbose >= 0)
516 {
517 if (!errors && !verbose)
518 _cupsLangPuts(stdout, _(" FAIL\n"));
519
520 _cupsLangPuts(stdout,
521 _(" **FAIL** REQUIRED FileVersion\n"
522 " REF: Page 56, section 5.3.\n"));
523 }
524
525 errors ++;
526 }
527
528 if (ppdFindAttr(ppd, "FormatVersion", NULL) != NULL)
529 {
530 if (verbose > 0)
531 _cupsLangPuts(stdout, _(" PASS FormatVersion\n"));
532 }
533 else
534 {
535 if (verbose >= 0)
536 {
537 if (!errors && !verbose)
538 _cupsLangPuts(stdout, _(" FAIL\n"));
539
540 _cupsLangPuts(stdout,
541 _(" **FAIL** REQUIRED FormatVersion\n"
542 " REF: Page 56, section 5.3.\n"));
543 }
544
545 errors ++;
546 }
547
548 if (ppd->lang_encoding != NULL)
549 {
550 if (verbose > 0)
551 _cupsLangPuts(stdout, _(" PASS LanguageEncoding\n"));
552 }
553 else if (ppdversion > 40)
554 {
555 if (verbose >= 0)
556 {
557 if (!errors && !verbose)
558 _cupsLangPuts(stdout, _(" FAIL\n"));
559
560 _cupsLangPuts(stdout,
561 _(" **FAIL** REQUIRED LanguageEncoding\n"
562 " REF: Pages 56-57, section 5.3.\n"));
563 }
564
565 errors ++;
566 }
567
568 if (ppd->lang_version != NULL)
569 {
570 if (verbose > 0)
571 _cupsLangPuts(stdout, _(" PASS LanguageVersion\n"));
572 }
573 else
574 {
575 if (verbose >= 0)
576 {
577 if (!errors && !verbose)
578 _cupsLangPuts(stdout, _(" FAIL\n"));
579
580 _cupsLangPuts(stdout,
581 _(" **FAIL** REQUIRED LanguageVersion\n"
582 " REF: Pages 57-58, section 5.3.\n"));
583 }
584
585 errors ++;
586 }
587
588 if (ppd->manufacturer != NULL)
589 {
590 if (!strncasecmp(ppd->manufacturer, "Hewlett-Packard", 15) ||
591 !strncasecmp(ppd->manufacturer, "Hewlett Packard", 15))
592 {
593 if (verbose >= 0)
594 {
595 if (!errors && !verbose)
596 _cupsLangPuts(stdout, _(" FAIL\n"));
597
598 _cupsLangPuts(stdout,
599 _(" **FAIL** BAD Manufacturer (should be "
600 "\"HP\")\n"
601 " REF: Page 211, table D.1.\n"));
602 }
603
604 errors ++;
605 }
606 else if (!strncasecmp(ppd->manufacturer, "OkiData", 7) ||
607 !strncasecmp(ppd->manufacturer, "Oki Data", 8))
608 {
609 if (verbose >= 0)
610 {
611 if (!errors && !verbose)
612 _cupsLangPuts(stdout, _(" FAIL\n"));
613
614 _cupsLangPuts(stdout,
615 _(" **FAIL** BAD Manufacturer (should be "
616 "\"Oki\")\n"
617 " REF: Page 211, table D.1.\n"));
618 }
619
620 errors ++;
621 }
622 else if (verbose > 0)
623 _cupsLangPuts(stdout, _(" PASS Manufacturer\n"));
624 }
625 else if (ppdversion >= 43)
626 {
627 if (verbose >= 0)
628 {
629 if (!errors && !verbose)
630 _cupsLangPuts(stdout, _(" FAIL\n"));
631
632 _cupsLangPuts(stdout,
633 _(" **FAIL** REQUIRED Manufacturer\n"
634 " REF: Pages 58-59, section 5.3.\n"));
635 }
636
637 errors ++;
638 }
639
640 if (ppd->modelname != NULL)
641 {
642 for (ptr = ppd->modelname; *ptr; ptr ++)
643 if (!isalnum(*ptr & 255) && !strchr(" ./-+", *ptr))
644 break;
645
646 if (*ptr)
647 {
648 if (verbose >= 0)
649 {
650 if (!errors && !verbose)
651 _cupsLangPuts(stdout, _(" FAIL\n"));
652
653 _cupsLangPrintf(stdout,
654 _(" **FAIL** BAD ModelName - \"%c\" not "
655 "allowed in string.\n"
656 " REF: Pages 59-60, section 5.3.\n"),
657 *ptr);
658 }
659
660 errors ++;
661 }
662 else if (verbose > 0)
663 _cupsLangPuts(stdout, _(" PASS ModelName\n"));
664 }
665 else
666 {
667 if (verbose >= 0)
668 {
669 if (!errors && !verbose)
670 _cupsLangPuts(stdout, _(" FAIL\n"));
671
672 _cupsLangPuts(stdout,
673 _(" **FAIL** REQUIRED ModelName\n"
674 " REF: Pages 59-60, section 5.3.\n"));
675 }
676
677 errors ++;
678 }
679
680 if (ppd->nickname != NULL)
681 {
682 if (verbose > 0)
683 _cupsLangPuts(stdout, _(" PASS NickName\n"));
684 }
685 else
686 {
687 if (verbose >= 0)
688 {
689 if (!errors && !verbose)
690 _cupsLangPuts(stdout, _(" FAIL\n"));
691
692 _cupsLangPuts(stdout,
693 _(" **FAIL** REQUIRED NickName\n"
694 " REF: Page 60, section 5.3.\n"));
695 }
696
697 errors ++;
698 }
699
700 if (ppdFindOption(ppd, "PageSize") != NULL)
701 {
702 if (verbose > 0)
703 _cupsLangPuts(stdout, _(" PASS PageSize\n"));
704 }
705 else
706 {
707 if (verbose >= 0)
708 {
709 if (!errors && !verbose)
710 _cupsLangPuts(stdout, _(" FAIL\n"));
711
712 _cupsLangPuts(stdout,
713 _(" **FAIL** REQUIRED PageSize\n"
714 " REF: Pages 99-100, section 5.14.\n"));
715 }
716
717 errors ++;
718 }
719
720 if (ppdFindOption(ppd, "PageRegion") != NULL)
721 {
722 if (verbose > 0)
723 _cupsLangPuts(stdout, _(" PASS PageRegion\n"));
724 }
725 else
726 {
727 if (verbose >= 0)
728 {
729 if (!errors && !verbose)
730 _cupsLangPuts(stdout, _(" FAIL\n"));
731
732 _cupsLangPuts(stdout,
733 _(" **FAIL** REQUIRED PageRegion\n"
734 " REF: Page 100, section 5.14.\n"));
735 }
736
737 errors ++;
738 }
739
740 if (ppd->pcfilename != NULL)
741 {
742 if (verbose > 0)
743 _cupsLangPuts(stdout, _(" PASS PCFileName\n"));
744 }
745 else
746 {
747 if (verbose >= 0)
748 {
749 if (!errors && !verbose)
750 _cupsLangPuts(stdout, _(" FAIL\n"));
751
752 _cupsLangPuts(stdout,
753 _(" **FAIL** REQUIRED PCFileName\n"
754 " REF: Pages 61-62, section 5.3.\n"));
755 }
756
757 errors ++;
758 }
759
760 if (ppd->product != NULL)
761 {
762 if (ppd->product[0] != '(' ||
763 ppd->product[strlen(ppd->product) - 1] != ')')
764 {
765 if (verbose >= 0)
766 {
767 if (!errors && !verbose)
768 _cupsLangPuts(stdout, _(" FAIL\n"));
769
770 _cupsLangPuts(stdout,
771 _(" **FAIL** BAD Product - not \"(string)\".\n"
772 " REF: Page 62, section 5.3.\n"));
773 }
774
775 errors ++;
776 }
777 else if (verbose > 0)
778 _cupsLangPuts(stdout, _(" PASS Product\n"));
779 }
780 else
781 {
782 if (verbose >= 0)
783 {
784 if (!errors && !verbose)
785 _cupsLangPuts(stdout, _(" FAIL\n"));
786
787 _cupsLangPuts(stdout,
788 _(" **FAIL** REQUIRED Product\n"
789 " REF: Page 62, section 5.3.\n"));
790 }
791
792 errors ++;
793 }
794
795 if ((attr = ppdFindAttr(ppd, "PSVersion", NULL)) != NULL &&
796 attr->value != NULL)
797 {
798 char junkstr[255]; /* Temp string */
799 int junkint; /* Temp integer */
800
801
802 if (sscanf(attr->value, "(%[^)])%d", junkstr, &junkint) != 2)
803 {
804 if (verbose >= 0)
805 {
806 if (!errors && !verbose)
807 _cupsLangPuts(stdout, _(" FAIL\n"));
808
809 _cupsLangPuts(stdout,
810 _(" **FAIL** BAD PSVersion - not \"(string) "
811 "int\".\n"
812 " REF: Pages 62-64, section 5.3.\n"));
813 }
814
815 errors ++;
816 }
817 else if (verbose > 0)
818 _cupsLangPuts(stdout, _(" PASS PSVersion\n"));
819 }
820 else
821 {
822 if (verbose >= 0)
823 {
824 if (!errors && !verbose)
825 _cupsLangPuts(stdout, _(" FAIL\n"));
826
827 _cupsLangPuts(stdout,
828 _(" **FAIL** REQUIRED PSVersion\n"
829 " REF: Pages 62-64, section 5.3.\n"));
830 }
831
832 errors ++;
833 }
834
835 if (ppd->shortnickname != NULL)
836 {
837 if (strlen(ppd->shortnickname) > 31)
838 {
839 if (verbose >= 0)
840 {
841 if (!errors && !verbose)
842 _cupsLangPuts(stdout, _(" FAIL\n"));
843
844 _cupsLangPuts(stdout,
845 _(" **FAIL** BAD ShortNickName - longer "
846 "than 31 chars.\n"
847 " REF: Pages 64-65, section 5.3.\n"));
848 }
849
850 errors ++;
851 }
852 else if (verbose > 0)
853 _cupsLangPuts(stdout, _(" PASS ShortNickName\n"));
854 }
855 else if (ppdversion >= 43)
856 {
857 if (verbose >= 0)
858 {
859 if (!errors && !verbose)
860 _cupsLangPuts(stdout, _(" FAIL\n"));
861
862 _cupsLangPuts(stdout,
863 _(" **FAIL** REQUIRED ShortNickName\n"
864 " REF: Page 64-65, section 5.3.\n"));
865 }
866
867 errors ++;
868 }
869
870 if (ppd->patches != NULL && strchr(ppd->patches, '\"') &&
871 strstr(ppd->patches, "*End"))
872 {
873 if (verbose >= 0)
874 {
875 if (!errors && !verbose)
876 _cupsLangPuts(stdout, _(" FAIL\n"));
877
878 _cupsLangPuts(stdout,
879 _(" **FAIL** BAD JobPatchFile attribute in file\n"
880 " REF: Page 24, section 3.4.\n"));
881 }
882
883 errors ++;
884 }
885
886 /*
887 * Check for page sizes without the corresponding ImageableArea or
888 * PaperDimension values...
889 */
890
891 if (ppd->num_sizes == 0)
892 {
893 if (verbose >= 0)
894 {
895 if (!errors && !verbose)
896 _cupsLangPuts(stdout, _(" FAIL\n"));
897
898 _cupsLangPuts(stdout,
899 _(" **FAIL** REQUIRED PageSize\n"
900 " REF: Page 41, section 5.\n"
901 " REF: Page 99, section 5.14.\n"));
902 }
903
904 errors ++;
905 }
906 else
907 {
908 for (j = 0, size = ppd->sizes; j < ppd->num_sizes; j ++, size ++)
909 {
910 /*
911 * Don't check custom size...
912 */
913
914 if (!strcmp(size->name, "Custom"))
915 continue;
916
917 /*
918 * Check for ImageableArea...
919 */
920
921 if (size->left == 0.0 && size->bottom == 0.0 &&
922 size->right == 0.0 && size->top == 0.0)
923 {
924 if (verbose >= 0)
925 {
926 if (!errors && !verbose)
927 _cupsLangPuts(stdout, _(" FAIL\n"));
928
929 _cupsLangPrintf(stdout,
930 _(" **FAIL** REQUIRED ImageableArea for "
931 "PageSize %s\n"
932 " REF: Page 41, section 5.\n"
933 " REF: Page 102, section 5.15.\n"),
934 size->name);
935 }
936
937 errors ++;
938 }
939
940 /*
941 * Check for PaperDimension...
942 */
943
944 if (size->width == 0.0 && size->length == 0.0)
945 {
946 if (verbose >= 0)
947 {
948 if (!errors && !verbose)
949 _cupsLangPuts(stdout, _(" FAIL\n"));
950
951 _cupsLangPrintf(stdout,
952 _(" **FAIL** REQUIRED PaperDimension "
953 "for PageSize %s\n"
954 " REF: Page 41, section 5.\n"
955 " REF: Page 103, section 5.15.\n"),
956 size->name);
957 }
958
959 errors ++;
960 }
961 }
962 }
963
964 /*
965 * Check for valid Resolution, JCLResolution, or SetResolution values...
966 */
967
968 if ((option = ppdFindOption(ppd, "Resolution")) == NULL)
969 if ((option = ppdFindOption(ppd, "JCLResolution")) == NULL)
970 option = ppdFindOption(ppd, "SetResolution");
971
972 if (option != NULL)
973 {
974 for (j = option->num_choices, choice = option->choices; j > 0; j --, choice ++)
975 {
976 /*
977 * Verify that all resolution options are of the form NNNdpi
978 * or NNNxNNNdpi...
979 */
980
981 xdpi = strtol(choice->choice, (char **)&ptr, 10);
982 if (ptr > choice->choice && xdpi > 0)
983 {
984 if (*ptr == 'x')
985 ydpi = strtol(ptr + 1, (char **)&ptr, 10);
986 else
987 ydpi = xdpi;
988 }
989 else
990 ydpi = xdpi;
991
992 if (xdpi <= 0 || xdpi > 99999 || ydpi <= 0 || ydpi > 99999 ||
993 strcmp(ptr, "dpi"))
994 {
995 if (verbose >= 0)
996 {
997 if (!errors && !verbose)
998 _cupsLangPuts(stdout, _(" FAIL\n"));
999
1000 _cupsLangPrintf(stdout,
1001 _(" **FAIL** Bad %s choice %s!\n"
1002 " REF: Page 84, section 5.9\n"),
1003 option->keyword, choice->choice);
1004 }
1005
1006 errors ++;
1007 }
1008 }
1009 }
1010
1011 /*
1012 * Check for a duplex option, and for standard values...
1013 */
1014
1015 if ((option = ppdFindOption(ppd, "Duplex")) == NULL)
1016 if ((option = ppdFindOption(ppd, "JCLDuplex")) == NULL)
1017 if ((option = ppdFindOption(ppd, "EFDuplex")) == NULL)
1018 option = ppdFindOption(ppd, "KD03Duplex");
1019
1020 if (option != NULL)
1021 {
1022 if (ppdFindChoice(option, "None") == NULL)
1023 {
1024 if (verbose >= 0)
1025 {
1026 if (!errors && !verbose)
1027 _cupsLangPuts(stdout, _(" FAIL\n"));
1028
1029 _cupsLangPrintf(stdout,
1030 _(" **FAIL** REQUIRED %s does not define "
1031 "choice None!\n"
1032 " REF: Page 122, section 5.17\n"),
1033 option->keyword);
1034 }
1035
1036 errors ++;
1037 }
1038
1039 for (j = option->num_choices, choice = option->choices; j > 0; j --, choice ++)
1040 if (strcmp(choice->choice, "None") &&
1041 strcmp(choice->choice, "DuplexNoTumble") &&
1042 strcmp(choice->choice, "DuplexTumble") &&
1043 strcmp(choice->choice, "SimplexTumble"))
1044 {
1045 if (verbose >= 0)
1046 {
1047 if (!errors && !verbose)
1048 _cupsLangPuts(stdout, _(" FAIL\n"));
1049
1050 _cupsLangPrintf(stdout,
1051 _(" **FAIL** Bad %s choice %s!\n"
1052 " REF: Page 122, section 5.17\n"),
1053 option->keyword, choice->choice);
1054 }
1055
1056 errors ++;
1057 }
1058 }
1059
1060 if ((attr = ppdFindAttr(ppd, "1284DeviceID", NULL)) &&
1061 strcmp(attr->name, "1284DeviceID"))
1062 {
1063 if (verbose >= 0)
1064 {
1065 if (!errors && !verbose)
1066 _cupsLangPuts(stdout, _(" FAIL\n"));
1067
1068 _cupsLangPrintf(stdout,
1069 _(" **FAIL** %s must be 1284DeviceID!\n"
1070 " REF: Page 72, section 5.5\n"),
1071 attr->name);
1072 }
1073
1074 errors ++;
1075 }
1076
1077 if (!(warn & WARN_CONSTRAINTS))
1078 errors = check_constraints(ppd, errors, verbose, 0);
1079
1080 if (!(warn & WARN_FILTERS))
1081 errors = check_filters(ppd, root, errors, verbose, 0);
1082
1083 if (!(warn & WARN_PROFILES))
1084 errors = check_profiles(ppd, root, errors, verbose, 0);
1085
1086 if (!(warn & WARN_TRANSLATIONS))
1087 errors = check_translations(ppd, errors, verbose, 0);
1088
1089 if ((attr = ppdFindAttr(ppd, "cupsLanguages", NULL)) != NULL &&
1090 attr->value)
1091 {
1092 /*
1093 * This file contains localizations, check for conformance of the
1094 * base translation...
1095 */
1096
1097 if ((attr = ppdFindAttr(ppd, "LanguageEncoding", NULL)) != NULL)
1098 {
1099 if (!attr->value || strcmp(attr->value, "ISOLatin1"))
1100 {
1101 if (!errors && !verbose)
1102 _cupsLangPuts(stdout, _(" FAIL\n"));
1103
1104 if (verbose >= 0)
1105 _cupsLangPrintf(stdout,
1106 _(" **FAIL** Bad LanguageEncoding %s - "
1107 "must be ISOLatin1!\n"),
1108 attr->value ? attr->value : "(null)");
1109
1110 errors ++;
1111 }
1112
1113 if (!ppd->lang_version || strcmp(ppd->lang_version, "English"))
1114 {
1115 if (!errors && !verbose)
1116 _cupsLangPuts(stdout, _(" FAIL\n"));
1117
1118 if (verbose >= 0)
1119 _cupsLangPrintf(stdout,
1120 _(" **FAIL** Bad LanguageVersion %s - "
1121 "must be English!\n"),
1122 ppd->lang_version ? ppd->lang_version : "(null)");
1123
1124 errors ++;
1125 }
1126
1127 /*
1128 * Loop through all options and choices...
1129 */
1130
1131 for (option = ppdFirstOption(ppd);
1132 option;
1133 option = ppdNextOption(ppd))
1134 {
1135 /*
1136 * Check for special characters outside A0 to BF, F7, or F8
1137 * that are used for languages other than English.
1138 */
1139
1140 for (ptr = option->text; *ptr; ptr ++)
1141 if ((*ptr & 0x80) && (*ptr & 0xe0) != 0xa0 &&
1142 (*ptr & 0xff) != 0xf7 && (*ptr & 0xff) != 0xf8)
1143 break;
1144
1145 if (*ptr)
1146 {
1147 if (!errors && !verbose)
1148 _cupsLangPuts(stdout, _(" FAIL\n"));
1149
1150 if (verbose >= 0)
1151 _cupsLangPrintf(stdout,
1152 _(" **FAIL** Default translation "
1153 "string for option %s contains 8-bit "
1154 "characters!\n"),
1155 option->keyword);
1156
1157 errors ++;
1158 }
1159
1160 for (j = 0; j < option->num_choices; j ++)
1161 {
1162 /*
1163 * Check for special characters outside A0 to BF, F7, or F8
1164 * that are used for languages other than English.
1165 */
1166
1167 for (ptr = option->choices[j].text; *ptr; ptr ++)
1168 if ((*ptr & 0x80) && (*ptr & 0xe0) != 0xa0 &&
1169 (*ptr & 0xff) != 0xf7 && (*ptr & 0xff) != 0xf8)
1170 break;
1171
1172 if (*ptr)
1173 {
1174 if (!errors && !verbose)
1175 _cupsLangPuts(stdout, _(" FAIL\n"));
1176
1177 if (verbose >= 0)
1178 _cupsLangPrintf(stdout,
1179 _(" **FAIL** Default translation "
1180 "string for option %s choice %s contains "
1181 "8-bit characters!\n"),
1182 option->keyword,
1183 option->choices[j].choice);
1184
1185 errors ++;
1186 }
1187 }
1188 }
1189 }
1190 }
1191
1192 /*
1193 * Final pass/fail notification...
1194 */
1195
1196 if (errors)
1197 status = ERROR_CONFORMANCE;
1198 else if (!verbose)
1199 _cupsLangPuts(stdout, _(" PASS\n"));
1200
1201 if (verbose >= 0)
1202 {
1203 check_basics(argv[i]);
1204
1205 if (warn & WARN_CONSTRAINTS)
1206 errors = check_constraints(ppd, errors, verbose, 1);
1207
1208 if (warn & WARN_DEFAULTS)
1209 errors = check_defaults(ppd, errors, verbose, 1);
1210
1211 if (warn & WARN_PROFILES)
1212 errors = check_profiles(ppd, root, errors, verbose, 1);
1213
1214 if (warn & WARN_FILTERS)
1215 errors = check_filters(ppd, root, errors, verbose, 1);
1216
1217 if (warn & WARN_TRANSLATIONS)
1218 errors = check_translations(ppd, errors, verbose, 1);
1219
1220 /*
1221 * Look for default keywords with no corresponding option...
1222 */
1223
1224 for (j = 0; j < ppd->num_attrs; j ++)
1225 {
1226 attr = ppd->attrs[j];
1227
1228 if (!strcmp(attr->name, "DefaultColorSpace") ||
1229 !strcmp(attr->name, "DefaultColorSep") ||
1230 !strcmp(attr->name, "DefaultFont") ||
1231 !strcmp(attr->name, "DefaultHalftoneType") ||
1232 !strcmp(attr->name, "DefaultImageableArea") ||
1233 !strcmp(attr->name, "DefaultLeadingEdge") ||
1234 !strcmp(attr->name, "DefaultOutputOrder") ||
1235 !strcmp(attr->name, "DefaultPaperDimension") ||
1236 !strcmp(attr->name, "DefaultResolution") ||
1237 !strcmp(attr->name, "DefaultScreenProc") ||
1238 !strcmp(attr->name, "DefaultTransfer"))
1239 continue;
1240
1241 if (!strncmp(attr->name, "Default", 7) &&
1242 !ppdFindOption(ppd, attr->name + 7))
1243 _cupsLangPrintf(stdout,
1244 _(" WARN %s has no corresponding "
1245 "options!\n"),
1246 attr->name);
1247 }
1248
1249 /*
1250 * Check for old Duplex option names...
1251 */
1252
1253 if ((option = ppdFindOption(ppd, "EFDuplex")) == NULL)
1254 option = ppdFindOption(ppd, "KD03Duplex");
1255
1256 if (option)
1257 {
1258 _cupsLangPrintf(stdout,
1259 _(" WARN Duplex option keyword %s "
1260 "should be named Duplex or JCLDuplex!\n"
1261 " REF: Page 122, section 5.17\n"),
1262 option->keyword);
1263 }
1264
1265 ppdMarkDefaults(ppd);
1266 if (ppdConflicts(ppd))
1267 {
1268 _cupsLangPuts(stdout,
1269 _(" WARN Default choices conflicting!\n"));
1270
1271 show_conflicts(ppd);
1272 }
1273
1274 if (ppdversion < 43)
1275 {
1276 _cupsLangPrintf(stdout,
1277 _(" WARN Obsolete PPD version %.1f!\n"
1278 " REF: Page 42, section 5.2.\n"),
1279 0.1f * ppdversion);
1280 }
1281
1282 if (!ppd->lang_encoding && ppdversion < 41)
1283 {
1284 _cupsLangPuts(stdout,
1285 _(" WARN LanguageEncoding required by PPD "
1286 "4.3 spec.\n"
1287 " REF: Pages 56-57, section 5.3.\n"));
1288 }
1289
1290 if (!ppd->manufacturer && ppdversion < 43)
1291 {
1292 _cupsLangPuts(stdout,
1293 _(" WARN Manufacturer required by PPD "
1294 "4.3 spec.\n"
1295 " REF: Pages 58-59, section 5.3.\n"));
1296 }
1297
1298 /*
1299 * Treat a PCFileName attribute longer than 12 characters as
1300 * a warning and not a hard error...
1301 */
1302
1303 if (ppd->pcfilename && strlen(ppd->pcfilename) > 12)
1304 {
1305 _cupsLangPuts(stdout,
1306 _(" WARN PCFileName longer than 8.3 in "
1307 "violation of PPD spec.\n"
1308 " REF: Pages 61-62, section 5.3.\n"));
1309 }
1310
1311 if (!ppd->shortnickname && ppdversion < 43)
1312 {
1313 _cupsLangPuts(stdout,
1314 _(" WARN ShortNickName required by PPD "
1315 "4.3 spec.\n"
1316 " REF: Pages 64-65, section 5.3.\n"));
1317 }
1318
1319 /*
1320 * Check the Protocols line and flag PJL + BCP since TBCP is
1321 * usually used with PJL...
1322 */
1323
1324 if (ppd->protocols)
1325 {
1326 if (strstr(ppd->protocols, "PJL") &&
1327 strstr(ppd->protocols, "BCP") &&
1328 !strstr(ppd->protocols, "TBCP"))
1329 {
1330 _cupsLangPuts(stdout,
1331 _(" WARN Protocols contains both PJL "
1332 "and BCP; expected TBCP.\n"
1333 " REF: Pages 78-79, section 5.7.\n"));
1334 }
1335
1336 if (strstr(ppd->protocols, "PJL") &&
1337 (!ppd->jcl_begin || !ppd->jcl_end || !ppd->jcl_ps))
1338 {
1339 _cupsLangPuts(stdout,
1340 _(" WARN Protocols contains PJL but JCL "
1341 "attributes are not set.\n"
1342 " REF: Pages 78-79, section 5.7.\n"));
1343 }
1344 }
1345
1346 /*
1347 * Check for options with a common prefix, e.g. Duplex and Duplexer,
1348 * which are errors according to the spec but won't cause problems
1349 * with CUPS specifically...
1350 */
1351
1352 for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++)
1353 for (k = 0, option = group->options; k < group->num_options; k ++, option ++)
1354 {
1355 len = strlen(option->keyword);
1356
1357 for (m = 0, group2 = ppd->groups;
1358 m < ppd->num_groups;
1359 m ++, group2 ++)
1360 for (n = 0, option2 = group2->options;
1361 n < group2->num_options;
1362 n ++, option2 ++)
1363 if (option != option2 &&
1364 len < strlen(option2->keyword) &&
1365 !strncmp(option->keyword, option2->keyword, len))
1366 {
1367 _cupsLangPrintf(stdout,
1368 _(" WARN %s shares a common "
1369 "prefix with %s\n"
1370 " REF: Page 15, section "
1371 "3.2.\n"),
1372 option->keyword, option2->keyword);
1373 }
1374 }
1375 }
1376
1377 #ifdef __APPLE__
1378 /*
1379 * APDialogExtension
1380 */
1381
1382 for (attr = ppdFindAttr(ppd, "APDialogExtension", NULL);
1383 attr != NULL;
1384 attr = ppdFindNextAttr(ppd, "APDialogExtension", NULL))
1385 {
1386 if ((!attr->value || access(attr->value, 0)) && verbose >= 0)
1387 _cupsLangPrintf(stdout, _(" WARN Missing "
1388 "APDialogExtension file \"%s\"\n"),
1389 attr->value ? attr->value : "<NULL>");
1390 }
1391
1392 /*
1393 * APPrinterIconPath
1394 */
1395
1396 for (attr = ppdFindAttr(ppd, "APPrinterIconPath", NULL);
1397 attr != NULL;
1398 attr = ppdFindNextAttr(ppd, "APPrinterIconPath", NULL))
1399 {
1400 if ((!attr->value || access(attr->value, 0)) && verbose >= 0)
1401 _cupsLangPrintf(stdout, _(" WARN Missing "
1402 "APPrinterIconPath file \"%s\"\n"),
1403 attr->value ? attr->value : "<NULL>");
1404 }
1405 #endif /* __APPLE__ */
1406
1407 if (verbose > 0)
1408 {
1409 if (errors)
1410 _cupsLangPrintf(stdout, _(" %d ERRORS FOUND\n"), errors);
1411 else
1412 _cupsLangPuts(stdout, _(" NO ERRORS FOUND\n"));
1413 }
1414
1415 /*
1416 * Then list the options, if "-v" was provided...
1417 */
1418
1419 if (verbose > 1)
1420 {
1421 _cupsLangPrintf(stdout,
1422 "\n"
1423 " language_level = %d\n"
1424 " color_device = %s\n"
1425 " variable_sizes = %s\n"
1426 " landscape = %d\n",
1427 ppd->language_level,
1428 ppd->color_device ? "TRUE" : "FALSE",
1429 ppd->variable_sizes ? "TRUE" : "FALSE",
1430 ppd->landscape);
1431
1432 switch (ppd->colorspace)
1433 {
1434 case PPD_CS_CMYK :
1435 _cupsLangPuts(stdout, " colorspace = PPD_CS_CMYK\n");
1436 break;
1437 case PPD_CS_CMY :
1438 _cupsLangPuts(stdout, " colorspace = PPD_CS_CMY\n");
1439 break;
1440 case PPD_CS_GRAY :
1441 _cupsLangPuts(stdout, " colorspace = PPD_CS_GRAY\n");
1442 break;
1443 case PPD_CS_RGB :
1444 _cupsLangPuts(stdout, " colorspace = PPD_CS_RGB\n");
1445 break;
1446 default :
1447 _cupsLangPuts(stdout, " colorspace = <unknown>\n");
1448 break;
1449 }
1450
1451 _cupsLangPrintf(stdout, " num_emulations = %d\n",
1452 ppd->num_emulations);
1453 for (j = 0; j < ppd->num_emulations; j ++)
1454 _cupsLangPrintf(stdout, " emulations[%d] = %s\n",
1455 j, ppd->emulations[j].name);
1456
1457 _cupsLangPrintf(stdout, " lang_encoding = %s\n",
1458 ppd->lang_encoding);
1459 _cupsLangPrintf(stdout, " lang_version = %s\n",
1460 ppd->lang_version);
1461 _cupsLangPrintf(stdout, " modelname = %s\n", ppd->modelname);
1462 _cupsLangPrintf(stdout, " ttrasterizer = %s\n",
1463 ppd->ttrasterizer == NULL ? "None" : ppd->ttrasterizer);
1464 _cupsLangPrintf(stdout, " manufacturer = %s\n",
1465 ppd->manufacturer);
1466 _cupsLangPrintf(stdout, " product = %s\n", ppd->product);
1467 _cupsLangPrintf(stdout, " nickname = %s\n", ppd->nickname);
1468 _cupsLangPrintf(stdout, " shortnickname = %s\n",
1469 ppd->shortnickname);
1470 _cupsLangPrintf(stdout, " patches = %d bytes\n",
1471 ppd->patches == NULL ? 0 : (int)strlen(ppd->patches));
1472
1473 _cupsLangPrintf(stdout, " num_groups = %d\n", ppd->num_groups);
1474 for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++)
1475 {
1476 _cupsLangPrintf(stdout, " group[%d] = %s\n",
1477 j, group->text);
1478
1479 for (k = 0, option = group->options; k < group->num_options; k ++, option ++)
1480 {
1481 _cupsLangPrintf(stdout,
1482 " options[%d] = %s (%s) %s %s %.0f "
1483 "(%d choices)\n",
1484 k, option->keyword, option->text, uis[option->ui],
1485 sections[option->section], option->order,
1486 option->num_choices);
1487
1488 if (!strcmp(option->keyword, "PageSize") ||
1489 !strcmp(option->keyword, "PageRegion"))
1490 {
1491 for (m = option->num_choices, choice = option->choices;
1492 m > 0;
1493 m --, choice ++)
1494 {
1495 size = ppdPageSize(ppd, choice->choice);
1496
1497 if (size == NULL)
1498 _cupsLangPrintf(stdout,
1499 " %s (%s) = ERROR",
1500 choice->choice, choice->text);
1501 else
1502 _cupsLangPrintf(stdout,
1503 " %s (%s) = %.2fx%.2fin "
1504 "(%.1f,%.1f,%.1f,%.1f)",
1505 choice->choice, choice->text,
1506 size->width / 72.0, size->length / 72.0,
1507 size->left / 72.0, size->bottom / 72.0,
1508 size->right / 72.0, size->top / 72.0);
1509
1510 if (!strcmp(option->defchoice, choice->choice))
1511 _cupsLangPuts(stdout, " *\n");
1512 else
1513 _cupsLangPuts(stdout, "\n");
1514 }
1515 }
1516 else
1517 {
1518 for (m = option->num_choices, choice = option->choices;
1519 m > 0;
1520 m --, choice ++)
1521 {
1522 _cupsLangPrintf(stdout, " %s (%s)",
1523 choice->choice, choice->text);
1524
1525 if (!strcmp(option->defchoice, choice->choice))
1526 _cupsLangPuts(stdout, " *\n");
1527 else
1528 _cupsLangPuts(stdout, "\n");
1529 }
1530 }
1531 }
1532 }
1533
1534 _cupsLangPrintf(stdout, " num_consts = %d\n",
1535 ppd->num_consts);
1536 for (j = 0; j < ppd->num_consts; j ++)
1537 _cupsLangPrintf(stdout,
1538 " consts[%d] = *%s %s *%s %s\n",
1539 j, ppd->consts[j].option1, ppd->consts[j].choice1,
1540 ppd->consts[j].option2, ppd->consts[j].choice2);
1541
1542 _cupsLangPrintf(stdout, " num_profiles = %d\n",
1543 ppd->num_profiles);
1544 for (j = 0; j < ppd->num_profiles; j ++)
1545 _cupsLangPrintf(stdout,
1546 " profiles[%d] = %s/%s %.3f %.3f "
1547 "[ %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f ]\n",
1548 j, ppd->profiles[j].resolution,
1549 ppd->profiles[j].media_type,
1550 ppd->profiles[j].gamma, ppd->profiles[j].density,
1551 ppd->profiles[j].matrix[0][0],
1552 ppd->profiles[j].matrix[0][1],
1553 ppd->profiles[j].matrix[0][2],
1554 ppd->profiles[j].matrix[1][0],
1555 ppd->profiles[j].matrix[1][1],
1556 ppd->profiles[j].matrix[1][2],
1557 ppd->profiles[j].matrix[2][0],
1558 ppd->profiles[j].matrix[2][1],
1559 ppd->profiles[j].matrix[2][2]);
1560
1561 _cupsLangPrintf(stdout, " num_fonts = %d\n", ppd->num_fonts);
1562 for (j = 0; j < ppd->num_fonts; j ++)
1563 _cupsLangPrintf(stdout, " fonts[%d] = %s\n",
1564 j, ppd->fonts[j]);
1565
1566 _cupsLangPrintf(stdout, " num_attrs = %d\n", ppd->num_attrs);
1567 for (j = 0; j < ppd->num_attrs; j ++)
1568 _cupsLangPrintf(stdout,
1569 " attrs[%d] = %s %s%s%s: \"%s\"\n", j,
1570 ppd->attrs[j]->name, ppd->attrs[j]->spec,
1571 ppd->attrs[j]->text[0] ? "/" : "",
1572 ppd->attrs[j]->text,
1573 ppd->attrs[j]->value ?
1574 ppd->attrs[j]->value : "(null)");
1575 }
1576
1577 ppdClose(ppd);
1578 }
1579
1580 if (!files)
1581 usage();
1582
1583 return (status);
1584 }
1585
1586
1587 /*
1588 * 'check_basics()' - Check for CR LF, mixed line endings, and blank lines.
1589 */
1590
1591 static void
1592 check_basics(const char *filename) /* I - PPD file to check */
1593 {
1594 cups_file_t *fp; /* File pointer */
1595 int ch; /* Current character */
1596 int col, /* Current column */
1597 whitespace; /* Only seen whitespace? */
1598 int eol; /* Line endings */
1599 int linenum; /* Line number */
1600 int mixed; /* Mixed line endings? */
1601
1602
1603 if ((fp = cupsFileOpen(filename, "r")) == NULL)
1604 return;
1605
1606 linenum = 1;
1607 col = 0;
1608 eol = EOL_NONE;
1609 mixed = 0;
1610 whitespace = 1;
1611
1612 while ((ch = cupsFileGetChar(fp)) != EOF)
1613 {
1614 if (ch == '\r' || ch == '\n')
1615 {
1616 if (ch == '\n')
1617 {
1618 if (eol == EOL_NONE)
1619 eol = EOL_LF;
1620 else if (eol != EOL_LF)
1621 mixed = 1;
1622 }
1623 else if (ch == '\r')
1624 {
1625 if (cupsFilePeekChar(fp) == '\n')
1626 {
1627 cupsFileGetChar(fp);
1628
1629 if (eol == EOL_NONE)
1630 eol = EOL_CRLF;
1631 else if (eol != EOL_CRLF)
1632 mixed = 1;
1633 }
1634 else if (eol == EOL_NONE)
1635 eol = EOL_CR;
1636 else if (eol != EOL_CR)
1637 mixed = 1;
1638 }
1639
1640 if (col > 0 && whitespace)
1641 _cupsLangPrintf(stdout,
1642 _(" WARN Line %d only contains whitespace!\n"),
1643 linenum);
1644
1645 linenum ++;
1646 col = 0;
1647 whitespace = 1;
1648 }
1649 else
1650 {
1651 if (ch != ' ' && ch != '\t')
1652 whitespace = 0;
1653
1654 col ++;
1655 }
1656 }
1657
1658 if (mixed)
1659 _cupsLangPuts(stdout,
1660 _(" WARN File contains a mix of CR, LF, and "
1661 "CR LF line endings!\n"));
1662
1663 if (eol == EOL_CRLF)
1664 _cupsLangPuts(stdout,
1665 _(" WARN Non-Windows PPD files should use lines "
1666 "ending with only LF, not CR LF!\n"));
1667
1668 cupsFileClose(fp);
1669 }
1670
1671
1672 /*
1673 * 'check_constraints()' - Check UIConstraints in the PPD file.
1674 */
1675
1676 static int /* O - Errors found */
1677 check_constraints(ppd_file_t *ppd, /* I - PPD file */
1678 int errors, /* I - Errors found */
1679 int verbose, /* I - Verbosity level */
1680 int warn) /* I - Warnings only? */
1681 {
1682 int i; /* Looping var */
1683 const char *prefix; /* WARN/FAIL prefix */
1684 ppd_const_t *c; /* Current UIConstraints data */
1685 ppd_attr_t *constattr; /* Current cupsUIConstraints attribute */
1686 const char *vptr; /* Pointer into constraint value */
1687 char option[PPD_MAX_NAME],
1688 /* Option name/MainKeyword */
1689 choice[PPD_MAX_NAME],
1690 /* Choice/OptionKeyword */
1691 *ptr; /* Pointer into option or choice */
1692 int num_options; /* Number of options */
1693 cups_option_t *options; /* Options */
1694 ppd_option_t *o; /* PPD option */
1695
1696
1697 prefix = warn ? " WARN " : "**FAIL**";
1698
1699
1700 /*
1701 * See what kind of constraint data we have in the PPD...
1702 */
1703
1704 if ((constattr = ppdFindAttr(ppd, "cupsUIConstraints", NULL)) != NULL)
1705 {
1706 /*
1707 * Check new-style cupsUIConstraints data...
1708 */
1709
1710 for (; constattr;
1711 constattr = ppdFindNextAttr(ppd, "cupsUIConstraints", NULL))
1712 {
1713 if (!constattr->value)
1714 {
1715 if (!warn && !errors && !verbose)
1716 _cupsLangPuts(stdout, _(" FAIL\n"));
1717
1718 _cupsLangPrintf(stdout,
1719 _(" %s Empty cupsUIConstraints %s!\n"),
1720 prefix, constattr->spec);
1721
1722 if (!warn)
1723 errors ++;
1724
1725 continue;
1726 }
1727
1728 for (i = 0, vptr = strchr(constattr->value, '*');
1729 vptr;
1730 i ++, vptr = strchr(vptr + 1, '*'));
1731
1732 if (i == 0)
1733 {
1734 if (!warn && !errors && !verbose)
1735 _cupsLangPuts(stdout, _(" FAIL\n"));
1736
1737 _cupsLangPrintf(stdout,
1738 _(" %s Bad cupsUIConstraints %s: \"%s\"!\n"),
1739 prefix, constattr->spec, constattr->value);
1740
1741 if (!warn)
1742 errors ++;
1743
1744 continue;
1745 }
1746
1747 cupsArraySave(ppd->sorted_attrs);
1748
1749 if (constattr->spec[0] &&
1750 !ppdFindAttr(ppd, "cupsUIResolver", constattr->spec))
1751 {
1752 if (!warn && !errors && !verbose)
1753 _cupsLangPuts(stdout, _(" FAIL\n"));
1754
1755 _cupsLangPrintf(stdout,
1756 _(" %s Missing cupsUIResolver %s!\n"),
1757 prefix, constattr->spec);
1758
1759 if (!warn)
1760 errors ++;
1761 }
1762
1763 cupsArrayRestore(ppd->sorted_attrs);
1764
1765 num_options = 0;
1766 options = NULL;
1767
1768 for (vptr = strchr(constattr->value, '*');
1769 vptr;
1770 vptr = strchr(vptr, '*'))
1771 {
1772 /*
1773 * Extract "*Option Choice" or just "*Option"...
1774 */
1775
1776 for (vptr ++, ptr = option; *vptr && !isspace(*vptr & 255); vptr ++)
1777 if (ptr < (option + sizeof(option) - 1))
1778 *ptr++ = *vptr;
1779
1780 *ptr = '\0';
1781
1782 while (isspace(*vptr & 255))
1783 vptr ++;
1784
1785 if (*vptr == '*')
1786 choice[0] = '\0';
1787 else
1788 {
1789 for (ptr = choice; *vptr && !isspace(*vptr & 255); vptr ++)
1790 if (ptr < (choice + sizeof(choice) - 1))
1791 *ptr++ = *vptr;
1792
1793 *ptr = '\0';
1794 }
1795
1796 if (!strncasecmp(option, "Custom", 6) && !strcasecmp(choice, "True"))
1797 {
1798 _cups_strcpy(option, option + 6);
1799 strcpy(choice, "Custom");
1800 }
1801
1802 if ((o = ppdFindOption(ppd, option)) == NULL)
1803 {
1804 if (!warn && !errors && !verbose)
1805 _cupsLangPuts(stdout, _(" FAIL\n"));
1806
1807 _cupsLangPrintf(stdout,
1808 _(" %s Missing option %s in "
1809 "cupsUIConstraints %s: \"%s\"!\n"),
1810 prefix, option, constattr->spec, constattr->value);
1811
1812 if (!warn)
1813 errors ++;
1814
1815 continue;
1816 }
1817
1818 if (choice[0] && !ppdFindChoice(o, choice))
1819 {
1820 if (!warn && !errors && !verbose)
1821 _cupsLangPuts(stdout, _(" FAIL\n"));
1822
1823 _cupsLangPrintf(stdout,
1824 _(" %s Missing choice *%s %s in "
1825 "cupsUIConstraints %s: \"%s\"!\n"),
1826 prefix, option, choice, constattr->spec,
1827 constattr->value);
1828
1829 if (!warn)
1830 errors ++;
1831
1832 continue;
1833 }
1834
1835 if (choice[0])
1836 num_options = cupsAddOption(option, choice, num_options, &options);
1837 else
1838 {
1839 for (i = 0; i < o->num_choices; i ++)
1840 if (strcasecmp(o->choices[i].choice, "None") &&
1841 strcasecmp(o->choices[i].choice, "Off") &&
1842 strcasecmp(o->choices[i].choice, "False"))
1843 {
1844 num_options = cupsAddOption(option, o->choices[i].choice,
1845 num_options, &options);
1846 break;
1847 }
1848 }
1849 }
1850
1851 /*
1852 * Test the resolver...
1853 */
1854
1855 if (!cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options))
1856 {
1857 if (!warn && !errors && !verbose)
1858 _cupsLangPuts(stdout, _(" FAIL\n"));
1859
1860 _cupsLangPrintf(stdout,
1861 _(" %s cupsUIResolver %s causes a loop!\n"),
1862 prefix, constattr->spec);
1863
1864 if (!warn)
1865 errors ++;
1866 }
1867
1868 cupsFreeOptions(num_options, options);
1869 }
1870 }
1871 else
1872 {
1873 /*
1874 * Check old-style [Non]UIConstraints data...
1875 */
1876
1877 for (i = ppd->num_consts, c = ppd->consts; i > 0; i --, c ++)
1878 {
1879 if (!strncasecmp(c->option1, "Custom", 6) &&
1880 !strcasecmp(c->choice1, "True"))
1881 {
1882 strcpy(option, c->option1 + 6);
1883 strcpy(choice, "Custom");
1884 }
1885 else
1886 {
1887 strcpy(option, c->option1);
1888 strcpy(choice, c->choice1);
1889 }
1890
1891 if ((o = ppdFindOption(ppd, option)) == NULL)
1892 {
1893 if (!warn && !errors && !verbose)
1894 _cupsLangPuts(stdout, _(" FAIL\n"));
1895
1896 _cupsLangPrintf(stdout,
1897 _(" %s Missing option %s in "
1898 "UIConstraints \"*%s %s *%s %s\"!\n"),
1899 prefix, c->option1,
1900 c->option1, c->choice1, c->option2, c->choice2);
1901
1902 if (!warn)
1903 errors ++;
1904 }
1905 else if (choice[0] && !ppdFindChoice(o, choice))
1906 {
1907 if (!warn && !errors && !verbose)
1908 _cupsLangPuts(stdout, _(" FAIL\n"));
1909
1910 _cupsLangPrintf(stdout,
1911 _(" %s Missing choice *%s %s in "
1912 "UIConstraints \"*%s %s *%s %s\"!\n"),
1913 prefix, c->option1, c->choice1,
1914 c->option1, c->choice1, c->option2, c->choice2);
1915
1916 if (!warn)
1917 errors ++;
1918 }
1919
1920 if (!strncasecmp(c->option2, "Custom", 6) &&
1921 !strcasecmp(c->choice2, "True"))
1922 {
1923 strcpy(option, c->option2 + 6);
1924 strcpy(choice, "Custom");
1925 }
1926 else
1927 {
1928 strcpy(option, c->option2);
1929 strcpy(choice, c->choice2);
1930 }
1931
1932 if ((o = ppdFindOption(ppd, option)) == NULL)
1933 {
1934 if (!warn && !errors && !verbose)
1935 _cupsLangPuts(stdout, _(" FAIL\n"));
1936
1937 _cupsLangPrintf(stdout,
1938 _(" %s Missing option %s in "
1939 "UIConstraints \"*%s %s *%s %s\"!\n"),
1940 prefix, c->option2,
1941 c->option1, c->choice1, c->option2, c->choice2);
1942
1943 if (!warn)
1944 errors ++;
1945 }
1946 else if (choice[0] && !ppdFindChoice(o, choice))
1947 {
1948 if (!warn && !errors && !verbose)
1949 _cupsLangPuts(stdout, _(" FAIL\n"));
1950
1951 _cupsLangPrintf(stdout,
1952 _(" %s Missing choice *%s %s in "
1953 "UIConstraints \"*%s %s *%s %s\"!\n"),
1954 prefix, c->option2, c->choice2,
1955 c->option1, c->choice1, c->option2, c->choice2);
1956
1957 if (!warn)
1958 errors ++;
1959 }
1960 }
1961 }
1962
1963 return (errors);
1964 }
1965
1966
1967 /*
1968 * 'check_defaults()' - Check default option keywords in the PPD file.
1969 */
1970
1971 static int /* O - Errors found */
1972 check_defaults(ppd_file_t *ppd, /* I - PPD file */
1973 int errors, /* I - Errors found */
1974 int verbose, /* I - Verbosity level */
1975 int warn) /* I - Warnings only? */
1976 {
1977 int j, k; /* Looping vars */
1978 ppd_attr_t *attr; /* PPD attribute */
1979 ppd_option_t *option; /* Standard UI option */
1980 const char *prefix; /* WARN/FAIL prefix */
1981
1982
1983 prefix = warn ? " WARN " : "**FAIL**";
1984
1985 for (j = 0; j < ppd->num_attrs; j ++)
1986 {
1987 attr = ppd->attrs[j];
1988
1989 if (!strcmp(attr->name, "DefaultColorSpace") ||
1990 !strcmp(attr->name, "DefaultFont") ||
1991 !strcmp(attr->name, "DefaultHalftoneType") ||
1992 !strcmp(attr->name, "DefaultImageableArea") ||
1993 !strcmp(attr->name, "DefaultLeadingEdge") ||
1994 !strcmp(attr->name, "DefaultOutputOrder") ||
1995 !strcmp(attr->name, "DefaultPaperDimension") ||
1996 !strcmp(attr->name, "DefaultResolution") ||
1997 !strcmp(attr->name, "DefaultTransfer"))
1998 continue;
1999
2000 if (!strncmp(attr->name, "Default", 7))
2001 {
2002 if ((option = ppdFindOption(ppd, attr->name + 7)) != NULL &&
2003 strcmp(attr->value, "Unknown"))
2004 {
2005 /*
2006 * Check that the default option value matches a choice...
2007 */
2008
2009 for (k = 0; k < option->num_choices; k ++)
2010 if (!strcmp(option->choices[k].choice, attr->value))
2011 break;
2012
2013 if (k >= option->num_choices)
2014 {
2015 if (!warn && !errors && !verbose)
2016 _cupsLangPuts(stdout, _(" FAIL\n"));
2017
2018 if (verbose >= 0)
2019 _cupsLangPrintf(stdout,
2020 _(" %s %s %s does not exist!\n"),
2021 prefix, attr->name, attr->value);
2022
2023 if (!warn)
2024 errors ++;
2025 }
2026 }
2027 }
2028 }
2029
2030 return (errors);
2031 }
2032
2033
2034 /*
2035 * 'check_filters()' - Check filters in the PPD file.
2036 */
2037
2038 static int /* O - Errors found */
2039 check_filters(ppd_file_t *ppd, /* I - PPD file */
2040 const char *root, /* I - Root directory */
2041 int errors, /* I - Errors found */
2042 int verbose, /* I - Verbosity level */
2043 int warn) /* I - Warnings only? */
2044 {
2045 int i; /* Looping var */
2046 ppd_attr_t *attr; /* PPD attribute */
2047 const char *ptr; /* Pointer into string */
2048 char super[16], /* Super-type for filter */
2049 type[256], /* Type for filter */
2050 program[1024], /* Program/filter name */
2051 pathprog[1024]; /* Complete path to program/filter */
2052 int cost; /* Cost of filter */
2053 const char *prefix; /* WARN/FAIL prefix */
2054
2055
2056 prefix = warn ? " WARN " : "**FAIL**";
2057
2058 for (i = 0; i < ppd->num_filters; i ++)
2059 {
2060 if (sscanf(ppd->filters[i], "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type,
2061 &cost, program) != 4)
2062 {
2063 if (!warn && !errors && !verbose)
2064 _cupsLangPuts(stdout, _(" FAIL\n"));
2065
2066 if (verbose >= 0)
2067 _cupsLangPrintf(stdout,
2068 _(" %s Bad cupsFilter value \"%s\"!\n"),
2069 prefix, ppd->filters[i]);
2070
2071 if (!warn)
2072 errors ++;
2073 }
2074 else
2075 {
2076 if (program[0] == '/')
2077 snprintf(pathprog, sizeof(pathprog), "%s%s", root, program);
2078 else
2079 {
2080 if ((ptr = getenv("CUPS_SERVERBIN")) == NULL)
2081 ptr = CUPS_SERVERBIN;
2082
2083 if (*ptr == '/' || !*root)
2084 snprintf(pathprog, sizeof(pathprog), "%s%s/filter/%s", root, ptr,
2085 program);
2086 else
2087 snprintf(pathprog, sizeof(pathprog), "%s/%s/filter/%s", root, ptr,
2088 program);
2089 }
2090
2091 if (access(pathprog, X_OK))
2092 {
2093 if (!warn && !errors && !verbose)
2094 _cupsLangPuts(stdout, _(" FAIL\n"));
2095
2096 if (verbose >= 0)
2097 _cupsLangPrintf(stdout, _(" %s Missing cupsFilter "
2098 "file \"%s\"\n"), prefix, program);
2099
2100 if (!warn)
2101 errors ++;
2102 }
2103 }
2104 }
2105
2106 for (attr = ppdFindAttr(ppd, "cupsPreFilter", NULL);
2107 attr;
2108 attr = ppdFindNextAttr(ppd, "cupsPreFilter", NULL))
2109 {
2110 if (!attr->value ||
2111 sscanf(attr->value, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type,
2112 &cost, program) != 4)
2113 {
2114 if (!warn && !errors && !verbose)
2115 _cupsLangPuts(stdout, _(" FAIL\n"));
2116
2117 if (verbose >= 0)
2118 _cupsLangPrintf(stdout,
2119 _(" %s Bad cupsPreFilter value \"%s\"!\n"),
2120 prefix, attr->value ? attr->value : "");
2121
2122 if (!warn)
2123 errors ++;
2124 }
2125 else
2126 {
2127 if (program[0] == '/')
2128 snprintf(pathprog, sizeof(pathprog), "%s%s", root, program);
2129 else
2130 {
2131 if ((ptr = getenv("CUPS_SERVERBIN")) == NULL)
2132 ptr = CUPS_SERVERBIN;
2133
2134 if (*ptr == '/' || !*root)
2135 snprintf(pathprog, sizeof(pathprog), "%s%s/filter/%s", root, ptr,
2136 program);
2137 else
2138 snprintf(pathprog, sizeof(pathprog), "%s/%s/filter/%s", root, ptr,
2139 program);
2140 }
2141
2142 if (access(pathprog, X_OK))
2143 {
2144 if (!warn && !errors && !verbose)
2145 _cupsLangPuts(stdout, _(" FAIL\n"));
2146
2147 if (verbose >= 0)
2148 _cupsLangPrintf(stdout, _(" %s Missing cupsPreFilter "
2149 "file \"%s\"\n"), prefix, program);
2150
2151 if (!warn)
2152 errors ++;
2153 }
2154 }
2155 }
2156
2157 return (errors);
2158 }
2159
2160
2161 /*
2162 * 'check_profiles()' - Check ICC color profiles in the PPD file.
2163 */
2164
2165 static int /* O - Errors found */
2166 check_profiles(ppd_file_t *ppd, /* I - PPD file */
2167 const char *root, /* I - Root directory */
2168 int errors, /* I - Errors found */
2169 int verbose, /* I - Verbosity level */
2170 int warn) /* I - Warnings only? */
2171 {
2172 int i; /* Looping var */
2173 ppd_attr_t *attr; /* PPD attribute */
2174 const char *ptr; /* Pointer into string */
2175 const char *prefix; /* WARN/FAIL prefix */
2176 char filename[1024]; /* Profile filename */
2177 int num_profiles = 0; /* Number of profiles */
2178 unsigned hash, /* Current hash value */
2179 hashes[1000]; /* Hash values of profile names */
2180 const char *specs[1000]; /* Specifiers for profiles */
2181
2182
2183 prefix = warn ? " WARN " : "**FAIL**";
2184
2185 for (attr = ppdFindAttr(ppd, "cupsICCProfile", NULL);
2186 attr;
2187 attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL))
2188 {
2189 /*
2190 * Check for valid selector...
2191 */
2192
2193 for (i = 0, ptr = strchr(attr->spec, '.'); ptr; ptr = strchr(ptr + 1, '.'))
2194 i ++;
2195
2196 if (!attr->value || i < 2)
2197 {
2198 if (!warn && !errors && !verbose)
2199 _cupsLangPuts(stdout, _(" FAIL\n"));
2200
2201 if (verbose >= 0)
2202 _cupsLangPrintf(stdout,
2203 _(" %s Bad cupsICCProfile %s!\n"),
2204 prefix, attr->spec);
2205
2206 if (!warn)
2207 errors ++;
2208
2209 continue;
2210 }
2211
2212 /*
2213 * Check for valid profile filename...
2214 */
2215
2216 if (attr->value[0] == '/')
2217 snprintf(filename, sizeof(filename), "%s%s", root, attr->value);
2218 else
2219 {
2220 if ((ptr = getenv("CUPS_DATADIR")) == NULL)
2221 ptr = CUPS_DATADIR;
2222
2223 if (*ptr == '/' || !*root)
2224 snprintf(filename, sizeof(filename), "%s%s/profiles/%s", root, ptr,
2225 attr->value);
2226 else
2227 snprintf(filename, sizeof(filename), "%s/%s/profiles/%s", root, ptr,
2228 attr->value);
2229 }
2230
2231 if (access(filename, 0))
2232 {
2233 if (!warn && !errors && !verbose)
2234 _cupsLangPuts(stdout, _(" FAIL\n"));
2235
2236 if (verbose >= 0)
2237 _cupsLangPrintf(stdout, _(" %s Missing cupsICCProfile "
2238 "file \"%s\"!\n"), prefix, attr->value);
2239
2240 if (!warn)
2241 errors ++;
2242 }
2243
2244 /*
2245 * Check for hash collisions...
2246 */
2247
2248 hash = _ppdHashName(attr->spec);
2249
2250 if (num_profiles > 0)
2251 {
2252 for (i = 0; i < num_profiles; i ++)
2253 if (hashes[i] == hash)
2254 break;
2255
2256 if (i < num_profiles)
2257 {
2258 if (!warn && !errors && !verbose)
2259 _cupsLangPuts(stdout, _(" FAIL\n"));
2260
2261 if (verbose >= 0)
2262 _cupsLangPrintf(stdout,
2263 _(" %s cupsICCProfile %s hash value "
2264 "collides with %s!\n"), prefix, attr->spec,
2265 specs[i]);
2266
2267 if (!warn)
2268 errors ++;
2269 }
2270 }
2271
2272 /*
2273 * Remember up to 1000 profiles...
2274 */
2275
2276 if (num_profiles < 1000)
2277 {
2278 hashes[num_profiles] = hash;
2279 specs[num_profiles] = attr->spec;
2280 num_profiles ++;
2281 }
2282 }
2283
2284 return (errors);
2285 }
2286
2287
2288 /*
2289 * 'check_translations()' - Check translations in the PPD file.
2290 */
2291
2292 static int /* O - Errors found */
2293 check_translations(ppd_file_t *ppd, /* I - PPD file */
2294 int errors, /* I - Errors found */
2295 int verbose, /* I - Verbosity level */
2296 int warn) /* I - Warnings only? */
2297 {
2298 int j; /* Looping var */
2299 ppd_attr_t *attr; /* PPD attribute */
2300 cups_array_t *languages; /* Array of languages */
2301 int langlen; /* Length of language */
2302 char *language, /* Current language */
2303 keyword[PPD_MAX_NAME], /* Localization keyword (full) */
2304 llkeyword[PPD_MAX_NAME],/* Localization keyword (base) */
2305 ckeyword[PPD_MAX_NAME], /* Custom option keyword (full) */
2306 cllkeyword[PPD_MAX_NAME];
2307 /* Custom option keyword (base) */
2308 ppd_option_t *option; /* Standard UI option */
2309 ppd_coption_t *coption; /* Custom option */
2310 ppd_cparam_t *cparam; /* Custom parameter */
2311 char ll[3]; /* Base language */
2312 const char *prefix; /* WARN/FAIL prefix */
2313
2314
2315 prefix = warn ? " WARN " : "**FAIL**";
2316
2317 if ((languages = _ppdGetLanguages(ppd)) != NULL)
2318 {
2319 /*
2320 * This file contains localizations, check them...
2321 */
2322
2323 for (language = (char *)cupsArrayFirst(languages);
2324 language;
2325 language = (char *)cupsArrayNext(languages))
2326 {
2327 langlen = strlen(language);
2328 if (langlen != 2 && langlen != 5)
2329 {
2330 if (!warn && !errors && !verbose)
2331 _cupsLangPuts(stdout, _(" FAIL\n"));
2332
2333 if (verbose >= 0)
2334 _cupsLangPrintf(stdout,
2335 _(" %s Bad language \"%s\"!\n"),
2336 prefix, language);
2337
2338 if (!warn)
2339 errors ++;
2340
2341 continue;
2342 }
2343
2344 if (!strcmp(language, "en"))
2345 continue;
2346
2347 strlcpy(ll, language, sizeof(ll));
2348
2349 /*
2350 * Loop through all options and choices...
2351 */
2352
2353 for (option = ppdFirstOption(ppd);
2354 option;
2355 option = ppdNextOption(ppd))
2356 {
2357 if (!strcmp(option->keyword, "PageRegion"))
2358 continue;
2359
2360 snprintf(keyword, sizeof(keyword), "%s.Translation", language);
2361 snprintf(llkeyword, sizeof(llkeyword), "%s.Translation", ll);
2362
2363 if ((attr = ppdFindAttr(ppd, keyword, option->keyword)) == NULL &&
2364 (attr = ppdFindAttr(ppd, llkeyword, option->keyword)) == NULL)
2365 {
2366 if (!warn && !errors && !verbose)
2367 _cupsLangPuts(stdout, _(" FAIL\n"));
2368
2369 if (verbose >= 0)
2370 _cupsLangPrintf(stdout,
2371 _(" %s Missing \"%s\" translation "
2372 "string for option %s!\n"),
2373 prefix, language, option->keyword);
2374
2375 if (!warn)
2376 errors ++;
2377 }
2378 else if (!valid_utf8(attr->text))
2379 {
2380 if (!warn && !errors && !verbose)
2381 _cupsLangPuts(stdout, _(" FAIL\n"));
2382
2383 if (verbose >= 0)
2384 _cupsLangPrintf(stdout,
2385 _(" %s Bad UTF-8 \"%s\" translation "
2386 "string for option %s!\n"),
2387 prefix, language, option->keyword);
2388
2389 if (!warn)
2390 errors ++;
2391 }
2392
2393 snprintf(keyword, sizeof(keyword), "%s.%s", language,
2394 option->keyword);
2395 snprintf(llkeyword, sizeof(llkeyword), "%s.%s", ll,
2396 option->keyword);
2397
2398 for (j = 0; j < option->num_choices; j ++)
2399 {
2400 if (!strcasecmp(option->choices[j].choice, "Custom") &&
2401 (coption = ppdFindCustomOption(ppd,
2402 option->keyword)) != NULL)
2403 {
2404 snprintf(ckeyword, sizeof(ckeyword), "%s.Custom%s",
2405 language, option->keyword);
2406
2407 if ((attr = ppdFindAttr(ppd, ckeyword, "True")) != NULL &&
2408 !valid_utf8(attr->text))
2409 {
2410 if (!warn && !errors && !verbose)
2411 _cupsLangPuts(stdout, _(" FAIL\n"));
2412
2413 if (verbose >= 0)
2414 _cupsLangPrintf(stdout,
2415 _(" %s Bad UTF-8 \"%s\" "
2416 "translation string for option %s, "
2417 "choice %s!\n"),
2418 prefix, language,
2419 ckeyword + 1 + strlen(language),
2420 "True");
2421
2422 if (!warn)
2423 errors ++;
2424 }
2425
2426 if (strcasecmp(option->keyword, "PageSize"))
2427 {
2428 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
2429 cparam;
2430 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
2431 {
2432 snprintf(ckeyword, sizeof(ckeyword), "%s.ParamCustom%s",
2433 language, option->keyword);
2434 snprintf(cllkeyword, sizeof(cllkeyword), "%s.ParamCustom%s",
2435 ll, option->keyword);
2436
2437 if ((attr = ppdFindAttr(ppd, ckeyword,
2438 cparam->name)) == NULL &&
2439 (attr = ppdFindAttr(ppd, cllkeyword,
2440 cparam->name)) == NULL)
2441 {
2442 if (!warn && !errors && !verbose)
2443 _cupsLangPuts(stdout, _(" FAIL\n"));
2444
2445 if (verbose >= 0)
2446 _cupsLangPrintf(stdout,
2447 _(" %s Missing \"%s\" "
2448 "translation string for option %s, "
2449 "choice %s!\n"),
2450 prefix, language,
2451 ckeyword + 1 + strlen(language),
2452 cparam->name);
2453
2454 if (!warn)
2455 errors ++;
2456 }
2457 else if (!valid_utf8(attr->text))
2458 {
2459 if (!warn && !errors && !verbose)
2460 _cupsLangPuts(stdout, _(" FAIL\n"));
2461
2462 if (verbose >= 0)
2463 _cupsLangPrintf(stdout,
2464 _(" %s Bad UTF-8 \"%s\" "
2465 "translation string for option %s, "
2466 "choice %s!\n"),
2467 prefix, language,
2468 ckeyword + 1 + strlen(language),
2469 cparam->name);
2470
2471 if (!warn)
2472 errors ++;
2473 }
2474 }
2475 }
2476 }
2477 else if ((attr = ppdFindAttr(ppd, keyword,
2478 option->choices[j].choice)) == NULL &&
2479 (attr = ppdFindAttr(ppd, llkeyword,
2480 option->choices[j].choice)) == NULL)
2481 {
2482 if (!warn && !errors && !verbose)
2483 _cupsLangPuts(stdout, _(" FAIL\n"));
2484
2485 if (verbose >= 0)
2486 _cupsLangPrintf(stdout,
2487 _(" %s Missing \"%s\" "
2488 "translation string for option %s, "
2489 "choice %s!\n"),
2490 prefix, language, option->keyword,
2491 option->choices[j].choice);
2492
2493 if (!warn)
2494 errors ++;
2495 }
2496 else if (!valid_utf8(attr->text))
2497 {
2498 if (!warn && !errors && !verbose)
2499 _cupsLangPuts(stdout, _(" FAIL\n"));
2500
2501 if (verbose >= 0)
2502 _cupsLangPrintf(stdout,
2503 _(" %s Bad UTF-8 \"%s\" "
2504 "translation string for option %s, "
2505 "choice %s!\n"),
2506 prefix, language, option->keyword,
2507 option->choices[j].choice);
2508
2509 if (!warn)
2510 errors ++;
2511 }
2512 }
2513 }
2514 }
2515
2516 /*
2517 * Verify that we have the base language for each localized one...
2518 */
2519
2520 for (language = (char *)cupsArrayFirst(languages);
2521 language;
2522 language = (char *)cupsArrayNext(languages))
2523 if (language[2])
2524 {
2525 /*
2526 * Lookup the base language...
2527 */
2528
2529 cupsArraySave(languages);
2530
2531 strlcpy(ll, language, sizeof(ll));
2532
2533 if (!cupsArrayFind(languages, ll) &&
2534 strcmp(ll, "zh") && strcmp(ll, "en"))
2535 {
2536 if (!warn && !errors && !verbose)
2537 _cupsLangPuts(stdout, _(" FAIL\n"));
2538
2539 if (verbose >= 0)
2540 _cupsLangPrintf(stdout,
2541 _(" %s No base translation \"%s\" "
2542 "is included in file!\n"), prefix, ll);
2543
2544 if (!warn)
2545 errors ++;
2546 }
2547
2548 cupsArrayRestore(languages);
2549 }
2550
2551 /*
2552 * Free memory used for the languages...
2553 */
2554
2555 _ppdFreeLanguages(languages);
2556 }
2557
2558 return (errors);
2559 }
2560
2561
2562 /*
2563 * 'show_conflicts()' - Show option conflicts in a PPD file.
2564 */
2565
2566 static void
2567 show_conflicts(ppd_file_t *ppd) /* I - PPD to check */
2568 {
2569 int i, j; /* Looping variables */
2570 ppd_const_t *c; /* Current constraint */
2571 ppd_option_t *o1, *o2; /* Options */
2572 ppd_choice_t *c1, *c2; /* Choices */
2573
2574
2575 /*
2576 * Loop through all of the UI constraints and report any options
2577 * that conflict...
2578 */
2579
2580 for (i = ppd->num_consts, c = ppd->consts; i > 0; i --, c ++)
2581 {
2582 /*
2583 * Grab pointers to the first option...
2584 */
2585
2586 o1 = ppdFindOption(ppd, c->option1);
2587
2588 if (o1 == NULL)
2589 continue;
2590 else if (c->choice1[0] != '\0')
2591 {
2592 /*
2593 * This constraint maps to a specific choice.
2594 */
2595
2596 c1 = ppdFindChoice(o1, c->choice1);
2597 }
2598 else
2599 {
2600 /*
2601 * This constraint applies to any choice for this option.
2602 */
2603
2604 for (j = o1->num_choices, c1 = o1->choices; j > 0; j --, c1 ++)
2605 if (c1->marked)
2606 break;
2607
2608 if (j == 0 ||
2609 !strcasecmp(c1->choice, "None") ||
2610 !strcasecmp(c1->choice, "Off") ||
2611 !strcasecmp(c1->choice, "False"))
2612 c1 = NULL;
2613 }
2614
2615 /*
2616 * Grab pointers to the second option...
2617 */
2618
2619 o2 = ppdFindOption(ppd, c->option2);
2620
2621 if (o2 == NULL)
2622 continue;
2623 else if (c->choice2[0] != '\0')
2624 {
2625 /*
2626 * This constraint maps to a specific choice.
2627 */
2628
2629 c2 = ppdFindChoice(o2, c->choice2);
2630 }
2631 else
2632 {
2633 /*
2634 * This constraint applies to any choice for this option.
2635 */
2636
2637 for (j = o2->num_choices, c2 = o2->choices; j > 0; j --, c2 ++)
2638 if (c2->marked)
2639 break;
2640
2641 if (j == 0 ||
2642 !strcasecmp(c2->choice, "None") ||
2643 !strcasecmp(c2->choice, "Off") ||
2644 !strcasecmp(c2->choice, "False"))
2645 c2 = NULL;
2646 }
2647
2648 /*
2649 * If both options are marked then there is a conflict...
2650 */
2651
2652 if (c1 != NULL && c1->marked && c2 != NULL && c2->marked)
2653 _cupsLangPrintf(stdout,
2654 _(" WARN \"%s %s\" conflicts with \"%s %s\"\n"
2655 " (constraint=\"%s %s %s %s\")\n"),
2656 o1->keyword, c1->choice, o2->keyword, c2->choice,
2657 c->option1, c->choice1, c->option2, c->choice2);
2658 }
2659 }
2660
2661
2662 /*
2663 * 'test_raster()' - Test PostScript commands for raster printers.
2664 */
2665
2666 static int /* O - 1 on success, 0 on failure */
2667 test_raster(ppd_file_t *ppd, /* I - PPD file */
2668 int verbose) /* I - Verbosity */
2669 {
2670 cups_page_header2_t header; /* Page header */
2671
2672
2673 ppdMarkDefaults(ppd);
2674 if (cupsRasterInterpretPPD(&header, ppd, 0, NULL, 0))
2675 {
2676 if (!verbose)
2677 _cupsLangPuts(stdout, _(" FAIL\n"));
2678
2679 if (verbose >= 0)
2680 _cupsLangPrintf(stdout,
2681 _(" **FAIL** Default option code cannot be "
2682 "interpreted: %s\n"), cupsRasterErrorString());
2683
2684 return (0);
2685 }
2686
2687 /*
2688 * Try a test of custom page size code, if available...
2689 */
2690
2691 if (!ppdPageSize(ppd, "Custom.612x792"))
2692 return (1);
2693
2694 ppdMarkOption(ppd, "PageSize", "Custom.612x792");
2695
2696 if (cupsRasterInterpretPPD(&header, ppd, 0, NULL, 0))
2697 {
2698 if (!verbose)
2699 _cupsLangPuts(stdout, _(" FAIL\n"));
2700
2701 if (verbose >= 0)
2702 _cupsLangPrintf(stdout,
2703 _(" **FAIL** Default option code cannot be "
2704 "interpreted: %s\n"), cupsRasterErrorString());
2705
2706 return (0);
2707 }
2708
2709 return (1);
2710 }
2711
2712
2713 /*
2714 * 'usage()' - Show program usage...
2715 */
2716
2717 static void
2718 usage(void)
2719 {
2720 _cupsLangPuts(stdout,
2721 _("Usage: cupstestppd [options] filename1.ppd[.gz] "
2722 "[... filenameN.ppd[.gz]]\n"
2723 " program | cupstestppd [options] -\n"
2724 "\n"
2725 "Options:\n"
2726 "\n"
2727 " -R root-directory Set alternate root\n"
2728 " -W {all,none,constraints,defaults,filters,translations}\n"
2729 " Issue warnings instead of errors\n"
2730 " -q Run silently\n"
2731 " -r Use 'relaxed' open mode\n"
2732 " -v Be slightly verbose\n"
2733 " -vv Be very verbose\n"));
2734
2735 exit(ERROR_USAGE);
2736 }
2737
2738
2739 /*
2740 * 'valid_utf8()' - Check whether a string contains valid UTF-8 text.
2741 */
2742
2743 static int /* O - 1 if valid, 0 if not */
2744 valid_utf8(const char *s) /* I - String to check */
2745 {
2746 while (*s)
2747 {
2748 if (*s & 0x80)
2749 {
2750 /*
2751 * Check for valid UTF-8 sequence...
2752 */
2753
2754 if ((*s & 0xc0) == 0x80)
2755 return (0); /* Illegal suffix byte */
2756 else if ((*s & 0xe0) == 0xc0)
2757 {
2758 /*
2759 * 2-byte sequence...
2760 */
2761
2762 s ++;
2763
2764 if ((*s & 0xc0) != 0x80)
2765 return (0); /* Missing suffix byte */
2766 }
2767 else if ((*s & 0xf0) == 0xe0)
2768 {
2769 /*
2770 * 3-byte sequence...
2771 */
2772
2773 s ++;
2774
2775 if ((*s & 0xc0) != 0x80)
2776 return (0); /* Missing suffix byte */
2777
2778 s ++;
2779
2780 if ((*s & 0xc0) != 0x80)
2781 return (0); /* Missing suffix byte */
2782 }
2783 else if ((*s & 0xf8) == 0xf0)
2784 {
2785 /*
2786 * 4-byte sequence...
2787 */
2788
2789 s ++;
2790
2791 if ((*s & 0xc0) != 0x80)
2792 return (0); /* Missing suffix byte */
2793
2794 s ++;
2795
2796 if ((*s & 0xc0) != 0x80)
2797 return (0); /* Missing suffix byte */
2798
2799 s ++;
2800
2801 if ((*s & 0xc0) != 0x80)
2802 return (0); /* Missing suffix byte */
2803 }
2804 else
2805 return (0); /* Bad sequence */
2806 }
2807
2808 s ++;
2809 }
2810
2811 return (1);
2812 }
2813
2814
2815 /*
2816 * End of "$Id: cupstestppd.c 7637 2008-06-11 17:25:36Z mike $".
2817 */