banner.c revision 1.1 1 /* $NetBSD: banner.c,v 1.1 1995/04/09 05:53:05 cgd Exp $ */
2 /*
3 * Changes for banner(1)
4 *
5 * @(#)Copyright (c) 1995, Simon J. Gerraty.
6 *
7 * This is free software. It comes with NO WARRANTY.
8 * Permission to use, modify and distribute this source code
9 * is granted subject to the following conditions.
10 * 1/ that the above copyright notice and this notice
11 * are preserved in all copies and that due credit be given
12 * to the author.
13 * 2/ that any changes to this code are clearly commented
14 * as such so that the author does not get blamed for bugs
15 * other than his own.
16 *
17 * Please send copies of changes and bug-fixes to:
18 * sjg (at) zen.void.oz.au
19 */
20 /*
21 * Copyright (c) 1983, 1993
22 * The Regents of the University of California. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. All advertising materials mentioning features or use of this software
33 * must display the following acknowledgement:
34 * This product includes software developed by the University of
35 * California, Berkeley and its contributors.
36 * 4. Neither the name of the University nor the names of its contributors
37 * may be used to endorse or promote products derived from this software
38 * without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 */
52 #ifndef lint
53 static char copyright[] =
54 "@(#) Copyright (c) 1983, 1993\n\
55 The Regents of the University of California. All rights reserved.\n";
56 #endif /* not lint */
57
58 #ifndef lint
59 static char sccsid[] = "@(#)printjob.c 8.2 (Berkeley) 4/16/94";
60 #endif /* not lint */
61
62 #ifndef lint
63 static char rcsid[] = "$NetBSD: banner.c,v 1.1 1995/04/09 05:53:05 cgd Exp $";
64 #endif
65 #include <stdio.h>
66
67 #include "banner.h"
68
69 static long PW = LINELEN;
70
71 /* the char gen code below is lifted from lpd */
72
73 static char *
74 scnline(key, p, c)
75 register int key;
76 register char *p;
77 int c;
78 {
79 register scnwidth;
80
81 /*
82 * <sjg> lpd makes chars out of the letter in question.
83 * the results are somewhat mixed. Sticking to '#' as
84 * banner(1) does is more consistent.
85 */
86 #ifndef NOHASH_ONLY
87 c = '#';
88 #endif
89
90 for (scnwidth = WIDTH; --scnwidth;) {
91 key <<= 1;
92 *p++ = key & 0200 ? c : BACKGND;
93 }
94 return (p);
95 }
96
97 #define TRC(q) (((q)-' ')&0177)
98
99
100 static int
101 dropit(c)
102 int c;
103 {
104 switch(c) {
105
106 case TRC('_'):
107 case TRC(';'):
108 case TRC(','):
109 case TRC('g'):
110 case TRC('j'):
111 case TRC('p'):
112 case TRC('q'):
113 case TRC('y'):
114 return (DROP);
115
116 default:
117 return (0);
118 }
119 }
120
121 static void
122 scan_out(scfd, scsp, dlm)
123 int scfd, dlm;
124 char *scsp;
125 {
126 register char *strp;
127 register nchrs, j;
128 char outbuf[LINELEN+1], *sp, c, cc;
129 int d, scnhgt;
130 extern char scnkey[][HEIGHT]; /* in lpdchar.c */
131
132 for (scnhgt = 0; scnhgt++ < HEIGHT+DROP; ) {
133 strp = &outbuf[0];
134 sp = scsp;
135 for (nchrs = 0; ; ) {
136 d = dropit(c = TRC(cc = *sp++));
137 if ((!d && scnhgt > HEIGHT) || (scnhgt <= DROP && d))
138 for (j = WIDTH; --j;)
139 *strp++ = BACKGND;
140 else
141 strp = scnline(scnkey[c][scnhgt-1-d], strp, cc);
142 if (*sp == dlm || *sp == '\0' || nchrs++ >= PW/(WIDTH+1)-1)
143 break;
144 *strp++ = BACKGND;
145 #ifdef LPD_CHSET /* <sjg> */
146 *strp++ = BACKGND;
147 #endif
148 }
149 while (*--strp == BACKGND && strp >= outbuf)
150 ;
151 strp++;
152 *strp++ = '\n';
153 (void) write(scfd, outbuf, strp-outbuf);
154 }
155 }
156
157 /*
158 * for each word, print up to 10 chars in big letters.
159 */
160 int
161 main(argc, argv)
162 int argc;
163 char **argv;
164 {
165 char word[10+1]; /* strings limited to 10 chars */
166
167 while (*++argv) {
168 (void)strncpy(word, *argv, sizeof (word) - 1);
169 word[sizeof (word) - 1] = '\0';
170 scan_out(1, word, '\0');
171 }
172 exit(0);
173 }
174