about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-21 07:41:14 -0500
committerJune McEnroe <june@causal.agency>2019-12-21 07:41:14 -0500
commit3dfd663c98d1f7586e95ce5d82a92c9059ab46c1 (patch)
tree0d36393b132264e38a8c2ea2d895feaf95807a32
parentConvert CRLF to LF (diff)
downloadimbox-3dfd663c98d1f7586e95ce5d82a92c9059ab46c1.tar.gz
imbox-3dfd663c98d1f7586e95ce5d82a92c9059ab46c1.zip
Clean up mboxrd code
-rw-r--r--imbox.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/imbox.c b/imbox.c
index 22bb36a..5ab23c1 100644
--- a/imbox.c
+++ b/imbox.c
@@ -55,35 +55,34 @@ static void printLines(const char *lines) {
 }
 
 static void mboxrd(const char *headers, const char *body) {
-	static regex_t fromRegex;
-	compile(&fromRegex, "^From: .*<([^>]+)>");
+#define MATCH(str, match) \
+	(int)((match).rm_eo - (match).rm_so), &(str)[(match).rm_so]
+	static regex_t fromRegex, dateRegex;
 
+	compile(&fromRegex, "^From: .*<([^>]+)>");
 	regmatch_t from[2];
 	int error = regexec(&fromRegex, headers, 2, from, 0);
 	if (error) errx(EX_DATAERR, "missing From header");
-	printf(
-		"From %.*s ",
-		(int)(from[1].rm_eo - from[1].rm_so), &headers[from[1].rm_so]
-	);
+	printf("From %.*s ", MATCH(headers, from[1]));
 
-	static regex_t dateRegex;
+	// Day, Date Month Year Time -> Day Month Date Time Year
 	compile(&dateRegex, "^Date: (...), (..) (...) (....) (.{8})");
-
 	regmatch_t date[6];
 	error = regexec(&dateRegex, headers, 6, date, 0);
 	if (error) errx(EX_DATAERR, "missing Date header");
 	printf(
 		"%.*s %.*s %.*s %.*s %.*s\n",
-		(int)(date[1].rm_eo - date[1].rm_so), &headers[date[1].rm_so],
-		(int)(date[3].rm_eo - date[3].rm_so), &headers[date[3].rm_so],
-		(int)(date[2].rm_eo - date[2].rm_so), &headers[date[2].rm_so],
-		(int)(date[5].rm_eo - date[5].rm_so), &headers[date[5].rm_so],
-		(int)(date[4].rm_eo - date[4].rm_so), &headers[date[4].rm_so]
+		MATCH(headers, date[1]),
+		MATCH(headers, date[3]),
+		MATCH(headers, date[2]),
+		MATCH(headers, date[5]),
+		MATCH(headers, date[4])
 	);
 
 	printLines(headers);
 	printLines(body);
 	printf("\n");
+#undef MATCH
 }
 
 static bool verbose;
'/cgit-pink/commit/ui-shared.c?h=1.4.0&id=a45030f8ee10bc97ffcf1bf0061a2e6f22c7252a&follow=1'>ui-shared: URL-escape script_nameJohn Keeping 2014-01-12ui-refs: escape HTML chars in author and tagger namesJohn Keeping 2014-01-12filter: pass extra arguments via cgit_open_filterJohn Keeping 2014-01-12ui-snapshot: set unused cgit_filter fields to zeroJohn Keeping 2014-01-12html: remove redundant htmlfd variableJohn Keeping 2014-01-12tests: add Valgrind supportJohn Keeping 2014-01-12cache: don't leave cache_slot fields uninitializedJohn Keeping 2014-01-10filter: split filter functions into their own fileJason A. Donenfeld 2014-01-10filter: make exit status localJason A. Donenfeld 2014-01-10parsing: fix header typoJason A. Donenfeld 2014-01-10cgit.c: Fix comment on bit mask hackLukas Fleischer 2014-01-10cgit.c: Use "else" for mutually exclusive branchesLukas Fleischer 2014-01-10ui-snapshot.c: Do not reinvent suffixcmp()Lukas Fleischer 2014-01-10Refactor cgit_parse_snapshots_mask()Lukas Fleischer 2014-01-10Disallow use of undocumented snapshot delimitersLukas Fleischer 2014-01-10Replace most uses of strncmp() with prefixcmp()Lukas Fleischer 2014-01-09README: Fix dependenciesLukas Fleischer 2014-01-08README: Spelling and formatting fixesLukas Fleischer 2014-01-08Fix UTF-8 with syntax-highlighting.pyPřemysl Janouch 2014-01-08Add a suggestion to the manpagePřemysl Janouch 2014-01-08Fix the example configurationPřemysl Janouch 2014-01-08Fix about-formatting.shPřemysl Janouch 2014-01-08Fix some spelling errorsPřemysl Janouch 2014-01-08filters: highlight.sh: add css comments for highlight 2.6 and 3.8Ferry Huberts