about summary refs log tree commit diff stats
path: root/src/chrtrans/makeuctb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/chrtrans/makeuctb.c')
-rw-r--r--src/chrtrans/makeuctb.c53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/chrtrans/makeuctb.c b/src/chrtrans/makeuctb.c
index e0630cc3..ad95c534 100644
--- a/src/chrtrans/makeuctb.c
+++ b/src/chrtrans/makeuctb.c
@@ -256,7 +256,8 @@ PUBLIC int main ARGS2(
 	if ((p = strchr(buffer, '\n')) != NULL) {
 	    *p = '\0';
 	} else {
-	    fprintf(stderr, "%s: Warning: line too long\n", tblname);
+	    fprintf(stderr, "%s: Warning: line too long or incomplete\n",
+		    tblname);
 	}
 
 	/*
@@ -268,11 +269,14 @@ PUBLIC int main ARGS2(
 	 *	<range>		<unicode range>
 	 *      <unicode>	:<replace>
 	 *      <unicode range>	:<replace>
+	 *      <unicode>	"<C replace>"
+	 *      <unicode range>	"<C replace>"
 	 *
 	 *  where <range> ::= <fontpos>-<fontpos>
 	 *  and <unicode> ::= U+<h><h><h><h>
 	 *  and <h> ::= <hexadecimal digit>
 	 *  and <replace> any string not containing '\n' or '\0'
+	 *  and <C replace> any string with C backslash escapes 
 	 */
 	p = buffer;
 	while (*p == ' ' || *p == '\t') {
@@ -405,24 +409,51 @@ PUBLIC int main ARGS2(
 		    p++;
 		}
 	    }
-	    if (*p != ':') {
-		fprintf(stderr, "No ':' where expected: %s\n", buffer);
+
+	    if (*p != ':' && *p != '"') {
+		fprintf(stderr, "No ':' or '\"' where expected: %s\n",
+			buffer);
 		continue;
 	    }
 
-	    tbuf = (char *) malloc (4*strlen(++p) + 1);
+	    tbuf = (char *) malloc (4*strlen(p));
 	    if (!(p1 = tbuf)) {
 		fprintf(stderr, "%s: Out of memory\n", tblname);
 		exit(EX_DATAERR);
 	    }
-	    for (ch = *p; (ch = *p) != '\0'; p++, p1++) {
-		if ((unsigned char)ch < 32 || ch == '\\' || ch == '\"' ||
-		    (unsigned char)ch >= 127) {
-		    sprintf(p1, "\\%.3o", (unsigned char)ch); 
+	    if (*p == '"') {
+		/*
+		 *  handle "<C replace>"
+		 *  Copy chars verbatim until first '"' not \-escaped or
+		 *  end of buffer
+		 */
+		int escaped = 0;
+		for (ch = *++p; (ch = *p) != '\0'; p++) {
+		    if (escaped) {
+			escaped = 0;
+		    } else if (ch == '"') {
+			break;
+		    } else if (ch == '\\') {
+			escaped = 1;
+		    }
+		    *p1++ = ch;
+		}
+		if (escaped || ch != '"') {
+		    fprintf(stderr, "Warning: String not terminated: %s\n",
+			    buffer);
+		    if (escaped)
+			*p1++ = '\n';
+		}
+	    } else {		/* we had ':' */
+		for (ch = *++p; (ch = *p) != '\0'; p++, p1++) {
+		    if ((unsigned char)ch < 32 || ch == '\\' || ch == '\"' ||
+			(unsigned char)ch >= 127) {
+			sprintf(p1, "\\%.3o", (unsigned char)ch); 
 /*		    fprintf(stderr, "%s\n", tbuf); */
-		    p1 += 3;
-		} else {
-		    *p1 = ch;
+			p1 += 3;
+		    } else {
+			*p1 = ch;
+		    }
 		}
 	    }
 	    *p1 = '\0';