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