From: cuz Date: Sun, 18 Jul 2004 08:46:12 +0000 (+0000) Subject: Improve handling of files with foreign newline sequences. X-Git-Tag: V2.12.0~670 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9b2834ef7e67b81b894d4c6844e487f3cac04d54;p=cc65 Improve handling of files with foreign newline sequences. git-svn-id: svn://svn.cc65.org/cc65/trunk@3163 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 981b43a68..1b87b78b4 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -466,6 +466,8 @@ static void NextChar (void) /* Check for end of line, read the next line if needed */ while (IFile->Line [IFile->Pos.Col] == '\0') { + unsigned Len, Removed; + /* End of current line reached, read next line */ if (fgets (IFile->Line, sizeof (IFile->Line), IFile->F) == 0) { /* End of file. Add an empty line to the listing. This is a @@ -476,6 +478,22 @@ static void NextChar (void) return; } + /* For better handling of files with unusual line endings (DOS + * files that are accidently translated on Unix for example), + * first remove all whitespace at the end, then add a single + * newline. + */ + Len = strlen (IFile->Line); + Removed = 0; + while (Len > 0 && IsSpace (IFile->Line[Len-1])) { + ++Removed; + --Len; + } + if (Removed) { + IFile->Line[Len+0] = '\n'; + IFile->Line[Len+1] = '\0'; + } + /* One more line */ IFile->Pos.Line++; IFile->Pos.Col = 0;