]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testconflicts.c
2 * PPD constraint test program for CUPS.
4 * Copyright 2008-2012 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
10 * Include necessary headers...
15 #include "string-private.h"
19 * 'main()' - Main entry.
22 int /* O - Exit status */
23 main(int argc
, /* I - Number of command-line arguments */
24 char *argv
[]) /* I - Command-line arguments */
26 int i
; /* Looping var */
27 ppd_file_t
*ppd
; /* PPD file loaded from disk */
28 char line
[256], /* Input buffer */
29 *ptr
, /* Pointer into buffer */
30 *optr
, /* Pointer to first option name */
31 *cptr
; /* Pointer to first choice */
32 int num_options
; /* Number of options */
33 cups_option_t
*options
; /* Options */
34 char *option
, /* Current option */
35 *choice
; /* Current choice */
40 puts("Usage: testconflicts filename.ppd");
44 if ((ppd
= ppdOpenFile(argv
[1])) == NULL
)
46 ppd_status_t err
; /* Last error in file */
47 int linenum
; /* Line number in file */
49 err
= ppdLastError(&linenum
);
51 printf("Unable to open PPD file \"%s\": %s on line %d\n", argv
[1],
52 ppdErrorString(err
), linenum
);
66 if (!cupsResolveConflicts(ppd
, option
, choice
, &num_options
, &options
))
67 puts("Unable to resolve conflicts!");
68 else if ((!option
&& num_options
> 0) || (option
&& num_options
> 1))
70 fputs("Resolved conflicts with the following options:\n ", stdout
);
71 for (i
= 0; i
< num_options
; i
++)
72 if (!option
|| _cups_strcasecmp(option
, options
[i
].name
))
73 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
76 cupsFreeOptions(num_options
, options
);
91 printf("\nNew Option(s): ");
93 if (!fgets(line
, sizeof(line
), stdin
) || line
[0] == '\n')
96 for (ptr
= line
; isspace(*ptr
& 255); ptr
++);
97 for (optr
= ptr
; *ptr
&& *ptr
!= '='; ptr
++);
100 for (*ptr
++ = '\0', cptr
= ptr
; *ptr
&& !isspace(*ptr
& 255); ptr
++);
105 option
= strdup(optr
);
106 choice
= strdup(cptr
);
107 num_options
= cupsParseOptions(ptr
, 0, &options
);
109 ppdMarkOption(ppd
, option
, choice
);
110 if (cupsMarkOptions(ppd
, num_options
, options
))
111 puts("Options Conflict!");
112 cupsFreeOptions(num_options
, options
);