summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-01-15 15:06:31 -0500
committerJune McEnroe <june@causal.agency>2021-01-15 15:10:23 -0500
commit6c34c92f0c45891db918dffbad9b7b4328269e01 (patch)
tree48ed06d7f3caa1ac643058c518b20cd584211c97
parentOutput htagml -x from the main loop (diff)
downloadsrc-6c34c92f0c45891db918dffbad9b7b4328269e01.tar.gz
src-6c34c92f0c45891db918dffbad9b7b4328269e01.zip
Simplyify htagml match output
-rw-r--r--bin/htagml.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/bin/htagml.c b/bin/htagml.c
index 955a9839..4df40d13 100644
--- a/bin/htagml.c
+++ b/bin/htagml.c
@@ -51,7 +51,7 @@ static size_t escape(bool esc, const char *ptr, size_t len) {
 	return len;
 }
 
-static char *hstrstr(char *haystack, char *needle) {
+static char *hstrstr(const char *haystack, const char *needle) {
 	while (haystack) {
 		char *elem = strchr(haystack, '<');
 		char *match = strstr(haystack, needle);
@@ -169,25 +169,25 @@ int main(int argc, char *argv[]) {
 			continue;
 		}
 
-		char *text = tag->tag;
-		char *match = (pipe ? hstrstr(buf, text) : strstr(buf, text));
+		size_t mlen = strlen(tag->tag);
+		char *match = (pipe ? hstrstr : strstr)(buf, tag->tag);
 		if (!match && tag->tag[0] == 'M') {
-			text = "main";
-			match = (pipe ? hstrstr(buf, text) : strstr(buf, text));
+			mlen = 4;
+			match = (pipe ? hstrstr : strstr)(buf, "main");
 		}
-		if (match) escape(!pipe, buf, match - buf);
+		if (!match) {
+			mlen = strlen(buf) - 1;
+			match = buf;
+		}
+		escape(!pipe, buf, match - buf);
 		printf("<a class=\"tag\" id=\"");
 		escape(true, tag->tag, strlen(tag->tag));
 		printf("\" href=\"#");
 		escape(true, tag->tag, strlen(tag->tag));
 		printf("\">");
-		if (match) {
-			match += escape(!pipe, match, strlen(text));
-		} else {
-			escape(!pipe, buf, strlen(buf));
-		}
+		match += escape(!pipe, match, mlen);
 		printf("</a>");
-		if (match) escape(!pipe, match, strlen(match));
+		escape(!pipe, match, strlen(match));
 	}
 	printf(pre ? "</pre>" : index ? "</ul>\n" : "");
 }
5c931c97810bdbef51b3d171513da98d81&follow=1'>Add The Red Threads of FortuneJune McEnroe 2019-09-28Add The Black Tides of HeavenJune McEnroe 2019-09-27Fail on HTTP failure status in titleJune McEnroe 2019-09-23Add Trail of LightningJune McEnroe 2019-09-22Revert "Enable cookies in title"June McEnroe This reverts commit 3231fe21d3b389448c9a5ca7b4c91fdd25c9e677. 2019-09-20Enable cookies in titleJune McEnroe Perhaps this will make it less suspicious to Google. Who knows. 2019-09-16Use sensitivity aliases in TF2June McEnroe 2019-09-16Add The Just CityJune McEnroe 2019-09-12Only GET the final redirect locationJune McEnroe 2019-09-12Consume entire bodyJune McEnroe Aborting the request and leaving data around may be causing intermittent errors. Just discard the rest of the data. 2019-09-10Add title -v flagJune McEnroe 2019-09-10Use curl error bufferJune McEnroe 2019-09-10Set Accept-Encoding in titleJune McEnroe Because apparently it's fine for servers to respond with Content-Encoding you didn't ask for, and curl won't decode it if you didn't ask for it. 2019-09-08Set title User-AgentJune McEnroe Some things don't like you if you don't send one. 2019-09-07Add -x flag to titleJune McEnroe 2019-09-07Ignore SIGPIPE in relayJune McEnroe Allows restarting consumers safely. 2019-09-07Add A Memory Called EmpireJune McEnroe 2019-09-05Handle lack of Content-TypeJune McEnroe 2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe Oops, didn't see this. 2019-09-05Decode 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