Module Name:    src
Committed By:   rillig
Date:           Sat Oct 12 19:26:24 UTC 2024

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

Log Message:
morse: clean up

No binary change on amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/games/morse/morse.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/morse/morse.c
diff -u src/games/morse/morse.c:1.22 src/games/morse/morse.c:1.23
--- src/games/morse/morse.c:1.22	Sun Jun 16 18:09:45 2024
+++ src/games/morse/morse.c	Sat Oct 12 19:26:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: morse.c,v 1.22 2024/06/16 18:09:45 rillig Exp $	*/
+/*	$NetBSD: morse.c,v 1.23 2024/10/12 19:26:24 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -30,18 +30,10 @@
  */
 
 #include <sys/cdefs.h>
-#ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1988, 1993\
  The Regents of the University of California.  All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)morse.c	8.1 (Berkeley) 5/31/93";
-#else
-__RCSID("$NetBSD: morse.c,v 1.22 2024/06/16 18:09:45 rillig Exp $");
-#endif
-#endif /* not lint */
+/*	@(#)morse.c	8.1 (Berkeley) 5/31/93	*/
+__RCSID("$NetBSD: morse.c,v 1.23 2024/10/12 19:26:24 rillig Exp $");
 
 #include <ctype.h>
 #include <stdio.h>
@@ -91,7 +83,7 @@ static const char alph[][5] = {
 	"--..",
 };
 
-static const struct punc {
+static const struct {
 	char c;
 	const char morse[7];
 } other[] = {
@@ -129,14 +121,13 @@ main(int argc, char **argv)
 	setgid(getgid());
 
 	while ((ch = getopt(argc, argv, "ds")) != -1)
-		switch((char)ch) {
+		switch ((char)ch) {
 		case 'd':
 			dflag = 1;
 			break;
 		case 's':
 			sflag = 1;
 			break;
-		case '?':
 		default:
 			fprintf(stderr, "usage: morse [-ds] [string ...]\n");
 			exit(1);
@@ -202,53 +193,45 @@ main(int argc, char **argv)
 void
 decode(const char *s)
 {
-	int i;
-
-	for (i = 0; i < 10; i++)
+	for (size_t i = 0; i < __arraycount(digit); i++)
 		if (strcmp(digit[i], s) == 0) {
 			putchar('0' + i);
 			return;
 		}
 
-	for (i = 0; i < 26; i++)
+	for (size_t i = 0; i < __arraycount(alph); i++)
 		if (strcmp(alph[i], s) == 0) {
 			putchar('A' + i);
 			return;
 		}
-	i = 0;
-	while (other[i].c) {
+
+	for (size_t i = 0; other[i].c; i++)
 		if (strcmp(other[i].morse, s) == 0) {
 			putchar(other[i].c);
 			return;
 		}
-		i++;
-	}
-	if (strcmp("...-.-", s) == 0)
+
+	if (strcmp("...-.-", s) == 0)	/* SK */
 		return;
+
 	putchar('x');	/* line noise */
 }
 
 void
 morse(int c)
 {
-	int i;
-
 	if (isalpha(c))
 		show(alph[c - (isupper(c) ? 'A' : 'a')]);
 	else if (isdigit(c))
 		show(digit[c - '0']);
 	else if (isspace(c))
 		show("");  /* could show BT for a pause */
-	else {
-		i = 0;
-		while (other[i].c) {
+	else
+		for (int i = 0; other[i].c; i++)
 			if (other[i].c == c) {
 				show(other[i].morse);
 				break;
 			}
-			i++;
-		}
-	}
 }
 
 void

Reply via email to