1 /*
2 * PPD cache testing program for CUPS.
3 *
4 * Copyright 2009-2018 by Apple Inc.
5 *
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
7 */
8
9 /*
10 * Include necessary headers...
11 */
12
13 #include "ppd-private.h"
14 #include "file-private.h"
15
16
17 /*
18 * 'main()' - Main entry.
19 */
20
21 int /* O - Exit status */
main(int argc,char * argv[])22 main(int argc, /* I - Number of command-line args */
23 char *argv[]) /* I - Command-line arguments */
24 {
25 int i; /* Looping var */
26 const char *ppdfile = NULL;/* PPD filename */
27 ppd_file_t *ppd; /* PPD file */
28 int num_options = 0;/* Number of options */
29 cups_option_t *options = NULL;/* Options */
30 _ppd_cache_t *pc; /* PPD cache and PWG mapping data */
31 int num_finishings, /* Number of finishing options */
32 finishings[20]; /* Finishing options */
33 ppd_choice_t *ppd_bin; /* OutputBin value */
34 const char *output_bin; /* output-bin value */
35
36 if (argc < 2)
37 {
38 puts("Usage: ./testcache filename.ppd [name=value ... name=value]");
39 return (1);
40 }
41
42 ppdfile = argv[1];
43 if ((ppd = ppdOpenFile(ppdfile)) == NULL)
44 {
45 ppd_status_t err; /* Last error in file */
46 int line; /* Line number in file */
47
48
49 err = ppdLastError(&line);
50
51 fprintf(stderr, "Unable to open \"%s\": %s on line %d\n", ppdfile, ppdErrorString(err), line);
52 return (1);
53 }
54
55 if ((pc = _ppdCacheCreateWithPPD(ppd)) == NULL)
56 {
57 fprintf(stderr, "Unable to create PPD cache from \"%s\".\n", ppdfile);
58 return (1);
59 }
60
61 for (i = 2; i < argc; i ++)
62 num_options = cupsParseOptions(argv[i], num_options, &options);
63
64 ppdMarkDefaults(ppd);
65 cupsMarkOptions(ppd, num_options, options);
66
67 num_finishings = _ppdCacheGetFinishingValues(ppd, pc, (int)sizeof(finishings) / sizeof(finishings[0]), finishings);
68
69 if (num_finishings > 0)
70 {
71 fputs("finishings=", stdout);
72 for (i = 0; i < num_finishings; i ++)
73 if (i)
74 printf(",%d", finishings[i]);
75 else
76 printf("%d", finishings[i]);
77 fputs("\n", stdout);
78 }
79
80 if ((ppd_bin = ppdFindMarkedChoice(ppd, "OutputBin")) != NULL &&
81 (output_bin = _ppdCacheGetBin(pc, ppd_bin->choice)) != NULL)
82 printf("output-bin=\"%s\"\n", output_bin);
83
84 return (0);
85 }
86