shithub: neatroff

Download patch

ref: 02a3e714e60e9340e32502bda6bfe3bfe8ff937f
parent: 98888b4b078cf0197416287f3650d9ad3a75acbe
author: Ali Gholami Rudi <[email protected]>
date: Wed Sep 25 15:09:28 EDT 2013

hyph: replace non-alphabetic characters with '.' in hyword()

--- a/hyph.c
+++ b/hyph.c
@@ -88,16 +88,23 @@
 		hyexcept_add(args[i]);
 }
 
-#define HYC_VALID(c)	((c) == '.' || ((c) >= 'a' && (c) <= 'z'))
 #define HYC_MAP(c)	((c) == '.' ? 0 : (c) - 'a' + 1)
 
 static int hyidx(int a, int b)
 {
-	if (!HYC_VALID(a) || !HYC_VALID(b))
-		return 0;
 	return (HYC_MAP(a) << 5) | HYC_MAP(b);
 }
 
+static void hyword(char *d, char *s)
+{
+	int c;
+	*d++ = '.';
+	while ((c = (unsigned char) *s++))
+		*d++ = isalpha(c) ? tolower(c) : '.';
+	*d++ = '.';
+	*d = '\0';
+}
+
 static void hyfind(char *hyph, char *word, int flg)
 {
 	char n[ILNLEN] = {0};
@@ -104,11 +111,8 @@
 	char w[ILNLEN];
 	char *p;
 	int i, j, wlen, plen;
-	w[0] = '.';
-	strcpy_lower(w + 1, word);
-	wlen = strlen(word) + 2;
-	w[wlen - 1] = '.';
-	w[wlen] = '\0';
+	hyword(w, word);
+	wlen = strlen(w);
 	for (i = 0; i < wlen - 1; i++) {
 		p = hyhash[hyidx(w[i], w[i + 1])];
 		while (p) {