From nobody Fri Feb 27 00:40:46 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fMTyQ68W1z6StG6 for ; Fri, 27 Feb 2026 00:40:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fMTyQ5VWxz3lGr for ; Fri, 27 Feb 2026 00:40:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1772152846; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yjo2JbayUIIx5WCV+MZoWJRq7D8nUE50ZGF+BkKdABI=; b=pGTLiZD8kdXW0AJLqKOo1eErnW+sP9wfBHinUasKPH15B4hnVZwNKtUcOS9V8pWWLa+j2C syGYrN1HLVRAW1ypPkFsVSraQMesQ/TpMg5kh2vTbsHLW7QJHOGbZMEBVgmoWtnkutSZsl GRZkSLCqjcuovP4ft4zgWaFW+LfiMmHNiiFRREFK1ehSPRZ867gIYfnc9sYvBRHbHAHyIB yIsg9VX+AKV4yO4BOfFTQTQ1G2Ps6yuOQKoNdMvvQkwPY4UqPqtxXRXf86iCNPaSX/NiVl DF+dd58s9KSuDjvVZdUlgz3eYR8ZPCvP9NL4D1fzrSBxg3cl05SIL/Sl+yXUhA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1772152846; a=rsa-sha256; cv=none; b=kvRCj5iExrND3CxNVfJHqlgLeJt4m4OMpncLzBDLEDny50h2WBg4A8CrBqirW99t/UKkLR HU/ugAgvHxAMnJ/N2rFEfwHxWeSpGlz8zQFv0B81cMXzngGBorgvUzpV9/lR6gdxFSKfJg InN0FiK4LR1xrWeUC6anCilRWQB4HSiQxJxieI7s272ssUcTCkMa9iLJHbsEeUiE4yXVRj yHMzKOQCCUgrIGnbULbyaqHTcFkGAW4SQ/vCYIerSVuavYWPW8F6tctpOLr7vs3SIBiYbk ictIwbWvOO1G6VqdcCXm1bwsFcdGn6v4ZrYYEOyHrWrKincQBVFsSaQkmyGcbw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1772152846; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yjo2JbayUIIx5WCV+MZoWJRq7D8nUE50ZGF+BkKdABI=; b=sUulQDQwc3tX6oFukyTMAog0s8GvIvYyrFJFpqsBeF6E74ddfDdKOj6htwW6SEi6Hl6y8k /qNelZwthshzsovVNWFfaF7xXJOh7M3ZgiDg3pEyNR8Ds5+hmX88CzBolOrPrJkvmct4c4 TZnhDPNcZUV53ihQgpouU5VK7pc7exbmMgqjRFOQz4/1RbsNhxBbW7zJcIp8WYCaKb4Zod ap3YZhkfKqbpH6hA7CzY45F1SMrKuxRf9esW3ki5zjG/jYZyQjovIRo+ZafbbJcD800C7h zc7CFQGAQjcA9B0V3rwqQyUbIH/9SWi+Z8zZsWAe52fpjH1NeFYVEGRoaGB3gQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fMTyQ54dBzvSp for ; Fri, 27 Feb 2026 00:40:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 463d2 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 27 Feb 2026 00:40:46 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 7951411672fa - main - sanitize.lua: A tool to extract interfaces from files List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7951411672fab14367d9e785bfc6fe7d9a29668c Auto-Submitted: auto-generated Date: Fri, 27 Feb 2026 00:40:46 +0000 Message-Id: <69a0e80e.463d2.1099fb1d@gitrepo.freebsd.org> The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=7951411672fab14367d9e785bfc6fe7d9a29668c commit 7951411672fab14367d9e785bfc6fe7d9a29668c Author: Warner Losh AuthorDate: 2026-02-27 00:40:10 +0000 Commit: Warner Losh CommitDate: 2026-02-27 00:40:32 +0000 sanitize.lua: A tool to extract interfaces from files This is a simple too to remove all comments, extra whitespace and other unnecessary things that may have creative content. What remains can be just the minimal interface described by the header file. When used with care, this can mechanically sanitize files, like some device tree bindings file, that are only #defines that are meant to be used in multiple context (the dts files and in C code to interpret the resulting dtb). Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55087 --- tools/tools/git/sanitize.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tools/tools/git/sanitize.lua b/tools/tools/git/sanitize.lua new file mode 100644 index 000000000000..a1c9317f3727 --- /dev/null +++ b/tools/tools/git/sanitize.lua @@ -0,0 +1,53 @@ +-- SPDX-License-Identifier: BSD-2-Clause +-- Copyright 2026 Warner Losh + +-- +-- Removes all comments, blank lines and extra whitespace from a C header file +-- and inserts a generated from comment at the top. Generally, this extracts the +-- smallest subset of the file that describes the interface that is necessary to +-- interoperate with that software. The user of this program should check the +-- results, however, to ensure the result minimally describes the public +-- interface. +-- +-- When applied to device-tree binding files, this will result in the #defines +-- being extracted, which are needed to generate the .dtb files, as well as for +-- code to interpret the .dtb files. The device-tree files must be written this +-- way to be used for this dual purpose. Other header files may not be so +-- constrained, which makes review necessary for those context. +-- + +-- +-- Useage lua sanitize.lua fn description +-- +-- fn will be read in, sanitized and the results printed on stdout. +-- The description will be all remaining args and will be inserted +-- in the first line comment to describe where the source file was +-- obtained from. +-- + +-- Open the file from the command line +local fn = arg[1] +if not fn then + print("Usage: sanitize fn") + os.exit(1) +end + +-- read it all in +local f = assert(io.open(fn)) +local content = f:read("*all") +f:close() + +-- Transform +content = content:gsub("/%*.-%*/", "") -- Remove block comments, .- is lazy, not greed, match +content = content:gsub("//[^\n]*", "") -- Remove single line comments +content = content:gsub("%s*\n", "\n") -- Remove trailing white space +content = content:gsub("\t+", " ") -- Convert blocks of tabs to a space +content = content:gsub("\n+", "\n") -- Remove blank lines +content = content:gsub("\n+$", "") -- Strip blank lines at the end (print adds one) +content = content:gsub("^\n+", "") -- Strip leading blank lines + +print("/* @" .. "generated from the interface found in " .. fn .. " -- result is in public domain */") +if arg[2] then + print("/* from " .. table.concat(table.pack(table.unpack(arg, 2)), ' ') .. " */") +end +print(content)