Home | History | Annotate | Line # | Download | only in banner
banner.c revision 1.4
      1  1.4    sjg /*	$NetBSD: banner.c,v 1.4 2000/05/30 12:03:31 sjg 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.1    cgd  * 3. All advertising materials mentioning features or use of this software
     35  1.1    cgd  *    must display the following acknowledgement:
     36  1.1    cgd  *	This product includes software developed by the University of
     37  1.1    cgd  *	California, Berkeley and its contributors.
     38  1.1    cgd  * 4. Neither the name of the University nor the names of its contributors
     39  1.1    cgd  *    may be used to endorse or promote products derived from this software
     40  1.1    cgd  *    without specific prior written permission.
     41  1.1    cgd  *
     42  1.1    cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     43  1.1    cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     44  1.1    cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     45  1.1    cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     46  1.1    cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     47  1.1    cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     48  1.1    cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     49  1.1    cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     50  1.1    cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     51  1.1    cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     52  1.1    cgd  * SUCH DAMAGE.
     53  1.1    cgd  */
     54  1.3  lukem 
     55  1.3  lukem #include <sys/cdefs.h>
     56  1.1    cgd #ifndef lint
     57  1.3  lukem __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
     58  1.3  lukem 	The Regents of the University of California.  All rights reserved.\n");
     59  1.1    cgd #endif /* not lint */
     60  1.1    cgd 
     61  1.1    cgd #ifndef lint
     62  1.2    cgd #if 0
     63  1.1    cgd static char sccsid[] = "@(#)printjob.c	8.2 (Berkeley) 4/16/94";
     64  1.2    cgd #else
     65  1.4    sjg __RCSID("$NetBSD: banner.c,v 1.4 2000/05/30 12:03:31 sjg Exp $");
     66  1.2    cgd #endif
     67  1.1    cgd #endif /* not lint */
     68  1.1    cgd 
     69  1.1    cgd #include <stdio.h>
     70  1.3  lukem #include <string.h>
     71  1.3  lukem #include <unistd.h>
     72  1.1    cgd 
     73  1.1    cgd #include "banner.h"
     74  1.1    cgd 
     75  1.1    cgd static long PW = LINELEN;
     76  1.4    sjg /*
     77  1.4    sjg  * <sjg> lpd makes chars out of the letter in question.
     78  1.4    sjg  * the results are somewhat mixed.  Sticking to '#' as
     79  1.4    sjg  * banner(1) does is more consistent.
     80  1.4    sjg  */
     81  1.4    sjg static int ForeGnd = '#';
     82  1.4    sjg static int BackGnd = ' ';
     83  1.4    sjg static int Drop = 0;				/* 3 for the LPD font */
     84  1.1    cgd 
     85  1.3  lukem static	int	dropit __P((int));
     86  1.3  lukem 	int	main __P((int, char **));
     87  1.3  lukem static	void	scan_out __P((int, char *, int));
     88  1.3  lukem static	char   *scnline __P((int, char *, int));
     89  1.3  lukem 
     90  1.1    cgd /* the char gen code below is lifted from lpd */
     91  1.1    cgd 
     92  1.1    cgd static char *
     93  1.1    cgd scnline(key, p, c)
     94  1.3  lukem 	int key;
     95  1.3  lukem 	char *p;
     96  1.1    cgd 	int c;
     97  1.1    cgd {
     98  1.3  lukem 	int scnwidth;
     99  1.1    cgd 
    100  1.4    sjg 	if (ForeGnd)
    101  1.4    sjg 	    c = ForeGnd;
    102  1.1    cgd 
    103  1.1    cgd 	for (scnwidth = WIDTH; --scnwidth;) {
    104  1.1    cgd 		key <<= 1;
    105  1.4    sjg 		*p++ = key & 0200 ? c : BackGnd;
    106  1.1    cgd 	}
    107  1.1    cgd 	return (p);
    108  1.1    cgd }
    109  1.1    cgd 
    110  1.1    cgd #define TRC(q)	(((q)-' ')&0177)
    111  1.1    cgd 
    112  1.1    cgd 
    113  1.1    cgd static int
    114  1.1    cgd dropit(c)
    115  1.1    cgd 	int c;
    116  1.1    cgd {
    117  1.1    cgd 	switch(c) {
    118  1.1    cgd 
    119  1.1    cgd 	case TRC('_'):
    120  1.1    cgd 	case TRC(';'):
    121  1.1    cgd 	case TRC(','):
    122  1.1    cgd 	case TRC('g'):
    123  1.1    cgd 	case TRC('j'):
    124  1.1    cgd 	case TRC('p'):
    125  1.1    cgd 	case TRC('q'):
    126  1.1    cgd 	case TRC('y'):
    127  1.4    sjg 		return (Drop);
    128  1.1    cgd 
    129  1.1    cgd 	default:
    130  1.1    cgd 		return (0);
    131  1.1    cgd 	}
    132  1.1    cgd }
    133  1.1    cgd 
    134  1.1    cgd static void
    135  1.1    cgd scan_out(scfd, scsp, dlm)
    136  1.3  lukem 	int scfd;
    137  1.1    cgd 	char *scsp;
    138  1.3  lukem 	int dlm;
    139  1.1    cgd {
    140  1.3  lukem 	char *strp;
    141  1.3  lukem 	int nchrs, j;
    142  1.1    cgd 	char outbuf[LINELEN+1], *sp, c, cc;
    143  1.1    cgd 	int d, scnhgt;
    144  1.1    cgd 
    145  1.4    sjg 	for (scnhgt = 0; scnhgt++ < HEIGHT+Drop; ) {
    146  1.1    cgd 		strp = &outbuf[0];
    147  1.4    sjg 		if (BackGnd != ' ')
    148  1.4    sjg 		    *strp++ = BackGnd;
    149  1.1    cgd 		sp = scsp;
    150  1.1    cgd 		for (nchrs = 0; ; ) {
    151  1.1    cgd 			d = dropit(c = TRC(cc = *sp++));
    152  1.4    sjg 			if ((!d && scnhgt > HEIGHT) || (scnhgt <= Drop && d))
    153  1.1    cgd 				for (j = WIDTH; --j;)
    154  1.4    sjg 					*strp++ = BackGnd;
    155  1.4    sjg 			else if (Drop == 0)
    156  1.4    sjg 				strp = scnline(
    157  1.4    sjg 				    scnkey_def[(int)c][scnhgt-1-d], strp, cc);
    158  1.1    cgd 			else
    159  1.3  lukem 				strp = scnline(
    160  1.4    sjg 				    scnkey_lpd[(int)c][scnhgt-1-d], strp, cc);
    161  1.1    cgd 			if (*sp == dlm || *sp == '\0' || nchrs++ >= PW/(WIDTH+1)-1)
    162  1.1    cgd 				break;
    163  1.4    sjg 			*strp++ = BackGnd;
    164  1.1    cgd 		}
    165  1.4    sjg 		if (BackGnd != ' ')
    166  1.4    sjg 		    *strp++ = BackGnd;
    167  1.4    sjg 		else {
    168  1.4    sjg 		    while (*--strp == ' ' && strp >= outbuf)
    169  1.1    cgd 			;
    170  1.4    sjg 		    strp++;
    171  1.4    sjg 		}
    172  1.1    cgd 		*strp++ = '\n';
    173  1.1    cgd 		(void) write(scfd, outbuf, strp-outbuf);
    174  1.1    cgd 	}
    175  1.1    cgd }
    176  1.1    cgd 
    177  1.1    cgd /*
    178  1.1    cgd  * for each word, print up to 10 chars in big letters.
    179  1.1    cgd  */
    180  1.1    cgd int
    181  1.1    cgd main(argc, argv)
    182  1.1    cgd 	int argc;
    183  1.1    cgd 	char **argv;
    184  1.1    cgd {
    185  1.4    sjg 	char word[10+1];		/* strings limited to 10 chars */
    186  1.4    sjg 	int c;
    187  1.4    sjg 
    188  1.4    sjg 	while ((c = getopt(argc, argv, "b:f:l")) != EOF) {
    189  1.4    sjg 	    switch (c) {
    190  1.4    sjg 	    case 'f':
    191  1.4    sjg 		if (*optarg == '-')
    192  1.4    sjg 		    ForeGnd = 0;
    193  1.4    sjg 		else
    194  1.4    sjg 		    ForeGnd = *optarg;
    195  1.4    sjg 		break;
    196  1.4    sjg 	    case 'b':
    197  1.4    sjg 		BackGnd = *optarg;
    198  1.4    sjg 		break;
    199  1.4    sjg 	    case 'l':
    200  1.4    sjg 		Drop = 3;			/* for LPD font */
    201  1.4    sjg 		break;
    202  1.4    sjg 	    }
    203  1.4    sjg 	}
    204  1.4    sjg 
    205  1.4    sjg 	for (; optind < argc; ++optind) {
    206  1.4    sjg 		(void)strncpy(word, argv[optind], sizeof (word) - 1);
    207  1.1    cgd 		word[sizeof (word) - 1] = '\0';
    208  1.1    cgd 		scan_out(1, word, '\0');
    209  1.1    cgd 	}
    210  1.1    cgd 	exit(0);
    211  1.1    cgd }
    212