#! /bin/sh #------------------------------------------------------------------------- # # Gen_fmgrtab.sh # shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h # # Portions Copyright (c) 1996-2000, PostgreSQL, Inc # Portions Copyright (c) 1994, Regents of the University of California # # # IDENTIFICATION # $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh,v 1.17 2000/07/13 16:07:06 petere Exp $ # #------------------------------------------------------------------------- CMDNAME=`basename $0` : ${AWK='awk'} : ${CPP='cc -E'} cleanup(){ [ x"$noclean" != x"t" ] && rm -f "$CPPTMPFILE" "$RAWFILE" "$$-$OIDSFILE" "$$-$TABLEFILE" } BKIOPTS= noclean= # # Process command line switches. # while [ $# -gt 0 ] do case $1 in -D) BKIOPTS="$BKIOPTS -D$2" shift;; -D*) BKIOPTS="$BKIOPTS $1" ;; --noclean) noclean=t ;; --help) echo "$CMDNAME generates fmgroids.h and fmgrtab.c from pg_proc.h." echo echo "Usage:" echo " $CMDNAME [ -D define [...] ]" echo echo "The environment variables CPP and AWK determine which C" echo "preprocessor and Awk program to use. The defaults are" echo "\`cc -E' and \`awk'." echo echo "Report bugs to ." exit 0 ;; --) shift; break;; -*) echo "$CMDNAME: invalid option: $1" exit 1 ;; *) INFILE=$1 ;; esac shift done if [ x"$INFILE" = x ] ; then echo "$CMDNAME: no input file" exit 1 fi CPPTMPFILE="$$-fmgrtmp.c" RAWFILE="$$-fmgr.raw" OIDSFILE=fmgroids.h TABLEFILE=fmgrtab.c trap 'echo "Caught signal." ; cleanup ; exit 1' 1 2 15 # # Generate the file containing raw pg_proc tuple data # (but only for "internal" and "newinternal" language procedures...). # # Unlike genbki.sh, which can run through cpp last, we have to # deal with preprocessor statements first (before we sort the # function table by oid). # $AWK ' BEGIN { raw = 0; } /^DATA/ { print; next; } /^BKI_BEGIN/ { raw = 1; next; } /^BKI_END/ { raw = 0; next; } raw == 1 { print; next; }' $INFILE | \ sed -e 's/^.*OID[^=]*=[^0-9]*//' \ -e 's/(//g' \ -e 's/[ ]*).*$//' | \ $AWK ' /^#/ { print; next; } $4 == "11" { print; next; } $4 == "12" { print; next; }' > $CPPTMPFILE if [ $? -ne 0 ]; then cleanup echo "$CMDNAME failed" exit 1 fi $CPP $BKIOPTS $CPPTMPFILE | \ egrep '^[0-9]' | \ sort -n > $RAWFILE if [ $? -ne 0 ]; then cleanup echo "$CMDNAME failed" exit 1 fi cpp_define=`echo $OIDSFILE | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | sed -e 's/[^A-Z]/_/g'` # # Generate fmgroids.h # cat > "$$-$OIDSFILE" <> "$$-$OIDSFILE" if [ $? -ne 0 ]; then cleanup echo "$CMDNAME failed" exit 1 fi cat >> "$$-$OIDSFILE" < "$$-$TABLEFILE" <> "$$-$TABLEFILE" if [ $? -ne 0 ]; then cleanup echo "$CMDNAME failed" exit 1 fi cat >> "$$-$TABLEFILE" <> "$$-$TABLEFILE" if [ $? -ne 0 ]; then cleanup echo "$CMDNAME failed" exit 1 fi cat >> "$$-$TABLEFILE" <