summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bin/mtags.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/bin/mtags.c b/bin/mtags.c
index 257adbe7..8f83496c 100644
--- a/bin/mtags.c
+++ b/bin/mtags.c
@@ -24,6 +24,15 @@
 #include <sysexits.h>
 #include <unistd.h>
 
+static void escape(FILE *file, const char *str, size_t len) {
+	for (size_t i = 0; i < len; ++i) {
+		if (str[i] == '\\' || str[i] == '/') {
+			putc('\\', file);
+		}
+		putc(str[i], file);
+	}
+}
+
 int main(int argc, char *argv[]) {
 	bool append = false;
 	const char *path = "tags";
@@ -70,17 +79,14 @@ int main(int argc, char *argv[]) {
 		while (0 < getline(&buf, &cap, file)) {
 			regmatch_t match[2];
 			if (regexec(regex, buf, 2, match, 0)) continue;
-			int n = fprintf(
-				tags, "%.*s\t%s\t/^%.*s/\n",
+			fprintf(
+				tags, "%.*s\t%s\t/^",
 				(int)(match[1].rm_eo - match[1].rm_so), &buf[match[1].rm_so],
-				argv[i],
-				(int)(match[0].rm_eo - match[0].rm_so), &buf[match[0].rm_so]
+				argv[i]
 			);
-			if (n < 0) err(EX_IOERR, "%s", path);
+			escape(tags, buf, match[0].rm_eo);
+			fprintf(tags, "/\n");
 		}
 		fclose(file);
 	}
-
-	error = fclose(tags);
-	if (error) err(EX_IOERR, "%s", path);
 }
8a2fa12349b&follow=1'>Decode entities in titlesJune McEnroe 2019-09-05Print title as soon as it's availableJune McEnroe 2019-09-05Use CURL_PREFIX to set flagsJune McEnroe 2019-09-05Add titleJune McEnroe 2019-09-04Add Avorter n'est pas tuerJune McEnroe 2019-08-29Unset executable on shell scriptsJune McEnroe 2019-08-29Add long-missing setopt to bin.7June McEnroe 2019-08-29Add editJune McEnroe