diff options
author | Aaron Ball <nullspoon@iohq.net> | 2015-12-09 00:58:07 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@iohq.net> | 2015-12-09 00:58:07 -0700 |
commit | dcea407aae6b03681705742acf38cf5697e7529c (patch) | |
tree | a298494fc72bf6fd336b9c45f83caa5856ed73e8 | |
download | mutt-outlook-compat-dcea407aae6b03681705742acf38cf5697e7529c.tar.gz mutt-outlook-compat-dcea407aae6b03681705742acf38cf5697e7529c.tar.xz |
Initial commit
Currently spaces to consecutive QUOTE_CHAR's that start a line.
Quote char and line buffer size are customizable via the Makefil.
Tested with mutt display_filter successfully.
-rw-r--r-- | Makefile | 26 | ||||
-rw-r--r-- | src/main.c | 56 |
2 files changed, 82 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f239f85 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +out = outlook-fix +warn = -Wall -Wpedantic +cc = cc +std = c99 + +# +# Variables +# + +# Maximum line char count. Lines longer than this will be truncated, so make +# sure this is a sane size. +LINE_BUF_SIZE = -D LINE_BUF_SIZE=1024 + +# The quote indent character. Typically is '>'. +# This must have the two single quotes. Very unsafe if these aren't here. +QUOTE_CHAR = -D QUOTE_CHAR="'>'" + +# Build the cflags +CFLAGS = $(QUOTE_CHAR) $(LINE_BUF_SIZE) + + +all: + $(cc) $(warn) -std=$(std) $(dbg) $(CFLAGS) src/main.c -o $(out) + +debug: + make all dbg='-g' diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..b3f7d69 --- /dev/null +++ b/src/main.c @@ -0,0 +1,56 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifndef LINE_BUF_SIZE + #define LINE_BUF_SIZE 1024 +#endif + +#ifndef QUOTE_CHAR + #define QUOTE_CHAR '>' +#endif + + +void fix_line(char* out, char* line) { + int cursor; + int fixcursor; + + // Initialize + out[0] = '\0'; + + // Reset the cursors + cursor = 0; + fixcursor = 0; + + // One char at a time... + while(line[cursor] != '\0') { + if(line[cursor] != QUOTE_CHAR) { + // As soon as we stop finding > chars, copy the rest and break; + strcpy(&out[fixcursor], &line[cursor]); + break; + } else { + out[fixcursor] = QUOTE_CHAR; + // If the next char isn't a space, insert one. + // We don't want double-stacked spaces in case someone did format + // something correctly. + if(line[cursor + 1] != ' ') { + fixcursor++; + out[fixcursor] = ' '; + } + } + cursor++; + fixcursor++; + } +} + + +int main(int argc, char* argv[]) { + char buf[LINE_BUF_SIZE]; + char fixbuf[LINE_BUF_SIZE]; + + while(fgets(buf, LINE_BUF_SIZE, stdin) != NULL) { + fix_line(fixbuf, buf); + printf("%s", fixbuf); + } + return 0; +} |