X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/e106683a5e1883b9be5d14532e79a9ca4c3dac80..5091acb41289c711cd19e004627df9d31a1b8b1f:/bcd/bcd.c?ds=inline diff --git a/bcd/bcd.c b/bcd/bcd.c index d236fe36..6cc595a0 100644 --- a/bcd/bcd.c +++ b/bcd/bcd.c @@ -1,9 +1,11 @@ +/* $NetBSD: bcd.c,v 1.11 2000/07/03 03:57:40 matt Exp $ */ + /* - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by - * Steve Hayman of the Indiana University Computer Science Dept.. + * Steve Hayman of the Indiana University Computer Science Dept. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,15 +36,18 @@ * SUCH DAMAGE. */ +#include #ifndef lint -char copyright[] = -"@(#) Copyright (c) 1989 The Regents of the University of California.\n\ - All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "from: @(#)bcd.c 4.4 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$Id: bcd.c,v 1.3 1993/11/04 20:39:30 jtc Exp $"; +#if 0 +static char sccsid[] = "@(#)bcd.c 8.2 (Berkeley) 3/20/94"; +#else +__RCSID("$NetBSD: bcd.c,v 1.11 2000/07/03 03:57:40 matt Exp $"); +#endif #endif /* not lint */ /* @@ -61,13 +66,29 @@ static char rcsid[] = "$Id: bcd.c,v 1.3 1993/11/04 20:39:30 jtc Exp $"; * Steve Hayman * sahayman@iuvax.cs.indiana.edu * 1989 11 30 + * + * + * I found an error in the table. The same error is found in the SunOS 4.1.1 + * version of bcd. It has apparently been around a long time. The error caused + * 'Q' and 'R' to have the same punch code. I only noticed the error due to + * someone pointing it out to me when the program was used to print a cover + * for an APA! The table was wrong in 4 places. The other error was masked + * by the fact that the input is converted to upper case before lookup. + * + * Dyane Bruce + * db@diana.ocunix.on.ca + * Nov 5, 1993 */ #include + #include +#include +#include #include +#include -u_short holes[256] = { +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, @@ -82,7 +103,7 @@ u_short holes[256] = { 0x204, 0x202, 0x201, 0x082, 0x822, 0x600, 0x282, 0x30f, 0x900, 0x880, 0x840, 0x820, 0x810, 0x808, 0x804, 0x802, 0x801, 0x500, 0x480, 0x440, 0x420, 0x410, 0x408, 0x404, - 0x402, 0x402, 0x280, 0x240, 0x220, 0x210, 0x208, 0x204, + 0x402, 0x401, 0x280, 0x240, 0x220, 0x210, 0x208, 0x204, 0x202, 0x201, 0x082, 0x806, 0x822, 0x600, 0x282, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -98,7 +119,7 @@ u_short holes[256] = { 0x202, 0x201, 0x082, 0x806, 0x822, 0x600, 0x282, 0x30f, 0x900, 0x880, 0x840, 0x820, 0x810, 0x808, 0x804, 0x802, 0x801, 0x500, 0x480, 0x440, 0x420, 0x410, 0x408, 0x404, - 0x402, 0x402, 0x280, 0x240, 0x220, 0x210, 0x208, 0x204, + 0x402, 0x401, 0x280, 0x240, 0x220, 0x210, 0x208, 0x204, 0x202, 0x201, 0x082, 0x806, 0x822, 0x600, 0x282, 0x0 }; @@ -107,12 +128,19 @@ u_short holes[256] = { */ #define bit(w,i) ((w)&(1<<(i))) +int main __P((int, char *[])); +void printcard __P((char *)); + +int main(argc, argv) 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. @@ -129,16 +157,16 @@ main(argc, argv) #define COLUMNS 48 +void printcard(str) - register char *str; + char *str; { - static char rowchars[] = " 123456789"; - register int i, row; - register char *p; - char *index(); + static const char rowchars[] = " 123456789"; + int i, row; + unsigned 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,7 +190,7 @@ printcard(str) p = str; putchar('/'); for (i = 1; *p; i++, p++) - if (holes[*p]) + if (holes[(int)*p]) putchar(*p); else putchar(' '); @@ -180,7 +208,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[(int)*p], 11 - row)) putchar(']'); else putchar(rowchars[row]);