From 943135931d5db0e1579e5b743e5c13dd5cc47158 Mon Sep 17 00:00:00 2001
From: Jim Meyering <jim@meyering.net>
Date: Mon, 20 Nov 2006 23:33:31 +0000
Subject: [PATCH] The beginnings of syntax-related checks for gnulib. *
 lib/Makefile: New file. * lib/t-idcache: New script.  Ensure that the two
 halves of idcache.c stay in sync.

---
 ChangeLog     |  5 +++++
 lib/Makefile  |  6 ++++++
 lib/t-idcache | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 lib/Makefile
 create mode 100755 lib/t-idcache

diff --git a/ChangeLog b/ChangeLog
index f41dcf9187..def7c47e04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,11 @@
 
 2006-11-20  Jim Meyering  <jim@meyering.net>
 
+	The beginnings of syntax-related checks for gnulib.
+	* lib/Makefile: New file.
+	* lib/t-idcache: New script.  Ensure that the two halves of
+	idcache.c stay in sync.
+
 	* lib/idcache.c: Adjust comments in user- and group- portions to
 	be more accurate, and to be consistent with one another.
 
diff --git a/lib/Makefile b/lib/Makefile
new file mode 100644
index 0000000000..2e10203783
--- /dev/null
+++ b/lib/Makefile
@@ -0,0 +1,6 @@
+# Run "make check" to ensure that the code passes some simple tests,
+# usually (always?) not involving compilation.
+all:
+
+check:
+	./t-idcache
diff --git a/lib/t-idcache b/lib/t-idcache
new file mode 100755
index 0000000000..e4d71af0a2
--- /dev/null
+++ b/lib/t-idcache
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Compare the two halves (user and group) of idcache.c.
+# Once xformed, they'd better be the same:
+
+pwd=`pwd`
+t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
+trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
+trap '(exit $?); exit $?' 1 2 13 15
+
+srcdir=../..
+framework_failure=0
+mkdir -p $tmp || framework_failure=1
+cd $tmp || framework_failure=1
+
+if test $framework_failure = 1; then
+  echo "$0: failure in testing framework" 1>&2
+  (exit 1); exit 1
+fi
+
+# Extract user-oriented functions.
+perl -ne \
+  'print if /^static struct.*user_alist/ .. /^static struct.*group_alist/' \
+  $srcdir/idcache.c | head -n -3 > u
+# Extract group-oriented functions.
+perl -ne 'print if /^static struct.*group_alist/ .. eof' $srcdir/idcache.c > g
+
+# Convert user-specific strings of "u" into corresponding group-specific strings
+subst='
+s/user_/group_/g;
+s/\buser\b/group/g;
+s/USER/GROUP/g;
+s/\bu\b/g/g;
+s/passwd/group/g;
+s/pw_uid/gr_gid/g;
+s/pwnam/grnam/g;
+s/pwent/grent/g;
+s/getpw/getgr/g;
+s/pw_/gr_/g;
+s/UID/GID/g;
+s/uid/gid/g;
+s/getuser/getgroup/;
+s/login name/group name/;
+s/to be the/to belong to/;
+s/pwd fun/grp fun/;
+'
+
+fail=0
+# Ensure that the transformed "u" is the same as g.
+# Any differences here constitute an error.
+perl -pe "$subst" u | diff -u - g || fail=1
+
+exit $fail
-- 
2.39.5