<<>> <> <> <> <> <> <> DIRECTORY AdobeCommon USING [AdobeTimeRope, EnumeratedTypes, GetFullLoginName, Handle, NoCredentials, PostMessage], AdobeIO, AdobeOps USING [ARNumber, WhichToRead], AdobeTool USING [EmptyContents, SetEnumField], ARAccess USING [AppendChar], BasicTime USING [Now], Convert USING [CardFromRope, Error, RopeFromCard, TimeFromRope], IO, PFS USING [Close, Copy, Error, NameConfirmProc, Open, OpenFile, PathFromRope, SetClientProperty, StreamFromOpenFile, StreamOpen], PFSNames USING [PATH], Rope, ViewerTools USING [SelPos, SelPosRec]; AdobeIOImpl: CEDAR MONITOR IMPORTS AdobeCommon, AdobeTool, ARAccess, BasicTime, Convert, IO, PFS, Rope EXPORTS AdobeIO~ { PathsLocked: LIST OF Rope.ROPE ¬ NIL; zeroSelection: ViewerTools.SelPos ¬ NEW[ViewerTools.SelPosRec ¬ [0, 0, FALSE, after]]; MakeARFileName: PROC [num: AdobeOps.ARNumber] RETURNS [file: Rope.ROPE ¬ NIL] = { power: CARDINAL ¬ 10000; WHILE (num < power) DO file ¬ Rope.Concat[file, "0"]; power ¬ power / 10; ENDLOOP; IF num # 0 THEN file ¬ Rope.Concat[file, Convert.RopeFromCard[num, 10, FALSE]]; file ¬ Rope.Concat[file, ".AR"]; }; LocalAndDomain: PUBLIC PROC [location: Rope.ROPE] RETURNS [noOrg: Rope.ROPE ¬ NIL] = { colonCount: CARD ¬ 0; index: INT ¬ 0; IF location = NIL THEN RETURN; WHILE colonCount < 2 DO ch: CHAR ~ location.Fetch[index]; index ¬ index + 1; IF ch = ': THEN colonCount ¬ colonCount + 1; IF colonCount < 2 THEN noOrg ¬ noOrg.Concat[Rope.FromChar[ch]]; ENDLOOP; RETURN[noOrg]; }; AddToLocks: PROC [r: Rope.ROPE] ~ { PathsLocked ¬ CONS[r, PathsLocked]; }; InLocks: PROC [r: Rope.ROPE] RETURNS [in: BOOL ¬ FALSE] ~ { FOR p: LIST OF Rope.ROPE ¬ PathsLocked, p.rest UNTIL p = NIL DO IF Rope.Equal[r, p.first, FALSE] THEN RETURN[TRUE]; ENDLOOP; }; RemoveFromLocks: PROC [r: Rope.ROPE] ~ { newPaths: LIST OF Rope.ROPE ¬ NIL; FOR p: LIST OF Rope.ROPE ¬ PathsLocked, p.rest UNTIL p = NIL DO IF ~Rope.Equal[r, p.first, FALSE] THEN newPaths ¬ CONS[p.first, newPaths]; ENDLOOP; PathsLocked ¬ newPaths; }; UnlockProc: PUBLIC PROCEDURE[num: AdobeOps.ARNumber, handle: AdobeCommon.Handle] ~ { ENABLE PFS.Error => { AdobeCommon.PostMessage[handle, TRUE, Rope.Concat["PFS.Error: ", error.explanation]]; GOTO cantReachFile; }; apath: PFSNames.PATH ¬ NIL; dirRope, short, aRope: Rope.ROPE ¬ NIL; <> dirRope ¬ LocalAndDomain[handle.systemHandle.host]; dirRope ¬ dirRope.Concat["-XNS:/"]; dirRope ¬ dirRope.Concat[handle.systemHandle.directory]; dirRope ¬ dirRope.Concat["/"]; short ¬ MakeARFileName[num]; aRope ¬ dirRope.Concat[short]; <> <> RemoveFromLocks[aRope]; IF handle.ARFile # NIL THEN { PFS.SetClientProperty[handle.ARFile, "ControlType", "lockNone"]; PFS.Close[handle.ARFile]; handle.ARFile ¬ NIL; }; EXITS cantReachFile => {}; }; ReadProc: PUBLIC PROCEDURE[num: AdobeOps.ARNumber, handle: AdobeCommon.Handle, str: IO.STREAM ¬ NIL, lock: BOOL ¬ FALSE] = { ENABLE PFS.Error => { AdobeCommon.PostMessage[handle, TRUE, Rope.Concat["PFS.Error: ", error.explanation]]; GOTO cantReachFile; }; apath: PFSNames.PATH ¬ NIL; dirRope, short, aRope: Rope.ROPE ¬ NIL; theStream: IO.STREAM ¬ NIL; numberOfFields: CARDINAL ¬ handle.systemHandle.fieldList.length; currentFieldIndex: CARDINAL ¬ 0; currentlyReading: AdobeOps.WhichToRead ¬ fieldname; dirRope ¬ LocalAndDomain[handle.systemHandle.host]; dirRope ¬ dirRope.Concat["-XNS:/"]; dirRope ¬ dirRope.Concat[handle.systemHandle.directory]; dirRope ¬ dirRope.Concat["/"]; short ¬ MakeARFileName[num]; aRope ¬ dirRope.Concat[short]; apath ¬ PFS.PathFromRope[aRope]; IF str # NIL THEN theStream ¬ str ELSE { IF InLocks[aRope] THEN ERROR PFS.Error[[user, $unknownClass, "File is locked."]]; handle.ARFile ¬ PFS.Open[name: apath]; theStream ¬ PFS.StreamFromOpenFile[openFile: handle.ARFile]; IF lock THEN { AddToLocks[aRope]; PFS.SetClientProperty[handle.ARFile, "ControlType", "exclusive"]; }; }; AdobeTool.EmptyContents[handle]; { ENABLE UNWIND => {}--IO.Close[theStream]--; currentField, currentValue: Rope.ROPE ¬ NIL; whereToPut: {nil, stream, viewer} ¬ nil; -- stream no longer used. enum: AdobeCommon.EnumeratedTypes ¬ NIL; str: IO.STREAM ¬ NIL; view: REF ANY ¬ NIL; index: CARD; didReturn: BOOL ¬ FALSE; UNTIL IO.EndOf[theStream] DO c: CHAR ¬ IO.GetChar[theStream]; IF currentlyReading = fieldname THEN { SELECT c FROM '' => c ¬ IO.GetChar[theStream]; ': => { currentField ¬ ARAccess.AppendChar[currentField, c]; c ¬ IO.GetChar[theStream]; currentlyReading ¬ fieldvalue; currentValue ¬ NIL; }; ENDCASE; currentField ¬ ARAccess.AppendChar[currentField, c]; IF currentlyReading = fieldvalue THEN { FOR index ¬ 0, index + 1 UNTIL ((index = handle.fieldViewer.buttons.length) OR Rope.Equal[handle.getBoxName[handle.fieldViewer.buttons[index].button], currentField, FALSE]) DO ENDLOOP; whereToPut ¬ nil; IF index # handle.fieldViewer.buttons.length THEN { <<>> <> <<>> <> <> <> <> <<}>> { whereToPut ¬ viewer; view ¬ handle.fieldViewer.buttons[index].controllerOf; enum ¬ handle.fieldViewer.buttons[index] }; }; }; } ELSE SELECT whereToPut FROM < >> <> <<'J - 75B => IO.PutF[str, "\n"];>> < IO.PutF[str, "%g", IO.char[c]];>> <<};>> <<'A + 153B => IO.PutF[str, "_"];>> <<'J - 75B => {>> <> <> <> <> <> <<};>> < IO.PutF[str, "%g", IO.char[c]];>> viewer => SELECT c FROM '' => { <> c ¬ IO.GetChar[theStream]; IF c = 'J - 75B THEN c ¬ 'J - 100B; IF c = 'J - 100B THEN didReturn ¬ TRUE; <