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