! ----------------------------------------------------------- ; integer procedure SPLITC( t, del, ta); ! ----------------------------------------------------------- ; TEXT t; CHARACTER del; TEXT ARRAY ta; ! this procedure splits the text T into parts separated by the character delimiter DEL and makes the elements of ta[1:n] denote the different parts of t (without DEL). the returned value splitc is the number of parts found. however, if more than n parts are found, the value -1 is returned. original author: mats ohlin, foa 1, fack, s-104 50 stockholm 80, sweden. ----------------------------------------------------------- Uses: - scanto ----------------------------------------------------------- ; BEGIN INTEGER i, n; n := upperbound( ta, 1); t.setpos(1); FOR i:= i+1 WHILE t.more DO IF i>n THEN BEGIN splitc := -1; GOTO exit END ELSE ta(i) :- scanto( t, del); splitc:= i - 1; FOR i := i STEP 1 UNTIL n DO ta(i) :- NOTEXT; exit: END of splitc; ! ----------------------------------------------------------- ; TEXT PROCEDURE scanto(tt,c); ! ----------------------------------------------------------- ; NAME tt; TEXT tt; CHARACTER c; ! Returns the a portion of the text in TT (starting at POS) and delimited by the character C ( or until the end of text). The delimiter C is not included in the returned text. POS is set just past the delimiter. Uses: - FROM ----------------------------------------------------------- ; BEGIN TEXT t; INTEGER p; t:- tt; p:= t.pos; WHILE t.more DO IF t.getchar = c THEN BEGIN scanto:- t.sub(p,t.pos-p-1); goto out; END; scanto:- from(t,p); out: tt.setpos(t.pos); END of scanto; ! ----------------------------------------------------------- ; TEXT PROCEDURE rest(t); TEXT t; ! ----------------------------------------------------------- ; ! returns a subtext reference of a text starting at POS. ; ! ----------------------------------------------------------- ; IF t =/= NOTEXT THEN rest :- t.Sub( t.Pos, t.Length - t.Pos + 1); ! ----------------------------------------------------------- ; TEXT PROCEDURE from( t, i); TEXT t; INTEGER i; ! ----------------------------------------------------------- returns a reference to the end part of T starting at POS = i. ! ----------------------------------------------------------- ; IF i <= t.length THEN from :- IF i <= 0 THEN t ELSE t.sub( i, t.Length - i + 1); ! ================================================= ; text procedure GetWord( T ); name T; Text T; ! ------------------------------------------------- Returns the next "word" in a text. Where WORD is defined as either a quoted string or a sequence of non-blank characters. 1) BLANK includes SPACE and TAB 2) The quotes ( ' or " ) are not considered part of the WORD 3) End-of-Line acts as a terminator ------------------------------------------------- ; Begin character C, C2; C := ' '; while T.more and blank(C) do C := T.getchar; if not Blank(C) then begin integer i,Len; if C= ''' or C = '"' then begin i := T.pos; while T.more and C2 <> C do C2 := T.getchar; Len := IF C = C2 THEN T.Pos-i-1 ELSE T.Pos-i; end else begin i := T.pos-1; while T.more and not Blank(C) DO C := T.getchar; Len := IF Blank(C) THEN T.Pos-i-1 ELSE T.Pos-i; end; GetWord :- copy(T.sub(i,Len)); end end *** GetWd ***; ! ================================================= ; Boolean procedure Blank(C) ; character C; ! ------------------------------------------------- ; Blank := C <= ' ' or else C = '!127!';