From 0c5e25abd8d5511aa476cc6af0bbc3d9dcc15695 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 2 Mar 2018 17:26:15 -0500 Subject: Take filter patterns in glitch --- bin/glitch.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'bin') diff --git a/bin/glitch.c b/bin/glitch.c index 8ce3905d..37d93a70 100644 --- a/bin/glitch.c +++ b/bin/glitch.c @@ -265,10 +265,10 @@ enum PACKED Filter { static struct { bool brokenPaeth; - bool forceDeclareFilter; - bool forceApplyFilter; - enum Filter declareFilter; - enum Filter applyFilter; + uint8_t declareFilter; + uint8_t applyFilter; + enum Filter declareFilters[255]; + enum Filter applyFilters[255]; } options; struct Bytes { @@ -366,14 +366,15 @@ static void filterData(void) { if (heuristic[type] < heuristic[minType]) minType = type; } - if (options.forceDeclareFilter) { - lines[y]->type = options.declareFilter; + if (options.declareFilter) { + lines[y]->type = options.declareFilters[y % options.declareFilter]; } else { lines[y]->type = minType; } - if (options.forceApplyFilter) { - memcpy(lines[y]->data, filter[options.applyFilter], lineSize()); + if (options.applyFilter) { + enum Filter type = options.applyFilters[y % options.applyFilter]; + memcpy(lines[y]->data, filter[type], lineSize()); } else { memcpy(lines[y]->data, filter[minType], lineSize()); } @@ -421,7 +422,7 @@ static void glitch(const char *inPath, const char *outPath) { if (error) err(EX_IOERR, "%s", path); } -enum Filter parseFilter(const char *s) { +static enum Filter parseFilter(const char *s) { switch (s[0]) { case 'N': case 'n': return NONE; case 'S': case 's': return SUB; @@ -432,6 +433,15 @@ enum Filter parseFilter(const char *s) { } } +static uint8_t parseFilters(enum Filter *filters, const char *s) { + uint8_t len = 0; + do { + filters[len++] = parseFilter(s); + s = strchr(s, ','); + } while (s++); + return len; +} + int main(int argc, char *argv[]) { bool stdio = false; char *output = NULL; @@ -440,13 +450,11 @@ int main(int argc, char *argv[]) { while (0 < (opt = getopt(argc, argv, "a:cd:o:p"))) { switch (opt) { case 'a': { - options.forceApplyFilter = true; - options.applyFilter = parseFilter(optarg); + options.applyFilter = parseFilters(options.applyFilters, optarg); } break; case 'c': stdio = true; break; case 'd': { - options.forceDeclareFilter = true; - options.declareFilter = parseFilter(optarg); + options.declareFilter = parseFilters(options.declareFilters, optarg); } break; case 'o': output = optarg; break; case 'p': options.brokenPaeth = true; break; -- cgit 1.4.1 id=398cca0404d3ba80f6299d2b9ddfe50e5940487f&follow=1'>Link with -lmJune McEnroe 2018-04-26Add UtopioidJune McEnroe>June McEnroe 2019-11-08Check that password is hashedJune McEnroe 2019-11-08Avoid calling getopt_long again after it returns -1June McEnroe On GNU, calling getopt_long again will reset optind back to the first non-option argument, which would cause an infinite loop of reading the same configurtion file forever. 2019-11-08Only change AWAY status for registered clientsJune McEnroe Turns out I did eventually fix this, because I may want to implement "passive clients" for logging or notification stuff, which wouldn't affect AWAY status either. 2019-11-07Just write the example normallyJune McEnroe 2019-11-07Include path in readlinkat errorJune McEnroe 2019-11-07Call clientConsume before clientRecvJune McEnroe This might reduce the frequency of a client getting its own message back because it was behind in the ring when it sent it. 2019-11-06Use -l:filename in Linux.mkJune McEnroe 2019-11-06Fix compat.h for #defined strlcpyJune McEnroe 2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe 2019-11-06Document calico service configurationJune McEnroe 2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe