From cc5db90495f5f566d4eba1132fe1db527d756447 Mon Sep 17 00:00:00 2001 From: KK Date: Thu, 2 Jul 2026 22:55:43 +0200 Subject: [PATCH] api query script --- misc/query-api | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 misc/query-api diff --git a/misc/query-api b/misc/query-api new file mode 100755 index 0000000..b6a53a4 --- /dev/null +++ b/misc/query-api @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +usage() { + cat <<'USAGE' +Usage: query-api PREFIX [ROOT] + +Search API by prefix. If PREFIX does not end with '_', '_' is appended. +Functions are matched as implementations only: lines/signatures ending with '{'. +Types are matched as complete typedef/struct/enum definitions. +Defines are matched from #define names with the same prefix. + +Examples: + misc/query-api s8 + misc/query-api sb8 src + misc/query-api type_info +USAGE +} + +if [[ $# -lt 1 || "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then + usage + exit 0 +fi + +prefix="$1" +root="${2:-src}" + +if [[ "$prefix" != *_ ]]; then + prefix="${prefix}_" +fi + +rg -n -U -P "(?ms)^fn\b(?=[^{;]*\b\Q${prefix}\E\w*\s*\()[^{;]*\{\s*$|^#define\s+\Q${prefix}\E\w*\b[^\r\n]*(?:\\\\\R[^\r\n]*)*|^typedef\s+struct\s+(\Q${prefix}\E\w*)\s+\1;\Rstruct\s+\1\s*\{.*?^\};|^struct\s+\Q${prefix}\E\w*\s*\{.*?^\};|^typedef\s+\w+\s+\Q${prefix}\E\w*;\Renum\s*\{.*?^\};|^typedef\b[^;]*\b\Q${prefix}\E\w*\b[^;]*;" "$root"