interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / semhash / dups.sh

33 lines · 1688 bytes Raw Blame History
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.
11set -u
12SH=${1:?usage: dups.sh SEMHASH [-i INDEX] [DIR...]}
13case $SH in /*) ;; *) SH=$PWD/$SH ;; esac
14[ -x "$SH" ] || { printf 'dups.sh: no semhash binary at %s\n' "$SH" >&2; exit 2; }
15shift
16IX=/dev/null
17if [ "${1:-}" = -i ]; then
18 IX=${2:?usage: dups.sh SEMHASH [-i INDEX] [DIR...]}
19 case $IX in /*) ;; *) IX=$PWD/$IX ;; esac
20 shift 2
21fi
22cd "$(dirname "$0")/../.." || exit 2
23[ $# -gt 0 ] || set -- om seed
24E=$(mktemp) || exit 2
25trap 'rm -f "$E"' EXIT
26find "$@" -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
33done | tee "$IX" | "$SH" dups