Date: Tue, 18 Sep 2001 11:39:12 +0300 (EEST) From: Andrey Simonenko <simon@simon.org.ua> To: <FreeBSD-gnats-submit@freebsd.org> Subject: bin/30641: Patch for games/grdc Message-ID: <20010918113631.I72277-100000@lion.com.ua>
next in thread | raw e-mail | index | archive | help
>Number: 30641 >Category: bin >Synopsis: Patch for games/grdc >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Sep 18 01:40:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Andrey Simonenko >Release: FreeBSD 4.4-RC i386 >Organization: >Environment: System: FreeBSD 4.4-RC i386 >Description: 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. In this patch type of "sigtermed" variable is changed from "int" to "voilatile sig_atomic_t", because "sigtermed" variable is changed in signal handler. In this patch also one fprintf(stderr) function is changed to appropriate errx(3) function. >How-To-Repeat: Apply following patch. >Fix: diff -ru /usr/src/games/grdc/grdc.6 grdc/grdc.6 --- /usr/src/games/grdc/grdc.6 Mon Dec 5 19:29:59 1994 +++ grdc/grdc.6 Mon Sep 17 02:40:22 2001 @@ -3,7 +3,7 @@ grdc \- grand digital clock (curses) .SH SYNOPSIS .B grdc -[-s] [ +[-sb] [ .I n ] .SH DESCRIPTION @@ -18,5 +18,8 @@ .B -s flag makes digits scroll as they change. In this curses mode implementation, the scrolling option has trouble keeping up. +The optional +.B -b +flag changes color of digits to b/w (useful option for b/w displays). .SH AUTHOR Amos Shapir, modified for curses by John Lupien. 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 Mon Sep 17 20:26:14 2001 @@ -1,18 +1,23 @@ /* * Grand digital clock for curses compatible terminals - * Usage: grdc [-s] [n] -- run for n seconds (default infinity) + * Usage: grdc [-sb] [n] -- run for n seconds (default infinity) * Flags: -s: scroll + * -b: b/w output * * modified 10-18-89 for curses (jrl) * 10-18-89 added signal handling + * 09-17-2001 added -b flag, 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 +36,9 @@ 074717, 074757, 071111, 075757, 075717, 002020 }; long old[6], next[6], new[6], mask; -char scrol; +int scrol = 0, bw = 0; -int sigtermed=0; +volatile sig_atomic_t sigtermed = 0; int hascolor = 0; @@ -56,6 +61,32 @@ long t, a; int i, j, s, k; int n = 0; +int opt; + + opterr = 0; + while ( (opt = getopt(argc, argv, "sb")) != -1) + switch (opt) { + case 's': + scrol = 1; + break; + case 'b': + bw = 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(); @@ -71,20 +102,19 @@ if(hascolor) { start_color(); - init_pair(1, COLOR_BLACK, COLOR_RED); - init_pair(2, COLOR_RED, COLOR_BLACK); + if (bw) { + init_pair(1, COLOR_BLACK, COLOR_WHITE); + init_pair(2, COLOR_WHITE, COLOR_BLACK); + } else { + init_pair(1, COLOR_BLACK, COLOR_RED); + init_pair(2, COLOR_RED, COLOR_BLACK); + } init_pair(3, COLOR_WHITE, COLOR_BLACK); attrset(COLOR_PAIR(2)); } clear(); refresh(); - while(--argc > 0) { - if(**++argv == '-') - scrol = 1; - else - n = atoi(*argv); - } if(hascolor) { attrset(COLOR_PAIR(3)); @@ -155,8 +185,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(); >Release-Note: >Audit-Trail: >Unformatted: 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?20010918113631.I72277-100000>