4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * This file contains an extremely rudimentary implementation of PPD file
30 * parsing support. The parsing done here converts the contents of a PPD
31 * file into a set of PAPI attributes that applications can use to build
41 process_line(char *line
, char **key
, char **value
, char **comment
)
49 if ((ptr
= strchr(line
, ':')) == NULL
)
53 * line is in the form:
56 * *key value/comment: data
59 while (isspace(*ptr
) != 0)
62 if ((ptr2
= strchr(line
, ' ')) != NULL
) {
65 * line is in the form:
66 * *key value/comment: data
78 if ((ptr
= strchr(ptr
, '/')) != NULL
) {
85 PPDFileToAttributesList(papi_attribute_t
***attributes
, char *filename
)
87 papi_status_t status
= PAPI_OK
;
93 char *current_group_name
= NULL
;
97 if ((fp
= fopen(filename
, "r")) == NULL
)
98 return (PAPI_NOT_POSSIBLE
);
100 while ((status
== PAPI_OK
) &&
101 (fgets(line
, sizeof (line
), fp
) != NULL
)) {
102 char *key
= NULL
, *value
= NULL
, *text
= NULL
;
104 /* we want *key...: "value" */
108 if (strchr(line
, ':') == NULL
)
111 if ((text
= strrchr(line
, '\n')) != NULL
)
114 process_line(line
, &key
, &value
, &text
);
116 if ((strcasecmp(key
, "PageSize") == 0) ||
117 (strcasecmp(key
, "InputSlot") == 0))
120 if (strcasecmp(key
, "OpenGroup") == 0) {
123 current_group_name
= strdup(value
);
124 } else if (strcasecmp(key
, "OpenUI") == 0) {
125 if ((strcasecmp(value
, "PageSize") == 0) ||
126 (strcasecmp(value
, "InputSlot") == 0))
128 snprintf(capability
, sizeof (capability
), "%s", value
);
129 snprintf(def
, sizeof (def
),
130 "%s-default", value
);
131 snprintf(supported
, sizeof (supported
),
132 "%s-supported", value
);
134 } else if (strcasecmp(key
, "CloseGroup") == 0) {
136 } else if (strcasecmp(key
, "CloseUI") == 0) {
139 } else if (strcasecmp(key
, "Manufacturer") == 0) {
140 status
= papiAttributeListAddString(attributes
,
142 "printer-make", value
);
143 } else if (strcasecmp(key
, "ModelName") == 0) {
144 status
= papiAttributeListAddString(attributes
,
146 "printer-model", value
);
147 } else if (strcasecmp(key
, "ShortNickName") == 0) {
148 status
= papiAttributeListAddString(attributes
,
150 "printer-make-and-model", value
);
151 } else if ((strncasecmp(key
, "Default", 7) == 0) && ui
) {
152 status
= papiAttributeListAddString(attributes
,
155 } else if ((strcasecmp(key
, capability
) == 0) && ui
) {
156 status
= papiAttributeListAddString(attributes
,