I notice that contrib/fuzzystrmatch/dmetaphone.c doesn't compile cleanly
as it stands - it mixes declarations in code, C++-style. The attached
patch shifts declarations to the tops of functions and enables this file
to compile cleanly as C.
Richard
Index: contrib/fuzzystrmatch/dmetaphone.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/contrib/fuzzystrmatch/dmetaphone.c,v
retrieving revision 1.1
diff -c -r1.1 dmetaphone.c
*** contrib/fuzzystrmatch/dmetaphone.c 1 Jul 2004 03:25:48 -0000 1.1
--- contrib/fuzzystrmatch/dmetaphone.c 15 Aug 2004 22:58:49 -0000
***************
*** 138,149 ****
Datum
dmetaphone(PG_FUNCTION_ARGS)
{
#ifdef DMETAPHONE_NOSTRICT
if (PG_ARGISNULL(0))
PG_RETURNNULL();
#endif
! text * arg = PG_GETARG_TEXT_P(0);
! int alen = VARSIZE(arg)-VARHDRSZ;
/*
* Postgres' string values might not have trailing nuls.
--- 138,153 ----
Datum
dmetaphone(PG_FUNCTION_ARGS)
{
+ text * arg, * result;
+ int alen, rsize;
+ char * aptr, *codes[2], * code, * rptr;
+
#ifdef DMETAPHONE_NOSTRICT
if (PG_ARGISNULL(0))
PG_RETURNNULL();
#endif
! arg = PG_GETARG_TEXT_P(0);
! alen = VARSIZE(arg)-VARHDRSZ;
/*
* Postgres' string values might not have trailing nuls.
***************
*** 153,170 ****
* (and we don't make space for it).
*/
! char * aptr = palloc(alen+1);
memcpy(aptr,VARDATA(arg),alen);
aptr[alen]=0;
- char * codes[2];
DoubleMetaphone(aptr,codes);
! char * code = codes[0];
if (!code)
code = "";
! int rsize = VARHDRSZ + strlen(code) ;
! text * result = (text *) palloc(rsize);
memset(result,0,rsize);
! char * rptr = VARDATA(result);
memcpy(rptr,code,strlen(code));
VARATT_SIZEP(result) = rsize;
PG_RETURN_TEXT_P(result);
--- 157,173 ----
* (and we don't make space for it).
*/
! aptr = palloc(alen+1);
memcpy(aptr,VARDATA(arg),alen);
aptr[alen]=0;
DoubleMetaphone(aptr,codes);
! code = codes[0];
if (!code)
code = "";
! rsize = VARHDRSZ + strlen(code) ;
! result = (text *) palloc(rsize);
memset(result,0,rsize);
! rptr = VARDATA(result);
memcpy(rptr,code,strlen(code));
VARATT_SIZEP(result) = rsize;
PG_RETURN_TEXT_P(result);
***************
*** 180,203 ****
Datum
dmetaphone_alt(PG_FUNCTION_ARGS)
{
#ifdef DMETAPHONE_NOSTRICT
if (PG_ARGISNULL(0))
PG_RETURNNULL();
#endif
! text * arg = PG_GETARG_TEXT_P(0);
! int alen = VARSIZE(arg)-VARHDRSZ;
! char * aptr = palloc(alen+1);
! memcpy(aptr,VARDATA(arg),alen);
aptr[alen]=0;
- char * codes[2];
DoubleMetaphone(aptr,codes);
! char * code = codes[1];
if (!code)
code = "";
! int rsize = VARHDRSZ + strlen(code) ;
! text * result = (text *) palloc(rsize);
memset(result,0,rsize);
! char * rptr = VARDATA(result);
memcpy(rptr,code,strlen(code));
VARATT_SIZEP(result) = rsize;
PG_RETURN_TEXT_P(result);
--- 183,209 ----
Datum
dmetaphone_alt(PG_FUNCTION_ARGS)
{
+ text * arg, * result;
+ int alen, rsize;
+ char * aptr, * codes[2], * code, * rptr;
+
#ifdef DMETAPHONE_NOSTRICT
if (PG_ARGISNULL(0))
PG_RETURNNULL();
#endif
! arg = PG_GETARG_TEXT_P(0);
! alen = VARSIZE(arg)-VARHDRSZ;
! aptr = palloc(alen+1);
! memcpy(aptr,VARDATA(arg),alen);
aptr[alen]=0;
DoubleMetaphone(aptr,codes);
! code = codes[1];
if (!code)
code = "";
! rsize = VARHDRSZ + strlen(code) ;
! result = (text *) palloc(rsize);
memset(result,0,rsize);
! rptr = VARDATA(result);
memcpy(rptr,code,strlen(code));
VARATT_SIZEP(result) = rsize;
PG_RETURN_TEXT_P(result);
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster