/* vi: set ts=2: * * $Id: umlaut.c,v 1.4 2001/02/13 02:58:51 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de) * Enno Rehling (enno@eressea-pbem.de) * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) * * based on: * * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace * Atlantis v1.7 Copyright 1996 by Alex Schröder * * This program may not be used, modified or distributed without * prior permission by the authors of Eressea. * This program may not be sold or used commercially without prior written * permission from the authors. */ #include #include "umlaut.h" #include #include #include #include void addtoken(tnode * root, const char* str, void * id) { static char zText[1024]; static struct replace { char c; const char * str; } replace[] = { {'ä', "ae"}, {'Ä', "ae"}, {'ö', "oe"}, {'Ö', "oe"}, {'ü', "ue"}, {'Ü', "ue"}, {'ß', "ss"}, { 0, 0 } }; assert(id!=E_TOK_NOMATCH); if (root->id!=E_TOK_NOMATCH && root->id!=id && !root->leaf) root->id=E_TOK_NOMATCH; if (!*str) { root->id = id; root->leaf=1; } else { tnode * tk; int index, i = 0; char c = *str; if (c<'a' || c>'z') c = (char)tolower((unsigned char)c); index = ((unsigned char)c) % 32; tk = root->next[index]; if (root->id==E_TOK_NOMATCH) root->id = id; while (tk && tk->c != c) tk = tk->nexthash; if (!tk) { tk = calloc(1, sizeof(tnode)); tk->id = E_TOK_NOMATCH; tk->c = c; tk->nexthash=root->next[index]; root->next[index] = tk; } addtoken(tk, str+1, id); while (replace[i].str) { if (*str==replace[i].c) { strcat(strcpy(zText, replace[i].str), str+1); addtoken(root, zText, id); break; } ++i; } } } void * findtoken(tnode * tk, const char * str) { if(*str == 0) return E_TOK_NOMATCH; while (*str) { int index; char c = *str; if (c<'a' || c>'z') c = (char)tolower((unsigned char)c); index = ((unsigned char)c) % 32; tk = tk->next[index]; while (tk && tk->c!=c) tk = tk->nexthash; ++str; if (!tk) return E_TOK_NOMATCH; } return tk->id; }