summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-03-24 18:13:06 -0400
committerJune McEnroe <june@causal.agency>2022-03-24 18:13:06 -0400
commitc41288c7056752f2b25afa5790ae68abf2b3bc88 (patch)
tree24f3890f7fb3377333f04fb172ae7309ba2369a6 /bin
parentAdd The Invisible Life of Addie LaRue (diff)
downloadsrc-c41288c7056752f2b25afa5790ae68abf2b3bc88.tar.gz
src-c41288c7056752f2b25afa5790ae68abf2b3bc88.zip
Skip matches with ident chars on either side
This fixes, for example, where the link gets placed on

    static regex_t regex(const char *pattern, int flags)

in title.c.
Diffstat (limited to '')
-rw-r--r--bin/htagml.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/bin/htagml.c b/bin/htagml.c
index 033f717a..1f547be6 100644
--- a/bin/htagml.c
+++ b/bin/htagml.c
@@ -77,6 +77,10 @@ static char *hstrstr(const char *haystack, const char *needle) {
 	return NULL;
 }
 
+static int isident(int c) {
+	return isalnum(c) || c == '_';
+}
+
 int main(int argc, char *argv[]) {
 	bool pre = false;
 	bool pipe = false;
@@ -190,7 +194,10 @@ int main(int argc, char *argv[]) {
 
 		size_t mlen = strlen(tag);
 		char *match = (pipe ? hstrstr : strstr)(buf, tag);
-		while (match > buf && isalnum(match[-1])) {
+		while (
+			match &&
+			((match > buf && isident(match[-1])) || isident(match[mlen]))
+		) {
 			match = (pipe ? hstrstr : strstr)(&match[mlen], tag);
 		}
 		if (!match && tag[0] == 'M') {