diff options
Diffstat (limited to 'src/mime.c')
-rw-r--r-- | src/mime.c | 28 |
1 files changed, 13 insertions, 15 deletions
@@ -619,28 +619,27 @@ static int mime_global_qpwrp(lua_State *L) | |||
619 | * end of line markers each, but \r\n, \n\r etc will only issue *one* | 619 | * end of line markers each, but \r\n, \n\r etc will only issue *one* |
620 | * marker. This covers Mac OS, Mac OS X, VMS, Unix and DOS, as well as | 620 | * marker. This covers Mac OS, Mac OS X, VMS, Unix and DOS, as well as |
621 | * probably other more obscure conventions. | 621 | * probably other more obscure conventions. |
622 | * | ||
623 | * c is the current character being processed | ||
624 | * last is the previous character | ||
622 | \*-------------------------------------------------------------------------*/ | 625 | \*-------------------------------------------------------------------------*/ |
623 | #define eolcandidate(c) (c == CR || c == LF) | 626 | #define eolcandidate(c) (c == CR || c == LF) |
624 | static size_t eolprocess(int c, int ctx, const char *marker, | 627 | static int eolprocess(int c, int last, const char *marker, |
625 | luaL_Buffer *buffer) | 628 | luaL_Buffer *buffer) |
626 | { | 629 | { |
627 | if (eolcandidate(ctx)) { | 630 | if (eolcandidate(c)) { |
628 | luaL_addstring(buffer, marker); | 631 | if (eolcandidate(last)) { |
629 | if (eolcandidate(c)) { | 632 | if (c == last) luaL_addstring(buffer, marker); |
630 | if (c == ctx) | ||
631 | luaL_addstring(buffer, marker); | ||
632 | return 0; | 633 | return 0; |
633 | } else { | 634 | } else { |
634 | luaL_putchar(buffer, c); | 635 | luaL_addstring(buffer, marker); |
635 | return 0; | 636 | return c; |
636 | } | 637 | } |
637 | } else { | 638 | } else { |
638 | if (!eolcandidate(c)) { | 639 | luaL_putchar(buffer, c); |
639 | luaL_putchar(buffer, c); | 640 | return 0; |
640 | return 0; | ||
641 | } else | ||
642 | return c; | ||
643 | } | 641 | } |
642 | |||
644 | } | 643 | } |
645 | 644 | ||
646 | /*-------------------------------------------------------------------------*\ | 645 | /*-------------------------------------------------------------------------*\ |
@@ -661,8 +660,7 @@ static int mime_global_eol(lua_State *L) | |||
661 | luaL_buffinit(L, &buffer); | 660 | luaL_buffinit(L, &buffer); |
662 | /* if the last character was a candidate, we output a new line */ | 661 | /* if the last character was a candidate, we output a new line */ |
663 | if (!input) { | 662 | if (!input) { |
664 | if (eolcandidate(ctx)) lua_pushstring(L, marker); | 663 | lua_pushnil(L); |
665 | else lua_pushnil(L); | ||
666 | lua_pushnumber(L, 0); | 664 | lua_pushnumber(L, 0); |
667 | return 2; | 665 | return 2; |
668 | } | 666 | } |