From 3dfd663c98d1f7586e95ce5d82a92c9059ab46c1 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 21 Dec 2019 07:41:14 -0500 Subject: Clean up mboxrd code --- imbox.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'imbox.c') 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 1.4.1 a2ab4a&follow=1'>root/home/.shrc (unfollow)
Commit message (Expand)Author
2021-09-23Allow FocusEvents in xtermJune McEnroe
2021-09-23Use NI_NUMERICSERVJune McEnroe
2021-09-23Make up build away from FreeBSDJune McEnroe
2021-09-23Add quickJune McEnroe
2021-09-23Add The HobbitJune McEnroe
2021-09-22Remove PSF fontsJune McEnroe
2021-09-22Remove Linux-specific utilitiesJune McEnroe
2021-09-22Call sandbox in CGI modeJune McEnroe
2021-09-22Support HTTP PUT in upJune McEnroe
2021-09-22Remove default faviconJune McEnroe
2021-09-21Use Z_FILTERED strategyJune McEnroe
2021-09-21Recalculate various lengths only as neededJune McEnroe
2021-09-21Rewrite pngo, add explicit optionsJune McEnroe
2021-09-16Fix /* **/ comment matchingJune McEnroe
2021-09-15Remove typer, add downgrade to READMEJune McEnroe
2021-09-15Set bot mode on downgradeJune McEnroe
2021-09-15Enter capsicum in downgradeJune McEnroe
2021-09-15Factor out common parts of downgrade messagesJune McEnroe
2021-09-14Add downgrade IRC botJune McEnroe
2021-09-14Sort by title if authors matchJune McEnroe
2021-09-13Swap-remove tags as they're foundJune McEnroe
2021-09-12Replace htagml regex with strncmpJune McEnroe
2021-09-11Also defer printing comment for lone close-parensJune McEnroe
2021-09-10Publish "git-comment"June McEnroe
2021-09-10Add git comment --pretty optionJune McEnroe
2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe
2021-09-08Up default min-repeat to 30 linesJune McEnroe
2021-09-08Handle dirty lines in git-commentJune McEnroe
2021-09-08Document and install git-commentJune McEnroe
2021-09-08Add repeat and all options to git-commentJune McEnroe
2021-09-08Add group threshold to git-commentJune McEnroe