97 #ifndef DMETAPHONE_MAIN
122 #ifndef DMETAPHONE_MAIN
138 #ifdef DMETAPHONE_NOSTRICT
167 #ifdef DMETAPHONE_NOSTRICT
187 #define META_MALLOC(v,n,t) \
188 (v = (t*)palloc(((n)*sizeof(t))))
190 #define META_REALLOC(v,n,t) \
191 (v = (t*)repalloc((v),((n)*sizeof(t))))
200 #define META_FREE(x) ((void)true)
205 #define META_MALLOC(v,n,t) \
206 (v = (t*)malloc(((n)*sizeof(t))))
208 #define META_REALLOC(v,n,t) \
209 (v = (t*)realloc((v),((n)*sizeof(t))))
211 #define META_FREE(x) free((x))
238 char empty_string[] =
"";
243 if (init_str == NULL)
244 init_str = empty_string;
245 s->
length = strlen(init_str);
287 *
i = toupper((
unsigned char) *
i);
296 if ((pos < 0) || (pos >= s->
length))
300 if ((
c ==
'A') || (
c ==
'E') || (
c ==
'I') || (
c ==
'O') ||
301 (
c ==
'U') || (
c ==
'Y'))
311 if ((
char *) strstr(s->
str,
"W"))
313 else if ((
char *) strstr(s->
str,
"K"))
315 else if ((
char *) strstr(s->
str,
"CZ"))
317 else if ((
char *) strstr(s->
str,
"WITZ"))
327 if ((pos < 0) || (pos >= s->
length))
330 return ((
char) *(s->
str + pos));
337 if ((pos < 0) || (pos >= s->
length))
362 test = va_arg(ap,
char *);
363 if (*
test && (strncmp(pos,
test, length) == 0))
369 while (strcmp(
test,
"") != 0);
385 add_length = strlen(new_str);
389 strcat(s->
str, new_str);
406 length = strlen(
str);
420 if (
StringAt(original, 0, 2,
"GN",
"KN",
"PN",
"WR",
"PS",
""))
424 if (
GetAt(original, 0) ==
'X')
432 while ((primary->
length < 4) || (secondary->
length < 4))
434 if (current >= length)
437 switch (
GetAt(original, current))
460 if (
GetAt(original, current + 1) ==
'B')
475 && !
IsVowel(original, current - 2)
476 &&
StringAt(original, (current - 1), 3,
"ACH",
"")
477 && ((
GetAt(original, current + 2) !=
'I')
478 && ((
GetAt(original, current + 2) !=
'E')
479 ||
StringAt(original, (current - 2), 6,
"BACHER",
490 &&
StringAt(original, current, 6,
"CAESAR",
""))
499 if (
StringAt(original, current, 4,
"CHIA",
""))
507 if (
StringAt(original, current, 2,
"CH",
""))
511 &&
StringAt(original, current, 4,
"CHAE",
""))
521 && (
StringAt(original, (current + 1), 5,
522 "HARAC",
"HARIS",
"")
523 ||
StringAt(original, (current + 1), 3,
"HOR",
524 "HYM",
"HIA",
"HEM",
""))
525 && !
StringAt(original, 0, 5,
"CHORE",
""))
534 if ((
StringAt(original, 0, 4,
"VAN ",
"VON ",
"")
535 ||
StringAt(original, 0, 3,
"SCH",
""))
537 ||
StringAt(original, (current - 2), 6,
"ORCHES",
538 "ARCHIT",
"ORCHID",
"")
539 ||
StringAt(original, (current + 2), 1,
"T",
"S",
541 || ((
StringAt(original, (current - 1), 1,
542 "A",
"O",
"U",
"E",
"")
548 &&
StringAt(original, (current + 2), 1,
"L",
"R",
549 "N",
"M",
"B",
"H",
"F",
"V",
"W",
559 if (
StringAt(original, 0, 2,
"MC",
""))
581 if (
StringAt(original, current, 2,
"CZ",
"")
582 && !
StringAt(original, (current - 2), 4,
"WICZ",
""))
591 if (
StringAt(original, (current + 1), 3,
"CIA",
""))
600 if (
StringAt(original, current, 2,
"CC",
"")
601 && !((current == 1) && (
GetAt(original, 0) ==
'M')))
604 if (
StringAt(original, (current + 2), 1,
"I",
"E",
"H",
"")
605 && !
StringAt(original, (current + 2), 2,
"HU",
""))
609 && (
GetAt(original, current - 1) ==
'A'))
610 ||
StringAt(original, (current - 1), 5,
"UCCEE",
634 if (
StringAt(original, current, 2,
"CK",
"CG",
"CQ",
""))
642 if (
StringAt(original, current, 2,
"CI",
"CE",
"CY",
""))
646 (original, current, 3,
"CIO",
"CIE",
"CIA",
""))
665 if (
StringAt(original, (current + 1), 2,
" C",
" Q",
" G",
""))
667 else if (
StringAt(original, (current + 1), 1,
"C",
"K",
"Q",
"")
668 && !
StringAt(original, (current + 1), 2,
676 if (
StringAt(original, current, 2,
"DG",
""))
678 if (
StringAt(original, (current + 2), 1,
697 if (
StringAt(original, current, 2,
"DT",
"DD",
""))
712 if (
GetAt(original, current + 1) ==
'F')
721 if (
GetAt(original, current + 1) ==
'H')
723 if ((current > 0) && !
IsVowel(original, current - 1))
736 if (
GetAt(original, current + 2) ==
'I')
756 &&
StringAt(original, (current - 2), 1,
760 &&
StringAt(original, (current - 3), 1,
764 &&
StringAt(original, (current - 4), 1,
777 && (
GetAt(original, current - 1) ==
'U')
778 &&
StringAt(original, (current - 3), 1,
"C",
779 "G",
"L",
"R",
"T",
""))
784 else if ((current > 0)
785 &&
GetAt(original, current - 1) !=
'I')
798 if (
GetAt(original, current + 1) ==
'N')
800 if ((current == 1) &&
IsVowel(original, 0)
808 if (!
StringAt(original, (current + 2), 2,
"EY",
"")
809 && (
GetAt(original, current + 1) !=
'Y')
825 if (
StringAt(original, (current + 1), 2,
"LI",
"")
836 && ((
GetAt(original, current + 1) ==
'Y')
837 ||
StringAt(original, (current + 1), 2,
"ES",
"EP",
838 "EB",
"EL",
"EY",
"IB",
"IL",
"IN",
"IE",
848 if ((
StringAt(original, (current + 1), 2,
"ER",
"")
849 || (
GetAt(original, current + 1) ==
'Y'))
851 "DANGER",
"RANGER",
"MANGER",
"")
852 && !
StringAt(original, (current - 1), 1,
"E",
"I",
"")
853 && !
StringAt(original, (current - 1), 3,
"RGY",
"OGY",
""))
862 if (
StringAt(original, (current + 1), 1,
"E",
"I",
"Y",
"")
863 ||
StringAt(original, (current - 1), 4,
867 if ((
StringAt(original, 0, 4,
"VAN ",
"VON ",
"")
868 ||
StringAt(original, 0, 3,
"SCH",
""))
869 ||
StringAt(original, (current + 1), 2,
"ET",
""))
878 (original, (current + 1), 4,
"IER ",
""))
893 if (
GetAt(original, current + 1) ==
'G')
903 if (((current == 0) ||
IsVowel(original, current - 1))
904 &&
IsVowel(original, current + 1))
917 if (
StringAt(original, current, 4,
"JOSE",
"")
918 ||
StringAt(original, 0, 4,
"SAN ",
""))
921 && (
GetAt(original, current + 4) ==
' '))
922 ||
StringAt(original, 0, 4,
"SAN ",
""))
937 && !
StringAt(original, current, 4,
"JOSE",
""))
945 if (
IsVowel(original, current - 1)
947 && ((
GetAt(original, current + 1) ==
'A')
948 || (
GetAt(original, current + 1) ==
'O')))
962 if (!
StringAt(original, (current + 1), 1,
"L",
"T",
963 "K",
"S",
"N",
"M",
"B",
"Z",
"")
964 && !
StringAt(original, (current - 1), 1,
974 if (
GetAt(original, current + 1) ==
'J')
981 if (
GetAt(original, current + 1) ==
'K')
990 if (
GetAt(original, current + 1) ==
'L')
993 if (((current == (length - 3))
994 &&
StringAt(original, (current - 1), 4,
"ILLO",
996 || ((
StringAt(original, (last - 1), 2,
"AS",
"OS",
"")
997 ||
StringAt(original, last, 1,
"A",
"O",
""))
998 &&
StringAt(original, (current - 1), 4,
1015 if ((
StringAt(original, (current - 1), 3,
"UMB",
"")
1016 && (((current + 1) == last)
1017 ||
StringAt(original, (current + 2), 2,
"ER",
"")))
1019 || (
GetAt(original, current + 1) ==
'M'))
1028 if (
GetAt(original, current + 1) ==
'N')
1043 if (
GetAt(original, current + 1) ==
'H')
1052 if (
StringAt(original, (current + 1), 1,
"P",
"B",
""))
1061 if (
GetAt(original, current + 1) ==
'Q')
1071 if ((current == last)
1073 &&
StringAt(original, (current - 2), 2,
"IE",
"")
1074 && !
StringAt(original, (current - 4), 2,
"ME",
"MA",
""))
1085 if (
GetAt(original, current + 1) ==
'R')
1093 if (
StringAt(original, (current - 1), 3,
"ISL",
"YSL",
""))
1101 &&
StringAt(original, current, 5,
"SUGAR",
""))
1109 if (
StringAt(original, current, 2,
"SH",
""))
1113 (original, (current + 1), 4,
"HEIM",
"HOEK",
"HOLM",
1129 if (
StringAt(original, current, 3,
"SIO",
"SIA",
"")
1130 ||
StringAt(original, current, 4,
"SIAN",
""))
1152 &&
StringAt(original, (current + 1), 1,
1153 "M",
"N",
"L",
"W",
""))
1154 ||
StringAt(original, (current + 1), 1,
"Z",
""))
1158 if (
StringAt(original, (current + 1), 1,
"Z",
""))
1165 if (
StringAt(original, current, 2,
"SC",
""))
1168 if (
GetAt(original, current + 2) ==
'H')
1171 if (
StringAt(original, (current + 3), 2,
1173 "UY",
"ED",
"EM",
""))
1176 if (
StringAt(original, (current + 3), 2,
1192 if ((current == 0) && !
IsVowel(original, 3)
1193 && (
GetAt(original, 3) !=
'W'))
1208 if (
StringAt(original, (current + 2), 1,
1224 if ((current == last)
1225 &&
StringAt(original, (current - 2), 2,
"AI",
"OI",
""))
1236 if (
StringAt(original, (current + 1), 1,
"S",
"Z",
""))
1243 if (
StringAt(original, current, 4,
"TION",
""))
1251 if (
StringAt(original, current, 3,
"TIA",
"TCH",
""))
1259 if (
StringAt(original, current, 2,
"TH",
"")
1260 ||
StringAt(original, current, 3,
"TTH",
""))
1263 if (
StringAt(original, (current + 2), 2,
"OM",
"AM",
"")
1264 ||
StringAt(original, 0, 4,
"VAN ",
"VON ",
"")
1265 ||
StringAt(original, 0, 3,
"SCH",
""))
1279 if (
StringAt(original, (current + 1), 1,
"T",
"D",
""))
1288 if (
GetAt(original, current + 1) ==
'V')
1298 if (
StringAt(original, current, 2,
"WR",
""))
1307 && (
IsVowel(original, current + 1)
1308 ||
StringAt(original, current, 2,
"WH",
"")))
1311 if (
IsVowel(original, current + 1))
1325 if (((current == last) &&
IsVowel(original, current - 1))
1326 ||
StringAt(original, (current - 1), 5,
"EWSKI",
"EWSKY",
1327 "OWSKI",
"OWSKY",
"")
1328 ||
StringAt(original, 0, 3,
"SCH",
""))
1337 if (
StringAt(original, current, 4,
"WICZ",
"WITZ",
""))
1351 if (!((current == last)
1352 && (
StringAt(original, (current - 3), 3,
1354 ||
StringAt(original, (current - 2), 2,
1362 if (
StringAt(original, (current + 1), 1,
"C",
"X",
""))
1370 if (
GetAt(original, current + 1) ==
'H')
1377 else if (
StringAt(original, (current + 1), 2,
1378 "ZO",
"ZI",
"ZA",
"")
1381 &&
GetAt(original, current - 1) !=
'T')))
1392 if (
GetAt(original, current + 1) ==
'Z')
1410 SetAt(primary, 4,
'\0');
1412 if (secondary->
length > 4)
1413 SetAt(secondary, 4,
'\0');
1415 *codes = primary->
str;
1416 *++codes = secondary->
str;
1423 #ifdef DMETAPHONE_MAIN
1427 main(
int argc,
char **argv)
1434 printf(
"%s|%s\n", codes[0], codes[1]);
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_TEXT_P(x)
int main(int argc, char **argv)
char * text_to_cstring(const text *t)
text * cstring_to_text(const char *s)