2001-01-25 10:37:55 +01:00
|
|
|
|
/* vi: set ts=2:
|
|
|
|
|
*
|
2001-02-13 03:58:51 +01:00
|
|
|
|
* $Id: umlaut.c,v 1.4 2001/02/13 02:58:51 enno Exp $
|
2001-01-25 10:37:55 +01:00
|
|
|
|
* 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<EFBFBD>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 <config.h>
|
|
|
|
|
#include "umlaut.h"
|
|
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
addtoken(tnode * root, const char* str, void * id)
|
|
|
|
|
{
|
2001-02-10 11:40:12 +01:00
|
|
|
|
static char zText[1024];
|
2001-01-25 10:37:55 +01:00
|
|
|
|
static struct replace {
|
|
|
|
|
char c;
|
|
|
|
|
const char * str;
|
|
|
|
|
} replace[] = {
|
|
|
|
|
{'<EFBFBD>', "ae"},
|
|
|
|
|
{'<EFBFBD>', "ae"},
|
|
|
|
|
{'<EFBFBD>', "oe"},
|
|
|
|
|
{'<EFBFBD>', "oe"},
|
|
|
|
|
{'<EFBFBD>', "ue"},
|
|
|
|
|
{'<EFBFBD>', "ue"},
|
|
|
|
|
{'<EFBFBD>', "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 {
|
2001-02-13 03:58:51 +01:00
|
|
|
|
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];
|
2001-01-25 10:37:55 +01:00
|
|
|
|
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) {
|
2001-02-10 11:40:12 +01:00
|
|
|
|
strcat(strcpy(zText, replace[i].str), str+1);
|
|
|
|
|
addtoken(root, zText, id);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
|
findtoken(tnode * tk, const char * str)
|
|
|
|
|
{
|
|
|
|
|
if(*str == 0) return E_TOK_NOMATCH;
|
|
|
|
|
|
|
|
|
|
while (*str) {
|
2001-02-13 03:58:51 +01:00
|
|
|
|
int index;
|
|
|
|
|
char c = *str;
|
|
|
|
|
if (c<'a' || c>'z') c = (char)tolower((unsigned char)c);
|
|
|
|
|
|
|
|
|
|
index = ((unsigned char)c) % 32;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
tk = tk->next[index];
|
|
|
|
|
while (tk && tk->c!=c) tk = tk->nexthash;
|
|
|
|
|
++str;
|
|
|
|
|
if (!tk) return E_TOK_NOMATCH;
|
|
|
|
|
}
|
|
|
|
|
return tk->id;
|
|
|
|
|
}
|
|
|
|
|
|