omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / semhash / dups.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # seed/semhash/dups.sh: duplicate-function report (#827 M1) over the .om units of om/ and seed/. |
| 4 | # Usage: seed/semhash/dups.sh SEMHASH [-i INDEX] [DIR...] DIR defaults to "om seed", relative to |
| 5 | # the repo root. Each unit is hashed with `SEMHASH hash`, every FN line gets the unit's path in |
| 6 | # front, and `SEMHASH dups` groups the functions whose meaning hashes are equal. A unit that |
| 7 | # semhash refuses (or a path holding a space) becomes a "SKIP path rc=N reason" line, counted in |
| 8 | # the summary. With -i, the full function index (every "PATH FN name hex line=N..." record and |
| 9 | # every SKIP line, in path order) is also written to INDEX, relative to the caller's directory. |
| 10 | # The grouping is done by semhash.om; this script only lists files and runs the tool. |
| 11 | set -u |
| 12 | SH=${1:?usage: dups.sh SEMHASH [-i INDEX] [DIR...]} |
| 13 | case $SH in /*) ;; *) SH=$PWD/$SH ;; esac |
| 14 | [ -x "$SH" ] || { printf 'dups.sh: no semhash binary at %s\n' "$SH" >&2; exit 2; } |
| 15 | shift |
| 16 | IX=/dev/null |
| 17 | if [ "${1:-}" = -i ]; then |
| 18 | IX=${2:?usage: dups.sh SEMHASH [-i INDEX] [DIR...]} |
| 19 | case $IX in /*) ;; *) IX=$PWD/$IX ;; esac |
| 20 | shift 2 |
| 21 | fi |
| 22 | cd "$(dirname "$0")/../.." || exit 2 |
| 23 | [ $# -gt 0 ] || set -- om seed |
| 24 | E=$(mktemp) || exit 2 |
| 25 | trap 'rm -f "$E"' EXIT |
| 26 | find "$@" -name '*.om' -type f | LC_ALL=C sort | while IFS= read -r f; do |
| 27 | case $f in *' '*) printf 'SKIP %s rc=2 space in path\n' "$(printf '%s' "$f" | tr ' ' '_')"; continue ;; esac |
| 28 | if out=$("$SH" hash < "$f" 2> "$E"); then |
| 29 | printf '%s\n' "$out" | sed -n "s|^FN |$f FN |p" |
| 30 | else |
| 31 | printf 'SKIP %s rc=%s %s\n' "$f" "$?" "$(tr '\n' ' ' < "$E" | sed 's/ *$//')" |
| 32 | fi |
| 33 | done | tee "$IX" | "$SH" dups |