PROC editor: rem 8th August 2000 global a$(9,200),b$(200),k$(10),ch%(3),ch$(3,80),tab$(10) global s$(20),r$(20),n$(255) global id%,kb%,w%,b%,y%,x%,k%,c%,l%,flag%,dl%,step% global mk%,sb%,eb%,ww%,w1%,w2%,chng%,cs%,ov% ww%=150 gat 90,10 gborder 1,ww%+10,140 id%=gcreate(95,15,ww%,130,1) guse id% gtmode 2 a$(1)="This is a test sentence..." a$(2)="" a$(3)="" a$(4)="" a$(5)="" a$(6)="" a$(7)="" ov%=0 y%=1 x%=0 b%=0 chng%=0 mk%=0 sb%=0 eb%=0 tab$=" " w%=gwidth-5 step%=w%/3 ch$(1)=",,,,,,,,,,,,,,,,,,,,,,,,,,,,,," ch$(2)=",,,,,,,,,,,,,,,,,,,,,,,,,,," ch$(3)=",,"+chr$(28)+","+chr$(4)+","+chr$(5)+","+chr$(6)+","+chr$(11)+","+chr$(12)+","+chr$(29)+",,"+chr$(25)+","+chr$(24)+","+chr$(27)+","+chr$(26)+",,,,,,,,,,,,,,,," wrap:(1) gat x%,16*y% cursor id%,14,2,15 do k$="" kb%=get k%=kmod if k%>15 k%=k%-16 endif b$=a$(y%) w1%=gtwidth(left$(b$,sb%)) w2%=gtwidth(left$(b$,eb%)) if kb%=611 ctrlchar: if k$<>"" editins: endif else k$=chr$(kb%) endif if kb%<127 and kb%>31 editins: elseif kb%=8 if mk%=0 edbkspc: else delmark: endif elseif kb%=9 k$=tab$ editins: elseif kb%=127 if mk%=0 editdel: else delmark: endif elseif kb%=617 if ov%=0 ov%=1 cursor id%,14,6,15 else ov%=0 cursor id%,14,2,15 endif elseif kb%=291 or kb%=616 edithelp: elseif kb%=258 and k%=0 if mk%>0 b%=eb% clrmark: else eright: endif elseif kb%=258 and k%=6 wrdmark: mk%=1 elseif kb%=258 and k%=4 rtwrd: elseif kb%=258 and k%=2 shftrt: elseif kb%=259 and k%=0 if mk%>0 b%=sb% clrmark: else eleft: endif elseif kb%=259 and k%=4 lftwrd: elseif kb%=259 and k%=6 wrdmark: mk%=2 elseif kb%=259 and k%=2 shftlft: elseif kb%=256 editup: elseif kb%=257 editdwn: elseif kb%=263 and k%=8 editend: elseif kb%=263 and k%=10 mrkend: elseif kb%=262 and k%=8 edithme: elseif kb%=262 and k%=10 mrkhome: elseif kb%=626 sr: endif until kb%=632 or kb%=27 gclose id% stop ENDP PROC editdwn: if mk%>0 clrmark: endif if y%<8 and a$(y%+1)<>"" y%=y%+1 if b%>len(a$(y%)) b%=len(a$(y%)) endif x%=gtwidth(left$(a$(y%),b%)) gat x%,16*y% endif ENDP PROC editup: if mk%>0 clrmark: endif if y%>1 y%=y%-1 if b%>len(a$(y%)) b%=len(a$(y%)) endif x%=gtwidth(left$(a$(y%),b%)) gat x%,16*y% endif ENDP PROC edithme: if mk%>0 clrmark: endif b%=0 x%=0 gat x%,16*y% ENDP PROC editend: if mk%>0 clrmark: endif b%=len(b$) x%=gtwidth(b$) gat x%,16*y% ENDP PROC refresh:(a%) local loop% loop%=a% cursor off do gat 0,16*loop% gprintb a$(loop%),w% loop%=loop%+1 until loop%=9 if ov%=0 cursor id%,14,2,15 else cursor id%,14,6,15 endif ENDP PROC eright: if b%"" y%=y%+1 b%=0 x%=0 endif gat x%,16*y% ENDP PROC eleft: if b%>0 b%=b%-1 x%=gtwidth(left$(b$,b%)) gat x%,16*y% elseif y%>1 y%=y%-1 x%=gtwidth(a$(y%)) b%=len(a$(y%)) gat x%,16*y% endif ENDP PROC editins: if len(a$(1))+len(a$(2))+len(a$(3))+len(a$(4))+len(a$(5))+len(a$(6))+len(a$(7))+len(a$(8))+len(k$)>255 and ov%=0 giprint "No more text may be entered" return endif if mk%>0 clrmark: endif if b$="" b$=b$+k$ elseif b%=0 if ov%=1 and k$<>tab$ b$=right$(b$,len(b$)-1) endif b$=k$+b$ elseif b%tab$ b$=left$(b$,b%)+right$(b$,len(b$)-b%-1) endif b$=left$(b$,b%)+k$+right$(b$,len(b$)-b%) elseif b%=len(b$) and y%<8 and a$(y%+1)<>"" and ov%=1 y%=y%+1 b$=a$(y%) b%=0 x%=0 b$=right$(b$,len(b$)-1) b$=k$+b$ else b$=b$+k$ endif chng%=1 b%=b%+len(k$) x%=x%+gtwidth(k$) a$(y%)=b$ l%=0 if (k$=" " or k$=tab$) and y%>1 l%=len(a$(y%-1)) wrap:(y%-1) if len(a$(y%-1))>l% x%=0 b%=0 elseif y%<8 and b%>len(a$(y%)) b%=b%-len(a$(y%)) y%=y%+1 x%=gtwidth(left$(a$(y%),b%)) endif elseif gtwidth(b$)>=w% or ov%=1 if y%>1 l%=len(a$(y%-1)) wrap:(y%-1) else wrap:(1) endif if y%>1 if len(a$(y%-1))>l% x%=0 b%=0 endif endif if y%<8 and b%>len(a$(y%)) b%=b%-len(a$(y%)) y%=y%+1 x%=gtwidth(left$(a$(y%),b%)) endif else gat 0,16*y% gprintb b$,w% endif gat x%,16*y% ENDP PROC edbkspc: if b%=0 and y%>1 y%=y%-1 b$=a$(y%) b%=len(b$)-1 b$=left$(b$,b%) x%=gtwidth(b$) elseif b%=1 if len(b$)>1 b$=right$(b$,len(b$)-1) else b$="" endif b%=0 x%=0 elseif b%>1 and b%0 b$=left$(b$,len(b$)-1) b%=b%-1 x%=gtwidth(b$) endif eddel1: ENDP PROC editdel: if b%=0 and b$<>"" if len(b$)=1 b$="" else b$=right$(b$,len(b$)-1) endif elseif b%=len(b$) and b$<>"" and y%<8 and a$(y%+1)<>"" y%=y%+1 b$=a$(y%) b%=0 x%=0 b$=right$(b$,len(b$)-1) elseif b$<>"" b$=left$(b$,b%)+right$(b$,len(b$)-b%-1) endif eddel1: ENDP PROC eddel1: local l%,l1% chng%=1 a$(y%)=b$ l%=len(b$) if y%>1 l1%=len(a$(y%-1)) wrap:(y%-1) else l1%=0 wrap:(1) endif if y%>1 if len(a$(y%-1))>l1% y%=y%-1 b%=b%+l1% x%=gtwidth(left$(a$(y%),b%)) endif endif if len(a$(y%))len(n$) if gtwidth(right$(n$,len(n$)-last%+1))len(n$) p%=len(n$) endif do p%=p%-1 until gtwidth(mid$(n$,last%,p%-last%+1))0 clrmark: endif if b%=0 if y%=1 return else y%=y%-1 b$=a$(y%) b%=len(b$) endif endif flag%=0 l%=b% do l%=l%-1 if l%=0 if y%=1 return else y%=y%-1 b$=a$(y%) b%=len(b$) l%=b% endif else sp$=mid$(b$,l%,2) if left$(sp$,1)=" " and right$(sp$,1)<>" " flag%=l% endif endif until flag%>0 or l%=1 if flag%>0 b%=flag% x%=gtwidth(left$(b$,b%)) else b%=0 x%=0 endif gat x%,16*y% ENDP PROC rtwrd: local sp$(2) if mk%>0 clrmark: endif if b%>=len(b$)-1 if y%=8 b%=len(b$) x%=gtwidth(b$) gat x%,16*y% return elseif y%<8 and a$(y%+1)="" b%=len(b$) x%=gtwidth(b$) gat x%,16*y% return else y%=y%+1 b$=a$(y%) b%=0 x%=0 gat x%,16*y% return endif endif flag%=0 l%=b% do l%=l%+1 sp$=mid$(b$,l%,2) if left$(sp$,1)=" " and right$(sp$,1)<>" " flag%=l% endif until flag%>0 or l%=len(b$)-1 if flag%>0 b%=flag% x%=gtwidth(left$(b$,b%)) if b%=len(b$)-1 and y%<8 and a$(y%+1)<>"" y%=y%+1 b%=0 x%=0 endif else if y%<8 and a$(y%+1)<>"" and right$(b$,1)=" " y%=y%+1 b%=0 x%=0 elseif a$(y%+1)="" b%=len(b$) x%=gtwidth(b$) endif endif gat x%,16*y% ENDP PROC wrdmark: if mk%=0 sb%=b% eb%=b% else ui: endif if len(b$)<3 sb%=0 eb%=len(b$) elseif sb%<2 sb%=0 elseif mk%=0 or mk%=2 if mk%=2 l%=sb%-1 else l%=sb% endif do if mid$(b$,l%,1)=" " sb%=l% break endif l%=l%-1 until l%=0 if l%=0 sb%=0 endif endif if eb%>len(b$)-2 eb%=len(b$) elseif mk%=0 or mk%=1 l%=eb%+1 do if mid$(b$,l%,1)=" " eb%=l% break endif l%=l%+1 until l%=len(b$) if l%=len(b$) eb%=len(b$) endif endif cursor off gat gtwidth(left$(b$,sb%)),y%*16-14 ginvert gtwidth(left$(b$,eb%))-gtwidth(left$(b$,sb%)),17 ENDP PROC mrkend: if b%=len(b$) or (mk%>0 and eb%=len(b$)) return endif if mk%>0 ui: endif if mk%=0 sb%=b% elseif mk%=2 sb%=eb% endif mk%=1 eb%=len(b$) w1%=gtwidth(left$(b$,sb%)) w2%=gtwidth(b$) cursor off ui: ENDP PROC mrkhome: if b%=0 or (mk%>0 and sb%=0) return endif if mk%>0 ui: endif if mk%=0 eb%=b% elseif mk%=1 eb%=sb% endif mk%=2 sb%=0 w1%=0 w2%=gtwidth(left$(b$,eb%)) cursor off ui: ENDP PROC delmark: chng%=1 if sb%=0 and eb%=len(b$) a$(y%)="" elseif sb%=0 a$(y%)=right$(b$,len(b$)-eb%) elseif eb%=len(b$) and sb%=len(b$) and eb%>1 a$(y%)=left$(b$,sb%-1) elseif eb%=len(b$) a$(y%)=left$(b$,sb%) else a$(y%)=left$(b$,sb%)+right$(b$,len(b$)-eb%) endif ui: b%=sb% x%=gtwidth(left$(a$(y%),b%)) mk%=0 eb%=0 sb%=0 wrap:(1) if a$(y%)="" and y%>1 y%=y%-1 b%=len(a$(y%)) x%=gtwidth(a$(y%)) endif if b%>len(a$(y%)) b%=len(a$(y%)) x%=gtwidth(a$(y%)) endif gat x%,16*y% if ov%=0 cursor id%,14,2,15 else cursor id%,14,6,15 endif ENDP PROC clrmark: ui: refresh:(1) mk%=0 sb%=0 eb%=0 x%=gtwidth(left$(b$,b%)) gat x%,16*y% if ov%=0 cursor id%,14,2,15 else cursor id%,14,6,15 endif ENDP PROC shftrt: if mk%=0 and b%0 cursor off eb%=b% w2%=gtwidth(left$(b$,eb%)) mk%=2 sb%=b%-1 w1%=gtwidth(left$(b$,sb%)) ui: elseif mk%=1 ui: eb%=eb%-1 if eb%>sb% w2%=gtwidth(left$(b$,eb%)) ui: else b%=sb% x%=gtwidth(left$(b$,b%)) gat x%,16*y% mk%=0 if ov%=0 cursor id%,14,2,15 else cursor id%,14,6,15 endif endif elseif mk%=2 and sb%>0 ui: sb%=sb%-1 w1%=gtwidth(left$(b$,sb%)) ui: endif ENDP PROC ui: gat w1%,16*y%-14 ginvert w2%-w1%,17 ENDP PROC sr: local p%,s%,r%,rp% if mk%>0 clrmark: endif if a$(1)="" return endif n$=a$(1)+a$(2)+a$(3)+a$(4)+a$(5)+a$(6)+a$(7)+a$(8) dinit "Search & Replace" dedit s$,"Search for",20 dedit r$,"Replace with",20 dchoice cs%,"Case sensitive","No,Yes" dialog s%=len(s$) r%=len(r$) if s$="" or len(n$)0 p%=p%+r%-1 endif else break endif else p%=p%+1 endif until p%>len(n$)-s%+1 if rp%=0 return endif a$(1)="" a$(2)="" a$(3)="" a$(4)="" a$(5)="" a$(6)="" a$(7)="" a$(8)="" if len(n$)<101 a$(1)=n$ else a$(1)=left$(n$,100) if len(n$)<201 a$(2)=right$(n$,len(n$)-100) else a$(2)=mid$(n$,101,100) a$(3)=right$(n$,len(n$)-200) endif endif wrap:(1) x%=0 y%=1 b%=0 chng%=1 gat x%,16*y% ENDP PROC edithelp: dinit dtext "","Psion+C Enter symbols, letters with accents",0 dtext "","Psion+R Search & replace",0 dtext "","Delete/Shift+Delete Delete character or marked text",0 dtext "","Psion+I Select insert or overwrite mode",0 dtext "","Shift+"+chr$(27)+"/"+chr$(26)+" Mark text",0 dtext "","Shift+Ctrl+"+chr$(27)+"/"+chr$(26)+" Mark the current word",0 dtext "","Psion+Shift+"+chr$(27)+"/"+chr$(26)+" Mark to the beginning/end of the line",0 dtext "","Esc Stop editing text",0 dtext "","When you have finished editing the text, press Enter",2 dialog ENDP