]>
Commit | Line | Data |
---|---|---|
247efae5 MS |
1 | /* |
2 | * "$Id$" | |
3 | * | |
4 | * PPD constraint test program for the Common UNIX Printing System (CUPS). | |
5 | * | |
c168a833 | 6 | * Copyright 2008-2009 by Apple Inc. |
247efae5 MS |
7 | * |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Apple Inc. and are protected by Federal copyright | |
10 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
11 | * which should have been included with this file. If this file is | |
12 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
13 | * | |
14 | * This file is subject to the Apple OS-Developed Software exception. | |
15 | * | |
16 | * Contents: | |
17 | * | |
18 | * main() - Main entry. | |
19 | */ | |
20 | ||
21 | /* | |
22 | * Include necessary headers... | |
23 | */ | |
24 | ||
25 | #include "cups.h" | |
26 | #include "string.h" | |
27 | ||
28 | ||
29 | /* | |
30 | * 'main()' - Main entry. | |
31 | */ | |
32 | ||
33 | int /* O - Exit status */ | |
34 | main(int argc, /* I - Number of command-line arguments */ | |
35 | char *argv[]) /* I - Command-line arguments */ | |
36 | { | |
37 | int i; /* Looping var */ | |
38 | ppd_file_t *ppd; /* PPD file loaded from disk */ | |
d1c13e16 MS |
39 | char line[256], /* Input buffer */ |
40 | *ptr, /* Pointer into buffer */ | |
41 | *optr, /* Pointer to first option name */ | |
42 | *cptr; /* Pointer to first choice */ | |
247efae5 MS |
43 | int num_options; /* Number of options */ |
44 | cups_option_t *options; /* Options */ | |
c168a833 MS |
45 | char *option, /* Current option */ |
46 | *choice; /* Current choice */ | |
247efae5 MS |
47 | |
48 | ||
49 | if (argc != 2) | |
50 | { | |
51 | puts("Usage: testconflicts filename.ppd"); | |
52 | return (1); | |
53 | } | |
54 | ||
55 | if ((ppd = ppdOpenFile(argv[1])) == NULL) | |
56 | { | |
57 | ppd_status_t err; /* Last error in file */ | |
58 | int linenum; /* Line number in file */ | |
59 | ||
60 | err = ppdLastError(&linenum); | |
61 | ||
62 | printf("Unable to open PPD file \"%s\": %s on line %d\n", argv[1], | |
63 | ppdErrorString(err), linenum); | |
64 | return (1); | |
65 | } | |
66 | ||
67 | ppdMarkDefaults(ppd); | |
68 | ||
c168a833 MS |
69 | option = NULL; |
70 | choice = NULL; | |
71 | ||
247efae5 MS |
72 | for (;;) |
73 | { | |
74 | num_options = 0; | |
75 | options = NULL; | |
76 | ||
c168a833 | 77 | if (!cupsResolveConflicts(ppd, option, choice, &num_options, &options)) |
247efae5 | 78 | puts("Unable to resolve conflicts!"); |
d1c13e16 | 79 | else if ((!option && num_options > 0) || (option && num_options > 1)) |
247efae5 MS |
80 | { |
81 | fputs("Resolved conflicts with the following options:\n ", stdout); | |
82 | for (i = 0; i < num_options; i ++) | |
d1c13e16 MS |
83 | if (!option || strcasecmp(option, options[i].name)) |
84 | printf(" %s=%s", options[i].name, options[i].value); | |
247efae5 MS |
85 | putchar('\n'); |
86 | ||
87 | cupsFreeOptions(num_options, options); | |
88 | } | |
89 | ||
c168a833 MS |
90 | if (option) |
91 | { | |
92 | free(option); | |
93 | free(choice); | |
94 | } | |
95 | ||
247efae5 MS |
96 | printf("\nNew Option(s): "); |
97 | fflush(stdout); | |
98 | if (!fgets(line, sizeof(line), stdin) || line[0] == '\n') | |
99 | break; | |
100 | ||
d1c13e16 MS |
101 | for (ptr = line; isspace(*ptr & 255); ptr ++); |
102 | for (optr = ptr; *ptr && *ptr != '='; ptr ++); | |
103 | if (!*ptr) | |
104 | break; | |
105 | for (*ptr++ = '\0', cptr = ptr; *ptr && !isspace(*ptr & 255); ptr ++); | |
106 | if (!*ptr) | |
107 | break; | |
108 | *ptr++ = '\0'; | |
109 | ||
110 | option = strdup(optr); | |
111 | choice = strdup(cptr); | |
112 | num_options = cupsParseOptions(ptr, 0, &options); | |
c168a833 | 113 | |
d1c13e16 | 114 | ppdMarkOption(ppd, option, choice); |
247efae5 MS |
115 | if (cupsMarkOptions(ppd, num_options, options)) |
116 | puts("Options Conflict!"); | |
117 | cupsFreeOptions(num_options, options); | |
118 | } | |
119 | ||
120 | return (0); | |
121 | } | |
122 | ||
123 | ||
124 | /* | |
125 | * End of "$Id$". | |
126 | */ |