From ca984be73bdba8c9e807aa56be6403a7b790ed21 Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Mon, 26 Nov 2018 01:02:53 +0100 Subject: [PATCH] add raw option to mhl raw allows to output a header as in the input, no changes are done by mhl. This is written for whatnow2. whatnow2 shall safe some data in the draft and use mhl with ignore to remove this data. Also other tools can use mhl to filter some header fields out of a message without changing the message itself. --- uip/mhl.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/uip/mhl.c b/uip/mhl.c index 76d2335..fa83602 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -78,7 +78,8 @@ char *version=VERSION; #define SPLIT 0x001000 /* split headers (don't concatenate) */ #define NONEWLINE 0x002000 /* don't write trailing newline */ #define RTRIM 0x004000 /* trim trailing whitespace */ -#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07LEFTADJUST\010COMPRESS\011ADDRFMT\012DATEFMT\013FORMAT\014INIT\015SPLIT\016NONEWLINE\017RTRIM" +#define RAW 0x008000 /* print the raw input */ +#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07LEFTADJUST\010COMPRESS\011ADDRFMT\012DATEFMT\013FORMAT\014INIT\015SPLIT\016NONEWLINE\017RTRIM\020RAW" #define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT) struct mcomp { @@ -139,21 +140,22 @@ struct triple { static struct triple triples[] = { { "nocomponent", NOCOMPONENT, 0 }, - { "uppercase", UPPERCASE, 0 }, + { "uppercase", UPPERCASE, RAW }, { "nouppercase", 0, UPPERCASE }, - { "center", CENTER, 0 }, + { "center", CENTER, RAW }, { "nocenter", 0, CENTER }, - { "leftadjust", LEFTADJUST, 0 }, + { "leftadjust", LEFTADJUST, RAW }, { "noleftadjust", 0, LEFTADJUST }, - { "compress", COMPRESS, 0 }, + { "compress", COMPRESS, RAW }, { "nocompress", 0, COMPRESS }, { "split", SPLIT, 0 }, { "nosplit", 0, SPLIT }, - { "rtrim", RTRIM, 0 }, + { "rtrim", RTRIM, RAW }, { "nortrim", 0, RTRIM }, - { "addrfield", ADDRFMT, DATEFMT }, - { "datefield", DATEFMT, ADDRFMT }, - { "newline", 0, NONEWLINE }, + { "raw", RAW|SPLIT|NOCOMPONENT|NONEWLINE, UPPERCASE|CENTER|LEFTADJUST|COMPRESS|DATEFMT|ADDRFMT }, + { "addrfield", ADDRFMT, DATEFMT|RAW }, + { "datefield", DATEFMT, ADDRFMT|RAW }, + { "newline", 0, NONEWLINE|RAW }, { "nonewline", NONEWLINE, 0 }, { NULL, 0, 0 } }; @@ -909,7 +911,6 @@ free_queue(struct mcomp **head, struct mcomp **tail) *head = *tail = NULL; } - static void putcomp(struct mcomp *c1, struct mcomp *c2, int flag) { @@ -936,6 +937,23 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag) return; } + if (c1->c_flags & RAW) { + switch (flag) { + case ONECOMP: + printf("%s:%s", c1->c_name, c1->c_text); + break; + case TWOCOMP: + printf("%s:%s", c2->c_name, c2->c_text); + break; + case BODYCOMP: + fputs(c2->c_text, stdout); + break; + default: + adios(EX_SOFTWARE, NULL, "BUG: putcomp() is called with a unknown flag"); + } + return; + } + if (c1->c_fstr && (c1->c_flags & (ADDRFMT | DATEFMT | FORMAT))) mcomp_format(c1, c2); @@ -1032,7 +1050,6 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag) c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */ } - static char * oneline(char *stuff, long flags) { @@ -1082,7 +1099,6 @@ oneline(char *stuff, long flags) return ret; } - static void putstr(char *string) { -- 1.7.10.4