95024494f3
* gnu/packages/games.scm (bsd-games): New variable. New patches, taken from Arch and Debian: * gnu/packages/patches/bsd-games-2.17-64bit.patch * gnu/packages/patches/bsd-games-bad-ntohl-cast.patch * gnu/packages/patches/bsd-games-gamescreen.h.patch * gnu/packages/patches/bsd-games-getline.patch * gnu/packages/patches/bsd-games-null-check.patch * gnu/packages/patches/bsd-games-number.c-and-test.patch * gnu/packages/patches/bsd-games-prevent-name-collisions.patch * gnu/packages/patches/bsd-games-stdio.h.patch New patches with our customizations (configure-config built after Arch's): * gnu/packages/patches/bsd-games-add-configure-config.patch * gnu/packages/patches/bsd-games-add-wrapper.patch * gnu/packages/patches/bsd-games-dont-install-empty-files.patch Signed-off-by: Nicolas Goaziou <mail@nicolasgoaziou.fr>
183 lines
3.8 KiB
Diff
183 lines
3.8 KiB
Diff
Arch's patch, and a fix for the "number" game's test.
|
|
--- bsdgames-2.17.orig/number/number.c
|
|
+++ bsdgames-2.17/number/number.c
|
|
@@ -78,9 +78,9 @@
|
|
|
|
void convert(char *);
|
|
int main(int, char *[]);
|
|
-int number(const char *, int);
|
|
-void pfract(int);
|
|
-int unit(int, const char *);
|
|
+int number(const char *, int, int *);
|
|
+void pfract(int, int);
|
|
+int unit(int, const char *, int *);
|
|
void usage(void) __attribute__((__noreturn__));
|
|
|
|
int lflag;
|
|
@@ -131,7 +131,7 @@
|
|
convert(line)
|
|
char *line;
|
|
{
|
|
- int flen, len, rval;
|
|
+ int flen, len, rval, singular;
|
|
char *p, *fraction;
|
|
|
|
flen = 0;
|
|
@@ -174,7 +174,7 @@
|
|
--len;
|
|
}
|
|
|
|
- rval = len > 0 ? unit(len, line) : 0;
|
|
+ rval = len > 0 ? unit(len, line, &singular) : 0;
|
|
if (fraction != NULL && flen != 0)
|
|
for (p = fraction; *p != '\0'; ++p)
|
|
if (*p != '0') {
|
|
@@ -182,10 +182,10 @@
|
|
(void)printf("%sand%s",
|
|
lflag ? " " : "",
|
|
lflag ? " " : "\n");
|
|
- if (unit(flen, fraction)) {
|
|
+ if (unit(flen, fraction, &singular)) {
|
|
if (lflag)
|
|
(void)printf(" ");
|
|
- pfract(flen);
|
|
+ pfract(flen, singular);
|
|
rval = 1;
|
|
}
|
|
break;
|
|
@@ -197,9 +197,10 @@
|
|
}
|
|
|
|
int
|
|
-unit(len, p)
|
|
+unit(len, p, singular)
|
|
int len;
|
|
const char *p;
|
|
+ int *singular;
|
|
{
|
|
int off, rval;
|
|
|
|
@@ -208,7 +209,7 @@
|
|
if (len % 3) {
|
|
off = len % 3;
|
|
len -= off;
|
|
- if (number(p, off)) {
|
|
+ if (number(p, off, singular)) {
|
|
rval = 1;
|
|
(void)printf(" %s%s",
|
|
name3[len / 3], lflag ? " " : ".\n");
|
|
@@ -217,14 +218,16 @@
|
|
}
|
|
for (; len > 3; p += 3) {
|
|
len -= 3;
|
|
- if (number(p, 3)) {
|
|
+ if (number(p, 3, singular)) {
|
|
rval = 1;
|
|
(void)printf(" %s%s",
|
|
name3[len / 3], lflag ? " " : ".\n");
|
|
}
|
|
}
|
|
}
|
|
- if (number(p, len)) {
|
|
+ if (number(p, len, singular)) {
|
|
+ if (rval)
|
|
+ *singular = 0;
|
|
if (!lflag)
|
|
(void)printf(".\n");
|
|
rval = 1;
|
|
@@ -233,17 +236,20 @@
|
|
}
|
|
|
|
int
|
|
-number(p, len)
|
|
+number(p, len, singular)
|
|
const char *p;
|
|
int len;
|
|
+ int *singular;
|
|
{
|
|
int val, rval;
|
|
|
|
rval = 0;
|
|
+ *singular = 1;
|
|
switch (len) {
|
|
case 3:
|
|
if (*p != '0') {
|
|
rval = 1;
|
|
+ *singular = 0;
|
|
(void)printf("%s hundred", name1[*p - '0']);
|
|
}
|
|
++p;
|
|
@@ -262,33 +268,42 @@
|
|
}
|
|
rval = 1;
|
|
}
|
|
+ if (val != 1)
|
|
+ *singular = 0;
|
|
break;
|
|
case 1:
|
|
if (*p != '0') {
|
|
rval = 1;
|
|
(void)printf("%s", name1[*p - '0']);
|
|
}
|
|
+ if (*p != '1')
|
|
+ *singular = 0;
|
|
}
|
|
return (rval);
|
|
}
|
|
|
|
void
|
|
-pfract(len)
|
|
+pfract(len, singular)
|
|
int len;
|
|
+ int singular;
|
|
{
|
|
static const char *const pref[] = { "", "ten-", "hundred-" };
|
|
|
|
switch(len) {
|
|
case 1:
|
|
- (void)printf("tenths.\n");
|
|
+ (void)printf("tenth");
|
|
break;
|
|
case 2:
|
|
- (void)printf("hundredths.\n");
|
|
+ (void)printf("hundredth");
|
|
break;
|
|
default:
|
|
- (void)printf("%s%sths.\n", pref[len % 3], name3[len / 3]);
|
|
+ (void)printf("%s%sth", pref[len % 3], name3[len / 3]);
|
|
break;
|
|
}
|
|
+ if (!singular) {
|
|
+ printf("s");
|
|
+ }
|
|
+ printf(".\n");
|
|
}
|
|
|
|
void
|
|
diff -Naur bsd-games-2.17/tests/number.-0.1 bsd-games-patch/tests/number.-0.1
|
|
--- bsd-games-2.17/tests/number.-0.1 1970-01-01 07:00:00.000000000 +0700
|
|
+++ bsd-games-patch/tests/number.-0.1 2020-04-17 15:14:27.831098084 +0700
|
|
@@ -1,3 +1,3 @@
|
|
minus
|
|
one.
|
|
-tenths.
|
|
+tenth.
|
|
diff -Naur bsd-games-2.17/tests/number.-0.2 bsd-games-patch/tests/number.-0.2
|
|
--- bsd-games-2.17/tests/number.-0.2 1970-01-01 07:00:00.000000000 +0700
|
|
+++ bsd-games-patch/tests/number.-0.2 2020-04-17 15:20:48.162336279 +0700
|
|
@@ -0,0 +1,3 @@
|
|
+minus
|
|
+two.
|
|
+tenths.
|
|
diff -Naur bsd-games-2.17/tests/number.test bsd-games-patch/tests/number.test
|
|
--- bsd-games-2.17/tests/number.test 1970-01-01 07:00:00.000000000 +0700
|
|
+++ bsd-games-patch/tests/number.test 2020-04-17 15:20:22.774654155 +0700
|
|
@@ -36,6 +36,8 @@
|
|
testno 1
|
|
number/number -- -0.1 >test.out 2>&1 || failtest
|
|
compare test.out tests/number.-0.1
|
|
+number/number -- -0.2 >test.out 2>&1 || failtest
|
|
+compare test.out tests/number.-0.2
|
|
rm -f test.out
|
|
|
|
testno 2
|