1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /*LINTLIBRARY*/ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #include <stdio.h> 32*0Sstevel@tonic-gate #include <string.h> 33*0Sstevel@tonic-gate #include <stdlib.h> 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate #include <papi_impl.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate papi_status_t 39*0Sstevel@tonic-gate addLPString(papi_attribute_t ***list, int flags, char *name, char *value) 40*0Sstevel@tonic-gate { 41*0Sstevel@tonic-gate papi_status_t result = PAPI_BAD_ARGUMENT; 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate if ((list != NULL) && (name != NULL) && (value != NULL) && 44*0Sstevel@tonic-gate (value[0] != NULL)) 45*0Sstevel@tonic-gate result = papiAttributeListAddString(list, flags, name, value); 46*0Sstevel@tonic-gate return (result); 47*0Sstevel@tonic-gate } 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate papi_status_t 50*0Sstevel@tonic-gate addLPStrings(papi_attribute_t ***list, int flags, char *name, 51*0Sstevel@tonic-gate char **values) 52*0Sstevel@tonic-gate { 53*0Sstevel@tonic-gate papi_status_t result = PAPI_OK; 54*0Sstevel@tonic-gate int i, flgs = flags; 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate if ((list == NULL) || (name == NULL) || (values == NULL)) 57*0Sstevel@tonic-gate result = PAPI_BAD_ARGUMENT; 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate for (i = 0; ((result == PAPI_OK) && (values[i] != NULL)); 60*0Sstevel@tonic-gate i++, flgs = PAPI_ATTR_APPEND) 61*0Sstevel@tonic-gate result = papiAttributeListAddString(list, flgs, name, 62*0Sstevel@tonic-gate values[i]); 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate return (result); 65*0Sstevel@tonic-gate } 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate char * 68*0Sstevel@tonic-gate printer_name_from_uri_id(const char *uri, int32_t id) 69*0Sstevel@tonic-gate { 70*0Sstevel@tonic-gate REQUEST *request = NULL; 71*0Sstevel@tonic-gate char *result = ""; 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate if (uri != NULL) { 74*0Sstevel@tonic-gate if ((result = strrchr(uri, '/')) != NULL) { 75*0Sstevel@tonic-gate result += 1; 76*0Sstevel@tonic-gate } else 77*0Sstevel@tonic-gate result = (char *)uri; 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate if ((strcmp(result, "jobs") == 0) || 80*0Sstevel@tonic-gate (strcmp(result, "any") == 0) || 81*0Sstevel@tonic-gate (strcmp(result, "all") == 0)) 82*0Sstevel@tonic-gate result = ""; 83*0Sstevel@tonic-gate } 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate if ((result[0] == NULL) && (id != -1)) { 86*0Sstevel@tonic-gate char path[32]; 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate snprintf(path, sizeof (path), "%d-0", id); 89*0Sstevel@tonic-gate if ((request = getrequest(path)) != NULL) 90*0Sstevel@tonic-gate result = request->destination; 91*0Sstevel@tonic-gate } 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate result = strdup(result); 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate if (request != NULL) 96*0Sstevel@tonic-gate freerequest(request); 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate return (result); 99*0Sstevel@tonic-gate } 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate /* 102*0Sstevel@tonic-gate * LP content type <-> MIME type conversion table. (order dependent) 103*0Sstevel@tonic-gate */ 104*0Sstevel@tonic-gate static struct { 105*0Sstevel@tonic-gate char *mime_type; 106*0Sstevel@tonic-gate char *lp_type; 107*0Sstevel@tonic-gate } type_map[] = { 108*0Sstevel@tonic-gate { "plain/text", "simple" }, 109*0Sstevel@tonic-gate { "application/octet-stream", "raw" }, 110*0Sstevel@tonic-gate { "application/octet-stream", "any" }, 111*0Sstevel@tonic-gate { "application/postscript", "postscript" }, 112*0Sstevel@tonic-gate { "application/postscript", "ps" }, 113*0Sstevel@tonic-gate { "application/x-cif", "cif" }, 114*0Sstevel@tonic-gate { "application/x-dvi", "dvi" }, 115*0Sstevel@tonic-gate { "application/x-plot", "plot" }, 116*0Sstevel@tonic-gate { "application/x-ditroff", "troff" }, 117*0Sstevel@tonic-gate { "application/x-troff", "otroff" }, 118*0Sstevel@tonic-gate { "application/x-pr", "pr" }, 119*0Sstevel@tonic-gate { "application/x-fortran", "fortran" }, 120*0Sstevel@tonic-gate { "application/x-raster", "raster" }, 121*0Sstevel@tonic-gate { NULL, NULL} 122*0Sstevel@tonic-gate }; 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate char * 125*0Sstevel@tonic-gate mime_type_to_lp_type(char *mime_type) 126*0Sstevel@tonic-gate { 127*0Sstevel@tonic-gate int i; 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate if (mime_type == NULL) 130*0Sstevel@tonic-gate return ("simple"); 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate for (i = 0; type_map[i].mime_type != NULL; i++) 133*0Sstevel@tonic-gate if (strcasecmp(type_map[i].mime_type, mime_type) == 0) 134*0Sstevel@tonic-gate return (type_map[i].lp_type); 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate return (mime_type); 137*0Sstevel@tonic-gate } 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate char * 140*0Sstevel@tonic-gate lp_type_to_mime_type(char *lp_type) 141*0Sstevel@tonic-gate { 142*0Sstevel@tonic-gate int i; 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate if (lp_type == NULL) 145*0Sstevel@tonic-gate return ("plain/text"); 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate for (i = 0; type_map[i].lp_type != NULL; i++) 148*0Sstevel@tonic-gate if (strcasecmp(type_map[i].lp_type, lp_type) == 0) 149*0Sstevel@tonic-gate return (type_map[i].mime_type); 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate return (lp_type); 152*0Sstevel@tonic-gate } 153