]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testconflicts.c
Import CUPS v1.7.1
[thirdparty/cups.git] / cups / testconflicts.c
CommitLineData
247efae5 1/*
61515785 2 * "$Id: testconflicts.c 3755 2012-03-30 05:59:14Z msweet $"
247efae5 3 *
71e16022 4 * PPD constraint test program for CUPS.
247efae5 5 *
82cc1f9a 6 * Copyright 2008-2012 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 ++)
88f9aafc 84 if (!option || _cups_strcasecmp(option, options[i].name))
d1c13e16 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);
82cc1f9a
MS
94 option = NULL;
95 }
96
97 if (choice)
98 {
c168a833 99 free(choice);
82cc1f9a 100 choice = NULL;
c168a833
MS
101 }
102
247efae5
MS
103 printf("\nNew Option(s): ");
104 fflush(stdout);
105 if (!fgets(line, sizeof(line), stdin) || line[0] == '\n')
106 break;
107
d1c13e16
MS
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);
c168a833 120
d1c13e16 121 ppdMarkOption(ppd, option, choice);
247efae5
MS
122 if (cupsMarkOptions(ppd, num_options, options))
123 puts("Options Conflict!");
124 cupsFreeOptions(num_options, options);
125 }
126
82cc1f9a
MS
127 if (option)
128 free(option);
129 if (choice)
130 free(choice);
131
247efae5
MS
132 return (0);
133}
134
135
136/*
61515785 137 * End of "$Id: testconflicts.c 3755 2012-03-30 05:59:14Z msweet $".
247efae5 138 */