• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * PPD cache testing program for CUPS.
3  *
4  * Copyright 2009-2014 by Apple Inc.
5  *
6  * These coded instructions, statements, and computer programs are the
7  * property of Apple Inc. and are protected by Federal copyright
8  * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
9  * which should have been included with this file.  If this file is
10  * missing or damaged, see the license at "http://www.cups.org/".
11  *
12  * This file is subject to the Apple OS-Developed Software exception.
13  */
14 
15 /*
16  * Include necessary headers...
17  */
18 
19 #include "ppd-private.h"
20 #include "file-private.h"
21 
22 
23 /*
24  * 'main()' - Main entry.
25  */
26 
27 int					/* O - Exit status */
main(int argc,char * argv[])28 main(int  argc,				/* I - Number of command-line args */
29      char *argv[])			/* I - Command-line arguments */
30 {
31   int			i;		/* Looping var */
32   const char		*ppdfile = NULL;/* PPD filename */
33   ppd_file_t		*ppd;		/* PPD file */
34   int			num_options = 0;/* Number of options */
35   cups_option_t		*options = NULL;/* Options */
36   _ppd_cache_t		*pc;		/* PPD cache and PWG mapping data */
37   int			num_finishings,	/* Number of finishing options */
38 			finishings[20];	/* Finishing options */
39   ppd_choice_t		*ppd_bin;	/* OutputBin value */
40   const char		*output_bin;	/* output-bin value */
41 
42   if (argc < 2)
43   {
44     puts("Usage: ./testcache filename.ppd [name=value ... name=value]");
45     return (1);
46   }
47 
48   ppdfile = argv[1];
49   if ((ppd = ppdOpenFile(ppdfile)) == NULL)
50   {
51     ppd_status_t err;			/* Last error in file */
52     int		line;			/* Line number in file */
53 
54 
55     err = ppdLastError(&line);
56 
57     fprintf(stderr, "Unable to open \"%s\": %s on line %d\n", ppdfile, ppdErrorString(err), line);
58     return (1);
59   }
60 
61   if ((pc = _ppdCacheCreateWithPPD(ppd)) == NULL)
62   {
63     fprintf(stderr, "Unable to create PPD cache from \"%s\".\n", ppdfile);
64     return (1);
65   }
66 
67   for (i = 2; i < argc; i ++)
68     num_options = cupsParseOptions(argv[i], num_options, &options);
69 
70   ppdMarkDefaults(ppd);
71   cupsMarkOptions(ppd, num_options, options);
72 
73   num_finishings = _ppdCacheGetFinishingValues(pc, num_options, options, (int)sizeof(finishings) / sizeof(finishings[0]), finishings);
74 
75   if (num_finishings > 0)
76   {
77     fputs("finishings=", stdout);
78     for (i = 0; i < num_finishings; i ++)
79       if (i)
80 	printf(",%d", finishings[i]);
81       else
82 	printf("%d", finishings[i]);
83     fputs("\n", stdout);
84   }
85 
86   if ((ppd_bin = ppdFindMarkedChoice(ppd, "OutputBin")) != NULL &&
87       (output_bin = _ppdCacheGetBin(pc, ppd_bin->choice)) != NULL)
88     printf("output-bin=\"%s\"\n", output_bin);
89 
90   return (0);
91 }
92