]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testconflicts.c
Greatly simplify the man page handling.
[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 *
e3101897 6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
247efae5
MS
7 */
8
9/*
10 * Include necessary headers...
11 */
12
13#include "cups.h"
aaf19ab0 14#include "ppd.h"
71e16022 15#include "string-private.h"
247efae5
MS
16
17
18/*
19 * 'main()' - Main entry.
20 */
21
22int /* O - Exit status */
23main(int argc, /* I - Number of command-line arguments */
24 char *argv[]) /* I - Command-line arguments */
25{
26 int i; /* Looping var */
27 ppd_file_t *ppd; /* PPD file loaded from disk */
d1c13e16
MS
28 char line[256], /* Input buffer */
29 *ptr, /* Pointer into buffer */
30 *optr, /* Pointer to first option name */
31 *cptr; /* Pointer to first choice */
247efae5
MS
32 int num_options; /* Number of options */
33 cups_option_t *options; /* Options */
c168a833
MS
34 char *option, /* Current option */
35 *choice; /* Current choice */
247efae5
MS
36
37
38 if (argc != 2)
39 {
40 puts("Usage: testconflicts filename.ppd");
41 return (1);
42 }
43
44 if ((ppd = ppdOpenFile(argv[1])) == NULL)
45 {
46 ppd_status_t err; /* Last error in file */
47 int linenum; /* Line number in file */
48
49 err = ppdLastError(&linenum);
50
51 printf("Unable to open PPD file \"%s\": %s on line %d\n", argv[1],
52 ppdErrorString(err), linenum);
53 return (1);
54 }
55
56 ppdMarkDefaults(ppd);
57
c168a833
MS
58 option = NULL;
59 choice = NULL;
60
247efae5
MS
61 for (;;)
62 {
63 num_options = 0;
64 options = NULL;
65
c168a833 66 if (!cupsResolveConflicts(ppd, option, choice, &num_options, &options))
247efae5 67 puts("Unable to resolve conflicts!");
d1c13e16 68 else if ((!option && num_options > 0) || (option && num_options > 1))
247efae5
MS
69 {
70 fputs("Resolved conflicts with the following options:\n ", stdout);
71 for (i = 0; i < num_options; i ++)
88f9aafc 72 if (!option || _cups_strcasecmp(option, options[i].name))
d1c13e16 73 printf(" %s=%s", options[i].name, options[i].value);
247efae5
MS
74 putchar('\n');
75
76 cupsFreeOptions(num_options, options);
77 }
78
c168a833
MS
79 if (option)
80 {
81 free(option);
82cc1f9a
MS
82 option = NULL;
83 }
84
85 if (choice)
86 {
c168a833 87 free(choice);
82cc1f9a 88 choice = NULL;
c168a833
MS
89 }
90
247efae5
MS
91 printf("\nNew Option(s): ");
92 fflush(stdout);
93 if (!fgets(line, sizeof(line), stdin) || line[0] == '\n')
94 break;
95
d1c13e16
MS
96 for (ptr = line; isspace(*ptr & 255); ptr ++);
97 for (optr = ptr; *ptr && *ptr != '='; ptr ++);
98 if (!*ptr)
99 break;
100 for (*ptr++ = '\0', cptr = ptr; *ptr && !isspace(*ptr & 255); ptr ++);
101 if (!*ptr)
102 break;
103 *ptr++ = '\0';
104
105 option = strdup(optr);
106 choice = strdup(cptr);
107 num_options = cupsParseOptions(ptr, 0, &options);
c168a833 108
d1c13e16 109 ppdMarkOption(ppd, option, choice);
247efae5
MS
110 if (cupsMarkOptions(ppd, num_options, options))
111 puts("Options Conflict!");
112 cupsFreeOptions(num_options, options);
113 }
114
82cc1f9a
MS
115 if (option)
116 free(option);
117 if (choice)
118 free(choice);
119
247efae5
MS
120 return (0);
121}