X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/da021cc5ef84fdb5f4c24da0e4f74208039166b9..c0e5f1acfc272507c6625a5ca9ba723a6b0a7df8:/banner/banner.c diff --git a/banner/banner.c b/banner/banner.c index e7fa4148..5861b50f 100644 --- a/banner/banner.c +++ b/banner/banner.c @@ -1,4 +1,4 @@ -/* $NetBSD: banner.c,v 1.6 1997/03/04 05:48:42 mikel Exp $ */ +/* $NetBSD: banner.c,v 1.21 2012/10/13 19:44:36 dholland Exp $ */ /* * Copyright (c) 1980, 1993, 1994 @@ -12,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,23 +29,23 @@ * SUCH DAMAGE. */ +#include #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1980, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1980, 1993, 1994\ + The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)banner.c 8.4 (Berkeley) 4/29/95"; #else -static char rcsid[] = "$NetBSD: banner.c,v 1.6 1997/03/04 05:48:42 mikel Exp $"; +__RCSID("$NetBSD: banner.c,v 1.21 2012/10/13 19:44:36 dholland Exp $"); #endif #endif /* not lint */ /* * banner - prints large signs - * banner [-w width] [-d] [-t] message ... + * banner [-dt] [-w width] [message] */ #include @@ -64,7 +60,7 @@ static char rcsid[] = "$NetBSD: banner.c,v 1.6 1997/03/04 05:48:42 mikel Exp $"; #define NBYTES 9271 /* Pointers into data_table for each ASCII char */ -int asc_ptr[NCHARS] = { +static const int asc_ptr[NCHARS] = { /* ^@ */ 0, 0, 0, 0, 0, 0, 0, 0, /* ^H */ 0, 0, 0, 0, 0, 0, 0, 0, /* ^P */ 0, 0, 0, 0, 0, 0, 0, 0, @@ -91,7 +87,7 @@ int asc_ptr[NCHARS] = { * is the next elt in array) and goto second * next element in array. */ -char data_table[NBYTES] = { +static const unsigned char data_table[NBYTES] = { /* 0 1 2 3 4 5 6 7 8 9 */ /* 0 */ 129, 227, 130, 34, 6, 90, 19, 129, 32, 10, /* 10 */ 74, 40, 129, 31, 12, 64, 53, 129, 30, 14, @@ -1023,20 +1019,27 @@ char data_table[NBYTES] = { /* 9270 */ 193 }; -char line[DWIDTH]; -char message[MAXMSG]; -char print[DWIDTH]; -int debug, i, j, linen, max, nchars, pc, term, trace, x, y; -int width = DWIDTH; /* -w option: scrunch letters to 80 columns */ +static char line[DWIDTH]; +static char message[MAXMSG]; +static char print[DWIDTH]; +static int debug, linen, max, nchars, pc, term, trace; +static int width = DWIDTH; /* -w option: scrunch letters to 80 columns */ + +__dead static void +toolong(void) +{ + errx(EXIT_FAILURE, "message too long"); +} int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int ch; + int i, j, x, y; + + x = y = 0; - while ((ch = getopt(argc, argv, "w:td")) != EOF) + while ((ch = getopt(argc, argv, "w:td")) != -1) switch (ch) { case 'd': debug = 1; @@ -1046,28 +1049,33 @@ main(argc, argv) break; case 'w': width = atoi(optarg); - if (width <= 0) + if (width <= 0 || width > DWIDTH) errx(1, "illegal argument for -w option"); break; case '?': default: - (void)fprintf(stderr, "usage: banner [-w width]\n"); + (void)fprintf(stderr, "usage: banner [-w width] [message]\n"); exit(1); } argc -= optind; argv += optind; for (i = 0; i < width; i++) { - j = i * 132 / width; + j = i * DWIDTH / width; print[j] = 1; } /* Have now read in the data. Next get the message to be printed. */ if (*argv) { - strcpy(message, *argv); + const size_t msize = sizeof(message); + + if (strlcpy(message, *argv, msize) >= msize) + toolong(); while (*++argv) { - strcat(message, " "); - strcat(message, *argv); + if (strlcat(message, " ", msize) >= msize) + toolong(); + if (strlcat(message, *argv, msize) >= msize) + toolong(); } nchars = strlen(message); } else { @@ -1093,7 +1101,7 @@ main(argc, argv) for (i = 0; i < NBYTES; i += 10) { printf("/* %4d */ ",i); for (j = i; j < i+10; j++) { - x = data_table[j] & 0377; + x = data_table[j]; printf(" %3d, ",x); } putchar('\n'); @@ -1130,9 +1138,12 @@ main(argc, argv) printf("bad pc: %d\n",pc); exit(1); } - x = data_table[pc] & 0377; - if (trace) - printf("pc=%d, term=%d, max=%d, linen=%d, x=%d\n",pc,term,max,linen,x); + x = data_table[pc]; + if (trace) { + printf("pc=%d, term=%d, max=%d, linen=%d, x=%d", + pc,term,max,linen,x); + printf("\n"); + } if (x >= 128) { if (x>192) term++; x = x & 63; @@ -1150,7 +1161,7 @@ main(argc, argv) else { y = data_table[pc+1]; /* compensate for narrow teminals */ -#ifdef notdef +#if 0 /* notdef */ x = (x*width + (DWIDTH/2)) / DWIDTH; y = (y*width + (DWIDTH/2)) / DWIDTH; #endif