]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testconflicts.c
Changelog.
[thirdparty/cups.git] / cups / testconflicts.c
CommitLineData
247efae5 1/*
503b54c9 2 * PPD constraint test program for CUPS.
247efae5 3 *
503b54c9 4 * Copyright 2008-2012 by Apple Inc.
247efae5 5 *
503b54c9
MS
6 * These coded instructions, statements, and computer programs are the
7 * property of Apple Inc. and are protected by Federal copyright
8 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
9 * which should have been included with this file. If this file is
10 * file is missing or damaged, see the license at "http://www.cups.org/".
247efae5 11 *
503b54c9 12 * This file is subject to the Apple OS-Developed Software exception.
247efae5
MS
13 */
14
15/*
16 * Include necessary headers...
17 */
18
19#include "cups.h"
aaf19ab0 20#include "ppd.h"
71e16022 21#include "string-private.h"
247efae5
MS
22
23
24/*
25 * 'main()' - Main entry.
26 */
27
28int /* O - Exit status */
29main(int argc, /* I - Number of command-line arguments */
30 char *argv[]) /* I - Command-line arguments */
31{
32 int i; /* Looping var */
33 ppd_file_t *ppd; /* PPD file loaded from disk */
d1c13e16
MS
34 char line[256], /* Input buffer */
35 *ptr, /* Pointer into buffer */
36 *optr, /* Pointer to first option name */
37 *cptr; /* Pointer to first choice */
247efae5
MS
38 int num_options; /* Number of options */
39 cups_option_t *options; /* Options */
c168a833
MS
40 char *option, /* Current option */
41 *choice; /* Current choice */
247efae5
MS
42
43
44 if (argc != 2)
45 {
46 puts("Usage: testconflicts filename.ppd");
47 return (1);
48 }
49
50 if ((ppd = ppdOpenFile(argv[1])) == NULL)
51 {
52 ppd_status_t err; /* Last error in file */
53 int linenum; /* Line number in file */
54
55 err = ppdLastError(&linenum);
56
57 printf("Unable to open PPD file \"%s\": %s on line %d\n", argv[1],
58 ppdErrorString(err), linenum);
59 return (1);
60 }
61
62 ppdMarkDefaults(ppd);
63
c168a833
MS
64 option = NULL;
65 choice = NULL;
66
247efae5
MS
67 for (;;)
68 {
69 num_options = 0;
70 options = NULL;
71
c168a833 72 if (!cupsResolveConflicts(ppd, option, choice, &num_options, &options))
247efae5 73 puts("Unable to resolve conflicts!");
d1c13e16 74 else if ((!option && num_options > 0) || (option && num_options > 1))
247efae5
MS
75 {
76 fputs("Resolved conflicts with the following options:\n ", stdout);
77 for (i = 0; i < num_options; i ++)
88f9aafc 78 if (!option || _cups_strcasecmp(option, options[i].name))
d1c13e16 79 printf(" %s=%s", options[i].name, options[i].value);
247efae5
MS
80 putchar('\n');
81
82 cupsFreeOptions(num_options, options);
83 }
84
c168a833
MS
85 if (option)
86 {
87 free(option);
82cc1f9a
MS
88 option = NULL;
89 }
90
91 if (choice)
92 {
c168a833 93 free(choice);
82cc1f9a 94 choice = NULL;
c168a833
MS
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
82cc1f9a
MS
121 if (option)
122 free(option);
123 if (choice)
124 free(choice);
125
247efae5
MS
126 return (0);
127}