CVS commit: src/games/rain

2024-02-28 Thread Charlotte Koch
Module Name:src
Committed By:   charlotte
Date:   Wed Feb 28 23:24:52 UTC 2024

Modified Files:
src/games/rain: rain.c

Log Message:
rain(6): Update the "rainable area" upon SIGWINCH

This makes sure rain falls to fill the entire window even if the window
grows in size.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 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.c
diff -u src/games/rain/rain.c:1.23 src/games/rain/rain.c:1.24
--- src/games/rain/rain.c:1.23	Wed Feb 28 23:14:37 2024
+++ src/games/rain/rain.c	Wed Feb 28 23:24:52 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: rain.c,v 1.23 2024/02/28 23:14:37 charlotte Exp $	*/
+/*	$NetBSD: rain.c,v 1.24 2024/02/28 23:24:52 charlotte 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.23 2024/02/28 23:14:37 charlotte Exp $");
+__RCSID("$NetBSD: rain.c,v 1.24 2024/02/28 23:24:52 charlotte Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,8 +59,11 @@ __RCSID("$NetBSD: rain.c,v 1.23 2024/02/
 #include 
 
 static volatile sig_atomic_t sig_caught = 0;
+static long cols;
+static long lines;
 
 int main(int, char **);
+static void winupdate(void);
 static void onsig(int);
 
 
@@ -68,7 +71,6 @@ int
 main(int argc, char **argv)
 {
 	int x, y, j;
-	long cols, lines;
 	unsigned int delay = 12;
 	unsigned long val = 0;
 	int ch;
@@ -95,10 +97,7 @@ main(int argc, char **argv)
 
 	if (!initscr())
 		errx(0, "couldn't initialize screen");
-	cols = COLS - 4;
-	lines = LINES - 4;
-	if (cols == 0) cols++;
-	if (lines == 0) lines++;
+	winupdate();
 
 	(void)signal(SIGHUP, onsig);
 	(void)signal(SIGINT, onsig);
@@ -114,6 +113,10 @@ main(int argc, char **argv)
 			(void)endwin();
 			exit(0);
 		}
+		if (is_term_resized(LINES, COLS)) {
+			resizeterm(LINES, COLS);
+			winupdate();
+		}
 		x = random() % cols + 2;
 		y = random() % lines + 2;
 		(void)mvaddch(y, x, '.');
@@ -147,6 +150,15 @@ main(int argc, char **argv)
 	}
 }
 
+static void
+winupdate(void)
+{
+	cols = COLS - 4;
+	lines = LINES - 4;
+	if (cols == 0) cols++;
+	if (lines == 0) lines++;
+}
+
 /* ARGSUSED */
 static void
 onsig(int dummy __unused)



CVS commit: src/games/rain

2024-02-28 Thread Charlotte Koch
Module Name:src
Committed By:   charlotte
Date:   Wed Feb 28 23:24:52 UTC 2024

Modified Files:
src/games/rain: rain.c

Log Message:
rain(6): Update the "rainable area" upon SIGWINCH

This makes sure rain falls to fill the entire window even if the window
grows in size.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/games/rain/rain.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/games/rain

2024-02-28 Thread Charlotte Koch
Module Name:src
Committed By:   charlotte
Date:   Wed Feb 28 23:14:37 UTC 2024

Modified Files:
src/games/rain: rain.c

Log Message:
rain(6): Avoid division by zero

If there were exactly 4 LINES or COLS then we'd attempt to draw a raindrop
at some value mod 0, which is invalid.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 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.c
diff -u src/games/rain/rain.c:1.22 src/games/rain/rain.c:1.23
--- src/games/rain/rain.c:1.22	Wed Oct 14 18:32:04 2020
+++ src/games/rain/rain.c	Wed Feb 28 23:14:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: rain.c,v 1.22 2020/10/14 18:32:04 nia Exp $	*/
+/*	$NetBSD: rain.c,v 1.23 2024/02/28 23:14:37 charlotte 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.22 2020/10/14 18:32:04 nia Exp $");
+__RCSID("$NetBSD: rain.c,v 1.23 2024/02/28 23:14:37 charlotte Exp $");
 #endif
 #endif /* not lint */
 
@@ -97,6 +97,8 @@ main(int argc, char **argv)
 		errx(0, "couldn't initialize screen");
 	cols = COLS - 4;
 	lines = LINES - 4;
+	if (cols == 0) cols++;
+	if (lines == 0) lines++;
 
 	(void)signal(SIGHUP, onsig);
 	(void)signal(SIGINT, onsig);



CVS commit: src/games/rain

2024-02-28 Thread Charlotte Koch
Module Name:src
Committed By:   charlotte
Date:   Wed Feb 28 23:14:37 UTC 2024

Modified Files:
src/games/rain: rain.c

Log Message:
rain(6): Avoid division by zero

If there were exactly 4 LINES or COLS then we'd attempt to draw a raindrop
at some value mod 0, which is invalid.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/games/rain/rain.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.