list: VersionMap.MapAndNameList ~ VersionMap.ShortNameToNames[mapList, fileName];
FOR p: VersionMap.MapAndNameList ¬ list, p.rest
UNTIL p=
NIL
DO
remoteFileName: ROPE ~ p.first.name;
fullFName, toFName, package, result, dfFile, src: ROPE ¬ NIL;
cp: FS.ComponentPositions;
shortFileName: ROPE;
[fullFName, cp] ¬ FS.ExpandName[remoteFileName];
IF cp.subDirs.length # 0
THEN
-- check for new style pseudoServer
package ¬ Rope.Substr[fullFName, cp.subDirs.start, cp.subDirs.length]
ELSE package ¬ Rope.Substr[fullFName, cp.dir.start, cp.dir.length];
shortFileName ¬
Rope.Substr[fullFName, cp.base.start, cp.base.length + cp.ext.length + 1];
the + 1 is for the . between the base and the extension
IF log # NIL THEN log.PutF["\nfullFName: %g, package: %g, prefix: %g, shortFileName: %g\n",
[rope[fullFName]], [rope[package]], [rope[prefix]], [rope[shortFileName]] ];
IF package.Equal[self,
FALSE]
THEN
--ain't this clever?-- {
IF log # NIL THEN log.PutF["I won't import %g from its own package (%g)\n", IO.rope[fileName], IO.rope[package]];
EXIT;
};
attach or copy the remote filename
src ¬ IF highest THEN fullFName.Substr[len: cp.ext.start+cp.ext.length] ELSE remoteFileName;
IF log #
NIL
THEN {
log.PutRope[src];
log.PutRope[" --> "];
};
toFName ¬ FS.Copy[from: src, to: shortFileName, remoteCheck: FALSE, attach: attach
! FS.Error => { result ¬ error.explanation; CONTINUE }];
IF log #
NIL
THEN {
log.PutRope[toFName];
log.PutRope[result];
log.PutRope["\n"];
};
IF NOT result.IsEmpty THEN LOOP; -- avoid attaching df file when failed to attach mob
IF imports #
NIL
THEN {
determine DF file from package directory name from the convention [Cedar10.1]<Package>Interface.mob
notFound: BOOL ¬ FALSE;
server: ROPE ¬ Rope.Substr[fullFName, cp.server.start, cp.server.length];
dfFile ¬ IO.PutFR["[%g]<Top>%g.df", [rope[server]], [rope[package]] ];
IF log # NIL THEN log.PutF["\ndfFile: %g\n", [rope[dfFile]] ];
[] ¬
FS.Copy[from: dfFile, to: Rope.Concat[package, ".df"], remoteCheck:
TRUE, attach: attach
!
FS.Error => {
notFound ¬ error.code = $unknownFile;
result ¬ error.explanation;
CONTINUE}];
IF notFound
THEN {
result ¬ NIL;
dfFile ¬ IO.PutFR["[%g]<Top>%g-PCR.df", [rope[server]], [rope[package]] ];
[] ¬ FS.Copy[from: dfFile, to: Rope.Concat[package, "-PCR.df"], attach: attach
! FS.Error => { result ¬ error.explanation; CONTINUE }];
};
IF result.IsEmpty
THEN {
EnsureFileImport[imports, dfFile, fileName];
EXIT;
}
ELSE IF log = NIL THEN NULL
ELSE {
log.PutF["DF file name guess %g for %g failed (%g)\n", IO.rope[dfFile], IO.rope[fileName], IO.rope[result]];
};
}
ELSE EXIT;
REPEAT
FINISHED => gotIt ¬ FALSE;
ENDLOOP;