Mercurial > illumos > onarm
comparison usr/src/cmd/banner/banner.c @ 0:c9caec207d52 b86
Initial porting based on b86
author | Koji Uno <koji.uno@sun.com> |
---|---|
date | Tue, 02 Jun 2009 18:56:50 +0900 |
parents | |
children | 1a15d5aaf794 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c9caec207d52 |
---|---|
1 /* | |
2 * CDDL HEADER START | |
3 * | |
4 * The contents of this file are subject to the terms of the | |
5 * Common Development and Distribution License, Version 1.0 only | |
6 * (the "License"). You may not use this file except in compliance | |
7 * with the License. | |
8 * | |
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
10 * or http://www.opensolaris.org/os/licensing. | |
11 * See the License for the specific language governing permissions | |
12 * and limitations under the License. | |
13 * | |
14 * When distributing Covered Code, include this CDDL HEADER in each | |
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
16 * If applicable, add the following below this CDDL HEADER, with the | |
17 * fields enclosed by brackets "[]" replaced with your own identifying | |
18 * information: Portions Copyright [yyyy] [name of copyright owner] | |
19 * | |
20 * CDDL HEADER END | |
21 */ | |
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ | |
23 /* All Rights Reserved */ | |
24 | |
25 | |
26 /* | |
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. | |
28 * Use is subject to license terms. | |
29 */ | |
30 | |
31 #pragma ident "@(#)banner.c 1.11 05/06/08 SMI" | |
32 | |
33 #include <locale.h> | |
34 #include <stdio.h> | |
35 #include <stdlib.h> | |
36 #include <sys/types.h> | |
37 | |
38 #define nchars 128 /* number of chars in char set */ | |
39 #define nlines 7 /* number of lines in a banner character */ | |
40 #define pposs 85 /* number of print positions */ | |
41 /* on a line (must be multiple of 4) */ | |
42 /* followed by end of string character */ | |
43 #define pospch 8 /* number of char positions per banner char */ | |
44 #define chpln 10 /* number of banner characters per line */ | |
45 | |
46 struct bann { | |
47 char alpha[nlines][pposs]; | |
48 }; | |
49 static struct bann buffer, *bp = &buffer; | |
50 static char ctbl[nchars][nlines] = { | |
51 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
52 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
53 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
54 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
55 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
56 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
57 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
58 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
59 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
60 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
61 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
62 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
63 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
64 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
65 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
66 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
67 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
68 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
69 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
70 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
71 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
72 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
73 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
74 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
75 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
76 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
77 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
78 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
79 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
80 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
81 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
82 0, 000, 000, 000, 000, 000, 000, /* below 040 */ | |
83 0, 000, 000, 000, 000, 000, 000, /* */ | |
84 034, 034, 034, 010, 0, 034, 034, /* ! */ | |
85 0167, 0167, 042, 0, 0, 0, 0, /* " */ | |
86 024, 024, 0177, 024, 0177, 024, 024, /* # */ | |
87 076, 0111, 0110, 076, 011, 0111, 076, /* $ */ | |
88 0161, 0122, 0164, 010, 027, 045, 0107, /* % */ | |
89 030, 044, 030, 070, 0105, 0102, 071, /* & */ | |
90 034, 034, 010, 020, 0, 0, 0, /* ' */ | |
91 014, 020, 040, 040, 040, 020, 014, /* ( */ | |
92 030, 4, 2, 2, 2, 4, 030, /* ) */ | |
93 0, 042, 024, 0177, 024, 042, 0, /* * */ | |
94 0, 010, 010, 076, 010, 010, 0, /* + */ | |
95 0, 0, 0, 034, 034, 010, 020, /* , */ | |
96 0, 0, 0, 076, 0, 0, 0, /* - */ | |
97 0, 0, 0, 0, 034, 034, 034, /* . */ | |
98 1, 2, 4, 010, 020, 040, 0100, /* / */ | |
99 034, 042, 0101, 0101, 0101, 042, 034, /* 0 */ | |
100 010, 030, 050, 010, 010, 010, 076, /* 1 */ | |
101 076, 0101, 1, 076, 0100, 0100, 0177, /* 2 */ | |
102 076, 0101, 1, 076, 1, 0101, 076, /* 3 */ | |
103 0100, 0102, 0102, 0102, 0177, 2, 2, /* 4 */ | |
104 0177, 0100, 0100, 0176, 1, 0101, 076, /* 5 */ | |
105 076, 0101, 0100, 0176, 0101, 0101, 076, /* 6 */ | |
106 0177, 0102, 04, 010, 020, 020, 020, /* 7 */ | |
107 076, 0101, 0101, 076, 0101, 0101, 076, /* 8 */ | |
108 076, 0101, 0101, 077, 1, 0101, 076, /* 9 */ | |
109 010, 034, 010, 0, 010, 034, 010, /* : */ | |
110 034, 034, 0, 034, 034, 010, 020, /* ; */ | |
111 4, 010, 020, 040, 020, 010, 4, /* < */ | |
112 0, 0, 076, 0, 076, 0, 0, /* = */ | |
113 020, 010, 4, 2, 4, 010, 020, /* > */ | |
114 076, 0101, 1, 016, 010, 0, 010, /* ? */ | |
115 076, 0101, 0135, 0135, 0136, 0100, 076, /* @ */ | |
116 010, 024, 042, 0101, 0177, 0101, 0101, /* A */ | |
117 0176, 0101, 0101, 0176, 0101, 0101, 0176, /* B */ | |
118 076, 0101, 0100, 0100, 0100, 0101, 076, /* C */ | |
119 0176, 0101, 0101, 0101, 0101, 0101, 0176, /* D */ | |
120 0177, 0100, 0100, 0174, 0100, 0100, 0177, /* E */ | |
121 0177, 0100, 0100, 0174, 0100, 0100, 0100, /* F */ | |
122 076, 0101, 0100, 0117, 0101, 0101, 076, /* G */ | |
123 0101, 0101, 0101, 0177, 0101, 0101, 0101, /* H */ | |
124 034, 010, 010, 010, 010, 010, 034, /* I */ | |
125 1, 1, 1, 1, 0101, 0101, 076, /* J */ | |
126 0102, 0104, 0110, 0160, 0110, 0104, 0102, /* K */ | |
127 0100, 0100, 0100, 0100, 0100, 0100, 0177, /* L */ | |
128 0101, 0143, 0125, 0111, 0101, 0101, 0101, /* M */ | |
129 0101, 0141, 0121, 0111, 0105, 0103, 0101, /* N */ | |
130 0177, 0101, 0101, 0101, 0101, 0101, 0177, /* O */ | |
131 0176, 0101, 0101, 0176, 0100, 0100, 0100, /* P */ | |
132 076, 0101, 0101, 0101, 0105, 0102, 075, /* Q */ | |
133 0176, 0101, 0101, 0176, 0104, 0102, 0101, /* R */ | |
134 076, 0101, 0100, 076, 1, 0101, 076, /* S */ | |
135 0177, 010, 010, 010, 010, 010, 010, /* T */ | |
136 0101, 0101, 0101, 0101, 0101, 0101, 076, /* U */ | |
137 0101, 0101, 0101, 0101, 042, 024, 010, /* V */ | |
138 0101, 0111, 0111, 0111, 0111, 0111, 066, /* W */ | |
139 0101, 042, 024, 010, 024, 042, 0101, /* X */ | |
140 0101, 042, 024, 010, 010, 010, 010, /* Y */ | |
141 0177, 2, 4, 010, 020, 040, 0177, /* Z */ | |
142 076, 040, 040, 040, 040, 040, 076, /* [ */ | |
143 0100, 040, 020, 010, 004, 002, 001, /* \ */ | |
144 076, 2, 2, 2, 2, 2, 076, /* ] */ | |
145 010, 024, 042, 0, 0, 0, 0, /* ^ */ | |
146 0, 000, 000, 000, 000, 000, 0177, /* _ */ | |
147 034, 034, 010, 04, 0, 0, 0, /* ` */ | |
148 0, 014, 022, 041, 077, 041, 041, /* A */ | |
149 0, 076, 041, 076, 041, 041, 076, /* B */ | |
150 0, 036, 041, 040, 040, 041, 036, /* C */ | |
151 0, 076, 041, 041, 041, 041, 076, /* D */ | |
152 0, 077, 040, 076, 040, 040, 077, /* E */ | |
153 0, 077, 040, 076, 040, 040, 040, /* F */ | |
154 0, 036, 041, 040, 047, 041, 036, /* G */ | |
155 0, 041, 041, 077, 041, 041, 041, /* H */ | |
156 0, 004, 004, 004, 004, 004, 004, /* I */ | |
157 0, 001, 001, 001, 001, 041, 036, /* J */ | |
158 0, 041, 042, 074, 044, 042, 041, /* K */ | |
159 0, 040, 040, 040, 040, 040, 077, /* L */ | |
160 0, 041, 063, 055, 041, 041, 041, /* M */ | |
161 0, 041, 061, 051, 045, 043, 041, /* N */ | |
162 0, 036, 041, 041, 041, 041, 036, /* O */ | |
163 0, 076, 041, 041, 076, 040, 040, /* P */ | |
164 0, 036, 041, 041, 045, 042, 035, /* Q */ | |
165 0, 076, 041, 041, 076, 042, 041, /* R */ | |
166 0, 036, 040, 036, 001, 041, 036, /* S */ | |
167 0, 037, 004, 004, 004, 004, 004, /* T */ | |
168 0, 041, 041, 041, 041, 041, 036, /* U */ | |
169 0, 041, 041, 041, 041, 022, 014, /* V */ | |
170 0, 041, 041, 041, 055, 063, 041, /* W */ | |
171 0, 041, 022, 014, 014, 022, 041, /* X */ | |
172 0, 021, 012, 004, 004, 004, 004, /* Y */ | |
173 0, 077, 002, 004, 010, 020, 077, /* Z */ | |
174 034, 040, 040, 0140, 040, 040, 034, /* { */ | |
175 010, 010, 010, 0, 010, 010, 010, /* | */ | |
176 034, 2, 2, 3, 2, 2, 034, /* } */ | |
177 060, 0111, 06, 0, 0, 0, 0, /* ~ */ | |
178 0, 000, 000, 000, 000, 000, 000 /* DEL */ | |
179 }; | |
180 static char blank = ' '; | |
181 static char plot = '#'; | |
182 static int msk = 0100; /* ? */ | |
183 | |
184 static void banner(char *s, struct bann *bufp); | |
185 static void banfil(char *c, struct bann *p); | |
186 static void banset(char c, struct bann *p); | |
187 static void banprt(struct bann *ptr); | |
188 static char convert(unsigned char c); | |
189 | |
190 int | |
191 main(int argc, char **argv) | |
192 { | |
193 int i; | |
194 /* | |
195 * if invoked with no arguments, prints error comment | |
196 * if invoked with an argument, prints it in banner form. | |
197 */ | |
198 (void) setlocale(LC_ALL, ""); | |
199 #if !defined(TEXT_DOMAIN) | |
200 #define TEXT_DOMAIN "SYS_TEST" | |
201 #endif | |
202 (void) textdomain(TEXT_DOMAIN); | |
203 if (argc < 2) { | |
204 (void) printf(gettext | |
205 ("Usage: banner \"up to 10 char arg string\" . . .\n")); | |
206 exit(1); | |
207 } | |
208 for (i = 1; i < argc; ++i) { | |
209 banner(argv[i], bp); | |
210 banprt(bp); | |
211 (void) printf("\n"); | |
212 } | |
213 return (0); | |
214 } | |
215 | |
216 static void | |
217 banner(char *s, struct bann *bufp) | |
218 { | |
219 char *p, *q; | |
220 unsigned char c; | |
221 struct bann *r; | |
222 p = s; | |
223 r = bufp; | |
224 banset(blank, bufp); | |
225 while ((c = *s++) != 0 && ((ptrdiff_t)s-(ptrdiff_t)p) <= chpln) { | |
226 if ((c & 0300)) { /* 8th bit is on */ | |
227 c = convert(c); | |
228 } | |
229 q = ctbl[c]; | |
230 banfil(q, r); | |
231 r = (struct bann *)((char *)r + pospch); | |
232 } | |
233 } | |
234 | |
235 static void | |
236 banfil(char *c, struct bann *p) | |
237 { | |
238 int i, j; | |
239 for (i = 0; i < nlines; i++) { | |
240 for (j = 0; j < pospch; j++) { | |
241 if (((c[i]<<j)&msk) != 0) p->alpha[i][j] = plot; | |
242 } | |
243 } | |
244 } | |
245 | |
246 static void | |
247 banset(char c, struct bann *p) | |
248 { | |
249 int i, j; | |
250 for (i = 0; i < nlines; i++) | |
251 for (j = 0; j < pposs-1; j++) | |
252 p->alpha[i][j] = c; | |
253 } | |
254 | |
255 static void | |
256 banprt(struct bann *ptr) | |
257 { | |
258 int i, j; | |
259 for (i = 0; i < nlines; i++) { | |
260 ptr->alpha[i][pposs-1] = '\0'; | |
261 for (j = pposs-2; j >= 0; j--) { | |
262 if (ptr->alpha[i][j] != blank)break; | |
263 ptr->alpha[i][j] = '\0'; | |
264 } | |
265 (void) printf("%s\n", ptr->alpha[i]); | |
266 } | |
267 } | |
268 | |
269 static char | |
270 convert(unsigned char c) | |
271 { | |
272 if (c >= 0xc0 && c <= 0xc6) | |
273 return ('A'); | |
274 if (c >= 0xc8 && c <= 0xcb) | |
275 return ('E'); | |
276 if (c == 0xc7) | |
277 return ('C'); | |
278 if (c >= 0xcc && c <= 0xcf) | |
279 return ('I'); | |
280 if (c == 0xd0) | |
281 return ('D'); | |
282 if (c == 0xd1) | |
283 return ('N'); | |
284 if (c >= 0xd2 && c <= 0xd6) | |
285 return ('O'); | |
286 if (c == 0xd7) | |
287 return ('X'); | |
288 if (c == 0xd8) | |
289 return ('O'); | |
290 if (c >= 0xd9 && c <= 0xdc) | |
291 return ('U'); | |
292 if (c == 0xdd) | |
293 return ('Y'); | |
294 if (c == 0xde) | |
295 return ('P'); | |
296 if (c == 0xdf) | |
297 return ('B'); | |
298 if (c >= 0xe0 && c <= 0xe6) | |
299 return ('a'); | |
300 if (c == 0xe7) | |
301 return ('c'); | |
302 if (c >= 0xe8 && c <= 0xeb) | |
303 return ('e'); | |
304 if (c >= 0xec && c <= 0xef) | |
305 return ('i'); | |
306 if (c == 0xf0) | |
307 return ('d'); | |
308 if (c == 0xf1) | |
309 return ('n'); | |
310 if (c >= 0xf2 && c <= 0xf6) | |
311 return ('o'); | |
312 if (c >= 0xf9 && c <= 0xfc) | |
313 return ('u'); | |
314 if (c == 0xfd) | |
315 return ('y'); | |
316 if (c == 0xfe) | |
317 return ('p'); | |
318 if (c == 0xff) | |
319 return ('y'); | |
320 return (c & 0177); | |
321 } |