[BACK]Return to banner.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / banner

Annotation of src/usr.bin/banner/banner.c, Revision 1.1

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