From nobody Mon Jul 6 19:44:13 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 4gvFDM1nFdz6kZS8 for ; Mon, 06 Jul 2026 19:44:19 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gvFDL5CPcz3nys for ; Mon, 06 Jul 2026 19:44:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783367058; 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=x5WxCErwc6UXOSEp1mVXHQZDML581pxQ96DOlijXNrY=; b=fgFVBI8CDG7TsF/v7Cd0iwK/KqjLqV/j51WoUhoRayfeVPAjVGM2YRFJi2GMt23b6Qm5YG PpxbfPWV/YrCrqeRUCYvEhQoEunxld4a/1iteTJdbcYi9DMX4fPWI1KjDE7DfTIXlIT9Qi KpmA0PN+sElMZkBIS6CJ3zxq7Iq7AMfbJZ6V1cAu7crI1J/uHHq01l0tRrd4HJwnbTyLq6 fGGYB+CUrOAuUw2tgmcTy6tc0lIlCArLcELh/yRGe5ySOHwHzrriRl2xhGI+B+PcJw55nY RWa0JzDjWAo+Wfx5IGtD0hyL+PV3+61PUk0CBiYFAstWAmBxc7/U87h/B9D7ZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1783367058; a=rsa-sha256; cv=none; b=VqaahtxmFBXO38dYllMA8CMEHOG4OtHoHOwQi4fWCjY6YP9Yg5A2U0G2qshue5fQfPmWqb jkC9vTL30p9R6wI65jHF16lnIjcSTkyphvFs20yqdvZw+bJuWbGMf66U+3dkem66Qm6qGm Pos89OY67Usg4S01lp4iF25jxSiTZSvgGN3t0S+++J9WcnWvKhEt/7bhCkoy874tDjEeAc QqQXc0PDC0Lpboee+/ZCZeK2aXMJcBVMVsFGegzLFF2gd183OOFkUV9ri7Jegvb8gTRh1m dod1VWjDUHY2JN5oFn55sYtRQO9dYhLrlP40gMvkjDGUNUgz93BMNw4fKNELYw== 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=1783367058; 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=x5WxCErwc6UXOSEp1mVXHQZDML581pxQ96DOlijXNrY=; b=eJqSHHsN/oGUMQYF+sBIOwuQEG3wzi5eNOAiWpd302jg21p65OSTSimb6g5zKXZesevOX8 MPY4C11i2MRSXLMlgpjJB5CiaDgDG3nE05+/hixjitxzJ7bCnjIblwj3BzXXlfZzKOh0YQ AjjTIfps6SNCYv5U4rDURnywX+uYwZ35LIxiIe8lFW6x6PIudcSojauSndb7Mhb0mGO7ZH yfev+6YFq5ZfR2LqssYTE5Jy5+zLG1+65B6EUY9XCP5V/EeHwoJLIUpJSm9AvXhrzP52N7 aCM2bd+RQnI4kL1NPayGLFqPGSos/jPGqfsVtdXl4dGzfIrlZkH/1R6Vn3a2Rg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gvFDL40Kbz1HNQ for ; Mon, 06 Jul 2026 19:44:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3ff3a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 06 Jul 2026 19:44:13 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 8b197806dcdf - main - libsysdecode: Teach mktables to handle enums 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8b197806dcdff5673dd4f77a97bf46035d14db2a Auto-Submitted: auto-generated Date: Mon, 06 Jul 2026 19:44:13 +0000 Message-Id: <6a4c058d.3ff3a.44bb1175@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=8b197806dcdff5673dd4f77a97bf46035d14db2a commit 8b197806dcdff5673dd4f77a97bf46035d14db2a Author: Dag-Erling Smørgrav AuthorDate: 2026-07-06 19:41:15 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-07-06 19:41:15 +0000 libsysdecode: Teach mktables to handle enums While here, clean up and simplify the existing code. MFC after: 1 week Reviewed by: glebius, jhb Differential Revision: https://reviews.freebsd.org/D57993 --- lib/libsysdecode/mktables | 59 +++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/lib/libsysdecode/mktables b/lib/libsysdecode/mktables index e7dde6f8e2ff..df742ff62f39 100644 --- a/lib/libsysdecode/mktables +++ b/lib/libsysdecode/mktables @@ -48,35 +48,54 @@ fi all_headers= # -# Generate a table C #definitions. The including file can define the -# TABLE_NAME(n), TABLE_ENTRY(x), and TABLE_END macros to define what -# the tables map to. +# Generate a table from C preprocessor symbol definitions. The +# including file can define the TABLE_START(n), TABLE_ENTRY(x), and +# TABLE_END macros to define what the tables map to. # gen_table() { - local name grep file excl filter - name=$1 - grep=$2 - file=$3 - excl=$4 + local name=$1 grep=$2 file=$3 excl=$4 - if [ -z "$excl" ]; then - filter="cat" - else - filter="egrep -v" + cat <<_EOF_ +TABLE_START(${name}) +_EOF_ + if [ -e "${include_dir}/${file}" ]; then + all_headers="${all_headers:+${all_headers} }${file}" + sed -nE ${excl:+-e "/${excl}/d"} \ + -e "/^#[[:space:]]*define[[:space:]]+${grep}/p" \ + "${include_dir}/${file}" | \ + sed -Ee 's/.*define[[:space:]]+([^[:space:]]+)\>.*/TABLE_ENTRY(\1)/' fi +cat <<_EOF_ +TABLE_END + +_EOF_ +} + +# +# Generate a table from C enum definitions. The including file can +# define the TABLE_START(n), TABLE_ENTRY(x), and TABLE_END macros to +# define what the tables map to. Works with most enum definitions as +# long as each constant is on a line by itself. +# +gen_table_enum() +{ + local name=$1 grep=$2 file=$3 excl=$4 + cat <<_EOF_ TABLE_START(${name}) _EOF_ if [ -e "${include_dir}/${file}" ]; then all_headers="${all_headers:+${all_headers} }${file}" - egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ - $include_dir/$file | ${filter} ${excl} | \ - awk '{ for (i = 1; i <= NF; i++) \ - if ($i ~ /define/) \ - break; \ - ++i; \ - printf "TABLE_ENTRY(%s)\n", $i }' + # preprocess the header + ${CPP:-${CC:-cc} -E} "${include_dir}/${file}" | + # filter out directives and apply exclusion + sed -Ee '/^#/d' ${excl:+-e "/${excl}/d"} | + # extract all enum definitions + awk '/^(typedef[[:space:]]*)?enum([[:space:]].*)?\{/, + /^\}([[:space:]].*)?;/' | + # pick out the constants we want + sed -Ene 's/^[[:space:]]*('"${grep}"')\>.*/TABLE_ENTRY(\1)/p' fi cat <<_EOF_ TABLE_END @@ -127,7 +146,7 @@ gen_table "rusage" "RUSAGE_[A-Z]+[[:space:]]+[-0-9]+" "sys/ gen_table "schedpolicy" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sys/sched.h" gen_table "sendfileflags" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" gen_table "shmatflags" "SHM_[A-Z]+[[:space:]]+[0-9]{6}" "sys/shm.h" -gen_table "shutdownhow" "SHUT_[A-Z]+[[:space:]]+SHUT_[A-Z]+" "sys/socket.h" +gen_table_enum "shutdownhow" "SHUT_[A-Z]+" "sys/socket.h" gen_table "sigbuscode" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" gen_table "sigchldcode" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" gen_table "sigfpecode" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"