Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/echo echo: clean up, increase WARNS to 6



details:   https://anonhg.NetBSD.org/src/rev/40da6fca93e2
branches:  trunk
changeset: 989044:40da6fca93e2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 10 19:07:19 2021 +0000

description:
echo: clean up, increase WARNS to 6

Lint can handle __COPYRIGHT and __RCSID, so there is no need to hide
them anymore.

Use proper type 'bool' for nflag, ensure correct types via lint's strict
bool mode.

Remove unnecessary call to exit(0); returning from main is equivalent
since C99.

No functional change.

diffstat:

 bin/echo/Makefile |   5 ++++-
 bin/echo/echo.c   |  26 +++++++++-----------------
 2 files changed, 13 insertions(+), 18 deletions(-)

diffs (84 lines):

diff -r 5cf1b326d62a -r 40da6fca93e2 bin/echo/Makefile
--- a/bin/echo/Makefile Sun Oct 10 18:46:25 2021 +0000
+++ b/bin/echo/Makefile Sun Oct 10 19:07:19 2021 +0000
@@ -1,6 +1,9 @@
-#      $NetBSD: Makefile,v 1.8 1997/07/20 22:36:53 christos Exp $
+#      $NetBSD: Makefile,v 1.9 2021/10/10 19:07:19 rillig Exp $
 #      @(#)Makefile    8.1 (Berkeley) 5/31/93
 
 PROG=  echo
 
+WARNS=         6
+LINTFLAGS+=    -T -w
+
 .include <bsd.prog.mk>
diff -r 5cf1b326d62a -r 40da6fca93e2 bin/echo/echo.c
--- a/bin/echo/echo.c   Sun Oct 10 18:46:25 2021 +0000
+++ b/bin/echo/echo.c   Sun Oct 10 19:07:19 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: echo.c,v 1.20 2021/05/19 22:12:36 kre Exp $        */
+/* $NetBSD: echo.c,v 1.21 2021/10/10 19:07:19 rillig Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -30,22 +30,19 @@
  */
 
 #include <sys/cdefs.h>
-#ifndef lint
 __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[] = "@(#)echo.c     8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: echo.c,v 1.20 2021/05/19 22:12:36 kre Exp $");
+__RCSID("$NetBSD: echo.c,v 1.21 2021/10/10 19:07:19 rillig Exp $");
 #endif
-#endif /* not lint */
 
 #include <err.h>
 #include <locale.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -54,29 +51,24 @@
 int
 main(int argc, char *argv[])
 {
-       int nflag;
+       bool nflag;
 
        setprogname(argv[0]);
        (void)setlocale(LC_ALL, "");
 
        /* This utility may NOT do getopt(3) option parsing. */
-       if (*++argv && !strcmp(*argv, "-n")) {
+       nflag = *++argv != NULL && strcmp(*argv, "-n") == 0;
+       if (nflag)
                ++argv;
-               nflag = 1;
-       }
-       else
-               nflag = 0;
 
-       while (*argv) {
+       while (*argv != NULL) {
                (void)printf("%s", *argv);
-               if (*++argv)
+               if (*++argv != NULL)
                        (void)putchar(' ');
        }
-       if (nflag == 0)
+       if (!nflag)
                (void)putchar('\n');
        fflush(stdout);
        if (ferror(stdout))
                err(1, "write error");
-       exit(0);
-       /* NOTREACHED */
 }



Home | Main Index | Thread Index | Old Index