Print this page
2837 - remove print/lp* from gate and use CUPS from userland


 186                         break;
 187                 case PAPI_DATETIME:
 188                         result->datetime = v->datetime;
 189                         break;
 190                 case PAPI_COLLECTION:
 191                         result->collection = collection_dup(v->collection);
 192                         break;
 193                 case PAPI_METADATA:
 194                         result->metadata = v->metadata;
 195                         break;
 196                 default:        /* unknown type, fail to duplicate */
 197                         free(result);
 198                         result = NULL;
 199                 }
 200         }
 201 
 202         return (result);
 203 }
 204 
 205 static papi_attribute_t *
 206 papiAttributeAlloc(char *name, papi_attribute_value_type_t type)
 207 {
 208         papi_attribute_t *result = NULL;
 209 
 210         if ((result = calloc(1, sizeof (*result))) != NULL) {
 211                 result->name = strdup(name);
 212                 result->type = type;
 213         }
 214 
 215         return (result);
 216 }
 217 
 218 static papi_status_t
 219 papiAttributeListAppendValue(papi_attribute_value_t ***values,
 220                 papi_attribute_value_type_t type,
 221                 papi_attribute_value_t *value)
 222 {
 223 
 224         if (values == NULL)
 225                 return (PAPI_BAD_ARGUMENT);
 226 
 227         if (value != NULL) {    /* this allows "empty" attributes */
 228                 papi_attribute_value_t *tmp = NULL;
 229 
 230                 if ((tmp = papiAttributeValueDup(type, value)) == NULL)
 231                         return (PAPI_TEMPORARY_ERROR);
 232 
 233                 list_append(values, tmp);
 234         }
 235 
 236         return (PAPI_OK);
 237 }
 238 
 239 papi_status_t
 240 papiAttributeListAddValue(papi_attribute_t ***list, int flgs,
 241                 char *name, papi_attribute_value_type_t type,
 242                 papi_attribute_value_t *value)
 243 {
 244         papi_status_t result;
 245         int flags = flgs;
 246         papi_attribute_t *attribute = NULL;
 247         papi_attribute_value_t **values = NULL;
 248 
 249         if ((list == NULL) || (name == NULL))
 250                 return (PAPI_BAD_ARGUMENT);
 251 
 252         if ((type == PAPI_RANGE) && (value != NULL) &&
 253             (value->range.lower > value->range.upper))
 254                 return (PAPI_BAD_ARGUMENT);     /* RANGE must have min <= max */
 255 
 256         if (flags == 0) /* if it wasn't set, set a default behaviour */
 257                 flags = PAPI_ATTR_APPEND;
 258 
 259         /* look for an existing one */
 260         attribute = papiAttributeListFind(*list, name);
 261 


 301                         char *name, char *string)
 302 {
 303         papi_attribute_value_t v;
 304 
 305         v.string = (char *)string;
 306         return (papiAttributeListAddValue(list, flags, name, PAPI_STRING, &v));
 307 }
 308 
 309 papi_status_t
 310 papiAttributeListAddInteger(papi_attribute_t ***list, int flags,
 311                         char *name, int integer)
 312 {
 313         papi_attribute_value_t v;
 314 
 315         v.integer = integer;
 316         return (papiAttributeListAddValue(list, flags, name, PAPI_INTEGER, &v));
 317 }
 318 
 319 papi_status_t
 320 papiAttributeListAddBoolean(papi_attribute_t ***list, int flags,
 321                         char *name, char boolean)
 322 {
 323         papi_attribute_value_t v;
 324 
 325         v.boolean = boolean;
 326         return (papiAttributeListAddValue(list, flags, name, PAPI_BOOLEAN, &v));
 327 }
 328 
 329 papi_status_t
 330 papiAttributeListAddRange(papi_attribute_t ***list, int flags,
 331                         char *name, int lower, int upper)
 332 {
 333         papi_attribute_value_t v;
 334 
 335         v.range.lower = lower;
 336         v.range.upper = upper;
 337         return (papiAttributeListAddValue(list, flags, name, PAPI_RANGE, &v));
 338 }
 339 
 340 papi_status_t
 341 papiAttributeListAddResolution(papi_attribute_t ***list, int flags,


 385 }
 386 
 387 papi_status_t
 388 papiAttributeListDelete(papi_attribute_t ***list, char *name)
 389 {
 390         papi_attribute_t *attribute;
 391 
 392         if ((list == NULL) || (name == NULL))
 393                 return (PAPI_BAD_ARGUMENT);
 394 
 395         if ((attribute = papiAttributeListFind(*list, name)) == NULL)
 396                 return (PAPI_NOT_FOUND);
 397 
 398         list_remove(list, attribute);
 399         papiAttributeFree(attribute);
 400 
 401         return (PAPI_OK);
 402 }
 403 
 404 papi_attribute_t *
 405 papiAttributeListFind(papi_attribute_t **list, char *name)
 406 {
 407         int i;
 408         if ((list == NULL) || (name == NULL))
 409                 return (NULL);
 410 
 411         for (i = 0; list[i] != NULL; i++)
 412                 if (strcasecmp(list[i]->name, name) == 0)
 413                         return ((papi_attribute_t *)list[i]);
 414 
 415         return (NULL);
 416 }
 417 
 418 papi_attribute_t *
 419 papiAttributeListGetNext(papi_attribute_t **list, void **iter)
 420 {
 421         papi_attribute_t **tmp, *result;
 422 
 423         if ((list == NULL) && (iter == NULL))
 424                 return (NULL);
 425 




 186                         break;
 187                 case PAPI_DATETIME:
 188                         result->datetime = v->datetime;
 189                         break;
 190                 case PAPI_COLLECTION:
 191                         result->collection = collection_dup(v->collection);
 192                         break;
 193                 case PAPI_METADATA:
 194                         result->metadata = v->metadata;
 195                         break;
 196                 default:        /* unknown type, fail to duplicate */
 197                         free(result);
 198                         result = NULL;
 199                 }
 200         }
 201 
 202         return (result);
 203 }
 204 
 205 static papi_attribute_t *
 206 papiAttributeAlloc(const char *name, papi_attribute_value_type_t type)
 207 {
 208         papi_attribute_t *result = NULL;
 209 
 210         if ((result = calloc(1, sizeof (*result))) != NULL) {
 211                 result->name = strdup(name);
 212                 result->type = type;
 213         }
 214 
 215         return (result);
 216 }
 217 
 218 static papi_status_t
 219 papiAttributeListAppendValue(papi_attribute_value_t ***values,
 220                 papi_attribute_value_type_t type,
 221                 papi_attribute_value_t *value)
 222 {
 223 
 224         if (values == NULL)
 225                 return (PAPI_BAD_ARGUMENT);
 226 
 227         if (value != NULL) {    /* this allows "empty" attributes */
 228                 papi_attribute_value_t *tmp = NULL;
 229 
 230                 if ((tmp = papiAttributeValueDup(type, value)) == NULL)
 231                         return (PAPI_TEMPORARY_ERROR);
 232 
 233                 list_append(values, tmp);
 234         }
 235 
 236         return (PAPI_OK);
 237 }
 238 
 239 papi_status_t
 240 papiAttributeListAddValue(papi_attribute_t ***list, int flgs,
 241                 const char *name, papi_attribute_value_type_t type,
 242                 papi_attribute_value_t *value)
 243 {
 244         papi_status_t result;
 245         int flags = flgs;
 246         papi_attribute_t *attribute = NULL;
 247         papi_attribute_value_t **values = NULL;
 248 
 249         if ((list == NULL) || (name == NULL))
 250                 return (PAPI_BAD_ARGUMENT);
 251 
 252         if ((type == PAPI_RANGE) && (value != NULL) &&
 253             (value->range.lower > value->range.upper))
 254                 return (PAPI_BAD_ARGUMENT);     /* RANGE must have min <= max */
 255 
 256         if (flags == 0) /* if it wasn't set, set a default behaviour */
 257                 flags = PAPI_ATTR_APPEND;
 258 
 259         /* look for an existing one */
 260         attribute = papiAttributeListFind(*list, name);
 261 


 301                         char *name, char *string)
 302 {
 303         papi_attribute_value_t v;
 304 
 305         v.string = (char *)string;
 306         return (papiAttributeListAddValue(list, flags, name, PAPI_STRING, &v));
 307 }
 308 
 309 papi_status_t
 310 papiAttributeListAddInteger(papi_attribute_t ***list, int flags,
 311                         char *name, int integer)
 312 {
 313         papi_attribute_value_t v;
 314 
 315         v.integer = integer;
 316         return (papiAttributeListAddValue(list, flags, name, PAPI_INTEGER, &v));
 317 }
 318 
 319 papi_status_t
 320 papiAttributeListAddBoolean(papi_attribute_t ***list, int flags,
 321                         const char *name, char boolean)
 322 {
 323         papi_attribute_value_t v;
 324 
 325         v.boolean = boolean;
 326         return (papiAttributeListAddValue(list, flags, name, PAPI_BOOLEAN, &v));
 327 }
 328 
 329 papi_status_t
 330 papiAttributeListAddRange(papi_attribute_t ***list, int flags,
 331                         char *name, int lower, int upper)
 332 {
 333         papi_attribute_value_t v;
 334 
 335         v.range.lower = lower;
 336         v.range.upper = upper;
 337         return (papiAttributeListAddValue(list, flags, name, PAPI_RANGE, &v));
 338 }
 339 
 340 papi_status_t
 341 papiAttributeListAddResolution(papi_attribute_t ***list, int flags,


 385 }
 386 
 387 papi_status_t
 388 papiAttributeListDelete(papi_attribute_t ***list, char *name)
 389 {
 390         papi_attribute_t *attribute;
 391 
 392         if ((list == NULL) || (name == NULL))
 393                 return (PAPI_BAD_ARGUMENT);
 394 
 395         if ((attribute = papiAttributeListFind(*list, name)) == NULL)
 396                 return (PAPI_NOT_FOUND);
 397 
 398         list_remove(list, attribute);
 399         papiAttributeFree(attribute);
 400 
 401         return (PAPI_OK);
 402 }
 403 
 404 papi_attribute_t *
 405 papiAttributeListFind(papi_attribute_t **list, const char *name)
 406 {
 407         int i;
 408         if ((list == NULL) || (name == NULL))
 409                 return (NULL);
 410 
 411         for (i = 0; list[i] != NULL; i++)
 412                 if (strcasecmp(list[i]->name, name) == 0)
 413                         return ((papi_attribute_t *)list[i]);
 414 
 415         return (NULL);
 416 }
 417 
 418 papi_attribute_t *
 419 papiAttributeListGetNext(papi_attribute_t **list, void **iter)
 420 {
 421         papi_attribute_t **tmp, *result;
 422 
 423         if ((list == NULL) && (iter == NULL))
 424                 return (NULL);
 425