8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / lp / lib / papi / lpsched-misc.c
blobce45d1aa5c2738c42e46c16048d44dba5786b637
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 /*LINTLIBRARY*/
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
34 #include <papi_impl.h>
37 papi_status_t
38 papiAttributeListAddLPString(papi_attribute_t ***list, int flags, char *name,
39 char *value)
41 papi_status_t result = PAPI_BAD_ARGUMENT;
43 if ((list != NULL) && (name != NULL) && (value != NULL) &&
44 (value[0] != NULL))
45 result = papiAttributeListAddString(list, flags, name, value);
46 return (result);
49 papi_status_t
50 papiAttributeListAddLPStrings(papi_attribute_t ***list, int flags, char *name,
51 char **values)
53 papi_status_t result = PAPI_OK;
54 int i, flgs = flags;
56 if ((list == NULL) || (name == NULL) || (values == NULL))
57 result = PAPI_BAD_ARGUMENT;
59 for (i = 0; ((result == PAPI_OK) && (values[i] != NULL));
60 i++, flgs = PAPI_ATTR_APPEND)
61 result = papiAttributeListAddString(list, flgs, name,
62 values[i]);
64 return (result);
67 void
68 papiAttributeListGetLPString(papi_attribute_t **attributes, char *key,
69 char **string)
71 char *value = NULL;
73 papiAttributeListGetString(attributes, NULL, key, &value);
74 if (value != NULL) {
75 if (*string != NULL)
76 free(*string);
77 *string = strdup(value);
81 void
82 papiAttributeListGetLPStrings(papi_attribute_t **attributes, char *key,
83 char ***strings)
85 papi_status_t status;
86 char **values = NULL;
87 char *value = NULL;
88 void *iter = NULL;
90 for (status = papiAttributeListGetString(attributes, &iter,
91 key, &value);
92 status == PAPI_OK;
93 status = papiAttributeListGetString(attributes, &iter,
94 NULL, &value))
95 addlist(&values, value);
97 if (values != NULL) {
98 if (*strings != NULL)
99 freelist(*strings);
100 *strings = values;
104 char *
105 printer_name_from_uri_id(char *uri, int32_t id)
107 REQUEST *request = NULL;
108 char *result = "";
110 if (uri != NULL) {
111 if ((result = strrchr(uri, '/')) != NULL) {
112 result += 1;
113 } else
114 result = (char *)uri;
116 if ((strcmp(result, "jobs") == 0) ||
117 (strcmp(result, "any") == 0) ||
118 (strcmp(result, "all") == 0))
119 result = "";
122 if ((result[0] == NULL) && (id != -1)) {
123 char path[32];
125 snprintf(path, sizeof (path), "%d-0", id);
126 if ((request = getrequest(path)) != NULL)
127 result = request->destination;
130 result = strdup(result);
132 if (request != NULL)
133 freerequest(request);
135 return (result);
139 * LP content type <-> MIME type conversion table. (order dependent)
141 static struct {
142 char *mime_type;
143 char *lp_type;
144 } type_map[] = {
145 { "text/plain", "simple" },
146 { "application/octet-stream", "raw" },
147 { "application/octet-stream", "any" },
148 { "application/postscript", "postscript" },
149 { "application/postscript", "ps" },
150 { "application/x-cif", "cif" },
151 { "application/x-dvi", "dvi" },
152 { "application/x-plot", "plot" },
153 { "application/x-ditroff", "troff" },
154 { "application/x-troff", "otroff" },
155 { "application/x-pr", "pr" },
156 { "application/x-fortran", "fortran" },
157 { "application/x-raster", "raster" },
158 { NULL, NULL}
161 char *
162 mime_type_to_lp_type(char *mime_type)
164 int i;
166 if (mime_type == NULL)
167 return ("simple");
169 for (i = 0; type_map[i].mime_type != NULL; i++)
170 if (strcasecmp(type_map[i].mime_type, mime_type) == 0)
171 return (type_map[i].lp_type);
173 return (mime_type);
176 char *
177 lp_type_to_mime_type(char *lp_type)
179 int i;
181 if (lp_type == NULL)
182 return ("text/plain");
184 for (i = 0; type_map[i].lp_type != NULL; i++)
185 if (strcasecmp(type_map[i].lp_type, lp_type) == 0)
186 return (type_map[i].mime_type);
188 return (lp_type);