@ -1,4 +1,4 @@
#!/bin/sh
#! /bin/sh
#-------------------------------------------------------------------------
#
# Gen_fmgrtab.sh
@ -9,36 +9,72 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.24 2000/06/02 02:00:28 tgl Exp $
#
# NOTES
# Passes any -D options on to cpp prior to generating the list
# of internal functions. These come from BKIOPTS.
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.25 2000/06/07 16:26:48 petere Exp $
#
#-------------------------------------------------------------------------
BKIOPTS = ''
CMDNAME = ` basename $0 `
AWK = "@AWK@"
CPP = "@CPP@"
cleanup( ) {
[ x" $noclean " != x"t" ] && rm -f " $CPPTMPFILE " " $RAWFILE " " $OIDSFILE .tmp " " $TABLEFILE .tmp "
}
BKIOPTS =
noclean =
#
# Pass on any -D declarations, throwing away any other command
# line switches.
# Process command line switches.
#
for opt in $*
while [ $# -gt 0 ]
do
case $opt in
-D) BKIOPTS = " $BKIOPTS -D $2 " ; shift; shift; ;
-D*) BKIOPTS = " $BKIOPTS $1 " ; shift; ;
case $1 in
-D)
BKIOPTS = " $BKIOPTS -D $2 "
; ;
-D*)
BKIOPTS = " $BKIOPTS $1 "
shift; ;
--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 "Report bugs to <pgsql-bugs@postgresql.org>."
exit 0
; ;
--) shift; break; ;
-*) shift; ;
esac
-*)
echo " $CMDNAME : invalid option: $1 "
exit 1
; ;
*)
INFILE = $1
esac
shift
done
INFILE = $1
RAWFILE = fmgr.raw
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 3 15
#
# Generate the file containing raw pg_proc tuple data
# (but only for "internal" and "newinternal" language procedures...).
@ -47,7 +83,7 @@ TABLEFILE=fmgrtab.c
# deal with preprocessor statements first (before we sort the
# function table by oid).
#
awk '
$AWK '
BEGIN { raw = 0; }
/^DATA/ { print; next; }
/^BKI_BEGIN/ { raw = 1; next; }
@ -56,21 +92,34 @@ raw == 1 { print; next; }' $INFILE | \
sed -e 's/^.*OID[^=]*=[^0-9]*//' \
-e 's/(//g' \
-e 's/[ ]*).*$//' | \
awk '
$AWK '
/^#/ { print; next; }
$4 = = "11" { print; next; }
$4 = = "12" { print; next; } ' > $CPPTMPFILE
@CPP@ $BKIOPTS $CPPTMPFILE | \
if [ $? -ne 0 ] ; then
cleanup
echo " $CMDNAME failed "
exit 1
fi
$CPP $BKIOPTS $CPPTMPFILE | \
egrep '^[0-9]' | \
sort -n > $RAWFILE
rm -f $CPPTMPFILE
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 <<FuNkYfMgRsTuF f
cat > " ${ OIDSFILE } .tmp " <<FuNkYfMgRsTuF f
/*-------------------------------------------------------------------------
*
* $OIDSFILE
@ -82,20 +131,18 @@ cat > $OIDSFILE <<FuNkYfMgRsTuFf
* Portions Copyright ( c) 1996-2000, PostgreSQL, Inc
* Portions Copyright ( c) 1994, Regents of the University of California
*
* $Id : Gen_fmgrtab.sh.in,v 1.24 2000/06/02 02:00:28 tgl Exp $
*
* NOTES
* ******************************
* *** DO NOT EDIT THIS FILE! ***
* ******************************
*
* It has been GENERATED by $0
* It has been GENERATED by $CMDNAME
* from $INFILE
*
*-------------------------------------------------------------------------
*/
#ifndef FMGROIDS_H
#define FMGROIDS_H
#ifndef $cpp_define
#define $cpp_define
/*
* Constant macros for the OIDs of entries in pg_proc.
@ -111,13 +158,19 @@ cat > $OIDSFILE <<FuNkYfMgRsTuFf
FuNkYfMgRsTuFf
tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' < $RAWFILE | \
awk '
$AWK '
BEGIN { OFS = "" ; }
{ if ( seenit[ $( NF-1) ] ++ = = 0) print "#define F_" , $( NF-1) , " " , $1 ; } ' >> $OIDSFILE
{ if ( seenit[ $( NF-1) ] ++ = = 0) print "#define F_" , $( NF-1) , " " , $1 ; } ' >> " ${ OIDSFILE } .tmp "
if [ $? -ne 0 ] ; then
cleanup
echo " $CMDNAME failed "
exit 1
fi
cat >> $OIDSFILE <<FuNkYfMgRsTuF f
cat >> " ${ OIDSFILE } .tmp " <<FuNkYfMgRsTuF f
#endif /* FMGROIDS_H */
#endif /* $cpp_define */
FuNkYfMgRsTuFf
#
@ -129,7 +182,7 @@ FuNkYfMgRsTuFf
# this table definition as a separate C file that won't need to include any
# "real" declarations for those functions!
#
cat > $ TABLEFILE <<FuNkYfMgRtAbStUfF
cat > " ${ TABLEFILE } .tmp " <<FuNkYfMgRtAbStUfF
/*-------------------------------------------------------------------------
*
* $TABLEFILE
@ -138,16 +191,13 @@ cat > $TABLEFILE <<FuNkYfMgRtAbStUfF
* 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.in,v 1.24 2000/06/02 02:00:28 tgl Exp $
*
* NOTES
*
* ******************************
* *** DO NOT EDIT THIS FILE! ***
* ******************************
*
* It has been GENERATED by $0
* It has been GENERATED by $CMDNAME
* from $INFILE
*
* We lie here to cc about the return type and arguments of old-style
@ -163,9 +213,16 @@ cat > $TABLEFILE <<FuNkYfMgRtAbStUfF
FuNkYfMgRtAbStUfF
awk '{ print "extern Datum", $(NF-1), "(PG_FUNCTION_ARGS);"; }' $RAWFILE >> $TABLEFILE
$AWK '{ print "extern Datum", $(NF-1), "(PG_FUNCTION_ARGS);"; }' $RAWFILE >> " ${ TABLEFILE } .tmp "
if [ $? -ne 0 ] ; then
cleanup
echo " $CMDNAME failed "
exit 1
fi
cat >> $TABLEFILE <<FuNkYfMgRtAbStUfF
cat >> " ${ TABLEFILE } .tmp " <<FuNkYfMgRtAbStUfF
const FmgrBuiltin fmgr_builtins[ ] = {
FuNkYfMgRtAbStUfF
@ -174,7 +231,7 @@ FuNkYfMgRtAbStUfF
# may seem tedious, but avoid the temptation to write a quick x?y:z
# conditional expression instead. Not all awks have conditional expressions.
awk ' BEGIN {
$AWK ' BEGIN {
Strict[ "t" ] = "true"
Strict[ "f" ] = "false"
OldStyle[ "11" ] = "true"
@ -182,10 +239,18 @@ awk 'BEGIN {
}
{ printf ( " { %d, \"%s\", %d, %s, %s, %s },\n" ) , \
$1 , $( NF-1) , $9 , Strict[ $8 ] , OldStyle[ $4 ] , $( NF-1)
} ' $RAWFILE >> $ TABLEFILE
} ' $RAWFILE >> " ${ TABLEFILE } .tmp "
cat >> $TABLEFILE <<FuNkYfMgRtAbStUfF
if [ $? -ne 0 ] ; then
cleanup
echo " $CMDNAME failed "
exit 1
fi
cat >> " ${ TABLEFILE } .tmp " <<FuNkYfMgRtAbStUfF
/* dummy entry is easier than getting rid of comma after last real one */
/* ( not that there has ever been anything wrong with *having* a
comma after the last field in an array initializer) */
{ 0, NULL, 0, false, false, ( PGFunction) NULL }
} ;
@ -194,9 +259,22 @@ const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
FuNkYfMgRtAbStUfF
rm -f $RAWFILE
# ----------------
# all done
# ----------------
# Now we check if the files fmgroids.h and fmgrtab.c already exist and
# are identical to what we would make them. In that case we avoid
# writing our new version, so as to not cause unnecessary recompilation
# because of changed timestamps.
for file in " $OIDSFILE " " $TABLEFILE " ; do
if test -f " $file " && cmp -s " $file " " ${ file } .tmp " ; then
echo " $file unchanged "
rm -f " ${ file } .tmp "
else
mv " ${ file } .tmp " " $file "
fi
done
cleanup
exit 0