Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/std/banner.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1989-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* David Korn
23
* AT&T Research
24
*
25
* banner [-d delim] [-w width] arg ...
26
*/
27
28
static const char usage[] =
29
"[-?\n@(#)$Id: banner (AT&T Research) 1999-04-28 $\n]"
30
USAGE_LICENSE
31
"[+NAME?banner - print large banner]"
32
"[+DESCRIPTION?\bbanner\b prints a large banner on the standard output.]"
33
34
"[d:delimiter?The banner print character is \achar\a.]:[char:=#]"
35
"[w:width?The banner print width is \awidth\a.]#[width:=80]"
36
37
"\n"
38
"\n[ message ... ]\n"
39
"\n"
40
"[+SEE ALSO?\blpr\b(1), \bpr\b(1)]"
41
;
42
43
#include <cmd.h>
44
#include <ccode.h>
45
46
#define CHAR_HEIGHT 8
47
48
const unsigned char bandata[128][CHAR_HEIGHT] =
49
{
50
0, 0, 0, 0, 0, 0, 0, 0,
51
0, 0, 0, 0, 0, 0, 0, 0,
52
0, 0, 0, 0, 0, 0, 0, 0,
53
0, 0, 0, 0, 0, 0, 0, 0,
54
0, 0, 0, 0, 0, 0, 0, 0,
55
0, 0, 0, 0, 0, 0, 0, 0,
56
0, 0, 0, 0, 0, 0, 0, 0,
57
0, 0, 0, 0, 0, 0, 0, 0,
58
0, 0, 0, 0, 0, 0, 0, 0,
59
0, 0, 0, 0, 0, 0,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0x10, 0, 0,
94
0, 0, 0, 0x38, 0x38, 0x10, 0x20, 0,
95
0, 0, 0, 0x7c, 0, 0, 0, 0,
96
0, 0, 0, 0, 0x38, 0x38, 0x38, 0,
97
0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0,
98
0x38, 0x44, 0x82, 0x82, 0x82, 0x44, 0x38, 0,
99
0x10, 0x30, 0x50, 0x10, 0x10, 0x10, 0x7c, 0,
100
0x7c, 0x82, 0x2, 0x7c, 0x80, 0x80, 0xfe, 0,
101
0x7c, 0x82, 0x2, 0x7c, 0x2, 0x82, 0x7c, 0,
102
0x80, 0x84, 0x84, 0x84, 0xfe, 0x4, 0x4, 0,
103
0xfe, 0x80, 0x80, 0xfc, 0x2, 0x82, 0x7c, 0,
104
0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c, 0,
105
0xfe, 0x84, 0x8, 0x10, 0x20, 0x20, 0x20, 0,
106
0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c, 0,
107
0x7c, 0x82, 0x82, 0x7e, 0x2, 0x82, 0x7c, 0,
108
0x10, 0x38, 0x10, 0, 0x10, 0x38, 0x10, 0,
109
0x38, 0x38, 0, 0x38, 0x38, 0x10, 0x20, 0,
110
0x8, 0x10, 0x20, 0x40, 0x20, 0x10, 0x8, 0,
111
0, 0, 0x7c, 0, 0x7c, 0, 0, 0,
112
0x20, 0x10, 0x8, 0x4, 0x8, 0x10, 0x20, 0,
113
0x7c, 0x82, 0x2, 0x1c, 0x10, 0, 0x10, 0,
114
0x7c, 0x82, 0xba, 0xba, 0xbc, 0x80, 0x7c, 0,
115
0x10, 0x28, 0x44, 0x82, 0xfe, 0x82, 0x82, 0,
116
0xfc, 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0,
117
0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0,
118
0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0,
119
0xfe, 0x80, 0x80, 0xf8, 0x80, 0x80, 0xfe, 0,
120
0xfe, 0x80, 0x80, 0xf8, 0x80, 0x80, 0x80, 0,
121
0x7c, 0x82, 0x80, 0x9e, 0x82, 0x82, 0x7c, 0,
122
0x82, 0x82, 0x82, 0xfe, 0x82, 0x82, 0x82, 0,
123
0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0,
124
0x2, 0x2, 0x2, 0x2, 0x82, 0x82, 0x7c, 0,
125
0x84, 0x88, 0x90, 0xe0, 0x90, 0x88, 0x84, 0,
126
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0,
127
0x82, 0xc6, 0xaa, 0x92, 0x82, 0x82, 0x82, 0,
128
0x82, 0xc2, 0xa2, 0x92, 0x8a, 0x86, 0x82, 0,
129
0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfe, 0,
130
0xfc, 0x82, 0x82, 0xfc, 0x80, 0x80, 0x80, 0,
131
0x7c, 0x82, 0x82, 0x82, 0x8a, 0x84, 0x7a, 0,
132
0xfc, 0x82, 0x82, 0xfc, 0x88, 0x84, 0x82, 0,
133
0x7c, 0x82, 0x80, 0x7c, 0x2, 0x82, 0x7c, 0,
134
0xfe, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0,
135
0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c, 0,
136
0x82, 0x82, 0x82, 0x82, 0x44, 0x28, 0x10, 0,
137
0x82, 0x92, 0x92, 0x92, 0x92, 0x92, 0x6c, 0,
138
0x82, 0x44, 0x28, 0x10, 0x28, 0x44, 0x82, 0,
139
0x82, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0,
140
0xfe, 0x4, 0x8, 0x10, 0x20, 0x40, 0xfe, 0,
141
0x7c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7c, 0,
142
0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0,
143
0x7c, 0x4, 0x4, 0x4, 0x4, 0x4, 0x7c, 0,
144
0x10, 0x28, 0x44, 0, 0, 0, 0, 0,
145
0, 0, 0, 0, 0, 0, 0xfe, 0,
146
0x38, 0x38, 0x10, 0x8, 0, 0, 0, 0,
147
0, 0x18, 0x24, 0x42, 0x7e, 0x42, 0x42, 0,
148
0, 0x7c, 0x42, 0x7c, 0x42, 0x42, 0x7c, 0,
149
0, 0x3c, 0x42, 0x40, 0x40, 0x42, 0x3c, 0,
150
0, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x7c, 0,
151
0, 0x7e, 0x40, 0x7c, 0x40, 0x40, 0x7e, 0,
152
0, 0x7e, 0x40, 0x7c, 0x40, 0x40, 0x40, 0,
153
0, 0x3c, 0x42, 0x40, 0x4e, 0x42, 0x3c, 0,
154
0, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0,
155
0, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0,
156
0, 0x2, 0x2, 0x2, 0x2, 0x42, 0x3c, 0,
157
0, 0x42, 0x44, 0x78, 0x48, 0x44, 0x42, 0,
158
0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0,
159
0, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0,
160
0, 0x42, 0x62, 0x52, 0x4a, 0x46, 0x42, 0,
161
0, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0,
162
0, 0x7c, 0x42, 0x42, 0x7c, 0x40, 0x40, 0,
163
0, 0x3c, 0x42, 0x42, 0x4a, 0x44, 0x3a, 0,
164
0, 0x7c, 0x42, 0x42, 0x7c, 0x44, 0x42, 0,
165
0, 0x3c, 0x40, 0x3c, 0x2, 0x42, 0x3c, 0,
166
0, 0x3e, 0x8, 0x8, 0x8, 0x8, 0x8, 0,
167
0, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0,
168
0, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0,
169
0, 0x42, 0x42, 0x42, 0x5a, 0x66, 0x42, 0,
170
0, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0,
171
0, 0x22, 0x14, 0x8, 0x8, 0x8, 0x8, 0,
172
0, 0x7e, 0x4, 0x8, 0x10, 0x20, 0x7e, 0,
173
0x38, 0x40, 0x40, 0xc0, 0x40, 0x40, 0x38, 0,
174
0x10, 0x10, 0x10, 0, 0x10, 0x10, 0x10, 0,
175
0x38, 0x4, 0x4, 0x6, 0x4, 0x4, 0x38, 0,
176
0x60, 0x92, 0xc, 0, 0, 0, 0, 0,
177
0, 0, 0, 0, 0, 0, 0, 0,
178
};
179
180
static void banner(const char *string,const char *delim,int width)
181
{
182
register unsigned mask;
183
register int c,i,n,j = strlen(string);
184
register const char *cp,*dp;
185
register unsigned char* map;
186
187
map = ccmap(CC_NATIVE, CC_ASCII);
188
if(j > width/8)
189
error(ERROR_exit(1),"up to %d char%s per arg",width/8,(width/8)==1?"":"s");
190
for(i=0; i < CHAR_HEIGHT; i++)
191
{
192
dp = delim;
193
for (n = 0, cp = string; c = ccmapchr(map, *cp++) & 0x07f; dp++)
194
{
195
if(*dp==0)
196
dp = delim;
197
if((mask = bandata[c][i])==0)
198
{
199
n += 8;
200
continue;
201
}
202
for(j=0x80; j>0; j >>=1)
203
{
204
if(mask&j)
205
{
206
if(n)
207
{
208
sfnputc(sfstdout,' ',n);
209
n = 0;
210
}
211
sfputc(sfstdout,*dp);
212
}
213
else
214
n++;
215
}
216
}
217
sfputc(sfstdout,'\n');
218
}
219
}
220
221
int
222
main(int argc, char *argv[])
223
{
224
register int n;
225
register char *cp;
226
char *delim = "#";
227
int width = 80;
228
229
NoP(argc);
230
error_info.id = "banner";
231
while (n = optget(argv, usage)) switch (n)
232
{
233
case 'd':
234
delim = opt_info.arg;
235
break;
236
case 'w':
237
width = opt_info.num;
238
break;
239
case ':':
240
error(2, "%s", opt_info.arg);
241
break;
242
case '?':
243
error(ERROR_usage(2), "%s", opt_info.arg);
244
break;
245
}
246
argv += opt_info.index;
247
if(error_info.errors || !*argv)
248
error(ERROR_usage(2), "%s", optusage((char*)0));
249
sfset(sfstdout,SF_LINE,0);
250
while(cp = *argv++)
251
banner(cp,delim,width);
252
exit(0);
253
}
254
255