DIRECTORY
AdobeIO USING [LocalAndDomain],
AdobeOps USING [ARSystemHandle],
ARAccess USING [ARStorage, DataTable, ErrorCode],
Auth USING [CopyIdentity, FreeIdentity, IdentityHandle],
Convert USING [RopeFromCard],
Courier USING [Error, ErrorCode],
Environment USING [Block, bytesPerPage],
IO USING [Close, EndOfStream, Error, GetChar, STREAM],
MSegment USING [Address, Create, Handle, Kill],
NSAssignedTypes USING [tText],
NSDataStream USING [
Abort, Aborted, Handle, SinkStream, Source, SourceStream],
NSFile USING [
Attribute, AttributesRecord, ChangeControls, ClearAttributes,
Close, Error, ErrorRecord, fullAccess, GetAttributes, Handle, ID,
Logoff, LogonDirect, nullHandle, nullID, nullSession, nullString,
Open, OpenByName, Probe, readAccess, Reference, Retrieve,
Selections, ServiceRecord, Session, Source, Store, String],
NSName USING [ClearName, CopyNameFields, String],
NSString USING [
CopyString, FreeString, String, StringFromMesaString, SubString],
PFS USING [AbsoluteName, Close, Error, ErrorDesc, Open, OpenFile, PATH, PathFromRope, StreamFromOpenFile],
Process USING [Abort, Detach, Pause, Seconds, SecondsToTicks],
RefText USING [AppendChar, ObtainScratch, ReleaseScratch],
Rope USING [Cat, Concat, FromRefText, Length, ROPE, Text];
Stream USING [
Block, CompletionCode, defaultInputOptions, Delete, EndOfStream,
Handle, SubSequenceType],
String USING [AppendChar, AppendLongNumber, AppendString];
AddPairToTable:
PROCEDURE [arS: ARAccess.ARStorage, field, value: Rope.
ROPE]
RETURNS [newARS: ARAccess.ARStorage ¬
NIL] = {
oldLen: CARD ¬ IF arS # NIL THEN arS.index ELSE 0;
newARS ¬ NEW[ARAccess.DataTable[oldLen + 1]];
FOR i:
CARD
IN [0..oldLen)
DO
newARS[i] ¬ arS[i];
ENDLOOP;
newARS[oldLen] ¬ [field, value];
newARS.index ¬ oldLen + 1;
};
AppendChar:
PUBLIC PROCEDURE [r: Rope.
ROPE, c:
CHAR]
RETURNS [Rope.
ROPE] = {
scratch: REF TEXT = RefText.ObtainScratch[3];
result: Rope.Text = Rope.FromRefText[RefText.AppendChar[scratch, c]];
RefText.ReleaseScratch[scratch];
RETURN[r.Concat[result]];
};
CopyAR:
PROC [session: Session, from: ARHandle]
RETURNS [to: ARAccess.ARStorage] = {
field, value: Rope.ROPE ¬ NIL;
c: CHAR;
{
ENABLE
IO.EndOfStream => {
IO.Close[from.sH];
IF (field #
NIL)
THEN
to ¬ AddPairToTable[to, field, value];
GOTO done;
};
from.sH ¬ PFS.StreamFromOpenFile[from.fH];
DO
c ¬ IO.GetChar[from.sH ! IO.EndOfStream => {IO.Close[from.sH]; GOTO done}];
WHILE c # ':
DO
IF c = ''
THEN
c ¬ IO.GetChar[from.sH];
field ¬ AppendChar[field, c];
c ¬ IO.GetChar[from.sH];
ENDLOOP;
c ¬ IO.GetChar[from.sH];
c ¬ IO.GetChar[from.sH];
WHILE c # ('J - 75B)
DO
IF c = ''
THEN
c ¬ IO.GetChar[from.sH];
value ¬ AppendChar[value, c];
c ¬ IO.GetChar[from.sH];
ENDLOOP;
c ¬ IO.GetChar[from.sH];
to ¬ AddPairToTable[to, field, value];
field ¬ value ¬ NIL;
ENDLOOP;
}
};
CopyAR: PROC [session: Session, from: ARHandle, to: ARAccess.ARStorage--Stream.Handle--]
RETURNS [bytes: LONG CARDINAL] = {
buffer: LONG POINTER = AssertBuffer[session];
bytes ← 0;
DO
bytesTransferred: CARDINAL;
why: Stream.CompletionCode;
savedSST: Stream.SubSequenceType;
block: Stream.Block ← [buffer, 0, bufferBytes];
[bytesTransferred, why, savedSST] ← from.get[
from, block, Stream.defaultInputOptions !
Stream.EndOfStream => {
why ← endOfStream; bytesTransferred ← nextIndex; CONTINUE}];
block.stopIndexPlusOne ← bytesTransferred;
bytes ← bytes + bytesTransferred;
to.put[to, block, FALSE];
IF why = endOfStream THEN EXIT;
ENDLOOP;
MSegment.Kill[session.buffer]};