Plural routine; once upon a time it may have been chiefly used for * user-defined fruits, but it is now used extensively throughout the * program. * * For fruit, we have to try to account for everything reasonable the * player has; something unreasonable can still break the code. * However, it's still a lot more accurate than "just add an 's' at the * end", which Rogue uses... * * Also us
| 2833 | * 3.6.0: made case-insensitive. |
| 2834 | */ |
| 2835 | char * |
| 2836 | makeplural(const char *oldstr) |
| 2837 | { |
| 2838 | char *spot; |
| 2839 | char lo_c, *str = nextobuf(); |
| 2840 | const char *excess = (char *) 0; |
| 2841 | int len, i; |
| 2842 | |
| 2843 | if (oldstr) |
| 2844 | while (*oldstr == ' ') |
| 2845 | oldstr++; |
| 2846 | if (!oldstr || !*oldstr) { |
| 2847 | impossible("plural of null?"); |
| 2848 | Strcpy(str, "s"); |
| 2849 | return str; |
| 2850 | } |
| 2851 | /* makeplural() is sometimes used on monsters rather than objects |
| 2852 | and sometimes pronouns are used for monsters, so check those; |
| 2853 | unfortunately, "her" (which matches genders[1].him and [1].his) |
| 2854 | and "it" (which matches genders[2].he and [2].him) are ambiguous; |
| 2855 | we'll live with that; caller can fix things up if necessary */ |
| 2856 | *str = '\0'; |
| 2857 | for (i = 0; i <= 2; ++i) { |
| 2858 | if (!strcmpi(genders[i].he, oldstr)) |
| 2859 | Strcpy(str, genders[3].he); /* "they" */ |
| 2860 | else if (!strcmpi(genders[i].him, oldstr)) |
| 2861 | Strcpy(str, genders[3].him); /* "them" */ |
| 2862 | else if (!strcmpi(genders[i].his, oldstr)) |
| 2863 | Strcpy(str, genders[3].his); /* "their" */ |
| 2864 | if (*str) { |
| 2865 | if (oldstr[0] == highc(oldstr[0])) |
| 2866 | str[0] = highc(str[0]); |
| 2867 | return str; |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | Strcpy(str, oldstr); |
| 2872 | |
| 2873 | /* |
| 2874 | * Skip changing "pair of" to "pairs of". According to Webster, usual |
| 2875 | * English usage is use pairs for humans, e.g. 3 pairs of dancers, |
| 2876 | * and pair for objects and non-humans, e.g. 3 pair of boots. We don't |
| 2877 | * refer to pairs of humans in this game so just skip to the bottom. |
| 2878 | */ |
| 2879 | if (!strncmpi(str, "pair of ", 8)) |
| 2880 | goto bottom; |
| 2881 | |
| 2882 | /* look for "foo of bar" so that we can focus on "foo" */ |
| 2883 | if ((spot = singplur_compound(str)) != 0) { |
| 2884 | excess = oldstr + (int) (spot - str); |
| 2885 | *spot = '\0'; |
| 2886 | } else |
| 2887 | spot = eos(str); |
| 2888 | |
| 2889 | spot--; |
| 2890 | while (spot > str && *spot == ' ') |
| 2891 | spot--; /* Strip blanks from end */ |
| 2892 | *(spot + 1) = '\0'; |
no test coverage detected