]> git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestppd.c
Merge changes from CUPS 1.4svn-r7715.
[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 j; /* Looping var */
1683 ppd_const_t *c; /* Current constraint */
1684 ppd_option_t *option; /* Standard UI option */
1685 ppd_option_t *option2; /* Standard UI option */
1686 const char *prefix; /* WARN/FAIL prefix */
1687
1688
1689 prefix = warn ? " WARN " : "**FAIL**";
1690
1691 for (j = ppd->num_consts, c = ppd->consts; j > 0; j --, c ++)
1692 {
1693 option = ppdFindOption(ppd, c->option1);
1694 option2 = ppdFindOption(ppd, c->option2);
1695
1696 if (!option || !option2)
1697 {
1698 if (!warn && !errors && !verbose)
1699 _cupsLangPuts(stdout, _(" FAIL\n"));
1700
1701 if (!option)
1702 _cupsLangPrintf(stdout,
1703 _(" %s Missing option %s in "
1704 "UIConstraint \"*%s %s *%s %s\"!\n"),
1705 prefix, c->option1,
1706 c->option1, c->choice1, c->option2, c->choice2);
1707
1708 if (!option2)
1709 _cupsLangPrintf(stdout,
1710 _(" %s Missing option %s in "
1711 "UIConstraint \"*%s %s *%s %s\"!\n"),
1712 prefix, c->option2,
1713 c->option1, c->choice1, c->option2, c->choice2);
1714
1715 if (!warn)
1716 errors ++;
1717
1718 continue;
1719 }
1720
1721 if (c->choice1[0] && !ppdFindChoice(option, c->choice1))
1722 {
1723 if (!warn && !errors && !verbose)
1724 _cupsLangPuts(stdout, _(" FAIL\n"));
1725
1726 _cupsLangPrintf(stdout,
1727 _(" %s Missing choice *%s %s in "
1728 "UIConstraint \"*%s %s *%s %s\"!\n"),
1729 prefix, c->option1, c->choice1,
1730 c->option1, c->choice1, c->option2, c->choice2);
1731
1732 if (!warn)
1733 errors ++;
1734 }
1735
1736 if (c->choice2[0] && !ppdFindChoice(option2, c->choice2))
1737 {
1738 if (!warn && !errors && !verbose)
1739 _cupsLangPuts(stdout, _(" FAIL\n"));
1740
1741 _cupsLangPrintf(stdout,
1742 _(" %s Missing choice *%s %s in "
1743 "UIConstraint \"*%s %s *%s %s\"!\n"),
1744 prefix, c->option2, c->choice2,
1745 c->option1, c->choice1, c->option2, c->choice2);
1746
1747 if (!warn)
1748 errors ++;
1749 }
1750 }
1751
1752 return (errors);
1753 }
1754
1755
1756 /*
1757 * 'check_defaults()' - Check default option keywords in the PPD file.
1758 */
1759
1760 static int /* O - Errors found */
1761 check_defaults(ppd_file_t *ppd, /* I - PPD file */
1762 int errors, /* I - Errors found */
1763 int verbose, /* I - Verbosity level */
1764 int warn) /* I - Warnings only? */
1765 {
1766 int j, k; /* Looping vars */
1767 ppd_attr_t *attr; /* PPD attribute */
1768 ppd_option_t *option; /* Standard UI option */
1769 const char *prefix; /* WARN/FAIL prefix */
1770
1771
1772 prefix = warn ? " WARN " : "**FAIL**";
1773
1774 for (j = 0; j < ppd->num_attrs; j ++)
1775 {
1776 attr = ppd->attrs[j];
1777
1778 if (!strcmp(attr->name, "DefaultColorSpace") ||
1779 !strcmp(attr->name, "DefaultFont") ||
1780 !strcmp(attr->name, "DefaultHalftoneType") ||
1781 !strcmp(attr->name, "DefaultImageableArea") ||
1782 !strcmp(attr->name, "DefaultLeadingEdge") ||
1783 !strcmp(attr->name, "DefaultOutputOrder") ||
1784 !strcmp(attr->name, "DefaultPaperDimension") ||
1785 !strcmp(attr->name, "DefaultResolution") ||
1786 !strcmp(attr->name, "DefaultTransfer"))
1787 continue;
1788
1789 if (!strncmp(attr->name, "Default", 7))
1790 {
1791 if ((option = ppdFindOption(ppd, attr->name + 7)) != NULL &&
1792 strcmp(attr->value, "Unknown"))
1793 {
1794 /*
1795 * Check that the default option value matches a choice...
1796 */
1797
1798 for (k = 0; k < option->num_choices; k ++)
1799 if (!strcmp(option->choices[k].choice, attr->value))
1800 break;
1801
1802 if (k >= option->num_choices)
1803 {
1804 if (!warn && !errors && !verbose)
1805 _cupsLangPuts(stdout, _(" FAIL\n"));
1806
1807 if (verbose >= 0)
1808 _cupsLangPrintf(stdout,
1809 _(" %s %s %s does not exist!\n"),
1810 prefix, attr->name, attr->value);
1811
1812 if (!warn)
1813 errors ++;
1814 }
1815 }
1816 }
1817 }
1818
1819 return (errors);
1820 }
1821
1822
1823 /*
1824 * 'check_filters()' - Check filters in the PPD file.
1825 */
1826
1827 static int /* O - Errors found */
1828 check_filters(ppd_file_t *ppd, /* I - PPD file */
1829 const char *root, /* I - Root directory */
1830 int errors, /* I - Errors found */
1831 int verbose, /* I - Verbosity level */
1832 int warn) /* I - Warnings only? */
1833 {
1834 int i; /* Looping var */
1835 ppd_attr_t *attr; /* PPD attribute */
1836 const char *ptr; /* Pointer into string */
1837 char super[16], /* Super-type for filter */
1838 type[256], /* Type for filter */
1839 program[1024], /* Program/filter name */
1840 pathprog[1024]; /* Complete path to program/filter */
1841 int cost; /* Cost of filter */
1842 const char *prefix; /* WARN/FAIL prefix */
1843
1844
1845 prefix = warn ? " WARN " : "**FAIL**";
1846
1847 for (i = 0; i < ppd->num_filters; i ++)
1848 {
1849 if (sscanf(ppd->filters[i], "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type,
1850 &cost, program) != 4)
1851 {
1852 if (!warn && !errors && !verbose)
1853 _cupsLangPuts(stdout, _(" FAIL\n"));
1854
1855 if (verbose >= 0)
1856 _cupsLangPrintf(stdout,
1857 _(" %s Bad cupsFilter value \"%s\"!\n"),
1858 prefix, ppd->filters[i]);
1859
1860 if (!warn)
1861 errors ++;
1862 }
1863 else
1864 {
1865 if (program[0] == '/')
1866 snprintf(pathprog, sizeof(pathprog), "%s%s", root, program);
1867 else
1868 {
1869 if ((ptr = getenv("CUPS_SERVERBIN")) == NULL)
1870 ptr = CUPS_SERVERBIN;
1871
1872 if (*ptr == '/' || !*root)
1873 snprintf(pathprog, sizeof(pathprog), "%s%s/filter/%s", root, ptr,
1874 program);
1875 else
1876 snprintf(pathprog, sizeof(pathprog), "%s/%s/filter/%s", root, ptr,
1877 program);
1878 }
1879
1880 if (access(pathprog, X_OK))
1881 {
1882 if (!warn && !errors && !verbose)
1883 _cupsLangPuts(stdout, _(" FAIL\n"));
1884
1885 if (verbose >= 0)
1886 _cupsLangPrintf(stdout, _(" %s Missing cupsFilter "
1887 "file \"%s\"\n"), prefix, program);
1888
1889 if (!warn)
1890 errors ++;
1891 }
1892 }
1893 }
1894
1895 for (attr = ppdFindAttr(ppd, "cupsPreFilter", NULL);
1896 attr;
1897 attr = ppdFindNextAttr(ppd, "cupsPreFilter", NULL))
1898 {
1899 if (!attr->value ||
1900 sscanf(attr->value, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type,
1901 &cost, program) != 4)
1902 {
1903 if (!warn && !errors && !verbose)
1904 _cupsLangPuts(stdout, _(" FAIL\n"));
1905
1906 if (verbose >= 0)
1907 _cupsLangPrintf(stdout,
1908 _(" %s Bad cupsPreFilter value \"%s\"!\n"),
1909 prefix, attr->value ? attr->value : "");
1910
1911 if (!warn)
1912 errors ++;
1913 }
1914 else
1915 {
1916 if (program[0] == '/')
1917 snprintf(pathprog, sizeof(pathprog), "%s%s", root, program);
1918 else
1919 {
1920 if ((ptr = getenv("CUPS_SERVERBIN")) == NULL)
1921 ptr = CUPS_SERVERBIN;
1922
1923 if (*ptr == '/' || !*root)
1924 snprintf(pathprog, sizeof(pathprog), "%s%s/filter/%s", root, ptr,
1925 program);
1926 else
1927 snprintf(pathprog, sizeof(pathprog), "%s/%s/filter/%s", root, ptr,
1928 program);
1929 }
1930
1931 if (access(pathprog, X_OK))
1932 {
1933 if (!warn && !errors && !verbose)
1934 _cupsLangPuts(stdout, _(" FAIL\n"));
1935
1936 if (verbose >= 0)
1937 _cupsLangPrintf(stdout, _(" %s Missing cupsPreFilter "
1938 "file \"%s\"\n"), prefix, program);
1939
1940 if (!warn)
1941 errors ++;
1942 }
1943 }
1944 }
1945
1946 return (errors);
1947 }
1948
1949
1950 /*
1951 * 'check_profiles()' - Check ICC color profiles in the PPD file.
1952 */
1953
1954 static int /* O - Errors found */
1955 check_profiles(ppd_file_t *ppd, /* I - PPD file */
1956 const char *root, /* I - Root directory */
1957 int errors, /* I - Errors found */
1958 int verbose, /* I - Verbosity level */
1959 int warn) /* I - Warnings only? */
1960 {
1961 int i; /* Looping var */
1962 ppd_attr_t *attr; /* PPD attribute */
1963 const char *ptr; /* Pointer into string */
1964 const char *prefix; /* WARN/FAIL prefix */
1965 char filename[1024]; /* Profile filename */
1966 int num_profiles = 0; /* Number of profiles */
1967 unsigned hash, /* Current hash value */
1968 hashes[1000]; /* Hash values of profile names */
1969 const char *specs[1000]; /* Specifiers for profiles */
1970
1971
1972 prefix = warn ? " WARN " : "**FAIL**";
1973
1974 for (attr = ppdFindAttr(ppd, "cupsICCProfile", NULL);
1975 attr;
1976 attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL))
1977 {
1978 /*
1979 * Check for valid selector...
1980 */
1981
1982 for (i = 0, ptr = strchr(attr->spec, '.'); ptr; ptr = strchr(ptr + 1, '.'))
1983 i ++;
1984
1985 if (!attr->value || i < 2)
1986 {
1987 if (!warn && !errors && !verbose)
1988 _cupsLangPuts(stdout, _(" FAIL\n"));
1989
1990 if (verbose >= 0)
1991 _cupsLangPrintf(stdout,
1992 _(" %s Bad cupsICCProfile %s!\n"),
1993 prefix, attr->spec);
1994
1995 if (!warn)
1996 errors ++;
1997
1998 continue;
1999 }
2000
2001 /*
2002 * Check for valid profile filename...
2003 */
2004
2005 if (attr->value[0] == '/')
2006 snprintf(filename, sizeof(filename), "%s%s", root, attr->value);
2007 else
2008 {
2009 if ((ptr = getenv("CUPS_DATADIR")) == NULL)
2010 ptr = CUPS_DATADIR;
2011
2012 if (*ptr == '/' || !*root)
2013 snprintf(filename, sizeof(filename), "%s%s/profiles/%s", root, ptr,
2014 attr->value);
2015 else
2016 snprintf(filename, sizeof(filename), "%s/%s/profiles/%s", root, ptr,
2017 attr->value);
2018 }
2019
2020 if (access(filename, 0))
2021 {
2022 if (!warn && !errors && !verbose)
2023 _cupsLangPuts(stdout, _(" FAIL\n"));
2024
2025 if (verbose >= 0)
2026 _cupsLangPrintf(stdout, _(" %s Missing cupsICCProfile "
2027 "file \"%s\"!\n"), prefix, attr->value);
2028
2029 if (!warn)
2030 errors ++;
2031 }
2032
2033 /*
2034 * Check for hash collisions...
2035 */
2036
2037 hash = _ppdHashName(attr->spec);
2038
2039 if (num_profiles > 0)
2040 {
2041 for (i = 0; i < num_profiles; i ++)
2042 if (hashes[i] == hash)
2043 break;
2044
2045 if (i < num_profiles)
2046 {
2047 if (!warn && !errors && !verbose)
2048 _cupsLangPuts(stdout, _(" FAIL\n"));
2049
2050 if (verbose >= 0)
2051 _cupsLangPrintf(stdout,
2052 _(" %s cupsICCProfile %s hash value "
2053 "collides with %s!\n"), prefix, attr->spec,
2054 specs[i]);
2055
2056 if (!warn)
2057 errors ++;
2058 }
2059 }
2060
2061 /*
2062 * Remember up to 1000 profiles...
2063 */
2064
2065 if (num_profiles < 1000)
2066 {
2067 hashes[num_profiles] = hash;
2068 specs[num_profiles] = attr->spec;
2069 num_profiles ++;
2070 }
2071 }
2072
2073 return (errors);
2074 }
2075
2076
2077 /*
2078 * 'check_translations()' - Check translations in the PPD file.
2079 */
2080
2081 static int /* O - Errors found */
2082 check_translations(ppd_file_t *ppd, /* I - PPD file */
2083 int errors, /* I - Errors found */
2084 int verbose, /* I - Verbosity level */
2085 int warn) /* I - Warnings only? */
2086 {
2087 int j; /* Looping var */
2088 ppd_attr_t *attr; /* PPD attribute */
2089 cups_array_t *languages; /* Array of languages */
2090 int langlen; /* Length of language */
2091 char *language, /* Current language */
2092 keyword[PPD_MAX_NAME], /* Localization keyword (full) */
2093 llkeyword[PPD_MAX_NAME],/* Localization keyword (base) */
2094 ckeyword[PPD_MAX_NAME], /* Custom option keyword (full) */
2095 cllkeyword[PPD_MAX_NAME];
2096 /* Custom option keyword (base) */
2097 ppd_option_t *option; /* Standard UI option */
2098 ppd_coption_t *coption; /* Custom option */
2099 ppd_cparam_t *cparam; /* Custom parameter */
2100 char ll[3]; /* Base language */
2101 const char *prefix; /* WARN/FAIL prefix */
2102
2103
2104 prefix = warn ? " WARN " : "**FAIL**";
2105
2106 if ((languages = _ppdGetLanguages(ppd)) != NULL)
2107 {
2108 /*
2109 * This file contains localizations, check them...
2110 */
2111
2112 for (language = (char *)cupsArrayFirst(languages);
2113 language;
2114 language = (char *)cupsArrayNext(languages))
2115 {
2116 langlen = strlen(language);
2117 if (langlen != 2 && langlen != 5)
2118 {
2119 if (!warn && !errors && !verbose)
2120 _cupsLangPuts(stdout, _(" FAIL\n"));
2121
2122 if (verbose >= 0)
2123 _cupsLangPrintf(stdout,
2124 _(" %s Bad language \"%s\"!\n"),
2125 prefix, language);
2126
2127 if (!warn)
2128 errors ++;
2129
2130 continue;
2131 }
2132
2133 if (!strcmp(language, "en"))
2134 continue;
2135
2136 strlcpy(ll, language, sizeof(ll));
2137
2138 /*
2139 * Loop through all options and choices...
2140 */
2141
2142 for (option = ppdFirstOption(ppd);
2143 option;
2144 option = ppdNextOption(ppd))
2145 {
2146 if (!strcmp(option->keyword, "PageRegion"))
2147 continue;
2148
2149 snprintf(keyword, sizeof(keyword), "%s.Translation", language);
2150 snprintf(llkeyword, sizeof(llkeyword), "%s.Translation", ll);
2151
2152 if ((attr = ppdFindAttr(ppd, keyword, option->keyword)) == NULL &&
2153 (attr = ppdFindAttr(ppd, llkeyword, option->keyword)) == NULL)
2154 {
2155 if (!warn && !errors && !verbose)
2156 _cupsLangPuts(stdout, _(" FAIL\n"));
2157
2158 if (verbose >= 0)
2159 _cupsLangPrintf(stdout,
2160 _(" %s Missing \"%s\" translation "
2161 "string for option %s!\n"),
2162 prefix, language, option->keyword);
2163
2164 if (!warn)
2165 errors ++;
2166 }
2167 else if (!valid_utf8(attr->text))
2168 {
2169 if (!warn && !errors && !verbose)
2170 _cupsLangPuts(stdout, _(" FAIL\n"));
2171
2172 if (verbose >= 0)
2173 _cupsLangPrintf(stdout,
2174 _(" %s Bad UTF-8 \"%s\" translation "
2175 "string for option %s!\n"),
2176 prefix, language, option->keyword);
2177
2178 if (!warn)
2179 errors ++;
2180 }
2181
2182 snprintf(keyword, sizeof(keyword), "%s.%s", language,
2183 option->keyword);
2184 snprintf(llkeyword, sizeof(llkeyword), "%s.%s", ll,
2185 option->keyword);
2186
2187 for (j = 0; j < option->num_choices; j ++)
2188 {
2189 if (!strcasecmp(option->choices[j].choice, "Custom") &&
2190 (coption = ppdFindCustomOption(ppd,
2191 option->keyword)) != NULL)
2192 {
2193 snprintf(ckeyword, sizeof(ckeyword), "%s.Custom%s",
2194 language, option->keyword);
2195
2196 if ((attr = ppdFindAttr(ppd, ckeyword, "True")) != NULL &&
2197 !valid_utf8(attr->text))
2198 {
2199 if (!warn && !errors && !verbose)
2200 _cupsLangPuts(stdout, _(" FAIL\n"));
2201
2202 if (verbose >= 0)
2203 _cupsLangPrintf(stdout,
2204 _(" %s Bad UTF-8 \"%s\" "
2205 "translation string for option %s, "
2206 "choice %s!\n"),
2207 prefix, language,
2208 ckeyword + 1 + strlen(language),
2209 "True");
2210
2211 if (!warn)
2212 errors ++;
2213 }
2214
2215 if (strcasecmp(option->keyword, "PageSize"))
2216 {
2217 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
2218 cparam;
2219 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
2220 {
2221 snprintf(ckeyword, sizeof(ckeyword), "%s.ParamCustom%s",
2222 language, option->keyword);
2223 snprintf(cllkeyword, sizeof(cllkeyword), "%s.ParamCustom%s",
2224 ll, option->keyword);
2225
2226 if ((attr = ppdFindAttr(ppd, ckeyword,
2227 cparam->name)) == NULL &&
2228 (attr = ppdFindAttr(ppd, cllkeyword,
2229 cparam->name)) == NULL)
2230 {
2231 if (!warn && !errors && !verbose)
2232 _cupsLangPuts(stdout, _(" FAIL\n"));
2233
2234 if (verbose >= 0)
2235 _cupsLangPrintf(stdout,
2236 _(" %s Missing \"%s\" "
2237 "translation string for option %s, "
2238 "choice %s!\n"),
2239 prefix, language,
2240 ckeyword + 1 + strlen(language),
2241 cparam->name);
2242
2243 if (!warn)
2244 errors ++;
2245 }
2246 else if (!valid_utf8(attr->text))
2247 {
2248 if (!warn && !errors && !verbose)
2249 _cupsLangPuts(stdout, _(" FAIL\n"));
2250
2251 if (verbose >= 0)
2252 _cupsLangPrintf(stdout,
2253 _(" %s Bad UTF-8 \"%s\" "
2254 "translation string for option %s, "
2255 "choice %s!\n"),
2256 prefix, language,
2257 ckeyword + 1 + strlen(language),
2258 cparam->name);
2259
2260 if (!warn)
2261 errors ++;
2262 }
2263 }
2264 }
2265 }
2266 else if ((attr = ppdFindAttr(ppd, keyword,
2267 option->choices[j].choice)) == NULL &&
2268 (attr = ppdFindAttr(ppd, llkeyword,
2269 option->choices[j].choice)) == NULL)
2270 {
2271 if (!warn && !errors && !verbose)
2272 _cupsLangPuts(stdout, _(" FAIL\n"));
2273
2274 if (verbose >= 0)
2275 _cupsLangPrintf(stdout,
2276 _(" %s Missing \"%s\" "
2277 "translation string for option %s, "
2278 "choice %s!\n"),
2279 prefix, language, option->keyword,
2280 option->choices[j].choice);
2281
2282 if (!warn)
2283 errors ++;
2284 }
2285 else if (!valid_utf8(attr->text))
2286 {
2287 if (!warn && !errors && !verbose)
2288 _cupsLangPuts(stdout, _(" FAIL\n"));
2289
2290 if (verbose >= 0)
2291 _cupsLangPrintf(stdout,
2292 _(" %s Bad UTF-8 \"%s\" "
2293 "translation string for option %s, "
2294 "choice %s!\n"),
2295 prefix, language, option->keyword,
2296 option->choices[j].choice);
2297
2298 if (!warn)
2299 errors ++;
2300 }
2301 }
2302 }
2303 }
2304
2305 /*
2306 * Verify that we have the base language for each localized one...
2307 */
2308
2309 for (language = (char *)cupsArrayFirst(languages);
2310 language;
2311 language = (char *)cupsArrayNext(languages))
2312 if (language[2])
2313 {
2314 /*
2315 * Lookup the base language...
2316 */
2317
2318 cupsArraySave(languages);
2319
2320 strlcpy(ll, language, sizeof(ll));
2321
2322 if (!cupsArrayFind(languages, ll) && strcmp(ll, "zh"))
2323 {
2324 if (!warn && !errors && !verbose)
2325 _cupsLangPuts(stdout, _(" FAIL\n"));
2326
2327 if (verbose >= 0)
2328 _cupsLangPrintf(stdout,
2329 _(" %s No base translation \"%s\" "
2330 "is included in file!\n"), prefix, ll);
2331
2332 if (!warn)
2333 errors ++;
2334 }
2335
2336 cupsArrayRestore(languages);
2337 }
2338
2339 /*
2340 * Free memory used for the languages...
2341 */
2342
2343 _ppdFreeLanguages(languages);
2344 }
2345
2346 return (errors);
2347 }
2348
2349
2350 /*
2351 * 'show_conflicts()' - Show option conflicts in a PPD file.
2352 */
2353
2354 static void
2355 show_conflicts(ppd_file_t *ppd) /* I - PPD to check */
2356 {
2357 int i, j; /* Looping variables */
2358 ppd_const_t *c; /* Current constraint */
2359 ppd_option_t *o1, *o2; /* Options */
2360 ppd_choice_t *c1, *c2; /* Choices */
2361
2362
2363 /*
2364 * Loop through all of the UI constraints and report any options
2365 * that conflict...
2366 */
2367
2368 for (i = ppd->num_consts, c = ppd->consts; i > 0; i --, c ++)
2369 {
2370 /*
2371 * Grab pointers to the first option...
2372 */
2373
2374 o1 = ppdFindOption(ppd, c->option1);
2375
2376 if (o1 == NULL)
2377 continue;
2378 else if (c->choice1[0] != '\0')
2379 {
2380 /*
2381 * This constraint maps to a specific choice.
2382 */
2383
2384 c1 = ppdFindChoice(o1, c->choice1);
2385 }
2386 else
2387 {
2388 /*
2389 * This constraint applies to any choice for this option.
2390 */
2391
2392 for (j = o1->num_choices, c1 = o1->choices; j > 0; j --, c1 ++)
2393 if (c1->marked)
2394 break;
2395
2396 if (j == 0 ||
2397 !strcasecmp(c1->choice, "None") ||
2398 !strcasecmp(c1->choice, "Off") ||
2399 !strcasecmp(c1->choice, "False"))
2400 c1 = NULL;
2401 }
2402
2403 /*
2404 * Grab pointers to the second option...
2405 */
2406
2407 o2 = ppdFindOption(ppd, c->option2);
2408
2409 if (o2 == NULL)
2410 continue;
2411 else if (c->choice2[0] != '\0')
2412 {
2413 /*
2414 * This constraint maps to a specific choice.
2415 */
2416
2417 c2 = ppdFindChoice(o2, c->choice2);
2418 }
2419 else
2420 {
2421 /*
2422 * This constraint applies to any choice for this option.
2423 */
2424
2425 for (j = o2->num_choices, c2 = o2->choices; j > 0; j --, c2 ++)
2426 if (c2->marked)
2427 break;
2428
2429 if (j == 0 ||
2430 !strcasecmp(c2->choice, "None") ||
2431 !strcasecmp(c2->choice, "Off") ||
2432 !strcasecmp(c2->choice, "False"))
2433 c2 = NULL;
2434 }
2435
2436 /*
2437 * If both options are marked then there is a conflict...
2438 */
2439
2440 if (c1 != NULL && c1->marked && c2 != NULL && c2->marked)
2441 _cupsLangPrintf(stdout,
2442 _(" WARN \"%s %s\" conflicts with \"%s %s\"\n"
2443 " (constraint=\"%s %s %s %s\")\n"),
2444 o1->keyword, c1->choice, o2->keyword, c2->choice,
2445 c->option1, c->choice1, c->option2, c->choice2);
2446 }
2447 }
2448
2449
2450 /*
2451 * 'test_raster()' - Test PostScript commands for raster printers.
2452 */
2453
2454 static int /* O - 1 on success, 0 on failure */
2455 test_raster(ppd_file_t *ppd, /* I - PPD file */
2456 int verbose) /* I - Verbosity */
2457 {
2458 cups_page_header2_t header; /* Page header */
2459
2460
2461 ppdMarkDefaults(ppd);
2462 if (cupsRasterInterpretPPD(&header, ppd, 0, NULL, 0))
2463 {
2464 if (!verbose)
2465 _cupsLangPuts(stdout, _(" FAIL\n"));
2466
2467 if (verbose >= 0)
2468 _cupsLangPrintf(stdout,
2469 _(" **FAIL** Default option code cannot be "
2470 "interpreted: %s\n"), cupsRasterErrorString());
2471
2472 return (0);
2473 }
2474
2475 /*
2476 * Try a test of custom page size code, if available...
2477 */
2478
2479 if (!ppdPageSize(ppd, "Custom.612x792"))
2480 return (1);
2481
2482 ppdMarkOption(ppd, "PageSize", "Custom.612x792");
2483
2484 if (cupsRasterInterpretPPD(&header, ppd, 0, NULL, 0))
2485 {
2486 if (!verbose)
2487 _cupsLangPuts(stdout, _(" FAIL\n"));
2488
2489 if (verbose >= 0)
2490 _cupsLangPrintf(stdout,
2491 _(" **FAIL** Default option code cannot be "
2492 "interpreted: %s\n"), cupsRasterErrorString());
2493
2494 return (0);
2495 }
2496
2497 return (1);
2498 }
2499
2500
2501 /*
2502 * 'usage()' - Show program usage...
2503 */
2504
2505 static void
2506 usage(void)
2507 {
2508 _cupsLangPuts(stdout,
2509 _("Usage: cupstestppd [options] filename1.ppd[.gz] "
2510 "[... filenameN.ppd[.gz]]\n"
2511 " program | cupstestppd [options] -\n"
2512 "\n"
2513 "Options:\n"
2514 "\n"
2515 " -R root-directory Set alternate root\n"
2516 " -W {all,none,constraints,defaults,filters,translations}\n"
2517 " Issue warnings instead of errors\n"
2518 " -q Run silently\n"
2519 " -r Use 'relaxed' open mode\n"
2520 " -v Be slightly verbose\n"
2521 " -vv Be very verbose\n"));
2522
2523 exit(ERROR_USAGE);
2524 }
2525
2526
2527 /*
2528 * 'valid_utf8()' - Check whether a string contains valid UTF-8 text.
2529 */
2530
2531 static int /* O - 1 if valid, 0 if not */
2532 valid_utf8(const char *s) /* I - String to check */
2533 {
2534 while (*s)
2535 {
2536 if (*s & 0x80)
2537 {
2538 /*
2539 * Check for valid UTF-8 sequence...
2540 */
2541
2542 if ((*s & 0xc0) == 0x80)
2543 return (0); /* Illegal suffix byte */
2544 else if ((*s & 0xe0) == 0xc0)
2545 {
2546 /*
2547 * 2-byte sequence...
2548 */
2549
2550 s ++;
2551
2552 if ((*s & 0xc0) != 0x80)
2553 return (0); /* Missing suffix byte */
2554 }
2555 else if ((*s & 0xf0) == 0xe0)
2556 {
2557 /*
2558 * 3-byte sequence...
2559 */
2560
2561 s ++;
2562
2563 if ((*s & 0xc0) != 0x80)
2564 return (0); /* Missing suffix byte */
2565
2566 s ++;
2567
2568 if ((*s & 0xc0) != 0x80)
2569 return (0); /* Missing suffix byte */
2570 }
2571 else if ((*s & 0xf8) == 0xf0)
2572 {
2573 /*
2574 * 4-byte sequence...
2575 */
2576
2577 s ++;
2578
2579 if ((*s & 0xc0) != 0x80)
2580 return (0); /* Missing suffix byte */
2581
2582 s ++;
2583
2584 if ((*s & 0xc0) != 0x80)
2585 return (0); /* Missing suffix byte */
2586
2587 s ++;
2588
2589 if ((*s & 0xc0) != 0x80)
2590 return (0); /* Missing suffix byte */
2591 }
2592 else
2593 return (0); /* Bad sequence */
2594 }
2595
2596 s ++;
2597 }
2598
2599 return (1);
2600 }
2601
2602
2603 /*
2604 * End of "$Id: cupstestppd.c 7637 2008-06-11 17:25:36Z mike $".
2605 */