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