Comments should no longer be able to break overlay parser.
This commit is contained in:
parent
f1031351ed
commit
a6cee7f529
2 changed files with 23 additions and 5 deletions
|
@ -23,6 +23,11 @@
|
||||||
|
|
||||||
#define SEGMENT_TEST
|
#define SEGMENT_TEST
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Breaking things { with comments!
|
||||||
|
*/
|
||||||
|
|
||||||
void test(int arg1, int arg2) {
|
void test(int arg1, int arg2) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,8 @@ void parseCFile(char *filename, char *targetFile, FILE *trampoline, char *trampo
|
||||||
char *b;
|
char *b;
|
||||||
bool found;
|
bool found;
|
||||||
int x;
|
int x;
|
||||||
|
int comments = 0;
|
||||||
|
bool inComment = false;
|
||||||
int brackets = 0;
|
int brackets = 0;
|
||||||
int crSinceStart = 0;
|
int crSinceStart = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
@ -93,7 +95,6 @@ void parseCFile(char *filename, char *targetFile, FILE *trampoline, char *trampo
|
||||||
*
|
*
|
||||||
* - It only handles C, not C++.
|
* - It only handles C, not C++.
|
||||||
* - It can only handle single-line function definitions with the opening '{' on the same line as the function.
|
* - It can only handle single-line function definitions with the opening '{' on the same line as the function.
|
||||||
* - It can be borked by comments.
|
|
||||||
* - It always generates trampolines, not just when they're needed.
|
* - It always generates trampolines, not just when they're needed.
|
||||||
*
|
*
|
||||||
* Someone should fix it. :-)
|
* Someone should fix it. :-)
|
||||||
|
@ -124,16 +125,28 @@ void parseCFile(char *filename, char *targetFile, FILE *trampoline, char *trampo
|
||||||
// Read next byte from C input file.
|
// Read next byte from C input file.
|
||||||
if ((c = fgetc(in)) == EOF) break;
|
if ((c = fgetc(in)) == EOF) break;
|
||||||
|
|
||||||
|
// Look for '//' comments.
|
||||||
|
if ((c == '/') && (pos > 0) && (buffer[pos-1] == '/')) inComment = true;
|
||||||
|
|
||||||
|
// Look for '/*' comment start.
|
||||||
|
if ((c == '*') && (pos > 0) && (buffer[pos-1] == '/')) comments++;
|
||||||
|
|
||||||
|
// Look for '*/' comment end.
|
||||||
|
if ((c == '/') && (pos > 0) && (buffer[pos-1] == '*')) comments--;
|
||||||
|
|
||||||
// Count brackets so we know if we're inside a function or not.
|
// Count brackets so we know if we're inside a function or not.
|
||||||
|
if ((!inComment) && (comments == 0)) {
|
||||||
if (c == '{') {
|
if (c == '{') {
|
||||||
brackets++;
|
brackets++;
|
||||||
crSinceStart = 0;
|
crSinceStart = 0;
|
||||||
}
|
}
|
||||||
if (c == '}') brackets--;
|
if (c == '}') brackets--;
|
||||||
|
}
|
||||||
|
|
||||||
// End of line?
|
// End of line?
|
||||||
if ((c == 13) || (c == 10)) {
|
if ((c == 13) || (c == 10)) {
|
||||||
|
|
||||||
|
inComment = false;
|
||||||
crSinceStart++;
|
crSinceStart++;
|
||||||
|
|
||||||
// End the line and trim the tail.
|
// End the line and trim the tail.
|
||||||
|
|
Loading…
Add table
Reference in a new issue