!ezBAS BASIC! editor ! Bundle.create globals Bundle.put globals,"mode","console" FN.DEF VERSION$() FN.RTN "ezBAS! editor 0.11" FN.END FN.DEF IsApk() FILE.EXISTS editorMode, "../source/ezbas.bas" FN.RTN !editorMode FN.END FN.DEF dmode(m$) Bundle.get 1,"mode",oldm$ IF oldm$=m$ THEN FN.RTN 0 Bundle.put 1,"mode",m$ IF oldm$="html" THEN HTML.CLOSE IF oldm$="gr" THEN GR.CLOSE IF m$="html" THEN HTML.OPEN 0 IF m$="gr" THEN GR.OPEN 255,0,0,0,0 IF m$="console" THEN CLS FN.END FN.DEF readln$(f$) FILE.EXISTS e,f$ if e then grabfile a$,f$ FN.RTN TRIM$(a$) FN.END FN.DEF writeln(f$,msg$) TEXT.OPEN w,h,f$ TEXT.WRITELN h,msg$ TEXT.CLOSE h FN.END FN.DEF get_text$(p$,d$) INPUT p$,s$,d$,canc IF canc THEN FN.RTN "" FN.RTN s$ FN.END FN.DEF promptreplace$(s$,f$,r$) ! case insensitive replace with prompts LET start=1 LET zf=LEN(f$) LET zr=LEN(r$) LET ff$=LOWER$(f$) LET lwr$=LOWER$(s$) DO LET i=IS_IN(ff$,lwr$,start) IF !i IF ct POPUP INT$(ct)+" replaced" ELSE POPUP ff$+" not found!" ENDIF D_U.BREAK ENDIF IF askyn("replace? "+MID$(s$,i-50,100)) news$+=MID$(s$,start,i-start)+r$ ct++ ELSE news$+=MID$(s$,start,i-start)+ff$ ENDIF LET start=i+zf UNTIL !i news$+=MID$(s$,start,LEN(s$)-start+1) FN.RTN news$ FN.END FN.DEF nocasereplace$(s$,f$, r$) ! case insensitive replace$() LET start=1 LET zf=LEN(f$) LET zr=LEN(r$) LET ff$=LOWER$(f$) LET lwr$=LOWER$(s$) DO LET i=IS_IN(ff$,lwr$,start) IF !i THEN D_U.BREAK news$+=MID$(s$,start,i-start)+r$ LET start=i+zf UNTIL !i news$+=MID$(s$,start,LEN(s$)-start+1) FN.RTN news$ FN.END FN.DEF dangle$(f$) ! search for endifs without a matching if ! doesn't work perfectly but might find something TEXT.OPEN R,H,f$ DO TEXT.READLN H,A$ a$=TRIM$(LOWER$(a$)) line++ IF STARTS_WITH("!! ",a$) DO TEXT.READLN H,A$ a$=TRIM$(LOWER$(a$)) line++ UNTIL STARTS_WITH("!! ",a$) | a$="eof" TEXT.READLN h,a$ a$=TRIM$(LOWER$(a$)) line++ ENDIF IF a$="eof" THEN D_U.BREAK IF STARTS_WITH("if ",a$) & !IS_IN(" then ",a$) THEN nest++ IF STARTS_WITH("endif",a$) & !STARTS_WITH("!",a$) & !STARTS_WITH("rem ",a$) THEN nest-- IF nest < 0 d$+= "dangling ENDIF at line "+INT$(line)+"\n" errs++ nest=0 ENDIF UNTIL A$="eof" d$+=INT$(errs)+" possible errors\n\n" TEXT.CLOSE h FN.RTN d$ FN.END FN.DEF orphans$(dat$,fl) ! search for unused functions dmode("console") dat$ = LOWER$(REPLACE$(dat$," ","")) DO pos = IS_IN("fn."+"def",dat$,pos) IF pos pos2 = IS_IN ( "(", dat$, pos) funName$ = MID$ ( dat$, pos+6, pos2-pos-6) LIST.ADD fl,funName$ pos = pos2 ENDIF UNTIL !pos LIST.SIZE fl,z IF z=0 THEN FN.RTN "no orphans" dat$ = LOWER$(REPLACE$(dat$," ","")) LIST.CREATE S, unused FOR i=1 TO z LIST.GET fl,i,n$ pos=IS_IN(n$+"(", dat$) IF pos>0 & MID$(dat$,pos-6,6)="fn.def" pos += 6+LEN(n$) pos=IS_IN(n$+"(", dat$, pos) ENDIF IF !pos THEN LIST.ADD unused,n$ NEXT LIST.SIZE unused,z IF !z s$="no orphans found" FN.RTN s$ ENDIF s$=INT$(z)+" possible orphan fns\n" FOR i=1 TO z LIST.GET unused,i,n$ s$+= n$+"\n" NEXT FN.RTN s$ FN.END FN.DEF waitclick$() DO PAUSE 50 HTML.GET.DATALINK data$ UNTIL data$ <> "" IF data$="STT" THEN FN.RTN data$ IF IS_IN("BAK:",data$)=1 EXIT ELSEIF IS_IN("DAT:",data$)=1 LET data$=MID$(data$,5) ELSEIF IS_IN("LNK:file:///",data$)=1&IS_IN("?",data$) %' Submit link LET i=IS_IN("?",data$) LET data$="SUBMIT&"+MID$(data$,i+1)+"&" ENDIF FN.RTN data$ FN.END FN.DEF htmledit$(p$,s$) dmode("html") s$=REPLACE$(s$,"&","&") s$=REPLACE$(s$,"<","<") s$=REPLACE$(s$,">",">") w$="" w$+="" w$+="" w$+="edit text" w$+="" w$+="" w$+="" w$+="" w$+="
" w$+="

###prompt

" w$+="" w$+="
" w$+="" w$+="" w$+="
" w$=REPLACE$(w$,"###prompt",p$) w$=REPLACE$(w$,"###edit",TRIM$(s$)) HTML.LOAD.STRING w$ HTML.LOAD.URL "javascript:DL(document.getElementById('id'))" r$=waitclick$() r$=REPLACE$(r$,"SUBMIT&submit=Done&id=","") r$=REPLACE$(r$,"&","&") r$=REPLACE$(r$,"<","<") r$=REPLACE$(r$,">",">") r$=DECODE$("URL","UTF-8",r$) FN.RTN LEFT$(r$,LEN(r$)-1) FN.END FN.DEF asklist$(l,msg$,c) ! drop down menu version ! returns user choice from list l with prompt msg$, c=0 if cancel or error r$="
" h$="" h$+="" h$+="" h$+=" Home" h$+="" h$+="" h$+="" h$+="
" h$+="
" h$+="
" h$+="

"+msg$ +"

" h$+="" LIST.SIZE l,z h$+="
" FOR i=1 TO z LIST.GET l,i,s$ s$=REPLACE$(s$,"'","'") col$="#005500" high$="#fff" IF IS_IN("###",s$) col$="#004" high$="#ffa" ENDIF IF IS_IN("$$red",s$) col$="#400" ENDIF IF IS_IN("$$tag",s$) high$="#aff" ENDIF s$=REPLACE$(s$,"$$red","") s$=REPLACE$(s$,"$$tag","") but$="
" h$+=but$ NEXT h$+="
" h$=REPLACE$(h$,"~","\"") dmode("html") HTML.LOAD.STRING h$ DO DO PAUSE 50 HTML.GET.DATALINK data$ PAUSE 100 UNTIL data$ <> "" IF IS_IN("DAT:",data$)=1 LET data$=MID$(data$,5) ELSEIF IS_IN("LNK:file:///",data$)=1&IS_IN("?",data$) %' Submit link LET i=IS_IN("?",data$) LET data$="SUBMIT&"+MID$(data$,i+1)+"&" ENDIF LET r$=data$ IF IS_NUMBER(r$) c=VAL(r$) ELSE c=0 FN.RTN r$ ENDIF UNTIL c>0 | r$="" !popup r$ IF r$="" THEN FN.RTN "" LIST.GET l,c,s$ s$=REPLACE$(s$,"$$blue","") s$=REPLACE$(s$,"$$red","") s$=REPLACE$(s$,"$$tag","") FN.RTN s$ FN.END FN.DEF oldaskyn(p$) LIST.CREATE s,m LIST.ADD m,"yes","no" c=0 asklist$(m,p$,&c) LIST.CLEAR m IF c=1 THEN FN.RTN 1 FN.RTN 0 FN.END FN.DEF askyn(m$) CALL dmode("console") DIALOG.MESSAGE,m$,c,"yes","no" IF c=1 THEN FN.RTN 1 FN.RTN 0 FN.END FN.DEF choosefile$(path$) dloop: ARRAY.DELETE d1$[] FILE.DIR path$,d1$[] ARRAY.LENGTH length,d1$[] ARRAY.DELETE d2$[] DIM d2$[length+1] d2$[1]=".." FOR i=1 TO length d2$[i+1]=d1$[i] NEXT s=0 LIST.CREATE s,l ARRAY.LENGTH z,d2$[] FOR i=1 TO z LIST.ADD l,d2$[i] NEXT asklist$(l,VERSION$()+"
select file",&s) IF s>1 n=IS_IN("(d)",d2$[s]) IF n=0 FN.RTN path$+d2$[s] END ENDIF dname$=LEFT$(d2$[s],n-1) path$=path$+dname$+"/" GOTO dloop ENDIF IF path$="" path$="../" GOTO dloop ENDIF ARRAY.DELETE p$[] SPLIT p$[],path$,"/" ARRAY.LENGTH length,p$[] IF p$[length]=".." path$+="../" GOTO dloop ENDIF IF length=1 path$="" GOTO dloop ENDIF path$="" FOR i=1 TO length-1 path$+=p$[i]+"/" NEXT GOTO dloop FN.END FN.DEF edit$(p$,s$) dmode("console") s$+="\n\n\n\n\n" s$=htmledit$(p$,s$) !TEXT.INPUT s$,s$,p$ s$=TRIM$(s$) SPLIT a$[],s$,"\n" ARRAY.LENGTH z,a$[] FOR i=1 TO z IF STARTS_WITH(":",TRIM$(a$[i])) a$[i]=REPLACE$(a$[i],":","FN.DEF ") ENDIF IF STARTS_WITH(";",TRIM$(a$[i])) a$[i]=REPLACE$(a$[i],";","FN.END") ENDIF IF TRIM$(UPPER$(a$[i]))="E" a$[i]="ENDIF" ENDIF NEXT JOIN A$[],x$,"\n" X$=nocasereplace$(x$,"FN.DEF","FN.DEF") FN.RTN TRIM$(x$) FN.END FN.DEF ParseProgram(a$,l) ! break program in a$ into string list l SPLIT r$[],a$,"\n" ARRAY.LENGTH z,r$[] LET s$="" FOR i=1 TO z LET rr$=r$[i]+"\n" LET tr$=TRIM$(UPPER$(rr$)) LET fd=STARTS_WITH("FN.DEF",tr$) LET fe=STARTS_WITH("FN.END",tr$) LET go2=(!STARTS_WITH("!",tr$) & ENDS_WITH(":",tr$) ) LET rt=STARTS_WITH("RETURN",tr$) IF fd |fe |go2 |rt IF fd | go2 LET section$=TRIM$(s$) IF LEN(section$) THEN LIST.ADD l,section$ LET s$=rr$ ELSE s$+=rr$: LET rr$="":LET section$=TRIM$(s$) IF LEN(section$) THEN LIST.ADD l,section$ LET s$="" ENDIF ELSE s$+=rr$ ENDIF NEXT LET section$=TRIM$(s$) IF LEN(section$)>0 THEN LIST.ADD l,section$ FN.END ! MAIN Asked=0 another: dmode("console") f$=readln$("ez.txt") FILE.EXISTS fe,f$ IF !fe | code$="###LOAD" f$=choosefile$("/../../rfo-basic/source/") writeln("ez.txt",f$) ENDIF let a$=readln$(f$) !GRABFILE a$,f$ DO LET a$=REPLACE$(a$,"\n\n\n","\n") UNTIL !IS_IN("\n\n\n",a$) LIST.CREATE s,l LIST.CREATE s,flist LIST.CREATE s,menu LIST.CREATE s,unused LIST.CREATE s,tags refresh: LIST.CLEAR l LIST.CLEAR flist LIST.CLEAR menu LIST.CLEAR unused ParseProgram(a$,l) UNDIM fnc$[] LIST.TOARRAY l,fnc$[] ARRAY.LENGTH z,fnc$[] LIST.CLEAR l FOR i=1 TO z LET m$=WORD$(fnc$[i],1,"\n") m$=REPLACE$(M$,"FN.DEF ","") LIST.ADD flist,m$ LIST.SEARCH TAGS,M$,tagged IF tagged THEN m$+="$$tag" LIST.ADD menu,m$ NEXT LET c=0 lf$=readln$("lastfn") LIST.SEARCH flist,lf$,lf IF !asked & lf > 0 & lf <= z asked=1 IF askyn("jump to section "+lf$+"?") LET fnc$[lf]=TRIM$(edit$("edit",fnc$[lf])) ENDIF ELSE asked=1 LET code$=asklist$(menu,VERSION$()+"
"+f$,&c) !popup code$ IF c>0 & c<=z & !STARTS_WITH("###",code$) % edit code section fe$=TRIM$(edit$("edit",fnc$[c])) LET fnc$[c]=fe$ LIST.GET flist,c,lf$ writeln("lastfn",lf$) ENDIF ENDIF IF CODE$="###DEL" LET x$= asklist$(flist,"delete which?",&c) IF askyn("delete "+x$) IF askyn("are you sure?") THEN fnc$[c]="" ENDIF ENDIF IF CODE$="###COPY" clip$="" DO LET x$=asklist$(flist,"COPY which?",&c) IF askyn("COPY "+x$) CLIP$+=fnc$[c]+"\n\n" ENDIF UNTIL !askyn("clip more?") CLIPBOARD.PUT clip$ POPUP "copied to clipboard" ENDIF IF code$="###CHECK" edit$("unused fns",orphans$(a$,unused)) tmp$="/../source/ezbastemp.bas" writeln(tmp$,a$) edit$("dangling endifs",dangle$(tmp$)) ENDIF IF code$="###TAG" dmode("console") section$=trim$(get_text$("search for?","")) IF section$<>"" ARRAY.LENGTH z,fnc$[] LIST.CLEAR tags FOR i=1 TO z IF IS_IN(LOWER$(section$),LOWER$(fnc$[i])) LIST.GET flist,i,t$ LIST.ADD tags,t$ ENDIF NEXT ENDIF ENDIF JOIN fnc$[],a$,"\n\n" IF code$="###REPLACE" dmode("console") srch$=get_text$( "search for?","") IF srch$<>"" rep$=get_text$("replace?","") a$=promptreplace$(a$,srch$,rep$) ENDIF ENDIF IF code$="###SAVE" | code$="###LOAD" | code$="###RUN" | code$="###QUIT" | code$="###OPTIMIZE" IF askyn("save?") dmode("console") INPUT "save to file:",f$,f$ writeln(f$,a$) writeln("ez.txt",f$) POPUP "saved!" ENDIF ENDIF IF code$="###LOAD" writeln("lastfn","") GOTO another ENDIF IF code$="###QUIT" THEN EXIT IF code$="###RUN" dmode("console") writeln("/../source/ezbastemp.bas",a$) RUN "/../source/ezbastemp.bas" ENDIF GOTO refresh