mirror of
https://github.com/cc65/cc65.git
synced 2024-12-26 08:32:00 +00:00
Merge pull request #2078 from bbbradsmith/line-endings
ca65 support for three line ending types: \r, \r\n, \n
This commit is contained in:
commit
83ff62d5e2
@ -112,6 +112,7 @@ struct CharSource {
|
|||||||
CharSource* Next; /* Linked list of char sources */
|
CharSource* Next; /* Linked list of char sources */
|
||||||
token_t Tok; /* Last token */
|
token_t Tok; /* Last token */
|
||||||
int C; /* Last character */
|
int C; /* Last character */
|
||||||
|
int SkipN; /* For '\r\n' line endings, skip '\n\ if next */
|
||||||
const CharSourceFunctions* Func; /* Pointer to function table */
|
const CharSourceFunctions* Func; /* Pointer to function table */
|
||||||
union {
|
union {
|
||||||
InputFile File; /* File data */
|
InputFile File; /* File data */
|
||||||
@ -325,6 +326,7 @@ static void UseCharSource (CharSource* S)
|
|||||||
Source = S;
|
Source = S;
|
||||||
|
|
||||||
/* Read the first character from the new file */
|
/* Read the first character from the new file */
|
||||||
|
S->SkipN = 0;
|
||||||
S->Func->NextChar (S);
|
S->Func->NextChar (S);
|
||||||
|
|
||||||
/* Setup the next token so it will be skipped on the next call to
|
/* Setup the next token so it will be skipped on the next call to
|
||||||
@ -386,6 +388,11 @@ static void IFNextChar (CharSource* S)
|
|||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
int N = fgetc (S->V.File.F);
|
int N = fgetc (S->V.File.F);
|
||||||
|
if (N == '\n' && S->SkipN) {
|
||||||
|
N = fgetc (S->V.File.F);
|
||||||
|
}
|
||||||
|
S->SkipN = 0;
|
||||||
|
|
||||||
if (N == EOF) {
|
if (N == EOF) {
|
||||||
/* End of file. Accept files without a newline at the end */
|
/* End of file. Accept files without a newline at the end */
|
||||||
if (SB_NotEmpty (&S->V.File.Line)) {
|
if (SB_NotEmpty (&S->V.File.Line)) {
|
||||||
@ -401,9 +408,12 @@ static void IFNextChar (CharSource* S)
|
|||||||
|
|
||||||
/* Check for end of line */
|
/* Check for end of line */
|
||||||
} else if (N == '\n') {
|
} else if (N == '\n') {
|
||||||
|
|
||||||
/* End of line */
|
/* End of line */
|
||||||
break;
|
break;
|
||||||
|
} else if (N == '\r') {
|
||||||
|
/* End of line, skip '\n' if it's the next character */
|
||||||
|
S->SkipN = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
/* Collect other stuff */
|
/* Collect other stuff */
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user