]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testconflicts.c
Merge changes from CUPS 1.4svn-r8196 (CUPS 1.4b2)
[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 *
6 * Copyright 2008 by Apple Inc.
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 */
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
64 for (;;)
65 {
66 num_options = 0;
67 options = NULL;
68
69 if (!cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options))
70 puts("Unable to resolve conflicts!");
71 else if (num_options > 0)
72 {
73 fputs("Resolved conflicts with the following options:\n ", stdout);
74 for (i = 0; i < num_options; i ++)
75 printf(" %s=%s", options[i].name, options[i].value);
76 putchar('\n');
77
78 cupsFreeOptions(num_options, options);
79 }
80
81 printf("\nNew Option(s): ");
82 fflush(stdout);
83 if (!fgets(line, sizeof(line), stdin) || line[0] == '\n')
84 break;
85
86 num_options = cupsParseOptions(line, 0, &options);
87 if (cupsMarkOptions(ppd, num_options, options))
88 puts("Options Conflict!");
89 cupsFreeOptions(num_options, options);
90 }
91
92 return (0);
93}
94
95
96/*
97 * End of "$Id$".
98 */