mirror of
https://github.com/cc65/cc65.git
synced 2025-01-14 16:33:00 +00:00
Improve handling of files with foreign newline sequences.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3163 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
104f041111
commit
9b2834ef7e
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user