MispFileSets:
CEDAR
PROGRAM
IMPORTS FileSets, IO, Misp, MoreFileSets, Rope, Tempus, VersionMapDefaults
={OPEN FileSets, MoreFileSets;
RefTime: TYPE = Misp.RefTime;
idsKey: ATOM ← $FileSetsIdentificationScheme;
GetIDS:
PROC [env: Misp.Environment, stack: Misp.Stack]
RETURNS [ids: IdentificationScheme] = {
r: REF ANY ← NIL;
r ← Misp.Eval[idsKey, env, stack !Misp.Error => CONTINUE];
IF r #
NIL
THEN ids ←
WITH r
SELECT
FROM
rids: REF IdentificationScheme => rids^,
ENDCASE => ERROR
ELSE ERROR;
};
EvalFSEnum:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme ← GetIDS[environment, stack];
pattern: ROPE ← NARROW[args.first];
cooked ← FromFS[pattern, ids];
};
EvalVMShortEnum:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme = GetIDS[environment, stack];
pattern: ROPE = NARROW[args.first];
which: ATOM = IF args.rest # NIL THEN NARROW[args.rest.first] ELSE NIL;
vml: VersionMap.MapList = VersionMapDefaults.GetMapList[which];
cooked ← FromVersionMapsByShortName[vml, pattern, ids];
};
EvalVMCreateEnum:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme = GetIDS[environment, stack];
from: RefTime = NARROW[args.first];
to: RefTime = NARROW[args.rest.first];
which: ATOM = IF args.rest.rest # NIL THEN NARROW[args.rest.rest.first] ELSE NIL;
vml: VersionMap.MapList = VersionMapDefaults.GetMapList[which];
cooked ← FromVersionMapsByCreateDate[vml, [from.t, to.t], ids];
};
EvalDFEnum:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme ← GetIDS[environment, stack];
dfs: FileSet ← NIL;
filter: DFUtilities.Filter ← [filterC: defining];
dfw: DFWhich ← remote;
FOR dl:
LORA ← args, dl.rest
WHILE dl #
NIL
DO
WITH dl.first
SELECT
FROM
a:
ATOM =>
SELECT a
FROM
$source => filter.filterA ← source;
$derived => filter.filterA ← derived;
$sourceAndDerived => filter.filterA ← all;
$public => filter.filterB ← public;
$private => filter.filterB ← private;
$publicAndPrivate => filter.filterB ← all;
$defining => filter.filterC ← defining;
$imported => filter.filterC ← imported;
$definingAndImported => filter.filterC ← all;
$remote => dfw ← remote;
$local => dfw ← local;
ENDCASE => SIGNAL Warning[IO.PutFR["Non-understood DF atom %g", IO.atom[a]]];
ul:
REF DFUtilities.UsingList => {
IF filter.list # NIL THEN SIGNAL Warning[IO.PutFR["DF list %g contains more than one using list", IO.refAny[args]]];
filter.list ← ul;
};
r:
ROPE => {
pattern: ROPE ← IF r.Find["!"] < 0 THEN r.Cat["!H"] ELSE r;
these: FileSet ← FromFS[pattern, ids];
dfs ← IF dfs = NIL THEN these ELSE Union[LIST[dfs, these]];
};
fs: FileSet => dfs ← IF dfs = NIL THEN fs ELSE Union[LIST[dfs, fs]];
ENDCASE => SIGNAL Warning[IO.PutFR["Non-understood DF thing %g", IO.refAny[dl.first]]];
ENDLOOP;
IF dfs = NIL THEN SIGNAL Warning["No DF files specified"];
cooked ← FromDFs[dfs, filter, dfw, ids];
};
EvalUsing:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
n, i: NAT ← 0;
ul: REF DFUtilities.UsingList;
FOR nl:
LORA ← args, nl.rest
WHILE nl #
NIL
DO
n ← n + 1;
ENDLOOP;
ul ← NEW [DFUtilities.UsingList[n]];
FOR nl:
LORA ← args, nl.rest
WHILE nl #
NIL
DO
ul[i] ← [FALSE, NARROW[nl.first]];
i ← i + 1;
ENDLOOP;
IF (ul.nEntries ← i) # n THEN ERROR;
cooked ← ul;
};
EvalArchiveEnum:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme ← GetIDS[environment, stack];
which: ArchiveWhich ← SELECT data FROM $archive => archive, $online => online, ENDCASE => ERROR;
dateRope: ROPE ← NARROW[args.first];
date: GMT ← Tempus.Parse[dateRope].time;
cooked ← FromArchiveMsg[date, which, ids];
};
EvalArchived:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme ← GetIDS[environment, stack];
fs: FileSet ← NIL;
FOR args ← args, args.rest
WHILE args #
NIL
DO
fileName: ROPE ← NARROW[args.first];
this: FileSet ← FromArchivist[pattern: fileName, ids: ids];
fs ← IF fs = NIL THEN this ELSE Union[LIST[fs, this]];
ENDLOOP;
cooked ← fs;
};
EvalFSFromFile:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme ← GetIDS[environment, stack];
fs: FileSet ← NIL;
FOR args ← args, args.rest
WHILE args #
NIL
DO
fileName: ROPE ← NARROW[args.first];
this: FileSet ← FromFile[fileName, ids];
fs ← IF fs = NIL THEN this ELSE Union[LIST[fs, this]];
ENDLOOP;
cooked ← fs;
};
EvalFSFromROPE:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme ← GetIDS[environment, stack];
fs: FileSet ← NIL;
FOR args ← args, args.rest
WHILE args #
NIL
DO
list: ROPE ← NARROW[args.first];
this: FileSet ← FromRope[list, ids];
fs ← IF fs = NIL THEN this ELSE Union[LIST[fs, this]];
ENDLOOP;
cooked ← fs;
};
FSLAppend:
PROC [oldHead, oldTail: FileSetList, fs: FileSet]
RETURNS [newHead, newTail: FileSetList] = {
this: FileSetList = LIST[fs];
newHead ← oldHead;
IF oldTail # NIL THEN oldTail.rest ← this ELSE newHead ← this;
newTail ← this;
};
Op: TYPE = PROC [fsl: FileSetList, fr: FileRelation ← NIL] RETURNS [fs: FileSet];
EvalOp:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
opr: REF Op ← NARROW[data];
head, tail: FileSetList ← NIL;
FOR rest:
LORA ← args, rest.rest
WHILE rest #
NIL
DO
sub: FileSet ← NARROW[rest.first];
[head, tail] ← FSLAppend[head, tail, sub];
ENDLOOP;
cooked ← opr[head];
};
EvalRealify:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
cooked ← Realify[NARROW[args.first]];
};
EvalFilter:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
mispFilter: Misp.Closure ← NARROW[args.first];
subject: FileSet ← NARROW[args.rest.first];
EvalMispFilter:
PROC [fn: FileNote, data:
REF
ANY]
RETURNS [
BOOL] =
{RETURN [Misp.ApplyFn[mispFilter, LIST[fn], environment, stack] # NIL]};
filter: Filter;
TRUSTED {filter ← NEW [FilterRep ← [EvalMispFilter, NIL]]};
cooked ← FilterFileSet[subject, filter];
};
EvalEnumFileSet:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme ← GetIDS[environment, stack];
fs: FileSet ← NARROW[args.first];
consumer: Misp.Closure ← NARROW[args.rest.first];
PerFile:
PROC [fn: FileNote] = {
[] ← Misp.ApplyFn[consumer, LIST[fn], environment, stack];
};
EnumSet[fs, PerFile];
cooked ← fs;
};
EvalFNID:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
fn: FileNote ← NARROW[args.first];
cooked ← LIST[fn.id.name, NewTime[fn.id.created]]};
EvalFNName:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
fn: FileNote ← NARROW[args.first];
cooked ← fn.fsName};
EvalFNCreated:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
fn: FileNote ← NARROW[args.first];
cooked ← NewTime[GetCreated[fn]]};
NewTime:
PROC [time: BasicTime.
GMT]
RETURNS [rt: RefTime] =
{rt ← NEW [Misp.TimeRec ← [time]]};
EvalFNRead:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
fn: FileNote ← NARROW[args.first];
cooked ← NewTime[GetAccounting[fn].read]};
EvalIDS:
PROC [args:
LORA, environment: Misp.Environment, data:
REF
ANY ←
NIL, stack: Misp.Stack]
RETURNS [cooked:
REF
ANY]
--Misp.EvalProc-- = {
ids: IdentificationScheme ← [];
FOR args ← args, args.rest
WHILE args #
NIL
DO
a: ATOM ← NARROW[args.first];
SELECT a
FROM
$withServer => ids.server ← TRUE;
$withoutServer => ids.server ← FALSE;
$withDirectory => ids.directory ← TRUE;
$withoutDirectory => ids.directory ← FALSE;
$withVersion => ids.version ← TRUE;
$withoutVersion => ids.version ← FALSE;
$withCreate => ids.create ← TRUE;
$withoutCreate => ids.create ← FALSE;
$askFS => ids.askFS ← TRUE;
ENDCASE => ERROR;
ENDLOOP;
cooked ← NEW [IdentificationScheme ← ids];
};
DefineMisps:
PROC [env: Misp.Environment] = {
Misp.Defun[env, $filesMatching, EvalFSEnum];
Misp.Defun[env, $versionMapFilesMatching, EvalVMShortEnum];
Misp.Defun[env, $versionMapFilesCreated, EvalVMCreateEnum];
Misp.Defun[env, $dfContents, EvalDFEnum];
Misp.Defun[env, $dfContentsq, EvalDFEnum, FALSE];
Misp.Defun[env, $using, EvalUsing];
Misp.Defun[env, $archive, EvalArchiveEnum, TRUE, $archive];
Misp.Defun[env, $online, EvalArchiveEnum, TRUE, $online];
Misp.Defun[env, $archived, EvalArchived];
Misp.Defun[env, $fsFromFile, EvalFSFromFile];
Misp.Defun[env, $fsFromROPE, EvalFSFromROPE];
Misp.Defun[env, $fsUnion, EvalOp, TRUE, NEW [Op ← Union]];
Misp.Defun[env, $fsDiff, EvalOp, TRUE, NEW [Op ← Difference]];
Misp.Defun[env, $fsSDiff, EvalOp, TRUE, NEW [Op ← SymmetricDifference]];
Misp.Defun[env, $fsIntersection, EvalOp, TRUE, NEW [Op ← Intersection]];
Misp.Defun[env, $fsRealify, EvalRealify];
Misp.Defun[env, $fsFilter, EvalFilter];
Misp.Defun[env, $enumFileSet, EvalEnumFileSet];
Misp.Defun[env, $fnID, EvalFNID];
Misp.Defun[env, $fnName, EvalFNName];
Misp.Defun[env, $fnCreated, EvalFNCreated];
Misp.Defun[env, $fnRead, EvalFNRead];
Misp.Defun[env, $consIDS, EvalIDS];
Misp.Defun[env, $consIDSq, EvalIDS, FALSE];
};
Start:
PROC = {
Misp.RegisterPrimitiveDefiner[DefineMisps];
};
Start[];
}.