commit 951b7e77f8adb0ba41e51c3bf8222bf6cf5890dd Author: Oswald Buddenhagen <o...@users.sf.net> Date: Sat Nov 5 18:32:49 2016 +0100
factor out copy_msg_bytes() src/sync.c | 64 ++++++++++++++++++++++++++-------------------------- 1 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/sync.c b/src/sync.c index a8eaee4..37bb94e 100644 --- a/src/sync.c +++ b/src/sync.c @@ -302,6 +302,36 @@ copy_msg( copy_vars_t *vars ) static void msg_stored( int sts, int uid, void *aux ); static void +copy_msg_bytes( char **out_ptr, const char *in_buf, int *in_idx, int in_len, int in_cr, int out_cr ) +{ + char *out = *out_ptr; + int idx = *in_idx; + if (out_cr != in_cr) { + char c; + if (out_cr) { + for (; idx < in_len; idx++) { + if ((c = in_buf[idx]) != '\r') { + if (c == '\n') + *out++ = '\r'; + *out++ = c; + } + } + } else { + for (; idx < in_len; idx++) { + if ((c = in_buf[idx]) != '\r') + *out++ = c; + } + } + } else { + memcpy( out, in_buf + idx, in_len - idx ); + out += in_len - idx; + idx = in_len; + } + *out_ptr = out; + *in_idx = idx; +} + +static void msg_fetched( int sts, void *aux ) { copy_vars_t *vars = (copy_vars_t *)aux; @@ -376,23 +406,7 @@ msg_fetched( int sts, void *aux ) buf = vars->data.data = nfmalloc( vars->data.len ); i = 0; if (vars->srec) { - if (tcr != scr) { - if (tcr) { - for (; i < sbreak; i++) - if ((c = fmap[i]) != '\r') { - if (c == '\n') - *buf++ = '\r'; - *buf++ = c; - } - } else { - for (; i < sbreak; i++) - if ((c = fmap[i]) != '\r') - *buf++ = c; - } - } else { - memcpy( buf, fmap, sbreak ); - buf += sbreak; - } + copy_msg_bytes( &buf, fmap, &i, sbreak, scr, tcr ); memcpy( buf, "X-TUID: ", 8 ); buf += 8; @@ -403,21 +417,7 @@ msg_fetched( int sts, void *aux ) *buf++ = '\n'; i = ebreak; } - if (tcr != scr) { - if (tcr) { - for (; i < len; i++) - if ((c = fmap[i]) != '\r') { - if (c == '\n') - *buf++ = '\r'; - *buf++ = c; - } - } else { - for (; i < len; i++) - if ((c = fmap[i]) != '\r') - *buf++ = c; - } - } else - memcpy( buf, fmap + i, len - i ); + copy_msg_bytes( &buf, fmap, &i, len, scr, tcr ); free( fmap ); } ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ isync-devel mailing list isync-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/isync-devel