shithub: neatroff

Download patch

ref: 7d4b995df2c1de9fd13d81b6048b4e8da4ccd7df
parent: 01ab075930d390e24321c78cac95930d0a618dd5
author: Ali Gholami Rudi <[email protected]>
date: Sat Jul 5 14:50:43 EDT 2014

hyph: read hcode mappings from the third argument of .hpf

The .hpf and .hpfa requests read the hyphenation character mappings
from the address specified as their third arguments.  Now the three
arguments of these requests correspond to files whose names end
with .pat.txt, .hyp.txt and .chr.txt in
ftp://ftp.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/txt/

--- a/hyph.c
+++ b/hyph.c
@@ -172,22 +172,25 @@
 	d[di] = '\0';
 }
 
+void hcode_add(char *c1, char *c2)
+{
+	int i = dict_get(&hcodedict, c1);
+	if (i >= 0) {
+		strcpy(hcodedst[i], c2);
+	} else if (hcode_n < NHCODES) {
+		strcpy(hcodesrc[hcode_n], c1);
+		strcpy(hcodedst[hcode_n], c2);
+		dict_put(&hcodedict, hcodesrc[hcode_n], hcode_n);
+		hcode_n++;
+	}
+}
+
 void tr_hcode(char **args)
 {
 	char c1[GNLEN], c2[GNLEN];
 	char *s = args[1];
-	int i;
-	while (s && charread(&s, c1) >= 0 && charread(&s, c2) >= 0) {
-		i = dict_get(&hcodedict, c1);
-		if (i >= 0) {
-			strcpy(hcodedst[i], c2);
-		} else if (hcode_n < NHCODES) {
-			strcpy(hcodesrc[hcode_n], c1);
-			strcpy(hcodedst[hcode_n], c2);
-			dict_put(&hcodedict, hcodesrc[hcode_n], hcode_n);
-			hcode_n++;
-		}
-	}
+	while (s && utf8read(&s, c1) && utf8read(&s, c2))
+		hcode_add(c1, c2);
 }
 
 static void hyph_readpatterns(char *s)
@@ -233,7 +236,7 @@
 
 void tr_hpfa(char **args)
 {
-	char tok[ILNLEN];
+	char tok[ILNLEN], c1[ILNLEN], c2[ILNLEN];
 	FILE *filp;
 	hyinit = 1;
 	/* load english hyphenation patterns with no arguments */
@@ -242,8 +245,7 @@
 		hyph_readexceptions(en_exceptions);
 	}
 	/* reading patterns */
-	if (args[1]) {
-		filp = fopen(args[1], "r");
+	if (args[1] && (filp = fopen(args[1], "r"))) {
 		while (fscanf(filp, "%s", tok) == 1)
 			if (strlen(tok) < WORDLEN)
 				hy_add(tok);
@@ -250,13 +252,21 @@
 		fclose(filp);
 	}
 	/* reading exceptions */
-	if (args[2]) {
-		filp = fopen(args[2], "r");
+	if (args[2] && (filp = fopen(args[2], "r"))) {
 		while (fscanf(filp, "%s", tok) == 1)
 			if (strlen(tok) < WORDLEN)
 				hw_add(tok);
 		fclose(filp);
 	}
+	/* reading hcode mappings */
+	if (args[3] && (filp = fopen(args[3], "r"))) {
+		while (fscanf(filp, "%s", tok) == 1) {
+			char *s = tok;
+			if (utf8read(&s, c1) && utf8read(&s, c2))
+				hcode_add(c2, c1);	/* inverting */
+		}
+		fclose(filp);
+	}
 }
 
 void hyph_init(void)
@@ -276,6 +286,9 @@
 	hwword_len = 0;
 	hw_n = 0;
 	dict_done(&hwdict);
+	/* reseting hcode mappings */
+	hcode_n = 0;
+	dict_done(&hcodedict);
 	/* reading */
 	hyph_init();
 	tr_hpfa(args);