FreeCalypso > hg > falcon-mail-tools
diff f-demime/main.c @ 4:612c4d0df768
f-demime: rework for unboundedly long lines
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 May 2023 09:02:12 +0000 |
parents | 7e0d08176f32 |
children |
line wrap: on
line diff
--- a/f-demime/main.c Sat May 06 06:41:20 2023 +0000 +++ b/f-demime/main.c Sat May 06 09:02:12 2023 +0000 @@ -15,7 +15,6 @@ #include "defs.h" char *att_filename_buf, *att_filename_base, *att_filename_tail; -unsigned input_lineno; static void get_attachment_dir() @@ -60,7 +59,9 @@ main(argc, argv) char **argv; { - char linebuf[LINE_BUF_SIZE], *cp; + char linebuf[LINE_BUF_SIZE]; + int c, unterm, prev_unterm; + unsigned lineno; if (argc > 3) { fprintf(stderr, "usage: %s [infile [outfile]]\n", argv[0]); @@ -75,25 +76,34 @@ perror(argv[2]); exit(1); } - for (input_lineno = 1; fgets(linebuf, sizeof linebuf, stdin); - input_lineno++) { - cp = index(linebuf, '\n'); - if (cp) { - *cp = '\0'; - if (cp > linebuf && cp[-1] == '\r') - *--cp = '\0'; - } else { - fprintf(stderr, - "f-demime warning: input line %u too long or unterminated\n", - input_lineno); - } - if (!strncmp(linebuf, "From ", 5)) { + lineno = 0; + for (prev_unterm = 0; fgets(linebuf, sizeof linebuf, stdin); + prev_unterm = unterm) { + if (!prev_unterm) + lineno++; + if (index(linebuf, '\n')) + unterm = 0; + else + unterm = 1; + if (!prev_unterm && !strncmp(linebuf, "From ", 5)) { finish_msg_body(); - puts(linebuf); + fputs(linebuf, stdout); + if (unterm) { + fprintf(stderr, + "f-demime warning: From line %u too long or unterminated\n", + lineno); + for (;;) { + c = getchar(); + if (c == EOF || c == '\n') + break; + } + putchar('\n'); + unterm = 0; + } begin_new_message(); continue; } - message_input_line(linebuf); + message_input_line(linebuf, unterm, prev_unterm); } finish_msg_body(); exit(0);