]> git.pond.sub.org Git - empserver/blob - src/lib/gen/plur.c
(budg): Create the capital/city name from the d_name field instead of
[empserver] / src / lib / gen / plur.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  plur.c: Pluralize (is that a word?) something
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include "misc.h"
35 #include "gen.h"
36
37 s_char *
38 splur(int n)
39 {
40     return n == 1 ? "" : "s";
41 }
42
43 s_char *
44 esplur(int n)
45 {
46     return n == 1 ? "" : "es";
47 }
48
49 s_char *
50 iesplur(int n)
51 {
52     return n == 1 ? "y" : "ies";
53 }
54
55 /*
56  * Change suffix of BUF to English plural if N > 1.
57  * Best effort, not 100% accurate English.
58  * Array BUF[MAX_LEN] contains a zero-terminated string.
59  * If there's not enough space for changed suffix, it is truncated.
60  */
61 char *
62 plurize(char *buf, int max_len, int n)
63 {
64     if (!strlen(buf) || n <= 1)
65         return buf;
66
67     switch(buf[strlen(buf) - 1]) {
68     case 'y':
69         buf[strlen(buf) -1] = '\0';
70         strncat(buf, "ies", max_len - 1);
71         break;
72     case 's':
73         strncat(buf, "es", max_len - 1);
74         break;
75     default:
76         strncat(buf, "s", max_len - 1);
77     }
78     return buf;
79 }