• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   PPD attribute lookup routine for CUPS.
3  *
4  *   Copyright 2007-2011 by Apple Inc.
5  *   Copyright 1993-2005 by Easy Software Products.
6  *
7  *   These coded instructions, statements, and computer programs are the
8  *   property of Apple Inc. and are protected by Federal copyright
9  *   law.  Distribution and use rights are outlined in the file "COPYING"
10  *   which should have been included with this file.
11  *
12  * Contents:
13  *
14  *   cupsFindAttr() - Find a PPD attribute based on the colormodel,
15  *                    media, and resolution.
16  */
17 
18 /*
19  * Include necessary headers.
20  */
21 
22 #include <config.h>
23 #include "driver.h"
24 #include <string.h>
25 #include <ctype.h>
26 
27 
28 /*
29  * 'cupsFindAttr()' - Find a PPD attribute based on the colormodel,
30  *                    media, and resolution.
31  */
32 
33 ppd_attr_t *				/* O - Matching attribute or NULL */
cupsFindAttr(ppd_file_t * ppd,const char * name,const char * colormodel,const char * media,const char * resolution,char * spec,int specsize)34 cupsFindAttr(ppd_file_t *ppd,		/* I - PPD file */
35              const char *name,		/* I - Attribute name */
36              const char *colormodel,	/* I - Color model */
37              const char *media,		/* I - Media type */
38              const char *resolution,	/* I - Resolution */
39 	     char       *spec,		/* O - Final selection string */
40 	     int        specsize)	/* I - Size of string buffer */
41 {
42   ppd_attr_t	*attr;			/* Attribute */
43 
44 
45  /*
46   * Range check input...
47   */
48 
49   if (!ppd || !name || !colormodel || !media || !resolution || !spec ||
50       specsize < PPD_MAX_NAME)
51     return (NULL);
52 
53  /*
54   * Look for the attribute with the following keywords:
55   *
56   *     ColorModel.MediaType.Resolution
57   *     ColorModel.Resolution
58   *     ColorModel
59   *     MediaType.Resolution
60   *     MediaType
61   *     Resolution
62   *     ""
63   */
64 
65   snprintf(spec, specsize, "%s.%s.%s", colormodel, media, resolution);
66   fprintf(stderr, "DEBUG2: Looking for \"*%s %s\"...\n", name, spec);
67   if ((attr = ppdFindAttr(ppd, name, spec)) != NULL && attr->value != NULL)
68     return (attr);
69 
70   snprintf(spec, specsize, "%s.%s", colormodel, resolution);
71   fprintf(stderr, "DEBUG2: Looking for \"*%s %s\"...\n", name, spec);
72   if ((attr = ppdFindAttr(ppd, name, spec)) != NULL && attr->value != NULL)
73     return (attr);
74 
75   snprintf(spec, specsize, "%s", colormodel);
76   fprintf(stderr, "DEBUG2: Looking for \"*%s %s\"...\n", name, spec);
77   if ((attr = ppdFindAttr(ppd, name, spec)) != NULL && attr->value != NULL)
78     return (attr);
79 
80   snprintf(spec, specsize, "%s.%s", media, resolution);
81   fprintf(stderr, "DEBUG2: Looking for \"*%s %s\"...\n", name, spec);
82   if ((attr = ppdFindAttr(ppd, name, spec)) != NULL && attr->value != NULL)
83     return (attr);
84 
85   snprintf(spec, specsize, "%s", media);
86   fprintf(stderr, "DEBUG2: Looking for \"*%s %s\"...\n", name, spec);
87   if ((attr = ppdFindAttr(ppd, name, spec)) != NULL && attr->value != NULL)
88     return (attr);
89 
90   snprintf(spec, specsize, "%s", resolution);
91   fprintf(stderr, "DEBUG2: Looking for \"*%s %s\"...\n", name, spec);
92   if ((attr = ppdFindAttr(ppd, name, spec)) != NULL && attr->value != NULL)
93     return (attr);
94 
95   spec[0] = '\0';
96   fprintf(stderr, "DEBUG2: Looking for \"*%s\"...\n", name);
97   if ((attr = ppdFindAttr(ppd, name, spec)) != NULL && attr->value != NULL)
98     return (attr);
99 
100   fprintf(stderr, "DEBUG2: No instance of \"*%s\" found...\n", name);
101 
102   return (NULL);
103 }
104 
105