xref: /freebsd/contrib/libfido2/man/check.sh (revision 2ccfa855b2fc331819953e3de1b1c15ce5b95a7e)
1#!/bin/sh -u
2
3# Copyright (c) 2022 Yubico AB. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6# SPDX-License-Identifier: BSD-2-Clause
7
8T=$(mktemp -d) || exit 1
9find . -maxdepth 1 -type f -name '*.3' -print0 > "$T/files"
10
11xargs -0 awk '/^.Sh NAME/,/^.Nd/' < "$T/files" | \
12    awk '/^.Nm/ { print $2 }' | sort -u > "$T/Nm"
13xargs -0 awk '/^.Fn/ { print $2 }' < "$T/files" | sort -u > "$T/Fn"
14(cd "$T" && diff -u Nm Fn)
15
16cut -c2- ../src/export.llvm | sort > "$T/exports"
17(cd "$T" && diff -u Nm exports)
18
19awk '/^list\(APPEND MAN_SOURCES/,/^\)/' CMakeLists.txt | \
20    awk '/.3$/ { print $1 }' | sort > "$T/listed_sources"
21xargs -0 -n1 basename < "$T/files" | sort > "$T/actual_sources"
22(cd "$T" && diff -u listed_sources actual_sources)
23
24awk '/^list\(APPEND MAN_ALIAS/,/^\)/' CMakeLists.txt | \
25    sed '1d;$d' | awk '{ print $1, $2 }' | sort > "$T/listed_aliases"
26xargs -0 grep -o "^.Fn [A-Za-z0-9_]* \"" < "$T/files" | \
27    cut -c3- | sed 's/\.3:\.Fn//;s/ "//' | awk '$1 != $2' | \
28    sort > "$T/actual_aliases"
29(cd "$T" && diff -u listed_aliases actual_aliases)
30
31xargs -0 grep -hB1 "^.Fn [A-Za-z0-9_]* \"" < "$T/files" | \
32    sed -E 's/^.F[tn] //;s/\*[^"\*]+"/\*"/g;s/ [^" \*]+"/"/g;/^--$/d' | \
33    paste -d " " - - | sed 's/\* /\*/' | sort > "$T/documented_prototypes"
34while read -r f; do
35	awk "/\/\*/ { next } /$f\(/,/;/" ../src/fido.h ../src/fido/*.h | \
36	    sed -E 's/^[ ]+//;s/[ ]+/ /' | tr '\n' ' ' | \
37	    sed 's/(/ "/;s/, /" "/g;s/);/"/;s/ $/\n/'
38done < "$T/exports" | sort > "$T/actual_prototypes"
39(cd "$T" && diff -u documented_prototypes actual_prototypes)
40
41(cd "$T" && rm files Nm Fn exports listed_sources actual_sources \
42    listed_aliases actual_aliases documented_prototypes actual_prototypes)
43rmdir -- "$T"
44