Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: move error handling code from main...



details:   https://anonhg.NetBSD.org/src/rev/c9f1c5685f89
branches:  trunk
changeset: 368255:c9f1c5685f89
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 01 21:25:39 2022 +0000

description:
lint: move error handling code from main1.c to err.c

No functional change.

diffstat:

 usr.bin/xlint/lint1/err.c      |  43 +++++++++++++++++++++++++++++++++++++++--
 usr.bin/xlint/lint1/externs1.h |   3 +-
 usr.bin/xlint/lint1/lint1.h    |  20 +------------------
 usr.bin/xlint/lint1/main1.c    |  27 +------------------------
 4 files changed, 45 insertions(+), 48 deletions(-)

diffs (204 lines):

diff -r af88c5b1178b -r c9f1c5685f89 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Fri Jul 01 21:22:44 2022 +0000
+++ b/usr.bin/xlint/lint1/err.c Fri Jul 01 21:25:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.177 2022/07/01 20:53:13 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.178 2022/07/01 21:25:39 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,11 +37,14 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.177 2022/07/01 20:53:13 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.178 2022/07/01 21:25:39 rillig Exp $");
 #endif
 
+#include <errno.h>
+#include <limits.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "lint1.h"
 
@@ -264,7 +267,7 @@
        "break outside loop or switch",                               /* 208 */
        "continue outside loop",                                      /* 209 */
        "enum type mismatch between '%s' and '%s' in initialization", /* 210 */
-       "function has return type '%s' but returns '%s'",                     /* 211 */
+       "function has return type '%s' but returns '%s'",             /* 211 */
        "cannot return incomplete type",                              /* 212 */
        "void function '%s' cannot return value",                     /* 213 */
        "function '%s' expects to return value",                      /* 214 */
@@ -405,12 +408,46 @@
        "non type argument to alignof is a GCC extension",            /* 349 */
 };
 
+#define        ERR_SETSIZE     1024
+#define __NERRBITS (sizeof(unsigned int))
+
+typedef        struct err_set {
+       unsigned int    errs_bits[(ERR_SETSIZE + __NERRBITS-1) / __NERRBITS];
+} err_set;
+
+#define        ERR_SET(n, p)   \
+       ((p)->errs_bits[(n)/__NERRBITS] |= (1 << ((n) % __NERRBITS)))
+#define        ERR_CLR(n, p)   \
+       ((p)->errs_bits[(n)/__NERRBITS] &= ~(1 << ((n) % __NERRBITS)))
+#define        ERR_ISSET(n, p) \
+       (((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS))) != 0)
+#define        ERR_ZERO(p)     (void)memset((p), 0, sizeof(*(p)))
+
+static err_set msgset;
+
 static struct include_level {
        const char *filename;
        int lineno;
        struct include_level *by;
 } *includes;
 
+void
+suppress_messages(char *ids)
+{
+       char *ptr, *end;
+       long id;
+
+       for (ptr = strtok(ids, ","); ptr != NULL; ptr = strtok(NULL, ",")) {
+               errno = 0;
+               id = strtol(ptr, &end, 0);
+               if ((id == TARG_LONG_MIN || id == TARG_LONG_MAX) &&
+                   errno == ERANGE)
+                       err(1, "invalid error message id '%s'", ptr);
+               if (*end != '\0' || ptr == end || id < 0 || id >= ERR_SETSIZE)
+                       errx(1, "invalid error message id '%s'", ptr);
+               ERR_SET(id, &msgset);
+       }
+}
 
 void
 update_location(const char *filename, int lineno, bool is_begin, bool is_end)
diff -r af88c5b1178b -r c9f1c5685f89 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Fri Jul 01 21:22:44 2022 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Fri Jul 01 21:25:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.162 2022/06/15 18:29:21 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.163 2022/07/01 21:25:39 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -168,6 +168,7 @@
 extern void    assert_failed(const char *, int, const char *, const char *)
                __attribute__((__noreturn__));
 extern void    update_location(const char *, int, bool, bool);
+extern void    suppress_messages(char *);
 
 /*
  * decl.c
diff -r af88c5b1178b -r c9f1c5685f89 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Fri Jul 01 21:22:44 2022 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Fri Jul 01 21:25:39 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.154 2022/05/26 13:40:49 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.155 2022/07/01 21:25:39 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -442,21 +442,6 @@
 
 #include "externs1.h"
 
-#define        ERR_SETSIZE     1024
-#define __NERRBITS (sizeof(unsigned int))
-
-typedef        struct err_set {
-       unsigned int    errs_bits[(ERR_SETSIZE + __NERRBITS-1) / __NERRBITS];
-} err_set;
-
-#define        ERR_SET(n, p)   \
-       ((p)->errs_bits[(n)/__NERRBITS] |= (1 << ((n) % __NERRBITS)))
-#define        ERR_CLR(n, p)   \
-       ((p)->errs_bits[(n)/__NERRBITS] &= ~(1 << ((n) % __NERRBITS)))
-#define        ERR_ISSET(n, p) \
-       (((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS))) != 0)
-#define        ERR_ZERO(p)     (void)memset((p), 0, sizeof(*(p)))
-
 #define INTERNAL_ERROR(fmt, args...) \
        internal_error(__FILE__, __LINE__, fmt, ##args)
 
@@ -466,9 +451,6 @@
                        assert_failed(__FILE__, __LINE__, __func__, #cond); \
        } while (false)
 
-extern err_set msgset;
-
-
 #ifdef DEBUG
 #  include "err-msgs.h"
 
diff -r af88c5b1178b -r c9f1c5685f89 usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c       Fri Jul 01 21:22:44 2022 +0000
+++ b/usr.bin/xlint/lint1/main1.c       Fri Jul 01 21:25:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main1.c,v 1.63 2022/05/30 15:13:25 rillig Exp $        */
+/*     $NetBSD: main1.c,v 1.64 2022/07/01 21:25:39 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,12 +37,10 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: main1.c,v 1.63 2022/05/30 15:13:25 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.64 2022/07/01 21:25:39 rillig Exp $");
 #endif
 
 #include <sys/types.h>
-#include <errno.h>
-#include <limits.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -120,8 +118,6 @@
 bool   allow_c11;
 bool   allow_gcc;
 
-err_set        msgset;
-
 sig_atomic_t fpe;
 
 static void    usage(void);
@@ -174,24 +170,6 @@
        fpe = 1;
 }
 
-static void
-suppress_messages(char *ids)
-{
-       char *ptr, *end;
-       long id;
-
-       for (ptr = strtok(ids, ","); ptr != NULL; ptr = strtok(NULL, ",")) {
-               errno = 0;
-               id = strtol(ptr, &end, 0);
-               if ((id == TARG_LONG_MIN || id == TARG_LONG_MAX) &&
-                   errno == ERANGE)
-                       err(1, "invalid error message id '%s'", ptr);
-               if (*end != '\0' || ptr == end || id < 0 || id >= ERR_SETSIZE)
-                       errx(1, "invalid error message id '%s'", ptr);
-               ERR_SET(id, &msgset);
-       }
-}
-
 int
 main(int argc, char *argv[])
 {
@@ -199,7 +177,6 @@
 
        setprogname(argv[0]);
 
-       ERR_ZERO(&msgset);
        while ((c = getopt(argc, argv, "abceghmprstuvwyzA:FPR:STX:")) != -1) {
                switch (c) {
                case 'a':       aflag++;        break;



Home | Main Index | Thread Index | Old Index