#! /bin/sh #------------------------------------------------------------------------- # # Gen_fmgrtab.sh # shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h # # Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # # # IDENTIFICATION # $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.sh,v 1.38 2008/01/01 19:45:52 momjian Exp $ # #------------------------------------------------------------------------- CMDNAME=`basename $0` : ${AWK='awk'} cleanup(){ [ x"$noclean" != x"t" ] && rm -f "$SORTEDFILE" "$$-$OIDSFILE" "$$-$TABLEFILE" } noclean= # # Process command line switches. # while [ $# -gt 0 ] do case $1 in --noclean) noclean=t ;; --help) echo "$CMDNAME generates fmgroids.h and fmgrtab.c from pg_proc.h." echo echo "Usage:" echo " $CMDNAME inputfile" echo echo "The environment variable AWK determines which Awk program" echo "to use. The default is \`awk'." echo echo "Report bugs to ." exit 0 ;; -*) 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 SORTEDFILE="$$-fmgr.data" 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" language procedures...). # Basically we strip off the DATA macro call, leaving procedure OID as $1 # and all the pg_proc field values as $2, $3, etc on each line. # # Note assumption here that prolang == $5 and INTERNALlanguageId == 12. # egrep '^DATA' $INFILE | \ sed -e 's/^.*OID[^=]*=[^0-9]*//' \ -e 's/(//g' \ -e 's/[ ]*).*$//' | \ $AWK '$5 == "12" { print }' | \ sort -n > $SORTEDFILE if [ $? -ne 0 ]; then cleanup echo "$CMDNAME failed" exit 1 fi cpp_define=`echo $OIDSFILE | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | sed -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/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" <