+#! /bin/sh
+
+set -e
+
+cat <<EOF
+/* -*-c-*-
+ *
+ * Table of standard prime subgroups [generated]
+ */
+
+#include "ptab.h"
+
+#define N(x) (sizeof(x)/sizeof(*x))
+#define MP(x) { x, x + N(x), N(x), 0, MP_CONST, 0 }
+
+/*----- Prime data --------------------------------------------------------*/
+
+EOF
+
+names=""
+while read t n; do
+
+ case $t in
+ group) ;;
+ alias) names="$names $n=$f" continue;;
+ \#* | "") continue;;
+ *) echo >&2 "$0: unknown keyword $t"; exit 1;;
+ esac
+
+ names="$names $n=$n"
+ cat <<EOF
+/* --- Group $n --- */
+
+EOF
+
+ n=`echo $n | sed 's/[^a-zA-Z0-9_][^a-zA-Z0-9_]*/_/g'`
+ read t p
+ if [ $t != p ]; then echo >&2 "$0: wanted p; found $t"; exit 1; fi
+ read t q
+ if [ $t != q ]; then echo >&2 "$0: wanted q; found $t"; exit 1; fi
+ read t g
+ if [ $t != g ]; then echo >&2 "$0: wanted g; found $t"; exit 1; fi
+
+ cat <<EOF
+static mpw p_${n}_p[] = {
+EOF
+ ./mpdump $p
+ cat <<EOF
+};
+
+static mpw p_${n}_q[] = {
+EOF
+ ./mpdump $q
+ cat <<EOF
+};
+
+static mpw p_${n}_g[] = {
+EOF
+ ./mpdump $g
+ cat <<EOF
+};
+
+static pdata p_$n = {
+ MP(p_${n}_p),
+ MP(p_${n}_q),
+ MP(p_${n}_g)
+};
+
+EOF
+
+done
+
+cat <<EOF
+/*----- Main table --------------------------------------------------------*/
+
+const pentry ptab[] = {
+EOF
+for i in $names; do
+ a=`echo $i | sed 's/=.*$//'`
+ n=`echo $i | sed 's/^.*=//; s/[^a-zA-Z0-9_][^a-zA-Z0-9_]*/_/g'`
+ cat <<EOF
+ { "$a", &p_$n },
+EOF
+done
+cat <<EOF
+ { 0, 0 }
+};
+
+/*----- That's all, folks -------------------------------------------------*/
+EOF