IMPORTS
BlackCherry, DFS, Icons, IO, RefText, Rope, UFS
Initial PCedar version
localStreamOptions:
UFS.StreamOptions ¬ [
tiogaRead: FALSE,
truncatePagesOnClose: FALSE,
closeUFSOpenFileOnClose: TRUE
];
UFSFullName:
PROC [ fileName:
ROPE, wDir:
ROPE ¬
NIL ]
RETURNS [ fullName:
ROPE ] ~ {
BEGIN
ENABLE
UFS.Error => {
Report["\n***UFS.Error: %g\n", [rope[error.explanation]] ];
IF error.code = $illegalName THEN GOTO tryAgain ELSE GOTO Bogus
};
fullName ¬ UFS.ExpandName[fileName, wDir].fullUName;
EXITS
Bogus => { ERROR BadName };
tryAgain => NULL;
END;
try getting rid of spaces and tabs in the name
BEGIN
BEGIN
ENABLE
UFS.Error => { Report["\n***UFS.Error: %g\n",
[rope[error.explanation]] ];
GOTO Bogus2 };
temp: REF TEXT ¬ RefText.ObtainScratch[RefText.line];
temp.length ¬ 0;
FOR i:
INT
IN [0..fileName.Length[])
DO
c: CHAR ~ fileName.Fetch[i];
IF (c = ' ) OR ( c = '\t ) THEN LOOP;
[] ¬ RefText.AppendChar[temp, c];
ENDLOOP;
fileName ¬ Rope.FromRefText[temp];
RefText.ReleaseScratch[temp];
fullName ¬ UFS.ExpandName[fileName, wDir].fullUName;
EXITS
Bogus2 => { ERROR BadName };
END;
END;
};
UFSFileOpenOrCreate:
PROC [ name:
ROPE, how:
ATOM ]
RETURNS [ fileData: BCFileData] ~ {
fileData ¬ NEW[BCFileDataRec ¬ [name: name] ];
Report["%g of %g\n", [atom[how]], [rope[name]] ];
IF how = $create
THEN {
fileData.writeStream ¬ UFS.StreamOpen[fileData.name, $create, UFS.binaryStreamOptions ];
fileData.writeStream.Close[];
};
fileData.writeStream ¬ UFS.StreamOpen[fileData.name, $write, UFS.binaryStreamOptions ];
fileData.readStream ¬ fileData.writeStream;
};
UFSSetByteCount:
PROC [ fileData: BCFileData, bytes:
INT ] ~ {
fileData.writeStream ¬ UFS.StreamOpen[fileData.name, $write, UFS.binaryStreamOptions ];
fileData.writeStream.SetLength[bytes];
fileData.writeStream.Close[];
fileData.writeStream ¬ NIL;
};
UFSIconSetter:
PROC[iconFileName:
ROPE] = {
BlackCherry.msgSetIcon ¬ Icons.NewIconFromFile[iconFileName, 1
! DFS.Error => { GOTO notFound }];
BlackCherry.msgIcon ¬ Icons.NewIconFromFile[iconFileName, 2];
};
Init:
PROC = {
procs: BlackCherry.FileProcs ¬
NEW[BlackCherry.FileProcsRec ¬ [
fullName: UFSFullName,
openOrCreate: UFSFileOpenOrCreate,
setByteCount: UFSSetByteCount,
iconSetter: UFSIconSetter
] ];
BlackCherry.RegisterFileProcs[procs];
};
Init[];