MCPcopy Create free account
hub / github.com/NetHack/NetHack / build_english_list

Function build_english_list

src/end.c:1822–1859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1820}
1821
1822char *
1823build_english_list(char *in)
1824{
1825 char *out, *p = in;
1826 int len = (int) strlen(p), words = wordcount(p);
1827
1828 /* +3: " or " - " "; +(words - 1): (N-1)*(", " - " ") */
1829 if (words > 1)
1830 len += 3 + (words - 1);
1831 out = (char *) alloc(len + 1);
1832 *out = '\0'; /* bel_copy1() appends */
1833
1834 switch (words) {
1835 case 0:
1836 impossible("no words in list");
1837 break;
1838 case 1:
1839 /* "single" */
1840 bel_copy1(&p, out);
1841 break;
1842 default:
1843 if (words == 2) {
1844 /* "first or second" */
1845 bel_copy1(&p, out);
1846 Strcat(out, " ");
1847 } else {
1848 /* "first, second, or third */
1849 do {
1850 bel_copy1(&p, out);
1851 Strcat(out, ", ");
1852 } while (--words > 1);
1853 }
1854 Strcat(out, "or ");
1855 bel_copy1(&p, out);
1856 break;
1857 }
1858 return out;
1859}
1860
1861/* What do we try to in what order? Tradeoffs:
1862 * libc: +no external programs required

Callers 3

wd_messageFunction · 0.85
wd_messageFunction · 0.85
cnf_line_WIZARDSFunction · 0.85

Calls 4

wordcountFunction · 0.85
bel_copy1Function · 0.85
allocFunction · 0.70
impossibleFunction · 0.70

Tested by

no test coverage detected