5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * tput - print terminal attribute
32 *
33 * return-codes - command line arguments:
34 * 0: ok if boolean capname -> TRUE
35 * 1: for boolean capname -> FALSE
36 *
37 * return-codes - standard input arguments:
38 * 0: ok; tput for all lines was successful
39 *
40 * return-codes - both cases:
41 * 2 usage error
42 * 3 bad terminal type given or no terminfo database
43 * 4 unknown capname
44 * -1 capname is a numeric variable that is not specified in the
157 cap = argv[optind++];
158
159 if (strcmp(cap, "init") == 0)
160 initterm();
161 else if (strcmp(cap, "reset") == 0)
162 reset_term();
163 else if (strcmp(cap, "longname") == 0)
164 (void) printf("%s\n", longname());
165 else
166 exit(outputcap(cap, argc, argv));
167 return (0);
168 } else { /* standard input argumets */
169 char buff[128];
170 char **v;
171
172 /* allocate storage for the 'faked' argv[] array */
173 v = (char **)malloc(10 * sizeof (char *));
174 for (i = 0; i < 10; i++)
175 v[i] = (char *)malloc(32 * sizeof (char));
176
177 while (gets(buff) != NULL) {
178 /* read standard input line; skip over empty lines */
179 if ((std_argc =
180 sscanf(buff, "%s %s %s %s %s %s %s %s %s %s",
181 v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7],
182 v[8], v[9])) < 1) {
183 continue;
184 }
185
186 cap = v[0];
187 optind = 1;
188
189 if (strcmp(cap, "init") == 0) {
190 initterm();
191 } else if (strcmp(cap, "reset") == 0) {
192 reset_term();
193 } else if (strcmp(cap, "longname") == 0) {
194 (void) printf("%s\n", longname());
195 } else {
196 (void) outputcap(cap, std_argc, v);
197 }
198 (void) fflush(stdout);
199 }
200
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright (c) 2012 Gary Mills
26 */
27
28 /* Copyright (c) 1988 AT&T */
29 /* All Rights Reserved */
30
31 /*
32 * tput - print terminal attribute
33 *
34 * return-codes - command line arguments:
35 * 0: ok if boolean capname -> TRUE
36 * 1: for boolean capname -> FALSE
37 *
38 * return-codes - standard input arguments:
39 * 0: ok; tput for all lines was successful
40 *
41 * return-codes - both cases:
42 * 2 usage error
43 * 3 bad terminal type given or no terminfo database
44 * 4 unknown capname
45 * -1 capname is a numeric variable that is not specified in the
158 cap = argv[optind++];
159
160 if (strcmp(cap, "init") == 0)
161 initterm();
162 else if (strcmp(cap, "reset") == 0)
163 reset_term();
164 else if (strcmp(cap, "longname") == 0)
165 (void) printf("%s\n", longname());
166 else
167 exit(outputcap(cap, argc, argv));
168 return (0);
169 } else { /* standard input argumets */
170 char buff[128];
171 char **v;
172
173 /* allocate storage for the 'faked' argv[] array */
174 v = (char **)malloc(10 * sizeof (char *));
175 for (i = 0; i < 10; i++)
176 v[i] = (char *)malloc(32 * sizeof (char));
177
178 while (fgets(buff, sizeof (buff), stdin) != NULL) {
179 /* read standard input line; skip over empty lines */
180 if ((std_argc =
181 sscanf(buff,
182 "%31s %31s %31s %31s %31s %31s %31s %31s "
183 "%31s %31s",
184 v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7],
185 v[8], v[9])) < 1) {
186 continue;
187 }
188
189 cap = v[0];
190 optind = 1;
191
192 if (strcmp(cap, "init") == 0) {
193 initterm();
194 } else if (strcmp(cap, "reset") == 0) {
195 reset_term();
196 } else if (strcmp(cap, "longname") == 0) {
197 (void) printf("%s\n", longname());
198 } else {
199 (void) outputcap(cap, std_argc, v);
200 }
201 (void) fflush(stdout);
202 }
203
|