]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testconflicts.c
7bfe420bf7aa351c9498b68800a3915fc55993ab
4 * PPD constraint test program for CUPS.
6 * Copyright 2008-2010 by Apple Inc.
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/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * main() - Main entry.
22 * Include necessary headers...
27 #include "string-private.h"
31 * 'main()' - Main entry.
34 int /* O - Exit status */
35 main(int argc
, /* I - Number of command-line arguments */
36 char *argv
[]) /* I - Command-line arguments */
38 int i
; /* Looping var */
39 ppd_file_t
*ppd
; /* PPD file loaded from disk */
40 char line
[256], /* Input buffer */
41 *ptr
, /* Pointer into buffer */
42 *optr
, /* Pointer to first option name */
43 *cptr
; /* Pointer to first choice */
44 int num_options
; /* Number of options */
45 cups_option_t
*options
; /* Options */
46 char *option
, /* Current option */
47 *choice
; /* Current choice */
52 puts("Usage: testconflicts filename.ppd");
56 if ((ppd
= ppdOpenFile(argv
[1])) == NULL
)
58 ppd_status_t err
; /* Last error in file */
59 int linenum
; /* Line number in file */
61 err
= ppdLastError(&linenum
);
63 printf("Unable to open PPD file \"%s\": %s on line %d\n", argv
[1],
64 ppdErrorString(err
), linenum
);
78 if (!cupsResolveConflicts(ppd
, option
, choice
, &num_options
, &options
))
79 puts("Unable to resolve conflicts!");
80 else if ((!option
&& num_options
> 0) || (option
&& num_options
> 1))
82 fputs("Resolved conflicts with the following options:\n ", stdout
);
83 for (i
= 0; i
< num_options
; i
++)
84 if (!option
|| strcasecmp(option
, options
[i
].name
))
85 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
88 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
);