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