From c6719e8ef2835fb712eeca67be621c580c2eeb95 Mon Sep 17 00:00:00 2001 From: Nikhil Anand Date: Thu, 5 Nov 2026 21:53:09 +0530 Subject: [PATCH] Recognize *.h.in files as C source in CLexer Add *.h.in to the CLexer filename patterns so that C header templates such as config.h.in are correctly identified. Add a data-driven regression fixture for config.h.in. Fixes https://github.com/aboutcode-org/scancode-toolkit/issues/605 Signed-off-by: Nikhil Anand --- src/typecode/pygments_lexers_mapping.py | 2 +- tests/data/filetest/code/c/config.h.in | 196 +++++++++++++++++++++ tests/data/filetest/code/c/config.h.in.yml | 11 ++ 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 tests/data/filetest/code/c/config.h.in create mode 100644 tests/data/filetest/code/c/config.h.in.yml diff --git a/src/typecode/pygments_lexers_mapping.py b/src/typecode/pygments_lexers_mapping.py index 624909a..c33af50 100644 --- a/src/typecode/pygments_lexers_mapping.py +++ b/src/typecode/pygments_lexers_mapping.py @@ -121,7 +121,7 @@ "typecode._vendor.pygments.lexers.c_cpp", "C", ("c",), - ("*.c", "*.h", "*.idc"), + ("*.c", "*.h", "*.idc", "*.h.in"), ("text/x-chdr", "text/x-csrc"), ), "CMakeLexer": ( diff --git a/tests/data/filetest/code/c/config.h.in b/tests/data/filetest/code/c/config.h.in new file mode 100644 index 0000000..73e7ee7 --- /dev/null +++ b/tests/data/filetest/code/c/config.h.in @@ -0,0 +1,196 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* disable extf queries */ +#undef DISABLE_EXTF + +/* Use libevent v1 */ +#undef EVENT_V1 + +/* Use libevent v2 */ +#undef EVENT_V2 + +/* Define to 1 if you have the `alarm' function. */ +#undef HAVE_ALARM + +/* Define to 1 if you have the header file. */ +#undef HAVE_ARPA_INET_H + +/* Define to 1 if you have the `endpwent' function. */ +#undef HAVE_ENDPWENT + +/* Define to 1 if you have the header file. */ +#undef HAVE_EXECINFO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LAUXLIB_H + +/* Define to 1 if you have the `config' library (-lconfig). */ +#undef HAVE_LIBCONFIG + +/* Define to 1 if you have the `event' library (-levent). */ +#undef HAVE_LIBEVENT + +/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */ +#undef HAVE_LIBGCRYPT + +/* Define to 1 if you have the `jansson' library (-ljansson). */ +#undef HAVE_LIBJANSSON + +/* Define to 1 if you have `z' library (-lz) */ +#undef HAVE_LIBZ + +/* Define to 1 if you have the header file. */ +#undef HAVE_LUACONF_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LUALIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LUA_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MACH_MACH_H + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#undef HAVE_MALLOC + +/* Define to 1 if you have the header file. */ +#undef HAVE_MALLOC_H + +/* Define to 1 if you have the `memmove' function. */ +#undef HAVE_MEMMOVE + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to 1 if you have the `mkdir' function. */ +#undef HAVE_MKDIR + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETDB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IN_H + +/* Define to 1 if your system has a GNU libc compatible `realloc' function, + and to 0 otherwise. */ +#undef HAVE_REALLOC + +/* Define to 1 if you have the `select' function. */ +#undef HAVE_SELECT + +/* Define to 1 if you have the `socket' function. */ +#undef HAVE_SOCKET + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strdup' function. */ +#undef HAVE_STRDUP + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strndup' function. */ +#undef HAVE_STRNDUP + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_FILE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_TERMIOS_H + +/* Define to 1 if you have the `uname' function. */ +#undef HAVE_UNAME + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if the system has the `__builtin_bswap32' built-in function */ +#undef HAVE___BUILTIN_BSWAP32 + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Use custom prog name */ +#undef PROG_NAME + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* avoid OpenSSL entirely, use libgcrypt instead (this can't read *.pub files, + though.) */ +#undef TGL_AVOID_OPENSSL + +/* use json */ +#undef USE_JSON + +/* use lua */ +#undef USE_LUA + +/* use python */ +#undef USE_PYTHON + +/* fixed for correct valgrind work */ +#undef VALGRIND_FIXES + +/* Define to `int' if doesn't define. */ +#undef gid_t + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to rpl_malloc if the replacement function should be used. */ +#undef malloc + +/* Define to rpl_realloc if the replacement function should be used. */ +#undef realloc + +/* Define to `unsigned int' if does not define. */ +#undef size_t + +/* Define to `int' if doesn't define. */ +#undef uid_t diff --git a/tests/data/filetest/code/c/config.h.in.yml b/tests/data/filetest/code/c/config.h.in.yml new file mode 100644 index 0000000..aeeec06 --- /dev/null +++ b/tests/data/filetest/code/c/config.h.in.yml @@ -0,0 +1,11 @@ +filetype_file: C source +mimetype_file: text/x-c +mimetype_python: text/plain +filetype_pygment: C +programming_language: C +is_file: yes +is_regular: yes +size: 5028 +is_text: yes +contains_text: yes +is_source: yes