#!/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"