commit 0319176f2df3db63b6ebeec2258bf1eaa7fa7e3d
parent 960a8635bcdc8c01b6e45470e5a3e76c86d62987
Author: Chris Allegretta <chrisa@asty.org>
Date: Sat, 22 Sep 2001 06:38:38 +0000
More Mac file fixes
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@777 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/files.c b/files.c
@@ -125,6 +125,7 @@ filestruct *read_line(char *buf, filestruct * prev, int *line1ins)
strcpy(fileptr->data, buf);
#ifndef NANO_SMALL
+ /* If it's a DOS file (CRLF), strip out the CR part*/
if (buf[strlen(buf) - 1] == '\r') {
fileptr->data[strlen(buf) - 1] = 0;
totsize--;
@@ -184,15 +185,21 @@ int read_file(int fd, char *filename, int quiet)
/* Read the entire file into file struct */
while ((size = read_byte(fd, filename, input)) > 0) {
linetemp = 0;
- if (input[0] == '\n'
-#ifndef NANO_SMALL
- || (ISSET(MAC_FILE) && input[0] == '\r')
-#endif
- ) {
+
+ if (input[0] == '\n') {
fileptr = read_line(buf, fileptr, &line1ins);
num_lines++;
buf[0] = 0;
i = 0;
+#ifndef NANO_SMALL
+ /* If it's a Mac file (no LF just a CR), handle it! */
+ } else if (i > 0 && buf[i-1] == '\r') {
+ fileptr = read_line(buf, fileptr, &line1ins);
+ num_lines++;
+ buf[0] = input[0];
+ buf[1] = 0;
+ i = 1;
+#endif
} else {
/* Now we allocate a bigger buffer 128 characters at a time.
If we allocate a lot of space for one line, we may indeed