Date: Thu, 20 Sep 2001 07:30:03 -0700 (PDT) From: Andrey Simonenko <simon@simon.org.ua> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/30641: Patch for games/grdc Message-ID: <200109201430.f8KEU3h32227@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/30641; it has been noted by GNATS. From: Andrey Simonenko <simon@simon.org.ua> To: Ruslan Ermilov <ru@FreeBSD.org> Cc: <bug-followup@FreeBSD.org> Subject: Re: bin/30641: Patch for games/grdc Date: Thu, 20 Sep 2001 17:22:05 +0300 (EEST) On Wed, 19 Sep 2001, Ruslan Ermilov wrote: > On Tue, Sep 18, 2001 at 11:39:12AM +0300, Andrey Simonenko wrote: > > > > grdc(8) outputs big digital clock. Color of digits is red, if grdc(8) > > is used on b/w display, then it is hard to see something. > > > > This patch adds new flag to grdc(8): -b, which changes color of digits > > to b/w. Also arguments checking is improved. > > > Use the right (B/W) terminal type such as cons25-m. > > > In this patch type of "sigtermed" variable is changed from "int" to > > "voilatile sig_atomic_t", because "sigtermed" variable is changed in signal > > handler. > > > This looks OK though a bit superflows in this case. :-) > Also, is sig_atomic_t guaranteed to be a superset of int? > (I'm mostly concerned about the portability issues here, > I know that in FreeBSD sig_atomic_t is ether int or long.) > Ok, I understand that there isn't any sense in -b option, so I remove -b option support from my patch, but all other improvements I keep there: diff -ru /usr/src/games/grdc/grdc.c grdc/grdc.c --- /usr/src/games/grdc/grdc.c Sun Dec 12 03:04:17 1999 +++ grdc/grdc.c Thu Sep 20 15:38:40 2001 @@ -5,14 +5,18 @@ * * modified 10-18-89 for curses (jrl) * 10-18-89 added signal handling + * 09-17-2001 improved arguments checking * * $FreeBSD: src/games/grdc/grdc.c,v 1.8 1999/12/12 03:04:17 billf Exp $ */ +#include <ctype.h> +#include <err.h> #include <time.h> #include <signal.h> #include <ncurses.h> #include <stdlib.h> +#include <string.h> #ifndef NONPOSIX #include <unistd.h> #endif @@ -31,9 +35,9 @@ 074717, 074757, 071111, 075757, 075717, 002020 }; long old[6], next[6], new[6], mask; -char scrol; +int scrol = 0; -int sigtermed=0; +volatile sig_atomic_t sigtermed = 0; int hascolor = 0; @@ -56,6 +60,29 @@ long t, a; int i, j, s, k; int n = 0; +int opt; + + opterr = 0; + while ( (opt = getopt(argc, argv, "s")) != -1) + switch (opt) { + case 's': + scrol = 1; + break; + case '?': + errx(1, "invalid switch -%c", optopt); + break; + default: + err(1, "getopt"); + } + if (optind < argc) { + if (optind == argc - 1) { + for (i = 0; i < strlen(argv[optind]); ++i) + if (isdigit(argv[optind][i]) == 0) + errx(1, "incorrect number of seconds \"%s\"", argv[optind]); + n = atoi(argv[optind]); + } else + errx(1, "too many arguments \"%s\"", argv[optind + 1]); + } initscr(); @@ -79,12 +106,6 @@ clear(); refresh(); - while(--argc > 0) { - if(**++argv == '-') - scrol = 1; - else - n = atoi(*argv); - } if(hascolor) { attrset(COLOR_PAIR(3)); @@ -155,8 +176,7 @@ clear(); refresh(); endwin(); - fprintf(stderr, "grdc terminated by signal %d\n", sigtermed); - exit(1); + errx(1, "terminated by signal %d", sigtermed); } } while(--n); standend(); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200109201430.f8KEU3h32227>