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