echo "Extracting file soundex.sql" sed -e 's/^X//' <<\SHAR_EOF > soundex.sql X-- Soundex SPL code X-- Designed to return a 5 position soundex code x-- after being passed a 40 position input string. X-- If a 'empty' string is passed, the routine X-- returns '*****'. X-- Duplicate (repeating) letters are eliminated. X Xcreate procedure soundex(input_str char(40)) returning varchar(10); Xdefine return_str varchar(10); Xdefine old_char char(1); Xdefine new_char char(1); Xdefine code char(1); Xdefine i, out_count, len smallint; X Xlet old_char = " "; Xlet len = length(input_str); X Xif len == 0 then -- make sure they actually passed us something X return "*****"; Xend if X Xwhile input_str[1,1] == " " -- shift left to first non-blank character X let input_str = input_str[2,40]; X let len = len - 1; Xend while X Xlet input_str = upper(input_str); -- convert to upper case X X Xlet old_char = input_str[1,1]; -- load first character Xlet return_str = old_char; X Xlet out_count = 1; -- keep track of output characters X Xfor i = 1 to len X let input_str = input_str[2,40]; X let new_char = input_str[1,1]; X X if new_char == " " or new_char == old_char then -- bypass spaces and duplicate letters X continue for; X end if X X let old_char = new_char; X X if new_char matches "[AEIOUY]" then -- we skip vowels X continue for; X elif new_char matches "[HW]" then -- we also skip "WH" X continue for; X elif new_char matches "[BFPV]" then X let code = 1; X elif new_char matches "[CGJKQSXZ]" then X let code = 2; X elif new_char matches "[DT]" then X let code = 3; X elif new_char matches "[L]" then X let code = 4; X elif new_char matches "[MN]" then X let code = 5; X elif new_char matches "[R]" then X let code = 6; X else X continue for; -- non-letters are ignored X end if X X let return_str = return_str || code; -- this combines the output string X X let out_count = out_count + 1; X X if out_count == 5 then -- no need to go further X exit for; X end if X Xend for X Xif out_count < 5 then -- we may be short X let return_str = return_str || "0000"; -- pad with "0's" Xend if X Xreturn return_str[1,5]; -- send back five positions Xend procedure; SHAR_EOF