4 * Revision 1.1 2001/04/04 05:43:38 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.2 1999/11/26 12:52:25 bnv
10 * Revision 1.1 1998/07/02 17:18:00 bnv
19 /* ------------------------* Soundex *--------------------------- */
20 #define MAX_LENGTH 20 /* max # of chars to check */
21 #define SOUNDEX_LENGTH 4 /* length of Soundex code */
23 #define ALPHA_OFFSET 65 /* ALPHA_OFFSET is decimal */
24 /* value of 'A' in ASCII character set */
26 Lsoundex( const PLstr to
, const PLstr str
)
28 /* ctable contains the Soundex value of each
29 letter in alphabetical order. 0 represents
30 letters which are to be ignored. */
32 static char ctable
[] = { "01230120022455012623010202" };
38 /* ---- initialise ---- */
41 Lfx(to
,SOUNDEX_LENGTH
);
48 /* convert name to all upper case */
49 if (len
> MAX_LENGTH
) len
= MAX_LENGTH
;
51 /* generate 1st character of Soundex code */
52 code
[0] = l2u
[(byte
)name
[0]];
56 if (l2u
[(byte
)name
[0]]=='K') /* modifications */
59 if (l2u
[(byte
)name
[0]]=='P' && l2u
[(byte
)name
[1]]=='H')
62 /* loop through the rest of name, until code complete */
63 for (i
=1; i
<len
; i
++) {
64 c
= l2u
[(byte
)name
[i
]];
69 /* skip succesive occurance */
70 if (c
==prior
) continue;
73 /* lookup letter in table */
75 if (ctable
[(byte
)c
]=='0')
76 continue; /* ignore this letter */
78 code
[y
++] = ctable
[(byte
)c
]; /* add to code */
80 if (y
>= SOUNDEX_LENGTH
) break; /* code is complete */
82 while (y
< SOUNDEX_LENGTH
) code
[y
++] = '0'; /* pad code with zeros */