]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testconflicts.c
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...
26 #include "string-private.h"
30 * 'main()' - Main entry.
33 int /* O - Exit status */
34 main(int argc
, /* I - Number of command-line arguments */
35 char *argv
[]) /* I - Command-line arguments */
37 int i
; /* Looping var */
38 ppd_file_t
*ppd
; /* PPD file loaded from disk */
39 char line
[256], /* Input buffer */
40 *ptr
, /* Pointer into buffer */
41 *optr
, /* Pointer to first option name */
42 *cptr
; /* Pointer to first choice */
43 int num_options
; /* Number of options */
44 cups_option_t
*options
; /* Options */
45 char *option
, /* Current option */
46 *choice
; /* Current choice */
51 puts("Usage: testconflicts filename.ppd");
55 if ((ppd
= ppdOpenFile(argv
[1])) == NULL
)
57 ppd_status_t err
; /* Last error in file */
58 int linenum
; /* Line number in file */
60 err
= ppdLastError(&linenum
);
62 printf("Unable to open PPD file \"%s\": %s on line %d\n", argv
[1],
63 ppdErrorString(err
), linenum
);
77 if (!cupsResolveConflicts(ppd
, option
, choice
, &num_options
, &options
))
78 puts("Unable to resolve conflicts!");
79 else if ((!option
&& num_options
> 0) || (option
&& num_options
> 1))
81 fputs("Resolved conflicts with the following options:\n ", stdout
);
82 for (i
= 0; i
< num_options
; i
++)
83 if (!option
|| strcasecmp(option
, options
[i
].name
))
84 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
87 cupsFreeOptions(num_options
, options
);
96 printf("\nNew Option(s): ");
98 if (!fgets(line
, sizeof(line
), stdin
) || line
[0] == '\n')
101 for (ptr
= line
; isspace(*ptr
& 255); ptr
++);
102 for (optr
= ptr
; *ptr
&& *ptr
!= '='; ptr
++);
105 for (*ptr
++ = '\0', cptr
= ptr
; *ptr
&& !isspace(*ptr
& 255); ptr
++);
110 option
= strdup(optr
);
111 choice
= strdup(cptr
);
112 num_options
= cupsParseOptions(ptr
, 0, &options
);
114 ppdMarkOption(ppd
, option
, choice
);
115 if (cupsMarkOptions(ppd
, num_options
, options
))
116 puts("Options Conflict!");
117 cupsFreeOptions(num_options
, options
);