@@ -42,14 +42,53 @@ static bool do_debug = false;
42
42
43
43
static bool readLine (std::string &r, std::istream &is)
44
44
{
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 ;
53
92
}
54
93
55
94
static int show_version ()
@@ -105,7 +144,7 @@ int main(int argc, char **argv)
105
144
return show_error (" invalid option '" + arg + " ', try -h for help" );
106
145
else if ( !ifile.is_open () )
107
146
{
108
- ifile.open (arg);
147
+ ifile.open (arg, std::ios::binary );
109
148
if ( !ifile.is_open () )
110
149
return show_error (" can't open input file '" + arg + " '" );
111
150
iname = arg;
0 commit comments