rem editor.opl
rem version 3.26
PROC editor$:(text$,winw%,nrlines%,winx%,winy%,pos%,o%,lines%,style%,file$)
global edit$(10,255),b$(255),k$(255),tab$(10),edver$(20),sp$(2)
global eds$(20),edr$(20),txt$(255),edch$(8,16),edclip$(255),edvdate$(30)
global win1%,win2%,kb%,w%,b%,y%,x%,k%,c%,l%,flag%,dl%,step%
global mk%,sb%,eb%,w1%,w2%,chng%,cs%,ov%,spx%,spy%,nl%,m%,ge%(6)
edver$="ver. 3.26"
edvdate$=" 17th December 2001 "
rem text$=initial text to be edited
rem winw%=editor window width
rem nrlines%=number of lines of text (1-9)
rem winx%=x coordinate of top left corner of editor window
rem winy%=y coordinate of top left corner of editor window
rem pos%: 0=position cursor at beginning of text, 1=position at end
rem o%: 0=insert, 1=overwrite
rem lines%: 0=lines off, 1=lines on
rem style%=font style
rem file$=name of file in m:\opd where text is to be saved
rem
rem ENTER save text in m:\opd\'file$'.txt
rem ESC quit without saving
rem
rem if editor is closed from the system screen,
rem it returns "$$$Editor$Closed$By$SYSTEM$$$"
nl%=nrlines%
if winw%<40 or nl%<1 or nl%>9 or winx%<0 or winx%+winw%>480 or winy%<0 or winy%+16*nl%+2>160 or file$="" or len(file$)>8
return ""
endif
win1%=gcreate(winx%,winy%,winw%,16*nl%+5,0,1)
win2%=gcreate(100,20,252,136,0,1)
guse win1%
gstyle style%
gtmode 2
if lines%=1
edlines:(winw%)
endif
edit$(1)=text$
ov%=o%
if ov%>1 or ov%<0
ov%=0
endif
w%=gwidth-5
step%=w%/3
edwrap:(1)
y%=1
x%=0
b%=0
if edit$(1)<>"" and pos%=1
edPgDn:
edend:
endif
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
chng%=0
mk%=0
sb%=0
eb%=0
tab$=" "
edclip$=""
rem create special character window
edch$(1)=""+chr$(28)+chr$(4)+chr$(5)+chr$(6)+chr$(11)+chr$(12)+chr$(29)+""+chr$(25)+chr$(24)+chr$(17)+chr$(16)
edch$(2)="柽"
edch$(3)="|"
edch$(4)="Ԃ҉ӟ֍ދ"
edch$(5)="פ"
edch$(6)="ၚ"
guse win2%
ggmode 2
gborder 1
spy%=1
do
spx%=1
do
gat 16*spx%-8,16*spy%+2
gprint mid$(edch$(spy%),spx%,1)
spx%=spx%+1
until spx%=16
spy%=spy%+1
until spy%=7
gat 90,110
gbutton "Esc",1,35,20,1
gat 130,110
gbutton "OK",1,30,20,1
rem end of special character window creation
spx%=1
spy%=1
guse win1%
gvisible on
do
k$=""
getevent ge%()
if ge%(1)=$404
edsave:(file$)
gclose win1%
gclose win2%
return "$$$Editor$Closed$By$SYSTEM$$$"
endif
kb%=ge%(1)
k%=ge%(2) and $00ff
if k%>15
k%=k%-16
endif
k$=chr$(kb%)
b$=edit$(y%)
w1%=gtwidth(left$(b$,sb%))
w2%=gtwidth(left$(b$,eb%))
if kb%<127 and kb%>31
edinsert:
elseif kb%=8
if mk%=0
edbkspc:
else
eddelmrk:(1)
endif
elseif kb%=9
k$=tab$
edinsert:
elseif kb%=127
if mk%=0
eddelete:
else
eddelmrk:(0)
endif
elseif kb%=611 and k%=10
edspcchr:
if k$<>""
edinsert:
endif
elseif kb%=611 and k%=8
edcopy:
elseif kb%=617
edpaste:
elseif kb%=623
if ov%=0
ov%=1
else
ov%=0
endif
cursor win1%,14,2+4*ov%,15
elseif kb%=290
edmenu:
elseif kb%=291 or kb%=616
edhelp:
elseif kb%=631
edwrdcnt:
elseif kb%=630
edcase:
elseif kb%=258 and k%=0
if mk%>0
b%=eb%
edclrmrk:
else
edright:
endif
elseif kb%=258 and k%=6
edrwdmrk:
elseif kb%=258 and k%=4
edrtwrd:
elseif kb%=258 and k%=2
edshrt:
elseif kb%=259 and k%=0
if mk%>0
b%=sb%
edclrmrk:
else
edleft:
endif
elseif kb%=259 and k%=4
edlftwrd:
elseif kb%=259 and k%=6
edlwdmrk:
elseif kb%=259 and k%=2
edshlft:
elseif kb%=256
edup:
elseif kb%=257
eddown:
elseif kb%=263 and k%=8
edend:
elseif kb%=260 and k%=8
edPgUp:
elseif kb%=260 and k%=12
edPgUp:
edhome:
elseif kb%=261 and k%=8
edPgDn:
elseif kb%=261 and k%=12
edPgDn:
edend:
elseif kb%=620
edmrkln:
elseif kb%=263 and k%=10
edmrkend:
elseif kb%=262 and k%=8
edhome:
elseif kb%=262 and k%=10
edmrkhm:
elseif kb%=626
edsrepl:
elseif kb%=27
if mk%>0
edclrmrk:
endif
if chng%=1
lock on
dinit "Discard changes?"
dbuttons "No",%n,"Yes",%y
dl%=dialog
lock off
if dl%=%y
goto nosave::
endif
else
goto nosave::
endif
endif
until kb%=13
edsave:(file$)
gclose win1%
gclose win2%
return edit$(1)+edit$(2)+edit$(3)+edit$(4)+edit$(5)+edit$(6)+edit$(7)+edit$(8)+edit$(9)
nosave::
trap delete "m:\opd\"+file$+".txt"
gclose win1%
gclose win2%
return text$
ENDP
PROC edlines:(winw%)
l%=1
ggrey 1
do
gat 0,16*l%+2
glineto winw%,16*l%+2
l%=l%+1
until l%>nl%
ggrey 0
ENDP
PROC edmenu:
lock on
minit
mcard "Edit","Copy",%c,"Paste",%i,"Mark Line",-%l,"Search & Replace",%r
mcard "Insert","Special Character",%C
mcard "Special","Word Count",%w,"Convert Case",%v
mcard chr$(4),"About Editor",%a,"Help",%h
m%=menu
lock off
if m%=%c
edcopy:
elseif m%=%i
edpaste:
elseif m%=%l
edmrkln:
elseif m%=%r
edsrepl:
elseif m%=%C
edspcchr:
if k$<>""
edinsert:
endif
elseif m%=%w
edwrdcnt:
elseif m%=%v
edcase:
elseif m%=%a
edabout:
elseif m%=%h
edhelp:
endif
ENDP
PROC eddown:
if mk%>0
edclrmrk:
endif
if y%<nl% and edit$(y%+1)<>""
y%=y%+1
if b%>len(edit$(y%))
b%=len(edit$(y%))
endif
x%=gtwidth(left$(edit$(y%),b%))
gat x%,16*y%
endif
ENDP
PROC edup:
if mk%>0
edclrmrk:
endif
if y%>1
y%=y%-1
if b%>len(edit$(y%))
b%=len(edit$(y%))
endif
x%=gtwidth(left$(edit$(y%),b%))
gat x%,16*y%
endif
ENDP
PROC edhome:
if mk%>0
edclrmrk:
endif
b%=0
x%=0
gat x%,16*y%
ENDP
PROC edend:
if mk%>0
edclrmrk:
endif
b%=len(edit$(y%))
x%=gtwidth(edit$(y%))
gat x%,16*y%
ENDP
PROC edPgUp:
if mk%>0
edclrmrk:
endif
y%=1
if b%>len(edit$(1))
b%=len(edit$(1))
endif
x%=gtwidth(left$(edit$(1),b%))
gat x%,16*y%
ENDP
PROC edPgDn:
if mk%>0
edclrmrk:
endif
if y%=nl% and edit$(y%)<>""
return
endif
y%=1
do
y%=y%+1
until y%=nl% or edit$(y%)=""
if edit$(y%)=""
y%=y%-1
endif
if b%>len(edit$(y%))
b%=len(edit$(y%))
endif
x%=gtwidth(left$(edit$(y%),b%))
gat x%,16*y%
ENDP
PROC eddispl:(a%)
local loop%
loop%=a%
cursor off
do
gat 0,16*loop%
gprintb edit$(loop%),w%
loop%=loop%+1
until loop%>nl%
cursor win1%,14,2+4*ov%,15
ENDP
PROC edright:
if b%<len(b$)
b%=b%+1
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
elseif y%<nl% and edit$(y%+1)<>""
y%=y%+1
b%=0
x%=0
endif
gat x%,16*y%
ENDP
PROC edleft:
if b%>0
b%=b%-1
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
elseif y%>1
y%=y%-1
x%=gtwidth(edit$(y%))
b%=len(edit$(y%))
gat x%,16*y%
endif
ENDP
PROC edinsert:
local ll%
ll%=len(edit$(1))+len(edit$(2))+len(edit$(3))+len(edit$(4))+len(edit$(5))+len(edit$(6))+len(edit$(7))+len(edit$(8))+len(edit$(9))
if (ov%=0 and mk%=0 and ll%+len(k$)>255) or (ov%=1 and ll%+len(k$)>255) or (mk%>0 and ll%-eb%+sb%+len(k$)>255)
return
endif
if y%=nl%
if mk%=0 and gtwidth(b$)+gtwidth(k$)>=w%
return
endif
if mk%>0
if gtwidth(b$)-gtwidth(mid$(b$,sb%,eb%-sb%+1))+gtwidth(k$)>=w%
return
endif
endif
endif
if mk%>0
if sb%=0 and eb%=len(b$)
edit$(y%)=""
elseif sb%=0
edit$(y%)=right$(b$,len(b$)-eb%)
elseif eb%=len(b$) and sb%=len(b$) and eb%>1
edit$(y%)=left$(b$,sb%-1)
elseif eb%=len(b$)
edit$(y%)=left$(b$,sb%)
else
edit$(y%)=left$(b$,sb%)+right$(b$,len(b$)-eb%)
endif
edshwmrk:
edclip$=mid$(b$,sb%+1,eb%-sb%)
if edit$(y%)="" and y%>1
y%=y%-1
sb%=len(edit$(y%))
endif
b$=edit$(y%)
b%=sb%
x%=gtwidth(left$(b$,b%))
cursor win1%,14,2+4*ov%,15
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%<len(b$)
if ov%=1 and k$<>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%<nl% and edit$(y%+1)<>"" and ov%=1
y%=y%+1
b$=edit$(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$)
edit$(y%)=b$
l%=0
if (k$=" " or k$=tab$) and y%>1
l%=len(edit$(y%-1))
edwrap:(y%-1)
if len(edit$(y%-1))>l%
x%=0
b%=0
elseif y%<nl% and b%>len(edit$(y%))
b%=b%-len(edit$(y%))
y%=y%+1
x%=gtwidth(left$(edit$(y%),b%))
endif
elseif gtwidth(b$)>=w% or ov%=1 or mk%=1
if y%>1
l%=len(edit$(y%-1))
edwrap:(y%-1)
else
edwrap:(1)
endif
if y%>1
if len(edit$(y%-1))>l%
x%=0
b%=0
endif
endif
if y%<nl% and b%>len(edit$(y%))
b%=b%-len(edit$(y%))
y%=y%+1
x%=gtwidth(left$(edit$(y%),b%))
endif
else
gat 0,16*y%
gprintb b$,w%
endif
mk%=0
gat x%,16*y%
ENDP
PROC edbkspc:
if b%=0 and y%>1
y%=y%-1
b$=edit$(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%<len(b$)
b$=left$(b$,b%-1)+right$(b$,len(b$)-b%)
b%=b%-1
x%=gtwidth(left$(b$,b%))
elseif b%=len(b$) and b%>0
b$=left$(b$,len(b$)-1)
b%=b%-1
x%=gtwidth(b$)
endif
eddelet1:
ENDP
PROC eddelete:
if b%=0 and b$<>""
if len(b$)=1
b$=""
else
b$=right$(b$,len(b$)-1)
endif
elseif b%=len(b$) and b$<>""
if y%<nl% and edit$(y%+1)<>""
y%=y%+1
b$=edit$(y%)
b%=0
x%=0
b$=right$(b$,len(b$)-1)
else
return
endif
elseif b$<>""
b$=left$(b$,b%)+right$(b$,len(b$)-b%-1)
endif
eddelet1:
ENDP
PROC eddelet1:
local l%,l1%
chng%=1
edit$(y%)=b$
l%=len(b$)
if y%>1
l1%=len(edit$(y%-1))
edwrap:(y%-1)
else
l1%=0
edwrap:(1)
endif
if y%>1
if len(edit$(y%-1))>l1%
y%=y%-1
b%=b%+l1%
x%=gtwidth(left$(edit$(y%),b%))
endif
endif
if len(edit$(y%))<l%
b%=l%-len(edit$(y%))
y%=y%+1
x%=gtwidth(left$(edit$(y%),b%))
endif
gat x%,16*y%
ENDP
PROC edwrap:(a%)
local p%,f%,last%,flag%
txt$=""
edit$(10)=""
f%=a%
do
if len(txt$)+len(edit$(f%))<255
txt$=txt$+edit$(f%)
f%=f%+1
else
txt$=txt$+left$(edit$(f%),255-len(txt$))
f%=nl%+1
endif
until f%>nl%
f%=a%
do
edit$(f%)=""
f%=f%+1
until f%>nl%
f%=a%
last%=1
flag%=0
do
p%=last%+step%
if p%>len(txt$)
if gtwidth(right$(txt$,len(txt$)-last%+1))<w%
edit$(f%)=right$(txt$,len(txt$)-last%+1)
flag%=1
else
p%=len(txt$)
endif
endif
if flag%=0
do
if mid$(txt$,p%,1)=" "
if gtwidth(mid$(txt$,last%,p%-last%+1))<w%
edit$(f%)=mid$(txt$,last%,p%-last%+1)
last%=p%+1
f%=f%+1
break
endif
endif
p%=p%-1
until p%=last%
if p%=last%
p%=last%+step%
if p%>len(txt$)
p%=len(txt$)
endif
do
p%=p%-1
until gtwidth(mid$(txt$,last%,p%-last%+1))<w%
edit$(f%)=mid$(txt$,last%,p%-last%+1)
last%=p%+1
f%=f%+1
endif
endif
until flag%=1 or f%>nl%
eddispl:(a%)
ENDP
PROC edrtwrd:
if mk%>0
edclrmrk:
endif
if b%>=len(b$)-1
if y%=nl%
b%=len(b$)
x%=gtwidth(b$)
gat x%,16*y%
return
elseif y%<nl% and edit$(y%+1)=""
b%=len(b$)
x%=gtwidth(b$)
gat x%,16*y%
return
else
y%=y%+1
b$=edit$(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%<nl% and edit$(y%+1)<>""
y%=y%+1
b%=0
x%=0
endif
else
if y%<nl% and edit$(y%+1)<>"" and right$(b$,1)=" "
y%=y%+1
b%=0
x%=0
elseif edit$(y%+1)=""
b%=len(b$)
x%=gtwidth(b$)
endif
endif
gat x%,16*y%
ENDP
PROC edlftwrd:
if mk%>0
edclrmrk:
endif
if b%=0
if y%=1
return
else
y%=y%-1
b$=edit$(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$=edit$(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 edrwdmrk:
if b$="" or b$=" " or b$=" "
return
elseif mk%=2
edrwdmk1:
return
elseif mk%=0
sb%=b%
eb%=b%
mk%=1
else
edshwmrk:
endif
if eb%>len(b$)-2
eb%=len(b$)
else
l%=eb%+1
do
sp$=mid$(b$,l%,2)
if left$(sp$,1)=" " and right$(sp$,1)<>" "
break
endif
l%=l%+1
until l%=len(b$)
eb%=l%
endif
if sb%=eb%
mk%=0
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
return
endif
w1%=gtwidth(left$(b$,sb%))
w2%=gtwidth(left$(b$,eb%))
cursor off
edshwmrk:
ENDP
PROC edrwdmk1:
edshwmrk:
if sb%=len(b$)-1
mk%=0
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
return
endif
l%=sb%+1
do
sp$=mid$(b$,l%,2)
if left$(sp$,1)=" " and right$(sp$,1)<>" "
break
endif
l%=l%+1
until l%=len(b$)
sb%=l%
if sb%>eb%
l%=eb%
eb%=sb%
sb%=l%
mk%=1
endif
if sb%=eb%
mk%=0
b%=sb%
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
return
endif
w1%=gtwidth(left$(b$,sb%))
w2%=gtwidth(left$(b$,eb%))
cursor off
edshwmrk:
ENDP
PROC edlwdmrk:
if b$=""
return
elseif mk%=1
edlwdmk1:
return
elseif mk%=0
sb%=b%
eb%=b%
mk%=2
else
edshwmrk:
endif
if b$=" "
mk%=0
elseif sb%<2
sb%=0
else
if mk%=2
l%=sb%-1
else
l%=sb%
endif
do
sp$=mid$(b$,l%,2)
if left$(sp$,1)=" " and right$(sp$,1)<>" "
break
endif
l%=l%-1
until l%=0
sb%=l%
endif
if sb%=eb%
mk%=0
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
return
endif
w1%=gtwidth(left$(b$,sb%))
w2%=gtwidth(left$(b$,eb%))
cursor off
edshwmrk:
ENDP
PROC edlwdmk1:
edshwmrk:
if eb%=1
mk%=0
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
return
endif
l%=eb%-1
do
sp$=mid$(b$,l%,2)
if left$(sp$,1)=" " and right$(sp$,1)<>" "
break
endif
l%=l%-1
until l%=0
eb%=l%
if sb%>eb%
l%=eb%
eb%=sb%
sb%=l%
mk%=2
endif
if sb%=eb%
mk%=0
b%=sb%
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
return
endif
w1%=gtwidth(left$(b$,sb%))
w2%=gtwidth(left$(b$,eb%))
cursor off
edshwmrk:
ENDP
PROC edmrkend:
if b%=len(b$) or (mk%>0 and eb%=len(b$))
return
endif
if mk%>0
edshwmrk:
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
edshwmrk:
ENDP
PROC edmrkhm:
if b%=0 or (mk%>0 and sb%=0)
return
endif
if mk%>0
edshwmrk:
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
edshwmrk:
ENDP
PROC edmrkln:
if b$=""
return
endif
if mk%>0
edclrmrk:
endif
b%=0
sb%=0
eb%=len(b$)
mk%=1
w1%=0
w2%=gtwidth(b$)
cursor off
edshwmrk:
ENDP
PROC eddelmrk:(clip%)
chng%=1
if sb%=0 and eb%=len(b$)
edit$(y%)=""
elseif sb%=0
edit$(y%)=right$(b$,len(b$)-eb%)
elseif eb%=len(b$) and sb%=len(b$) and eb%>1
edit$(y%)=left$(b$,sb%-1)
elseif eb%=len(b$)
edit$(y%)=left$(b$,sb%)
else
edit$(y%)=left$(b$,sb%)+right$(b$,len(b$)-eb%)
endif
if clip%=1
edclip$=mid$(b$,sb%+1,eb%-sb%)
endif
edshwmrk:
b%=sb%
x%=gtwidth(left$(edit$(y%),b%))
mk%=0
eb%=0
sb%=0
edwrap:(1)
if edit$(y%)="" and y%>1
y%=y%-1
b%=len(edit$(y%))
x%=gtwidth(edit$(y%))
endif
if b%>len(edit$(y%))
b%=len(edit$(y%))
x%=gtwidth(edit$(y%))
endif
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
ENDP
PROC edclrmrk:
edshwmrk:
eddispl:(1)
mk%=0
sb%=0
eb%=0
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
ENDP
PROC edshrt:
if mk%=0 and b%<len(b$)
cursor off
sb%=b%
w1%=gtwidth(left$(b$,sb%))
mk%=1
eb%=b%+1
w2%=gtwidth(left$(b$,eb%))
edshwmrk:
elseif mk%=1 and eb%<len(b$)
edshwmrk:
eb%=eb%+1
w2%=gtwidth(left$(b$,eb%))
edshwmrk:
elseif mk%=2
edshwmrk:
sb%=sb%+1
if sb%<eb%
w1%=gtwidth(left$(b$,sb%))
edshwmrk:
else
b%=sb%
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
mk%=0
endif
endif
ENDP
PROC edshlft:
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%))
edshwmrk:
elseif mk%=1
edshwmrk:
eb%=eb%-1
if eb%>sb%
w2%=gtwidth(left$(b$,eb%))
edshwmrk:
else
b%=sb%
x%=gtwidth(left$(b$,b%))
gat x%,16*y%
mk%=0
cursor win1%,14,2+4*ov%,15
endif
elseif mk%=2 and sb%>0
edshwmrk:
sb%=sb%-1
w1%=gtwidth(left$(b$,sb%))
edshwmrk:
endif
ENDP
PROC edshwmrk:
gat w1%,16*y%-14
ginvert w2%-w1%,17
ENDP
PROC edpaste:
local ll%
if edclip$=""
return
endif
k$=edclip$
ll%=len(edit$(1))+len(edit$(2))+len(edit$(3))+len(edit$(4))+len(edit$(5))+len(edit$(6))+len(edit$(7))+len(edit$(8))+len(edit$(9))
if (ov%=0 and mk%=0 and ll%+len(k$)>255) or (ov%=1 and ll%+len(k$)>255) or (mk%>0 and ll%-eb%+sb%+len(k$)>255)
return
endif
if y%=nl%
if mk%=0 and gtwidth(b$)+gtwidth(k$)>=w%
return
endif
if mk%>0
if gtwidth(b$)-gtwidth(mid$(b$,sb%,eb%-sb%+1))+gtwidth(k$)>=w%
return
endif
endif
endif
edinsert:
ENDP
PROC edcopy:
if mk%=0
return
endif
edclip$=mid$(b$,sb%+1,eb%-sb%)
edshwmrk:
if mk%=1
b%=eb%
else
b%=sb%
endif
mk%=0
x%=gtwidth(left$(edit$(y%),b%))
gat x%,16*y%
cursor win1%,14,2+4*ov%,15
ENDP
PROC edsrepl:
local p%,s%,r%,rp%
if mk%>0
edclrmrk:
endif
if edit$(1)=""
return
endif
txt$=edit$(1)+edit$(2)+edit$(3)+edit$(4)+edit$(5)+edit$(6)+edit$(7)+edit$(8)+edit$(9)
lock on
dinit "Search & Replace"
dedit eds$,"Search for",20
dedit edr$,"Replace with",20
dchoice cs%,"Case sensitive","No,Yes"
dialog
lock off
s%=len(eds$)
r%=len(edr$)
if eds$="" or len(txt$)<s% or eds$=edr$
return
endif
rp%=0
p%=1
do
if mid$(txt$,p%,s%)=eds$ or (cs%=1 and lower$(mid$(txt$,p%,s%))=lower$(eds$))
if len(txt$)+r%-s%<256
txt$=left$(txt$,p%-1)+edr$+right$(txt$,len(txt$)-p%-s%+1)
rp%=1
if r%>0
p%=p%+r%-1
endif
else
break
endif
else
p%=p%+1
endif
until p%>len(txt$)-s%+1
if rp%=0
return
endif
edit$(1)=""
edit$(2)=""
edit$(3)=""
edit$(4)=""
edit$(5)=""
edit$(6)=""
edit$(7)=""
edit$(8)=""
edit$(9)=""
edit$(1)=txt$
edwrap:(1)
x%=0
y%=1
b%=0
chng%=1
gat x%,16*y%
ENDP
PROC edspcchr:
guse win2%
edspcurs:
gvisible on
k$=""
do
k%=get
if k%=257 and spy%<6
edspcurs:
spy%=spy%+1
edspcurs:
elseif k%=256 and spy%>1
edspcurs:
spy%=spy%-1
edspcurs:
elseif k%=259 and spx%>1
edspcurs:
spx%=spx%-1
edspcurs:
elseif k%=258 and spx%<15
edspcurs:
spx%=spx%+1
edspcurs:
elseif k%=261 and spy%<6
edspcurs:
spy%=6
edspcurs:
elseif k%=260 and spy%>1
edspcurs:
spy%=1
edspcurs:
elseif k%=262 and spx%>1
edspcurs:
spx%=1
edspcurs:
elseif k%=263 and spx%<15
edspcurs:
spx%=15
edspcurs:
elseif k%=13
k$=mid$(edch$(spy%),spx%,1)
edspcurs:
gvisible off
guse win1%
return
endif
until k%=27
gvisible off
edspcurs:
guse win1%
ENDP
PROC edspcurs:
gat 16*spx%-12,16*spy%-11
gbox 16,16
ENDP
PROC edwrdcnt:
local p%,sp%,words%
txt$=edit$(1)+edit$(2)+edit$(3)+edit$(4)+edit$(5)+edit$(6)+edit$(7)+edit$(8)+edit$(9)
if txt$=""
return
endif
p%=1
sp%=1
words%=0
do
if mid$(txt$,p%,1)<>" " and sp%=1
words%=words%+1
sp%=0
elseif mid$(txt$,p%,1)=" "
sp%=1
endif
p%=p%+1
until p%>len(txt$)
if words%=0
return
endif
lock on
dinit "Word Count"
dtext "","Number of words: "+num$(words%,3),2
dialog
lock off
ENDP
PROC edcase:
local c%
if edit$(1)=""
return
endif
lock on
dinit ""
dchoice c%,"Convert to","Upper Case,Lower Case"
dl%=dialog
lock off
if dl%=0
return
endif
if c%=2
edit$(1)=lower$(edit$(1))
edit$(2)=lower$(edit$(2))
edit$(3)=lower$(edit$(3))
edit$(4)=lower$(edit$(4))
edit$(5)=lower$(edit$(5))
edit$(6)=lower$(edit$(6))
edit$(7)=lower$(edit$(7))
edit$(8)=lower$(edit$(8))
edit$(9)=lower$(edit$(9))
else
edit$(1)=upper$(edit$(1))
edit$(2)=upper$(edit$(2))
edit$(3)=upper$(edit$(3))
edit$(4)=upper$(edit$(4))
edit$(5)=upper$(edit$(5))
edit$(6)=upper$(edit$(6))
edit$(7)=upper$(edit$(7))
edit$(8)=upper$(edit$(8))
edit$(9)=upper$(edit$(9))
endif
chng%=1
edwrap:(1)
eddispl:(1)
edPgDn:
edend:
ENDP
PROC edsave:(file$)
cursor off
lopen "m:\opd\"+file$+".txt"
lprint edit$(1)
lprint edit$(2)
lprint edit$(3)
lprint edit$(4)
lprint edit$(5)
lprint edit$(6)
lprint edit$(7)
lprint edit$(8)
lprint edit$(9)
lclose
ENDP
PROC edhelp:
lock on
dinit "Help - 1"
dtext "Psion+C","Copy",0
dtext "Psion+I","Paste",0
dtext "Psion+L","Mark the current line",0
dtext "Psion+R","Search & replace",0
dtext "Shift+Psion+C","Insert Special Character",0
dtext "Psion+O","Select insert or overwrite mode",0
dtext "Psion+W","Word Count",0
dl%=dialog
lock off
if dl%=0
return
endif
lock on
dinit "Help - 2"
dtext "Psion+V","Convert case"
dtext "Delete/Shift+Delete","Delete character or marked text",0
dtext "Shift+"+chr$(27)+"/"+chr$(26),"Mark text",0
dtext "Shift+Ctrl+"+chr$(27)+"/"+chr$(26),"Mark the current word",0
dtext "Shift+Psion+"+chr$(27)+"/"+chr$(26),"Mark to the beginning/end of the line",0
dtext "Esc","Quit",0
dtext "Enter","Save",0
dialog
lock off
ENDP
PROC edabout:
lock on
dinit "Editor "+edver$
dtext "",edvdate$,2
dtext "","written by Ian Chapple",2
dtext "","e-mail: ian_and_aida@compuserve.com",2
dialog
lock off
ENDP
|