[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.6

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