banner.c revision 1.8
1302520Smav/* $OpenBSD: banner.c,v 1.8 2003/06/10 22:20:44 deraadt Exp $ */ 2302520Smav/* $NetBSD: banner.c,v 1.2 1995/04/09 06:00:15 cgd Exp $ */ 3302520Smav 4302520Smav/* 5302520Smav * Changes for banner(1) 6302520Smav * 7302520Smav * @(#)Copyright (c) 1995, Simon J. Gerraty. 8302520Smav * 9302520Smav * This is free software. It comes with NO WARRANTY. 10302520Smav * Permission to use, modify and distribute this source code 11302520Smav * is granted subject to the following conditions. 12302520Smav * 1/ that the above copyright notice and this notice 13302520Smav * are preserved in all copies and that due credit be given 14302520Smav * to the author. 15302520Smav * 2/ that any changes to this code are clearly commented 16302520Smav * as such so that the author does not get blamed for bugs 17302520Smav * other than his own. 18302520Smav * 19302520Smav * Please send copies of changes and bug-fixes to: 20302520Smav * sjg@zen.void.oz.au 21302520Smav */ 22302520Smav 23302520Smav/* 24302520Smav * Copyright (c) 1983, 1993 25302520Smav * The Regents of the University of California. All rights reserved. 26302520Smav * 27302520Smav * Redistribution and use in source and binary forms, with or without 28323453Smav * modification, are permitted provided that the following conditions 29302520Smav * are met: 30302520Smav * 1. Redistributions of source code must retain the above copyright 31302520Smav * notice, this list of conditions and the following disclaimer. 32302520Smav * 2. Redistributions in binary form must reproduce the above copyright 33302520Smav * notice, this list of conditions and the following disclaimer in the 34302520Smav * documentation and/or other materials provided with the distribution. 35302520Smav * 3. Neither the name of the University nor the names of its contributors 36302520Smav * may be used to endorse or promote products derived from this software 37302520Smav * without specific prior written permission. 38323453Smav * 39323453Smav * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 40302520Smav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41302520Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 42302520Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 43302520Smav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 44302520Smav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 45302520Smav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46302520Smav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 47302520Smav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 48302520Smav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 49302520Smav * SUCH DAMAGE. 50302520Smav */ 51302520Smav#ifndef lint 52302520Smavstatic const char copyright[] = 53323453Smav"@(#) Copyright (c) 1983, 1993\n\ 54304368Smav The Regents of the University of California. All rights reserved.\n"; 55302520Smav#if 0 56302520Smavstatic char sccsid[] = "@(#)printjob.c 8.2 (Berkeley) 4/16/94"; 57302520Smav#else 58302520Smavstatic const char rcsid[] = "$OpenBSD: banner.c,v 1.8 2003/06/10 22:20:44 deraadt Exp $"; 59302520Smav#endif 60302520Smav#endif /* not lint */ 61323453Smav 62323453Smav#include <stdio.h> 63323453Smav#include <unistd.h> 64323453Smav#include <stdlib.h> 65302520Smav#include <string.h> 66302520Smav 67302520Smav#include "banner.h" 68302520Smav 69302520Smavstatic long PW = LINELEN; 70302520Smav 71302520Smav/* the char gen code below is lifted from lpd */ 72302520Smav 73302520Smavstatic char * 74302520Smavscnline(int key, char *p, int c) 75302520Smav{ 76302520Smav int scnwidth; 77302520Smav 78302520Smav /* 79302520Smav * <sjg> lpd makes chars out of the letter in question. 80302520Smav * the results are somewhat mixed. Sticking to '#' as 81302520Smav * banner(1) does is more consistent. 82302520Smav */ 83302520Smav#ifndef NOHASH_ONLY 84302520Smav c = '#'; 85302520Smav#endif 86302520Smav 87304368Smav for (scnwidth = WIDTH; --scnwidth;) { 88304368Smav key <<= 1; 89304368Smav *p++ = key & 0200 ? c : BACKGND; 90 } 91 return (p); 92} 93 94#define TRC(q) (((q)-' ')&0177) 95 96 97static int 98dropit(int c) 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 117static void 118scan_out(int scfd, char *scsp, int dlm) 119{ 120 char *strp; 121 int nchrs, j; 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; 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); 136 d = dropit(c); 137 if ((!d && scnhgt > HEIGHT) || (scnhgt <= DROP && d)) 138 for (j = WIDTH; --j;) 139 *strp++ = BACKGND; 140 else 141 strp = scnline(scnkey[(int)c][scnhgt-1-d], strp, cc); 142 if (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 */ 160int 161main(int argc, char *argv[]) 162{ 163 char word[10+1]; /* strings limited to 10 chars */ 164 165 while (*++argv) { 166 (void)strlcpy(word, *argv, sizeof (word)); 167 scan_out(1, word, '\0'); 168 } 169 exit(0); 170} 171