2 #-------------------------------------------------------------------------
5 # shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h
7 # Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8 # Portions Copyright (c) 1994, Regents of the University of California
12 # $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh,v 1.20 2001/05/22 12:06:51 momjian Exp $
14 #-------------------------------------------------------------------------
22 [ x"$noclean" != x"t" ] && rm -f "$CPPTMPFILE" "$RAWFILE" "$$-$OIDSFILE" "$$-$TABLEFILE"
29 # Process command line switches.
35 BKIOPTS="$BKIOPTS -D$2"
44 echo "$CMDNAME generates fmgroids.h and fmgrtab.c from pg_proc.h."
47 echo " $CMDNAME [ -D define [...] ]"
49 echo "The environment variables CPP and AWK determine which C"
50 echo "preprocessor and Awk program to use. The defaults are"
51 echo "\`cc -E' and \`awk'."
53 echo "Report bugs to <pgsql-bugs@postgresql.org>."
58 echo "$CMDNAME: invalid option: $1"
69 if [ x"$INFILE" = x ] ; then
70 echo "$CMDNAME: no input file"
74 CPPTMPFILE="$$-fmgrtmp.c"
80 trap 'echo "Caught signal." ; cleanup ; exit 1' 1 2 15
84 # Generate the file containing raw pg_proc tuple data
85 # (but only for "internal" language procedures...).
87 # Unlike genbki.sh, which can run through cpp last, we have to
88 # deal with preprocessor statements first (before we sort the
89 # function table by oid).
93 /^DATA/ { print; next; }
94 /^BKI_BEGIN/ { raw = 1; next; }
95 /^BKI_END/ { raw = 0; next; }
96 raw == 1 { print; next; }' $INFILE | \
97 sed -e 's/^.*OID[^=]*=[^0-9]*//' \
101 /^#/ { print; next; }
102 $4 == "12" { print; next; }' > $CPPTMPFILE
104 if [ $? -ne 0 ]; then
106 echo "$CMDNAME failed"
110 $CPP $BKIOPTS $CPPTMPFILE | \
111 egrep '^[ ]*[0-9]' | \
114 if [ $? -ne 0 ]; then
116 echo "$CMDNAME failed"
121 cpp_define=`echo $OIDSFILE | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | sed -e 's/[^A-Z]/_/g'`
124 # Generate fmgroids.h
126 cat > "$$-$OIDSFILE" <<FuNkYfMgRsTuFf
127 /*-------------------------------------------------------------------------
130 * Macros that define the OIDs of built-in functions.
132 * These macros can be used to avoid a catalog lookup when a specific
133 * fmgr-callable function needs to be referenced.
135 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
136 * Portions Copyright (c) 1994, Regents of the University of California
139 * ******************************
140 * *** DO NOT EDIT THIS FILE! ***
141 * ******************************
143 * It has been GENERATED by $CMDNAME
146 *-------------------------------------------------------------------------
152 * Constant macros for the OIDs of entries in pg_proc.
154 * NOTE: macros are named after the prosrc value, ie the actual C name
155 * of the implementing function, not the proname which may be overloaded.
156 * For example, we want to be able to assign different macro names to both
157 * char_text() and int4_text() even though these both appear with proname
158 * 'text'. If the same C function appears in more than one pg_proc entry,
159 * its equivalent macro will be defined with the lowest OID among those
164 tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' < $RAWFILE | \
167 { if (seenit[$(NF-1)]++ == 0) print "#define F_", $(NF-1), " ", $1; }' >> "$$-$OIDSFILE"
169 if [ $? -ne 0 ]; then
171 echo "$CMDNAME failed"
175 cat >> "$$-$OIDSFILE" <<FuNkYfMgRsTuFf
177 #endif /* $cpp_define */
181 # Generate fmgr's built-in-function table.
183 # Print out the function declarations, then the table that refers to them.
185 cat > "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
186 /*-------------------------------------------------------------------------
189 * The function manager's table of internal functions.
191 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
192 * Portions Copyright (c) 1994, Regents of the University of California
196 * ******************************
197 * *** DO NOT EDIT THIS FILE! ***
198 * ******************************
200 * It has been GENERATED by $CMDNAME
203 *-------------------------------------------------------------------------
206 #include "postgres.h"
208 #include "utils/fmgrtab.h"
212 $AWK '{ print "extern Datum", $(NF-1), "(PG_FUNCTION_ARGS);"; }' $RAWFILE >> "$$-$TABLEFILE"
214 if [ $? -ne 0 ]; then
216 echo "$CMDNAME failed"
221 cat >> "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
223 const FmgrBuiltin fmgr_builtins[] = {
226 # Note: using awk arrays to translate from pg_proc values to fmgrtab values
227 # may seem tedious, but avoid the temptation to write a quick x?y:z
228 # conditional expression instead. Not all awks have conditional expressions.
234 { printf (" { %d, \"%s\", %d, %s, %s, %s },\n"), \
235 $1, $(NF-1), $9, Bool[$8], Bool[$10], $(NF-1)
236 }' $RAWFILE >> "$$-$TABLEFILE"
238 if [ $? -ne 0 ]; then
240 echo "$CMDNAME failed"
244 cat >> "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
245 /* dummy entry is easier than getting rid of comma after last real one */
246 /* (not that there has ever been anything wrong with *having* a
247 comma after the last field in an array initializer) */
248 { 0, NULL, 0, false, false, (PGFunction) NULL }
251 /* Note fmgr_nbuiltins excludes the dummy entry */
252 const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
256 # We use the temporary files to avoid problems with concurrent runs
257 # (which can happen during parallel make).
258 mv "$$-$OIDSFILE" $OIDSFILE
259 mv "$$-$TABLEFILE" $TABLEFILE