10 rem ************************************************************************ 20 rem * 30 rem * NED Line Editor Version 1.0 40 rem * Copyright (C) 2004, 2005 SylvaWare 50 rem * 60 rem ************************************************************************ 70 : 80 if peek(788)=1 then end else if peek(36)<4 then print "NED requires NBASIC Version 1.2 or later": end 90 : 100 poke 1210,0: poke 6023,0: poke 20570,0: poke 46332,0: init: sz=100: si=10: dim bf$(sz): ml=65535: tl=0: cl=-1: mf=false 110 : 120 def fnchkfn(f$)=verify(f$) and mapped(splitname$(fullname$(f$),-1)) 130 : 140 line input "File";ff$: ff$=trim$(ff$): if ff$="" then end 150 : 160 if not fnchkfn(ff$) then print "Invalid file name": goto 140 else if not exists(ff$) then print "New file": goto 340 170 : 180 on error goto 300: open ff$ for input as #1 190 if eof(1) then 260 200 line input #1,a$: a$=left$(a$,255) 210 if tl<=sz then 240 220 sz=sz+si: if sz>ml then sz=ml 230 redim preserve bf$(sz) 240 bf$(tl)=a$: tl=tl+1: if tl>ml then print "Buffer full": goto 260 250 goto 190 260 close #1: on error goto 0 270 if tl>0 then cl=0 280 goto 340 290 : 300 print err$(err): end 310 : 320 print err$(err): abort #1: resume 360 330 : 340 print "Enter ? for help" 350 : 360 line input "*",cs$: cs$=trim$(cs$): cc$=ucase$(left$(cs$)): if cc$="" then 1340 else if len(cs$)>0 then cs$=trim$(right$(cs$,len(cs$)-1)) 370 : 380 rem QUIT 390 if cc$<>"Q" then 430 else if len(cs$)>0 then 1400 else if not mf then end 400 print "File modified, quit (Y/N)? ";: k$=ucase$(input$(1)): if k$="Y" then end else if k$="N" then print: goto 360 else print: goto 400 410 : 420 rem EXIT 430 if cc$<>"E" then 490 else if len(cs$)>0 then 1400 else if not mf then end 440 on error goto 320: open ff$ for output as #1 450 if tl>0 then for i=0 to tl-1: print #1,bf$(i): next i 460 close #1: end 470 : 480 rem WRITE 490 if cc$<>"W" then 550 else if len(cs$)>0 then 1400 else if not mf then 360 500 on error goto 320: open ff$ for output as #1 510 if tl>0 then for i=0 to tl-1: print #1,bf$(i): next i 520 close #1: on error goto 0: mf=false: goto 360 530 : 540 rem LIST 550 if cc$<>"L" then 640 else if len(cs$)=0 then if tl=0 then 360 else sl=0: el=tl-1: goto 600 560 ln=0: gosub 1430: sl=ln: if sl=-1 or sl>=tl then 1400 570 cs$=ltrim$(cs$): if left$(cs$)<>"," then el=sl: goto 590 else cs$=ltrim$(right$(cs$,len(cs$)-1)) 580 ln=tl-1: gosub 1430: el=ln: if el=-1 or el>=tl or sl>el then 1400 590 if len(cs$)>0 then 1400 600 for i=sl to el: print using "#####:";i+1;: if i=cl then print "*"; else print " "; 610 print bf$(i): next i: goto 360 620 : 630 rem INSERT 640 if cc$<>"I" then 760 else if len(cs$)=0 and tl=0 then 890 650 ln=cl: gosub 1430: sl=ln: if sl=-1 or sl>=tl then 1400 660 if len(cs$)>0 then 1400 else cl=sl 670 if tl<=ml then 690 680 print "Buffer full": goto 360 690 print using "#####: ";cl+1;: line input i$: if i$="" then 360 700 if tl<=sz then 730 710 sz=sz+si: if sz>ml then sz=ml 720 redim preserve bf$(sz) 730 for i=tl-1 to cl step -1: bf$(i+1)=bf$(i): next i: bf$(cl)=i$: mf=true: cl=cl+1: tl=tl+1: goto 670 740 : 750 rem DELETE 760 if cc$<>"D" then 870 else if len(cs$)=0 then if tl=0 then 360 else sl=cl: el=cl: goto 810 770 ln=cl: gosub 1430: sl=ln: if sl=-1 or sl>=tl then 1400 780 cs$=ltrim$(cs$): if left$(cs$)<>"," then el=sl: goto 800 else cs$=ltrim$(right$(cs$,len(cs$)-1)) 790 ln=tl-1: gosub 1430: el=ln: if el=-1 or el>=tl or sl>el then 1400 800 if len(cs$)>0 then 1400 810 if el=tl-1 then tl=sl: goto 830 820 j=sl: for i=el+1 to tl-1: bf$(j)=bf$(i): j=j+1: next i: tl=tl-(el-sl+1) 830 cl=sl: if cl>=tl then cl=tl-1 840 mf=true: goto 360 850 : 860 rem APPEND 870 if cc$<>"A" then 960 else if len(cs$)>0 then 1400 880 if tl<=ml then 890 else 680 890 print using "#####: ";tl+1;: line input i$: if i$="" then goto 360 900 if tl<=sz then 930 910 sz=sz+si: if sz>ml then sz=ml 920 redim preserve bf$(sz) 930 bf$(tl)=i$: mf=true: cl=tl: tl=tl+1: goto 880 940 : 950 rem BLANK 960 if cc$<>"B" then 1050 else if len(cs$)=0 and tl=0 then sl=cl: goto 1020 970 ln=cl: gosub 1430: sl=ln: if sl=-1 or sl>=tl then 1400 980 if len(cs$)>0 then 1400 else cl=sl 990 if tl<=ml then 1020 else 680 1000 sz=sz+si: if sz>ml then sz=ml 1010 redim preserve bf$(sz) 1020 for i=tl-1 to cl step -1: bf$(i+1)=bf$(i): next i: bf$(sl)=i$: mf=true: tl=tl+1: goto 360 1030 : 1040 rem EDIT LINE 1050 if not digit(cc$) then 1120 1060 l$=cc$: i=1 1070 if i<=len(cs$) then if digit(mid$(cs$,i)) then l$=l$+mid$(cs$,i): i=i+1: goto 1070 else 1400 1080 if len(l$)>5 then 1400 else l=val(l$): if l=0 or l>tl then 1400 1090 cl=l-1: goto 1370 1100 : 1110 rem EDIT CURRENT LINE 1120 if cc$<>"." then 1160 else if len(cs$)>0 then 1400 1130 goto 1370 1140 : 1150 rem EDIT LAST LINE 1160 if cc$<>"$" then 1200 else if len(cs$)>0 then 1400 1170 cl=tl-1: goto 1370 1180 : 1190 rem HELP 1200 if cc$<>"?" then 1330 else if len(cs$)>0 then 1400 1210 print "A Append line(s) to end of file" 1220 print "B[line] Insert blank line" 1230 print "D[[start][,[end]]] Delete line(s)" 1240 print "E Save changes and quit" 1250 print "I[line] Insert line(s)" 1260 print "L[[start][,[end]]] List line(s)" 1270 print "Q Quit" 1280 print "W Write" 1290 print " Edit line" 1300 goto 360 1310 : 1320 rem EDIT NEXT LINE 1330 if cc$<>"" then 1400 1340 if cl=-1 or cl=tl-1 then 360 1350 cl=cl+1: goto 1370 1360 : 1370 print using "#####: ";cl+1;: line edit(bf$(cl)) bf$(cl): mf=true: print: goto 360 1380 : 1390 rem command error 1400 print "Command error": goto 360 1410 : 1420 rem command parser 1430 if cs$="" then return else if left$(cs$)="," then return 1440 if left$(cs$)="." then ln=cl: cs$=right$(cs$,len(cs$)-1): return else if left$(cs$)="$" then ln=tl-1: cs$=right$(cs$,len(cs$)-1): return else l$="" 1450 if digit(left$(cs$)) then l$=l$+left$(cs$): cs$=right$(cs$,len(cs$)-1): if len(cs$)>0 then 1450 1460 if len(l$)>5 then pop: goto 1400 else if len(l$)>0 then ln=val(l$)-1 1470 return