ResolveHint:
PUBLIC
PROC [hint:
ROPE, contextFileName:
ROPE ←
NIL, searchHack:
BOOL ←
FALSE, tryAll:
BOOL ←
TRUE]
RETURNS [ans: Answer] = {
fullContextName, fullShortName: ROPE;
contextCP, shortCP: FS.ComponentPositions;
wDir: ROPE ← NIL;
isADfFileName, standardExtension: BOOL ← FALSE;
ans ← [NIL, NIL];
IF contextFileName.Length[] # 0
THEN {
[fullContextName, contextCP, ] ← FS.ExpandName[contextFileName];
wDir ← fullContextName.Substr[len: contextCP.base.start];
isADfFileName ← fullContextName.Substr[start: contextCP.ext.start, len: contextCP.ext.length].Equal["df", FALSE];
};
[fullShortName, shortCP, ] ← FS.ExpandName[hint, wDir];
IF OK[ans ← TryFull[fullShortName]] THEN RETURN;
{hadDir: BOOL = HasDir[hint];
hasExtension: BOOL = shortCP.ext.start # shortCP.base.start + shortCP.base.length;
hasVersion: BOOL = shortCP.ver.start # shortCP.ext.start + shortCP.ext.length;
base: ROPE = fullShortName.Substr[start: shortCP.base.start, len: shortCP.base.length];
ext: ROPE = fullShortName.Substr[start: shortCP.ext.start, len: shortCP.ext.length];
extless: ROPE = fullShortName.Substr[len: shortCP.base.start + shortCP.base.length];
shortPart: ROPE = fullShortName.Substr[start: shortCP.base.start];
IF hasExtension
OR hasVersion
OR
NOT tryAll
THEN
NULL
ELSE {
IF verbose THEN MessageWindow.Append[Rope.Cat["Trying source extensions to ", fullShortName], TRUE];
IF OK[ans ← TryExtensions[fullShortName, TEditProfile.sourceExtensions]] THEN RETURN;
};
[ans.fullFileName, ans.searchFor] ← DWIMit[hint, wDir, contextFileName, searchHack, isADfFileName];
IF OK[ans] OR hasVersion OR NOT tryAll THEN RETURN;
IF searchHack
AND hasExtension
THEN {
standardExtension ← RopeList.Memb[TEditProfile.sourceExtensions, ext, FALSE];
IF
NOT standardExtension
THEN {
IF verbose THEN MessageWindow.Append[Rope.Cat["Looking for prog=", extless, ", search=", ext], TRUE];
IF OK[ans ← TryExtensions[extless, TEditProfile.implExtensions]] THEN {ans.searchFor ← ext; RETURN};
};
};
IF (
NOT hadDir)
AND TEditProfile.tryVersionMap
THEN {
IF verbose THEN MessageWindow.Append[Rope.Cat["Trying version maps for ", shortPart], TRUE];
IF OK[ans ← TryVersionMap[shortPart]] THEN NULL
ELSE
IF
NOT hasExtension
THEN {
ans ← TryVersionMapExtensions[base, TEditProfile.sourceExtensions];
}
ELSE
IF
NOT standardExtension
THEN {
IF OK[ans ← TryVersionMapExtensions[base, TEditProfile.implExtensions]] THEN ans.searchFor ← ext;
};
IF verbose THEN MessageWindow.Append[" .", FALSE];
};
}};
TryVersionMap:
PROC [shortName:
ROPE]
RETURNS [ans: Answer] = {
mapList: VersionMap.MapList ~ VersionMapDefaults.GetMapList[$Source];
ranges: VersionMap.RangeList ~ VersionMap.ShortNameToRanges[mapList, shortName];
bestName: ROPE ← NIL;
bestDate: BasicTime.GMT ← BasicTime.nullGMT;
FOR list: VersionMap.RangeList ← ranges, list.rest
UNTIL list=
NIL
DO
range: VersionMap.Range ← list.first;
WHILE range.len # 0
DO
fullName: ROPE;
created: BasicTime.GMT;
[name: fullName, created: created, next: range] ← VersionMap.RangeToEntry[range];
IF bestDate = BasicTime.nullGMT OR BasicTime.Period[from: bestDate, to: created] > 0 THEN {bestDate ← created; bestName ← fullName};
ENDLOOP;
ENDLOOP;
ans ← [bestName, NIL];
};
TryVersionMapExtensions:
PROC [name:
ROPE, extensions: ROPEList]
RETURNS [ans: Answer] = {
base: ROPE ~ name.Concat["."];
FOR list:
LIST
OF
ROPE ← extensions, list.rest
UNTIL list=
NIL
DO
IF OK[ans ← TryVersionMap[base.Concat[list.first]]] THEN RETURN;
ENDLOOP;
ans ← [NIL, NIL];
};