home *** CD-ROM | disk | FTP | other *** search
- unit Lines;
-
- interface
-
- uses
- OpInline,
- OpRoot,
- OpString;
-
- const
- IsBlocked = $0001;
- IsMarked = $0002;
-
- type
- StrPtr = ^String;
- LinePtr = ^LineNode;
- LineNode =
- object(DoubleListNode)
- St : StrPtr;
- Flags : Word;
-
- constructor Init(S : String);
- {-init object}
- destructor Done; virtual;
- {-dispose of it when finished}
- procedure lnUpdate(NewS : String);
- {-update the string pointer in the node to the new string}
- function lnReturn : String;
- {-return the contents of the string}
- function lnLen : Byte;
- {-return the length of the stored string}
- function lnFlagsAreOn(Options : Word) : Boolean;
- {-true if all flag bits specified in Options are set}
- procedure lnFlagsOn(Options : Word);
- {-turn on one or more flag bits}
- procedure lnFlagsOff(Options : Word);
- {-turn off one or more flag bits}
- end;
-
- LineList =
- object(DoubleList)
- function Num(P : DoubleNodePtr) : Word;
- {-return the position in the list of P}
- procedure Clean;
- {-clear the list of all nodes}
- end;
-
-
-
- implementation
-
- constructor LineNode.Init(S : String);
- begin
- if NOT DoubleListNode.Init then Fail;
- St := StrPtr(StringToHeap(S));
- Flags := 0;
- end;
-
- destructor LineNode.Done;
- begin
- DisposeString(Pointer(St));
- DoubleListNode.Done;
- end;
-
- procedure LineNode.lnUpdate(NewS : String);
- begin
- DisposeString(Pointer(St));
- St := StrPtr(StringToHeap(TrimTrail(NewS)));
- end;
-
- function LineNode.lnReturn : String;
- begin
- lnReturn := St^;
- end;
-
- function LineNode.lnLen : Byte;
- begin
- lnLen := Byte(St^[0]);
- end;
-
- function LineNode.lnFlagsAreOn(Options : Word) : Boolean;
- begin
- lnFlagsAreOn := FlagIsSet(Flags,Options);
- end;
-
- procedure LineNode.lnFlagsOn(Options : Word);
- begin
- SetFlag(Flags,Options);
- end;
-
- procedure LineNode.lnFlagsOff(Options : Word);
- begin
- ClearFlag(Flags,Options);
- end;
-
- {----------------------------------------------------}
-
- function LineList.Num(P : DoubleNodePtr) : Word;
- var W : Word;
- N : DoubleNodePtr;
- begin
- Num := 0;
- if P = nil then exit;
- W := 1;
- N := dlHead;
- while (N <> P) do begin
- Inc(W);
- N := N^.dlNext;
- if N = nil then exit;
- end;
- Num := W;
- end;
-
- procedure LineList.Clean;
- var N : DoubleNodePtr;
- P : DoubleNodePtr;
- begin
- N := dlTail;
- while N <> nil do begin
- P := N^.dlPrev;
- if OS(N).S >= OS(HeapOrg).S then
- Dispose(N, Done)
- else
- N^.Done;
- N := P;
- end;
- dlTail := nil;
- dlHead := nil;
- dlSize := 0;
- end;
-
- end.