mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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
This commit is contained in:
@ -48,8 +48,8 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Revision: 1.1 $
|
* $Revision: 1.2 $
|
||||||
* $Id: dmetaphone.c,v 1.1 2004/07/01 03:25:48 joe Exp $
|
* $Id: dmetaphone.c,v 1.2 2004/08/20 19:48:14 momjian Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -138,12 +138,16 @@ PG_FUNCTION_INFO_V1(dmetaphone);
|
|||||||
Datum
|
Datum
|
||||||
dmetaphone(PG_FUNCTION_ARGS)
|
dmetaphone(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
|
text * arg, * result;
|
||||||
|
int alen, rsize;
|
||||||
|
char * aptr, *codes[2], * code, * rptr;
|
||||||
|
|
||||||
#ifdef DMETAPHONE_NOSTRICT
|
#ifdef DMETAPHONE_NOSTRICT
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
PG_RETURNNULL();
|
PG_RETURNNULL();
|
||||||
#endif
|
#endif
|
||||||
text * arg = PG_GETARG_TEXT_P(0);
|
arg = PG_GETARG_TEXT_P(0);
|
||||||
int alen = VARSIZE(arg)-VARHDRSZ;
|
alen = VARSIZE(arg)-VARHDRSZ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Postgres' string values might not have trailing nuls.
|
* Postgres' string values might not have trailing nuls.
|
||||||
@ -153,18 +157,17 @@ dmetaphone(PG_FUNCTION_ARGS)
|
|||||||
* (and we don't make space for it).
|
* (and we don't make space for it).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char * aptr = palloc(alen+1);
|
aptr = palloc(alen+1);
|
||||||
memcpy(aptr,VARDATA(arg),alen);
|
memcpy(aptr,VARDATA(arg),alen);
|
||||||
aptr[alen]=0;
|
aptr[alen]=0;
|
||||||
char * codes[2];
|
|
||||||
DoubleMetaphone(aptr,codes);
|
DoubleMetaphone(aptr,codes);
|
||||||
char * code = codes[0];
|
code = codes[0];
|
||||||
if (!code)
|
if (!code)
|
||||||
code = "";
|
code = "";
|
||||||
int rsize = VARHDRSZ + strlen(code) ;
|
rsize = VARHDRSZ + strlen(code) ;
|
||||||
text * result = (text *) palloc(rsize);
|
result = (text *) palloc(rsize);
|
||||||
memset(result,0,rsize);
|
memset(result,0,rsize);
|
||||||
char * rptr = VARDATA(result);
|
rptr = VARDATA(result);
|
||||||
memcpy(rptr,code,strlen(code));
|
memcpy(rptr,code,strlen(code));
|
||||||
VARATT_SIZEP(result) = rsize;
|
VARATT_SIZEP(result) = rsize;
|
||||||
PG_RETURN_TEXT_P(result);
|
PG_RETURN_TEXT_P(result);
|
||||||
@ -180,24 +183,27 @@ PG_FUNCTION_INFO_V1(dmetaphone_alt);
|
|||||||
Datum
|
Datum
|
||||||
dmetaphone_alt(PG_FUNCTION_ARGS)
|
dmetaphone_alt(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
|
text * arg, * result;
|
||||||
|
int alen, rsize;
|
||||||
|
char * aptr, * codes[2], * code, * rptr;
|
||||||
|
|
||||||
#ifdef DMETAPHONE_NOSTRICT
|
#ifdef DMETAPHONE_NOSTRICT
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
PG_RETURNNULL();
|
PG_RETURNNULL();
|
||||||
#endif
|
#endif
|
||||||
text * arg = PG_GETARG_TEXT_P(0);
|
arg = PG_GETARG_TEXT_P(0);
|
||||||
int alen = VARSIZE(arg)-VARHDRSZ;
|
alen = VARSIZE(arg)-VARHDRSZ;
|
||||||
char * aptr = palloc(alen+1);
|
aptr = palloc(alen+1);
|
||||||
memcpy(aptr,VARDATA(arg),alen);
|
memcpy(aptr,VARDATA(arg),alen);
|
||||||
aptr[alen]=0;
|
aptr[alen]=0;
|
||||||
char * codes[2];
|
|
||||||
DoubleMetaphone(aptr,codes);
|
DoubleMetaphone(aptr,codes);
|
||||||
char * code = codes[1];
|
code = codes[1];
|
||||||
if (!code)
|
if (!code)
|
||||||
code = "";
|
code = "";
|
||||||
int rsize = VARHDRSZ + strlen(code) ;
|
rsize = VARHDRSZ + strlen(code) ;
|
||||||
text * result = (text *) palloc(rsize);
|
result = (text *) palloc(rsize);
|
||||||
memset(result,0,rsize);
|
memset(result,0,rsize);
|
||||||
char * rptr = VARDATA(result);
|
rptr = VARDATA(result);
|
||||||
memcpy(rptr,code,strlen(code));
|
memcpy(rptr,code,strlen(code));
|
||||||
VARATT_SIZEP(result) = rsize;
|
VARATT_SIZEP(result) = rsize;
|
||||||
PG_RETURN_TEXT_P(result);
|
PG_RETURN_TEXT_P(result);
|
||||||
|
Reference in New Issue
Block a user