]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testconflicts.c
269c53ec3d31f93d4e6aa6facf2fae6128879d01
[thirdparty/cups.git] / cups / testconflicts.c
1 /*
2 * "$Id$"
3 *
4 * PPD constraint test program for CUPS.
5 *
6 * Copyright 2008-2012 by Apple Inc.
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 "ppd.h"
27 #include "string-private.h"
28
29
30 /*
31 * 'main()' - Main entry.
32 */
33
34 int /* O - Exit status */
35 main(int argc, /* I - Number of command-line arguments */
36 char *argv[]) /* I - Command-line arguments */
37 {
38 int i; /* Looping var */
39 ppd_file_t *ppd; /* PPD file loaded from disk */
40 char line[256], /* Input buffer */
41 *ptr, /* Pointer into buffer */
42 *optr, /* Pointer to first option name */
43 *cptr; /* Pointer to first choice */
44 int num_options; /* Number of options */
45 cups_option_t *options; /* Options */
46 char *option, /* Current option */
47 *choice; /* Current choice */
48
49
50 if (argc != 2)
51 {
52 puts("Usage: testconflicts filename.ppd");
53 return (1);
54 }
55
56 if ((ppd = ppdOpenFile(argv[1])) == NULL)
57 {
58 ppd_status_t err; /* Last error in file */
59 int linenum; /* Line number in file */
60
61 err = ppdLastError(&linenum);
62
63 printf("Unable to open PPD file \"%s\": %s on line %d\n", argv[1],
64 ppdErrorString(err), linenum);
65 return (1);
66 }
67
68 ppdMarkDefaults(ppd);
69
70 option = NULL;
71 choice = NULL;
72
73 for (;;)
74 {
75 num_options = 0;
76 options = NULL;
77
78 if (!cupsResolveConflicts(ppd, option, choice, &num_options, &options))
79 puts("Unable to resolve conflicts!");
80 else if ((!option && num_options > 0) || (option && num_options > 1))
81 {
82 fputs("Resolved conflicts with the following options:\n ", stdout);
83 for (i = 0; i < num_options; i ++)
84 if (!option || _cups_strcasecmp(option, options[i].name))
85 printf(" %s=%s", options[i].name, options[i].value);
86 putchar('\n');
87
88 cupsFreeOptions(num_options, options);
89 }
90
91 if (option)
92 {
93 free(option);
94 option = NULL;
95 }
96
97 if (choice)
98 {
99 free(choice);
100 choice = NULL;
101 }
102
103 printf("\nNew Option(s): ");
104 fflush(stdout);
105 if (!fgets(line, sizeof(line), stdin) || line[0] == '\n')
106 break;
107
108 for (ptr = line; isspace(*ptr & 255); ptr ++);
109 for (optr = ptr; *ptr && *ptr != '='; ptr ++);
110 if (!*ptr)
111 break;
112 for (*ptr++ = '\0', cptr = ptr; *ptr && !isspace(*ptr & 255); ptr ++);
113 if (!*ptr)
114 break;
115 *ptr++ = '\0';
116
117 option = strdup(optr);
118 choice = strdup(cptr);
119 num_options = cupsParseOptions(ptr, 0, &options);
120
121 ppdMarkOption(ppd, option, choice);
122 if (cupsMarkOptions(ppd, num_options, options))
123 puts("Options Conflict!");
124 cupsFreeOptions(num_options, options);
125 }
126
127 if (option)
128 free(option);
129 if (choice)
130 free(choice);
131
132 return (0);
133 }
134
135
136 /*
137 * End of "$Id$".
138 */