Commit | Line | Data |
---|---|---|
95024494 VS |
1 | Arch's patch, and a fix for the "number" game's test. |
2 | --- bsdgames-2.17.orig/number/number.c | |
3 | +++ bsdgames-2.17/number/number.c | |
4 | @@ -78,9 +78,9 @@ | |
5 | ||
6 | void convert(char *); | |
7 | int main(int, char *[]); | |
8 | -int number(const char *, int); | |
9 | -void pfract(int); | |
10 | -int unit(int, const char *); | |
11 | +int number(const char *, int, int *); | |
12 | +void pfract(int, int); | |
13 | +int unit(int, const char *, int *); | |
14 | void usage(void) __attribute__((__noreturn__)); | |
15 | ||
16 | int lflag; | |
17 | @@ -131,7 +131,7 @@ | |
18 | convert(line) | |
19 | char *line; | |
20 | { | |
21 | - int flen, len, rval; | |
22 | + int flen, len, rval, singular; | |
23 | char *p, *fraction; | |
24 | ||
25 | flen = 0; | |
26 | @@ -174,7 +174,7 @@ | |
27 | --len; | |
28 | } | |
29 | ||
30 | - rval = len > 0 ? unit(len, line) : 0; | |
31 | + rval = len > 0 ? unit(len, line, &singular) : 0; | |
32 | if (fraction != NULL && flen != 0) | |
33 | for (p = fraction; *p != '\0'; ++p) | |
34 | if (*p != '0') { | |
35 | @@ -182,10 +182,10 @@ | |
36 | (void)printf("%sand%s", | |
37 | lflag ? " " : "", | |
38 | lflag ? " " : "\n"); | |
39 | - if (unit(flen, fraction)) { | |
40 | + if (unit(flen, fraction, &singular)) { | |
41 | if (lflag) | |
42 | (void)printf(" "); | |
43 | - pfract(flen); | |
44 | + pfract(flen, singular); | |
45 | rval = 1; | |
46 | } | |
47 | break; | |
48 | @@ -197,9 +197,10 @@ | |
49 | } | |
50 | ||
51 | int | |
52 | -unit(len, p) | |
53 | +unit(len, p, singular) | |
54 | int len; | |
55 | const char *p; | |
56 | + int *singular; | |
57 | { | |
58 | int off, rval; | |
59 | ||
60 | @@ -208,7 +209,7 @@ | |
61 | if (len % 3) { | |
62 | off = len % 3; | |
63 | len -= off; | |
64 | - if (number(p, off)) { | |
65 | + if (number(p, off, singular)) { | |
66 | rval = 1; | |
67 | (void)printf(" %s%s", | |
68 | name3[len / 3], lflag ? " " : ".\n"); | |
69 | @@ -217,14 +218,16 @@ | |
70 | } | |
71 | for (; len > 3; p += 3) { | |
72 | len -= 3; | |
73 | - if (number(p, 3)) { | |
74 | + if (number(p, 3, singular)) { | |
75 | rval = 1; | |
76 | (void)printf(" %s%s", | |
77 | name3[len / 3], lflag ? " " : ".\n"); | |
78 | } | |
79 | } | |
80 | } | |
81 | - if (number(p, len)) { | |
82 | + if (number(p, len, singular)) { | |
83 | + if (rval) | |
84 | + *singular = 0; | |
85 | if (!lflag) | |
86 | (void)printf(".\n"); | |
87 | rval = 1; | |
88 | @@ -233,17 +236,20 @@ | |
89 | } | |
90 | ||
91 | int | |
92 | -number(p, len) | |
93 | +number(p, len, singular) | |
94 | const char *p; | |
95 | int len; | |
96 | + int *singular; | |
97 | { | |
98 | int val, rval; | |
99 | ||
100 | rval = 0; | |
101 | + *singular = 1; | |
102 | switch (len) { | |
103 | case 3: | |
104 | if (*p != '0') { | |
105 | rval = 1; | |
106 | + *singular = 0; | |
107 | (void)printf("%s hundred", name1[*p - '0']); | |
108 | } | |
109 | ++p; | |
110 | @@ -262,33 +268,42 @@ | |
111 | } | |
112 | rval = 1; | |
113 | } | |
114 | + if (val != 1) | |
115 | + *singular = 0; | |
116 | break; | |
117 | case 1: | |
118 | if (*p != '0') { | |
119 | rval = 1; | |
120 | (void)printf("%s", name1[*p - '0']); | |
121 | } | |
122 | + if (*p != '1') | |
123 | + *singular = 0; | |
124 | } | |
125 | return (rval); | |
126 | } | |
127 | ||
128 | void | |
129 | -pfract(len) | |
130 | +pfract(len, singular) | |
131 | int len; | |
132 | + int singular; | |
133 | { | |
134 | static const char *const pref[] = { "", "ten-", "hundred-" }; | |
135 | ||
136 | switch(len) { | |
137 | case 1: | |
138 | - (void)printf("tenths.\n"); | |
139 | + (void)printf("tenth"); | |
140 | break; | |
141 | case 2: | |
142 | - (void)printf("hundredths.\n"); | |
143 | + (void)printf("hundredth"); | |
144 | break; | |
145 | default: | |
146 | - (void)printf("%s%sths.\n", pref[len % 3], name3[len / 3]); | |
147 | + (void)printf("%s%sth", pref[len % 3], name3[len / 3]); | |
148 | break; | |
149 | } | |
150 | + if (!singular) { | |
151 | + printf("s"); | |
152 | + } | |
153 | + printf(".\n"); | |
154 | } | |
155 | ||
156 | void | |
157 | diff -Naur bsd-games-2.17/tests/number.-0.1 bsd-games-patch/tests/number.-0.1 | |
158 | --- bsd-games-2.17/tests/number.-0.1 1970-01-01 07:00:00.000000000 +0700 | |
159 | +++ bsd-games-patch/tests/number.-0.1 2020-04-17 15:14:27.831098084 +0700 | |
160 | @@ -1,3 +1,3 @@ | |
161 | minus | |
162 | one. | |
163 | -tenths. | |
164 | +tenth. | |
165 | diff -Naur bsd-games-2.17/tests/number.-0.2 bsd-games-patch/tests/number.-0.2 | |
166 | --- bsd-games-2.17/tests/number.-0.2 1970-01-01 07:00:00.000000000 +0700 | |
167 | +++ bsd-games-patch/tests/number.-0.2 2020-04-17 15:20:48.162336279 +0700 | |
168 | @@ -0,0 +1,3 @@ | |
169 | +minus | |
170 | +two. | |
171 | +tenths. | |
172 | diff -Naur bsd-games-2.17/tests/number.test bsd-games-patch/tests/number.test | |
173 | --- bsd-games-2.17/tests/number.test 1970-01-01 07:00:00.000000000 +0700 | |
174 | +++ bsd-games-patch/tests/number.test 2020-04-17 15:20:22.774654155 +0700 | |
175 | @@ -36,6 +36,8 @@ | |
176 | testno 1 | |
177 | number/number -- -0.1 >test.out 2>&1 || failtest | |
178 | compare test.out tests/number.-0.1 | |
179 | +number/number -- -0.2 >test.out 2>&1 || failtest | |
180 | +compare test.out tests/number.-0.2 | |
181 | rm -f test.out | |
182 | ||
183 | testno 2 |