2 * PPD constraint test program for CUPS.
4 * Copyright 2008-2012 by Apple Inc.
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 * missing or damaged, see the license at "http://www.cups.org/".
12 * This file is subject to the Apple OS-Developed Software exception.
16 * Include necessary headers...
21 #include "string-private.h"
25 * 'main()' - Main entry.
28 int /* O - Exit status */
29 main(int argc, /* I - Number of command-line arguments */
30 char *argv[]) /* I - Command-line arguments */
32 int i; /* Looping var */
33 ppd_file_t *ppd; /* PPD file loaded from disk */
34 char line[256], /* Input buffer */
35 *ptr, /* Pointer into buffer */
36 *optr, /* Pointer to first option name */
37 *cptr; /* Pointer to first choice */
38 int num_options; /* Number of options */
39 cups_option_t *options; /* Options */
40 char *option, /* Current option */
41 *choice; /* Current choice */
46 puts("Usage: testconflicts filename.ppd");
50 if ((ppd = ppdOpenFile(argv[1])) == NULL)
52 ppd_status_t err; /* Last error in file */
53 int linenum; /* Line number in file */
55 err = ppdLastError(&linenum);
57 printf("Unable to open PPD file \"%s\": %s on line %d\n", argv[1],
58 ppdErrorString(err), linenum);
72 if (!cupsResolveConflicts(ppd, option, choice, &num_options, &options))
73 puts("Unable to resolve conflicts!");
74 else if ((!option && num_options > 0) || (option && num_options > 1))
76 fputs("Resolved conflicts with the following options:\n ", stdout);
77 for (i = 0; i < num_options; i ++)
78 if (!option || _cups_strcasecmp(option, options[i].name))
79 printf(" %s=%s", options[i].name, options[i].value);
82 cupsFreeOptions(num_options, options);
97 printf("\nNew Option(s): ");
99 if (!fgets(line, sizeof(line), stdin) || line[0] == '\n')
102 for (ptr = line; isspace(*ptr & 255); ptr ++);
103 for (optr = ptr; *ptr && *ptr != '='; ptr ++);
106 for (*ptr++ = '\0', cptr = ptr; *ptr && !isspace(*ptr & 255); ptr ++);
111 option = strdup(optr);
112 choice = strdup(cptr);
113 num_options = cupsParseOptions(ptr, 0, &options);
115 ppdMarkOption(ppd, option, choice);
116 if (cupsMarkOptions(ppd, num_options, options))
117 puts("Options Conflict!");
118 cupsFreeOptions(num_options, options);