home *** CD-ROM | disk | FTP | other *** search
- 10 rem ****************************
- 20 rem ** basic editor ver1.0 **
- 30 rem ** by p.f.hayes (c) 1988 **
- 40 rem ****************************
- 50 print"[147]initialising program":gosub 2900:clr:gosub 1720
- 60 gosub 1770
- 70 print"[147][158]**************basic editor**************[154]"
- 80 print" 1) exit from editor"
- 90 print" 2) re-initialise program"
- 100 print" 3) load file"
- 110 print" 4) input line(s)"
- 120 print" 5) list line(s)"
- 130 print" 6) delete line(s)"
- 140 print" 7) edit file"
- 150 print" 8) merge/append file"
- 160 print" 9) save file line(s)"
- 170 print" 10) change device number"
- 180 print" 11) search for string"
- 190 print" 12) directory"
- 200 input"command (1-12) = ";cm
- 210 if cm=1 then goto 2820
- 220 if cm=2 or cm=3 then input"erases current file:continue (y/n) n[157][157][157]";t$
- 230 if cm=2 and t$="y" then clr:gosub 1720:gosub 1770
- 240 if cm=3 and t$="y" then clr:cm=3:gosub 1720:gosub 1770:gosub 1360
- 250 if cm>3 then on cm-3 gosub 280,830,1130,1850,1280,1480,1680,2510,2680
- 260 goto 70
- 270 rem ***input basic line(s)***
- 280 input"auto line numbering (y/n) n[157][157][157]";t$
- 290 if t$="y" then 400
- 300 print"[147]":open 2,0
- 310 input@2,ip$:if ip$=chr$(95) then 370
- 320 if len(ip$)>80 then ip$=left$(ip$,80)
- 330 gosub 500:if ln=-1 then 370
- 340 if ln<1 or ln>65534 then print"invalid line number:re-enter":goto 310
- 350 gosub 550:if len(ip$)=0 then 380
- 360 gosub 580:if not err then print:goto 310
- 370 close 2:return
- 380 gosub 750:if not err then gosub 1190
- 390 print:goto 310
- 400 input"start line number = ";bl:input"line number increment = ";il
- 410 print"[147]":open 2,0:si=0
- 420 al$=mid$(str$(bl+si),2):printal$;" ";:input@2,ip$:if ip$=chr$(95) then 480
- 430 ip$=al$+ip$:if len(ip$)>80 then ip$=left$(ip$,80)
- 440 gosub 500:if ln=-1 then 480
- 450 if ln<1 or ln>65534 then print"invalid line number:re-enter":goto 420
- 460 gosub 550:if len(ip$)=0 then print:goto 420
- 470 gosub 580:if not err then si=si+il:print:goto 420
- 480 close 2:return
- 490 rem ***extract line number***
- 500 ln=-1:if len(ip$)=0 or ip$<"0" or left$(ip$,1)>"9" then 530
- 510 for t=1 to len(ip$):if mid$(ip$,t,1)<="9" and mid$(ip$,t,1)>="0" then next t
- 520 ln=val(left$(ip$,t-1)):ip$=mid$(ip$,t)
- 530 return
- 540 rem ***extract line text***
- 550 for t=1 to len(ip$):if mid$(ip$,t,1)=" " then next t
- 560 ip$=mid$(ip$,t):return
- 570 rem ***insert line in file array***
- 580 if ln<1 or ln>65534 then 720
- 590 gosub 750
- 600 tt=im
- 610 if not err then tt=ma:goto 660
- 620 if len(em$)=0 then 640
- 630 tt=fne1(tt):em$=mid$(em$,3):im=im-1:va=va-1
- 640 kk$=chr$(tt/256)+chr$(tt-256*int(tt/256))
- 650 mr$(qq)=left$(mr$(qq),2*lm-2)+kk$+mid$(mr$(qq),2*lm-1)
- 660 t1=fne2(ln):a$(tt)=chr$(ln-t1*256)+chr$(t1)+ip$
- 670 if not err then 730
- 680 for i=0 to 6:if len(mr$(i))<=250 then 710
- 690 mr$(i+1)=right$(mr$(i),2)+mr$(i+1)
- 700 mr$(i)=left$(mr$(i),len(mr$(i))-2):if peek(152)<>0 then t=fre(0)
- 710 next i:im=im+1
- 720 err=false
- 730 return
- 740 rem ***find line number in file array***
- 750 tt=im-va:pw=fnf5(tt):mm=fnf6(pw):for bv=pw-1 to 0 step -1
- 760 qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):t1=fnf4(ma):mm=fnf7(mm)
- 770 if mm>tt-1 then mm=tt-1
- 780 next bv
- 790 qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):t1=fnf4(ma):if t1>=ln then 810
- 800 mm=mm+1:goto 790
- 810 err=not(t1=ln):return
- 820 rem ***list lines***
- 830 gosub 930:if err then 910
- 840 goto 2820
- 850 print"[147]":gosub 1040:if fm<sm or fm=0 then 910
- 860 if dev=4 then open 2,dev:cmd 2
- 870 for mm=sm to fm:qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):gosub 1090:next mm
- 880 if dev=4 then print#2:close 2:gosub 1680
- 890 if peek(152)=0 then print"< return for main menu >"
- 900 if peek(152)=0 then gett$:if t$="" then 900
- 910 return
- 920 rem ***input line number range***
- 930 print"enter line number range (eg 100-500)"
- 940 ip$="":input"first line-last line = ";ip$
- 950 sl=1:fl=65534:err=false
- 960 if len(ip$)=0 then 1020
- 970 gosub 500:if ln>=0 then sl=ln:goto 990
- 980 if ln>-1 then fl=-ln:goto 1020
- 990 gosub 550:if len(ip$)=0 then fl=sl:goto 1020
- 1000 ip$=mid$(ip$,2):gosub 550
- 1010 if len(ip$)>0 then gosub 500:fl=ln
- 1020 err=sl<1 or sl>65534 or fl<1 or fl>65534 or err:return
- 1030 rem ***line number range markers***
- 1040 ln=sl:gosub 750:sm=mm
- 1050 ln=fl:gosub 750:fm=mm
- 1060 if err then fm=fm-1
- 1070 return
- 1080 rem ***list lines marked by ma***
- 1090 tp$=str$(fnf4(ma)):printmid$(tp$,2);" ";mid$(a$(ma),3)
- 1100 if peek(152)=0 then wait 198,1,1:poke 198,0
- 1110 return
- 1120 rem ***delete line(s)***
- 1130 gosub 930:if err then 1170
- 1140 goto 2820
- 1150 gosub 1040:if fm<sm then 1170
- 1160 for mm=fmtosm step -1:qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):gosub 1190:nextmm
- 1170 return
- 1180 rem ***delete line marked by ma***
- 1190 mr$(qq)=left$(mr$(qq),2*lm-2)+mid$(mr$(qq),2*lm+1)
- 1200 for i=0 to 6
- 1210 if len(mr$(i))>=250 or len(mr$(i+1))=0 then 1230
- 1220 mr$(i)=mr$(i)+left$(mr$(i+1),2):mr$(i+1)=mid$(mr$(i+1),3)
- 1230 next i:va=va+1:a$(ma)=""
- 1240 if len(em$)>250 then 1260
- 1250 em$=chr$(ma/256)+chr$(ma-256*int(ma/256))+em$
- 1260 return
- 1270 rem ***merge file from device***
- 1280 gosub 1630:if dev=8 then tn$=tn$+",s,r"
- 1290 if dev<>1 and dev<>8 then return
- 1300 goto 2820
- 1310 open 2,dev,0,tn$
- 1320 input@2,ip$:gosub 500:if ln=-1 or st then 1340
- 1330 gosub 550:gosub 580:goto 1320
- 1340 close 2:return
- 1350 rem ***load file from device***
- 1360 gosub 1630:if dev=8 then tn$=tn$+",s,r"
- 1370 if dev<>1 and dev<>8 then return
- 1380 goto 2820
- 1390 open 2,dev,0,tn$
- 1400 input@2,ip$:gosub 500:if ln=-1 or st then 1460
- 1410 gosub 550:gosub 580
- 1420 input@2,ip$:gosub 500:if ln=-1 or st then 1460
- 1430 gosub 550:mm=mm+1:qq=fnf1(mm):lm=fnf2(mm)
- 1440 if ln<1 or ln>65534 then 1420
- 1450 err=-1:gosub 600:goto 1420
- 1460 close 2:return
- 1470 rem ***save file to device***
- 1480 gosub 1630:gosub 930:if dev<>1 and dev<>8 then 1610
- 1490 if err then print"invalid lines:re-enter commands":goto 1480
- 1500 gosub 1040:err=(fl<sl):if err then goto 1490
- 1510 if dev<>8 then 1580
- 1520 print"enter file operation :"
- 1530 input"c[146]reate,o[146]verwrite,a[146]ppend (c/o/a) ";t$
- 1540 if t$="c" then tn$=tn$+",s,w":goto 1580
- 1550 if t$="o" then tn$="@0:"+tn$+",s,w":goto 1580
- 1560 if t$="a" then tn$=tn$+",s,a":goto 1580
- 1570 goto 1510
- 1580 goto 2820
- 1590 open 2,dev,2,tn$:cmd 2:gosub 870
- 1600 print#2:close 2
- 1610 return
- 1620 rem ***input file name***
- 1630 tn$="":gosub 1680:if dev=4 then 1660
- 1640 input"file name = ";tn$:lt=len(tn$)
- 1650 if lt>16 or lt<1 then print"file name invalid":goto 1640
- 1660 return
- 1670 rem ***change device number***
- 1680 print"(printer=4:disc=8:tape=1)"
- 1690 print spc(21) dev
- 1700 input"[145]new device number = ";dev:return
- 1710 rem ***initialise program & define functions***
- 1720 dim mr$(7),a$(300),fs(50):im=2:va=0
- 1730 mr$(0)=chr$(0)+chr$(0)+chr$(0)+chr$(1)
- 1740 a$(0)=chr$(0)+chr$(0):a$(1)=chr$(255)+chr$(255)
- 1750 cp$=""
- 1760 o$=" ":o$=o$+o$:return
- 1770 def fnf1(mm)=int((mm-1)/125):def fnf2(mm)=mm-125*qq
- 1780 def fnf3(qq)=256*asc(mid$(mr$(qq),2*lm-1))+asc(mid$(mr$(qq),2*lm))
- 1790 def fnf4(ma)=asc(mid$(a$(ma),1,1))+256*asc(mid$(a$(ma),2,1))
- 1800 def fnf5(tt)=int(log(tt)/.693147)
- 1810 def fnf6(pw)=2^pw:def fnf7(mm)=mm+2^bv*((ln<t1)-(ln>t1))
- 1820 def fnf8(p)=1024+lr*40+p:def fne1(tt)=256*asc(em$)+asc(mid$(em$,2))
- 1830 def fne2(ln)=int(ln/256):return
- 1840 rem ***edit file***
- 1850 p=0:lr=1:lp=1:ai=0:tf=0:ns=11:tp$="":fq=0:if th=1 then th=0:goto 1930
- 1860 if tc=1 then tc=0:goto 1930
- 1870 input"edit from linenumber = ";ln:lt=ln
- 1880 gosub 750:if err and tf=0 or ln<1 or ln>65534 then 1900
- 1890 goto 1930
- 1900 input"invalid line:r[146]e-enter or e[146]xit";t$
- 1910 if t$="e" then return
- 1920 goto 1870
- 1930 if ns>im-mm-va then ns=im-mm-va
- 1940 if ns=0 and (im-va)>2 then 2420
- 1950 if ns=0 then return
- 1960 pt=mm:qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):lt=val(str$(fnf4(ma))):print"[147]"
- 1970 for pr=1 to ns
- 1980 qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq)
- 1990 tp$=str$(fnf4(ma))
- 2000 tp$=mid$(tp$,2)+" "+mid$(a$(ma),3)
- 2010 cd$=left$(cp$,lr-(2*int(lr/2)-lr<>0)-1)
- 2020 print"";cd$;o$;"[145][145]";tp$
- 2030 mm=mm+1:lr=lr+2:next pr
- 2040 lr=lp+2*(lp=ns*2+1)
- 2050 ac=ai:ai=pt+int((lr+1)/2)-1:if ai=ac and tf=0 then 2090
- 2060 qq=int((ai-1)/125):lm=ai-125*qq:tf=0
- 2070 ma=fnf3(qq):tp$=str$(fnf4(ma))
- 2080 tp$=mid$(tp$,2)+" "+mid$(a$(ma),3)
- 2090 cd$=left$(cp$,lr-(2*int(lr/2)-lr<>0)-1)
- 2100 print"";cd$;o$;"[145][145]";tp$
- 2110 ch=peek(fnf8(p)):poke 54272+fnf8(p),14:poke fnf8(p),160
- 2120 for nu=1 to 5:next nu:poke fnf8(p),ch
- 2130 get sc$:if sc$="" then 2110
- 2140 if sc$=chr$(34) then fq=-(fq=0)
- 2150 if sc$=chr$(13) then 2440
- 2160 if sc$=chr$(141) then return
- 2170 if sc$=chr$(19) and fq=0 then return
- 2180 if sc$=chr$(147) and fq=0 then return
- 2190 if sc$=chr$(133) then 2400
- 2200 if sc$=chr$(137) then 2420
- 2210 if sc$=chr$(134) then p=0:lr=1:goto 2050
- 2220 if sc$=chr$(138) then p=0:lr=ns*2-1:goto 2050
- 2230 if sc$=chr$(135) then p=0:goto 2110
- 2240 if sc$=chr$(139) then p=len(tp$)-1:goto 2110
- 2250 if sc$=chr$(136) then return
- 2260 if sc$=chr$(140) then print"[147]":goto 1850
- 2270 if p>0 and sc$=chr$(20) then tp$=left$(tp$,p-1)+mid$(tp$,p+1):p=p-1
- 2280 if sc$=chr$(20) then 2050
- 2290 if sc$="[145]" and p<=39 and fq=0 then lr=lr+2*(lr>1):p=0:goto 2050
- 2300 if sc$="[145]" and p>39 and fq=0 then p=p-40:goto 2110
- 2310 if sc$="" and p<=39 and len(tp$)>40 and fq=0 then p=40:goto 2110
- 2320 if sc$="" and fq=0 then lr=lr-2*(lr<ns*2-1):p=0:goto 2050
- 2330 if len(tp$)=80 then 2370
- 2340 if sc$=chr$(148) then tp$=left$(tp$,p)+" "+mid$(tp$,p+1):goto 2050
- 2350 if fq=1 then tp$=left$(tp$,p)+sc$+mid$(tp$,p+2):p=p-1*(p<79):goto 2050
- 2360 ifsc$<>"[157]"andsc$<>""thentp$=left$(tp$,p)+sc$+mid$(tp$,p+2):p=p-1*(p<79):goto2050
- 2370 if sc$="[157]" and p>0 then p=p-1
- 2380 if sc$="" and p<len(tp$)-1 then p=p+1
- 2390 goto 2110
- 2400 mm=pt+11:if mm>im-va then mm=im-va-1
- 2410 th=1:goto 1850
- 2420 mm=pt-11:if mm<2 then mm=2
- 2430 tc=1:goto 1850
- 2440 ip$=left$(tp$,len(tp$))
- 2450 gosub 500:if ln<1 or ln>65534 or ln=-1 then 2490
- 2460 gosub 550:if len(ip$)=0 then 2480
- 2470 gosub 580:goto 2490
- 2480 gosub 750:if not err then gosub 1190
- 2490 tf=1:p=0:lp=lr:ln=lt:lr=1:ns=11:fq=0:goto 1880
- 2500 rem ***search routine***
- 2510 input"input search string = ";tg$:gosub 930:if err then return
- 2520 gosub 1040:if fm<sm or fm=0 then return
- 2530 goto 2820
- 2540 print"[147]lines found= lines scanned="
- 2550 k=0:for mm=sm to fm:qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq)
- 2560 for i=1 to len(a$(ma))-len(tg$)+1
- 2570 if mid$(a$(ma),i,len(tg$))=tg$ then k=k+1:fs(k)=ma:goto 2590
- 2580 next i
- 2590 if k>49 then print"search terminating-array fs(k) full":goto 2620
- 2600 print"";k;"";mm-sm+1:next mm:print
- 2610 rem ***list search lines***
- 2620 if k=0 then 2660
- 2630 for i=1tok:ma=fs(i):tp$=str$(fnf4(ma)):printmid$(tp$,2);" ";mid$(a$(ma),3)
- 2640 if peek(152)=0 then wait 198,1,1:poke 198,0
- 2650 next i
- 2660 goto 890
- 2670 rem ***list directory***
- 2680 print"[147]":open 1,8,0,"$0":get#1,b$,d$
- 2690 get#1,b$,d$:get#1,b$,d$:b=0
- 2700 if b$<>"" then b=asc(b$)
- 2710 if d$<>"" then b=b+asc(d$)*256
- 2720 print""mid$(str$(b),2);tab(5);"[146]";
- 2730 get#1,d$:if st<>0 then 2810
- 2740 if d$<>chr$(34) then 2730
- 2750 get#1,d$:if d$ <>chr$(34) then printd$;:goto 2750
- 2760 get#1,d$:if d$=chr$(32) then 2760
- 2770 print tab(18);:c$=""
- 2780 c$=c$+d$:get#1,d$:if d$<>"" then 2780
- 2790 printtab(22)""left$(c$,3)
- 2800 if st=0 then 2690
- 2810 print"blocks free":close 1:goto 890
- 2820 rem ***confirmation routine***
- 2830 input"is above correct (y/n) y[157][157][157]";t$
- 2840 ift$="y"then oncmgoto 2870,2870,1390,2870,850,1150,2870,1310,1590,2870,2540
- 2850 ift$="n"then oncmgoto 70,70,2880,2880,2880,2880,2880,2880,2880,2880,2880
- 2860 goto 2830
- 2870 clr:end
- 2880 return
- 2890 rem ***input@ routine***
- 2900 ad=49152:ln=2960
- 2910 read vl:if vl<256 then poke ad,vl:su=su+vl:ad=ad+1:goto 2910
- 2920 if su=vl then su=0:ln=ln+10:goto 2910
- 2930 if vl=999 then 2950
- 2940 print"[147]data error in line";ln:stop
- 2950 sys 49152:return
- 2960 data 169,11,160,192,141,8,3,140,824
- 2970 data 9,3,96,32,115,0,201,133,589
- 2980 data 240,6,32,121,0,76,231,167,873
- 2990 data 32,115,0,201,64,240,6,32,690
- 3000 data 191,171,76,174,167,32,155,183,1149
- 3010 data 32,30,225,32,253,174,160,0,906
- 3020 data 32,183,255,41,100,208,20,132,971
- 3030 data 252,32,18,225,164,252,153,160,1256
- 3040 data 192,200,201,13,208,234,136,192,1376
- 3050 data 0,240,227,132,251,32,139,176,1197
- 3060 data 133,73,132,74,32,163,182,165,954
- 3070 data 251,32,117,180,160,2,185,97,1024
- 3080 data 0,145,73,136,16,248,164,251,1033
- 3090 data 192,0,240,9,136,185,160,192,1114
- 3100 data 145,98,136,16,248,32,204,255,1134
- 3110 data 76,174,167,417,999
-