| 1820 | } |
| 1821 | |
| 1822 | char * |
| 1823 | build_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 |
no test coverage detected