shithub: neatpost

Download patch

ref: 5b1f9c9a899c04f7531a9a47baf008c8db68fd15
parent: f8ee2bb9d6ad4bb0e43de1bdf2c68a900c9a6366
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Oct 26 05:47:13 EDT 2017

out: support quoted strings for eps file names and link destinations

--- a/out.c
+++ b/out.c
@@ -255,6 +255,27 @@
 	outrel(h1, v1);
 }
 
+static char *strcut(char *dst, char *src)
+{
+	while (*src == ' ' || *src == '\n')
+		src++;
+	if (src[0] == '"') {
+		src++;
+		while (*src && (src[0] != '"' || src[1] == '"')) {
+			if (*src == '"')
+				src++;
+			*dst++ = *src++;
+		}
+		if (*src == '"')
+			src++;
+	} else {
+		while (*src && *src != ' ' && *src != '\n')
+			*dst++ = *src++;
+	}
+	*dst = '\0';
+	return src;
+}
+
 void outeps(char *spec)
 {
 	char eps[1 << 12];
@@ -263,11 +284,12 @@
 	int hwid, vwid;
 	FILE *filp;
 	int nspec, nbb;
-	if ((nspec = sscanf(spec, "%s %d %d", eps, &hwid, &vwid)) < 1)
+	spec = strcut(eps, spec);
+	if (!eps[0] || (nspec = sscanf(spec, "%d %d", &hwid, &vwid)) < 0)
 		return;
-	if (nspec < 2)
+	if (nspec < 1)
 		hwid = 0;
-	if (nspec < 3)
+	if (nspec < 2)
 		vwid = 0;
 	if (!(filp = fopen(eps, "r")))
 		return;
@@ -312,7 +334,8 @@
 	char lnk[1 << 12];
 	int hwid, vwid;
 	int nspec;
-	if ((nspec = sscanf(spec, "%s %d %d", lnk, &hwid, &vwid)) != 3)
+	spec = strcut(lnk, spec);
+	if (!lnk[0] || (nspec = sscanf(spec, "%d %d", &hwid, &vwid)) != 2)
 		return;
 	o_flush();
 	if (isdigit((unsigned char) lnk[0])) {