home *** CD-ROM | disk | FTP | other *** search
/ Commodore Disk User Volume 1 #4 / Commodore_Disk_User_Vol.1_4_1988_-.d64 / basic editor (.txt) < prev    next >
Encoding:
Commodore BASIC  |  1988-01-01  |  9.8 KB  |  312 lines

  1. 10 rem ****************************
  2. 20 rem **  basic editor  ver1.0  **
  3. 30 rem ** by p.f.hayes  (c) 1988 **
  4. 40 rem ****************************
  5. 50 print"[147]initialising program":gosub 2900:clr:gosub 1720
  6. 60 gosub 1770
  7. 70 print"[147][158]**************basic editor**************[154]"
  8. 80 print"      1) exit from editor"
  9. 90 print"      2) re-initialise program"
  10. 100 print"      3) load file"
  11. 110 print"      4) input line(s)"
  12. 120 print"      5) list line(s)"
  13. 130 print"      6) delete line(s)"
  14. 140 print"      7) edit file"
  15. 150 print"      8) merge/append file"
  16. 160 print"      9) save file line(s)"
  17. 170 print"     10) change device number"
  18. 180 print"     11) search for string"
  19. 190 print"     12) directory"
  20. 200 input"command (1-12) = ";cm
  21. 210 if cm=1 then goto 2820
  22. 220 if cm=2 or cm=3 then input"erases current file:continue (y/n)   n[157][157][157]";t$
  23. 230 if cm=2 and t$="y" then clr:gosub 1720:gosub 1770
  24. 240 if cm=3 and t$="y" then clr:cm=3:gosub 1720:gosub 1770:gosub 1360
  25. 250 if cm>3 then on cm-3 gosub 280,830,1130,1850,1280,1480,1680,2510,2680
  26. 260 goto 70
  27. 270 rem ***input basic line(s)***
  28. 280 input"auto line numbering (y/n)   n[157][157][157]";t$
  29. 290 if t$="y" then 400
  30. 300 print"[147]":open 2,0
  31. 310 input@2,ip$:if ip$=chr$(95) then 370
  32. 320 if len(ip$)>80 then ip$=left$(ip$,80)
  33. 330 gosub 500:if ln=-1 then 370
  34. 340 if ln<1 or ln>65534 then print"invalid line number:re-enter":goto 310
  35. 350 gosub 550:if len(ip$)=0 then 380
  36. 360 gosub 580:if not err then print:goto 310
  37. 370 close 2:return
  38. 380 gosub 750:if not err then gosub 1190
  39. 390 print:goto 310
  40. 400 input"start line number = ";bl:input"line number increment = ";il
  41. 410 print"[147]":open 2,0:si=0
  42. 420 al$=mid$(str$(bl+si),2):printal$;" ";:input@2,ip$:if ip$=chr$(95) then 480
  43. 430 ip$=al$+ip$:if len(ip$)>80 then ip$=left$(ip$,80)
  44. 440 gosub 500:if ln=-1 then 480
  45. 450 if ln<1 or ln>65534 then print"invalid line number:re-enter":goto 420
  46. 460 gosub 550:if len(ip$)=0 then print:goto 420
  47. 470 gosub 580:if not err then si=si+il:print:goto 420
  48. 480 close 2:return
  49. 490 rem ***extract line number***
  50. 500 ln=-1:if len(ip$)=0 or ip$<"0" or left$(ip$,1)>"9" then 530
  51. 510 for t=1 to len(ip$):if mid$(ip$,t,1)<="9" and mid$(ip$,t,1)>="0" then next t
  52. 520 ln=val(left$(ip$,t-1)):ip$=mid$(ip$,t)
  53. 530 return
  54. 540 rem ***extract line text***
  55. 550 for t=1 to len(ip$):if mid$(ip$,t,1)=" " then next t
  56. 560 ip$=mid$(ip$,t):return
  57. 570 rem ***insert line in file array***
  58. 580 if ln<1 or ln>65534 then 720
  59. 590 gosub 750
  60. 600 tt=im
  61. 610 if not err then tt=ma:goto 660
  62. 620 if len(em$)=0 then 640
  63. 630 tt=fne1(tt):em$=mid$(em$,3):im=im-1:va=va-1
  64. 640 kk$=chr$(tt/256)+chr$(tt-256*int(tt/256))
  65. 650 mr$(qq)=left$(mr$(qq),2*lm-2)+kk$+mid$(mr$(qq),2*lm-1)
  66. 660 t1=fne2(ln):a$(tt)=chr$(ln-t1*256)+chr$(t1)+ip$
  67. 670 if not err then 730
  68. 680 for i=0 to 6:if len(mr$(i))<=250 then 710
  69. 690 mr$(i+1)=right$(mr$(i),2)+mr$(i+1)
  70. 700 mr$(i)=left$(mr$(i),len(mr$(i))-2):if peek(152)<>0 then t=fre(0)
  71. 710 next i:im=im+1
  72. 720 err=false
  73. 730 return
  74. 740 rem ***find line number in file array***
  75. 750 tt=im-va:pw=fnf5(tt):mm=fnf6(pw):for bv=pw-1 to 0 step -1
  76. 760 qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):t1=fnf4(ma):mm=fnf7(mm)
  77. 770 if mm>tt-1 then mm=tt-1
  78. 780 next bv
  79. 790 qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):t1=fnf4(ma):if t1>=ln then 810
  80. 800 mm=mm+1:goto 790
  81. 810 err=not(t1=ln):return
  82. 820 rem ***list lines***
  83. 830 gosub 930:if err then 910
  84. 840 goto 2820
  85. 850 print"[147]":gosub 1040:if fm<sm or fm=0 then 910
  86. 860 if dev=4 then open 2,dev:cmd 2
  87. 870 for mm=sm to fm:qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):gosub 1090:next mm
  88. 880 if dev=4 then print#2:close 2:gosub 1680
  89. 890 if peek(152)=0 then print"< return for main menu >"
  90. 900 if peek(152)=0 then gett$:if t$="" then 900
  91. 910 return
  92. 920 rem ***input line number range***
  93. 930 print"enter line number range (eg 100-500)"
  94. 940 ip$="":input"first line-last line = ";ip$
  95. 950 sl=1:fl=65534:err=false
  96. 960 if len(ip$)=0 then 1020
  97. 970 gosub 500:if ln>=0 then sl=ln:goto 990
  98. 980 if ln>-1 then fl=-ln:goto 1020
  99. 990 gosub 550:if len(ip$)=0 then fl=sl:goto 1020
  100. 1000 ip$=mid$(ip$,2):gosub 550
  101. 1010 if len(ip$)>0 then gosub 500:fl=ln
  102. 1020 err=sl<1 or sl>65534 or fl<1 or fl>65534 or err:return
  103. 1030 rem ***line number range markers***
  104. 1040 ln=sl:gosub 750:sm=mm
  105. 1050 ln=fl:gosub 750:fm=mm
  106. 1060 if err then fm=fm-1
  107. 1070 return
  108. 1080 rem ***list lines marked by ma***
  109. 1090 tp$=str$(fnf4(ma)):printmid$(tp$,2);" ";mid$(a$(ma),3)
  110. 1100 if peek(152)=0 then wait 198,1,1:poke 198,0
  111. 1110 return
  112. 1120 rem ***delete line(s)***
  113. 1130 gosub 930:if err then 1170
  114. 1140 goto 2820
  115. 1150 gosub 1040:if fm<sm then 1170
  116. 1160 for mm=fmtosm step -1:qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):gosub 1190:nextmm
  117. 1170 return
  118. 1180 rem ***delete line marked by ma***
  119. 1190 mr$(qq)=left$(mr$(qq),2*lm-2)+mid$(mr$(qq),2*lm+1)
  120. 1200 for i=0 to 6
  121. 1210 if len(mr$(i))>=250 or len(mr$(i+1))=0 then 1230
  122. 1220 mr$(i)=mr$(i)+left$(mr$(i+1),2):mr$(i+1)=mid$(mr$(i+1),3)
  123. 1230 next i:va=va+1:a$(ma)=""
  124. 1240 if len(em$)>250 then 1260
  125. 1250 em$=chr$(ma/256)+chr$(ma-256*int(ma/256))+em$
  126. 1260 return
  127. 1270 rem ***merge file from device***
  128. 1280 gosub 1630:if dev=8 then tn$=tn$+",s,r"
  129. 1290 if dev<>1 and dev<>8 then return
  130. 1300 goto 2820
  131. 1310 open 2,dev,0,tn$
  132. 1320 input@2,ip$:gosub 500:if ln=-1 or st then 1340
  133. 1330 gosub 550:gosub 580:goto 1320
  134. 1340 close 2:return
  135. 1350 rem ***load file from device***
  136. 1360 gosub 1630:if dev=8 then tn$=tn$+",s,r"
  137. 1370 if dev<>1 and dev<>8 then return
  138. 1380 goto 2820
  139. 1390 open 2,dev,0,tn$
  140. 1400 input@2,ip$:gosub 500:if ln=-1 or st then 1460
  141. 1410 gosub 550:gosub 580
  142. 1420 input@2,ip$:gosub 500:if ln=-1 or st then 1460
  143. 1430 gosub 550:mm=mm+1:qq=fnf1(mm):lm=fnf2(mm)
  144. 1440 if ln<1 or ln>65534 then 1420
  145. 1450 err=-1:gosub 600:goto 1420
  146. 1460 close 2:return
  147. 1470 rem ***save file to device***
  148. 1480 gosub 1630:gosub 930:if dev<>1 and dev<>8 then 1610
  149. 1490 if err then print"invalid lines:re-enter commands":goto 1480
  150. 1500 gosub 1040:err=(fl<sl):if err then goto 1490
  151. 1510 if dev<>8 then 1580
  152. 1520 print"enter file operation :"
  153. 1530 input"c[146]reate,o[146]verwrite,a[146]ppend (c/o/a) ";t$
  154. 1540 if t$="c" then tn$=tn$+",s,w":goto 1580
  155. 1550 if t$="o" then tn$="@0:"+tn$+",s,w":goto 1580
  156. 1560 if t$="a" then tn$=tn$+",s,a":goto 1580
  157. 1570 goto 1510
  158. 1580 goto 2820
  159. 1590 open 2,dev,2,tn$:cmd 2:gosub 870
  160. 1600 print#2:close 2
  161. 1610 return
  162. 1620 rem ***input file name***
  163. 1630 tn$="":gosub 1680:if dev=4 then 1660
  164. 1640 input"file name = ";tn$:lt=len(tn$)
  165. 1650 if lt>16 or lt<1 then print"file name invalid":goto 1640
  166. 1660 return
  167. 1670 rem ***change device number***
  168. 1680 print"(printer=4:disc=8:tape=1)"
  169. 1690 print spc(21) dev
  170. 1700 input"[145]new device number = ";dev:return
  171. 1710 rem ***initialise program & define functions***
  172. 1720 dim mr$(7),a$(300),fs(50):im=2:va=0
  173. 1730 mr$(0)=chr$(0)+chr$(0)+chr$(0)+chr$(1)
  174. 1740 a$(0)=chr$(0)+chr$(0):a$(1)=chr$(255)+chr$(255)
  175. 1750 cp$=""
  176. 1760 o$="                                        ":o$=o$+o$:return
  177. 1770 def fnf1(mm)=int((mm-1)/125):def fnf2(mm)=mm-125*qq
  178. 1780 def fnf3(qq)=256*asc(mid$(mr$(qq),2*lm-1))+asc(mid$(mr$(qq),2*lm))
  179. 1790 def fnf4(ma)=asc(mid$(a$(ma),1,1))+256*asc(mid$(a$(ma),2,1))
  180. 1800 def fnf5(tt)=int(log(tt)/.693147)
  181. 1810 def fnf6(pw)=2^pw:def fnf7(mm)=mm+2^bv*((ln<t1)-(ln>t1))
  182. 1820 def fnf8(p)=1024+lr*40+p:def fne1(tt)=256*asc(em$)+asc(mid$(em$,2))
  183. 1830 def fne2(ln)=int(ln/256):return
  184. 1840 rem ***edit file***
  185. 1850 p=0:lr=1:lp=1:ai=0:tf=0:ns=11:tp$="":fq=0:if th=1 then th=0:goto 1930
  186. 1860 if tc=1 then tc=0:goto 1930
  187. 1870 input"edit from linenumber = ";ln:lt=ln
  188. 1880 gosub 750:if err and tf=0 or ln<1 or ln>65534 then 1900
  189. 1890 goto 1930
  190. 1900 input"invalid line:r[146]e-enter or e[146]xit";t$
  191. 1910 if t$="e" then return
  192. 1920 goto 1870
  193. 1930 if ns>im-mm-va then ns=im-mm-va
  194. 1940 if ns=0 and (im-va)>2 then 2420
  195. 1950 if ns=0 then return
  196. 1960 pt=mm:qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq):lt=val(str$(fnf4(ma))):print"[147]"
  197. 1970 for pr=1 to ns
  198. 1980 qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq)
  199. 1990 tp$=str$(fnf4(ma))
  200. 2000 tp$=mid$(tp$,2)+" "+mid$(a$(ma),3)
  201. 2010 cd$=left$(cp$,lr-(2*int(lr/2)-lr<>0)-1)
  202. 2020 print"";cd$;o$;"[145][145]";tp$
  203. 2030 mm=mm+1:lr=lr+2:next pr
  204. 2040 lr=lp+2*(lp=ns*2+1)
  205. 2050 ac=ai:ai=pt+int((lr+1)/2)-1:if ai=ac and tf=0 then 2090
  206. 2060 qq=int((ai-1)/125):lm=ai-125*qq:tf=0
  207. 2070 ma=fnf3(qq):tp$=str$(fnf4(ma))
  208. 2080 tp$=mid$(tp$,2)+" "+mid$(a$(ma),3)
  209. 2090 cd$=left$(cp$,lr-(2*int(lr/2)-lr<>0)-1)
  210. 2100 print"";cd$;o$;"[145][145]";tp$
  211. 2110 ch=peek(fnf8(p)):poke 54272+fnf8(p),14:poke fnf8(p),160
  212. 2120 for nu=1 to 5:next nu:poke fnf8(p),ch
  213. 2130 get sc$:if sc$="" then 2110
  214. 2140 if sc$=chr$(34) then fq=-(fq=0)
  215. 2150 if sc$=chr$(13) then 2440
  216. 2160 if sc$=chr$(141) then return
  217. 2170 if sc$=chr$(19) and fq=0 then return
  218. 2180 if sc$=chr$(147) and fq=0 then return
  219. 2190 if sc$=chr$(133) then 2400
  220. 2200 if sc$=chr$(137) then 2420
  221. 2210 if sc$=chr$(134) then p=0:lr=1:goto 2050
  222. 2220 if sc$=chr$(138) then p=0:lr=ns*2-1:goto 2050
  223. 2230 if sc$=chr$(135) then p=0:goto 2110
  224. 2240 if sc$=chr$(139) then p=len(tp$)-1:goto 2110
  225. 2250 if sc$=chr$(136) then return
  226. 2260 if sc$=chr$(140) then print"[147]":goto 1850
  227. 2270 if p>0 and sc$=chr$(20) then tp$=left$(tp$,p-1)+mid$(tp$,p+1):p=p-1
  228. 2280 if sc$=chr$(20) then 2050
  229. 2290 if sc$="[145]" and p<=39 and fq=0 then lr=lr+2*(lr>1):p=0:goto 2050
  230. 2300 if sc$="[145]" and p>39 and fq=0 then p=p-40:goto 2110
  231. 2310 if sc$="" and p<=39 and len(tp$)>40 and fq=0 then p=40:goto 2110
  232. 2320 if sc$="" and fq=0 then lr=lr-2*(lr<ns*2-1):p=0:goto 2050
  233. 2330 if len(tp$)=80 then 2370
  234. 2340 if sc$=chr$(148) then tp$=left$(tp$,p)+" "+mid$(tp$,p+1):goto 2050
  235. 2350 if fq=1 then tp$=left$(tp$,p)+sc$+mid$(tp$,p+2):p=p-1*(p<79):goto 2050
  236. 2360 ifsc$<>"[157]"andsc$<>""thentp$=left$(tp$,p)+sc$+mid$(tp$,p+2):p=p-1*(p<79):goto2050
  237. 2370 if sc$="[157]" and p>0 then p=p-1
  238. 2380 if sc$="" and p<len(tp$)-1 then p=p+1
  239. 2390 goto 2110
  240. 2400 mm=pt+11:if mm>im-va then mm=im-va-1
  241. 2410 th=1:goto 1850
  242. 2420 mm=pt-11:if mm<2 then mm=2
  243. 2430 tc=1:goto 1850
  244. 2440 ip$=left$(tp$,len(tp$))
  245. 2450 gosub 500:if ln<1 or ln>65534 or ln=-1 then 2490
  246. 2460 gosub 550:if len(ip$)=0 then 2480
  247. 2470 gosub 580:goto 2490
  248. 2480 gosub 750:if not err then gosub 1190
  249. 2490 tf=1:p=0:lp=lr:ln=lt:lr=1:ns=11:fq=0:goto 1880
  250. 2500 rem ***search routine***
  251. 2510 input"input search string = ";tg$:gosub 930:if err then return
  252. 2520 gosub 1040:if fm<sm or fm=0 then return
  253. 2530 goto 2820
  254. 2540 print"[147]lines found=    lines scanned="
  255. 2550 k=0:for mm=sm to fm:qq=fnf1(mm):lm=fnf2(mm):ma=fnf3(qq)
  256. 2560 for i=1 to len(a$(ma))-len(tg$)+1
  257. 2570 if mid$(a$(ma),i,len(tg$))=tg$ then k=k+1:fs(k)=ma:goto 2590
  258. 2580 next i
  259. 2590 if k>49 then print"search terminating-array fs(k) full":goto 2620
  260. 2600 print"";k;"";mm-sm+1:next mm:print
  261. 2610 rem ***list search lines***
  262. 2620 if k=0 then 2660
  263. 2630 for i=1tok:ma=fs(i):tp$=str$(fnf4(ma)):printmid$(tp$,2);" ";mid$(a$(ma),3)
  264. 2640 if peek(152)=0 then wait 198,1,1:poke 198,0
  265. 2650 next i
  266. 2660 goto 890
  267. 2670 rem ***list directory***
  268. 2680 print"[147]":open 1,8,0,"$0":get#1,b$,d$
  269. 2690 get#1,b$,d$:get#1,b$,d$:b=0
  270. 2700 if b$<>"" then b=asc(b$)
  271. 2710 if d$<>"" then b=b+asc(d$)*256
  272. 2720 print""mid$(str$(b),2);tab(5);"[146]";
  273. 2730 get#1,d$:if st<>0 then 2810
  274. 2740 if d$<>chr$(34) then 2730
  275. 2750 get#1,d$:if d$ <>chr$(34) then printd$;:goto 2750
  276. 2760 get#1,d$:if d$=chr$(32) then 2760
  277. 2770 print tab(18);:c$=""
  278. 2780 c$=c$+d$:get#1,d$:if d$<>"" then 2780
  279. 2790 printtab(22)""left$(c$,3)
  280. 2800 if st=0 then 2690
  281. 2810 print"blocks free":close 1:goto 890
  282. 2820 rem ***confirmation routine***
  283. 2830 input"is above correct (y/n)  y[157][157][157]";t$
  284. 2840 ift$="y"then oncmgoto 2870,2870,1390,2870,850,1150,2870,1310,1590,2870,2540
  285. 2850 ift$="n"then oncmgoto 70,70,2880,2880,2880,2880,2880,2880,2880,2880,2880
  286. 2860 goto 2830
  287. 2870 clr:end
  288. 2880 return
  289. 2890 rem ***input@ routine***
  290. 2900 ad=49152:ln=2960
  291. 2910 read vl:if vl<256 then poke ad,vl:su=su+vl:ad=ad+1:goto 2910
  292. 2920 if su=vl then su=0:ln=ln+10:goto 2910
  293. 2930 if vl=999 then 2950
  294. 2940 print"[147]data error in line";ln:stop
  295. 2950 sys 49152:return
  296. 2960 data 169,11,160,192,141,8,3,140,824
  297. 2970 data 9,3,96,32,115,0,201,133,589
  298. 2980 data 240,6,32,121,0,76,231,167,873
  299. 2990 data 32,115,0,201,64,240,6,32,690
  300. 3000 data 191,171,76,174,167,32,155,183,1149
  301. 3010 data 32,30,225,32,253,174,160,0,906
  302. 3020 data 32,183,255,41,100,208,20,132,971
  303. 3030 data 252,32,18,225,164,252,153,160,1256
  304. 3040 data 192,200,201,13,208,234,136,192,1376
  305. 3050 data 0,240,227,132,251,32,139,176,1197
  306. 3060 data 133,73,132,74,32,163,182,165,954
  307. 3070 data 251,32,117,180,160,2,185,97,1024
  308. 3080 data 0,145,73,136,16,248,164,251,1033
  309. 3090 data 192,0,240,9,136,185,160,192,1114
  310. 3100 data 145,98,136,16,248,32,204,255,1134
  311. 3110 data 76,174,167,417,999
  312.