summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-03-22 20:25:24 +0100
committerAlejandro Colomar <alx@kernel.org>2023-03-22 20:34:25 +0100
commit23dd53bea262b82ea781bcdf51cd8257bf9a2a83 (patch)
treeb415e2294f367558ae293e25807fb0c86568b7f4
bin/: Add source codev0.1
Cc: Matt Jolly <Matt.Jolly@footclan.ninja> Cc: Oskari Pirhonen <xxc3ncoredxx@gmail.com> Cc: Brian Inglis <Brian.Inglis@Shaw.ca> Cc: Guillem Jover <guillem@hadrons.org> Cc: Tom Schwindl <schwindl@posteo.de> Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rwxr-xr-xbin/stdc65
1 files changed, 65 insertions, 0 deletions
diff --git a/bin/stdc b/bin/stdc
new file mode 100755
index 0000000..8c725a2
--- /dev/null
+++ b/bin/stdc
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+set -Eefuo pipefail;
+
+prefix="/usr/local";
+datarootdir="$prefix/share";
+docdir="$datarootdir/doc";
+
+err()
+{
+ >&2 echo "$(basename "$0"): error: $*";
+ exit 1;
+}
+
+grep_proto()
+{
+ pcregrep -M "(?s)\b$1 *\([[:alnum:]*,._\s\(\)-]*\);$";
+}
+
+libc_summ_c89()
+{
+ sed -n '/A.3 LIBRARY SUMMARY/,$p' <"$docdir/c/c89/c89-draft.txt";
+}
+
+libc_summ()
+{
+ sed -n '/Library summary$/,/Sequence points$/p';
+}
+
+case $# in
+0)
+ err "missing ISO C version.";
+ ;;
+1)
+ err "missing function name.";
+ ;;
+2)
+ ;;
+*)
+ shift;
+ shift;
+ err "unsupported extra argument(s): $*";
+ ;;
+esac;
+
+case "$1" in
+c89)
+ shift;
+ libc_summ_c89 \
+ | grep_proto $@;
+ ;;
+c99)
+ shift;
+ libc_summ <"$docdir/c/c99/n1256.txt" \
+ | grep_proto $@;
+ ;;
+c11)
+ shift;
+ libc_summ <"$docdir/c/c11/n1570.txt" \
+ | grep_proto $@;
+ ;;
+*)
+ err "$1: unsupported ISO C version.";
+ ;;
+esac;