Skip to content

Commit a41c4e2

Browse files
committed
Allows any character inside string constants in the cross-compiler.
This adds a pre-parser stage that splits lines keeping track if there are strings.
1 parent 64ebdf3 commit a41c4e2

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

src/compiler/main.cc

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,53 @@ static bool do_debug = false;
4242

4343
static bool readLine(std::string &r, std::istream &is)
4444
{
45-
int c;
46-
while( -1 != (c = is.get()) )
47-
{
48-
r += char(c);
49-
if( c == '\n' || c == (unsigned char)'\x9b' )
50-
return true;
51-
}
52-
return false;
45+
// Special handling of EOL: We allow Unix / DOS line endings - except inside
46+
// strings, because that would be incompatible with the Atari IDE.
47+
// To properly split lines then, we must pre-parse the content, skipping
48+
// comments and keeping track of the strings.
49+
bool in_string = false;
50+
bool in_comment = false;
51+
bool in_start = true;
52+
while( -1 != is.peek() )
53+
{
54+
char c = is.get();
55+
r += c;
56+
if( in_string )
57+
{
58+
// Inside strings, consume any char except for the '"'
59+
if( c == '\"' )
60+
in_string = false;
61+
continue;
62+
}
63+
// Check for DOS end of line
64+
if( c == '\x0D' && '\x0A' == is.peek() )
65+
{
66+
// Check if next char is 0x0A and replace
67+
c = is.get();
68+
r[r.size()-1] = c;
69+
}
70+
// Check for any end of line
71+
if( c == '\x0A' || c == '\x9B' )
72+
return true;
73+
// Check we are not entering a string or a comment
74+
if( in_start )
75+
{
76+
if( c == '.' || c == '\'' )
77+
in_comment = true;
78+
if( c != ' ' )
79+
in_start = false;
80+
}
81+
if( !in_comment )
82+
{
83+
if( c == '\'' )
84+
in_comment = true;
85+
else if( c == ':' )
86+
in_start = true;
87+
else if( c == '\"' )
88+
in_string = true;
89+
}
90+
}
91+
return false;
5392
}
5493

5594
static int show_version()
@@ -105,7 +144,7 @@ int main(int argc, char **argv)
105144
return show_error("invalid option '" + arg + "', try -h for help");
106145
else if( !ifile.is_open() )
107146
{
108-
ifile.open(arg);
147+
ifile.open(arg, std::ios::binary);
109148
if( !ifile.is_open() )
110149
return show_error("can't open input file '" + arg + "'");
111150
iname = arg;

0 commit comments

Comments
 (0)