changeset 2712:ac63db65b917

Implement -Wextra for some extra warnings.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 04 Mar 2024 11:20:27 +0200
parents 63d100185adf
children b87091b47c42
files src/mkloc.c
diffstat 1 files changed, 50 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/mkloc.c	Mon Mar 04 11:07:12 2024 +0200
+++ b/src/mkloc.c	Mon Mar 04 11:20:27 2024 +0200
@@ -30,9 +30,11 @@
     WARN_NONE                = 0x0000,
     WARN_MARKER_INVALID      = 0x0001,
     WARN_MARKER_MISSING      = 0x0002,
-    WARN_AUTHORS            = 0x0004,
-    WARN_TIMESTAMPS          = 0x0008,
-    WARN_ALL                 = 0xffff
+    WARN_AUTHORS_MISSING     = 0x0004,
+    WARN_TIMESTAMPS_MISSING  = 0x0008,
+
+    WARN_EXTRA               = 0x1000,
+    WARN_ALL                 = 0x0fff
 };
 
 
@@ -91,7 +93,8 @@
     { 18,'t', "type-prefix", "Prepend labels with type prefix", OPT_NONE },
     { 19,'X', "markers",     "Location markers ('" LOC_MARKERS "')", OPT_ARGREQ },
     { 22,'W', "warnings",    "Output warnings about: "
-                             "none, all, timestamps, authors", OPT_ARGREQ },
+                             "none, all, timestamps, authors, extra\n"
+                             "(NOTE: 'all' does NOT include 'extra')", OPT_ARGREQ },
     { 23,  0, "warn-loc",    "Output warnings to loc file instead of stderr", OPT_NONE },
 };
 
@@ -265,11 +268,14 @@
         else
         switch (tolower(optArg[0]))
         {
-            case 't':
-                optWarnings |= WARN_TIMESTAMPS;
+            case 'a':
+                optWarnings |= WARN_AUTHORS_MISSING;
                 break;
-            case 'c':
-                optWarnings |= WARN_AUTHORS;
+            case 't':
+                optWarnings |= WARN_TIMESTAMPS_MISSING;
+                break;
+            case 'e':
+                optWarnings |= WARN_EXTRA;
                 break;
             default:
                 THERR("Invalid argument to -W: '%s'\n", optArg);
@@ -736,11 +742,45 @@
                 (loc->flags & LOCF_M_PCITY) == 0 &&
                 (loc->flags & LOCF_T_SHRINE) == 0)
             {
-                if ((optWarnings & WARN_TIMESTAMPS) && !loc->valid)
+                if ((optWarnings & WARN_TIMESTAMPS_MISSING) && !loc->valid)
                     printLocWarning(&first, outFile, loc, "No timestamp");
 
-                if ((optWarnings & WARN_AUTHORS) && loc->nauthors == 0)
+                if ((optWarnings & WARN_AUTHORS_MISSING) && loc->nauthors == 0)
                     printLocWarning(&first, outFile, loc, "No authors listed");
+
+                if (optWarnings & WARN_EXTRA)
+                {
+                    if (loc->valid)
+                    {
+                        const char *msg = NULL;
+                        switch (loc->added.accuracy)
+                        {
+                            case TS_ACC_DEFAULT:
+                                msg = "Addition timestamp 'default'.";
+                                break;
+/*
+                            case TS_ACC_GUESSTIMATE:
+                                msg = "Addition timestamp 'approximate'.";
+                                break;
+*/
+                        }
+                        if (msg != NULL)
+                            printLocWarning(&first, outFile, loc, msg);
+                    }
+
+                    if (loc->nauthors > 0)
+                    {
+                        int flags = 0;
+                        for (int nauthor = 0; nauthor < loc->nauthors; nauthor++)
+                        {
+                            flags |= loc->authors[nauthor].flags;
+                        }
+                        if ((flags & AUTHOR_ORIG) == 0)
+                        {
+                            printLocWarning(&first, outFile, loc, "Primary author not set");
+                        }
+                    }
+                }
             }
         }