DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T p

⟦b20f3198f⟧ TextFile

    Length: 1304 (0x518)
    Types: TextFile
    Names: »plural.c.orig«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Scrabble/plural.c.orig« 

TextFile


/* RCS Info: $Revision: 1.1 $ on $Date: 89/03/15 11:17:10 $
 *           $Source: /yew3/faustus/src/scrabble/RCS/plural.c,v $
 * Copyright (c) 1989 Wayne A. Christopher, U. C. Berkeley CS Dept
 *	 faustus@renoir.berkeley.edu, ucbvax!faustus
 * Permission is granted to modify and re-distribute this code in any manner
 * as long as this notice is preserved.  All standard disclaimers apply.
 *
 * This program reads words from standard input and pluralizes them.
 */

#include <stdio.h>
#include <strings.h>

struct {
	char *end;
	char *new;
} endings[] = {
	{ "s",		"ses" },
	{ "x",		"xes" },
	{ "z",		"zes" },
	{ "ch",		"ches" },
	{ "sh",		"shes" },
	{ "ey",		"eys" },
	{ "y",		"ies" },
	{ "",		"s" }
} ;

void
pluralize(char *word)
{
	int i, wl, sl;
	char *s, *t;

	for (i = 0; i < sizeof (endings) / sizeof (endings[0]); i++) {
		for (s = word, wl = 0; *s; s++, wl++)
			;
		for (t = endings[i].end, sl = 0; *t; t++, sl++)
			;
		if (sl > wl)
			continue;
		s -= sl;
		for (t = endings[i].end; *t; t++, s++)
			if (*s != *t)
				break;
		if (!*t) {
			s -= sl;
			for (t = endings[i].new; *t; t++, s++)
				*s = *t;
			*s = '\0';
			break;
		}
	}
}

main()
{
	char buf[512];

	while (fgets(buf, 512, stdin)) {
		buf[strlen(buf) - 1] = '\0';
		pluralize(buf);
		printf("%s\n", buf);
	}

	exit(0);
}