#! /bin/sh #------------------------------------------------------------------------- # # Gen_fmgrtab.sh # shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h # # NOTE: if you change this, you need to fix Gen_fmgrtab.pl too! # # Portions Copyright (c) 1996-2009, 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.41 2009/01/01 17:23:48 momjian Exp $ # #------------------------------------------------------------------------- CMDNAME=`basename $0` if [ x"$AWK" = x"" ]; then AWK=awk fi 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 # # Collect the column numbers of the pg_proc columns we need. Because we will # be looking at data that includes the OID as the first column, add one to # each column number. # proname=`egrep '^#define Anum_pg_proc_proname[ ]' $INFILE | $AWK '{print $3+1}'` prolang=`egrep '^#define Anum_pg_proc_prolang[ ]' $INFILE | $AWK '{print $3+1}'` proisstrict=`egrep '^#define Anum_pg_proc_proisstrict[ ]' $INFILE | $AWK '{print $3+1}'` proretset=`egrep '^#define Anum_pg_proc_proretset[ ]' $INFILE | $AWK '{print $3+1}'` pronargs=`egrep '^#define Anum_pg_proc_pronargs[ ]' $INFILE | $AWK '{print $3+1}'` prosrc=`egrep '^#define Anum_pg_proc_prosrc[ ]' $INFILE | $AWK '{print $3+1}'` # # Generate the file containing raw pg_proc data. We do three things here: # 1. 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. # 2. Fold quoted fields to simple "xxx". We need this because such fields # may contain whitespace, which would confuse awk's counting of fields. # Fortunately, this script doesn't need to look at any fields that might # need quoting, so this simple hack is sufficient. # 3. Select out just the rows for internal-language procedures. # # Note assumption here that INTERNALlanguageId == 12. # egrep '^DATA' $INFILE | \ sed -e 's/^[^O]*OID[^=]*=[ ]*//' \ -e 's/(//' \ -e 's/"[^"]*"/"xxx"/g' | \ $AWK "\$$prolang == \"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" <