From e802e19058fa8e3cc07e13623e06f5119e650c19 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Tue, 13 Apr 2004 19:29:54 +0000 Subject: [PATCH] Sempoint OLR patches by Redy --- ChangeLog | 2 ++ lib/msg.c | 69 +++++++++++++++++++++++++++++++++++++---------- lib/msg.h | 1 + mbsebbs/offline.c | 1 + 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index e34be1f1..001ffd48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,8 @@ v0.51.4 11-Apr-2004 mbsebbs: Added loging of virus scanner results. + Patches for offline reader programs that create messages with + wrong line terminaters (Sempoint). mbsetup: Added auto setup for message area creation date. Also creates diff --git a/lib/msg.c b/lib/msg.c index d717f38c..da646875 100644 --- a/lib/msg.c +++ b/lib/msg.c @@ -308,26 +308,14 @@ int Msg_WriteHeader (unsigned long ulMsg) void Msg_Write(FILE *fp) { char *Buf; - int i; Buf = calloc(MAX_LINE_LENGTH +1, sizeof(char)); - while ((fgets(Buf, MAX_LINE_LENGTH, fp)) != NULL) { - - for (i = 0; i < strlen(Buf); i++) { - if (*(Buf + i) == '\0') - break; - if (*(Buf + i) == '\n') - *(Buf + i) = '\0'; - if (*(Buf + i) == '\r') - *(Buf + i) = '\0'; - } - + while ((Fgets(Buf, MAX_LINE_LENGTH, fp)) != NULL) MsgText_Add2(Buf); - } free(Buf); } - + typedef struct { unsigned long Subject; @@ -457,4 +445,57 @@ int Msg_Link(char *Path, int do_quiet, int slow_util) return msg_link; } +/* + * Fgets() is like fgets() but never returns the line terminator + * at end of line and handles that line terminators: + * + * DOS/WINDOWS -> CR/LF + * UNIX -> LF only + * MAC -> CR only + */ +char *Fgets(char *l, int size, FILE *f) { + char *cp = l; + int cr, eol = FALSE; + + if (feof(f)) return NULL; + + cr = FALSE; + while (size>1 && !feof(f)) { + int c = fgetc(f); + if (c == EOF) { + if (ferror(f)) return NULL; + break; + } + if (cr && c != '\n') { + /* CR end-of-line (MAC) */ + ungetc(c,f); + eol = TRUE; + break; + } else + cr = (c=='\r'); + if ( cr ) + continue; + --size; + if (c=='\n') { eol = TRUE; break; } + *(cp++) = c; + } + *cp = '\0'; + + cr = FALSE; + while (!eol && !feof(f)) { + int c = fgetc(f); + if (c == EOF) + break; + if (cr && c != '\n') { + /* CR end-of-line (MAC) */ + ungetc(c,f); + break; + } else + cr = (c=='\r'); + if ( cr ) + continue; + if (c=='\n') break; + } + return l; +} diff --git a/lib/msg.h b/lib/msg.h index 445e15d5..098310eb 100644 --- a/lib/msg.h +++ b/lib/msg.h @@ -114,6 +114,7 @@ char *strlwr(char *); char *strupr(char *); long filelength(int); long tell(int); +char *Fgets(char *, int, FILE *); diff --git a/mbsebbs/offline.c b/mbsebbs/offline.c index e7534996..981586c2 100644 --- a/mbsebbs/offline.c +++ b/mbsebbs/offline.c @@ -1612,6 +1612,7 @@ void BlueWave_Fetch() Syslog('m', " Type : Internet"); else Syslog('m', " Type : Fidonet"); + getfilecase(Dirpath, Upr.filename); Syslog('m', " File : %s", Upr.filename); Syslog('m', " Tag : %s", Upr.echotag);