From 0c7f1034f20ac87259878c0c45b44d5f67faf3bdfc23ab19ae87f50e1150141d Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 4 Apr 2025 11:46:06 +0300 Subject: [PATCH] Fix included headers --- c/cmd/pp/pp.c | 21 ++++++++++++++++++++- c/compile_flags.txt.do | 3 ++- c/conf/cflags | 1 + c/lib/dec.h | 2 +- c/lib/dectai.c | 1 - c/lib/dectai.h | 3 +-- c/lib/enctai.h | 2 +- c/lib/schema.h | 2 +- c/lint/iwyu | 9 +++++++++ c/lint/iwyu-maps.imp | 1 + 10 files changed, 37 insertions(+), 8 deletions(-) create mode 100755 c/lint/iwyu diff --git a/c/cmd/pp/pp.c b/c/cmd/pp/pp.c index 5cba845..c30d1f1 100644 --- a/c/cmd/pp/pp.c +++ b/c/cmd/pp/pp.c @@ -20,12 +20,20 @@ #include #include #include +#include #include #include #include -#include #include +#ifdef __FreeBSD__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreserved-macro-identifier" +#define __BSD_VISIBLE 1 +#pragma clang diagnostic pop +#endif +#include + #include #include #include @@ -84,7 +92,10 @@ printer( // NOLINT(misc-no-recursion) fputs(" ", stdout); } else { fprintf(stdout, "%s%zd%s ", ColourBlue, indent, ColourReset); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-nonliteral" fprintf(stdout, OffFmt, ColourRed, items->offsets[idx], ColourReset); +#pragma clang diagnostic pop } struct KEKSItem *item = &(items->list[idx]); printIndent(indent); @@ -372,13 +383,21 @@ main(int argc, char **argv) KEKSItemsNoOffsets(&items); } errno = 0; +#ifdef __FreeBSD__ if (clock_gettime(CLOCK_MONOTONIC_PRECISE, &started) != 0) { +#else + if (clock_gettime(CLOCK_MONOTONIC, &started) != 0) { +#endif fprintf(stderr, "clock_gettime(started): %s\n", strerror(errno)); exit(EXIT_FAILURE); } err = KEKSItemsParse(&items, &off, buf, len); errno = 0; +#ifdef __FreeBSD__ if (clock_gettime(CLOCK_MONOTONIC_PRECISE, &finished) != 0) { +#else + if (clock_gettime(CLOCK_MONOTONIC, &finished) != 0) { +#endif fprintf(stderr, "clock_gettime(finished): %s\n", strerror(errno)); exit(EXIT_FAILURE); } diff --git a/c/compile_flags.txt.do b/c/compile_flags.txt.do index 1b9f125..302dc07 100644 --- a/c/compile_flags.txt.do +++ b/c/compile_flags.txt.do @@ -1,3 +1,4 @@ -redo-ifchange conf/prefix +redo-ifchange conf/cflags conf/prefix read PREFIX -#include "atom.h" +#include "atom.h" // IWYU pragma: keep // struct KEKSAtom #include "err.h" // TEXINFO: KEKSAtomDecode diff --git a/c/lib/dectai.c b/c/lib/dectai.c index ace0cab..8684bd5 100644 --- a/c/lib/dectai.c +++ b/c/lib/dectai.c @@ -13,7 +13,6 @@ // You should have received a copy of the GNU Lesser General Public // License along with this program. If not, see . -#include #include #include diff --git a/c/lib/dectai.h b/c/lib/dectai.h index 49a69d9..3724578 100644 --- a/c/lib/dectai.h +++ b/c/lib/dectai.h @@ -1,8 +1,7 @@ #ifndef KEKS_DECTAI_H #define KEKS_DECTAI_H -#include -#include +#include // IWYU pragma: keep // struct timespec #include "err.h" diff --git a/c/lib/enctai.h b/c/lib/enctai.h index 6bd612d..2ed501c 100644 --- a/c/lib/enctai.h +++ b/c/lib/enctai.h @@ -2,7 +2,7 @@ #define KEKS_ENCTAI_H #include -#include +#include // IWYU pragma: keep // struct timespec // TEXINFO: KEKSTimespecToTAI64 // @deftypefun bool KEKSTimespecToTAI64 @ diff --git a/c/lib/schema.h b/c/lib/schema.h index 1a280a5..502674c 100644 --- a/c/lib/schema.h +++ b/c/lib/schema.h @@ -3,7 +3,7 @@ #include -#include "items.h" +#include "items.h" // IWYU pragma: keep // struct KEKSItems // TEXINFO: KEKSSchemaErrType // @deftp {Data type} {enum KEKSSchemaErrType} diff --git a/c/lint/iwyu b/c/lint/iwyu new file mode 100755 index 0000000..0b249dd --- /dev/null +++ b/c/lint/iwyu @@ -0,0 +1,9 @@ +#!/bin/sh -e + +root=${0%/*} +redo-ifchange $root/../compile_flags.txt +cflags=$(cat $root/../compile_flags.txt) +[ $# -eq 0 ] && srcs=*.c || srcs="$@" +for c in $srcs ; do + include-what-you-use $cflags -Xiwyu --mapping_file=$root/iwyu-maps.imp $c 2>&1 +done diff --git a/c/lint/iwyu-maps.imp b/c/lint/iwyu-maps.imp index 446e7e9..fd6611b 100644 --- a/c/lint/iwyu-maps.imp +++ b/c/lint/iwyu-maps.imp @@ -1,5 +1,6 @@ [ { symbol: ["CLOCK_REALTIME", "private", "", "public"] }, + { symbol: ["CLOCK_MONOTONIC_PRECISE", "private", "", "public"] }, { symbol: ["PTRDIFF_MAX", "private", "", "public"] }, { symbol: ["SIZE_MAX", "private", "", "public"] }, ] -- 2.48.1