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