Print this page
10080 smatch Makefile changes for usr/src/cmd
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/print/printer-info/printer-info.c
+++ new/usr/src/cmd/print/printer-info/printer-info.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
27 +/*
28 + * Copyright (c) 2018, Joyent, Inc.
29 + */
28 30
29 31 #include <stdio.h>
32 +#include <stdlib.h>
30 33 #include <unistd.h>
31 34 #include <string.h>
32 35 #include <sys/ioctl.h>
33 36 #include <sys/prnio.h>
34 37 #include <fcntl.h>
35 38
36 39 #define COMMAND_SET_MAX 16 /* more than 16 command sets is not likely */
37 40 #define NP(x) (x ? x : "")
38 41
39 42 typedef struct {
40 43 char *manufacturer;
41 44 char *model;
42 45 char *description;
43 46 char *class;
44 47 char *command_set[COMMAND_SET_MAX];
45 48 } printer_description_t;
46 49
47 50 int
48 51 get_printer_description(char *path, printer_description_t *info)
49 52 {
50 53 int fd, rc;
51 54 struct prn_1284_device_id id;
52 55 char buf[BUFSIZ];
53 56 char *s, *iter = NULL;
54 57
55 58 /* open the device */
56 59 if ((fd = open(path, O_RDWR)) < 0)
57 60 return (fd);
58 61
59 62 /* get the 1284 device id */
60 63 memset(&id, 0, sizeof (id));
61 64 memset(&buf, 0, sizeof (buf));
62 65 id.id_len = sizeof (buf);
63 66 id.id_data = buf;
64 67
65 68 rc = ioctl(fd, PRNIOC_GET_1284_DEVID, &id);
66 69 /* close(fd); */
67 70 if (rc < 0)
68 71 return (rc);
69 72
70 73 memset(info, 0, sizeof (*info));
71 74
72 75 /* parse the 1284 device id string */
73 76 for (s = (char *)strtok_r(buf, ";\n", &iter); s != NULL;
74 77 s = (char *)strtok_r(NULL, ";\n", &iter)) {
75 78 char *t, *u, *iter2 = NULL;
76 79
77 80 if ((t = (char *)strtok_r(s, ":\n", &iter2)) == NULL)
78 81 continue;
79 82
80 83 if ((u = (char *)strtok_r(NULL, ":\n", &iter2)) == NULL)
81 84 continue;
82 85
83 86 if ((strcasecmp(t, "MFG") == 0) ||
84 87 (strcasecmp(t, "MANUFACTURER") == 0))
85 88 info->manufacturer = strdup(u);
86 89 else if ((strcasecmp(t, "MDL") == 0) ||
87 90 (strcasecmp(t, "MODEL") == 0))
88 91 info->model = strdup(u);
89 92 else if ((strcasecmp(t, "DES") == 0) ||
90 93 (strcasecmp(t, "DESCRIPTION") == 0))
91 94 info->description = strdup(u);
92 95 else if ((strcasecmp(t, "CLS") == 0) ||
93 96 (strcasecmp(t, "CLASS") == 0))
94 97 info->class = strdup(u);
95 98 else if ((strcasecmp(t, "CMD") == 0) ||
96 99 (strcasecmp(t, "COMMAND SET") == 0)) {
97 100 /* this should be more dynamic, I got lazy */
98 101 char *v, *iter3 = NULL;
99 102 int i = 0;
100 103
101 104 for (v = (char *)strtok_r(u, ",\n", &iter3);
102 105 ((v != NULL) && (i < COMMAND_SET_MAX));
103 106 v = (char *)strtok_r(NULL, ",\n", &iter3))
104 107 info->command_set[i++] = strdup(v);
105 108 }
106 109 }
107 110
108 111 return (0);
109 112 }
110 113
111 114 static void
112 115 usage(char *name)
113 116 {
114 117 char *program;
115 118
116 119 if ((program = strrchr(name, '/')) == NULL)
117 120 program = name;
118 121 else
119 122 program++;
120 123
121 124 printf("Usage: %s [-aMmdCc] (path) ...\n", program);
122 125 }
123 126
124 127 int
125 128 main(int ac, char *av[])
126 129 {
127 130 int rc;
128 131 int manufacturer = 0, model = 0, description = 0, command_set = 0,
129 132 class = 0;
130 133
131 134 while ((rc = getopt(ac, av, "aMmdCc")) != EOF)
132 135 switch (rc) {
133 136 case 'a':
134 137 manufacturer++;
135 138 model++;
136 139 description++;
137 140 command_set++;
138 141 class++;
139 142 break;
140 143 case 'M':
141 144 manufacturer++;
142 145 break;
143 146 case 'm':
144 147 model++;
145 148 break;
146 149 case 'd':
147 150 description++;
148 151 break;
149 152 case 'C':
150 153 command_set++;
151 154 break;
152 155 case 'c':
153 156 class++;
154 157 break;
155 158 default:
156 159 usage(av[0]);
157 160 exit(1);
158 161 }
159 162
160 163 if (optind >= ac) {
161 164 usage(av[0]);
162 165 exit(1);
163 166 }
164 167
165 168 while (optind < ac) {
166 169 char *path = av[optind++];
167 170 printer_description_t info;
168 171
169 172 rc = get_printer_description(path, &info);
170 173 if (rc == 0) {
171 174 printf("%s:\n", path);
172 175 if (manufacturer != 0)
173 176 printf("\tManufacturer: %s\n",
174 177 NP(info.manufacturer));
175 178 if (model != 0)
176 179 printf("\tModel: %s\n",
177 180 NP(info.model));
178 181 if (description != 0)
179 182 printf("\tDescription: %s\n",
180 183 NP(info.description));
181 184 if (class != 0)
182 185 printf("\tClass: %s\n",
183 186 NP(info.class));
184 187 if (command_set != 0) {
185 188 int i;
186 189
187 190 printf("\tCommand set:\n");
188 191 for (i = 0; info.command_set[i] != NULL; i++)
189 192 printf("\t\tcmd[%d]: %s\n", i,
190 193 info.command_set[i]);
191 194 }
192 195 } else
193 196 perror(path);
194 197 }
195 198 return (rc);
196 199 }
↓ open down ↓ |
157 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX