<<>> <> <> <> <> <> <> <> DIRECTORY Basics USING [IsBound], BasicTime USING [GetClockPulses], Commander USING [CommandObject, Handle], CommandTool USING [CurrentWorkingDirectory, Install], Convert USING [RopeFromTime], FS, Icons USING [IconFlavor, NewIconFromFile], IO USING [card, Close, GetChar, noInputStream, PutChar, PutF, PutFR, rope, STREAM, Value], List USING [AList, Assoc, PutAssoc], MakeDo, MakeDoPrivate, MakeDoPorting USING [logPath], MessageWindow USING [Append, Blink], ProcessProps USING [AddPropList, GetPropList], RefTab, Rope, SymTab, UserProfile USING [CallWhenProfileChanges, ProfileChangeReason, Token]; MakeDoAuxImpl: CEDAR MONITOR IMPORTS Basics, BasicTime, CommandTool, Convert, FS, Icons, IO, List, MakeDo, MakeDoPrivate, MakeDoPorting, MessageWindow, ProcessProps, RefTab, Rope, SymTab, UserProfile EXPORTS MakeDo, MakeDoPrivate <> <> <> = BEGIN OPEN MakeDo, MakeDoPrivate; RefTableE: TYPE = MakeDo.RefTable; ROPE: TYPE = Rope.ROPE; NodeRep: PUBLIC TYPE = MakeDoPrivate.NodeRep; ActionRep: PUBLIC TYPE = MakeDoPrivate.ActionRep; NodeClassRep: PUBLIC TYPE = MakeDoPrivate.NodeClassRep; Warning: PUBLIC SIGNAL [message: ROPE] = CODE; debugging: PUBLIC BOOL _ FALSE; leafClass: ActionClass _ NEW [ActionClassRep _ []]; leaf: PUBLIC Action _ NEW [ActionRep _ [cmd: "-- leaf", class: leafClass]]; nodes: SymTab.Ref _ SymTab.Create[case: FALSE]; installationDirectory: ROPE = CommandTool.CurrentWorkingDirectory[]; defaultIconFileShortName: ROPE = "MakeDo-MTV.icons"; iconsFileName: ROPE _ NIL; icons: PUBLIC IconSeq; LoadIcons: PROC [fileName: ROPE] RETURNS [icons: IconSeq] = { nIcons: NAT _ 0; flavors: LIST OF Icons.IconFlavor _ NIL; FOR nIcons _ 0, nIcons+1 DO flavor: Icons.IconFlavor = Icons.NewIconFromFile[fileName, nIcons]; IF flavor = unInit THEN EXIT; flavors _ CONS[flavor, flavors]; ENDLOOP; icons _ NEW [IconSeqPrivate[nIcons]]; FOR i: NAT DECREASING IN [0 .. icons.length) DO icons[i] _ flavors.first; flavors _ flavors.rest; ENDLOOP; IF flavors # NIL THEN ERROR; }; DoInWDir: PROC [wDirRope: ROPE, inner: PROC] ~ { propList: List.AList ~ List.PutAssoc[key: wDirKey, val: wDirRope, aList: NIL]; ProcessProps.AddPropList[propList: propList, inner: inner]; }; wDirKey: ATOM ~ $WorkingDirectory; NoteProfile: PROC [reason: UserProfile.ProfileChangeReason] --UserProfile.ProfileChangedProc-- = { proFileName: ROPE = UserProfile.Token["MakeDo.IconFile", defaultIconFileShortName]; Try: PROC [short: ROPE] RETURNS [ok: BOOL _ TRUE] ~ { TryInWDir: PROC ~ { icons _ LoadIcons[short !FS.Error => { ok _ FALSE; MessageWindow.Append[Rope.Cat["Problem loading MakeDo icons from ", short], TRUE]; MessageWindow.Blink[]; CONTINUE}]; IF ok THEN iconsFileName _ short; RETURN}; IF short.Equal[iconsFileName, FALSE] THEN RETURN; DoInWDir[installationDirectory, TryInWDir]; RETURN}; IF Basics.IsBound[MessageWindow.Append] THEN IF NOT (Try[proFileName] OR Try[defaultIconFileShortName]) THEN { icons _ NEW [IconSeqPrivate[1]]; icons[0] _ tool; iconsFileName _ NIL; }; }; GetNode: PUBLIC ENTRY PROC [someName: ROPE, class: NodeClass, mayAdd: BOOL _ TRUE] RETURNS [node: Node] = { ENABLE UNWIND => NULL; canonicalName: ROPE _ IF class # NIL THEN class.CanonizeName[someName] ELSE someName; IF (node _ NARROW[nodes.Fetch[canonicalName].val]) = NIL AND mayAdd THEN { node _ NEW [NodeRep _ [given: someName, name: canonicalName, class: class, memberships: MakeRefTable[]]]; StartTime[node]; IF NOT nodes.Insert[canonicalName, node] THEN ERROR; } ELSE IF node = NIL THEN NULL ELSE IF class # node.class THEN ERROR; }; EnumerateAndDestroy: PUBLIC ENTRY PROC [to: PROC [Node], andDestroy--table when done--: BOOL] = { ENABLE UNWIND => {}; PerNode: PROC [key, val: REF ANY] RETURNS [stop: BOOL _ FALSE] --RefTab.EachPairAction-- = { n: Node = NARROW[val]; to[n]; RETURN [FALSE]}; IF nodes.Pairs[PerNode] THEN ERROR; IF andDestroy THEN nodes.Erase[]; }; IncrementStepCount: PUBLIC ENTRY PROC [job: Job] = { ENABLE UNWIND => {}; job.nSteps _ job.nSteps + 1; }; AddFailedCmd: PUBLIC ENTRY PROC [job: Job, a: Action] = { ENABLE UNWIND => {}; job.failedSteps _ CONS[a, job.failedSteps]; }; MakeRefTable: PUBLIC PROC RETURNS [table: RefTable] = {table _ RefTab.Create[]}; AddToRefTable: PUBLIC PROC [ra: REF ANY, t: RefTable] = {IF NOT t.Insert[ra, $T] THEN ERROR; RETURN}; EnsureRefInTable: PUBLIC PROC [ra: REF ANY, t: RefTable] = { [] _ t.Insert[ra, $T]; RETURN}; DeleteFromRefTable: PUBLIC PROC [ra: REF ANY, t: RefTable] RETURNS [found: BOOL] = { found _ t.Delete[ra]; RETURN}; RefInTable: PUBLIC PROC [ra: REF ANY, t: RefTable] RETURNS [BOOL] = { RETURN [t.Fetch[ra].found]}; MDInstall: PUBLIC PROC [dir, packageName: ROPE] RETURNS [foundFile, failed: BOOL _ TRUE] ~ { log: IO.STREAM ~ FS.StreamOpen[fileName: Rope.Cat[MakeDoPorting.logPath, packageName, ".InstallLog"], accessOptions: create, keep: 10]; searchRules: REF ANY _ List.Assoc[$SearchRules, GetCommanderHandle[].propertyList]; processProps: List.AList ~ List.PutAssoc[$WorkingDirectory, dir, NIL]; cmd: Commander.Handle ~ NEW [Commander.CommandObject _ [ in: IO.noInputStream, out: log, err: log, commandLine: NIL, propertyList: List.PutAssoc[$SearchRules, searchRules, NIL] ]]; Doit: PROC ~ {[foundFile, failed] _ CommandTool.Install[packageName, cmd]; RETURN}; ProcessProps.AddPropList[processProps, Doit]; log.Close[]; RETURN}; chKey: ATOM _ $CommanderHandle; GetCommanderHandle: PUBLIC PROC RETURNS [ch: Commander.Handle] = { ch _ NARROW[List.Assoc[chKey, ProcessProps.GetPropList[]]]; IF ch = NIL THEN ERROR; }; fineTime: BOOL _ FALSE; Log: PUBLIC PROC [fmt: ROPE, v1, v2, v3, v4, v5: IO.Value _ [null[]]] = BEGIN out: IO.STREAM _ GetCommanderHandle[].out; IF fineTime THEN out.PutF["%g:", IO.card[BasicTime.GetClockPulses[]]]; out.PutF[fmt, v1, v2, v3, v4, v5]; out.PutChar['\n]; END; Confirm: PUBLIC PROC [action: ROPE] = BEGIN ch: Commander.Handle = GetCommanderHandle[]; in: IO.STREAM = ch.in; out: IO.STREAM = ch.out; out.PutF["Ready to %g ? ", IO.rope[action]]; WHILE in.GetChar[] # '\n DO NULL ENDLOOP; END; Exists: PUBLIC PROC [n: Node, zeroLenExists: BOOL _ TRUE] RETURNS [exists: BOOL] = {created: Time; length: INT; [created, length] _ GetInfo[n]; RETURN [(created # notExistTime) AND (zeroLenExists OR length#0)]}; InnerExists: PUBLIC PROC [n: Node, zeroLenExists: BOOL _ TRUE] RETURNS [exists: BOOL] = {created: Time; length: INT; [created, length] _ InnerGetInfo[n]; RETURN [(created # notExistTime) AND (zeroLenExists OR length#0)]}; FmtTime: PUBLIC PROC [t: Time] RETURNS [asRope: ROPE] = { asRope _ SELECT t FROM notExistTime => "never", unknownTime => "unknown", ENDCASE => Convert.RopeFromTime[from: t, end: seconds, useAMPM: FALSE, includeZone: FALSE]; }; PublicPartsOfNode: PUBLIC PROC [n: Node] RETURNS [name: ROPE, class: NodeClass] = { RETURN [ name: n.name, class: n.class]; }; DescribeNode: PUBLIC PROC [n: Node] RETURNS [r: ROPE] = { SELECT n.class FROM fileClass => { r _ n.name; }; ENDCASE => { r _ IO.PutFR["(%g %g)", [refAny[n.class.name]], [refAny[n.name]]]; }; }; PublicPartsOfAction: PUBLIC PROC [a: Action] RETURNS [cmd: ROPE, foundData: REF ANY, class: ActionClass] = { RETURN [ cmd: a.cmd, foundData: a.foundData, class: a.class]; }; DestructivelyReverseActionList: PUBLIC PROC [old: ActionList] RETURNS [new: ActionList] = { prev: ActionList _ NIL; cur: ActionList _ old; WHILE cur # NIL DO next: ActionList _ cur.rest; cur.rest _ prev; prev _ cur; cur _ next; ENDLOOP; new _ prev; }; EnglishList: PUBLIC PROC [nl: NodeList] RETURNS [el: ROPE, ec: CARDINAL] = BEGIN twoOfMany: ROPE; ec _ 0; FOR nl _ nl, nl.rest WHILE nl # NIL DO SELECT ec FROM =0 => el _ nl.first.name; =1 => { twoOfMany _ nl.first.name.Cat[", and ", el]; el _ nl.first.name.Cat[" and ", el]; }; =2 => el _ nl.first.name.Cat[", ", twoOfMany]; >2 => el _ nl.first.name.Cat[", ", el]; ENDCASE => ERROR; ec _ ec + 1; ENDLOOP; END; IsNode: PUBLIC PROC [ra: REF ANY] RETURNS [BOOL] = {RETURN [ISTYPE[ra, Node]]}; NarrowToNode: PUBLIC PROC [ra: REF ANY] RETURNS [Node] = {RETURN[NARROW[ra]]}; IsAction: PUBLIC PROC [ra: REF ANY] RETURNS [BOOL] = {RETURN [ISTYPE[ra, Action]]}; NarrowToAction: PUBLIC PROC [ra: REF ANY] RETURNS [Action] = {RETURN[NARROW[ra]]}; IsNodeClass: PUBLIC PROC [ra: REF ANY] RETURNS [BOOL] = {RETURN [ISTYPE[ra, NodeClass]]}; NarrowToNodeClass: PUBLIC PROC [ra: REF ANY] RETURNS [NodeClass] = {RETURN[NARROW[ra]]}; UserProfile.CallWhenProfileChanges[NoteProfile]; END.