class TextArray; begin ! ----------------------------------------------------------- This class is designed to support the text data associated with TEXT_EDIT windows. Public procedures: ----------------- - Size ->integer - set (n,Text) : sets line N to Text - get (n)-> Text: returns pointer to Line 'n' - put (T) : adds a line at end containing T - delete(pos,n) : deletes N lines starting at Pos * - insert(pos,n) : inserts n blanks lines starting at Pos * * both procedures COUNT, the number of lines, and shift the lines at the end of the array accordingly (J. vaucher, 19 april 1995) ----------------------------------------------------------- ; ref(TextData) Data; integer Count; class TextData (Limit); integer Limit; begin text array Line(1:Limit); end; integer procedure SIZE; size := count; procedure CLEAR; count := 0; text procedure SET(ind,T); integer ind; text T; if 1 <= ind and ind <= count then Data.Line(ind) :- T; text procedure GET(ind); integer ind; if 1 <= ind and ind <= count then get :- Data.Line(ind) else get :- notext; text procedure PUT(T); text T; begin Grow(1); Data.Line(count) :- T; end; procedure DELETE(pos,N); integer pos,N; if pos >= 1 and pos <= count then begin integer i; N := min(max( N, 0), count-pos+1); inspect DATA do for i := pos step 1 until count-n do Line(i) :- Line(i+n); count := count - N; end; procedure INSERT(pos,N); integer pos,n; if N > 0 then begin integer i, top; pos := min(max( pos, 1), count+1); top := count; Grow(N); inspect DATA do begin for i := top step -1 until pos do Line(i+n) :- Line(i); for i := pos step 1 until pos+N-1 do Line(pos) :- notext; end; end; procedure Grow(n); integer n; begin if count + n > Data.Limit then begin ref(TextData) TD; integer i; TD :- new TextData( Data.Limit + max(n,50) ); for i := 1 step 1 until count do TD.Line(i) :- Data.Line(i); Data :- TD; end; count := count+n; end; Data :- new TextData(100); end TextArray;