2 #-------------------------------------------------------------------------
5 # shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h
7 # NOTE: if you change this, you need to fix Gen_fmgrtab.pl too!
9 # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
10 # Portions Copyright (c) 1994, Regents of the University of California
16 #-------------------------------------------------------------------------
20 if [ x
"$AWK" = x
"" ]; then
25 [ x
"$noclean" != x
"t" ] && rm -f "$SORTEDFILE" "$$-$OIDSFILE" "$$-$TABLEFILE"
31 # Process command line switches.
40 echo "$CMDNAME generates fmgroids.h and fmgrtab.c from pg_proc.h."
43 echo " $CMDNAME inputfile"
45 echo "The environment variable AWK determines which Awk program"
46 echo "to use. The default is \`awk'."
48 echo "Report bugs to <pgsql-bugs@postgresql.org>."
52 echo "$CMDNAME: invalid option: $1"
63 if [ x
"$INFILE" = x
] ; then
64 echo "$CMDNAME: no input file"
68 SORTEDFILE
="$$-fmgr.data"
73 trap 'echo "Caught signal." ; cleanup ; exit 1' 1 2 15
76 # Collect the column numbers of the pg_proc columns we need. Because we will
77 # be looking at data that includes the OID as the first column, add one to
80 proname
=`egrep '^#define Anum_pg_proc_proname[ ]' $INFILE | $AWK '{print $3+1}'`
81 prolang
=`egrep '^#define Anum_pg_proc_prolang[ ]' $INFILE | $AWK '{print $3+1}'`
82 proisstrict
=`egrep '^#define Anum_pg_proc_proisstrict[ ]' $INFILE | $AWK '{print $3+1}'`
83 proretset
=`egrep '^#define Anum_pg_proc_proretset[ ]' $INFILE | $AWK '{print $3+1}'`
84 pronargs
=`egrep '^#define Anum_pg_proc_pronargs[ ]' $INFILE | $AWK '{print $3+1}'`
85 prosrc
=`egrep '^#define Anum_pg_proc_prosrc[ ]' $INFILE | $AWK '{print $3+1}'`
88 # Generate the file containing raw pg_proc data. We do three things here:
89 # 1. Strip off the DATA macro call, leaving procedure OID as $1
90 # and all the pg_proc field values as $2, $3, etc on each line.
91 # 2. Fold quoted fields to simple "xxx". We need this because such fields
92 # may contain whitespace, which would confuse awk's counting of fields.
93 # Fortunately, this script doesn't need to look at any fields that might
94 # need quoting, so this simple hack is sufficient.
95 # 3. Select out just the rows for internal-language procedures.
97 # Note assumption here that INTERNALlanguageId == 12.
99 egrep '^DATA' $INFILE | \
100 sed -e 's/^[^O]*OID[^=]*=[ ]*//' \
102 -e 's/"[^"]*"/"xxx"/g' | \
103 $AWK "\$$prolang == \"12\" { print }" | \
104 sort -n > $SORTEDFILE
106 if [ $?
-ne 0 ]; then
108 echo "$CMDNAME failed"
113 cpp_define
=`echo $OIDSFILE | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | sed -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
116 # Generate fmgroids.h
118 cat > "$$-$OIDSFILE" <<FuNkYfMgRsTuFf
119 /*-------------------------------------------------------------------------
122 * Macros that define the OIDs of built-in functions.
124 * These macros can be used to avoid a catalog lookup when a specific
125 * fmgr-callable function needs to be referenced.
127 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
128 * Portions Copyright (c) 1994, Regents of the University of California
131 * ******************************
132 * *** DO NOT EDIT THIS FILE! ***
133 * ******************************
135 * It has been GENERATED by $CMDNAME
138 *-------------------------------------------------------------------------
144 * Constant macros for the OIDs of entries in pg_proc.
146 * NOTE: macros are named after the prosrc value, ie the actual C name
147 * of the implementing function, not the proname which may be overloaded.
148 * For example, we want to be able to assign different macro names to both
149 * char_text() and name_text() even though these both appear with proname
150 * 'text'. If the same C function appears in more than one pg_proc entry,
151 * its equivalent macro will be defined with the lowest OID among those
156 tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' < $SORTEDFILE | \
157 $AWK "{ if (seenit[\$$prosrc]++ == 0)
158 printf \"#define F_%s %s\\n\", \$$prosrc, \$1; }" >> "$$-$OIDSFILE"
160 if [ $?
-ne 0 ]; then
162 echo "$CMDNAME failed"
166 cat >> "$$-$OIDSFILE" <<FuNkYfMgRsTuFf
168 #endif /* $cpp_define */
172 # Generate fmgr's built-in-function table.
174 # Print out the function declarations, then the table that refers to them.
176 cat > "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
177 /*-------------------------------------------------------------------------
180 * The function manager's table of internal functions.
182 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
183 * Portions Copyright (c) 1994, Regents of the University of California
187 * ******************************
188 * *** DO NOT EDIT THIS FILE! ***
189 * ******************************
191 * It has been GENERATED by $CMDNAME
194 *-------------------------------------------------------------------------
197 #include "postgres.h"
199 #include "utils/fmgrtab.h"
203 $AWK "{ if (seenit[\$$prosrc]++ == 0)
204 print \"extern Datum\", \$$prosrc, \"(PG_FUNCTION_ARGS);\"; }" $SORTEDFILE >> "$$-$TABLEFILE"
206 if [ $?
-ne 0 ]; then
208 echo "$CMDNAME failed"
213 cat >> "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
215 const FmgrBuiltin fmgr_builtins[] = {
218 # Note: using awk arrays to translate from pg_proc values to fmgrtab values
219 # may seem tedious, but avoid the temptation to write a quick x?y:z
220 # conditional expression instead. Not all awks have conditional expressions.
223 Bool[\"t\"] = \"true\";
224 Bool[\"f\"] = \"false\";
226 { printf (\" { %d, \\\"%s\\\", %d, %s, %s, %s },\\n\"),
227 \$1, \$$prosrc, \$$pronargs, Bool[\$$proisstrict], Bool[\$$proretset], \$$prosrc ;
228 }" $SORTEDFILE >> "$$-$TABLEFILE"
230 if [ $?
-ne 0 ]; then
232 echo "$CMDNAME failed"
236 cat >> "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
237 /* dummy entry is easier than getting rid of comma after last real one */
238 /* (not that there has ever been anything wrong with *having* a
239 comma after the last field in an array initializer) */
240 { 0, NULL, 0, false, false, NULL }
243 /* Note fmgr_nbuiltins excludes the dummy entry */
244 const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
247 # We use the temporary files to avoid problems with concurrent runs
248 # (which can happen during parallel make).
249 mv "$$-$OIDSFILE" $OIDSFILE
250 mv "$$-$TABLEFILE" $TABLEFILE