Robustify mpers.awk against input containing index loops

Make mpers.awk check for potential index loops.  Such loops should not
normally happen, but mpers.awk will not go into infinite recursion if
they do.

* mpers.awk (enter, leave): New functions.
(what_is): Use them.
diff --git a/mpers.awk b/mpers.awk
index f511acf..4c2def2 100644
--- a/mpers.awk
+++ b/mpers.awk
@@ -15,9 +15,26 @@
 	}
 	return array_return
 }
+function enter(array_idx)
+{
+	if (called[array_idx]) {
+		printf("%s: index loop detected:", FILENAME) > "/dev/stderr"
+		for (item in called)
+			printf(" %s", item) > "/dev/stderr"
+		print "" > "/dev/stderr"
+		exit 1
+	}
+	called[array_idx] = 1
+}
+function leave(array_idx, to_return)
+{
+	delete called[array_idx]
+	return to_return
+}
 function what_is(what_idx, type_idx, special, item, \
 		 location, prev_location, prev_returned_size)
 {
+	enter(what_idx)
 	special = array_get(what_idx, "special")
 	switch (special) {
 	case "base_type":
@@ -52,7 +69,7 @@
 		returned_size = to_return * returned_size
 		if ("" == to_return)
 			to_return = "00"
-		return to_return
+		return leave(what_idx, to_return)
 		break
 	case "structure_type":
 		print "struct {"
@@ -107,18 +124,18 @@
 		break
 	case "typedef":
 		type_idx = array_get(what_idx, "type")
-		return what_is(type_idx)
+		return leave(what_idx, what_is(type_idx))
 		break
 	case "member":
 		type_idx = array_get(what_idx, "type")
-		return what_is(type_idx)
+		return leave(what_idx, what_is(type_idx))
 		break
 	default:
 		type_idx = array_get(what_idx, "type")
 		what_is(type_idx)
 		break
 	}
-	return 0
+	return leave(what_idx, 0)
 }
 BEGIN {
 	print "#include <inttypes.h>"