From b43fd16eecde5c03b0e863fdddefb57a0a3f6a42 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 20 Aug 2004 19:48:14 +0000 Subject: [PATCH] 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 Poole --- contrib/fuzzystrmatch/dmetaphone.c | 44 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/contrib/fuzzystrmatch/dmetaphone.c b/contrib/fuzzystrmatch/dmetaphone.c index ccb21c537e..49cd284e75 100644 --- a/contrib/fuzzystrmatch/dmetaphone.c +++ b/contrib/fuzzystrmatch/dmetaphone.c @@ -48,8 +48,8 @@ /* - * $Revision: 1.1 $ - * $Id: dmetaphone.c,v 1.1 2004/07/01 03:25:48 joe Exp $ + * $Revision: 1.2 $ + * $Id: dmetaphone.c,v 1.2 2004/08/20 19:48:14 momjian Exp $ */ @@ -138,12 +138,16 @@ PG_FUNCTION_INFO_V1(dmetaphone); 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 - text * arg = PG_GETARG_TEXT_P(0); - int alen = VARSIZE(arg)-VARHDRSZ; + arg = PG_GETARG_TEXT_P(0); + alen = VARSIZE(arg)-VARHDRSZ; /* * Postgres' string values might not have trailing nuls. @@ -153,18 +157,17 @@ dmetaphone(PG_FUNCTION_ARGS) * (and we don't make space for it). */ - char * aptr = palloc(alen+1); + aptr = palloc(alen+1); memcpy(aptr,VARDATA(arg),alen); aptr[alen]=0; - char * codes[2]; DoubleMetaphone(aptr,codes); - char * code = codes[0]; + code = codes[0]; if (!code) code = ""; - int rsize = VARHDRSZ + strlen(code) ; - text * result = (text *) palloc(rsize); + rsize = VARHDRSZ + strlen(code) ; + result = (text *) palloc(rsize); memset(result,0,rsize); - char * rptr = VARDATA(result); + rptr = VARDATA(result); memcpy(rptr,code,strlen(code)); VARATT_SIZEP(result) = rsize; PG_RETURN_TEXT_P(result); @@ -180,24 +183,27 @@ PG_FUNCTION_INFO_V1(dmetaphone_alt); 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 - text * arg = PG_GETARG_TEXT_P(0); - int alen = VARSIZE(arg)-VARHDRSZ; - char * aptr = palloc(alen+1); - memcpy(aptr,VARDATA(arg),alen); + arg = PG_GETARG_TEXT_P(0); + alen = VARSIZE(arg)-VARHDRSZ; + aptr = palloc(alen+1); + memcpy(aptr,VARDATA(arg),alen); aptr[alen]=0; - char * codes[2]; DoubleMetaphone(aptr,codes); - char * code = codes[1]; + code = codes[1]; if (!code) code = ""; - int rsize = VARHDRSZ + strlen(code) ; - text * result = (text *) palloc(rsize); + rsize = VARHDRSZ + strlen(code) ; + result = (text *) palloc(rsize); memset(result,0,rsize); - char * rptr = VARDATA(result); + rptr = VARDATA(result); memcpy(rptr,code,strlen(code)); VARATT_SIZEP(result) = rsize; PG_RETURN_TEXT_P(result);