17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5355b4669Sjacobs  * Common Development and Distribution License (the "License").
6355b4669Sjacobs  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21355b4669Sjacobs 
227c478bd9Sstevel@tonic-gate /*
23ee169c7eSGary Mills  * Copyright (c) 2014 Gary Mills
24ee169c7eSGary Mills  *
2543b9c050Sjacobs  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
27355b4669Sjacobs  *
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <stdio.h>
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
34355b4669Sjacobs #include <stdarg.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
3643b9c050Sjacobs #include <ctype.h>
37355b4669Sjacobs #include <alloca.h>
38355b4669Sjacobs #include <papi.h>
3943b9c050Sjacobs #include <regex.h>
407c478bd9Sstevel@tonic-gate 
41fa9d6f9fSsg #define	MAX_PAGES 32767
42fa9d6f9fSsg /*
43fa9d6f9fSsg  * Assuming the maximum number of pages in
44fa9d6f9fSsg  * a document to be 32767
45fa9d6f9fSsg  */
46fa9d6f9fSsg 
477c478bd9Sstevel@tonic-gate static void papiAttributeFree(papi_attribute_t *attribute);
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate static void
papiAttributeValueFree(papi_attribute_value_type_t type,papi_attribute_value_t * value)507c478bd9Sstevel@tonic-gate papiAttributeValueFree(papi_attribute_value_type_t type,
513cf7d3e9SToomas Soome     papi_attribute_value_t *value)
527c478bd9Sstevel@tonic-gate {
537c478bd9Sstevel@tonic-gate 	if (value != NULL) {
547c478bd9Sstevel@tonic-gate 		switch (type) {
557c478bd9Sstevel@tonic-gate 		case PAPI_STRING:
567c478bd9Sstevel@tonic-gate 			if (value->string != NULL)
577c478bd9Sstevel@tonic-gate 				free(value->string);
587c478bd9Sstevel@tonic-gate 			break;
597c478bd9Sstevel@tonic-gate 		case PAPI_COLLECTION:
607c478bd9Sstevel@tonic-gate 			if (value->collection != NULL) {
617c478bd9Sstevel@tonic-gate 				int i;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 				for (i = 0; value->collection[i] != NULL; i++)
647c478bd9Sstevel@tonic-gate 					papiAttributeFree(value->collection[i]);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 				free(value->collection);
677c478bd9Sstevel@tonic-gate 			}
687c478bd9Sstevel@tonic-gate 			break;
697c478bd9Sstevel@tonic-gate 		default: /* don't need to free anything extra */
707c478bd9Sstevel@tonic-gate 			break;
717c478bd9Sstevel@tonic-gate 		}
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 		free(value);
747c478bd9Sstevel@tonic-gate 	}
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate static void
papiAttributeValuesFree(papi_attribute_value_type_t type,papi_attribute_value_t ** values)787c478bd9Sstevel@tonic-gate papiAttributeValuesFree(papi_attribute_value_type_t type,
793cf7d3e9SToomas Soome     papi_attribute_value_t **values)
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate 	if (values != NULL) {
827c478bd9Sstevel@tonic-gate 		int i;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 		for (i = 0; values[i] != NULL; i++)
857c478bd9Sstevel@tonic-gate 			papiAttributeValueFree(type, values[i]);
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 		free(values);
887c478bd9Sstevel@tonic-gate 	}
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate static void
papiAttributeFree(papi_attribute_t * attribute)927c478bd9Sstevel@tonic-gate papiAttributeFree(papi_attribute_t *attribute)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	if (attribute != NULL) {
953cf7d3e9SToomas Soome 		free(attribute->name);
967c478bd9Sstevel@tonic-gate 		if (attribute->values != NULL)
977c478bd9Sstevel@tonic-gate 			papiAttributeValuesFree(attribute->type,
983cf7d3e9SToomas Soome 			    attribute->values);
993cf7d3e9SToomas Soome 		free(attribute);
1007c478bd9Sstevel@tonic-gate 	}
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate void
papiAttributeListFree(papi_attribute_t ** list)1047c478bd9Sstevel@tonic-gate papiAttributeListFree(papi_attribute_t **list)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	if (list != NULL) {
1077c478bd9Sstevel@tonic-gate 		int i;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 		for (i = 0; list[i] != NULL; i++)
1107c478bd9Sstevel@tonic-gate 			papiAttributeFree(list[i]);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 		free(list);
1137c478bd9Sstevel@tonic-gate 	}
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate static papi_attribute_t **
collection_dup(papi_attribute_t ** collection)1177c478bd9Sstevel@tonic-gate collection_dup(papi_attribute_t **collection)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 	papi_attribute_t **result = NULL;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	/* allows a NULL collection that is "empty" or "no value" */
1227c478bd9Sstevel@tonic-gate 	if (collection != NULL) {
123355b4669Sjacobs 		papi_status_t status = PAPI_OK;
1247c478bd9Sstevel@tonic-gate 		int i;
1257c478bd9Sstevel@tonic-gate 
126355b4669Sjacobs 		for (i = 0; ((collection[i] != NULL) && (status == PAPI_OK));
1273cf7d3e9SToomas Soome 		    i++) {
1287c478bd9Sstevel@tonic-gate 			papi_attribute_t *a = collection[i];
1297c478bd9Sstevel@tonic-gate 
130355b4669Sjacobs 			status = papiAttributeListAddValue(&result,
1313cf7d3e9SToomas Soome 			    PAPI_ATTR_APPEND, a->name, a->type, NULL);
132355b4669Sjacobs 			if ((status == PAPI_OK) && (a->values != NULL)) {
1337c478bd9Sstevel@tonic-gate 				int j;
1347c478bd9Sstevel@tonic-gate 
135355b4669Sjacobs 				for (j = 0; ((a->values[j] != NULL) &&
1363cf7d3e9SToomas Soome 				    (status == PAPI_OK)); j++)
137355b4669Sjacobs 					status = papiAttributeListAddValue(
1383cf7d3e9SToomas Soome 					    &result, PAPI_ATTR_APPEND,
1393cf7d3e9SToomas Soome 					    a->name, a->type, a->values[j]);
1407c478bd9Sstevel@tonic-gate 			}
1417c478bd9Sstevel@tonic-gate 		}
142355b4669Sjacobs 		if (status != PAPI_OK) {
143355b4669Sjacobs 			papiAttributeListFree(result);
144355b4669Sjacobs 			result = NULL;
145355b4669Sjacobs 		}
1467c478bd9Sstevel@tonic-gate 	}
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	return (result);
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate static papi_attribute_value_t *
papiAttributeValueDup(papi_attribute_value_type_t type,papi_attribute_value_t * v)152355b4669Sjacobs papiAttributeValueDup(papi_attribute_value_type_t type,
1533cf7d3e9SToomas Soome     papi_attribute_value_t *v)
1547c478bd9Sstevel@tonic-gate {
1557c478bd9Sstevel@tonic-gate 	papi_attribute_value_t *result = NULL;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	if ((v != NULL) && ((result = calloc(1, sizeof (*result))) != NULL)) {
1587c478bd9Sstevel@tonic-gate 		switch (type) {
1597c478bd9Sstevel@tonic-gate 		case PAPI_STRING:
1607c478bd9Sstevel@tonic-gate 			if (v->string == NULL) {
1617c478bd9Sstevel@tonic-gate 				free(result);
1627c478bd9Sstevel@tonic-gate 				result = NULL;
163*f4593de7SToomas Soome 			} else {
1647c478bd9Sstevel@tonic-gate 				result->string = strdup(v->string);
165*f4593de7SToomas Soome 			}
1667c478bd9Sstevel@tonic-gate 			break;
1677c478bd9Sstevel@tonic-gate 		case PAPI_INTEGER:
1687c478bd9Sstevel@tonic-gate 			result->integer = v->integer;
1697c478bd9Sstevel@tonic-gate 			break;
1707c478bd9Sstevel@tonic-gate 		case PAPI_BOOLEAN:
1717c478bd9Sstevel@tonic-gate 			result->boolean = v->boolean;
1727c478bd9Sstevel@tonic-gate 			break;
1737c478bd9Sstevel@tonic-gate 		case PAPI_RANGE:
1747c478bd9Sstevel@tonic-gate 			result->range.lower = v->range.lower;
1757c478bd9Sstevel@tonic-gate 			result->range.upper = v->range.upper;
1767c478bd9Sstevel@tonic-gate 			break;
1777c478bd9Sstevel@tonic-gate 		case PAPI_RESOLUTION:
1787c478bd9Sstevel@tonic-gate 			result->resolution.xres = v->resolution.xres;
1797c478bd9Sstevel@tonic-gate 			result->resolution.yres = v->resolution.yres;
1807c478bd9Sstevel@tonic-gate 			result->resolution.units = v->resolution.units;
1817c478bd9Sstevel@tonic-gate 			break;
1827c478bd9Sstevel@tonic-gate 		case PAPI_DATETIME:
1837c478bd9Sstevel@tonic-gate 			result->datetime = v->datetime;
1847c478bd9Sstevel@tonic-gate 			break;
1857c478bd9Sstevel@tonic-gate 		case PAPI_COLLECTION:
1867c478bd9Sstevel@tonic-gate 			result->collection = collection_dup(v->collection);
1877c478bd9Sstevel@tonic-gate 			break;
188355b4669Sjacobs 		case PAPI_METADATA:
189355b4669Sjacobs 			result->metadata = v->metadata;
190355b4669Sjacobs 			break;
1917c478bd9Sstevel@tonic-gate 		default:	/* unknown type, fail to duplicate */
1927c478bd9Sstevel@tonic-gate 			free(result);
1937c478bd9Sstevel@tonic-gate 			result = NULL;
1947c478bd9Sstevel@tonic-gate 		}
1957c478bd9Sstevel@tonic-gate 	}
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	return (result);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate static papi_attribute_t *
papiAttributeAlloc(char * name,papi_attribute_value_type_t type)201355b4669Sjacobs papiAttributeAlloc(char *name, papi_attribute_value_type_t type)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate 	papi_attribute_t *result = NULL;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	if ((result = calloc(1, sizeof (*result))) != NULL) {
2067c478bd9Sstevel@tonic-gate 		result->name = strdup(name);
2077c478bd9Sstevel@tonic-gate 		result->type = type;
2087c478bd9Sstevel@tonic-gate 	}
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	return (result);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate static papi_status_t
papiAttributeListAppendValue(papi_attribute_value_t *** values,papi_attribute_value_type_t type,papi_attribute_value_t * value)214355b4669Sjacobs papiAttributeListAppendValue(papi_attribute_value_t ***values,
2153cf7d3e9SToomas Soome     papi_attribute_value_type_t type,
2163cf7d3e9SToomas Soome     papi_attribute_value_t *value)
2177c478bd9Sstevel@tonic-gate {
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	if (values == NULL)
2207c478bd9Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	if (value != NULL) {	/* this allows "empty" attributes */
2237c478bd9Sstevel@tonic-gate 		papi_attribute_value_t *tmp = NULL;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 		if ((tmp = papiAttributeValueDup(type, value)) == NULL)
2267c478bd9Sstevel@tonic-gate 			return (PAPI_TEMPORARY_ERROR);
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 		list_append(values, tmp);
2297c478bd9Sstevel@tonic-gate 	}
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	return (PAPI_OK);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListAddValue(papi_attribute_t *** list,int flgs,char * name,papi_attribute_value_type_t type,papi_attribute_value_t * value)235355b4669Sjacobs papiAttributeListAddValue(papi_attribute_t ***list, int flgs,
2363cf7d3e9SToomas Soome     char *name, papi_attribute_value_type_t type,
2373cf7d3e9SToomas Soome     papi_attribute_value_t *value)
2387c478bd9Sstevel@tonic-gate {
2397c478bd9Sstevel@tonic-gate 	papi_status_t result;
2407c478bd9Sstevel@tonic-gate 	int flags = flgs;
2417c478bd9Sstevel@tonic-gate 	papi_attribute_t *attribute = NULL;
2427c478bd9Sstevel@tonic-gate 	papi_attribute_value_t **values = NULL;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	if ((list == NULL) || (name == NULL))
2457c478bd9Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	if ((type == PAPI_RANGE) && (value != NULL) &&
2487c478bd9Sstevel@tonic-gate 	    (value->range.lower > value->range.upper))
2497c478bd9Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);	/* RANGE must have min <= max */
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	if (flags == 0) /* if it wasn't set, set a default behaviour */
2527c478bd9Sstevel@tonic-gate 		flags = PAPI_ATTR_APPEND;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	/* look for an existing one */
2557c478bd9Sstevel@tonic-gate 	attribute = papiAttributeListFind(*list, name);
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	if (((flags & PAPI_ATTR_EXCL) != 0) && (attribute != NULL))
2587c478bd9Sstevel@tonic-gate 		return (PAPI_CONFLICT); /* EXISTS */
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 	if (((flags & PAPI_ATTR_REPLACE) == 0) && (attribute != NULL) &&
2617c478bd9Sstevel@tonic-gate 	    (attribute->type != type))
2627c478bd9Sstevel@tonic-gate 		return (PAPI_CONFLICT); /* TYPE CONFLICT */
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	/* if we don't have one, create it and add it to the list */
2657c478bd9Sstevel@tonic-gate 	if ((attribute == NULL) &&
2667c478bd9Sstevel@tonic-gate 	    ((attribute = papiAttributeAlloc(name, type)) != NULL))
2677c478bd9Sstevel@tonic-gate 		list_append(list, attribute);
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	/* if we don't have one by now, it's most likely an alloc fail */
2707c478bd9Sstevel@tonic-gate 	if (attribute == NULL)
2717c478bd9Sstevel@tonic-gate 		return (PAPI_TEMPORARY_ERROR);
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	/*
2747c478bd9Sstevel@tonic-gate 	 * if we are replacing, clear any existing values, but don't free
2757c478bd9Sstevel@tonic-gate 	 * until after we have replaced the values, in case we are replacing
2767c478bd9Sstevel@tonic-gate 	 * a collection with a relocated version of the original collection.
2777c478bd9Sstevel@tonic-gate 	 */
2787c478bd9Sstevel@tonic-gate 	if (((flags & PAPI_ATTR_REPLACE) != 0) && (attribute->values != NULL)) {
2797c478bd9Sstevel@tonic-gate 		values = attribute->values;
2807c478bd9Sstevel@tonic-gate 		attribute->values = NULL;
2817c478bd9Sstevel@tonic-gate 	}
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	attribute->type = type;
2847c478bd9Sstevel@tonic-gate 
285355b4669Sjacobs 	result = papiAttributeListAppendValue(&attribute->values, type, value);
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	/* free old values if we replaced them */
2887c478bd9Sstevel@tonic-gate 	if (values != NULL)
2897c478bd9Sstevel@tonic-gate 		papiAttributeValuesFree(type, values);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	return (result);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListAddString(papi_attribute_t *** list,int flags,char * name,char * string)295355b4669Sjacobs papiAttributeListAddString(papi_attribute_t ***list, int flags,
2963cf7d3e9SToomas Soome     char *name, char *string)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	papi_attribute_value_t v;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	v.string = (char *)string;
301355b4669Sjacobs 	return (papiAttributeListAddValue(list, flags, name, PAPI_STRING, &v));
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListAddInteger(papi_attribute_t *** list,int flags,char * name,int integer)305355b4669Sjacobs papiAttributeListAddInteger(papi_attribute_t ***list, int flags,
3063cf7d3e9SToomas Soome     char *name, int integer)
3077c478bd9Sstevel@tonic-gate {
3087c478bd9Sstevel@tonic-gate 	papi_attribute_value_t v;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	v.integer = integer;
311355b4669Sjacobs 	return (papiAttributeListAddValue(list, flags, name, PAPI_INTEGER, &v));
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListAddBoolean(papi_attribute_t *** list,int flags,char * name,char boolean)315355b4669Sjacobs papiAttributeListAddBoolean(papi_attribute_t ***list, int flags,
3163cf7d3e9SToomas Soome     char *name, char boolean)
3177c478bd9Sstevel@tonic-gate {
3187c478bd9Sstevel@tonic-gate 	papi_attribute_value_t v;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	v.boolean = boolean;
321355b4669Sjacobs 	return (papiAttributeListAddValue(list, flags, name, PAPI_BOOLEAN, &v));
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListAddRange(papi_attribute_t *** list,int flags,char * name,int lower,int upper)325355b4669Sjacobs papiAttributeListAddRange(papi_attribute_t ***list, int flags,
3263cf7d3e9SToomas Soome     char *name, int lower, int upper)
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate 	papi_attribute_value_t v;
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	v.range.lower = lower;
3317c478bd9Sstevel@tonic-gate 	v.range.upper = upper;
332355b4669Sjacobs 	return (papiAttributeListAddValue(list, flags, name, PAPI_RANGE, &v));
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListAddResolution(papi_attribute_t *** list,int flags,char * name,int xres,int yres,papi_resolution_unit_t units)336355b4669Sjacobs papiAttributeListAddResolution(papi_attribute_t ***list, int flags,
3373cf7d3e9SToomas Soome     char *name, int xres, int yres, papi_resolution_unit_t units)
3387c478bd9Sstevel@tonic-gate {
3397c478bd9Sstevel@tonic-gate 	papi_attribute_value_t v;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	v.resolution.xres = xres;
3427c478bd9Sstevel@tonic-gate 	v.resolution.yres = yres;
3437c478bd9Sstevel@tonic-gate 	v.resolution.units = units;
344355b4669Sjacobs 	return (papiAttributeListAddValue(list, flags, name,
3453cf7d3e9SToomas Soome 	    PAPI_RESOLUTION, &v));
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListAddDatetime(papi_attribute_t *** list,int flags,char * name,time_t datetime)349355b4669Sjacobs papiAttributeListAddDatetime(papi_attribute_t ***list, int flags,
3503cf7d3e9SToomas Soome     char *name, time_t datetime)
3517c478bd9Sstevel@tonic-gate {
3527c478bd9Sstevel@tonic-gate 	papi_attribute_value_t v;
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	v.datetime = datetime;
355355b4669Sjacobs 	return (papiAttributeListAddValue(list, flags, name,
3563cf7d3e9SToomas Soome 	    PAPI_DATETIME, &v));
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListAddCollection(papi_attribute_t *** list,int flags,char * name,papi_attribute_t ** collection)360355b4669Sjacobs papiAttributeListAddCollection(papi_attribute_t ***list, int flags,
3613cf7d3e9SToomas Soome     char *name, papi_attribute_t **collection)
3627c478bd9Sstevel@tonic-gate {
3637c478bd9Sstevel@tonic-gate 	papi_attribute_value_t v;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	v.collection = (papi_attribute_t **)collection;
366355b4669Sjacobs 	return (papiAttributeListAddValue(list, flags, name,
3673cf7d3e9SToomas Soome 	    PAPI_COLLECTION, &v));
368355b4669Sjacobs }
369355b4669Sjacobs 
370355b4669Sjacobs papi_status_t
papiAttributeListAddMetadata(papi_attribute_t *** list,int flags,char * name,papi_metadata_t metadata)371355b4669Sjacobs papiAttributeListAddMetadata(papi_attribute_t ***list, int flags,
3723cf7d3e9SToomas Soome     char *name, papi_metadata_t metadata)
373355b4669Sjacobs {
374355b4669Sjacobs 	papi_attribute_value_t v;
375355b4669Sjacobs 
376355b4669Sjacobs 	v.metadata = metadata;
377355b4669Sjacobs 	return (papiAttributeListAddValue(list, flags, name,
3783cf7d3e9SToomas Soome 	    PAPI_METADATA, &v));
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate papi_status_t
papiAttributeListDelete(papi_attribute_t *** list,char * name)382355b4669Sjacobs papiAttributeListDelete(papi_attribute_t ***list, char *name)
3837c478bd9Sstevel@tonic-gate {
3847c478bd9Sstevel@tonic-gate 	papi_attribute_t *attribute;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	if ((list == NULL) || (name == NULL))
3877c478bd9Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 	if ((attribute = papiAttributeListFind(*list, name)) == NULL)
3907c478bd9Sstevel@tonic-gate 		return (PAPI_NOT_FOUND);
3917c478bd9Sstevel@tonic-gate 
3920a44ef6dSjacobs 	list_remove(list, attribute);
3937c478bd9Sstevel@tonic-gate 	papiAttributeFree(attribute);
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	return (PAPI_OK);
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate papi_attribute_t *
papiAttributeListFind(papi_attribute_t ** list,char * name)399355b4669Sjacobs papiAttributeListFind(papi_attribute_t **list, char *name)
4007c478bd9Sstevel@tonic-gate {
401355b4669Sjacobs 	int i;
402355b4669Sjacobs 	if ((list == NULL) || (name == NULL))
403355b4669Sjacobs 		return (NULL);
4047c478bd9Sstevel@tonic-gate 
405355b4669Sjacobs 	for (i = 0; list[i] != NULL; i++)
406355b4669Sjacobs 		if (strcasecmp(list[i]->name, name) == 0)
407