gl_language.c
src/clib/gl_language.c · 2.9 KB
From the archive Lpmud-CD.03.31beta1.tar.gz
Download the archive « Back to the archive contents
#include <stdio.h>
#include <string.h>
#include "../lint.h"
#include "../interface.h"
#include "../object.h"
/* Define variables */
extern struct object *previous_ob;
/* Define functions */
extern char *malloc(unsigned);
#ifdef _SEQUENT_
extern void *alloca(unsigned);
#endif
char lower(char c)
{
char ret;
ret = c;
if (ret < 96)
ret += 32;
return ret;
}
static void
global_article(struct svalue *fp)
{
char *tmp, *a;
if (fp[0].type != T_STRING)
{
push_number(0);
return;
}
tmp = alloca((strlen(fp[0].u.string) + 2));
strcpy(tmp, (char *)(fp[0].u.string));
strcat(tmp, " ");
tmp[0] = (char)lower(tmp[0]);
if (!strncmp(tmp, "the ", 4))
{
push_string("", STRING_CONSTANT);
return;
}
if (tmp[0] == 'a' || tmp[0] == 'e' || tmp[0] == 'i' ||
tmp[0] == 'o' || tmp[0] == 'u')
{
push_string("an", STRING_CONSTANT);
return;
}
push_string("a", STRING_CONSTANT);
return;
}
static func func_article =
{
"article",
global_article,
};
static void
global_plural_word(struct svalue *fp)
{
char *tmp, *str, ultimate, penultimate;
int sl;
if (fp[0].type != T_STRING)
{
push_number(0);
return;
}
str = fp[0].u.string;
if (strcmp(str, "tooth") == 0)
{
push_string("teeth", STRING_CONSTANT); return;
}
else if (strcmp(str, "foot") == 0)
{
push_string("feet", STRING_CONSTANT); return;
}
else if (strcmp(str, "man") == 0)
{
push_string("men", STRING_CONSTANT); return;
}
else if (strcmp(str, "woman") == 0)
{
push_string("women", STRING_CONSTANT); return;
}
else if (strcmp(str, "child") == 0)
{
push_string("children", STRING_CONSTANT); return;
}
else if (strcmp(str, "sheep") == 0)
{
push_string("sheep", STRING_CONSTANT); return;
}
else if (strcmp(str, "key") == 0)
{
push_string("keys", STRING_CONSTANT); return;
}
if ((sl = strlen(str)) < 3)
{
push_string(str, STRING_MALLOC);
return;
}
tmp = alloca((strlen((char *)str) + 10));
strncpy(tmp, str, sl);
ultimate = str[sl - 1];
penultimate = str[sl - 2];
tmp[sl] = '\0';
switch(ultimate)
{
case 's':
case 'x':
case 'h':
strcat(tmp, "es");
break;
case 'y':
if (penultimate == 'a' || penultimate == 'e' || penultimate == 'o')
strcat(tmp, "s");
else
{
tmp[sl - 1] = '\0';
strcat(tmp, "ies");
}
break;
case 'e':
if (penultimate == 'f')
{
tmp[sl - 1] = '\0';
strcat(tmp, "ves");
}
break;
default:
strcat(tmp, "s");
break;
}
push_string(tmp, STRING_MALLOC);
return;
}
static func func_plural_word =
{
"plural_word",
global_plural_word,
};
static func *(funcs[]) =
{
&func_article,
&func_plural_word,
0,
};
static var *(vars[]) =
{
0,
};
struct interface gl_language =
{
"sys/global/language.c",
vars,
funcs,
};