From 10e5dbfbcc8adf413c766582e95c53094f367456 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 6 May 2012 14:27:57 +0200 Subject: [PATCH] raw_read() always fopen("rb") even on windows, always swallow "\r" --- src/frontend/rawfile.c | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/frontend/rawfile.c b/src/frontend/rawfile.c index d13f29e0a..ccb2f52c4 100644 --- a/src/frontend/rawfile.c +++ b/src/frontend/rawfile.c @@ -292,42 +292,11 @@ raw_read(char *name) { FILE *fp, *lastin, *lastout, *lasterr; -#if defined(__MINGW32__) || defined(_MSC_VER) - bool binary = TRUE; -#endif - - if ((fp = fopen(name, "r")) == NULL) { + if ((fp = fopen(name, "rb")) == NULL) { perror(name); } -#if defined(__MINGW32__) || defined(_MSC_VER) - /* Test, whether file really ASCII, otherwise assume binary hvogt 15.3.2000 */ - while (fgets(buf, BSIZE_SP, fp)) { - if (ciprefix("values:", buf)) { - binary = FALSE; - rewind(fp); /* rewind */ - fprintf(cp_err, "\nASCII raw file\n"); - break; - } - else if (ciprefix("binary:", buf)) { - binary = TRUE; - rewind(fp); /* rewind */ - break; - } - } - - if (binary) { - (void) fclose(fp); - if ((fp = fopen(name, "rb")) == NULL) { - perror(name); - return (NULL); - } - fprintf(cp_err, "\nbinary raw file\n"); - } - /*--------------------------------------------------------*/ -#endif - /* Since we call cp_evloop() from here, we have to do this junk. */ lastin = cp_curin; lastout = cp_curout; @@ -339,6 +308,11 @@ raw_read(char *name) { cp_pushcontrol(); while (fgets(buf, BSIZE_SP, fp)) { + r = strchr(buf, '\n'); + if(r && r > buf && r[-1] == '\r') { + r[-1] = '\n'; + r[0] = '\0'; + } /* Figure out what this line is... */ if (ciprefix("title:", buf)) { s = buf;