]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testconflicts.c
Merge changes from CUPS 1.5b1-r9774.
[thirdparty/cups.git] / cups / testconflicts.c
CommitLineData
247efae5
MS
1/*
2 * "$Id$"
3 *
71e16022 4 * PPD constraint test program for CUPS.
247efae5 5 *
71e16022 6 * Copyright 2008-2010 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"
aaf19ab0 26#include "ppd.h"
71e16022 27#include "string-private.h"
247efae5
MS
28
29
30/*
31 * 'main()' - Main entry.
32 */
33
34int /* O - Exit status */
35main(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 */
d1c13e16
MS
40 char line[256], /* Input buffer */
41 *ptr, /* Pointer into buffer */
42 *optr, /* Pointer to first option name */
43 *cptr; /* Pointer to first choice */
247efae5
MS
44 int num_options; /* Number of options */
45 cups_option_t *options; /* Options */
c168a833
MS
46 char *option, /* Current option */
47 *choice; /* Current choice */
247efae5
MS
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
c168a833
MS
70 option = NULL;
71 choice = NULL;
72
247efae5
MS
73 for (;;)
74 {
75 num_options = 0;
76 options = NULL;
77
c168a833 78 if (!cupsResolveConflicts(ppd, option, choice, &num_options, &options))
247efae5 79 puts("Unable to resolve conflicts!");
d1c13e16 80 else if ((!option && num_options > 0) || (option && num_options > 1))
247efae5
MS
81 {
82 fputs("Resolved conflicts with the following options:\n ", stdout);
83 for (i = 0; i < num_options; i ++)
d1c13e16
MS
84 if (!option || strcasecmp(option, options[i].name))
85 printf(" %s=%s", options[i].name, options[i].value);
247efae5
MS
86 putchar('\n');
87
88 cupsFreeOptions(num_options, options);
89 }
90
c168a833
MS
91 if (option)
92 {
93 free(option);
94 free(choice);
95 }
96
247efae5
MS
97 printf("\nNew Option(s): ");
98 fflush(stdout);
99 if (!fgets(line, sizeof(line), stdin) || line[0] == '\n')
100 break;
101
d1c13e16
MS
102 for (ptr = line; isspace(*ptr & 255); ptr ++);
103 for (optr = ptr; *ptr && *ptr != '='; ptr ++);
104 if (!*ptr)
105 break;
106 for (*ptr++ = '\0', cptr = ptr; *ptr && !isspace(*ptr & 255); ptr ++);
107 if (!*ptr)
108 break;
109 *ptr++ = '\0';
110
111 option = strdup(optr);
112 choice = strdup(cptr);
113 num_options = cupsParseOptions(ptr, 0, &options);
c168a833 114
d1c13e16 115 ppdMarkOption(ppd, option, choice);
247efae5
MS
116 if (cupsMarkOptions(ppd, num_options, options))
117 puts("Options Conflict!");
118 cupsFreeOptions(num_options, options);
119 }
120
121 return (0);
122}
123
124
125/*
126 * End of "$Id$".
127 */