CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: nia Date: Sun Aug 15 08:57:01 UTC 2021 Modified Files: src/games/fortune/datfiles: netbsd-tips Log Message: Capitalization police. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/games/fortune/datfiles/netbsd-tips Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/netbsd-tips diff -u src/games/fortune/datfiles/netbsd-tips:1.10 src/games/fortune/datfiles/netbsd-tips:1.11 --- src/games/fortune/datfiles/netbsd-tips:1.10 Fri Jun 4 11:18:31 2021 +++ src/games/fortune/datfiles/netbsd-tips Sun Aug 15 08:57:01 2021 @@ -120,7 +120,7 @@ and "systat netstat" commands. Visit the NetBSD Security website to keep track of advisories: http://www.NetBSD.org/support/security/ Or join the security-announce mailing list for alerts: - http://www.netbsd.org/mailinglists/#security-announce + http://www.NetBSD.org/mailinglists/#security-announce % Here's an example of finding what package a file belongs to:
CVS commit: src/games/fish
Module Name:src Committed By: dholland Date: Sun Jul 25 02:00:42 UTC 2021 Modified Files: src/games/fish: fish.c Log Message: Flush input to EOL correctly in games/fish. PR 54885 from Mouse, with a somewhat different patch. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/games/fish/fish.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fish/fish.c diff -u src/games/fish/fish.c:1.26 src/games/fish/fish.c:1.27 --- src/games/fish/fish.c:1.26 Sun May 2 12:25:55 2021 +++ src/games/fish/fish.c Sun Jul 25 02:00:42 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fish.c,v 1.26 2021/05/02 12:25:55 rillig Exp $ */ +/* $NetBSD: fish.c,v 1.27 2021/07/25 02:00:42 dholland Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19 #if 0 static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: fish.c,v 1.26 2021/05/02 12:25:55 rillig Exp $"); +__RCSID("$NetBSD: fish.c,v 1.27 2021/07/25 02:00:42 dholland Exp $"); #endif #endif /* not lint */ @@ -432,15 +432,20 @@ init(void) static void instructions(void) { - int input; + int input, c; pid_t pid; int fd; const char *pager; int status; (void)printf("Would you like instructions (y or n)? "); - input = getchar(); - while (getchar() != '\n'); + input = c = getchar(); + while (c != '\n') { + c = getchar(); + if (c == EOF) { + exit(1); + } + } if (input != 'y') return;
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: dholland Date: Sun Jul 11 00:35:05 UTC 2021 Modified Files: src/games/fortune/datfiles: fortunes Log Message: add something To generate a diff of this commit: cvs rdiff -u -r1.96 -r1.97 src/games/fortune/datfiles/fortunes Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/fortunes diff -u src/games/fortune/datfiles/fortunes:1.96 src/games/fortune/datfiles/fortunes:1.97 --- src/games/fortune/datfiles/fortunes:1.96 Mon Nov 9 03:23:14 2020 +++ src/games/fortune/datfiles/fortunes Sun Jul 11 00:35:05 2021 @@ -16307,3 +16307,5 @@ The purpose of computing numbers is not % Iamonthemoonandthereisnowheretogetabeer. Thereisnospacebar. +% +metropole, n.: The axis on which the subway turns.
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: nia Date: Fri Jun 4 11:18:31 UTC 2021 Modified Files: src/games/fortune/datfiles: netbsd-tips Log Message: SIGINFO is a useful tip To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/games/fortune/datfiles/netbsd-tips Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/netbsd-tips diff -u src/games/fortune/datfiles/netbsd-tips:1.9 src/games/fortune/datfiles/netbsd-tips:1.10 --- src/games/fortune/datfiles/netbsd-tips:1.9 Fri Jun 4 10:56:55 2021 +++ src/games/fortune/datfiles/netbsd-tips Fri Jun 4 11:18:31 2021 @@ -159,3 +159,6 @@ on its extension. For example, to extra You can use progress(1) to monitor the progress of data in a pipe: zcat example.tar.gz | progress tar xf - +% +Press CTRL+T to send SIGINFO and see the current status of the +command running in the current terminal.
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: nia Date: Fri Jun 4 10:56:55 UTC 2021 Modified Files: src/games/fortune/datfiles: netbsd-tips Log Message: add some tips To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/games/fortune/datfiles/netbsd-tips Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/netbsd-tips diff -u src/games/fortune/datfiles/netbsd-tips:1.8 src/games/fortune/datfiles/netbsd-tips:1.9 --- src/games/fortune/datfiles/netbsd-tips:1.8 Sun Jun 7 15:41:03 2020 +++ src/games/fortune/datfiles/netbsd-tips Fri Jun 4 10:56:55 2021 @@ -141,3 +141,21 @@ To do so: cd /usr/tests atf-run | atf-report % +To share files from your NetBSD system, you can use the built-in +httpd(8). Uncomment the 'http' lines in /etc/inetd.conf, reload inetd +with service(8), and then any files in /var/www will be published to +http://127.0.0.1/. +% +You can schedule simple periodic tasks for your NetBSD system to run +without using cron(8) by editing the sh(1) scripts /etc/daily.local, +/etc/weekly.local, and /etc/monthly.local. +% +NetBSD's tar(1) command can handle a wide range of file types, e.g. +zip, 7z, and rar, and will autodetect the type of the file based +on its extension. For example, to extract a zip file: + + tar xvf example.zip +% +You can use progress(1) to monitor the progress of data in a pipe: + + zcat example.tar.gz | progress tar xf -
CVS commit: src/games/cgram
Module Name:src Committed By: dholland Date: Fri May 28 03:55:46 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: I don't see any code I wrote left in here. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.24 src/games/cgram/cgram.c:1.25 --- src/games/cgram/cgram.c:1.24 Fri May 28 03:55:08 2021 +++ src/games/cgram/cgram.c Fri May 28 03:55:45 2021 @@ -1,11 +1,11 @@ -/* $NetBSD: cgram.c,v 1.24 2021/05/28 03:55:08 dholland Exp $ */ +/* $NetBSD: cgram.c,v 1.25 2021/05/28 03:55:45 dholland Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by David A. Holland and Roland Illig. + * by Roland Illig. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.24 2021/05/28 03:55:08 dholland Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.25 2021/05/28 03:55:45 dholland Exp $"); #endif #include
CVS commit: src/games/cgram
Module Name:src Committed By: dholland Date: Fri May 28 03:55:08 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: Restore return value of main, arbitrarily thrown away in -r1.4. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.23 src/games/cgram/cgram.c:1.24 --- src/games/cgram/cgram.c:1.23 Sat May 1 20:29:23 2021 +++ src/games/cgram/cgram.c Fri May 28 03:55:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.23 2021/05/01 20:29:23 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.24 2021/05/28 03:55:08 dholland Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.23 2021/05/01 20:29:23 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.24 2021/05/28 03:55:08 dholland Exp $"); #endif #include @@ -612,4 +612,5 @@ main(int argc, char *argv[]) init(argc > 1 ? argv[1] : NULL); loop(); done(); + return 0; }
CVS commit: src/games/snake/snscore
Module Name:src Committed By: kre Date: Wed May 12 15:26:44 UTC 2021 Modified Files: src/games/snake/snscore: snscore.c Log Message: Adapt to recent change to ../snake/pathnames.h To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/games/snake/snscore/snscore.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/snake/snscore/snscore.c diff -u src/games/snake/snscore/snscore.c:1.19 src/games/snake/snscore/snscore.c:1.20 --- src/games/snake/snscore/snscore.c:1.19 Tue Jun 19 05:46:09 2012 +++ src/games/snake/snscore/snscore.c Wed May 12 15:26:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: snscore.c,v 1.19 2012/06/19 05:46:09 dholland Exp $ */ +/* $NetBSD: snscore.c,v 1.20 2021/05/12 15:26:44 kre Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)snscore.c 8.1 (Berkeley) 7/19/93"; #else -__RCSID("$NetBSD: snscore.c,v 1.19 2012/06/19 05:46:09 dholland Exp $"); +__RCSID("$NetBSD: snscore.c,v 1.20 2021/05/12 15:26:44 kre Exp $"); #endif #endif /* not lint */ @@ -52,7 +52,7 @@ __RCSID("$NetBSD: snscore.c,v 1.19 2012/ #include #include "pathnames.h" -static const char *recfile = _PATH_RAWSCORES; +static const char *recfile = SNAKE_PATH_RAWSCORES; #define MAXPLAYERS 256 struct player {
CVS commit: src/games/snake/snake
Module Name:src Committed By: nia Date: Wed May 12 11:08:31 UTC 2021 Modified Files: src/games/snake/snake: pathnames.h snake.c Log Message: snake: Avoid creating definitions prefixed with _ inside a program To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/games/snake/snake/pathnames.h cvs rdiff -u -r1.30 -r1.31 src/games/snake/snake/snake.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/snake/snake/pathnames.h diff -u src/games/snake/snake/pathnames.h:1.4 src/games/snake/snake/pathnames.h:1.5 --- src/games/snake/snake/pathnames.h:1.4 Thu Aug 7 09:37:45 2003 +++ src/games/snake/snake/pathnames.h Wed May 12 11:08:31 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pathnames.h,v 1.4 2003/08/07 09:37:45 agc Exp $ */ +/* $NetBSD: pathnames.h,v 1.5 2021/05/12 11:08:31 nia Exp $ */ /* * Copyright (c) 1989, 1993 @@ -31,5 +31,5 @@ * @(#)pathnames.h 8.1 (Berkeley) 5/31/93 */ -#define _PATH_RAWSCORES "/var/games/snakerawscores" -#define _PATH_LOGFILE "/var/games/snake.log" +#define SNAKE_PATH_RAWSCORES "/var/games/snakerawscores" +#define SNAKE_PATH_LOGFILE "/var/games/snake.log" Index: src/games/snake/snake/snake.c diff -u src/games/snake/snake/snake.c:1.30 src/games/snake/snake/snake.c:1.31 --- src/games/snake/snake/snake.c:1.30 Thu May 14 08:34:18 2020 +++ src/games/snake/snake/snake.c Wed May 12 11:08:31 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: snake.c,v 1.30 2020/05/14 08:34:18 msaitoh Exp $ */ +/* $NetBSD: snake.c,v 1.31 2021/05/12 11:08:31 nia Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)snake.c 8.2 (Berkeley) 1/7/94"; #else -__RCSID("$NetBSD: snake.c,v 1.30 2020/05/14 08:34:18 msaitoh Exp $"); +__RCSID("$NetBSD: snake.c,v 1.31 2021/05/12 11:08:31 nia Exp $"); #endif #endif/* not lint */ @@ -143,15 +143,15 @@ main(int argc, char **argv) time_t tv; /* Open score files then revoke setgid privileges */ - rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664); + rawscores = open(SNAKE_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664); if (rawscores < 0) { - warn("open %s", _PATH_RAWSCORES); + warn("open %s", SNAKE_PATH_RAWSCORES); sleep(2); } else if (rawscores < 3) exit(1); - logfile = fopen(_PATH_LOGFILE, "a"); + logfile = fopen(SNAKE_PATH_LOGFILE, "a"); if (logfile == NULL) { - warn("fopen %s", _PATH_LOGFILE); + warn("fopen %s", SNAKE_PATH_LOGFILE); sleep(2); } setgid(getgid());
CVS commit: src/games/countmail
Module Name:src Committed By: rillig Date: Sun May 2 13:10:36 UTC 2021 Modified Files: src/games/countmail: countmail Log Message: countmail: remove outdated comments Using the shell builtin 'read' command was necessarily slow because it is specified to read a single byte at a time. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/games/countmail/countmail Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/countmail/countmail diff -u src/games/countmail/countmail:1.7 src/games/countmail/countmail:1.8 --- src/games/countmail/countmail:1.7 Mon Apr 28 20:22:53 2008 +++ src/games/countmail/countmail Sun May 2 13:10:36 2021 @@ -1,5 +1,5 @@ #!/bin/sh -# $NetBSD: countmail,v 1.7 2008/04/28 20:22:53 martin Exp $ +# $NetBSD: countmail,v 1.8 2021/05/02 13:10:36 rillig Exp $ # # Copyright (c) 1998, 2002 The NetBSD Foundation, Inc. @@ -30,29 +30,10 @@ # POSSIBILITY OF SUCH DAMAGE. # -# Count the messages in your mailbox, using only POSIX shell builtins. +# Count the messages in your mailbox. # -# Caveats: -# -# The read loop is horrendously slow on every implementation I've -# tried. I suggest using from(1) and wc(1) instead, though these are -# not shell builtins. - -# for krb. -#set -- `from -t` -#v=$3 -set -- `from 2>/dev/null |wc -l` +set -- `from 2>/dev/null | wc -l` v=$1 -#v=`from | wc -l` - -#v=0 -#exec 0
CVS commit: src/games/fish
Module Name:src Committed By: rillig Date: Sun May 2 12:25:56 UTC 2021 Modified Files: src/games/fish: fish.c Log Message: fish: remove trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/games/fish/fish.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fish/fish.c diff -u src/games/fish/fish.c:1.25 src/games/fish/fish.c:1.26 --- src/games/fish/fish.c:1.25 Sun May 2 12:24:59 2021 +++ src/games/fish/fish.c Sun May 2 12:25:55 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fish.c,v 1.25 2021/05/02 12:24:59 rillig Exp $ */ +/* $NetBSD: fish.c,v 1.26 2021/05/02 12:25:55 rillig Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19 #if 0 static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: fish.c,v 1.25 2021/05/02 12:24:59 rillig Exp $"); +__RCSID("$NetBSD: fish.c,v 1.26 2021/05/02 12:25:55 rillig Exp $"); #endif #endif /* not lint */ @@ -120,7 +120,7 @@ main(int argc, char **argv) } printplayer(USER); (void)printf("get to start.\n"); - + for (;;) { move = usermove(); if (!comphand[move]) { @@ -243,12 +243,12 @@ promove(void) max = i; break; } - while (++i < RANKS) + while (++i < RANKS) if (comphand[i] != CARDS && comphand[i] > comphand[max]) max = i; return(max); - } + } if (arc4random_uniform(1024) == 0723) { for (i = 0; i < RANKS; ++i) if (userhand[i] && comphand[i]) @@ -369,7 +369,7 @@ printhand(const int *hand) for (book = i = 0; i < RANKS; i++) if (hand[i] < CARDS) - for (j = hand[i]; --j >= 0;) + for (j = hand[i]; --j >= 0;) PRC(i); else ++book;
CVS commit: src/games/fish
Module Name:src Committed By: rillig Date: Sun May 2 12:24:59 UTC 2021 Modified Files: src/games/fish: fish.c Log Message: fish: use arc4random_uniform for drawing random numbers Thanks nia@ for the hint. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/games/fish/fish.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fish/fish.c diff -u src/games/fish/fish.c:1.24 src/games/fish/fish.c:1.25 --- src/games/fish/fish.c:1.24 Sat May 1 21:10:57 2021 +++ src/games/fish/fish.c Sun May 2 12:24:59 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fish.c,v 1.24 2021/05/01 21:10:57 rillig Exp $ */ +/* $NetBSD: fish.c,v 1.25 2021/05/02 12:24:59 rillig Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19 #if 0 static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: fish.c,v 1.24 2021/05/01 21:10:57 rillig Exp $"); +__RCSID("$NetBSD: fish.c,v 1.25 2021/05/02 12:24:59 rillig Exp $"); #endif #endif /* not lint */ @@ -54,7 +54,6 @@ __RCSID("$NetBSD: fish.c,v 1.24 2021/05/ #include #include #include -#include #include #include "pathnames.h" @@ -87,7 +86,6 @@ static int gofish(int, int, int *); static void goodmove(int, int, int *, int *); static void init(void); static void instructions(void); -static int nrandom(int); static void printhand(const int *); static void printplayer(int); static int promove(void); @@ -112,11 +110,10 @@ main(int argc, char **argv) usage(); } - srandom(time(NULL)); instructions(); init(); - if (nrandom(2) == 1) { + if (arc4random_uniform(2) == 1) { printplayer(COMPUTER); (void)printf("get to start.\n"); goto istart; @@ -200,11 +197,11 @@ usermove(void) continue; } - if (nrandom(3) == 1) + if (arc4random_uniform(3) == 1) (void)printf("You don't have any of those!\n"); else (void)printf("You don't have any %s's!\n", cards[n]); - if (nrandom(4) == 1) + if (arc4random_uniform(4) == 1) (void)printf("No cheating!\n"); (void)printf("Guess again.\n"); } @@ -240,7 +237,7 @@ promove(void) userasked[i] = 0; return(i); } - if (nrandom(3) == 1) { + if (arc4random_uniform(3) == 1) { for (i = 0;; ++i) if (comphand[i] && comphand[i] != CARDS) { max = i; @@ -252,7 +249,7 @@ promove(void) max = i; return(max); } - if (nrandom(1024) == 0723) { + if (arc4random_uniform(1024) == 0723) { for (i = 0; i < RANKS; ++i) if (userhand[i] && comphand[i]) return(i); @@ -341,11 +338,11 @@ chkwinner(int player, const int *hand) (void)printf("\nI have %d, you have %d.\n", cb, ub); if (ub > cb) { (void)printf("\nYou win!!!\n"); - if (nrandom(1024) == 0723) + if (arc4random_uniform(1024) == 0723) (void)printf("Cheater, cheater, pumpkin eater!\n"); } else if (cb > ub) { (void)printf("\nI win!!!\n"); - if (nrandom(1024) == 0723) + if (arc4random_uniform(1024) == 0723) (void)printf("Hah! Stupid peasant!\n"); } else (void)printf("\nTie!\n"); @@ -419,7 +416,7 @@ init(void) for (i = 0; i < TOTCARDS; ++i) deck[i] = i % RANKS; for (i = 0; i < TOTCARDS - 1; ++i) { - j = nrandom(TOTCARDS-i); + j = arc4random_uniform(TOTCARDS-i); if (j == 0) continue; temp = deck[i]; @@ -432,18 +429,6 @@ init(void) } } -static int -nrandom(int n) -{ - long r; - - for (;;) { - r = random(); - if (r < RANDOM_MAX - RANDOM_MAX % n) - return (int)(r % n); - } -} - static void instructions(void) {
CVS commit: src/games/fish
Module Name:src Committed By: rillig Date: Sat May 1 21:10:57 UTC 2021 Modified Files: src/games/fish: fish.c Log Message: fish: remove modulo bias from random number generation It probably doesn't matter in practice, but omitting this piece of code always looks like an oversight. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/games/fish/fish.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fish/fish.c diff -u src/games/fish/fish.c:1.23 src/games/fish/fish.c:1.24 --- src/games/fish/fish.c:1.23 Mon Mar 5 04:59:54 2018 +++ src/games/fish/fish.c Sat May 1 21:10:57 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fish.c,v 1.23 2018/03/05 04:59:54 eadler Exp $ */ +/* $NetBSD: fish.c,v 1.24 2021/05/01 21:10:57 rillig Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19 #if 0 static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: fish.c,v 1.23 2018/03/05 04:59:54 eadler Exp $"); +__RCSID("$NetBSD: fish.c,v 1.24 2021/05/01 21:10:57 rillig Exp $"); #endif #endif /* not lint */ @@ -435,8 +435,13 @@ init(void) static int nrandom(int n) { + long r; - return((int)random() % n); + for (;;) { + r = random(); + if (r < RANDOM_MAX - RANDOM_MAX % n) + return (int)(r % n); + } } static void
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sat May 1 20:29:23 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: rename local functions The word 'cleanup' should have been named clean_up all along, but 'done' is even shorter. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.22 src/games/cgram/cgram.c:1.23 --- src/games/cgram/cgram.c:1.22 Thu Apr 29 20:17:20 2021 +++ src/games/cgram/cgram.c Sat May 1 20:29:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.22 2021/04/29 20:17:20 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.23 2021/05/01 20:29:23 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.22 2021/04/29 20:17:20 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.23 2021/05/01 20:29:23 rillig Exp $"); #endif #include @@ -143,7 +143,7 @@ stringarray_init(struct stringarray *a) } static void -stringarray_cleanup(struct stringarray *a) +stringarray_done(struct stringarray *a) { for (size_t i = 0; i < a->num; i++) free(a->v[i].s); @@ -584,12 +584,12 @@ loop(void) } static void -clean_up(void) +done(void) { endwin(); - stringarray_cleanup(); - stringarray_cleanup(); + stringarray_done(); + stringarray_done(); } @@ -611,5 +611,5 @@ main(int argc, char *argv[]) init(argc > 1 ? argv[1] : NULL); loop(); - clean_up(); + done(); }
CVS commit: src/games/caesar
Module Name:src Committed By: rillig Date: Sat May 1 20:21:25 UTC 2021 Modified Files: src/games/caesar: Makefile caesar.c Log Message: caesar: WARNS=6, strict bool mode The rotation is validated to be nonnegative, therefore use unsigned int for it. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/games/caesar/Makefile cvs rdiff -u -r1.22 -r1.23 src/games/caesar/caesar.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/caesar/Makefile diff -u src/games/caesar/Makefile:1.8 src/games/caesar/Makefile:1.9 --- src/games/caesar/Makefile:1.8 Mon Jan 28 07:03:59 2008 +++ src/games/caesar/Makefile Sat May 1 20:21:25 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.8 2008/01/28 07:03:59 dholland Exp $ +# $NetBSD: Makefile,v 1.9 2021/05/01 20:21:25 rillig Exp $ # @(#)Makefile 8.1 (Berkeley) 5/31/93 PROG= caesar @@ -8,4 +8,7 @@ LDADD= -lm MLINKS= caesar.6 rot13.6 SCRIPTS=rot13.sh +WARNS= 6 +LINTFLAGS+= -T + .include Index: src/games/caesar/caesar.c diff -u src/games/caesar/caesar.c:1.22 src/games/caesar/caesar.c:1.23 --- src/games/caesar/caesar.c:1.22 Sun Jul 20 01:03:21 2008 +++ src/games/caesar/caesar.c Sat May 1 20:21:25 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: caesar.c,v 1.22 2008/07/20 01:03:21 lukem Exp $ */ +/* $NetBSD: caesar.c,v 1.23 2021/05/01 20:21:25 rillig Exp $ */ /* * Copyright (c) 1989, 1993 @@ -48,7 +48,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 #if 0 static char sccsid[] = "@(#)caesar.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: caesar.c,v 1.22 2008/07/20 01:03:21 lukem Exp $"); +__RCSID("$NetBSD: caesar.c,v 1.23 2021/05/01 20:21:25 rillig Exp $"); #endif #endif /* not lint */ @@ -79,7 +79,7 @@ static unsigned char rottbl[NCHARS]; static void -init_rottbl(int rot) +init_rottbl(unsigned int rot) { size_t i; @@ -121,7 +121,7 @@ print_array(const unsigned char *a, size } } -static int +static unsigned int get_rotation(const char *arg) { long rot; @@ -135,7 +135,7 @@ get_rotation(const char *arg) errno = ERANGE; if (errno) err(EXIT_FAILURE, "Bad rotation value `%s'", arg); - return (int)rot; + return (unsigned int)rot; } static void @@ -145,7 +145,7 @@ guess_and_rotate(void) unsigned int obs[NCHARS]; size_t i, nread; double dot, winnerdot; - int try, winner; + unsigned int try, winner; int ch; /* adjust frequency table to weight low probs REAL low */
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Thu Apr 29 20:17:20 UTC 2021 Modified Files: src/games/cgram: cgram.6 cgram.c Log Message: cgram: in hinting mode, show all correct characters in bold face For almost solved cryptograms, this makes the punctuation stand out less, helping to focus on the missing letters. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/games/cgram/cgram.6 cvs rdiff -u -r1.21 -r1.22 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.6 diff -u src/games/cgram/cgram.6:1.3 src/games/cgram/cgram.6:1.4 --- src/games/cgram/cgram.6:1.3 Thu Apr 22 14:57:36 2021 +++ src/games/cgram/cgram.6 Thu Apr 29 20:17:20 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: cgram.6,v 1.3 2021/04/22 14:57:36 wiz Exp $ +.\" $NetBSD: cgram.6,v 1.4 2021/04/29 20:17:20 rillig Exp $ .\" .\" Copyright (c) 2004, 2013 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 22, 2021 +.Dd April 29, 2021 .Dt CGRAM 6 .Os .Sh NAME @@ -55,7 +55,7 @@ Enter a tilde to quit. Press asterisk .Pq * -to enter an easier mode where correct letters are displayed in +to enter an easier mode where correct characters are displayed in boldface. .Sh SEE ALSO .Xr caesar 6 Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.21 src/games/cgram/cgram.c:1.22 --- src/games/cgram/cgram.c:1.21 Sun Apr 25 20:38:03 2021 +++ src/games/cgram/cgram.c Thu Apr 29 20:17:20 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.21 2021/04/25 20:38:03 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.22 2021/04/29 20:17:20 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.21 2021/04/25 20:38:03 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.22 2021/04/29 20:17:20 rillig Exp $"); #endif #include @@ -348,8 +348,7 @@ redraw(void) for (int x = 0; x < max_x; x++) { char ch = line[offset_x + x]; bool bold = hinting && - ch == solline[offset_x + x] && - ch_isalpha(ch); + (ch == solline[offset_x + x] || !ch_isalpha(ch)); if (bold) attron(A_BOLD);
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Apr 25 20:38:03 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: use ASCII-only implementation of functions The function 'encode' already assumes that all letter characters are contiguous and that there are only 26 letters of each case. At the moment, cgram cannot handle UTF-8 anyway since it reads the input byte-wise, assuming that each byte is exacty one character. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.20 src/games/cgram/cgram.c:1.21 --- src/games/cgram/cgram.c:1.20 Sun Apr 25 20:19:19 2021 +++ src/games/cgram/cgram.c Sun Apr 25 20:38:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.20 2021/04/25 20:19:19 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.21 2021/04/25 20:38:03 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.20 2021/04/25 20:19:19 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.21 2021/04/25 20:38:03 rillig Exp $"); #endif #include @@ -46,42 +46,41 @@ __RCSID("$NetBSD: cgram.c,v 1.20 2021/04 #include "pathnames.h" - -static char -ch_toupper(char ch) +static bool +ch_isspace(char ch) { - return (char)toupper((unsigned char)ch); + return isspace((unsigned char)ch) != 0; } -static char -ch_tolower(char ch) +static bool +ch_islower(char ch) { - return (char)tolower((unsigned char)ch); + return ch >= 'a' && ch <= 'z'; } static bool -ch_isalpha(char ch) +ch_isupper(char ch) { - return isalpha((unsigned char)ch) != 0; + return ch >= 'A' && ch <= 'Z'; } static bool -ch_islower(char ch) +ch_isalpha(char ch) { - return islower((unsigned char)ch) != 0; + return ch_islower(ch) || ch_isupper(ch); } -static bool -ch_isspace(char ch) +static char +ch_toupper(char ch) { - return isspace((unsigned char)ch) != 0; + return ch_islower(ch) ? (char)(ch - 'a' + 'A') : ch; } -static bool -ch_isupper(char ch) +static char +ch_tolower(char ch) { - return isupper((unsigned char)ch) != 0; + return ch_isupper(ch) ? (char)(ch - 'A' + 'a') : ch; } static int
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Apr 25 20:19:19 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: provide usage on incorrect invocation To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.19 src/games/cgram/cgram.c:1.20 --- src/games/cgram/cgram.c:1.19 Sun Apr 25 20:14:29 2021 +++ src/games/cgram/cgram.c Sun Apr 25 20:19:19 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.19 2021/04/25 20:14:29 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.20 2021/04/25 20:19:19 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.19 2021/04/25 20:14:29 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.20 2021/04/25 20:19:19 rillig Exp $"); #endif #include @@ -594,11 +594,23 @@ clean_up(void) stringarray_cleanup(); } - + +static void __dead +usage(void) +{ + + fprintf(stderr, "usage: %s [file]\n", getprogname()); + exit(1); +} int main(int argc, char *argv[]) { + + setprogname(argv[0]); + if (argc != 1 && argc != 2) + usage(); + init(argc > 1 ? argv[1] : NULL); loop(); clean_up();
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Apr 25 20:14:29 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: conform to lint's strict bool mode, KNF To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.18 src/games/cgram/cgram.c:1.19 --- src/games/cgram/cgram.c:1.18 Thu Apr 22 14:57:36 2021 +++ src/games/cgram/cgram.c Sun Apr 25 20:14:29 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.18 2021/04/22 14:57:36 wiz Exp $ */ +/* $NetBSD: cgram.c,v 1.19 2021/04/25 20:14:29 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.18 2021/04/22 14:57:36 wiz Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.19 2021/04/25 20:14:29 rillig Exp $"); #endif #include @@ -216,7 +216,9 @@ char_at_cursor(void) return lines.v[cursor_y].s[cursor_x]; } -static void getquote(FILE *f) { +static void +getquote(FILE *f) +{ struct string line; string_init(); @@ -255,7 +257,7 @@ readfile(const char *name) getquote(f); if (fclose(f) != 0) - exit(1); + err(1, "%s", name); } @@ -558,7 +560,7 @@ init(const char *filename) stringarray_init(); stringarray_init(); srandom((unsigned int)time(NULL)); - if (filename) { + if (filename != NULL) { readfile(filename); } else { readquote();
CVS commit: src/games/cgram
Module Name:src Committed By: wiz Date: Thu Apr 22 14:57:36 UTC 2021 Modified Files: src/games/cgram: cgram.6 cgram.c Log Message: cgram: allow providing an input file instead of the random fortune To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/games/cgram/cgram.6 cvs rdiff -u -r1.17 -r1.18 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.6 diff -u src/games/cgram/cgram.6:1.2 src/games/cgram/cgram.6:1.3 --- src/games/cgram/cgram.6:1.2 Sun Aug 4 07:55:09 2013 +++ src/games/cgram/cgram.6 Thu Apr 22 14:57:36 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: cgram.6,v 1.2 2013/08/04 07:55:09 wiz Exp $ +.\" $NetBSD: cgram.6,v 1.3 2021/04/22 14:57:36 wiz Exp $ .\" .\" Copyright (c) 2004, 2013 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,21 +27,24 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd August 3, 2013 +.Dd April 22, 2021 .Dt CGRAM 6 .Os .Sh NAME .Nm cgram .Nd solve Sunday-paper cryptograms .Sh SYNOPSIS -.Nm +.Nm Op Ar file .Sh DESCRIPTION .Nm is a curses-based widget for solving Sunday-paper-type cryptograms based on substitution ciphers. -A random cleartext is chosen using -.Xr fortune 6 -and a random substitution key is generated. +If +.Ar file +is given, it is used as cleartext, otherwise a random cleartext is +chosen using +.Xr fortune 6 ; +either way, a random substitution key is generated. .Pp The ciphertext is displayed. Typing a letter changes the key so that the letter under the cursor Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.17 src/games/cgram/cgram.c:1.18 --- src/games/cgram/cgram.c:1.17 Fri Feb 26 15:18:40 2021 +++ src/games/cgram/cgram.c Thu Apr 22 14:57:36 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.17 2021/02/26 15:18:40 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.18 2021/04/22 14:57:36 wiz Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.17 2021/02/26 15:18:40 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.18 2021/04/22 14:57:36 wiz Exp $"); #endif #include @@ -216,13 +216,7 @@ char_at_cursor(void) return lines.v[cursor_y].s[cursor_x]; } -static void -readquote(void) -{ - FILE *f = popen(_PATH_FORTUNE, "r"); - if (f == NULL) - err(1, "%s", _PATH_FORTUNE); - +static void getquote(FILE *f) { struct string line; string_init(); @@ -249,6 +243,30 @@ readquote(void) extent_y = (int)lines.num; for (int i = 0; i < extent_y; i++) extent_x = imax(extent_x, (int)lines.v[i].len); +} + +static void +readfile(const char *name) +{ + FILE *f = fopen(name, "r"); + if (f == NULL) + err(1, "%s", name); + + getquote(f); + + if (fclose(f) != 0) + exit(1); +} + + +static void +readquote(void) +{ + FILE *f = popen(_PATH_FORTUNE, "r"); + if (f == NULL) + err(1, "%s", _PATH_FORTUNE); + + getquote(f); if (pclose(f) != 0) exit(1); /* error message must come from child process */ @@ -535,12 +553,16 @@ handle_key(void) } static void -init(void) +init(const char *filename) { stringarray_init(); stringarray_init(); srandom((unsigned int)time(NULL)); - readquote(); + if (filename) { + readfile(filename); + } else { + readquote(); + } encode(); initscr(); @@ -573,9 +595,9 @@ clean_up(void) int -main(void) +main(int argc, char *argv[]) { - init(); + init(argc > 1 ? argv[1] : NULL); loop(); clean_up(); }
CVS commit: src/games/hunt/huntd
Module Name:src Committed By: mrg Date: Thu Apr 15 01:55:21 UTC 2021 Modified Files: src/games/hunt/huntd: Makefile Log Message: one port complains about string overflow here that i can't see. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/games/hunt/huntd/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/hunt/huntd/Makefile diff -u src/games/hunt/huntd/Makefile:1.9 src/games/hunt/huntd/Makefile:1.10 --- src/games/hunt/huntd/Makefile:1.9 Mon Apr 12 02:54:08 2021 +++ src/games/hunt/huntd/Makefile Thu Apr 15 01:55:21 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.9 2021/04/12 02:54:08 mrg Exp $ +# $NetBSD: Makefile,v 1.10 2021/04/15 01:55:21 mrg Exp $ PROG= huntd SRCS= answer.c draw.c driver.c execute.c expl.c \ @@ -12,5 +12,6 @@ CPPFLAGS+=-I${.CURDIR}/../include # Appears wrong - should not exceed bounds of array. COPTS.answer.c+= ${GCC_NO_STRINGOP_OVERFLOW} COPTS.shots.c+= ${GCC_NO_STRINGOP_OVERFLOW} +COPTS.driver.c+= ${GCC_NO_STRINGOP_OVERFLOW} .include
CVS commit: src/games/warp
Module Name:src Committed By: mrg Date: Tue Apr 13 08:06:38 UTC 2021 Modified Files: src/games/warp: term.h Log Message: avoid duplicating symbols in libterminfo. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/games/warp/term.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/term.h diff -u src/games/warp/term.h:1.5 src/games/warp/term.h:1.6 --- src/games/warp/term.h:1.5 Wed Nov 11 17:11:19 2020 +++ src/games/warp/term.h Tue Apr 13 08:06:38 2021 @@ -252,8 +252,10 @@ EXT bool bizarre INIT(false); /* do we */ #ifdef HAVETERMLIB +#if 0 EXT char *BC INIT(NULL); /* backspace character */ EXT char *UP INIT(NULL); /* move cursor up one line */ +#endif EXT char *myUP; EXT char *ND INIT(NULL); /* non-destructive cursor right */ EXT char *myND; @@ -275,8 +277,10 @@ EXT char *UC INIT(NULL); /* underline a EXT int UG INIT(0); /* blanks left by US and UE */ EXT bool AM INIT(false); /* does terminal have automatic margins? */ EXT bool XN INIT(false); /* does it eat 1st newline after automatic wrap? */ +#if 0 EXT char PC INIT(0); /* pad character for use by tputs() */ EXT short ospeed INIT(0); /* terminal output speed, for use by tputs() */ +#endif EXT int LINES INIT(0), COLS INIT(0); /* size of screen */ EXT int just_a_sec INIT(960); /* 1 sec at current baud rate */ /* (number of nulls) */
CVS commit: src/games/backgammon/common_source
Module Name:src Committed By: mrg Date: Tue Apr 13 02:11:40 UTC 2021 Modified Files: src/games/backgammon/common_source: Makefile fancy.c Log Message: no longer need -Wno-error=implicit-fallthrough. don't provide common symbols that are in libterminfo now days. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/games/backgammon/common_source/Makefile cvs rdiff -u -r1.15 -r1.16 src/games/backgammon/common_source/fancy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/backgammon/common_source/Makefile diff -u src/games/backgammon/common_source/Makefile:1.11 src/games/backgammon/common_source/Makefile:1.12 --- src/games/backgammon/common_source/Makefile:1.11 Sun Sep 29 23:44:59 2019 +++ src/games/backgammon/common_source/Makefile Tue Apr 13 02:11:39 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.11 2019/09/29 23:44:59 mrg Exp $ +# $NetBSD: Makefile,v 1.12 2021/04/13 02:11:39 mrg Exp $ LIBISPRIVATE= yes @@ -6,11 +6,4 @@ LIB= common SRCS= allow.c board.c check.c fancy.c init.c odds.c \ one.c save.c subs.c table.c -.include - -# Has fallthru comment that is missed -.if defined(HAVE_GCC) && ${HAVE_GCC} >= 7 && ${ACTIVE_CC} == "gcc" -COPTS.check.c+= -Wno-error=implicit-fallthrough -.endif - .include Index: src/games/backgammon/common_source/fancy.c diff -u src/games/backgammon/common_source/fancy.c:1.15 src/games/backgammon/common_source/fancy.c:1.16 --- src/games/backgammon/common_source/fancy.c:1.15 Wed Apr 22 23:36:26 2020 +++ src/games/backgammon/common_source/fancy.c Tue Apr 13 02:11:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fancy.c,v 1.15 2020/04/22 23:36:26 joerg Exp $ */ +/* $NetBSD: fancy.c,v 1.16 2021/04/13 02:11:39 mrg Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)fancy.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: fancy.c,v 1.15 2020/04/22 23:36:26 joerg Exp $"); +__RCSID("$NetBSD: fancy.c,v 1.16 2021/04/13 02:11:39 mrg Exp $"); #endif #endif /* not lint */ @@ -52,8 +52,10 @@ static void newline(void); * * XXX: rewrite this crap using curses. */ +#if 0 charPC; /* padding character */ char *BC; /* backspace sequence */ +#endif char *CD; /* clear to end of screen sequence */ char *CE; /* clear to end of line sequence */ char *CL; /* clear screen sequence */ @@ -62,7 +64,9 @@ char *HO; /* home cursor sequence */ char *MC; /* column cursor movement map */ char *ML; /* row cursor movement map */ char *ND; /* forward cursor sequence */ +#if 0 char *UP; /* up cursor sequence */ +#endif static int lHO; /* length of HO */ static int lBC; /* length of BC */
CVS commit: src/games/robots
Module Name:src Committed By: mrg Date: Tue Apr 13 01:50:46 UTC 2021 Modified Files: src/games/robots: score.c Log Message: properly terminate after using strncpy(). To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/games/robots/score.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/robots/score.c diff -u src/games/robots/score.c:1.23 src/games/robots/score.c:1.24 --- src/games/robots/score.c:1.23 Wed Aug 12 08:30:55 2009 +++ src/games/robots/score.c Tue Apr 13 01:50:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: score.c,v 1.23 2009/08/12 08:30:55 dholland Exp $ */ +/* $NetBSD: score.c,v 1.24 2021/04/13 01:50:46 mrg Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: score.c,v 1.23 2009/08/12 08:30:55 dholland Exp $"); +__RCSID("$NetBSD: score.c,v 1.24 2021/04/13 01:50:46 mrg Exp $"); #endif #endif /* not lint */ @@ -198,9 +198,10 @@ set_name(SCORE *scp) struct passwd *pp; if ((pp = getpwuid(scp->s_uid)) == NULL) - strncpy(scp->s_name, "???", MAXNAME); + strncpy(scp->s_name, "???", MAXNAME - 1); else - strncpy(scp->s_name, pp->pw_name, MAXNAME); + strncpy(scp->s_name, pp->pw_name, MAXNAME - 1); + scp->s_name[MAXNAME - 1] = '\0'; } /*
CVS commit: src/games/adventure
Module Name:src Committed By: mrg Date: Mon Apr 12 09:12:28 UTC 2021 Modified Files: src/games/adventure: save.c Log Message: avoid leaving off the trailing nul in a literal string. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/games/adventure/save.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/adventure/save.c diff -u src/games/adventure/save.c:1.14 src/games/adventure/save.c:1.15 --- src/games/adventure/save.c:1.14 Sat Mar 22 22:04:40 2014 +++ src/games/adventure/save.c Mon Apr 12 09:12:28 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: save.c,v 1.14 2014/03/22 22:04:40 dholland Exp $ */ +/* $NetBSD: save.c,v 1.15 2021/04/12 09:12:28 mrg Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: save.c,v 1.14 2014/03/22 22:04:40 dholland Exp $"); +__RCSID("$NetBSD: save.c,v 1.15 2021/04/12 09:12:28 mrg Exp $"); #endif #endif/* not lint */ @@ -77,7 +77,7 @@ static const char header[] = "Adventure * Map 16 plain values into 90 coded values and back. */ -static const char coding[90] = +static const char coding[91] = "Db.GOyT]7a6zpF(c*5H9oK~0[WVAg)ml,2^q-1Y3v+" "X/=JirZL$C>_N?:}B{dfnsxU<@MQ%8|P!4h`ESt;euwIj" ;
CVS commit: src/games/factor
Module Name:src Committed By: mrg Date: Mon Apr 12 04:19:32 UTC 2021 Modified Files: src/games/factor: Makefile Log Message: include bsd.own.mk to be sure NETBSDSRCDIR is set. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/games/factor/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/Makefile diff -u src/games/factor/Makefile:1.13 src/games/factor/Makefile:1.14 --- src/games/factor/Makefile:1.13 Sun May 21 15:28:41 2017 +++ src/games/factor/Makefile Mon Apr 12 04:19:32 2021 @@ -1,6 +1,8 @@ -# $NetBSD: Makefile,v 1.13 2017/05/21 15:28:41 riastradh Exp $ +# $NetBSD: Makefile,v 1.14 2021/04/12 04:19:32 mrg Exp $ # @(#)Makefile 8.1 (Berkeley) 5/31/93 +.include + PRIMES= ${NETBSDSRCDIR}/games/primes PROG= factor
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Fri Feb 26 15:18:40 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: don't beep if the window is resized To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.16 src/games/cgram/cgram.c:1.17 --- src/games/cgram/cgram.c:1.16 Fri Feb 26 15:15:34 2021 +++ src/games/cgram/cgram.c Fri Feb 26 15:18:40 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.16 2021/02/26 15:15:34 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.17 2021/02/26 15:18:40 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.16 2021/02/26 15:15:34 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.17 2021/02/26 15:18:40 rillig Exp $"); #endif #include @@ -525,6 +525,8 @@ handle_key(void) break; case '~': return false; + case KEY_RESIZE: + break; default: handle_char_input(ch); break;
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Fri Feb 26 15:15:34 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: place the 'solved' marker nearer to the text This way, it cannot be overlooked as easily as before. It also doesn't change the position of the keyboard help text anymore. Only if there is not enough space, the 'solved' marker is put into the bottom line. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.15 src/games/cgram/cgram.c:1.16 --- src/games/cgram/cgram.c:1.15 Fri Feb 26 14:55:37 2021 +++ src/games/cgram/cgram.c Fri Feb 26 15:15:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.15 2021/02/26 14:55:37 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.16 2021/02/26 15:15:34 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.15 2021/02/26 14:55:37 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.16 2021/02/26 15:15:34 rillig Exp $"); #endif #include @@ -342,13 +342,17 @@ redraw(void) } move(LINES - 1, 0); + addstr("~ to quit, * to cheat, ^pnfb to move"); + if (is_solved()) { + if (extent_y + 1 - offset_y < LINES - 2) + move(extent_y + 1 - offset_y, 0); + else + addch(' '); attron(A_BOLD | A_STANDOUT); addstr("*solved*"); attroff(A_BOLD | A_STANDOUT); - addch(' '); } - addstr("~ to quit, * to cheat, ^pnfb to move"); move(cursor_y - offset_y, cursor_x - offset_x);
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Fri Feb 26 14:55:37 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: make the 'solved' stand out more Suggested by Weitian LI via [1]. [1] https://github.com/NetBSD/src/commit/efec6410b2b5a736 To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.14 src/games/cgram/cgram.c:1.15 --- src/games/cgram/cgram.c:1.14 Mon Feb 22 19:34:07 2021 +++ src/games/cgram/cgram.c Fri Feb 26 14:55:37 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.14 2021/02/22 19:34:07 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.15 2021/02/26 14:55:37 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.14 2021/02/22 19:34:07 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.15 2021/02/26 14:55:37 rillig Exp $"); #endif #include @@ -342,8 +342,12 @@ redraw(void) } move(LINES - 1, 0); - if (is_solved()) - addstr("*solved* "); + if (is_solved()) { + attron(A_BOLD | A_STANDOUT); + addstr("*solved*"); + attroff(A_BOLD | A_STANDOUT); + addch(' '); + } addstr("~ to quit, * to cheat, ^pnfb to move"); move(cursor_y - offset_y, cursor_x - offset_x);
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Mon Feb 22 19:34:07 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: fix assertion when substituting at the end of the longest line Reported by Weitian LI via GitHub. Contrary to the patch suggested in [1], still allow the cursor to be placed to the very right of the text in a line since that is the usual behavior of text editors. Split the function substitute() into two parts: one that handles the curses-specific part of checking whether a substitution is possible at the current cursor position, and one that performs the actual substitution. Only the latter is kept in the code section for the string manipulation functions, the other is moved to the section for curses code. Having all the curses code in one place reduces the places that call beep(). Previously, as well as now, there is a single beep per invalid key before, but that was not obvious from the previous code. [1]: https://github.com/DragonFlyBSD/DragonFlyBSD/commit/18d09f18cf4c To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.13 src/games/cgram/cgram.c:1.14 --- src/games/cgram/cgram.c:1.13 Mon Feb 22 17:36:42 2021 +++ src/games/cgram/cgram.c Mon Feb 22 19:34:07 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.13 2021/02/22 17:36:42 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.14 2021/02/22 19:34:07 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.13 2021/02/22 17:36:42 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.14 2021/02/22 19:34:07 rillig Exp $"); #endif #include @@ -279,40 +279,26 @@ encode(void) } } -static bool -substitute(char ch) +static void +substitute(char a, char b) { - assert(cursor_x >= 0 && cursor_x < extent_x); - assert(cursor_y >= 0 && cursor_y < extent_y); - if (cursor_x >= cur_max_x()) { - beep(); - return false; - } - - char och = char_at_cursor(); - if (!ch_isalpha(och)) { - beep(); - return false; - } - - char loch = ch_tolower(och); - char uoch = ch_toupper(och); - char lch = ch_tolower(ch); - char uch = ch_toupper(ch); + char la = ch_tolower(a); + char ua = ch_toupper(a); + char lb = ch_tolower(b); + char ub = ch_toupper(b); for (int y = 0; y < (int)lines.num; y++) { for (char *p = lines.v[y].s; *p != '\0'; p++) { - if (*p == loch) -*p = lch; - else if (*p == uoch) -*p = uch; - else if (*p == lch) -*p = loch; - else if (*p == uch) -*p = uoch; + if (*p == la) +*p = lb; + else if (*p == ua) +*p = ub; + else if (*p == lb) +*p = la; + else if (*p == ub) +*p = ua; } } - return true; } static bool @@ -457,19 +443,24 @@ go_to_next_word(void) go_right(); } +static bool +can_substitute_here(int ch) +{ + return isascii(ch) && + ch_isalpha((char)ch) && + cursor_x < cur_max_x() && + ch_isalpha(char_at_cursor()); +} + static void handle_char_input(int ch) { - if (isascii(ch) && ch_isalpha((char)ch)) { - if (substitute((char)ch)) { - if (cursor_x < cur_max_x()) -cursor_x++; - if (cursor_x == cur_max_x()) -go_to_next_line(); - } - } else if (ch == char_at_cursor()) + if (ch == char_at_cursor()) + go_right(); + else if (can_substitute_here(ch)) { + substitute(char_at_cursor(), (char)ch); go_right(); - else + } else beep(); }
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Mon Feb 22 17:36:42 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: add advanced cursor movement with tab, shift+tab, return To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.12 src/games/cgram/cgram.c:1.13 --- src/games/cgram/cgram.c:1.12 Mon Feb 22 16:28:20 2021 +++ src/games/cgram/cgram.c Mon Feb 22 17:36:42 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.12 2021/02/22 16:28:20 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.13 2021/02/22 17:36:42 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.12 2021/02/22 16:28:20 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.13 2021/02/22 17:36:42 rillig Exp $"); #endif #include @@ -73,6 +73,12 @@ ch_islower(char ch) } static bool +ch_isspace(char ch) +{ + return isspace((unsigned char)ch) != 0; +} + +static bool ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; @@ -193,6 +199,23 @@ cur_max_y(void) return extent_y - 1; } +static char +char_left_of_cursor(void) +{ + if (cursor_x > 0) + return lines.v[cursor_y].s[cursor_x - 1]; + assert(cursor_y > 0); + return '\n'; /* eol of previous line */ +} + +static char +char_at_cursor(void) +{ + if (cursor_x == cur_max_x()) + return '\n'; + return lines.v[cursor_y].s[cursor_x]; +} + static void readquote(void) { @@ -266,7 +289,7 @@ substitute(char ch) return false; } - char och = lines.v[cursor_y].s[cursor_x]; + char och = char_at_cursor(); if (!ch_isalpha(och)) { beep(); return false; @@ -292,8 +315,6 @@ substitute(char ch) return true; } - - static bool is_solved(void) { @@ -303,6 +324,8 @@ is_solved(void) return true; } + + static void redraw(void) { @@ -342,21 +365,6 @@ redraw(void) refresh(); } -static void -opencurses(void) -{ - initscr(); - cbreak(); - noecho(); - keypad(stdscr, true); -} - -static void -closecurses(void) -{ - endwin(); -} - static void @@ -383,6 +391,72 @@ scroll_into_view(void) offset_y = cursor_y - (LINES - 2); } +static bool +can_go_left(void) +{ + return cursor_y > 0 || + (cursor_y == 0 && cursor_x > 0); +} + +static bool +can_go_right(void) +{ + return cursor_y < cur_max_y() || + (cursor_y == cur_max_y() && cursor_x < cur_max_x()); +} + +static void +go_to_prev_line(void) +{ + cursor_y--; + cursor_x = cur_max_x(); +} + +static void +go_to_next_line(void) +{ + cursor_x = 0; + cursor_y++; +} + +static void +go_left(void) +{ + if (cursor_x > 0) + cursor_x--; + else if (cursor_y > 0) + go_to_prev_line(); +} + +static void +go_right(void) +{ + if (cursor_x < cur_max_x()) + cursor_x++; + else if (cursor_y < cur_max_y()) + go_to_next_line(); +} + +static void +go_to_prev_word(void) +{ + while (can_go_left() && ch_isspace(char_left_of_cursor())) + go_left(); + + while (can_go_left() && !ch_isspace(char_left_of_cursor())) + go_left(); +} + +static void +go_to_next_word(void) +{ + while (can_go_right() && !ch_isspace(char_at_cursor())) + go_right(); + + while (can_go_right() && ch_isspace(char_at_cursor())) + go_right(); +} + static void handle_char_input(int ch) { @@ -390,23 +464,13 @@ handle_char_input(int ch) if (substitute((char)ch)) { if (cursor_x < cur_max_x()) cursor_x++; - if (cursor_x == cur_max_x() && - cursor_y < cur_max_y()) { -cursor_x = 0; -cursor_y++; - } - } - } else if (cursor_x < cur_max_x() && - ch == lines.v[cursor_y].s[cursor_x]) { - cursor_x++; - if (cursor_x == cur_max_x() && - cursor_y < cur_max_y()) { - cursor_x = 0; - cursor_y++; + if (cursor_x == cur_max_x()) +go_to_next_line(); } - } else { + } else if (ch == char_at_cursor()) + go_right(); + else beep(); - } } static bool @@ -421,12 +485,7 @@ handle_key(void) break; case 2: /* ^B */ case KEY_LEFT: - if (cursor_x > 0) { - cursor_x--; - } else if (cursor_y > 0) { - cursor_y--; - cursor_x = cur_max_x(); - } + go_left(); break; case 5: /* ^E */ case KEY_END: @@ -434,12 +493,16 @@ handle_key(void) break; case 6: /* ^F */ case KEY_RIGHT: - if (cursor_x < cur_max_x()) { - cursor_x++; - } else if (cursor_y < cur_max_y()) { - cursor_y++; - cursor_x = 0; - } + go_right(); + break; + case '\t': + go_to_next_word(); + break; + case KEY_BTAB: + go_to_prev_word(); + break; + case '\n': + go_to_next_line(); break; case 12: /* ^L */ clear(); @@ -478,7 +541,11 @@ init(void) srandom((unsigned
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Mon Feb 22 16:28:20 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: properly handle input errors On both NetBSD and Cygwin, a missing /usr/bin/fortune would previously continue since popen does not return an error (as /bin/sh is found and can be executed), so the next chance to catch an error is pclose. At that point, the shell has already printed an informative error message about what happened (or what didn't happen), so that cgram does not need to print an error by itself. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.11 src/games/cgram/cgram.c:1.12 --- src/games/cgram/cgram.c:1.11 Sun Feb 21 22:21:56 2021 +++ src/games/cgram/cgram.c Mon Feb 22 16:28:20 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.11 2021/02/21 22:21:56 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.12 2021/02/22 16:28:20 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.11 2021/02/21 22:21:56 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.12 2021/02/22 16:28:20 rillig Exp $"); #endif #include @@ -227,7 +227,8 @@ readquote(void) for (int i = 0; i < extent_y; i++) extent_x = imax(extent_x, (int)lines.v[i].len); - pclose(f); + if (pclose(f) != 0) + exit(1); /* error message must come from child process */ } static void
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 22:21:56 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: allow navigation with KEY_PPAGE and KEY_NPAGE To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.10 src/games/cgram/cgram.c:1.11 --- src/games/cgram/cgram.c:1.10 Sun Feb 21 20:33:42 2021 +++ src/games/cgram/cgram.c Sun Feb 21 22:21:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.11 2021/02/21 22:21:56 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.11 2021/02/21 22:21:56 rillig Exp $"); #endif #include @@ -361,8 +361,8 @@ closecurses(void) static void saturate_cursor(void) { - assert(cursor_y >= 0); - assert(cursor_y <= cur_max_y()); + cursor_y = imax(cursor_y, 0); + cursor_y = imin(cursor_y, cur_max_y()); assert(cursor_x >= 0); cursor_x = imin(cursor_x, cur_max_x()); @@ -445,13 +445,17 @@ handle_key(void) break; case 14: /* ^N */ case KEY_DOWN: - if (cursor_y < cur_max_y()) - cursor_y++; + cursor_y++; break; case 16: /* ^P */ case KEY_UP: - if (cursor_y > 0) - cursor_y--; + cursor_y--; + break; + case KEY_PPAGE: + cursor_y -= LINES - 2; + break; + case KEY_NPAGE: + cursor_y += LINES - 2; break; case '*': hinting = !hinting;
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 20:33:43 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: rewrite completely, fixing bugs and style Fixed bugs: Do not consider the puzzle solved if all letters in the visible area are substituted correctly. To be properly solved, the whole puzzle must be solved, even those parts that are currently off-screen. Never place the cursor at the very right edge of the screen since that does not work well with some terminals. The maximum valid x coordinate is COLS - 1. Add horizontal scrolling. Make all coordinate handling symmetric in regard to the horizontal and vertical axes. Previously, lines longer than 80 characters could not be seen on the screen. Improvements: Remove the arbitrary limit of 128 characters per line. Even if fortune(6) may never generate such long lines, the code is easy enough to adapt to other sources. Properly clean up the allocated memory. Previously, only the string arrays were freed but not the strings themselves. Stylistic: Add RCS ID. Fix ctype functions in lint's strict bool mode. Avoid excessive calls to strlen whenever the cursor moves. Given that the whole screen is redrawn every time a key is pressed, this is an unnecessary optimization, but the code smelled nevertheless. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.9 src/games/cgram/cgram.c:1.10 --- src/games/cgram/cgram.c:1.9 Sun Feb 21 17:16:00 2021 +++ src/games/cgram/cgram.c Sun Feb 21 20:33:42 2021 @@ -1,11 +1,11 @@ -/* $NetBSD: cgram.c,v 1.9 2021/02/21 17:16:00 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $ */ /*- - * Copyright (c) 2013 The NetBSD Foundation, Inc. + * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by David A. Holland. + * by David A. Holland and Roland Illig. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,6 +29,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $"); +#endif + #include #include #include @@ -43,19 +48,6 @@ -static char * -xstrdup(const char *s) -{ - char *ret; - - ret = malloc(strlen(s) + 1); - if (ret == NULL) { - errx(1, "Out of memory"); - } - strcpy(ret, s); - return ret; -} - static char ch_toupper(char ch) { @@ -71,29 +63,74 @@ ch_tolower(char ch) static bool ch_isalpha(char ch) { - return isalpha((unsigned char)ch); + return isalpha((unsigned char)ch) != 0; } static bool ch_islower(char ch) { - return islower((unsigned char)ch); + return islower((unsigned char)ch) != 0; } static bool ch_isupper(char ch) { - return isupper((unsigned char)ch); + return isupper((unsigned char)ch) != 0; +} + +static int +imax(int a, int b) +{ + return a > b ? a : b; +} + +static int +imin(int a, int b) +{ + return a < b ? a : b; } +struct string { + char *s; + size_t len; + size_t cap; +}; + struct stringarray { - char **v; + struct string *v; size_t num; }; static void +string_init(struct string *s) +{ + s->s = NULL; + s->len = 0; + s->cap = 0; +} + +static void +string_add(struct string *s, char ch) +{ + if (s->len >= s->cap) { + s->cap = 2 * s->cap + 16; + s->s = realloc(s->s, s->cap); + if (s->s == NULL) + errx(1, "Out of memory"); + } + s->s[s->len++] = ch; +} + +static void +string_finish(struct string *s) +{ + string_add(s, '\0'); + s->len--; +} + +static void stringarray_init(struct stringarray *a) { a->v = NULL; @@ -103,18 +140,33 @@ stringarray_init(struct stringarray *a) static void stringarray_cleanup(struct stringarray *a) { + for (size_t i = 0; i < a->num; i++) + free(a->v[i].s); free(a->v); } static void -stringarray_add(struct stringarray *a, const char *s) +stringarray_add(struct stringarray *a, struct string *s) { - a->v = realloc(a->v, (a->num + 1) * sizeof(a->v[0])); - if (a->v == NULL) { + size_t num = a->num++; + a->v = realloc(a->v, a->num * sizeof a->v[0]); + if (a->v == NULL) errx(1, "Out of memory"); + a->v[num] = *s; +} + +static void +stringarray_dup(struct stringarray *dst, const struct stringarray *src) +{ + assert(dst->num == 0); + for (size_t i = 0; i < src->num; i++) { + struct string str; + string_init(); + for (const char *p = src->v[i].s; *p != '\0'; p++) + string_add(, *p); + string_finish(); + stringarray_add(dst, ); } - a->v[a->num] = xstrdup(s); - a->num++; }
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 17:16:00 UTC 2021 Modified Files: src/games/cgram: Makefile cgram.c Log Message: cgram: WARNS=6, use int for all coordinates Eliminate some frequently occurring subexpressions during substitution. No functional change, assuming that fortune(6) always spits out less than 2 gigacharacters of text. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/games/cgram/Makefile cvs rdiff -u -r1.8 -r1.9 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/Makefile diff -u src/games/cgram/Makefile:1.2 src/games/cgram/Makefile:1.3 --- src/games/cgram/Makefile:1.2 Sun Feb 21 16:05:44 2021 +++ src/games/cgram/Makefile Sun Feb 21 17:16:00 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.2 2021/02/21 16:05:44 rillig Exp $ +# $NetBSD: Makefile,v 1.3 2021/02/21 17:16:00 rillig Exp $ PROG= cgram DPADD= ${LIBCURSES} ${LIBTERMINFO} @@ -7,5 +7,6 @@ SRCS= cgram.c MAN= cgram.6 HIDEGAME= hidegame LINTFLAGS+= -T +WARNS= 6 .include Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.8 src/games/cgram/cgram.c:1.9 --- src/games/cgram/cgram.c:1.8 Sun Feb 21 16:50:57 2021 +++ src/games/cgram/cgram.c Sun Feb 21 17:16:00 2021 @@ -1,4 +1,4 @@ -/* $NetBSD */ +/* $NetBSD: cgram.c,v 1.9 2021/02/21 17:16:00 rillig Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ ch_isupper(char ch) struct stringarray { char **v; - int num; + size_t num; }; static void @@ -123,7 +123,7 @@ static struct stringarray lines; static struct stringarray sollines; static bool hinting; static int scrolldown; -static unsigned curx; +static int curx; static int cury; static void @@ -167,34 +167,32 @@ static void encode(void) { int key[26]; + for (int i = 0; i < 26; i++) key[i] = i; + for (int i = 26; i > 1; i--) { - int c = random() % i; + int c = (int)(random() % i); int t = key[i - 1]; key[i - 1] = key[c]; key[c] = t; } - for (int y = 0; y < lines.num; y++) { - for (unsigned x = 0; lines.v[y][x] != '\0'; x++) { - if (ch_islower(lines.v[y][x])) { -int q = lines.v[y][x] - 'a'; -lines.v[y][x] = 'a' + key[q]; - } - if (ch_isupper(lines.v[y][x])) { -int q = lines.v[y][x] - 'A'; -lines.v[y][x] = 'A' + key[q]; - } + for (int y = 0; y < (int)lines.num; y++) { + for (char *p = lines.v[y]; *p != '\0'; p++) { + if (ch_islower(*p)) +*p = (char)('a' + key[*p - 'a']); + if (ch_isupper(*p)) +*p = (char)('A' + key[*p - 'A']); } } } static bool -substitute(int ch) +substitute(char ch) { - assert(cury >= 0 && cury < lines.num); - if (curx >= strlen(lines.v[cury])) { + assert(cury >= 0 && cury < (int)lines.num); + if (curx >= (int)strlen(lines.v[cury])) { beep(); return false; } @@ -210,17 +208,16 @@ substitute(int ch) char lch = ch_tolower(ch); char uch = ch_toupper(ch); - for (int y = 0; y < lines.num; y++) { - for (unsigned x = 0; lines.v[y][x] != '\0'; x++) { - if (lines.v[y][x] == loch) { -lines.v[y][x] = lch; - } else if (lines.v[y][x] == uoch) { -lines.v[y][x] = uch; - } else if (lines.v[y][x] == lch) { -lines.v[y][x] = loch; - } else if (lines.v[y][x] == uch) { -lines.v[y][x] = uoch; - } + for (int y = 0; y < (int)lines.num; y++) { + for (char *p = lines.v[y]; *p != '\0'; p++) { + if (*p == loch) +*p = lch; + else if (*p == uoch) +*p = uch; + else if (*p == lch) +*p = loch; + else if (*p == uch) +*p = uoch; } } return true; @@ -236,7 +233,7 @@ redraw(void) for (int i = 0; i < LINES - 1; i++) { move(i, 0); int ln = i + scrolldown; - if (ln < lines.num) { + if (ln < (int)lines.num) { for (unsigned j = 0; lines.v[i][j] != '\0'; j++) { char ch = lines.v[i][j]; if (ch != sollines.v[i][j] && ch_isalpha(ch)) { @@ -304,18 +301,18 @@ loop(void) curx--; } else if (cury > 0) { cury--; -curx = strlen(lines.v[cury]); +curx = (int)strlen(lines.v[cury]); } break; case 5: /* ^E */ case KEY_END: - curx = strlen(lines.v[cury]); + curx = (int)strlen(lines.v[cury]); break; case 6: /* ^F */ case KEY_RIGHT: - if (curx < strlen(lines.v[cury])) { + if (curx < (int)strlen(lines.v[cury])) { curx++; - } else if (cury < lines.num - 1) { + } else if (cury < (int)lines.num - 1) { cury++; curx = 0; } @@ -325,11 +322,11 @@ loop(void) break; case 14: /* ^N */ case KEY_DOWN: - if (cury < lines.num - 1) { + if (cury < (int)lines.num - 1) { cury++; } - if (curx > strlen(lines.v[cury])) { -curx = strlen(lines.v[cury]); + if (curx > (int)strlen(lines.v[cury])) { +curx = (int)strlen(lines.v[cury]); } if (scrolldown < cury - (LINES - 2)) { scrolldown = cury - (LINES - 2); @@ -340,8 +337,8 @@ loop(void) if (cury > 0) { cury--;
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 16:50:58 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: consistently use char for characters Having to convert back and forth between char, unsigned char and int is confusing. Just stay with char, until the support for wide characters is added. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.7 src/games/cgram/cgram.c:1.8 --- src/games/cgram/cgram.c:1.7 Sun Feb 21 16:37:26 2021 +++ src/games/cgram/cgram.c Sun Feb 21 16:50:57 2021 @@ -56,6 +56,36 @@ xstrdup(const char *s) return ret; } +static char +ch_toupper(char ch) +{ + return (char)toupper((unsigned char)ch); +} + +static char +ch_tolower(char ch) +{ + return (char)tolower((unsigned char)ch); +} + +static bool +ch_isalpha(char ch) +{ + return isalpha((unsigned char)ch); +} + +static bool +ch_islower(char ch) +{ + return islower((unsigned char)ch); +} + +static bool +ch_isupper(char ch) +{ + return isupper((unsigned char)ch); +} + struct stringarray { @@ -148,11 +178,11 @@ encode(void) for (int y = 0; y < lines.num; y++) { for (unsigned x = 0; lines.v[y][x] != '\0'; x++) { - if (islower((unsigned char)lines.v[y][x])) { + if (ch_islower(lines.v[y][x])) { int q = lines.v[y][x] - 'a'; lines.v[y][x] = 'a' + key[q]; } - if (isupper((unsigned char)lines.v[y][x])) { + if (ch_isupper(lines.v[y][x])) { int q = lines.v[y][x] - 'A'; lines.v[y][x] = 'A' + key[q]; } @@ -169,16 +199,16 @@ substitute(int ch) return false; } - int och = lines.v[cury][curx]; - if (!isalpha((unsigned char)och)) { + char och = lines.v[cury][curx]; + if (!ch_isalpha(och)) { beep(); return false; } - int loch = tolower((unsigned char)och); - int uoch = toupper((unsigned char)och); - int lch = tolower((unsigned char)ch); - int uch = toupper((unsigned char)ch); + char loch = ch_tolower(och); + char uoch = ch_toupper(och); + char lch = ch_tolower(ch); + char uch = ch_toupper(ch); for (int y = 0; y < lines.num; y++) { for (unsigned x = 0; lines.v[y][x] != '\0'; x++) { @@ -208,14 +238,13 @@ redraw(void) int ln = i + scrolldown; if (ln < lines.num) { for (unsigned j = 0; lines.v[i][j] != '\0'; j++) { -int ch = lines.v[i][j]; -if (ch != sollines.v[i][j] && -isalpha((unsigned char)ch)) { +char ch = lines.v[i][j]; +if (ch != sollines.v[i][j] && ch_isalpha(ch)) { won = false; } bool bold = false; if (hinting && ch == sollines.v[i][j] && -isalpha((unsigned char)ch)) { +ch_isalpha(ch)) { bold = true; attron(A_BOLD); }
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 16:37:26 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: fix undefined behavior when pressing function keys The key codes for function keys are outside of the "range representable by an unsigned char". This resulted in parts of the screen being cleaned. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.6 src/games/cgram/cgram.c:1.7 --- src/games/cgram/cgram.c:1.6 Sun Feb 21 16:05:44 2021 +++ src/games/cgram/cgram.c Sun Feb 21 16:37:26 2021 @@ -325,7 +325,7 @@ loop(void) done = true; break; default: - if (isalpha(ch)) { + if (isascii(ch) && isalpha(ch)) { if (substitute(ch)) { if (curx < strlen(lines.v[cury])) { curx++;
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 16:05:44 UTC 2021 Modified Files: src/games/cgram: Makefile cgram.c Log Message: cgram: adjust style to survive lint's strict bool mode The biggest change is the return type of substitute(). Before, 0 meant success, now false means failure. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/games/cgram/Makefile cvs rdiff -u -r1.5 -r1.6 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/Makefile diff -u src/games/cgram/Makefile:1.1 src/games/cgram/Makefile:1.2 --- src/games/cgram/Makefile:1.1 Sun Aug 4 05:42:47 2013 +++ src/games/cgram/Makefile Sun Feb 21 16:05:44 2021 @@ -1,10 +1,11 @@ -# $NetBSD: Makefile,v 1.1 2013/08/04 05:42:47 dholland Exp $ +# $NetBSD: Makefile,v 1.2 2021/02/21 16:05:44 rillig Exp $ -PROG=cgram -DPADD=${LIBCURSES} ${LIBTERMINFO} -LDADD=-lcurses -lterminfo -SRCS=cgram.c -MAN=cgram.6 -HIDEGAME=hidegame +PROG= cgram +DPADD= ${LIBCURSES} ${LIBTERMINFO} +LDADD= -lcurses -lterminfo +SRCS= cgram.c +MAN= cgram.6 +HIDEGAME= hidegame +LINTFLAGS+= -T .include Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.5 src/games/cgram/cgram.c:1.6 --- src/games/cgram/cgram.c:1.5 Sun Feb 21 15:42:21 2021 +++ src/games/cgram/cgram.c Sun Feb 21 16:05:44 2021 @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -99,22 +100,22 @@ static void readquote(void) { FILE *f = popen(_PATH_FORTUNE, "r"); - if (!f) { + if (f == NULL) { err(1, "%s", _PATH_FORTUNE); } char buf[128], buf2[8 * sizeof(buf)]; - while (fgets(buf, sizeof(buf), f)) { + while (fgets(buf, sizeof buf, f) != NULL) { char *s = strrchr(buf, '\n'); - assert(s); + assert(s != NULL); assert(strlen(s) == 1); - *s = 0; + *s = '\0'; int i, j; - for (i = j = 0; buf[i]; i++) { + for (i = j = 0; buf[i] != '\0'; i++) { if (buf[i] == '\t') { buf2[j++] = ' '; -while (j % 8) +while (j % 8 != 0) buf2[j++] = ' '; } else if (buf[i] == '\b') { if (j > 0) @@ -123,7 +124,7 @@ readquote(void) buf2[j++] = buf[i]; } } - buf2[j] = 0; + buf2[j] = '\0'; stringarray_add(, buf2); stringarray_add(, buf2); @@ -146,7 +147,7 @@ encode(void) } for (int y = 0; y < lines.num; y++) { - for (unsigned x = 0; lines.v[y][x]; x++) { + for (unsigned x = 0; lines.v[y][x] != '\0'; x++) { if (islower((unsigned char)lines.v[y][x])) { int q = lines.v[y][x] - 'a'; lines.v[y][x] = 'a' + key[q]; @@ -159,19 +160,19 @@ encode(void) } } -static int +static bool substitute(int ch) { assert(cury >= 0 && cury < lines.num); if (curx >= strlen(lines.v[cury])) { beep(); - return -1; + return false; } int och = lines.v[cury][curx]; if (!isalpha((unsigned char)och)) { beep(); - return -1; + return false; } int loch = tolower((unsigned char)och); @@ -180,7 +181,7 @@ substitute(int ch) int uch = toupper((unsigned char)ch); for (int y = 0; y < lines.num; y++) { - for (unsigned x = 0; lines.v[y][x]; x++) { + for (unsigned x = 0; lines.v[y][x] != '\0'; x++) { if (lines.v[y][x] == loch) { lines.v[y][x] = lch; } else if (lines.v[y][x] == uoch) { @@ -192,7 +193,7 @@ substitute(int ch) } } } - return 0; + return true; } @@ -206,7 +207,7 @@ redraw(void) move(i, 0); int ln = i + scrolldown; if (ln < lines.num) { - for (unsigned j = 0; lines.v[i][j]; j++) { + for (unsigned j = 0; lines.v[i][j] != '\0'; j++) { int ch = lines.v[i][j]; if (ch != sollines.v[i][j] && isalpha((unsigned char)ch)) { @@ -325,7 +326,7 @@ loop(void) break; default: if (isalpha(ch)) { -if (!substitute(ch)) { +if (substitute(ch)) { if (curx < strlen(lines.v[cury])) { curx++; } @@ -364,7 +365,7 @@ main(void) encode(); opencurses(); - keypad(stdscr, TRUE); + keypad(stdscr, true); loop(); closecurses();
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 15:42:21 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: sort includes To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.4 src/games/cgram/cgram.c:1.5 --- src/games/cgram/cgram.c:1.4 Sun Feb 21 15:41:04 2021 +++ src/games/cgram/cgram.c Sun Feb 21 15:42:21 2021 @@ -29,14 +29,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include +#include +#include +#include #include -#include #include -#include +#include #include -#include -#include -#include + #include "pathnames.h"
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 15:41:04 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: indent With manual corrections afterwards: - indent removes empty lines between statement and declaration. This had been a syntax error in C90, since C99 this is common style and should be accepted by indent. - indent didn't format the first line of main for whatever reason, did that manually. - indent removed the empty line above the '/' separators. It should have left these empty lines as-is. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.3 src/games/cgram/cgram.c:1.4 --- src/games/cgram/cgram.c:1.3 Sun Feb 21 13:35:37 2021 +++ src/games/cgram/cgram.c Sun Feb 21 15:41:04 2021 @@ -1,3 +1,5 @@ +/* $NetBSD */ + /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. * All rights reserved. @@ -39,40 +41,48 @@ -static char *xstrdup(const char *s) { - char *ret; - - ret = malloc(strlen(s) + 1); - if (ret == NULL) { - errx(1, "Out of memory"); - } - strcpy(ret, s); - return ret; +static char * +xstrdup(const char *s) +{ + char *ret; + + ret = malloc(strlen(s) + 1); + if (ret == NULL) { + errx(1, "Out of memory"); + } + strcpy(ret, s); + return ret; } struct stringarray { - char **v; - int num; + char **v; + int num; }; -static void stringarray_init(struct stringarray *a) { - a->v = NULL; - a->num = 0; -} - -static void stringarray_cleanup(struct stringarray *a) { - free(a->v); -} - -static void stringarray_add(struct stringarray *a, const char *s) { - a->v = realloc(a->v, (a->num + 1) * sizeof(a->v[0])); - if (a->v == NULL) { - errx(1, "Out of memory"); - } - a->v[a->num] = xstrdup(s); - a->num++; +static void +stringarray_init(struct stringarray *a) +{ + a->v = NULL; + a->num = 0; +} + +static void +stringarray_cleanup(struct stringarray *a) +{ + free(a->v); +} + +static void +stringarray_add(struct stringarray *a, const char *s) +{ + a->v = realloc(a->v, (a->num + 1) * sizeof(a->v[0])); + if (a->v == NULL) { + errx(1, "Out of memory"); + } + a->v[a->num] = xstrdup(s); + a->num++; } @@ -84,265 +94,279 @@ static int scrolldown; static unsigned curx; static int cury; -static void readquote(void) { - FILE *f = popen(_PATH_FORTUNE, "r"); - if (!f) { - err(1, "%s", _PATH_FORTUNE); - } - - char buf[128], buf2[8*sizeof(buf)]; - while (fgets(buf, sizeof(buf), f)) { - char *s = strrchr(buf, '\n'); - assert(s); - assert(strlen(s)==1); - *s = 0; - - int i,j; - for (i=j=0; buf[i]; i++) { - if (buf[i]=='\t') { - buf2[j++] = ' '; - while (j%8) buf2[j++] = ' '; - } - else if (buf[i]=='\b') { - if (j>0) j--; - } - else { - buf2[j++] = buf[i]; - } - } - buf2[j] = 0; - - stringarray_add(, buf2); - stringarray_add(, buf2); - } - - pclose(f); -} - -static void encode(void) { - int key[26]; - for (int i=0; i<26; i++) key[i] = i; - for (int i=26; i>1; i--) { - int c = random() % i; - int t = key[i-1]; - key[i-1] = key[c]; - key[c] = t; - } - - for (int y=0; y=0 && cury= strlen(lines.v[cury])) { - beep(); - return -1; - } - - int och = lines.v[cury][curx]; - if (!isalpha((unsigned char)och)) { - beep(); - return -1; - } - - int loch = tolower((unsigned char)och); - int uoch = toupper((unsigned char)och); - int lch = tolower((unsigned char)ch); - int uch = toupper((unsigned char)ch); - - for (int y=0; y 0) + j--; + } else { +buf2[j++] = buf[i]; + } + } + buf2[j] = 0; + + stringarray_add(, buf2); + stringarray_add(, buf2); + } + + pclose(f); +} + +static void +encode(void) +{ + int key[26]; + for (int i = 0; i < 26; i++) + key[i] = i; + for (int i = 26; i > 1; i--) { + int c = random() % i; + int t = key[i - 1]; + key[i - 1] = key[c]; + key[c] = t; + } + + for (int y = 0; y < lines.num; y++) { + for (unsigned x = 0; lines.v[y][x]; x++) { + if (islower((unsigned char)lines.v[y][x])) { +int q = lines.v[y][x] - 'a'; +lines.v[y][x] = 'a' + key[q]; + } + if (isupper((unsigned char)lines.v[y][x])) { +int q = lines.v[y][x] - 'A'; +lines.v[y][x] = 'A' + key[q]; + } + } + } +} + +static int +substitute(int ch) +{ + assert(cury >= 0 && cury < lines.num); + if (curx >= strlen(lines.v[cury])) { + beep(); + return -1; + } + + int och = lines.v[cury][curx]; + if (!isalpha((unsigned char)och)) { + beep(); + return -1; + } + + int loch = tolower((unsigned char)och); + int uoch =
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Sun Feb 21 13:35:37 UTC 2021 Modified Files: src/games/cgram: cgram.c Log Message: cgram: fix Home key for cursor navigation Reported by liweitianux via GitHub. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.2 src/games/cgram/cgram.c:1.3 --- src/games/cgram/cgram.c:1.2 Thu Jul 2 19:11:01 2020 +++ src/games/cgram/cgram.c Sun Feb 21 13:35:37 2021 @@ -241,7 +241,7 @@ static void loop(void) { int ch = getch(); switch (ch) { case 1: /* ^A */ - case KEY_BEG: + case KEY_HOME: curx=0; break; case 2: /* ^B */
CVS commit: src/games/testpat
Module Name:src Committed By: christos Date: Fri Jan 8 15:16:04 UTC 2021 Modified Files: src/games/testpat: testpat.c Log Message: - Don't allocate memory dynamically on the stack (for SSP) - Don't return errno as exit code - Fold long lines To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/games/testpat/testpat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/testpat/testpat.c diff -u src/games/testpat/testpat.c:1.3 src/games/testpat/testpat.c:1.4 --- src/games/testpat/testpat.c:1.3 Sat Jan 2 07:12:26 2021 +++ src/games/testpat/testpat.c Fri Jan 8 10:16:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: testpat.c,v 1.3 2021/01/02 12:12:26 jmcneill Exp $ */ +/* $NetBSD: testpat.c,v 1.4 2021/01/08 15:16:04 christos Exp $ */ /*- * Copyright (c) 2016 Nathanial Sloss @@ -25,6 +25,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#include +__RCSID("$NetBSD: testpat.c,v 1.4 2021/01/08 15:16:04 christos Exp $"); + +#include +#include #include #include @@ -34,69 +39,66 @@ #include #include #include -#include -#include + +static int colour_list[6] = { + COLOR_YELLOW, + COLOR_CYAN, + COLOR_GREEN, + COLOR_MAGENTA, + COLOR_RED, + COLOR_BLUE, +}; +static int numcolours = (int)__arraycount(colour_list); int main(int argc, char *argv[]) { int i, col, colour, line, x_limit, y_limit, colourOK, spacing; int xpos, ypos, spacing_residual, spacing_start, spacing_end; - int grid_x, grid_y; + int grid_x, grid_y, **circle_pos; + size_t ncpos; float grid_unit; - - char title[255] = "NetBSD"; - int numcolours = 6; - - int colour_list[6] = { - COLOR_YELLOW, - COLOR_CYAN, - COLOR_GREEN, - COLOR_MAGENTA, - COLOR_RED, - COLOR_BLUE, - }; - + const char *title = "NetBSD"; float coord_x, circle_int; float a_axis, b_axis; - if (!(initscr())) { - printf("\nUnknown terminal type."); - printf("\n"); - return EXIT_FAILURE; + if (!initscr()) { + errx(EXIT_FAILURE, "Unknown terminal type"); } + curs_set(0); if (argc > 2) { endwin(); - errx(EINVAL, "usage: testpat [title]"); + fprintf(stderr, "Usage: %s ", getprogname()); + return EXIT_FAILURE; } - if (argc == 2 && strlen(argv[1]) < (size_t)COLS) - snprintf(title, sizeof(title), "%s", argv[1]); - else if (argc == 2 && (int)strlen(argv[1]) > COLS) { - endwin(); - errx(EINVAL, "title string must be less than display columns"); + if (argc == 2) { + title = argv[1]; + if (strlen(title) >= (size_t)COLS) { + endwin(); + errx(EXIT_FAILURE, + "Title string is longer than display cols"); + } } colourOK = has_colors(); if (COLS < 13 || LINES < 13) { endwin(); - printf("\nTerminal size must be at least 72x25."); - printf("\n"); - return EXIT_FAILURE; + errx(EXIT_FAILURE, "Terminal size must be at least 72x25."); } if (colourOK) { start_color(); - init_pair( 0, COLOR_WHITE, COLOR_BLACK ); - init_pair( 1, COLOR_WHITE, COLOR_RED ); - init_pair( 2, COLOR_WHITE, COLOR_GREEN ); - init_pair( 3, COLOR_WHITE, COLOR_YELLOW ); - init_pair( 4, COLOR_WHITE, COLOR_BLUE ); - init_pair( 5, COLOR_WHITE, COLOR_MAGENTA ); - init_pair( 6, COLOR_WHITE, COLOR_CYAN ); - init_pair( 7, COLOR_BLACK, COLOR_WHITE ); + init_pair(0, COLOR_WHITE, COLOR_BLACK); + init_pair(1, COLOR_WHITE, COLOR_RED); + init_pair(2, COLOR_WHITE, COLOR_GREEN); + init_pair(3, COLOR_WHITE, COLOR_YELLOW); + init_pair(4, COLOR_WHITE, COLOR_BLUE); + init_pair(5, COLOR_WHITE, COLOR_MAGENTA); + init_pair(6, COLOR_WHITE, COLOR_CYAN); + init_pair(7, COLOR_BLACK, COLOR_WHITE); attrset(COLOR_PAIR(0)); } @@ -113,11 +115,21 @@ int main(int argc, char *argv[]) { grid_y = grid_unit; grid_x = grid_unit * 2; - int circle_pos[y_limit][2]; - memset(circle_pos, -1, sizeof(circle_pos)); + + ncpos = y_limit * sizeof(*circle_pos) + + y_limit * 2 * sizeof(**circle_pos); + circle_pos = malloc(ncpos); + if (circle_pos == NULL) { + endwin(); + errx(EXIT_FAILURE, "Can't allocate circle positions"); + } + for (i = 0; i < y_limit; i++) { + circle_pos[i] = (void *)_pos[y_limit + i * 2]; + circle_pos[i][0] = circle_pos[i][1] = -1; + } for (i = 0; i < y_limit; i++) { - /* Draw an elipse (looks more circular.) */ + /* Draw an ellipse (looks more circular.) */ circle_int = (i - a_axis) / a_axis; circle_int = 1 - powf(circle_int, 2); circle_int = circle_int * powf(b_axis, 2); @@ -200,8 +212,8 @@ int main(int argc, char *argv[]) { attrset(COLOR_PAIR(COLOR_BLACK)); for (col = roundf((4 * grid_unit * 2) + - circle_pos[y_limit /2][0]); col <= roundf((9 * grid_unit - * 2) + circle_pos[y_limit /2][0]); col++) + circle_pos[y_limit / 2][0]); col <= roundf((9 * grid_unit + * 2) + circle_pos[y_limit / 2][0]); col++) mvaddch(i, col, '
CVS commit: src/games/testpat
Module Name:src Committed By: jmcneill Date: Sat Jan 2 12:12:26 UTC 2021 Modified Files: src/games/testpat: testpat.c Log Message: set the cursor to invisible To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/games/testpat/testpat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/testpat/testpat.c diff -u src/games/testpat/testpat.c:1.2 src/games/testpat/testpat.c:1.3 --- src/games/testpat/testpat.c:1.2 Sat Jan 2 12:10:17 2021 +++ src/games/testpat/testpat.c Sat Jan 2 12:12:26 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: testpat.c,v 1.2 2021/01/02 12:10:17 jmcneill Exp $ */ +/* $NetBSD: testpat.c,v 1.3 2021/01/02 12:12:26 jmcneill Exp $ */ /*- * Copyright (c) 2016 Nathanial Sloss @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) { printf("\n"); return EXIT_FAILURE; } + curs_set(0); if (argc > 2) { endwin();
CVS commit: src/games/testpat
Module Name:src Committed By: jmcneill Date: Sat Jan 2 12:10:17 UTC 2021 Modified Files: src/games/testpat: testpat.c Log Message: trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/games/testpat/testpat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/testpat/testpat.c diff -u src/games/testpat/testpat.c:1.1 src/games/testpat/testpat.c:1.2 --- src/games/testpat/testpat.c:1.1 Sat Jan 2 03:21:39 2021 +++ src/games/testpat/testpat.c Sat Jan 2 12:10:17 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: testpat.c,v 1.1 2021/01/02 03:21:39 nat Exp $ */ +/* $NetBSD: testpat.c,v 1.2 2021/01/02 12:10:17 jmcneill Exp $ */ /*- * Copyright (c) 2016 Nathanial Sloss @@ -66,9 +66,9 @@ int main(int argc, char *argv[]) { if (argc > 2) { endwin(); - errx(EINVAL, "usage: testpat [title]"); + errx(EINVAL, "usage: testpat [title]"); } - + if (argc == 2 && strlen(argv[1]) < (size_t)COLS) snprintf(title, sizeof(title), "%s", argv[1]); else if (argc == 2 && (int)strlen(argv[1]) > COLS) { @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) { if (colourOK) { start_color(); - + init_pair( 0, COLOR_WHITE, COLOR_BLACK ); init_pair( 1, COLOR_WHITE, COLOR_RED ); init_pair( 2, COLOR_WHITE, COLOR_GREEN ); @@ -192,7 +192,7 @@ int main(int argc, char *argv[]) { mvaddch(i, col, 32 | A_REVERSE); } } - + /* Add title segment. */ for (i = roundf(1 * grid_unit); i < roundf(2 * grid_unit); i++) { if (colourOK) @@ -204,7 +204,7 @@ int main(int argc, char *argv[]) { mvaddch(i, col, ' '); } - i = roundf(1.4 * grid_unit); + i = roundf(1.4 * grid_unit); col = y_limit - (strlen(title) / 2) + circle_pos[y_limit / 2][0]; mvprintw(i, col, "%s", title); @@ -221,7 +221,7 @@ int main(int argc, char *argv[]) { mvaddch(line, xpos, ' '); } - for (col = roundf((9.5 * grid_unit * 2)); col < + for (col = roundf((9.5 * grid_unit * 2)); col < roundf((13 * grid_unit * 2)); col++) { xpos = col + circle_pos[y_limit / 2][0]; if (xpos >= circle_pos[line][0] && @@ -263,7 +263,7 @@ int main(int argc, char *argv[]) { if (colourOK) attrset(COLOR_PAIR(colour)); - if (i == 0) + if (i == 0) spacing_start = 0; else spacing_start = (spacing * i) + spacing_residual; @@ -293,7 +293,7 @@ int main(int argc, char *argv[]) { col++) mvaddch(line, col, ' '); - for (col = roundf((1.5 * grid_unit * 2)); col < + for (col = roundf((1.5 * grid_unit * 2)); col < roundf((4.3 * grid_unit * 2)); col++) { xpos = col + circle_pos[y_limit / 2][0]; if (xpos >= circle_pos[line][0] && @@ -301,7 +301,7 @@ int main(int argc, char *argv[]) { mvaddch(line, xpos, 120 | A_ALTCHARSET); } - for (col = roundf((4.3 * grid_unit * 2)); col < + for (col = roundf((4.3 * grid_unit * 2)); col < roundf((7.6 * grid_unit * 2)); col++) { xpos = col + circle_pos[y_limit / 2][0]; if (xpos >= circle_pos[line][0] && @@ -309,7 +309,7 @@ int main(int argc, char *argv[]) { mvaddch(line, xpos, '|'); } - for (col = roundf((7.6 * grid_unit * 2)); col < + for (col = roundf((7.6 * grid_unit * 2)); col < roundf((11.5 * grid_unit * 2)); col++) { xpos = col + circle_pos[y_limit / 2][0]; if (xpos >= circle_pos[line][0] && @@ -324,7 +324,7 @@ int main(int argc, char *argv[]) { if (colourOK) attrset(COLOR_PAIR(COLOR_BLACK)); - for (col = roundf((0 * grid_unit * 2)); col < + for (col = roundf((0 * grid_unit * 2)); col < roundf((4 * grid_unit * 2)); col++) { xpos = col + circle_pos[y_limit / 2][0]; if (xpos >= circle_pos[line][0] && @@ -332,7 +332,7 @@ int main(int argc, char *argv[]) { mvaddch(line, xpos, ' '); } - for (col = roundf((4 * grid_unit * 2)); col < + for (col = roundf((4 * grid_unit * 2)); col < roundf((6.5 * grid_unit * 2)); col++) { xpos = col + circle_pos[y_limit / 2][0]; if (xpos >= circle_pos[line][0] && @@ -343,7 +343,7 @@ int main(int argc, char *argv[]) { if (colourOK) attrset(COLOR_PAIR(COLOR_WHITE)); - for (col = roundf((6.5 * grid_unit * 2)); col < + for (col = roundf((6.5 * grid_unit * 2)); col < roundf((9 * grid_unit * 2)); col++) { xpos = col + circle_pos[y_limit / 2][0]; if (xpos >= circle_pos[line][0] && @@ -351,7 +351,7 @@ int main(int argc, char *argv[]) { mvaddch(line, xpos, 97 | A_ALTCHARSET); } - for (col = roundf((9 * grid_unit * 2)); col < + for (col = roundf((9 * grid_unit * 2)); col < roundf((13 * grid_unit * 2)); col++) { xpos = col + circle_pos[y_limit / 2][0]; if (xpos >= circle_pos[line][0] && @@ -406,7 +406,7 @@ int main(int argc, char *argv[]) { if (colourOK) attrset(COLOR_PAIR(COLOR_RED)); - for (col = roundf((6 * grid_unit * 2)); col < + for (col = roundf((6 * grid_unit *
CVS commit: src/games/testpat
Module Name:src Committed By: wiz Date: Sat Jan 2 08:55:51 UTC 2021 Modified Files: src/games/testpat: testpat.6 Log Message: Markup/typo fixes. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/games/testpat/testpat.6 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/testpat/testpat.6 diff -u src/games/testpat/testpat.6:1.1 src/games/testpat/testpat.6:1.2 --- src/games/testpat/testpat.6:1.1 Sat Jan 2 03:21:39 2021 +++ src/games/testpat/testpat.6 Sat Jan 2 08:55:51 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: testpat.6,v 1.1 2021/01/02 03:21:39 nat Exp $ +.\" $NetBSD: testpat.6,v 1.2 2021/01/02 08:55:51 wiz Exp $ .\" .\" Copyright (c) 2021 Nathanial Sloss .\" All rights reserved. @@ -24,7 +24,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd Janurary 2, 2021 +.Dd January 2, 2021 .Dt TESTPAT 6 .Os .Sh NAME @@ -38,7 +38,6 @@ The .Nm command displays a test pattern on a color capable terminal using .Xr curses 3 . - Title is a string to display as the title of the test pattern. .Sh SEE ALSO .Xr curses 3 @@ -47,4 +46,4 @@ Title is a string to display as the titl appeared in .Nx 10.0 . .Sh AUTHORS -Nathanial Sloss +.An Nathanial Sloss
CVS commit: src/games
Module Name:src Committed By: nat Date: Sat Jan 2 03:21:39 UTC 2021 Modified Files: src/games: Makefile Added Files: src/games/testpat: Makefile testpat.6 testpat.c Log Message: Add testpat(6) to games. Testpat displays a test pattern in curses(3). To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/games/Makefile cvs rdiff -u -r0 -r1.1 src/games/testpat/Makefile src/games/testpat/testpat.6 \ src/games/testpat/testpat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/Makefile diff -u src/games/Makefile:1.30 src/games/Makefile:1.31 --- src/games/Makefile:1.30 Tue Nov 10 08:49:08 2020 +++ src/games/Makefile Sat Jan 2 03:21:39 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.30 2020/11/10 08:49:08 kamil Exp $ +# $NetBSD: Makefile,v 1.31 2021/01/02 03:21:39 nat Exp $ # @(#)Makefile 8.3 (Berkeley) 7/24/94 # Missing: dungeon @@ -13,7 +13,7 @@ SUBDIR= adventure arithmetic atc \ dm factor fish fortune gomoku \ hack hals_end hangman hunt larn mille monop morse number \ phantasia pig pom ppt primes quiz \ - rain random robots rogue sail snake tetris trek \ + rain random robots rogue sail snake testpat tetris trek \ wargames warp worm worms wtf wump .if ${MKCXX} != "no" Added files: Index: src/games/testpat/Makefile diff -u /dev/null src/games/testpat/Makefile:1.1 --- /dev/null Sat Jan 2 03:21:39 2021 +++ src/games/testpat/Makefile Sat Jan 2 03:21:39 2021 @@ -0,0 +1,8 @@ +# $NetBSD: Makefile,v 1.1 2021/01/02 03:21:39 nat Exp $ + +PROG= testpat +MAN= testpat.6 +DPADD= ${LIBMATH} ${LIBCURSES} ${LIBTERMINFO} +LDADD= -lcurses -lm -lterminfo + +.include Index: src/games/testpat/testpat.6 diff -u /dev/null src/games/testpat/testpat.6:1.1 --- /dev/null Sat Jan 2 03:21:39 2021 +++ src/games/testpat/testpat.6 Sat Jan 2 03:21:39 2021 @@ -0,0 +1,50 @@ +.\" $NetBSD: testpat.6,v 1.1 2021/01/02 03:21:39 nat Exp $ +.\" +.\" Copyright (c) 2021 Nathanial Sloss +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\"notice, this list of conditions and the following disclaimer. +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd Janurary 2, 2021 +.Dt TESTPAT 6 +.Os +.Sh NAME +.Nm testpat +.Nd display test pattern +.Sh SYNOPSIS +.Nm +.Op title +.Sh DESCRIPTION +The +.Nm +command displays a test pattern on a color capable terminal using +.Xr curses 3 . + +Title is a string to display as the title of the test pattern. +.Sh SEE ALSO +.Xr curses 3 +.Sh HISTORY +.Nm +appeared in +.Nx 10.0 . +.Sh AUTHORS +Nathanial Sloss Index: src/games/testpat/testpat.c diff -u /dev/null src/games/testpat/testpat.c:1.1 --- /dev/null Sat Jan 2 03:21:39 2021 +++ src/games/testpat/testpat.c Sat Jan 2 03:21:39 2021 @@ -0,0 +1,459 @@ +/* $NetBSD: testpat.c,v 1.1 2021/01/02 03:21:39 nat Exp $ */ + +/*- + * Copyright (c) 2016 Nathanial Sloss + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +
CVS commit: src/games/backgammon/common_source
Module Name:src Committed By: dholland Date: Sun Dec 6 11:41:47 UTC 2020 Modified Files: src/games/backgammon/common_source: back.h Log Message: speed limit 80 To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/games/backgammon/common_source/back.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/backgammon/common_source/back.h diff -u src/games/backgammon/common_source/back.h:1.21 src/games/backgammon/common_source/back.h:1.22 --- src/games/backgammon/common_source/back.h:1.21 Wed Apr 22 23:36:26 2020 +++ src/games/backgammon/common_source/back.h Sun Dec 6 11:41:47 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: back.h,v 1.21 2020/04/22 23:36:26 joerg Exp $ */ +/* $NetBSD: back.h,v 1.22 2020/12/06 11:41:47 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -46,7 +46,12 @@ #define rnum(r) (random()%r) #define D0 dice[0] #define D1 dice[1] -#define mswap(m) {(m)->D0 ^= (m)->D1; (m)->D1 ^= (m)->D0; (m)->D0 ^= (m)->D1; (m)->d0 = 1-(m)->d0;} +#define mswap(m) { \ + (m)->D0 ^= (m)->D1; \ + (m)->D1 ^= (m)->D0; \ + (m)->D0 ^= (m)->D1; \ + (m)->d0 = 1-(m)->d0; \ +} struct move { int dice[2]; /* value of dice */ @@ -121,7 +126,7 @@ extern char cin[100]; /* input line of c extern const char *const color[]; /* colors as strings */ extern const char *const *colorptr; /* color of current player */ -extern const char *const *Colorptr; /* color of current player, capitalized */ +extern const char *const *Colorptr; /* ditto, capitalized */ extern int colen; /* length of color of current player */ extern int buffnum;
CVS commit: src/games/battlestar
Module Name:src Committed By: dholland Date: Sun Dec 6 11:35:27 UTC 2020 Modified Files: src/games/battlestar: globals.c Log Message: speed limit 80 To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/games/battlestar/globals.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/battlestar/globals.c diff -u src/games/battlestar/globals.c:1.19 src/games/battlestar/globals.c:1.20 --- src/games/battlestar/globals.c:1.19 Thu Aug 7 09:37:02 2003 +++ src/games/battlestar/globals.c Sun Dec 6 11:35:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: globals.c,v 1.19 2003/08/07 09:37:02 agc Exp $ */ +/* $NetBSD: globals.c,v 1.20 2020/12/06 11:35:27 dholland Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)globals.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: globals.c,v 1.19 2003/08/07 09:37:02 agc Exp $"); +__RCSID("$NetBSD: globals.c,v 1.20 2020/12/06 11:35:27 dholland Exp $"); #endif #endif/* not lint */ @@ -67,7 +67,8 @@ const char *const objdes[NUMOFOBJECTS] "A dead woodsman has fallen here. He was savagely murdered.", "A heavy wooden mallet lies nearby.", "There is a laser pistol here.", - "A flower-like young goddess is bathing in the hot mineral pools. She is \nwatching you, but continues to steep and sing softly.", + "A flower-like young goddess is bathing in the hot mineral pools. She " + "is \nwatching you, but continues to steep and sing softly.", "The goddess is reclining on a bed of ferns and studying you intently.", "There is a grenade here.", "There is a length of heavy chain here.", @@ -78,7 +79,8 @@ const char *const objdes[NUMOFOBJECTS] "A long, sharp halberd is propped up here.", "There is a compass here.", "Wreckage and smoldering debris from a crash litter the ground here.", - "A woodland Elf armed with a shield and deadly halberd lunges toward you!", + "A woodland Elf armed with a shield and deadly halberd lunges toward " + "you!", "I think I hear footsteps behind us.", "There are a few coins here.", "There are some matches here.", @@ -91,15 +93,28 @@ const char *const objdes[NUMOFOBJECTS] "There is a sparkling diamond ring here.", "There is a colorful pink potion in a small crystal vial here.", "A gold bracelet is on the ground here.", - "A swarthy woman with stern features pulls you aside from the crowd,\n'I must talk to you -- but not here. Meet me at midnight in the gardens.'", - "The swarthy woman has been awaiting you anxiously. 'I must warn you that the\nIsland has anticipated your Quest. You will not be welcomed. The Darkness is\nstrong where you must search. Seek not the shadows save only at night, for\nthen are they the weakest. In the mountains far from here a canyon winds\nwith ferns and streams and forgotten vines. There you must go. Take this\nrope.'", - "Out from the shadows a figure leaps! His black cape swirls around, and he\nholds a laser sword at your chest. 'So, you have come to fulfill the Quest.\nHa! Your weapons are no match for me!'", - "An old-timer with one eye missing and no money for a drink sits at the bar.", + "A swarthy woman with stern features pulls you aside from the crowd,\n" + "'I must talk to you -- but not here. " + "Meet me at midnight in the gardens.'", + "The swarthy woman has been awaiting you anxiously. 'I must warn you " + "that the\nIsland has anticipated your Quest. You will not be " + "welcomed. The Darkness is\nstrong where you must search. Seek" + " not the shadows save only at night, for\nthen are they the " + "weakest. In the mountains far from here a canyon winds\nwith " + "ferns and streams and forgotten vines. There you must go. " + "Take this\nrope.'", + "Out from the shadows a figure leaps! His black cape swirls around," + " and he\nholds a laser sword at your chest. 'So, you have" + " come to fulfill the Quest.\nHa! Your weapons are no match for" + " me!'", + "An old-timer with one eye missing and no money for a drink sits at the" + " bar.", "You are flying through an asteroid field!", "A planet is nearby.", "The ground is charred here.", "There is a thermonuclear warhead here.", - "The fragile, beautiful young goddess lies here. You murdered her horribly.", + "The fragile, beautiful young goddess lies here. You murdered her " + "horribly.", "The old-timer is lying here. He is dead.", "The native girl's body is lying here.", "A native girl is sitting here.",
CVS commit: src/games/warp
Module Name:src Committed By: rin Date: Sat Nov 21 09:24:02 UTC 2020 Modified Files: src/games/warp: util.h Log Message: roundsleep(): Too many zeros; tv_nsec should be compared with 500 msec, not 5000. Raised by clang for ILP32 archs. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/games/warp/util.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/util.h diff -u src/games/warp/util.h:1.6 src/games/warp/util.h:1.7 --- src/games/warp/util.h:1.6 Thu Nov 12 22:23:16 2020 +++ src/games/warp/util.h Sat Nov 21 09:24:02 2020 @@ -18,7 +18,7 @@ /* we get fractions of seconds from calling ftime on timebuf */ extern struct timespec timebuf; -#define roundsleep(x) (clock_gettime(CLOCK_REALTIME, ),sleep(timebuf.tv_nsec > 50 ?x+1:x)) +#define roundsleep(x) (clock_gettime(CLOCK_REALTIME, ),sleep(timebuf.tv_nsec > (500 * 1000 * 1000) ?x+1:x)) #define waiting 0
CVS commit: src/games/warp
Module Name:src Committed By: joerg Date: Thu Nov 12 22:23:16 UTC 2020 Modified Files: src/games/warp: intrp.c score.h sig.h util.c util.h Log Message: Avoid common symbols. Use __dead. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/games/warp/intrp.c cvs rdiff -u -r1.4 -r1.5 src/games/warp/score.h src/games/warp/sig.h cvs rdiff -u -r1.5 -r1.6 src/games/warp/util.c src/games/warp/util.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/intrp.c diff -u src/games/warp/intrp.c:1.6 src/games/warp/intrp.c:1.7 --- src/games/warp/intrp.c:1.6 Wed Nov 11 19:55:33 2020 +++ src/games/warp/intrp.c Thu Nov 12 22:23:16 2020 @@ -32,7 +32,7 @@ static char *getrealname(uid_t); static char *skipinterp(const char *, const char *); #endif -static void abort_interp(void); +__dead static void abort_interp(void); void intrp_init(char *tcbuf) Index: src/games/warp/score.h diff -u src/games/warp/score.h:1.4 src/games/warp/score.h:1.5 --- src/games/warp/score.h:1.4 Wed Nov 11 19:55:33 2020 +++ src/games/warp/score.h Thu Nov 12 22:23:16 2020 @@ -42,7 +42,7 @@ EXT char longlognam[128]; EXT char c INIT(' '); void score_init(void); -void wscore(void); +__dead void wscore(void); void display_status(void); void wavescore(void); void score(void); Index: src/games/warp/sig.h diff -u src/games/warp/sig.h:1.4 src/games/warp/sig.h:1.5 --- src/games/warp/sig.h:1.4 Tue Nov 10 22:42:19 2020 +++ src/games/warp/sig.h Thu Nov 12 22:23:16 2020 @@ -8,8 +8,8 @@ void sig_init(void); void mytstp(void); -void finalize(int status); -void sig_catcher(int signo); +__dead void finalize(int status); +__dead void sig_catcher(int signo); #ifdef SIGTSTP void cont_catcher(int x); void stop_catcher(int sig); Index: src/games/warp/util.c diff -u src/games/warp/util.c:1.5 src/games/warp/util.c:1.6 --- src/games/warp/util.c:1.5 Tue Nov 10 23:03:22 2020 +++ src/games/warp/util.c Thu Nov 12 22:23:16 2020 @@ -21,6 +21,8 @@ #include "INTERN.h" #include "util.h" +struct timespec timebuf; + void util_init(void) { Index: src/games/warp/util.h diff -u src/games/warp/util.h:1.5 src/games/warp/util.h:1.6 --- src/games/warp/util.h:1.5 Wed Nov 11 19:55:33 2020 +++ src/games/warp/util.h Thu Nov 12 22:23:16 2020 @@ -17,7 +17,7 @@ /* we get fractions of seconds from calling ftime on timebuf */ -EXT struct timespec timebuf; +extern struct timespec timebuf; #define roundsleep(x) (clock_gettime(CLOCK_REALTIME, ),sleep(timebuf.tv_nsec > 50 ?x+1:x)) #define waiting 0 @@ -37,7 +37,7 @@ EXT int len_last_line_got INIT(0); void util_init(void); void movc3(int, char *, char *); -void no_can_do(const char *); +__dead void no_can_do(const char *); int exdis(int); void *safemalloc(size_t size); char *safecpy(char *, const char *, size_t); @@ -46,6 +46,6 @@ char *instr(const char *, const char *); #ifdef SETUIDGID int eaccess(const char *, mode_t); #endif -void prexit(const char *); +__dead void prexit(const char *); char *savestr(const char *); char *getval(const char *, const char *);
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Wed Nov 11 20:04:02 UTC 2020 Modified Files: src/games/warp: Makefile Log Message: Comment out debugging build (it still randomly crashes though) pointed out by wiz To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/games/warp/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/Makefile diff -u src/games/warp/Makefile:1.4 src/games/warp/Makefile:1.5 --- src/games/warp/Makefile:1.4 Wed Nov 11 14:54:53 2020 +++ src/games/warp/Makefile Wed Nov 11 15:04:02 2020 @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.4 2020/11/11 19:54:53 christos Exp $ +# $NetBSD: Makefile,v 1.5 2020/11/11 20:04:02 christos Exp $ .include PROG= warp -DBG=-g +#DBG=-g SRCS= bang.c init.c intrp.c move.c object.c play.c score.c sig.c term.c \ them.c us.c util.c version.c warp.c weapon.c
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Wed Nov 11 19:55:33 UTC 2020 Modified Files: src/games/warp: config.h config.h.SH config.sh init.c intrp.c score.c score.h sig.c term.c util.h warp.c Log Message: use strchr, strrchr, random, more lint removal, savefile in /var/games/warp not /usr/share/games/warp... To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/games/warp/config.h src/games/warp/sig.c \ src/games/warp/util.h cvs rdiff -u -r1.2 -r1.3 src/games/warp/config.h.SH cvs rdiff -u -r1.1 -r1.2 src/games/warp/config.sh cvs rdiff -u -r1.3 -r1.4 src/games/warp/init.c src/games/warp/score.h cvs rdiff -u -r1.5 -r1.6 src/games/warp/intrp.c src/games/warp/score.c cvs rdiff -u -r1.6 -r1.7 src/games/warp/term.c src/games/warp/warp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/config.h diff -u src/games/warp/config.h:1.4 src/games/warp/config.h:1.5 --- src/games/warp/config.h:1.4 Wed Nov 11 12:11:19 2020 +++ src/games/warp/config.h Wed Nov 11 14:55:33 2020 @@ -85,12 +85,6 @@ */ #define PREFSHELL "/bin/csh" /**/ -/* RANDBITS: - * This symbol contains the number of bits of random number the rand() - * function produces. Usual values are 15, 16, and 31. - */ -#define RANDBITS 15 /**/ - /* ROOTID: * This symbol contains the uid of root, normally 0. */ Index: src/games/warp/sig.c diff -u src/games/warp/sig.c:1.4 src/games/warp/sig.c:1.5 --- src/games/warp/sig.c:1.4 Tue Nov 10 17:42:19 2020 +++ src/games/warp/sig.c Wed Nov 11 14:55:33 2020 @@ -25,9 +25,6 @@ void sig_init(void) { -#ifdef lint -; -#else sigignore(SIGINT); /* for inquiry of existence via kill call */ #ifdef SIGTTOU sigignore(SIGTTOU); @@ -38,8 +35,10 @@ sig_init(void) sigset(SIGQUIT, sig_catcher); sigset(SIGILL, sig_catcher); sigset(SIGFPE, sig_catcher); +#if 0 sigset(SIGBUS, sig_catcher); sigset(SIGSEGV, sig_catcher); +#endif sigset(SIGSYS, sig_catcher); sigset(SIGTERM, sig_catcher); } @@ -53,7 +52,6 @@ sig_init(void) sigset(SIGTSTP, stop_catcher); sigset(SIGSTOP, stop_catcher); #endif -#endif /* lint */ } #ifdef SIGTSTP Index: src/games/warp/util.h diff -u src/games/warp/util.h:1.4 src/games/warp/util.h:1.5 --- src/games/warp/util.h:1.4 Tue Nov 10 17:42:19 2020 +++ src/games/warp/util.h Wed Nov 11 14:55:33 2020 @@ -6,49 +6,19 @@ * */ -#if RANDBITS < 15 || defined(lint) -#define rand_mod(m) getpid() -#define RANDRAND 0.0 -#define HALFRAND 0 -#define myrand() getpid() -#else -#if RANDBITS == 15 /* 15 bits of rand()? */ -#define RANDRAND 268435456.0 /* that's 2**28 */ -#define HALFRAND 0x4000 /* that's 2**14 */ -int rand(void); -#define myrand() (rand()&32767) -#define rand_mod(m) ((int)((double)myrand() / 32768.0 * ((double)(m -/* pick number in 0..m-1 */ - -#else - -#if RANDBITS < 31 /* 16 bits of rand()? */ -#define RANDRAND 1073741824.0 /* that's 2**30 */ -#define HALFRAND 0x8000 /* that's 2**15 */ -unsigned rand(); -#define myrand() (rand()&65535) -#define rand_mod(m) ((int)((double)myrand() / 65536.0 * ((double)(m -/* pick number in 0..m-1 */ - -#else /* assume 31 bits */ #define RANDRAND 1152921504606846976.0 /* that's 2**60 */ #define HALFRAND 0x4000 /* that's 2**30 */ -long rand(); -#define myrand() rand() +#define myrand() (int)random() #define rand_mod(m) ((myrand() / 37) % (m)) /* pick number in 0..m-1 */ /* * The reason for the /37 above is that our random number generator yields * successive evens and odds, for some reason. This makes strange star maps. */ -#endif -#endif -#endif - /* we get fractions of seconds from calling ftime on timebuf */ -EXT struct timeb timebuf; -#define roundsleep(x) (ftime(),sleep(timebuf.millitm > 500?x+1:x)) +EXT struct timespec timebuf; +#define roundsleep(x) (clock_gettime(CLOCK_REALTIME, ),sleep(timebuf.tv_nsec > 50 ?x+1:x)) #define waiting 0 Index: src/games/warp/config.h.SH diff -u src/games/warp/config.h.SH:1.2 src/games/warp/config.h.SH:1.3 --- src/games/warp/config.h.SH:1.2 Tue Nov 10 17:42:19 2020 +++ src/games/warp/config.h.SH Wed Nov 11 14:55:33 2020 @@ -87,16 +87,16 @@ cat
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Wed Nov 11 19:54:54 UTC 2020 Modified Files: src/games/warp: Makefile Log Message: no need for -lcompat To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/games/warp/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/Makefile diff -u src/games/warp/Makefile:1.3 src/games/warp/Makefile:1.4 --- src/games/warp/Makefile:1.3 Wed Nov 11 12:11:19 2020 +++ src/games/warp/Makefile Wed Nov 11 14:54:53 2020 @@ -1,14 +1,15 @@ -# $NetBSD: Makefile,v 1.3 2020/11/11 17:11:19 christos Exp $ +# $NetBSD: Makefile,v 1.4 2020/11/11 19:54:53 christos Exp $ .include PROG= warp +DBG=-g SRCS= bang.c init.c intrp.c move.c object.c play.c score.c sig.c term.c \ them.c us.c util.c version.c warp.c weapon.c -DPADD= ${LIBTERMLIB} ${LIBM} ${LIBCOMPAT} -LDADD= -ltermlib -lm -lcompat +DPADD= ${LIBTERMLIB} ${LIBM} +LDADD= -ltermlib -lm CPPFLAGS+=-DHAVETERMLIB @@ -18,9 +19,6 @@ HIDEGAME=hidegame SETGIDGAME=yes MAN= warp.6 -BINGRP= games -BINMODE=2555 - warp.6: ${_MKTARGET_CREATE} cat ${.CURDIR}/warp.man > ${.TARGET} @@ -69,14 +67,4 @@ FILES+=warp.doc warp.news README FILESDIR=/usr/share/games/warp .endif -CFLAGS+= -Wno-error=old-style-definition -Wno-error=strict-prototypes -CFLAGS+= -Wno-error=comment -Wno-error=maybe-uninitialized -CFLAGS+= -Wno-error=discarded-qualifiers -Wno-error=dangling-else -CFLAGS+= -Wno-error=char-subscripts -Wno-error=parentheses -CFLAGS+= -Wno-error=unused-value -Wno-error=format-extra-args -CFLAGS+= -Wno-error=format-overflow= -Wno-error=builtin-declaration-mismatch -CFLAGS+= -Wno-error=format= -Wno-error=sign-compare -Wno-error=return-type -CFLAGS+= -Wno-error=unused-label -Wno-error=unused-variable -CFLAGS+= -Wno-error=format-nonliteral -Wno-error=implicit-fallthrough= - .include
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Wed Nov 11 17:11:19 UTC 2020 Modified Files: src/games/warp: Makefile config.h intrp.c score.c term.c term.h warp.h Log Message: - use termios - enable setgid games - enable savedir To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/games/warp/Makefile cvs rdiff -u -r1.3 -r1.4 src/games/warp/config.h cvs rdiff -u -r1.4 -r1.5 src/games/warp/intrp.c src/games/warp/score.c \ src/games/warp/term.h src/games/warp/warp.h cvs rdiff -u -r1.5 -r1.6 src/games/warp/term.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/Makefile diff -u src/games/warp/Makefile:1.2 src/games/warp/Makefile:1.3 --- src/games/warp/Makefile:1.2 Tue Nov 10 03:49:08 2020 +++ src/games/warp/Makefile Wed Nov 11 12:11:19 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.2 2020/11/10 08:49:08 kamil Exp $ +# $NetBSD: Makefile,v 1.3 2020/11/11 17:11:19 christos Exp $ .include @@ -18,6 +18,9 @@ HIDEGAME=hidegame SETGIDGAME=yes MAN= warp.6 +BINGRP= games +BINMODE=2555 + warp.6: ${_MKTARGET_CREATE} cat ${.CURDIR}/warp.man > ${.TARGET} Index: src/games/warp/config.h diff -u src/games/warp/config.h:1.3 src/games/warp/config.h:1.4 --- src/games/warp/config.h:1.3 Tue Nov 10 17:42:19 2020 +++ src/games/warp/config.h Wed Nov 11 12:11:19 2020 @@ -20,12 +20,12 @@ */ #define SIGNEDCHAR /**/ -/* TERMIO: +/* TERMIOS: * This symbol, if defined, indicates that the program should include * termio.h rather than sgtty.h. There are also differences in the * ioctl() calls that depend on the value of this symbol. */ -#undef TERMIO /**/ +#define TERMIOS /**/ /* USENDIR: * This symbol, if defined, indicates that the program should compile Index: src/games/warp/intrp.c diff -u src/games/warp/intrp.c:1.4 src/games/warp/intrp.c:1.5 --- src/games/warp/intrp.c:1.4 Tue Nov 10 17:42:19 2020 +++ src/games/warp/intrp.c Wed Nov 11 12:11:19 2020 @@ -568,7 +568,7 @@ getrealname(uid_t uid) if (fork()) wait(0); else { - setuid(getuid()); + setgid(getgid()); if ((tmpfp = fopen(filexp(FULLNAMEFILE),"w")) == NULL) exit(1); fprintf(tmpfp, "%s\n", buf); Index: src/games/warp/score.c diff -u src/games/warp/score.c:1.4 src/games/warp/score.c:1.5 --- src/games/warp/score.c:1.4 Tue Nov 10 17:42:19 2020 +++ src/games/warp/score.c Wed Nov 11 12:11:19 2020 @@ -35,20 +35,18 @@ score_init(void) int i; FILE *savfil; -#if 0 if (stat(SAVEDIR,)) { printf("Cannot access %s\r\n",SAVEDIR); finalize(1); } -if (filestat.st_uid != geteuid()) { - printf("Warp will not run right without being setuid.\r\n"); +if (filestat.st_gid != getegid()) { + printf("Warp will not run right without being setgid.\r\n"); finalize(1); } if ((filestat.st_mode & 0605) != 0605) { printf("%s is not protected correctly (must be u+rw o+rx).\r\n",SAVEDIR); finalize(1); } -#endif #ifdef SCOREFULL interp(longlognam, sizeof longlognam, "%N"); @@ -241,9 +239,7 @@ wscore(void) printf("WHO SCORE DF CDF E B WV FLAGS\r\n"); resetty(); snprintf(spbuf, sizeof(spbuf), "/bin/cat %ssave.*",SAVEDIR); -#ifndef lint execl("/bin/sh", "sh", "-c", spbuf, NULL); -#endif finalize(1); } @@ -421,10 +417,8 @@ wavescore(void) snprintf(spbuf, sizeof(spbuf), "Star save ratio: %1.8f (%d/%d)", starscore, numstars, inumstars); mvaddstr( 6,5, spbuf); -#ifndef lint bonuses += tmp = (long) (((double)curscore / possiblescore) * (starscore*starscore) * smarts * 20); -#endif snprintf(spbuf, sizeof(spbuf), "%6ld", tmp); mvaddstr( 6, 68, spbuf); row = 7; Index: src/games/warp/term.h diff -u src/games/warp/term.h:1.4 src/games/warp/term.h:1.5 --- src/games/warp/term.h:1.4 Tue Nov 10 17:42:19 2020 +++ src/games/warp/term.h Wed Nov 11 12:11:19 2020 @@ -181,9 +181,16 @@ EXT char INTRCH INIT('\03'); /* stuff wanted by terminal mode diddling routines */ -#ifdef TERMIO +#ifdef TERMIOS +EXT struct termios _tty, _oldtty; +#elif defined(TERMIO) +typedef int speed_t; EXT struct termio _tty, _oldtty; +#define tcsetattr(fd, how, ti) ioctl(fd, how, ti) +#define tcgetattr(fd, ti) ioctl(fd, TCGETA, ti) +#define cfgetospeed(ti) ((ti)->c_cflag & CBAUD) #else +typedef int speed_t; EXT struct sgttyb _tty; EXT int _res_flg INIT(0); #endif @@ -193,18 +200,18 @@ EXT bool bizarre INIT(false); /* do we /* terminal mode diddling routines */ -#ifdef TERMIO +#if defined(TERMIO) || defined(TERMIOS) -#define raw() ((bizarre=1),_tty.c_lflag &=~ISIG,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty)) -#define noraw() ((bizarre=1),_tty.c_lflag |= ISIG,_tty.c_cc[VEOF] = CEOF,ioctl(_tty_ch,TCSETAF,&_tty)) -#define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty)) -#define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF]
CVS commit: src/games/warp
Module Name:src Committed By: kamil Date: Wed Nov 11 11:54:42 UTC 2020 Modified Files: src/games/warp: warp.c Log Message: Fix the old leftover license note Larry Wall: "I outgrew commercial-free licensing about 30 years ago." To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/games/warp/warp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/warp.c diff -u src/games/warp/warp.c:1.5 src/games/warp/warp.c:1.6 --- src/games/warp/warp.c:1.5 Tue Nov 10 22:52:32 2020 +++ src/games/warp/warp.c Wed Nov 11 11:54:42 2020 @@ -5,17 +5,33 @@ char rcsid[] = "@(#)Header: warp.c,v 7.0 * helpers: Jonathan and Mark Biggar, and Dan Faigin * special thanks to my sweetie Gloria who suggested the Planet Crusher * - * Copyright (C) 1986, Larry Wall - * - * This program may be copied as long as this copyright notice is - * included, and as long as it is not being copied for purposes - * of profit. If you want to modify this program in any way other - * than normal configuration changes, common decency would suggest - * that you also modify the name of the program so that my good name - * (what there is of it) is not impugned. (Calling it something like - * "warpx" or "superwarp" would be fine.) Also, give it another - * WARPDIR so that the scoreboards don't get confused. - * + * Copyright (c) 2020 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Larry Wall. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * * version 5.0 04/20/83 * 5.1 05/05/83 various tidbits * 5.2 05/12/83 VAX -> vax, ifdef'ed a SIGCONT
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Tue Nov 10 23:32:33 UTC 2020 Modified Files: src/games/warp: play.c Log Message: remove error(1) comments To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/games/warp/play.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/play.c diff -u src/games/warp/play.c:1.3 src/games/warp/play.c:1.4 --- src/games/warp/play.c:1.3 Tue Nov 10 17:42:19 2020 +++ src/games/warp/play.c Tue Nov 10 18:32:33 2020 @@ -138,8 +138,6 @@ play(void) possiblescore += 5000; } if (apolloflag & 2) { -/*###141 [cc] warning: array subscript has type 'char' [-Wchar-subscripts]%%%*/ -/*###141 [cc] warning: array subscript has type 'char' [-Wchar-subscripts]%%%*/ if (blast[realapollo->posy][realapollo->posx] <= 32000) bvely = bvelx = 0; realapollo->energy = 32000;
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Tue Nov 10 23:03:22 UTC 2020 Modified Files: src/games/warp: util.c Log Message: Antivaxer support. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/games/warp/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/util.c diff -u src/games/warp/util.c:1.4 src/games/warp/util.c:1.5 --- src/games/warp/util.c:1.4 Tue Nov 10 17:42:19 2020 +++ src/games/warp/util.c Tue Nov 10 18:03:22 2020 @@ -29,11 +29,6 @@ util_init(void) void movc3(int len, char *src, char *dest) -#ifdef vax -{ -asm("movc3 4(ap),*8(ap),*12(ap)"); -} -#else { if (dest <= src) { for (; len; len--) { @@ -48,7 +43,6 @@ movc3(int len, char *src, char *dest) } } } -#endif void no_can_do(const char *what)
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Tue Nov 10 22:56:49 UTC 2020 Removed Files: src/games/warp: config.H Log Message: can't have config.h and config.H in case-preserving but case-folding file-systems. To generate a diff of this commit: cvs rdiff -u -r1.2 -r0 src/games/warp/config.H Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Tue Nov 10 22:52:46 UTC 2020 Modified Files: src/games/warp: term.c Log Message: don't segv if the terminal is too big. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/games/warp/term.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/term.c diff -u src/games/warp/term.c:1.4 src/games/warp/term.c:1.5 --- src/games/warp/term.c:1.4 Tue Nov 10 17:42:19 2020 +++ src/games/warp/term.c Tue Nov 10 17:52:45 2020 @@ -286,6 +286,8 @@ term_set(char *tcbuf) /* temp area for " no_can_do("dumb"); if (!scorespec && (LINES < 24 || COLS < 80)) no_can_do("puny"); +if (LINES > 25) + no_can_do("humongus"); crmode(); raw();
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Tue Nov 10 22:52:32 UTC 2020 Modified Files: src/games/warp: warp.c Log Message: pray-tell where are you trying to write? To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/games/warp/warp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/warp.c diff -u src/games/warp/warp.c:1.4 src/games/warp/warp.c:1.5 --- src/games/warp/warp.c:1.4 Tue Nov 10 17:42:19 2020 +++ src/games/warp/warp.c Tue Nov 10 17:52:32 2020 @@ -325,7 +325,7 @@ main(int argc, char *argv[]) if (!experimenting) { if ((savfil = fopen(savefilename,"w")) == NULL) { resetty(); - printf("Can't open savefile\r\n"); + printf("Can't open savefile `%s'\r\n", savefilename); finalize(1); } fprintf(savfil,
CVS commit: src/games/warp
Module Name:src Committed By: christos Date: Tue Nov 10 22:42:19 UTC 2020 Modified Files: src/games/warp: bang.c bang.h config.H config.h config.h.SH init.c init.h intrp.c intrp.h move.c move.h object.c object.h play.c play.h score.c score.h sig.c sig.h sm.c term.c term.h them.c them.h us.c us.h util.c util.h version.c version.h warp.c warp.h weapon.c weapon.h Log Message: Time warp forward 34 years so that it compiles (but not work) To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/games/warp/bang.c src/games/warp/bang.h \ src/games/warp/config.h src/games/warp/init.c src/games/warp/init.h \ src/games/warp/intrp.h src/games/warp/move.c src/games/warp/move.h \ src/games/warp/object.c src/games/warp/object.h src/games/warp/play.c \ src/games/warp/play.h src/games/warp/score.h src/games/warp/them.c \ src/games/warp/them.h src/games/warp/us.c src/games/warp/us.h \ src/games/warp/version.h src/games/warp/weapon.c src/games/warp/weapon.h cvs rdiff -u -r1.1 -r1.2 src/games/warp/config.H src/games/warp/config.h.SH cvs rdiff -u -r1.3 -r1.4 src/games/warp/intrp.c src/games/warp/score.c \ src/games/warp/sig.c src/games/warp/sig.h src/games/warp/sm.c \ src/games/warp/term.c src/games/warp/term.h src/games/warp/util.c \ src/games/warp/util.h src/games/warp/version.c src/games/warp/warp.c \ src/games/warp/warp.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/bang.c diff -u src/games/warp/bang.c:1.2 src/games/warp/bang.c:1.3 --- src/games/warp/bang.c:1.2 Mon Nov 9 19:02:11 2020 +++ src/games/warp/bang.c Tue Nov 10 17:42:19 2020 @@ -26,17 +26,15 @@ #include "bang.h" void -bang_init() +bang_init(void) { ; } void -make_plink(y,x) -Reg1 int x; -Reg2 int y; +make_plink(int x, int y) { -Reg3 OBJECT *obj; +OBJECT *obj; move(y+1,x*2,0); beg_qwrite(); @@ -57,11 +55,7 @@ Reg2 int y; } void -make_blast(y,x,mass,size) -Reg1 int x; -Reg2 int y; -int size; -long mass; +make_blast(int x, int y, int size, long mass) { bangy[nxtbang] = y; bangx[nxtbang] = x; @@ -77,7 +71,7 @@ long mass; return; } else if (mass >= 0) { - Reg3 OBJECT *obj; + OBJECT *obj; move(y+1,x*2,0); beg_qwrite(); @@ -107,15 +101,15 @@ long mass; } void -do_bangs() +do_bangs(void) { -Reg1 int x; -Reg2 int y; -Reg3 int i; -Reg4 int j; -Reg7 int k; -Reg5 int lastxy; -Reg6 OBJECT *obj; +int x; +int y; +int i; +int j; +int k; +int lastxy; +OBJECT *obj; /* read blast list and update blast array */ assert(nxtbang >= 0 && nxtbang <= XSIZE * YSIZE); @@ -131,7 +125,7 @@ do_bangs() yblasted[yy[j] = (y+YSIZE00) % YSIZE] |= 1; xblasted[xx[j] = (x+XSIZE00) % XSIZE] |= 1; } - blasted = TRUE; + blasted = true; for (y=lastxy;y>=0;--y) { for (x=lastxy;x>=0;--x) { if (lastxy > 2) { Index: src/games/warp/bang.h diff -u src/games/warp/bang.h:1.2 src/games/warp/bang.h:1.3 --- src/games/warp/bang.h:1.2 Mon Nov 9 19:02:11 2020 +++ src/games/warp/bang.h Tue Nov 10 17:42:19 2020 @@ -24,7 +24,7 @@ EXT int yy[MAXBDIST]; EXT int nxtbang; EXT bool banging; -void make_plink(); -void make_blast(); -void do_bangs(); -void bang_init(); +void bang_init(void); +void make_plink(int, int); +void make_blast(int, int, int, long); +void do_bangs(void); Index: src/games/warp/config.h diff -u src/games/warp/config.h:1.2 src/games/warp/config.h:1.3 --- src/games/warp/config.h:1.2 Tue Nov 10 03:49:08 2020 +++ src/games/warp/config.h Tue Nov 10 17:42:19 2020 @@ -3,7 +3,7 @@ * to find out if there is input pending on an IO channel. Generally * the routine is used only if FIONREAD and O_NDELAY aren't available. */ -#/*undef RDCHK /**/ +#undef RDCHK /**/ /* SCOREFULL: * This symbol, if defined, indicates that any scoreboard kept by the @@ -11,7 +11,7 @@ * to the user's login name. If the user can change his full name he * can enter multiple scores if this is defined. */ -#/*undef SCOREFULL /**/ +#undef SCOREFULL /**/ /* SIGNEDCHAR: * This symbol, if defined, indicates that characters are a signed type. @@ -25,7 +25,7 @@ * termio.h rather than sgtty.h. There are also differences in the * ioctl() calls that depend on the value of this symbol. */ -#/*undef TERMIO /**/ +#undef TERMIO /**/ /* USENDIR: * This symbol, if defined, indicates that the program should compile @@ -35,15 +35,15 @@ * This symbol, if defined, indicates that the program should include the * system's version of ndir.h, rather than the one with this package. */ -#/*undef USENDIR /**/ -#/*undef LIBNDIR /**/ +#undef USENDIR /**/ +#undef LIBNDIR /**/ #define LIBNDIR /* WHOAMI: * This symbol, if defined, indicates that the program may include * whoami.h. */ -#/*undef WHOAMI /**/ +#undef WHOAMI
CVS commit: src/games/warp
Module Name:src Committed By: kamil Date: Tue Nov 10 11:29:29 UTC 2020 Removed Files: src/games/warp: smap.0 smap.1 smap.2 smap.3 smap.4 smap.5 smap.6 smap.7 Log Message: Remove the smap.* files They are generated during the build. To generate a diff of this commit: cvs rdiff -u -r1.1 -r0 src/games/warp/smap.0 src/games/warp/smap.1 \ src/games/warp/smap.2 src/games/warp/smap.3 src/games/warp/smap.4 \ src/games/warp/smap.5 src/games/warp/smap.6 src/games/warp/smap.7 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/games/warp
Module Name:src Committed By: kamil Date: Tue Nov 10 00:02:11 UTC 2020 Modified Files: src/games/warp: EXTERN.h INTERN.h bang.c bang.h init.c init.h intrp.c intrp.h move.c move.h object.c object.h play.c play.h score.c score.h sig.c sig.h sm.c term.c term.h them.c them.h us.c us.h util.c util.h version.c version.h warp.c warp.h weapon.c weapon.h Log Message: Reset CVS keywords To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/games/warp/EXTERN.h src/games/warp/INTERN.h \ src/games/warp/bang.c src/games/warp/bang.h src/games/warp/init.c \ src/games/warp/init.h src/games/warp/intrp.c src/games/warp/intrp.h \ src/games/warp/move.c src/games/warp/move.h src/games/warp/object.c \ src/games/warp/object.h src/games/warp/play.c src/games/warp/play.h \ src/games/warp/score.c src/games/warp/score.h src/games/warp/sig.c \ src/games/warp/sig.h src/games/warp/sm.c src/games/warp/term.c \ src/games/warp/term.h src/games/warp/them.c src/games/warp/them.h \ src/games/warp/us.c src/games/warp/us.h src/games/warp/util.c \ src/games/warp/util.h src/games/warp/version.c src/games/warp/version.h \ src/games/warp/warp.c src/games/warp/warp.h src/games/warp/weapon.c \ src/games/warp/weapon.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/warp/EXTERN.h diff -u src/games/warp/EXTERN.h:1.1 src/games/warp/EXTERN.h:1.2 --- src/games/warp/EXTERN.h:1.1 Mon Nov 9 23:37:05 2020 +++ src/games/warp/EXTERN.h Tue Nov 10 00:02:11 2020 @@ -1,24 +1,6 @@ -/* $Header: /cvsroot/src/games/warp/EXTERN.h,v 1.1 2020/11/09 23:37:05 kamil Exp $ - * - * $Log: EXTERN.h,v $ - * Revision 1.1 2020/11/09 23:37:05 kamil - * Add Warp Kit, Version 7.0 by Larry Wall - * - * Warp is a real-time space war game that doesn't get boring very quickly. - * Read warp.doc and the manual page for more information. - * - * games/warp originally distributed with 4.3BSD-Reno, is back to the BSD - * world via NetBSD. Its remnants were still mentioned in games/Makefile. - * - * Larry Wall, the original author and the copyright holder, generously - * donated the game and copyright to The NetBSD Foundation, Inc. - * - * Import the game sources as-is from 4.3BSD-Reno, with the cession - * of the copyright and license to BSD-2-clause NetBSD-style. - * - * Signed-off-by: Larry Wall - * Signed-off-by: Kamil Rytarowski +/* Header: EXTERN.h,v 7.0.1.1 86/12/12 16:46:50 lwall Exp * + * Log: EXTERN.h,v * Revision 7.0.1.1 86/12/12 16:46:50 lwall * Guarded the undefs. * Index: src/games/warp/INTERN.h diff -u src/games/warp/INTERN.h:1.1 src/games/warp/INTERN.h:1.2 --- src/games/warp/INTERN.h:1.1 Mon Nov 9 23:37:05 2020 +++ src/games/warp/INTERN.h Tue Nov 10 00:02:11 2020 @@ -1,24 +1,6 @@ -/* $Header: /cvsroot/src/games/warp/INTERN.h,v 1.1 2020/11/09 23:37:05 kamil Exp $ - * - * $Log: INTERN.h,v $ - * Revision 1.1 2020/11/09 23:37:05 kamil - * Add Warp Kit, Version 7.0 by Larry Wall - * - * Warp is a real-time space war game that doesn't get boring very quickly. - * Read warp.doc and the manual page for more information. - * - * games/warp originally distributed with 4.3BSD-Reno, is back to the BSD - * world via NetBSD. Its remnants were still mentioned in games/Makefile. - * - * Larry Wall, the original author and the copyright holder, generously - * donated the game and copyright to The NetBSD Foundation, Inc. - * - * Import the game sources as-is from 4.3BSD-Reno, with the cession - * of the copyright and license to BSD-2-clause NetBSD-style. - * - * Signed-off-by: Larry Wall - * Signed-off-by: Kamil Rytarowski +/* Header: INTERN.h,v 7.0.1.1 86/12/12 16:51:45 lwall Exp * + * Log: INTERN.h,v * Revision 7.0.1.1 86/12/12 16:51:45 lwall * Guarded the undefs. * Index: src/games/warp/bang.c diff -u src/games/warp/bang.c:1.1 src/games/warp/bang.c:1.2 --- src/games/warp/bang.c:1.1 Mon Nov 9 23:37:05 2020 +++ src/games/warp/bang.c Tue Nov 10 00:02:11 2020 @@ -1,24 +1,6 @@ -/* $Header: /cvsroot/src/games/warp/bang.c,v 1.1 2020/11/09 23:37:05 kamil Exp $ */ +/* Header: bang.c,v 7.0.1.3 86/12/12 16:57:00 lwall Exp */ -/* $Log: bang.c,v $ -/* Revision 1.1 2020/11/09 23:37:05 kamil -/* Add Warp Kit, Version 7.0 by Larry Wall -/* -/* Warp is a real-time space war game that doesn't get boring very quickly. -/* Read warp.doc and the manual page for more information. -/* -/* games/warp originally distributed with 4.3BSD-Reno, is back to the BSD -/* world via NetBSD. Its remnants were still mentioned in games/Makefile. -/* -/* Larry Wall, the original author and the copyright holder, generously -/* donated the game and copyright to The NetBSD Foundation, Inc. -/* -/* Import the game sources as-is from 4.3BSD-Reno, with the cession -/* of the copyright and license to BSD-2-clause NetBSD-style. -/* -/* Signed-off-by: Larry Wall -/* Signed-off-by: Kamil
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: dholland Date: Mon Nov 9 03:23:15 UTC 2020 Modified Files: src/games/fortune/datfiles: fortunes Log Message: Restore the catman joke. It needs the (8), or it fails to work for people who don't know or had forgotten catman(8) was ever a thing. as the de facto fortunes editor and also I think the person who added that fortune in the first place, and given the discussion in tech-userlevel, I think I get to do this. To generate a diff of this commit: cvs rdiff -u -r1.95 -r1.96 src/games/fortune/datfiles/fortunes Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/fortunes diff -u src/games/fortune/datfiles/fortunes:1.95 src/games/fortune/datfiles/fortunes:1.96 --- src/games/fortune/datfiles/fortunes:1.95 Mon Nov 9 00:46:00 2020 +++ src/games/fortune/datfiles/fortunes Mon Nov 9 03:23:14 2020 @@ -16177,7 +16177,7 @@ be named Eustace Clarence Scrubb. % Never leave a macassar and an antimacassar in the same room together. % -Why did the furry install Unix? Because it supports catman. +Why did the furry install Unix? Because it supports catman(8). % Many people don't realize that trailhead doggerel is illegal -- but surely you've heard of "hike rhymes and misdemeanors"...
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: kamil Date: Mon Nov 9 00:46:00 UTC 2020 Modified Files: src/games/fortune/datfiles: fortunes Log Message: Revert to the original phrasing, but remove the man 8 section reference. catman is a historical Unix tool. To generate a diff of this commit: cvs rdiff -u -r1.94 -r1.95 src/games/fortune/datfiles/fortunes Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/fortunes diff -u src/games/fortune/datfiles/fortunes:1.94 src/games/fortune/datfiles/fortunes:1.95 --- src/games/fortune/datfiles/fortunes:1.94 Sun Nov 8 17:37:29 2020 +++ src/games/fortune/datfiles/fortunes Mon Nov 9 00:46:00 2020 @@ -16177,7 +16177,7 @@ be named Eustace Clarence Scrubb. % Never leave a macassar and an antimacassar in the same room together. % -Why did the furry install Unix? Because it supported catman(8). +Why did the furry install Unix? Because it supports catman. % Many people don't realize that trailhead doggerel is illegal -- but surely you've heard of "hike rhymes and misdemeanors"...
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: kamil Date: Sun Nov 8 17:37:30 UTC 2020 Modified Files: src/games/fortune/datfiles: fortunes Log Message: catman(8) is a past thing To generate a diff of this commit: cvs rdiff -u -r1.93 -r1.94 src/games/fortune/datfiles/fortunes Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/fortunes diff -u src/games/fortune/datfiles/fortunes:1.93 src/games/fortune/datfiles/fortunes:1.94 --- src/games/fortune/datfiles/fortunes:1.93 Fri Oct 30 04:56:32 2020 +++ src/games/fortune/datfiles/fortunes Sun Nov 8 17:37:29 2020 @@ -16177,7 +16177,7 @@ be named Eustace Clarence Scrubb. % Never leave a macassar and an antimacassar in the same room together. % -Why did the furry install Unix? Because it supports catman(8). +Why did the furry install Unix? Because it supported catman(8). % Many people don't realize that trailhead doggerel is illegal -- but surely you've heard of "hike rhymes and misdemeanors"...
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: simonb Date: Fri Oct 30 04:56:32 UTC 2020 Modified Files: src/games/fortune/datfiles: fortunes Log Message: Add one. To generate a diff of this commit: cvs rdiff -u -r1.92 -r1.93 src/games/fortune/datfiles/fortunes Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/fortunes diff -u src/games/fortune/datfiles/fortunes:1.92 src/games/fortune/datfiles/fortunes:1.93 --- src/games/fortune/datfiles/fortunes:1.92 Wed Aug 19 02:19:06 2020 +++ src/games/fortune/datfiles/fortunes Fri Oct 30 04:56:32 2020 @@ -16304,3 +16304,6 @@ b) on "typo" ! -- John Lions, Australian UNIX Users Group Newsletter, Oct 1978 % The purpose of computing numbers is not yet in sight +% +Iamonthemoonandthereisnowheretogetabeer. +Thereisnospacebar.
CVS commit: src/games/rain
Module Name:src Committed By: nia Date: Wed Oct 14 18:32:04 UTC 2020 Modified Files: src/games/rain: rain.6 rain.c Log Message: rain(6): Make the default delay useful for modern terminals To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/games/rain/rain.6 cvs rdiff -u -r1.21 -r1.22 src/games/rain/rain.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/rain/rain.6 diff -u src/games/rain/rain.6:1.12 src/games/rain/rain.6:1.13 --- src/games/rain/rain.6:1.12 Thu Sep 15 02:09:41 2005 +++ src/games/rain/rain.6 Wed Oct 14 18:32:04 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: rain.6,v 1.12 2005/09/15 02:09:41 wiz Exp $ +.\" $NetBSD: rain.6,v 1.13 2020/10/14 18:32:04 nia Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)rain.6 8.1 (Berkeley) 5/31/93 .\" -.Dd May 31, 1993 +.Dd October 14, 2020 .Dt RAIN 6 .Os .Sh NAME @@ -44,11 +44,12 @@ The output of is modeled after the .Tn VAX/VMS program of the same name. -To obtain the proper effect, either the terminal must be set for 9600 -baud or the -.Fl d -option must be used to specify a delay, in milliseconds, between each -update. -A reasonable delay is 120; the default is 0. +.Bl -tag -width Ds +.It Fl d +Delay between updates (in milliseconds). +If the terminal is faster than 9600 baud, must be set to non-zero to +obtain a proper rain effect. +The default is 120. +.El .Sh AUTHORS .An Eric P. Scott Index: src/games/rain/rain.c diff -u src/games/rain/rain.c:1.21 src/games/rain/rain.c:1.22 --- src/games/rain/rain.c:1.21 Fri Aug 8 16:10:47 2008 +++ src/games/rain/rain.c Wed Oct 14 18:32:04 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: rain.c,v 1.21 2008/08/08 16:10:47 drochner Exp $ */ +/* $NetBSD: rain.c,v 1.22 2020/10/14 18:32:04 nia Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)rain.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: rain.c,v 1.21 2008/08/08 16:10:47 drochner Exp $"); +__RCSID("$NetBSD: rain.c,v 1.22 2020/10/14 18:32:04 nia Exp $"); #endif #endif /* not lint */ @@ -69,7 +69,7 @@ main(int argc, char **argv) { int x, y, j; long cols, lines; - unsigned int delay = 0; + unsigned int delay = 12; unsigned long val = 0; int ch; char *ep;
CVS commit: src/games/worms
Module Name:src Committed By: nia Date: Wed Oct 14 07:32:53 UTC 2020 Modified Files: src/games/worms: worms.6 worms.c Log Message: worms(6): Use a reasonable default delay for non-1980s terminals. This is still fast, but not unreasonably fast. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/games/worms/worms.6 cvs rdiff -u -r1.22 -r1.23 src/games/worms/worms.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/worms/worms.6 diff -u src/games/worms/worms.6:1.15 src/games/worms/worms.6:1.16 --- src/games/worms/worms.6:1.15 Sun Aug 12 17:30:03 2012 +++ src/games/worms/worms.6 Wed Oct 14 07:32:53 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: worms.6,v 1.15 2012/08/12 17:30:03 wiz Exp $ +.\" $NetBSD: worms.6,v 1.16 2020/10/14 07:32:53 nia Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)worms.6 8.1 (Berkeley) 5/31/93 .\" -.Dd July 31, 2012 +.Dd October 14, 2020 .Dt WORMS 6 .Os .Sh NAME @@ -56,7 +56,7 @@ Specifies as a delay, in milliseconds, between each update. This is useful for fast terminals. Reasonable values are around 20-200; -the default is 0. +the default is 20. .It Fl f Makes a .Dq field Index: src/games/worms/worms.c diff -u src/games/worms/worms.c:1.22 src/games/worms/worms.c:1.23 --- src/games/worms/worms.c:1.22 Tue Jun 19 05:46:09 2012 +++ src/games/worms/worms.c Wed Oct 14 07:32:53 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: worms.c,v 1.22 2012/06/19 05:46:09 dholland Exp $ */ +/* $NetBSD: worms.c,v 1.23 2020/10/14 07:32:53 nia Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)worms.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: worms.c,v 1.22 2012/06/19 05:46:09 dholland Exp $"); +__RCSID("$NetBSD: worms.c,v 1.23 2020/10/14 07:32:53 nia Exp $"); #endif #endif /* not lint */ @@ -194,7 +194,7 @@ main(int argc, char *argv[]) short **ref; const char *field; char *mp; - unsigned int delay = 0; + unsigned int delay = 2; mp = NULL; length = 16;
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Mon Oct 12 13:54:51 UTC 2020 Modified Files: src/games/factor: factor.c Log Message: - remove duplicate comment - flush after printing the number (from kre@) To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.37 src/games/factor/factor.c:1.38 --- src/games/factor/factor.c:1.37 Sun Oct 11 14:46:21 2020 +++ src/games/factor/factor.c Mon Oct 12 09:54:51 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.37 2020/10/11 18:46:21 christos Exp $ */ +/* $NetBSD: factor.c,v 1.38 2020/10/12 13:54:51 christos Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); #endif #ifdef __RCSID -__RCSID("$NetBSD: factor.c,v 1.37 2020/10/11 18:46:21 christos Exp $"); +__RCSID("$NetBSD: factor.c,v 1.38 2020/10/12 13:54:51 christos Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); @@ -70,7 +70,6 @@ __FBSDID("$FreeBSD: head/usr.bin/factor/ * If the -x flag is specified numbers are printed in hex. * * If no number args are given, the list of numbers are read from stdin. - * If no args are given, the list of numbers are read from stdin. */ #include @@ -225,6 +224,7 @@ pr_fact(BIGNUM *val, int hflag, int xfla } else BN_print_dec_fp(stdout, val); putchar(':'); + fflush(stdout); for (fact = [0]; !BN_is_one(val); ++fact) { /* Look for the smallest factor. */ do {
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Mon Oct 12 13:53:43 UTC 2020 Modified Files: src/games/factor: factor.6 Log Message: more clarifications. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/games/factor/factor.6 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.6 diff -u src/games/factor/factor.6:1.17 src/games/factor/factor.6:1.18 --- src/games/factor/factor.6:1.17 Sun Oct 11 14:48:20 2020 +++ src/games/factor/factor.6 Mon Oct 12 09:53:43 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: factor.6,v 1.17 2020/10/11 18:48:20 christos Exp $ +.\" $NetBSD: factor.6,v 1.18 2020/10/12 13:53:43 christos Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -35,7 +35,7 @@ .\" .\" By Landon Curt Noll, http://www.isthe.com/chongo/index.html /\oo/\ .\" -.Dd October 11, 2020 +.Dd October 12, 2020 .Dt FACTOR 6 .Os .Sh NAME @@ -48,7 +48,8 @@ .Sh DESCRIPTION The .Nm -utility factors integers larger than 1. +utility factors integers larger than +.Dv 0 . When a number is factored, it is printed, followed by a .Dq \&: , and the list of @@ -76,7 +77,10 @@ Numbers may be preceded by a single +. Numbers that start with .Dv 0x are interpreted as hexadecimal. -Integer less than 2 are rejected. +A +.Dv 0 +input exits the program. +Negative numbers are not allowed. Numbers are terminated by a non-digit character (such as a newline). After a number is read, it is factored. Input lines must not be longer than
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Sun Oct 11 18:48:20 UTC 2020 Modified Files: src/games/factor: factor.6 Log Message: mention hex numbers To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/games/factor/factor.6 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.6 diff -u src/games/factor/factor.6:1.16 src/games/factor/factor.6:1.17 --- src/games/factor/factor.6:1.16 Sun Oct 4 10:22:52 2020 +++ src/games/factor/factor.6 Sun Oct 11 14:48:20 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: factor.6,v 1.16 2020/10/04 14:22:52 kre Exp $ +.\" $NetBSD: factor.6,v 1.17 2020/10/11 18:48:20 christos Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -35,7 +35,7 @@ .\" .\" By Landon Curt Noll, http://www.isthe.com/chongo/index.html /\oo/\ .\" -.Dd October 3, 2020 +.Dd October 11, 2020 .Dt FACTOR 6 .Os .Sh NAME @@ -73,6 +73,9 @@ arguments, reads numbers, one per line, from standard input, until end of file or error. Leading white-space and empty lines are ignored. Numbers may be preceded by a single +. +Numbers that start with +.Dv 0x +are interpreted as hexadecimal. Integer less than 2 are rejected. Numbers are terminated by a non-digit character (such as a newline). After a number is read, it is factored.
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Sun Oct 11 18:46:21 UTC 2020 Modified Files: src/games/factor: factor.c Log Message: Remove is_hex_str() (trying to guess if a number was hex or not). It is not documented and can lead to unexpected behavior. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.36 src/games/factor/factor.c:1.37 --- src/games/factor/factor.c:1.36 Sun Oct 11 13:18:34 2020 +++ src/games/factor/factor.c Sun Oct 11 14:46:21 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.36 2020/10/11 17:18:34 christos Exp $ */ +/* $NetBSD: factor.c,v 1.37 2020/10/11 18:46:21 christos Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); #endif #ifdef __RCSID -__RCSID("$NetBSD: factor.c,v 1.36 2020/10/11 17:18:34 christos Exp $"); +__RCSID("$NetBSD: factor.c,v 1.37 2020/10/11 18:46:21 christos Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); @@ -120,7 +120,6 @@ static void BN_print_fp(FILE *, const BI static void BN_print_dec_fp(FILE *, const BIGNUM *); static void convert_str2bn(BIGNUM **, char *); -static bool is_hex_str(char *); static void pr_fact(BIGNUM *, int, int); /* print factors of a value */ static void pr_print(BIGNUM *, int, int); /* print a prime */ static void usage(void) __dead; @@ -451,29 +450,6 @@ BN_dup(const BIGNUM *a) #endif -/* - * Scan the string from left-to-right to see if the longest substring - * is a valid hexadecimal number. - */ -static bool -is_hex_str(char *str) -{ - char c, *p; - bool saw_hex = false; - - for (p = str; *p; p++) { - if (isdigit((unsigned char)*p)) - continue; - c = tolower((unsigned char)*p); - if (c >= 'a' && c <= 'f') { - saw_hex = true; - continue; - } - break; /* Not a hexadecimal digit. */ - } - return saw_hex; -} - /* Convert string pointed to by *str to a bignum. */ static void convert_str2bn(BIGNUM **val, char *p) @@ -486,7 +462,7 @@ convert_str2bn(BIGNUM **val, char *p) if (*p == '0' && (p[1] == 'x' || p[1] == 'X')) { n = BN_hex2bn(val, p + 2); } else { - n = is_hex_str(p) ? BN_hex2bn(val, p) : BN_dec2bn(val, p); + n = BN_dec2bn(val, p); } if (n == 0) errx(1, "%s: illegal numeric format.", p);
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Sun Oct 11 17:18:34 UTC 2020 Modified Files: src/games/factor: factor.c Log Message: >From gson@ - don't assume -h is always on for large factors - fix saved large factors printing when -h To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.35 src/games/factor/factor.c:1.36 --- src/games/factor/factor.c:1.35 Wed Oct 7 15:48:29 2020 +++ src/games/factor/factor.c Sun Oct 11 13:18:34 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.35 2020/10/07 19:48:29 christos Exp $ */ +/* $NetBSD: factor.c,v 1.36 2020/10/11 17:18:34 christos Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); #endif #ifdef __RCSID -__RCSID("$NetBSD: factor.c,v 1.35 2020/10/07 19:48:29 christos Exp $"); +__RCSID("$NetBSD: factor.c,v 1.36 2020/10/11 17:18:34 christos Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); @@ -91,7 +91,8 @@ __FBSDID("$FreeBSD: head/usr.bin/factor/ #define PRIME_CHECKS 5 -static void pollard_pminus1(BIGNUM *, int); /* print factors for big numbers */ +/* print factors for big numbers */ +static void pollard_pminus1(BIGNUM *, int, int); #else @@ -121,7 +122,7 @@ static void BN_print_dec_fp(FILE *, cons static void convert_str2bn(BIGNUM **, char *); static bool is_hex_str(char *); static void pr_fact(BIGNUM *, int, int); /* print factors of a value */ -static void pr_print(BIGNUM *, int); /* print a prime */ +static void pr_print(BIGNUM *, int, int); /* print a prime */ static void usage(void) __dead; static BN_CTX *ctx; /* just use a global context */ @@ -243,13 +244,13 @@ pr_fact(BIGNUM *val, int hflag, int xfla errx(1, "error in BN_sqr()"); if (BN_cmp(bnfact, val) > 0 || BN_is_prime_ex(val, PRIME_CHECKS, NULL, NULL) == 1) -pr_print(val, xflag); +pr_print(val, hflag, xflag); else -pollard_pminus1(val, xflag); +pollard_pminus1(val, hflag, xflag); #else - pr_print(val, xflag); + pr_print(val, hflag, xflag); #endif - pr_print(NULL, xflag); + pr_print(NULL, hflag, xflag); break; } @@ -275,39 +276,49 @@ pr_fact(BIGNUM *val, int hflag, int xfla } static void -pr_print(BIGNUM *val, int xflag) +pr_print(BIGNUM *val, int hflag, int xflag) { static BIGNUM *sval; static int ex = 1; - if (sval == NULL) { - sval = BN_dup(val); - return; - } + BIGNUM *pval; + + if (hflag) { + if (sval == NULL) { + sval = BN_dup(val); + return; + } - if (val != NULL && BN_cmp(val, sval) == 0) { - ex++; + if (val != NULL && BN_cmp(val, sval) == 0) { + ex++; + return; + } + pval = sval; + } else if (val == NULL) { return; + } else { + pval = val; } - if (val == NULL) - val = sval; if (xflag) { fputs(" 0x", stdout); - BN_print_fp(stdout, val); + BN_print_fp(stdout, pval); } else { putchar(' '); - BN_print_dec_fp(stdout, val); + BN_print_dec_fp(stdout, pval); } - if (ex > 1) - pr_exp(ex, xflag); - if (val != NULL) { - BN_copy(sval, val); - } else { - BN_free(sval); - sval = NULL; + if (hflag) { + if (ex > 1) + pr_exp(ex, xflag); + + if (val != NULL) { + BN_copy(sval, val); + } else { + BN_free(sval); + sval = NULL; + } + ex = 1; } - ex = 1; } static void @@ -321,7 +332,7 @@ usage(void) /* pollard p-1, algorithm from Jim Gillogly, May 2000 */ static void -pollard_pminus1(BIGNUM *val, int xflag) +pollard_pminus1(BIGNUM *val, int hflag, int xflag) { BIGNUM *base, *rbase, *num, *i, *x; @@ -350,9 +361,9 @@ newbase: if (!BN_is_one(x)) { if (BN_is_prime_ex(x, PRIME_CHECKS, NULL, NULL) == 1) -pr_print(x, xflag); +pr_print(x, hflag, xflag); else -pollard_pminus1(x, xflag); +pollard_pminus1(x, hflag, xflag); fflush(stdout); BN_div(num, NULL, val, x, ctx); @@ -360,7 +371,7 @@ newbase: return; if (BN_is_prime_ex(num, PRIME_CHECKS, NULL, NULL) == 1) { -pr_print(num, xflag); +pr_print(num, hflag, xflag); fflush(stdout); return; }
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Wed Oct 7 19:48:29 UTC 2020 Modified Files: src/games/factor: factor.c Log Message: - for readability when the exponent < 10 don't prefix it with 0x (from kre) - fix usage - merge printing code. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.34 src/games/factor/factor.c:1.35 --- src/games/factor/factor.c:1.34 Mon Oct 5 17:11:47 2020 +++ src/games/factor/factor.c Wed Oct 7 15:48:29 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.34 2020/10/05 21:11:47 christos Exp $ */ +/* $NetBSD: factor.c,v 1.35 2020/10/07 19:48:29 christos Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); #endif #ifdef __RCSID -__RCSID("$NetBSD: factor.c,v 1.34 2020/10/05 21:11:47 christos Exp $"); +__RCSID("$NetBSD: factor.c,v 1.35 2020/10/07 19:48:29 christos Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); @@ -177,6 +177,18 @@ main(int argc, char *argv[]) exit(0); } +static void +pr_exp(int i, int xflag) +{ + printf(xflag && i > 9 ? "^0x%x" : "^%d", i); +} + +static void +pr_uint64(uint64_t i, int xflag) +{ + printf(xflag ? " 0x%" PRIx64 : " %" PRIu64, i); +} + /* * pr_fact - print the factors of a number * @@ -246,15 +258,14 @@ pr_fact(BIGNUM *val, int hflag, int xfla do { i++; if (!hflag) -printf(xflag ? " 0x%" PRIx64 : " %" PRIu64, -*fact); +pr_uint64(*fact, xflag); BN_div_word(val, (BN_ULONG)*fact); } while (BN_mod_word(val, (BN_ULONG)*fact) == 0); if (hflag) { - printf(xflag ? " 0x%" PRIx64 : " %" PRIu64, *fact); + pr_uint64(*fact, xflag); if (i > 1) -printf(xflag ? "^0x%x" : "^%d", i); +pr_exp(i, xflag); } /* Let the user know we're doing something. */ @@ -288,7 +299,7 @@ pr_print(BIGNUM *val, int xflag) BN_print_dec_fp(stdout, val); } if (ex > 1) - printf(xflag ? "^0x%x" : "^%d", ex); + pr_exp(ex, xflag); if (val != NULL) { BN_copy(sval, val); @@ -302,7 +313,7 @@ pr_print(BIGNUM *val, int xflag) static void usage(void) { - fprintf(stderr, "usage: factor [-h] [value ...]\n"); + fprintf(stderr, "Usage: %s [-hx] [value ...]\n", getprogname()); exit(1); }
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Mon Oct 5 21:11:47 UTC 2020 Modified Files: src/games/factor: factor.c Log Message: PR/55695: Andreas Gustafsson: factor(6) -h option doesn't always work Handle -h for factors greater than the primes table. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.33 src/games/factor/factor.c:1.34 --- src/games/factor/factor.c:1.33 Mon Oct 5 10:31:30 2020 +++ src/games/factor/factor.c Mon Oct 5 17:11:47 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.33 2020/10/05 14:31:30 christos Exp $ */ +/* $NetBSD: factor.c,v 1.34 2020/10/05 21:11:47 christos Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); #endif #ifdef __RCSID -__RCSID("$NetBSD: factor.c,v 1.33 2020/10/05 14:31:30 christos Exp $"); +__RCSID("$NetBSD: factor.c,v 1.34 2020/10/05 21:11:47 christos Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); @@ -100,11 +100,16 @@ typedef u_long BN_ULONG; #define BN_CTX int #define BN_CTX_new() NULL -#define BN_new() ((BIGNUM *)calloc(sizeof(BIGNUM), 1)) +#define BN_new() calloc(sizeof(BIGNUM), 1) +#define BN_free(a) free(a) + +#define BN_copy(a, b) *(a) = *(b) +#define BN_cmp(a, b) (*(a) - *(b)) #define BN_is_zero(v) (*(v) == 0) #define BN_is_one(v) (*(v) == 1) #define BN_mod_word(a, b) (*(a) % (b)) +static BIGNUM *BN_dup(const BIGNUM *); static int BN_dec2bn(BIGNUM **, const char *); static int BN_hex2bn(BIGNUM **, const char *); static BN_ULONG BN_div_word(BIGNUM *, BN_ULONG); @@ -232,6 +237,7 @@ pr_fact(BIGNUM *val, int hflag, int xfla #else pr_print(val, xflag); #endif + pr_print(NULL, xflag); break; } @@ -260,6 +266,20 @@ pr_fact(BIGNUM *val, int hflag, int xfla static void pr_print(BIGNUM *val, int xflag) { + static BIGNUM *sval; + static int ex = 1; + if (sval == NULL) { + sval = BN_dup(val); + return; + } + + if (val != NULL && BN_cmp(val, sval) == 0) { + ex++; + return; + } + if (val == NULL) + val = sval; + if (xflag) { fputs(" 0x", stdout); BN_print_fp(stdout, val); @@ -267,6 +287,16 @@ pr_print(BIGNUM *val, int xflag) putchar(' '); BN_print_dec_fp(stdout, val); } + if (ex > 1) + printf(xflag ? "^0x%x" : "^%d", ex); + + if (val != NULL) { + BN_copy(sval, val); + } else { + BN_free(sval); + sval = NULL; + } + ex = 1; } static void @@ -389,6 +419,14 @@ BN_div_word(BIGNUM *a, BN_ULONG b) return mod; } +static BIGNUM * +BN_dup(const BIGNUM *a) +{ + BIGNUM *b = BN_new(); + BN_copy(b, a); + return b; +} + #endif /*
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Mon Oct 5 14:31:30 UTC 2020 Modified Files: src/games/factor: factor.c Log Message: revert previous and don't parse octal To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.32 src/games/factor/factor.c:1.33 --- src/games/factor/factor.c:1.32 Mon Oct 5 08:22:49 2020 +++ src/games/factor/factor.c Mon Oct 5 10:31:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.32 2020/10/05 12:22:49 tnn Exp $ */ +/* $NetBSD: factor.c,v 1.33 2020/10/05 14:31:30 christos Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); #endif #ifdef __RCSID -__RCSID("$NetBSD: factor.c,v 1.32 2020/10/05 12:22:49 tnn Exp $"); +__RCSID("$NetBSD: factor.c,v 1.33 2020/10/05 14:31:30 christos Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); @@ -423,11 +423,8 @@ convert_str2bn(BIGNUM **val, char *p) if (*p == '+') p++; if (*p == '-') errx(1, "negative numbers aren't permitted."); - if (*p == '0') { - if (p[1] == 'x' || p[1] == 'X') - n = BN_hex2bn(val, p + 2); - else - n = BN_oct2bn(val, p + 1); + if (*p == '0' && (p[1] == 'x' || p[1] == 'X')) { + n = BN_hex2bn(val, p + 2); } else { n = is_hex_str(p) ? BN_hex2bn(val, p) : BN_dec2bn(val, p); }
CVS commit: src/games/factor
Module Name:src Committed By: tnn Date: Mon Oct 5 12:22:49 UTC 2020 Modified Files: src/games/factor: factor.c Log Message: factor: usage(): mark __dead To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.31 src/games/factor/factor.c:1.32 --- src/games/factor/factor.c:1.31 Sun Oct 4 19:32:15 2020 +++ src/games/factor/factor.c Mon Oct 5 12:22:49 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.31 2020/10/04 19:32:15 christos Exp $ */ +/* $NetBSD: factor.c,v 1.32 2020/10/05 12:22:49 tnn Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); #endif #ifdef __RCSID -__RCSID("$NetBSD: factor.c,v 1.31 2020/10/04 19:32:15 christos Exp $"); +__RCSID("$NetBSD: factor.c,v 1.32 2020/10/05 12:22:49 tnn Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); @@ -117,7 +117,7 @@ static void convert_str2bn(BIGNUM **, ch static bool is_hex_str(char *); static void pr_fact(BIGNUM *, int, int); /* print factors of a value */ static void pr_print(BIGNUM *, int); /* print a prime */ -static void usage(void); +static void usage(void) __dead; static BN_CTX *ctx; /* just use a global context */
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Sun Oct 4 19:32:15 UTC 2020 Modified Files: src/games/factor: factor.c Log Message: - Accept octal input. - Don't play with the original string so we can print it. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.30 src/games/factor/factor.c:1.31 --- src/games/factor/factor.c:1.30 Sat Oct 3 18:27:00 2020 +++ src/games/factor/factor.c Sun Oct 4 15:32:15 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.30 2020/10/03 22:27:00 christos Exp $ */ +/* $NetBSD: factor.c,v 1.31 2020/10/04 19:32:15 christos Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -41,7 +41,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); #endif #ifdef __RCSID -__RCSID("$NetBSD: factor.c,v 1.30 2020/10/03 22:27:00 christos Exp $"); +__RCSID("$NetBSD: factor.c,v 1.31 2020/10/04 19:32:15 christos Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); @@ -424,9 +424,10 @@ convert_str2bn(BIGNUM **val, char *p) if (*p == '-') errx(1, "negative numbers aren't permitted."); if (*p == '0') { - p++; - if (*p == 'x' || *p == 'X') - n = BN_hex2bn(val, ++p); + if (p[1] == 'x' || p[1] == 'X') + n = BN_hex2bn(val, p + 2); + else + n = BN_oct2bn(val, p + 1); } else { n = is_hex_str(p) ? BN_hex2bn(val, p) : BN_dec2bn(val, p); }
CVS commit: src/games/factor
Module Name:src Committed By: kre Date: Sun Oct 4 14:22:52 UTC 2020 Modified Files: src/games/factor: factor.6 Log Message: Fix a typo (s/int/in/) To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/games/factor/factor.6 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.6 diff -u src/games/factor/factor.6:1.15 src/games/factor/factor.6:1.16 --- src/games/factor/factor.6:1.15 Sat Oct 3 22:27:00 2020 +++ src/games/factor/factor.6 Sun Oct 4 14:22:52 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: factor.6,v 1.15 2020/10/03 22:27:00 christos Exp $ +.\" $NetBSD: factor.6,v 1.16 2020/10/04 14:22:52 kre Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -101,7 +101,7 @@ If a factor x divides a value n (>1) tim .It Fl x If the .Fl x -flag is specified, factors will be printed int hexadecimal format. +flag is specified, factors will be printed in hexadecimal format. .El .Sh DIAGNOSTICS Out of range or invalid input results in
CVS commit: src/games/factor
Module Name:src Committed By: christos Date: Sat Oct 3 22:27:00 UTC 2020 Modified Files: src/games/factor: factor.6 factor.c Log Message: PR/55693: Andreas Gustafsson: factor(6) lists factors in wrong order Sync with FreeBSD and change their -h (that printed hex) to -x because we were already using -h. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/games/factor/factor.6 cvs rdiff -u -r1.29 -r1.30 src/games/factor/factor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/factor/factor.6 diff -u src/games/factor/factor.6:1.14 src/games/factor/factor.6:1.15 --- src/games/factor/factor.6:1.14 Sat Nov 11 18:48:44 2017 +++ src/games/factor/factor.6 Sat Oct 3 18:27:00 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: factor.6,v 1.14 2017/11/11 23:48:44 rin Exp $ +.\" $NetBSD: factor.6,v 1.15 2020/10/03 22:27:00 christos Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -35,7 +35,7 @@ .\" .\" By Landon Curt Noll, http://www.isthe.com/chongo/index.html /\oo/\ .\" -.Dd Nov 12, 2017 +.Dd October 3, 2020 .Dt FACTOR 6 .Os .Sh NAME @@ -43,7 +43,7 @@ .Nd factor a number .Sh SYNOPSIS .Nm -.Op Fl h +.Op Fl hx .Op Ar number ... .Sh DESCRIPTION The @@ -98,6 +98,10 @@ If the .Fl h flag is specified, factors will be printed in "human-readable" format. If a factor x divides a value n (>1) times, it will appear as x^n. +.It Fl x +If the +.Fl x +flag is specified, factors will be printed int hexadecimal format. .El .Sh DIAGNOSTICS Out of range or invalid input results in Index: src/games/factor/factor.c diff -u src/games/factor/factor.c:1.29 src/games/factor/factor.c:1.30 --- src/games/factor/factor.c:1.29 Tue Feb 6 11:53:27 2018 +++ src/games/factor/factor.c Sat Oct 3 18:27:00 2020 @@ -1,5 +1,4 @@ -/* $NetBSD: factor.c,v 1.29 2018/02/06 16:53:27 christos Exp $ */ - +/* $NetBSD: factor.c,v 1.30 2020/10/03 22:27:00 christos Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -32,29 +31,34 @@ * SUCH DAMAGE. */ -#include #ifndef lint +#include +#ifdef __COPYRIGHT __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[] = "@(#)factor.c 8.4 (Berkeley) 5/4/95"; -#else -__RCSID("$NetBSD: factor.c,v 1.29 2018/02/06 16:53:27 christos Exp $"); + The Regents of the University of California. All rights reserved."); +#endif +#ifdef __SCCSID +__SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95"); +#endif +#ifdef __RCSID +__RCSID("$NetBSD: factor.c,v 1.30 2020/10/03 22:27:00 christos Exp $"); +#endif +#ifdef __FBSDID +__FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 35 2020-01-12 20:25:11Z gad $"); #endif #endif /* not lint */ /* * factor - factor a number into primes * - * By Landon Curt Noll, http://www.isthe.com/chongo/index.html /\oo/\ + * By: Landon Curt Noll cho...@toad.com, ...!{sun,tolsoft}!hoptoad!chongo + * + * chongo /\oo/\ * * usage: - * factor [-h] [number] ... + * factor [-hx] [number] ... * - * By Default, the form of the output is: + * The form of the output is: * * number: factor1 factor1 factor2 factor3 factor3 factor3 ... * @@ -63,93 +67,80 @@ __RCSID("$NetBSD: factor.c,v 1.29 2018/0 * If the -h flag is specified, the output is in "human-readable" format. * Duplicate factors are printed in the form of x^n. * + * If the -x flag is specified numbers are printed in hex. + * * If no number args are given, the list of numbers are read from stdin. + * If no args are given, the list of numbers are read from stdin. */ #include #include #include +#include #include +#include #include #include #include -#include + +#include "primes.h" #ifdef HAVE_OPENSSL + #include + +#define PRIME_CHECKS 5 + +static void pollard_pminus1(BIGNUM *, int); /* print factors for big numbers */ + #else + typedef long BIGNUM; typedef u_long BN_ULONG; -static int BN_dec2bn(BIGNUM **a, const char *str); + +#define BN_CTX int +#define BN_CTX_new() NULL #define BN_new() ((BIGNUM *)calloc(sizeof(BIGNUM), 1)) #define BN_is_zero(v) (*(v) == 0) #define BN_is_one(v) (*(v) == 1) #define BN_mod_word(a, b) (*(a) % (b)) -#endif - -#include "primes.h" -/* - * prime[i] is the (i-1)th prime. - * - * We are able to sieve 2^32-1 because this byte table yields all primes - * up to 65537 and 65537^2 > 2^32-1. - */ - -#if 0 /* debugging: limit table use to stress the "pollard" code */ -#define pr_limit [0] -#endif - -#define PRIME_CHECKS 5 - -#ifdef HAVE_OPENSSL -static BN_CTX *ctx; /* just use a global context */ -#endif - -static void pr_fact(BIGNUM *, int); /* print factors of a value */ -static void BN_print_dec_fp(FILE *, const BIGNUM *); -static void usage(void) __dead; -#ifdef
CVS commit: src/games/tetris
Module Name:src Committed By: mrg Date: Mon Sep 7 00:31:11 UTC 2020 Modified Files: src/games/tetris: scores.c Log Message: avoid uninit memory and use memmove vs strncpy for a will be truncated on purpose string. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/games/tetris/scores.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/tetris/scores.c diff -u src/games/tetris/scores.c:1.24 src/games/tetris/scores.c:1.25 --- src/games/tetris/scores.c:1.24 Sun Jun 24 12:55:36 2018 +++ src/games/tetris/scores.c Mon Sep 7 00:31:11 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: scores.c,v 1.24 2018/06/24 12:55:36 mrg Exp $ */ +/* $NetBSD: scores.c,v 1.25 2020/09/07 00:31:11 mrg Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -599,7 +599,7 @@ putscores(int sd) { #ifdef ALLOW_SCORE_UPDATES struct highscore_header header; - struct highscore_ondisk buf[MAXHISCORES]; + struct highscore_ondisk buf[MAXHISCORES] = {0}; int i; if (sd == -1) { @@ -611,7 +611,7 @@ putscores(int sd) header.hsh_version = HSH_VERSION; for (i=0; i
CVS commit: src/games/tetris
Module Name:src Committed By: mrg Date: Sun Sep 6 10:51:20 UTC 2020 Modified Files: src/games/tetris: Makefile Log Message: apply ${GCC_NO_FORMAT_TRUNCATION} to scores.c To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/games/tetris/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/tetris/Makefile diff -u src/games/tetris/Makefile:1.8 src/games/tetris/Makefile:1.9 --- src/games/tetris/Makefile:1.8 Sun Oct 13 07:28:10 2019 +++ src/games/tetris/Makefile Sun Sep 6 10:51:20 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.8 2019/10/13 07:28:10 mrg Exp $ +# $NetBSD: Makefile,v 1.9 2020/09/06 10:51:20 mrg Exp $ # @(#)Makefile 8.1 (Berkeley) 5/31/93 PROG= tetris @@ -10,5 +10,6 @@ HIDEGAME=hidegame SETGIDGAME=yes COPTS.tetris.c+= ${GCC_NO_FORMAT_TRUNCATION} +COPTS.scores.c+= ${GCC_NO_FORMAT_TRUNCATION} .include
CVS commit: src/games/robots
Module Name:src Committed By: nia Date: Sun Jul 26 15:38:22 UTC 2020 Modified Files: src/games/robots: main.c rnd_pos.c Log Message: robots: Use arc4random_uniform for better uniform distribution To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/games/robots/main.c cvs rdiff -u -r1.10 -r1.11 src/games/robots/rnd_pos.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/robots/main.c diff -u src/games/robots/main.c:1.32 src/games/robots/main.c:1.33 --- src/games/robots/main.c:1.32 Wed Aug 12 08:30:55 2009 +++ src/games/robots/main.c Sun Jul 26 15:38:22 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.32 2009/08/12 08:30:55 dholland Exp $ */ +/* $NetBSD: main.c,v 1.33 2020/07/26 15:38:22 nia Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.32 2009/08/12 08:30:55 dholland Exp $"); +__RCSID("$NetBSD: main.c,v 1.33 2020/07/26 15:38:22 nia Exp $"); #endif #endif /* not lint */ @@ -167,7 +167,6 @@ main(int argc, char **argv) stdscr = newwin(Y_SIZE, X_SIZE, 0, 0); } - srandom(time(NULL)); if (Real_time) signal(SIGALRM, move_robots); do { Index: src/games/robots/rnd_pos.c diff -u src/games/robots/rnd_pos.c:1.10 src/games/robots/rnd_pos.c:1.11 --- src/games/robots/rnd_pos.c:1.10 Wed Aug 12 08:30:55 2009 +++ src/games/robots/rnd_pos.c Sun Jul 26 15:38:22 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $ */ +/* $NetBSD: rnd_pos.c,v 1.11 2020/07/26 15:38:22 nia Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $"); +__RCSID("$NetBSD: rnd_pos.c,v 1.11 2020/07/26 15:38:22 nia Exp $"); #endif #endif /* not lint */ @@ -44,8 +44,6 @@ __RCSID("$NetBSD: rnd_pos.c,v 1.10 2009/ #define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) -static int rnd(int); - /* * rnd_pos: * Pick a random, unoccupied position @@ -57,17 +55,10 @@ rnd_pos(void) static int call = 0; do { - pos.y = rnd(Y_FIELDSIZE - 1) + 1; - pos.x = rnd(X_FIELDSIZE - 1) + 1; + pos.y = arc4random_uniform(Y_FIELDSIZE - 1) + 1; + pos.x = arc4random_uniform(X_FIELDSIZE - 1) + 1; refresh(); } while (Field[pos.y][pos.x] != 0); call++; return } - -static int -rnd(int range) -{ - - return random() % range; -}
CVS commit: src/games/random
Module Name:src Committed By: nia Date: Sun Jul 26 15:24:00 UTC 2020 Modified Files: src/games/random: random.c Log Message: random(6): Use arc4random_uniform to simplify code To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/games/random/random.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/random/random.c diff -u src/games/random/random.c:1.14 src/games/random/random.c:1.15 --- src/games/random/random.c:1.14 Wed Aug 12 08:27:24 2009 +++ src/games/random/random.c Sun Jul 26 15:24:00 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: random.c,v 1.14 2009/08/12 08:27:24 dholland Exp $ */ +/* $NetBSD: random.c,v 1.15 2020/07/26 15:24:00 nia Exp $ */ /* * Copyright (c) 1994 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1994\ #if 0 static char sccsid[] = "@(#)random.c 8.6 (Berkeley) 6/1/94"; #else -__RCSID("$NetBSD: random.c,v 1.14 2009/08/12 08:27:24 dholland Exp $"); +__RCSID("$NetBSD: random.c,v 1.15 2020/07/26 15:24:00 nia Exp $"); #endif #endif /* not lint */ @@ -62,7 +62,6 @@ static void usage(void) __dead; int main(int argc, char *argv[]) { - struct timeval tp; double denom; int ch, random_exit, selected, unbuffer_output; char *ep; @@ -103,12 +102,9 @@ main(int argc, char *argv[]) /* NOTREACHED */ } - (void)gettimeofday(, NULL); - srandom((unsigned long)tp.tv_usec + tp.tv_sec + getpid()); - /* Compute a random exit status between 0 and denom - 1. */ if (random_exit) - return ((denom * random()) / RANDOM_MAX); + return arc4random_uniform(denom); /* * Act as a filter, randomly choosing lines of the standard input @@ -123,7 +119,7 @@ main(int argc, char *argv[]) * 0 (which has a 1 / denom chance of being true), we select the * line. */ - selected = (int)(denom * random() / RANDOM_MAX) == 0; + selected = (arc4random_uniform(denom) == 0); while ((ch = getchar()) != EOF) { if (selected) (void)putchar(ch); @@ -133,7 +129,7 @@ main(int argc, char *argv[]) err(2, "stdout"); /* Now see if the next line is to be printed. */ - selected = (int)(denom * random() / RANDOM_MAX) == 0; + selected = (arc4random_uniform(denom) == 0); } } if (ferror(stdin))
CVS commit: src/games/fortune/strfile
Module Name:src Committed By: nia Date: Sun Jul 26 15:14:09 UTC 2020 Modified Files: src/games/fortune/strfile: strfile.c Log Message: Revert arc4random usage for now this is a host tool and needs to be portable future plans: add arc4random to libnbcompat To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/games/fortune/strfile/strfile.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/strfile/strfile.c diff -u src/games/fortune/strfile/strfile.c:1.41 src/games/fortune/strfile/strfile.c:1.42 --- src/games/fortune/strfile/strfile.c:1.41 Tue Jul 21 03:05:40 2020 +++ src/games/fortune/strfile/strfile.c Sun Jul 26 15:14:09 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: strfile.c,v 1.41 2020/07/21 03:05:40 nia Exp $ */ +/* $NetBSD: strfile.c,v 1.42 2020/07/26 15:14:09 nia Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 #if 0 static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: strfile.c,v 1.41 2020/07/21 03:05:40 nia Exp $"); +__RCSID("$NetBSD: strfile.c,v 1.42 2020/07/26 15:14:09 nia Exp $"); #endif #endif /* not lint */ #endif /* __NetBSD__ */ @@ -438,6 +438,8 @@ randomize(void) off_t tmp; off_t *sp; + srandom((int)(time(NULL) + getpid())); + Tbl.str_flags |= STR_RANDOM; cnt = Tbl.str_numstr; @@ -446,7 +448,7 @@ randomize(void) */ for (sp = Seekpts; cnt > 0; cnt--, sp++) { - i = arc4random_uniform(cnt); + i = random() % cnt; tmp = sp[0]; sp[0] = sp[i]; sp[i] = tmp;
CVS commit: src/games/fortune
Module Name:src Committed By: nia Date: Tue Jul 21 03:05:40 UTC 2020 Modified Files: src/games/fortune/fortune: fortune.c src/games/fortune/strfile: strfile.c Log Message: fortune: arc4random_uniform for better uniform values than random() % ... To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/games/fortune/fortune/fortune.c cvs rdiff -u -r1.40 -r1.41 src/games/fortune/strfile/strfile.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/fortune/fortune.c diff -u src/games/fortune/fortune/fortune.c:1.64 src/games/fortune/fortune/fortune.c:1.65 --- src/games/fortune/fortune/fortune.c:1.64 Tue Jun 19 05:46:08 2012 +++ src/games/fortune/fortune/fortune.c Tue Jul 21 03:05:40 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: fortune.c,v 1.64 2012/06/19 05:46:08 dholland Exp $ */ +/* $NetBSD: fortune.c,v 1.65 2020/07/21 03:05:40 nia Exp $ */ /*- * Copyright (c) 1986, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1986, 19 #if 0 static char sccsid[] = "@(#)fortune.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: fortune.c,v 1.64 2012/06/19 05:46:08 dholland Exp $"); +__RCSID("$NetBSD: fortune.c,v 1.65 2020/07/21 03:05:40 nia Exp $"); #endif #endif /* not lint */ @@ -190,7 +190,6 @@ static size_t maxlen_in_list(FILEDESC *) int main(int ac, char *av[]) { - struct timeval tv; #ifdef OK_TO_WRITE_DISK int fd; #endif /* OK_TO_WRITE_DISK */ @@ -203,12 +202,6 @@ main(int ac, char *av[]) #endif init_prob(); - if (gettimeofday(, NULL) != 0) - err(1, "gettimeofday()"); - srandom(((unsigned long)tv.tv_sec)* -((unsigned long)tv.tv_usec+1) * - ((unsigned long)getpid()+1) * -((unsigned long)getppid()+1)); do { get_fort(); } while ((Short_only && fortlen() > SLEN) || @@ -933,7 +926,7 @@ get_fort(void) if (File_list->next == NULL || File_list->percent == NO_PROB) fp = File_list; else { - choice = random() % 100; + choice = arc4random_uniform(100); DPRINTF(1, (stderr, "choice = %d\n", choice)); for (fp = File_list; fp->percent != NO_PROB; fp = fp->next) if (choice < fp->percent) @@ -953,7 +946,7 @@ get_fort(void) else { if (fp->next != NULL) { sum_noprobs(fp); - choice = random() % Noprob_tbl.str_numstr; + choice = arc4random_uniform(Noprob_tbl.str_numstr); DPRINTF(1, (stderr, "choice = %d (of %d) \n", choice, Noprob_tbl.str_numstr)); while ((u_int32_t)choice >= fp->tbl.str_numstr) { @@ -994,7 +987,7 @@ pick_child(FILEDESC *parent) int choice; if (Equal_probs) { - choice = random() % parent->num_children; + choice = arc4random_uniform(parent->num_children); DPRINTF(1, (stderr, "choice = %d (of %d)\n", choice, parent->num_children)); for (fp = parent->child; choice--; fp = fp->next) @@ -1004,7 +997,7 @@ pick_child(FILEDESC *parent) } else { get_tbl(parent); - choice = random() % parent->tbl.str_numstr; + choice = arc4random_uniform(parent->tbl.str_numstr); DPRINTF(1, (stderr, "choice = %d (of %d)\n", choice, parent->tbl.str_numstr)); for (fp = parent->child; (u_int32_t)choice >= fp->tbl.str_numstr; @@ -1084,13 +1077,13 @@ get_pos(FILEDESC *fp) #ifdef OK_TO_WRITE_DISK if ((fd = open(fp->posfile, O_RDONLY)) < 0 || read(fd, >pos, sizeof fp->pos) != sizeof fp->pos) - fp->pos = random() % fp->tbl.str_numstr; + fp->pos = arc4random_uniform(fp->tbl.str_numstr); else if (fp->pos >= fp->tbl.str_numstr) fp->pos %= fp->tbl.str_numstr; if (fd >= 0) (void) close(fd); #else - fp->pos = random() % fp->tbl.str_numstr; + fp->pos = arc4random_uniform(fp->tbl.str_numstr); #endif /* OK_TO_WRITE_DISK */ } if ((u_int64_t)++(fp->pos) >= fp->tbl.str_numstr) Index: src/games/fortune/strfile/strfile.c diff -u src/games/fortune/strfile/strfile.c:1.40 src/games/fortune/strfile/strfile.c:1.41 --- src/games/fortune/strfile/strfile.c:1.40 Thu Apr 30 12:32:26 2020 +++ src/games/fortune/strfile/strfile.c Tue Jul 21 03:05:40 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: strfile.c,v 1.40 2020/04/30 12:32:26 christos Exp $ */ +/* $NetBSD: strfile.c,v 1.41 2020/07/21 03:05:40 nia Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 #if 0 static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: strfile.c,v 1.40 2020/04/30 12:32:26 christos Exp $"); +__RCSID("$NetBSD: strfile.c,v 1.41 2020/07/21 03:05:40 nia Exp $"); #endif #endif /* not lint */ #endif /* __NetBSD__ */ @@ -438,8 +438,6 @@ randomize(void) off_t tmp; off_t *sp; - srandom((int)(time(NULL) + getpid())); - Tbl.str_flags |= STR_RANDOM; cnt = Tbl.str_numstr; @@ -448,7 +446,7 @@ randomize(void) */ for (sp = Seekpts; cnt > 0; cnt--, sp++) { - i = random() % cnt; + i = arc4random_uniform(cnt); tmp = sp[0]; sp[0] = sp[i]; sp[i] = tmp;
CVS commit: src/games/tetris
Module Name:src Committed By: nia Date: Tue Jul 21 02:42:05 UTC 2020 Modified Files: src/games/tetris: tetris.c tetris.h Log Message: tetris: Use arc4random_uniform instead of modulo for better randomness To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/games/tetris/tetris.c cvs rdiff -u -r1.15 -r1.16 src/games/tetris/tetris.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/tetris/tetris.c diff -u src/games/tetris/tetris.c:1.32 src/games/tetris/tetris.c:1.33 --- src/games/tetris/tetris.c:1.32 Thu Mar 3 21:38:55 2016 +++ src/games/tetris/tetris.c Tue Jul 21 02:42:05 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: tetris.c,v 1.32 2016/03/03 21:38:55 nat Exp $ */ +/* $NetBSD: tetris.c,v 1.33 2020/07/21 02:42:05 nia Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -207,7 +207,6 @@ main(int argc, char *argv[]) scr_init(); setup_board(); - srandom(getpid()); scr_set(); pos = A_FIRST*B_COLS + (B_COLS/2)-1; Index: src/games/tetris/tetris.h diff -u src/games/tetris/tetris.h:1.15 src/games/tetris/tetris.h:1.16 --- src/games/tetris/tetris.h:1.15 Thu Mar 3 21:38:55 2016 +++ src/games/tetris/tetris.h Tue Jul 21 02:42:05 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: tetris.h,v 1.15 2016/03/03 21:38:55 nat Exp $ */ +/* $NetBSD: tetris.h,v 1.16 2020/07/21 02:42:05 nia Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -130,7 +130,7 @@ struct shape { }; extern const struct shape shapes[]; -#define randshape() ([random() % 7]) +#define randshape() ([arc4random_uniform(7)]) extern const struct shape *nextshape;
CVS commit: src/games/hangman
Module Name:src Committed By: dholland Date: Sun Jul 12 02:34:54 UTC 2020 Modified Files: src/games/hangman: prdata.c Log Message: Avoid messing up the display when too many letters are guessed at once. The field to put them in was made 26 characters wide... but includes the string "Guessed: ". So if you get to 17 it wraps to the next line and clreol()'s it. Instead, when reaching this point step on the "Guessed:" string instead. Reported by phil@. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/games/hangman/prdata.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/hangman/prdata.c diff -u src/games/hangman/prdata.c:1.7 src/games/hangman/prdata.c:1.8 --- src/games/hangman/prdata.c:1.7 Sat Oct 13 21:03:09 2012 +++ src/games/hangman/prdata.c Sun Jul 12 02:34:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: prdata.c,v 1.7 2012/10/13 21:03:09 dholland Exp $ */ +/* $NetBSD: prdata.c,v 1.8 2020/07/12 02:34:54 dholland Exp $ */ /*- * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)prdata.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: prdata.c,v 1.7 2012/10/13 21:03:09 dholland Exp $"); +__RCSID("$NetBSD: prdata.c,v 1.8 2020/07/12 02:34:54 dholland Exp $"); #endif #endif /* not lint */ @@ -47,9 +47,17 @@ __RCSID("$NetBSD: prdata.c,v 1.7 2012/10 void prdata(void) { - int i; + int i, n, l; - move(GUESSY, GUESSX + sizeof "Guessed: "); + for (i = n = 0; i < 26; i++) + if (Guessed[i]) + n++; + + move(GUESSY, GUESSX); + l = sizeof "Guessed: "; + if (GUESSX + l + n < COLS) { + addstr("Guessed: "); + } for (i = 0; i < 26; i++) if (Guessed[i]) addch(i + 'a');
CVS commit: src/games/cgram
Module Name:src Committed By: rillig Date: Thu Jul 2 19:11:01 UTC 2020 Modified Files: src/games/cgram: cgram.c Log Message: cgram(6): use standard cursor keys, use standard shuffle algorithm The previous shuffle algorithm asked for 100 random numbers, on average. The new algorithm asks exactly for 26 random numbers. Curses predefines numeric constants for keys, and there is no apparent reason not to use these standard keys for cursor movement. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.1 src/games/cgram/cgram.c:1.2 --- src/games/cgram/cgram.c:1.1 Sun Aug 4 05:42:47 2013 +++ src/games/cgram/cgram.c Thu Jul 2 19:11:01 2020 @@ -120,16 +120,13 @@ static void readquote(void) { } static void encode(void) { - int used[26]; - for (int i=0; i<26; i++) used[i] = 0; - int key[26]; - int keypos=0; - while (keypos < 26) { - int c = random()%26; - if (used[c]) continue; - key[keypos++] = c; - used[c] = 1; + for (int i=0; i<26; i++) key[i] = i; + for (int i=26; i>1; i--) { + int c = random() % i; + int t = key[i-1]; + key[i-1] = key[c]; + key[c] = t; } for (int y=0; y 0) { curx--; } @@ -256,9 +255,11 @@ static void loop(void) { } break; case 5: /* ^E */ + case KEY_END: curx = strlen(lines.v[cury]); break; case 6: /* ^F */ + case KEY_RIGHT: if (curx < strlen(lines.v[cury])) { curx++; } @@ -271,6 +272,7 @@ static void loop(void) { clear(); break; case 14: /* ^N */ + case KEY_DOWN: if (cury < lines.num-1) { cury++; } @@ -282,6 +284,7 @@ static void loop(void) { } break; case 16: /* ^P */ + case KEY_UP: if (cury > 0) { cury--; } @@ -335,6 +338,7 @@ int main(void) { encode(); opencurses(); + keypad(stdscr, TRUE); loop(); closecurses();
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: sevan Date: Mon Jun 15 12:57:51 UTC 2020 Modified Files: src/games/fortune/datfiles: fortunes Log Message: A revision of "The purpose of computing is insight, not numbers" by Richard Hamming. >From The Art of Doing Science and Engineering To generate a diff of this commit: cvs rdiff -u -r1.90 -r1.91 src/games/fortune/datfiles/fortunes Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/fortunes diff -u src/games/fortune/datfiles/fortunes:1.90 src/games/fortune/datfiles/fortunes:1.91 --- src/games/fortune/datfiles/fortunes:1.90 Mon May 18 20:19:08 2020 +++ src/games/fortune/datfiles/fortunes Mon Jun 15 12:57:51 2020 @@ -16302,3 +16302,5 @@ Bell has two patents on UNIX a) set-user-id bit b) on "typo" ! -- John Lions, Australian UNIX Users Group Newsletter, Oct 1978 +% +The purpose of computing numbers is not yet in sight
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: leot Date: Sun Jun 7 15:41:03 UTC 2020 Modified Files: src/games/fortune/datfiles: netbsd-tips Log Message: Recommend using `pkg_admin {fetch-pkg-vulnerabilities,audit}' instead of {download-vulnerability-list,audit-packages}. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/games/fortune/datfiles/netbsd-tips Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/netbsd-tips diff -u src/games/fortune/datfiles/netbsd-tips:1.7 src/games/fortune/datfiles/netbsd-tips:1.8 --- src/games/fortune/datfiles/netbsd-tips:1.7 Sun Jun 7 15:37:04 2020 +++ src/games/fortune/datfiles/netbsd-tips Sun Jun 7 15:41:03 2020 @@ -35,11 +35,11 @@ You can view your non-default Postfix se To report about installed packages with known vulnerabilities, fetch the latest pkg-vulnerabilities file as the superuser with: - download-vulnerability-list + pkg_admin fetch-pkg-vulnerabilities And then run: - audit-packages + pkg_admin audit % The following shows an example of temporarily adding 10MB more swap space for virtual memory:
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: leot Date: Sun Jun 7 15:37:04 UTC 2020 Modified Files: src/games/fortune/datfiles: netbsd-tips Log Message: Properly quote printf string Noticed by Ottavio Caruso on #netbsd@Freenode, thanks! To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/games/fortune/datfiles/netbsd-tips Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/netbsd-tips diff -u src/games/fortune/datfiles/netbsd-tips:1.6 src/games/fortune/datfiles/netbsd-tips:1.7 --- src/games/fortune/datfiles/netbsd-tips:1.6 Sun Sep 2 16:08:12 2018 +++ src/games/fortune/datfiles/netbsd-tips Sun Jun 7 15:37:04 2020 @@ -51,7 +51,7 @@ space for virtual memory: If your console ever gets broken, you can try resetting it to its initial state with: - printf "\033c + printf "\033c" % If you installed a package, but don't know what the software is called or what executables to run, use pkg_info with the -L switch
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: sevan Date: Mon May 18 20:19:08 UTC 2020 Modified Files: src/games/fortune/datfiles: fortunes Log Message: Heads up on Bell patents P21 on https://minnie.tuhs.org/Archive/Documentation/AUUGN/AUUGN-V01.1.pdf To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/games/fortune/datfiles/fortunes Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/fortunes diff -u src/games/fortune/datfiles/fortunes:1.89 src/games/fortune/datfiles/fortunes:1.90 --- src/games/fortune/datfiles/fortunes:1.89 Thu Apr 2 05:55:02 2020 +++ src/games/fortune/datfiles/fortunes Mon May 18 20:19:08 2020 @@ -16297,3 +16297,8 @@ Fail we may, sail we must % Don't shout at your JBODs, they don't like it! -- Brendan Gregg, "Shouting in the Datacenter" +% +Bell has two patents on UNIX +a) set-user-id bit +b) on "typo" ! + -- John Lions, Australian UNIX Users Group Newsletter, Oct 1978
CVS commit: src/games/fortune/unstr
Module Name:src Committed By: christos Date: Thu Apr 30 12:40:11 UTC 2020 Modified Files: src/games/fortune/unstr: unstr.c Log Message: Simplify, little KNF To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/games/fortune/unstr/unstr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/unstr/unstr.c diff -u src/games/fortune/unstr/unstr.c:1.15 src/games/fortune/unstr/unstr.c:1.16 --- src/games/fortune/unstr/unstr.c:1.15 Wed Apr 29 17:00:42 2020 +++ src/games/fortune/unstr/unstr.c Thu Apr 30 08:40:11 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $ */ +/* $NetBSD: unstr.c,v 1.16 2020/04/30 12:40:11 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19 #if 0 static char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $"); +__RCSID("$NetBSD: unstr.c,v 1.16 2020/04/30 12:40:11 christos Exp $"); #endif #endif /* not lint */ @@ -59,19 +59,19 @@ __RCSID("$NetBSD: unstr.c,v 1.15 2020/04 * Ken Arnold Aug 13, 1978 */ -# include -# include -# include -# include -# include -# include -# include -# include -# include "strfile.h" - -# ifndef MAXPATHLEN -# define MAXPATHLEN 1024 -# endif /* MAXPATHLEN */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "strfile.h" + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif /* MAXPATHLEN */ char *Infile, /* name of input file */ Datafile[MAXPATHLEN], /* name of data file */ @@ -91,9 +91,9 @@ main(int ac __unused, char **av) getargs(av); if ((Inf = fopen(Infile, "r")) == NULL) - err(1, "fopen %s", Infile); + err(EXIT_FAILURE, "fopen %s", Infile); if ((Dataf = fopen(Datafile, "r")) == NULL) - err(1, "fopen %s", Datafile); + err(EXIT_FAILURE, "fopen %s", Datafile); (void) fread((char *) , sizeof tbl, 1, Dataf); BE32TOH(tbl.str_version); BE32TOH(tbl.str_numstr); @@ -108,19 +108,19 @@ main(int ac __unused, char **av) order_unstr(); (void) fclose(Inf); (void) fclose(Dataf); - exit(0); + return EXIT_SUCCESS; } void getargs(char *av[]) { - if (!*++av || (strlen(*av) + sizeof(".dat")) > sizeof(Datafile)) { - (void) fprintf(stderr, "usage: unstr datafile\n"); - exit(1); + if (!*++av || + (size_t)snprintf(Datafile, sizeof(Datafile), "%s.dat", Infile) > + sizeof(Datafile)) { + (void) fprintf(stderr, "Usage: %s datafile\n", getprogname()); + exit(EXIT_FAILURE); } Infile = *av; - (void) strcpy(Datafile, Infile); - (void) strcat(Datafile, ".dat"); } void
CVS commit: src/games/fortune/strfile
Module Name:src Committed By: christos Date: Thu Apr 30 12:32:26 UTC 2020 Modified Files: src/games/fortune/strfile: strfile.c Log Message: Simplify, errors to stderr. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/games/fortune/strfile/strfile.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/strfile/strfile.c diff -u src/games/fortune/strfile/strfile.c:1.39 src/games/fortune/strfile/strfile.c:1.40 --- src/games/fortune/strfile/strfile.c:1.39 Wed Apr 29 16:45:05 2020 +++ src/games/fortune/strfile/strfile.c Thu Apr 30 08:32:26 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: strfile.c,v 1.39 2020/04/29 20:45:05 nia Exp $ */ +/* $NetBSD: strfile.c,v 1.40 2020/04/30 12:32:26 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 #if 0 static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: strfile.c,v 1.39 2020/04/29 20:45:05 nia Exp $"); +__RCSID("$NetBSD: strfile.c,v 1.40 2020/04/30 12:32:26 christos Exp $"); #endif #endif /* not lint */ #endif /* __NetBSD__ */ @@ -55,6 +55,7 @@ __RCSID("$NetBSD: strfile.c,v 1.39 2020/ #include #include #include +#include #include #include #include @@ -131,7 +132,7 @@ static STR *Firstch; /* first chars of static uint32_t h2nl(uint32_t h); static void getargs(int argc, char **argv); -static void usage(void) __dead; +static void usage(const char *, ...) __dead __printflike(1, 2); static void add_offset(FILE *fp, off_t off); static void do_order(void); static int cmp_str(const void *vp1, const void *vp2); @@ -295,39 +296,39 @@ getargs(int argc, char **argv) break; case '?': default: - usage(); + usage(NULL); } argv += optind; if (*argv) { Infile = *argv; if (*++argv) { - len = strlen(*argv); + len = strlcpy(Outfile, *argv, sizeof(Outfile)); if (len >= sizeof(Outfile)) { -puts("Bad output filename"); -usage(); +usage("Too long output filename"); } - (void) memcpy(Outfile, *argv, len + 1); } } if (!Infile) { - puts("No input file name"); - usage(); + usage("No input file name"); } if (*Outfile == '\0') { - len = strlen(Infile) + sizeof(".dat"); - if (len > sizeof(Outfile)) { - puts("Bad input filename"); - usage(); + len = snprintf(Outfile, sizeof(Outfile), "%s.dat", Infile); + if (len >= sizeof(Outfile)) { + usage("Too long input filename"); } - (void) strcpy(Outfile, Infile); - (void) strcat(Outfile, ".dat"); } } static void -usage(void) +usage(const char *fmt, ...) { + if (fmt) { + va_list ap; + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); + } (void) fprintf(stderr, "Usage: %s [-iorsx] [-c char] sourcefile [datafile]\n", getprogname());
CVS commit: src/games/fortune/unstr
Module Name:src Committed By: nia Date: Wed Apr 29 21:00:42 UTC 2020 Modified Files: src/games/fortune/unstr: unstr.c Log Message: unstr: Check that the input filename fits in the buffer. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/games/fortune/unstr/unstr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/unstr/unstr.c diff -u src/games/fortune/unstr/unstr.c:1.14 src/games/fortune/unstr/unstr.c:1.15 --- src/games/fortune/unstr/unstr.c:1.14 Tue Jun 19 05:46:08 2012 +++ src/games/fortune/unstr/unstr.c Wed Apr 29 21:00:42 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: unstr.c,v 1.14 2012/06/19 05:46:08 dholland Exp $ */ +/* $NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19 #if 0 static char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: unstr.c,v 1.14 2012/06/19 05:46:08 dholland Exp $"); +__RCSID("$NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $"); #endif #endif /* not lint */ @@ -114,7 +114,7 @@ main(int ac __unused, char **av) void getargs(char *av[]) { - if (!*++av) { + if (!*++av || (strlen(*av) + sizeof(".dat")) > sizeof(Datafile)) { (void) fprintf(stderr, "usage: unstr datafile\n"); exit(1); }
CVS commit: src/games/fortune/strfile
Module Name:src Committed By: nia Date: Wed Apr 29 20:45:05 UTC 2020 Modified Files: src/games/fortune/strfile: strfile.c Log Message: strfile: Check that input/output filenames don't exceed the buffer size To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/games/fortune/strfile/strfile.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/strfile/strfile.c diff -u src/games/fortune/strfile/strfile.c:1.38 src/games/fortune/strfile/strfile.c:1.39 --- src/games/fortune/strfile/strfile.c:1.38 Thu Sep 19 00:34:00 2013 +++ src/games/fortune/strfile/strfile.c Wed Apr 29 20:45:05 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: strfile.c,v 1.38 2013/09/19 00:34:00 uwe Exp $ */ +/* $NetBSD: strfile.c,v 1.39 2020/04/29 20:45:05 nia Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 #if 0 static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: strfile.c,v 1.38 2013/09/19 00:34:00 uwe Exp $"); +__RCSID("$NetBSD: strfile.c,v 1.39 2020/04/29 20:45:05 nia Exp $"); #endif #endif /* not lint */ #endif /* __NetBSD__ */ @@ -267,6 +267,7 @@ getargs(int argc, char **argv) int ch; extern int optind; extern char *optarg; + size_t len; while ((ch = getopt(argc, argv, "c:iorsx")) != -1) switch(ch) { @@ -300,14 +301,25 @@ getargs(int argc, char **argv) if (*argv) { Infile = *argv; - if (*++argv) - (void) strcpy(Outfile, *argv); + if (*++argv) { + len = strlen(*argv); + if (len >= sizeof(Outfile)) { +puts("Bad output filename"); +usage(); + } + (void) memcpy(Outfile, *argv, len + 1); + } } if (!Infile) { puts("No input file name"); usage(); } if (*Outfile == '\0') { + len = strlen(Infile) + sizeof(".dat"); + if (len > sizeof(Outfile)) { + puts("Bad input filename"); + usage(); + } (void) strcpy(Outfile, Infile); (void) strcat(Outfile, ".dat"); }
CVS commit: src/games/backgammon/common_source
Module Name:src Committed By: joerg Date: Wed Apr 22 23:36:26 UTC 2020 Modified Files: src/games/backgammon/common_source: back.h fancy.c Log Message: buffnum is shared between subs.c and fancy.c To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/games/backgammon/common_source/back.h cvs rdiff -u -r1.14 -r1.15 src/games/backgammon/common_source/fancy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/backgammon/common_source/back.h diff -u src/games/backgammon/common_source/back.h:1.20 src/games/backgammon/common_source/back.h:1.21 --- src/games/backgammon/common_source/back.h:1.20 Sat Oct 13 19:19:39 2012 +++ src/games/backgammon/common_source/back.h Wed Apr 22 23:36:26 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: back.h,v 1.20 2012/10/13 19:19:39 dholland Exp $ */ +/* $NetBSD: back.h,v 1.21 2020/04/22 23:36:26 joerg Exp $ */ /* * Copyright (c) 1980, 1993 @@ -124,6 +124,8 @@ extern const char *const *colorptr; /* c extern const char *const *Colorptr; /* color of current player, capitalized */ extern int colen; /* length of color of current player */ +extern int buffnum; + extern struct termios old, noech, raw;/* original tty status */ extern int curr; /* row position of cursor */ Index: src/games/backgammon/common_source/fancy.c diff -u src/games/backgammon/common_source/fancy.c:1.14 src/games/backgammon/common_source/fancy.c:1.15 --- src/games/backgammon/common_source/fancy.c:1.14 Wed Aug 12 05:17:57 2009 +++ src/games/backgammon/common_source/fancy.c Wed Apr 22 23:36:26 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: fancy.c,v 1.14 2009/08/12 05:17:57 dholland Exp $ */ +/* $NetBSD: fancy.c,v 1.15 2020/04/22 23:36:26 joerg Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)fancy.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: fancy.c,v 1.14 2009/08/12 05:17:57 dholland Exp $"); +__RCSID("$NetBSD: fancy.c,v 1.15 2020/04/22 23:36:26 joerg Exp $"); #endif #endif /* not lint */ @@ -78,8 +78,6 @@ static char tcap[] = "bccdceclcmhomcmlnd /* corresponding strings */ static char **tstr[] = {, , , , , , , , , }; -int buffnum; /* pointer to output buffer */ - static char tbuf[1024]; /* buffer for decoded termcap entries */ static int oldb[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
CVS commit: src/games/fortune/datfiles
Module Name:src Committed By: sevan Date: Thu Apr 2 05:55:02 UTC 2020 Modified Files: src/games/fortune/datfiles: fortunes Log Message: Disks can sense vibes, DTrace confirms it. https://youtu.be/tDacjrSCeq4 To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 src/games/fortune/datfiles/fortunes Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/games/fortune/datfiles/fortunes diff -u src/games/fortune/datfiles/fortunes:1.88 src/games/fortune/datfiles/fortunes:1.89 --- src/games/fortune/datfiles/fortunes:1.88 Sat Feb 22 19:03:04 2020 +++ src/games/fortune/datfiles/fortunes Thu Apr 2 05:55:02 2020 @@ -16294,3 +16294,6 @@ Fanfare, n.: The food available for consumption at a con. % Fail we may, sail we must +% +Don't shout at your JBODs, they don't like it! + -- Brendan Gregg, "Shouting in the Datacenter"