Created
January 23, 2015 17:26
-
-
Save headius/a78c68145e2f8c739b1e to your computer and use it in GitHub Desktop.
Nearly-finished port of search_required from MRI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MRI: search_required | |
protected char searchRequired(String fname, String[] path) { | |
String tmp; | |
int extOffset; | |
String ext, ftptr; | |
char type, ft = 0; | |
String[] loadingP; | |
path[0] = null; | |
extOffset = (ftptr = fname).lastIndexOf('.'); | |
ext = extOffset == -1 ? null : ftptr.substring(extOffset); | |
if (ext != null) { | |
if (ext.equals(".rb")) { | |
if (isFeatureLoaded(ftptr, ext, true, false, loadingP) != 0) { | |
if (loadingP != null) path[0] = loadingP[0]; | |
return 'r'; | |
} | |
if ((tmp = findFileSafe(fname)) != null) { | |
extOffset = (ftptr = tmp).lastIndexOf('.'); | |
ext = extOffset == -1 ? null : ftptr.substring(extOffset); | |
if (isFeatureLoaded(ftptr, ext, true, true, loadingP) == 0 || loadingP[0] != null) | |
path[0] = tmp; | |
return 'r'; | |
} | |
return 0; | |
} | |
else if (ext.equals(".jar")) { | |
if (isFeatureLoaded(ftptr, ext, false, false, loadingP) != 0) { | |
if (loadingP[0] != null) path[0] = loadingP[0]; | |
return 's'; | |
} | |
tmp = fname.substring(0, extOffset); | |
tmp = tmp + ".jar"; | |
if ((tmp = findFileSafe(tmp)) != null) { | |
extOffset = (ftptr = tmp).lastIndexOf('.'); | |
ext = extOffset == -1 ? null : ftptr.substring(extOffset); | |
if (isFeatureLoaded(ftptr, ext, false, true, loadingP) == 0 || loadingP[0] != null) | |
path[0] = tmp; | |
return 's'; | |
} | |
} | |
else if (ext.equals(".jar")) { | |
if (isFeatureLoaded(ftptr, ext, false, false, loadingP) != 0) { | |
if (loadingP[0] != null) path[0] = loadingP[0]; | |
return 's'; | |
} | |
if ((tmp = findFileSafe(fname)) != null) { | |
extOffset = (ftptr = tmp).lastIndexOf('.'); | |
ext = extOffset == -1 ? null : ftptr.substring(extOffset); | |
if (isFeatureLoaded(ftptr, ext, false, true, loadingP) == 0 || loadingP[0] != null) | |
path[0] = tmp; | |
return 's'; | |
} | |
} | |
} | |
else if ((ft = isFeatureLoaded(ftptr, null, false, false, loadingP)) == 'r') { | |
if (loadingP[0] != null) path[0] = loadingP[0]; | |
return 'r'; | |
} | |
String[] tmpP = {fname}; | |
type = findFileExtSafe(tmpP, loadable_ext); | |
switch (type) { | |
case 0: | |
if (ft != 0) | |
goto statically_linked; | |
ftptr = tmp; | |
return isFeatureLoaded(ftptr, null, false, true, null); | |
default: | |
if (ft != 0) { | |
statically_linked: | |
if (loadingP[0] != null) path[0] = loadingP[0]; | |
return ft; | |
} | |
case 1: | |
extOffset = (ftptr = tmp).lastIndexOf('.'); | |
ext = extOffset == -1 ? null : ftptr.substring(extOffset); | |
if (isFeatureLoaded(ftptr, ext, (--type) == 0, true, loadingP) != 0 && loadingP[0] == null) | |
break; | |
path[0] = tmp; | |
} | |
if (true) { | |
return type != 0 ? 's' : 'r'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment