unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 1acbeff30a58d89d102b4f416772c2656539c9fd 2890 bytes (raw)
name: gnu/packages/patches/bsd-games-number.c.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
 
--- 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


debug log:

solving 1acbeff30a ...
found 1acbeff30a in https://yhetil.org/guix-patches/mI4iG8ZhDza81on0BxLDj7FnB_WzIfzcky6EG-5QYoRJLEPuYAdV4tZfhlts5in5dAa0mhfl6NEaCWIp1L7QrMRzFRBRF3K9vkshTrugYK8=@protonmail.com/ ||
	https://yhetil.org/guix-patches/_PWhYxkw6OfHG67OjoQ_rXEbyw4zBvKV_awdd7pY-rDTnqBXtu_CvLiwr_eyPeF4cmqYRVkKYYfBQH-5ilv10F7igF9d40wsozcOAdLfeVs=@protonmail.com/ ||
	https://yhetil.org/guix-patches/ff2iu2bW1tBFrGN2L7u6kGsUl3_b0Iohk-KEjwDYVftqfTeGuRnUgclM3VEquudkczw_67OLLuUkHG7bknJiV0-b0P64FCAF9zWCK7WO-3w=@protonmail.com/

applying [1/1] https://yhetil.org/guix-patches/mI4iG8ZhDza81on0BxLDj7FnB_WzIfzcky6EG-5QYoRJLEPuYAdV4tZfhlts5in5dAa0mhfl6NEaCWIp1L7QrMRzFRBRF3K9vkshTrugYK8=@protonmail.com/
diff --git a/gnu/packages/patches/bsd-games-number.c.patch b/gnu/packages/patches/bsd-games-number.c.patch
new file mode 100644
index 0000000000..1acbeff30a

1:10: trailing whitespace.
 
1:20: trailing whitespace.
 
1:24: space before tab in indent.
 	char *line;
1:28: space before tab in indent.
 	char *p, *fraction;
1:29: trailing whitespace.
 
Checking patch gnu/packages/patches/bsd-games-number.c.patch...
Applied patch gnu/packages/patches/bsd-games-number.c.patch cleanly.
warning: squelched 76 whitespace errors
warning: 81 lines add whitespace errors.

skipping https://yhetil.org/guix-patches/_PWhYxkw6OfHG67OjoQ_rXEbyw4zBvKV_awdd7pY-rDTnqBXtu_CvLiwr_eyPeF4cmqYRVkKYYfBQH-5ilv10F7igF9d40wsozcOAdLfeVs=@protonmail.com/ for 1acbeff30a
skipping https://yhetil.org/guix-patches/ff2iu2bW1tBFrGN2L7u6kGsUl3_b0Iohk-KEjwDYVftqfTeGuRnUgclM3VEquudkczw_67OLLuUkHG7bknJiV0-b0P64FCAF9zWCK7WO-3w=@protonmail.com/ for 1acbeff30a
index at:
100644 1acbeff30a58d89d102b4f416772c2656539c9fd	gnu/packages/patches/bsd-games-number.c.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).