Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some sfd can use tabs in places the parser expected spaces #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/amiga/AmigaHunkAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private static DataType getAmigaDataType(String type, FileDataTypeManager fdm) {
type = type.replace("VOLATILE ", "");
if(type.contains("("))
return new PointerDataType(new FunctionDefinitionDataType("FUNC")); // TODO: correct function pointer type
for(var word : type.split(" ")) {
for(var word : type.split("\\s+")) {
if(word.equals("*")) {
dataType = new PointerDataType(dataType);
} else if(word.equals("**")) {
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/fd/FdParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,17 @@ private static FdLibFunctions readFd(File f) throws Exception {

return funcTable;
}


// find the last space or tab, searching from 'startSearchAt'
private static int lastIndexOfSpaceOrTab(String line,int startSearchAt) {
for(int off = Math.min(startSearchAt, line.length() - 1); off >= 0; --off) {
if (line.charAt(off) == ' ' || line.charAt(off) == '\t') {
return off;
}
}
return -1;
}

private static FdLibFunctions readSfd(File f) throws Exception {
FdLibFunctions funcTable = null;
var libname = f.getName();
Expand Down Expand Up @@ -193,7 +203,7 @@ else if(line.startsWith("end", 2))
var paren_reg = line.lastIndexOf('(');
assert paren_arg != -1;
assert paren_reg != -1;
var func_spc = line.lastIndexOf(' ', paren_arg);
var func_spc = lastIndexOfSpaceOrTab(line, paren_arg);
assert func_spc != -1;
var func = new FdFunction(libname, line.substring(func_spc + 1, paren_arg), line.substring(0, func_spc), offset, false);

Expand All @@ -214,7 +224,7 @@ else if(line.startsWith("end", 2))
var next = StringUtils.indexOfAny(line.substring(p_arg), "(),") + p_arg;
assert next >= p_arg && next < paren_reg;
if(line.charAt(next) == ',' || line.charAt(next) == ')') {
var arg_spc = line.lastIndexOf(' ', next);
var arg_spc = lastIndexOfSpaceOrTab(line,next);
assert arg_spc != -1;
if(arg_spc > p_arg) {
type = line.substring(p_arg, arg_spc);
Expand Down Expand Up @@ -245,7 +255,7 @@ else if(line.startsWith("end", 2))
assert line.charAt(func_end + 1) == ',';
p_arg = func_end + 2;
}
if(line.charAt(p_arg) == ' ') p_arg++;
if(line.charAt(p_arg) == ' ' || line.charAt(p_arg) == '\t') p_arg++;
}
//System.out.format("%s returns '%s' = -$%x\n", func.getName(false), func.getReturnType(), Math.abs(func.getBias()));
//for(var arg : func.getArgs())
Expand Down