X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/a65a873e56c35780711e9f73872c4fe0254589b0..6ab4965434cb30f31450949e29f988bc4915e16d:/bcd/bcd.c diff --git a/bcd/bcd.c b/bcd/bcd.c index 69ee9a13..9f5dce7a 100644 --- a/bcd/bcd.c +++ b/bcd/bcd.c @@ -1,4 +1,4 @@ -/* $NetBSD: bcd.c,v 1.6 1995/04/24 12:22:23 cgd Exp $ */ +/* $NetBSD: bcd.c,v 1.17 2009/08/12 05:21:28 dholland Exp $ */ /* * Copyright (c) 1989, 1993 @@ -15,11 +15,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. * @@ -36,14 +32,18 @@ * SUCH DAMAGE. */ +#include #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1989, 1993\ + The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)bcd.c 8.2 (Berkeley) 3/20/94"; +#else +__RCSID("$NetBSD: bcd.c,v 1.17 2009/08/12 05:21:28 dholland Exp $"); +#endif #endif /* not lint */ /* @@ -79,10 +79,12 @@ static char sccsid[] = "@(#)bcd.c 8.2 (Berkeley) 3/20/94"; #include #include +#include #include #include +#include -u_short holes[256] = { +static const u_short holes[256] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -122,13 +124,16 @@ u_short holes[256] = { */ #define bit(w,i) ((w)&(1<<(i))) +static void printcard(char *); + int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { char cardline[80]; + /* revoke setgid privileges */ + setgid(getgid()); + /* * The original bcd prompts with a "%" when reading from stdin, * but this seems kind of silly. So this one doesn't. @@ -145,16 +150,15 @@ main(argc, argv) #define COLUMNS 48 -printcard(str) - register char *str; +static void +printcard(char *str) { - static char rowchars[] = " 123456789"; - register int i, row; - register char *p; - char *index(); + static const char rowchars[] = " 123456789"; + int i, row; + char *p; /* ruthlessly remove newlines and truncate at 48 characters. */ - if ((p = index(str, '\n'))) + if ((p = strchr(str, '\n'))) *p = '\0'; if (strlen(str) > COLUMNS) @@ -162,8 +166,8 @@ printcard(str) /* make string upper case. */ for (p = str; *p; ++p) - if (isascii(*p) && islower(*p)) - *p = toupper(*p); + if (isascii((unsigned char)*p) && islower((unsigned char)*p)) + *p = toupper((unsigned char) *p); /* top of card */ putchar(' '); @@ -178,7 +182,7 @@ printcard(str) p = str; putchar('/'); for (i = 1; *p; i++, p++) - if (holes[*p]) + if (holes[(unsigned char)*p]) putchar(*p); else putchar(' '); @@ -196,7 +200,7 @@ printcard(str) for (row = 0; row <= 11; ++row) { putchar('|'); for (i = 0, p = str; *p; i++, p++) { - if (bit(holes[*p], 11 - row)) + if (bit(holes[(unsigned char)*p], 11 - row)) putchar(']'); else putchar(rowchars[row]);