; English forum: http://www.purebasic.fr/english/viewtopic.php?t=20481 ; Author: Michael Vogel (adapted by Andre) ; Date: 18. March 2006 ; OS: Windows ; Demo: Yes ;- Some notes: ; a project which translates GFA listings (*.lst) to PureBasic source code (*.pb)... ; Of course it's not that easy, because GFA is able to do some things, PureBasic ; forgot to implement, like... ; Code: ; DO [While ...] ; : ; LOOP [Until ...] ; ; MID$(string,from,[To]) ; INSTR(string,what,[fromwhere]) And RINSTR(string,what,[fromwhere]) ; ; Procedure test(VAR test) ; : ; Return ; ; Abs(a), SGN(a),... ; PRED(a), SUCC(a), a++, a-- ; MUL(a,b), DIV(a,b), SCALE(a,b,c),... ; MIN(a,b), MAX(a,b), IMIN(a,b),... ; SINQ(a), COSQ(a),... ; ; ARRAYFILL numericarray(),TRUE ; ARRAYFILL stringcarray(),"n/a" ; However, everyone who did GFA-16 maybe has some old code waiting to be converted. Ok, it will not ; run after being "translated" with my program, but a lot of hand work will be handled with this ; tool (and maybe I've time to add more features)... ;- Converter Code ; Define (V0.30) ; What works already... ; ------------------------- ; Procedure/Return ; Function/Endfunc ; If ... Then ... ; Variable Types ; Remarks (', //) ; Local variables, Variable address pointer (V:) ; Do/Loop, Repeat/Until, While/Wend ; Graphic commands (OpenW/CloseW, Dialog, Cls, Line, Color,...) ; Constants (True/False, WM_, WS_,...) ; What should be done... ; -------------------------- ; Pred, Succ, Inc, Dec ; Mid(a$,1) ; Abs() no idea, how to get it to an integer... ; --, ++, +=, -=, *=, /= ; Byte{}, Byte(), Word{}, Word(), Char{},... ; (Some) Further issues... ; ---------------------------- ; Case "x" (Fred, com'on) ; Case n To ; Case To n ; Otherwise ; CosQ, SinQ,... ; Curve (Bezier) ; KeyGet EnableExplicit #InputExtension=".lst" #OutputExtension=".pb" #MaxVal=#MAXSHORT-1 Global Dateiname.s="GFA_Testcode" Global InputFile Global OutputFile Global Zeile.s Global Klein.s Global LoopStack.s="" Enumeration #Bemerkung #Strichpunkt #LetztesZeichen #Prozedur #SuchErgebnis #Gefunden #LinkesZeichen #RechtesZeichen #LastFlag EndEnumeration Global Dim Flags.w(#LastFlag) ; EndDefine Procedure.s Ersetze(von.w,len.w,mit.s) ; Werte anpassen (von ist immer kleiner Strichpunkt und LetztesZeichen) Flags(#LetztesZeichen)-len+Len(mit) Flags(#Strichpunkt)-len+Len(mit) Zeile=Left(Zeile,von-1)+mit+Mid(Zeile,von+len,#MaxVal) EndProcedure Procedure ErsetzePlus(von.w,len.w,mit.s) Ersetze(von.w,len.w,mit.s) Ersetze(Flags(#LetztesZeichen)+1,0,")") EndProcedure Procedure Bemerkungen() ; Vorselektion (Bemerkungen) Flags(#Bemerkung)=#False Select Left(Zeile,2) Case "//" Zeile="; "+Zeile Flags(#Bemerkung)=#True Case "> " Zeile=Mid(Zeile,3,#MaxVal) EndSelect Select Left(Zeile,1) Case "'" PokeB(@Zeile,Asc(";")) Flags(#Bemerkung)=#True Case "$" Zeile="; (x) "+Zeile Flags(#Bemerkung)=#True EndSelect Flags(#Strichpunkt)=0 Flags(#LetztesZeichen)=Len(Zeile) If Flags(#Bemerkung)=#False Protected i.w=0 Protected q.w=0 Protected s.w=0 While is+1 Ersetze(i+1,1,".s"); Variable (e.g. Dummy$ wird Dummy.s) i+1 EndIf Case 33; ! Bit Ersetze(i+1,1,".b") ;Case 124; | Byte ;Ersetze(i+1,1,".b") Case 38; & Word Ersetze(i+1,1,".w") ;Case 37; % Long ;Ersetze(i+1,1,".l") ;Case 35; # Double ;Ersetze(i+1,1,".d") Case 64; @ Procedure/Function Ersetze(i+1,1,"") i-1 k=#True; () ist anzufügen... Case 58; : Address of Variable If i>0 If PeekB(@Zeile+i-1)=86; "V" Ersetze(i,2,"@") i-1 EndIf EndIf EndSelect EndIf i+1 Wend If k; Klammern fehlen noch... Ersetze(Flags(#LetztesZeichen)+1,0,"()") EndIf EndProcedure Procedure Klammern(i.w) Protected q.w=0 Protected k.w=#True While ih1 h2-1 EndIf If h2 ; 0-> Parameter löschen If Feld(h2,i-1) ; Test(x,y) h1=Flags(#LinkesZeichen)+Flags(#RechtesZeichen) If PeekB(@Zeile+h1-1)=41 ; Test(x,y) -> Test(x,y|,z|) s=","+s Else ; Test(x,y) -> Test(x,|z,|y) s=s+"," h1+1 EndIf Ersetze(h1,0,s) ; Parameter einfügen EndIf EndIf EndIf extra=Mid(extra,3,#MaxVal) Until Len(extra)=0 EndIf EndIf EndProcedure Procedure Befehle() Protected i.w ; Window / Dialog If Left(Zeile,7)="OPENW #" Ersetze(1,7,"OpenWindow(") i=KommaSuche(12,5) If i ErsetzePlus(i,0,","+#DOUBLEQUOTE$+#DOUBLEQUOTE$) Else Ersetze(Flags(#LetztesZeichen),0,"; (xxx)") EndIf ElseIf Left(Zeile,8)="DIALOG #" Ersetze(1,8,"OpenWindow(") i=KommaSuche(12,7) If i Ersetze(i,1,"); (x) ") Else Ersetze(Flags(#LetztesZeichen)+1,0,")") EndIf i=KommaSuche(12,1) If i Zeile=zeile+#CR$+#LF$+"CreateGadgetList(WindowID("+Mid(Zeile,12,i-12)+")); (x)" EndIf ElseIf Left(Zeile,8)="CLOSEW #" ErsetzePlus(1,8,"CloseWindow(") ElseIf Left(Zeile,13)="CLOSEDIALOG #" ErsetzePlus(1,13,"CloseWindow(") ElseIf Left(Zeile,9)="ENDDIALOG" Ersetze(1,9,"; (x) EndDialog") ElseIf Left(Zeile,10)="SHOWDIALOG" Ersetze(1,10,"; (x) ShowDialog") ; Graphik ElseIf Left(Zeile,4)="CLS " ErsetzePlus(1,4,"ClearScreen(") ElseIf Left(Zeile,6)="COLOR " i=KommaSuche(7,1) If i Ersetze(i,1,") : BackColor(") EndIf ErsetzePlus(1,6,"FrontColor(") ElseIf Left(Zeile,8)="DEFFILL " ErsetzePlus(1,8,"; (xxx) DefFill(") ElseIf Left(Zeile,5)="FILL " Ersetze(1,5,"FillArea(") Ersetze(Flags(#LetztesZeichen)+1,0,",-1); (x Color)") ElseIf Left(Zeile,5)="LINE " ErsetzePlus(1,5,"LineXY(") ElseIf Left(Zeile,6)="CURVE " ErsetzePlus(1,6,"; (xxx) Curve(") ; Events ElseIf Left(Zeile,8)="GETEVENT" ErsetzePlus(1,8,"Global _Mess=WaitWindowEvent(") ElseIf Left(Zeile,9)="PEEKEVENT" ErsetzePlus(1,9,"Global _Mess=WindowEvent(") ElseIf Left(Zeile,7)="KEYGET " ErsetzePlus(1,7,"; (xxx) KeyGet(") ; Sonstiges ElseIf Left(Zeile,6)="PRINT " Ersetze(1,6,"Debug ") EndIf ; Mathematik Austausch("SUCC(","(1+",""); schön ist anders... Austausch("PRED(","(-1+",""); noch grauslicher... ; Zeit Austausch("DELAY ","Delay(1000*",")") Austausch("DATE$","FormatDate("+#DOUBLEQUOTE$+"%dd%mm%yy"+#DOUBLEQUOTE$+",Date())","") ; Windows-API Austausch("GETNEAREST(","GetNearestColor_(WindowID(#win), RGB(","); (xxx #win)") Austausch("GetModuleHandle(","GetModuleHandle_(","") Austausch("_wParam","EventwParam()","") Austausch("_lParam","EventlParam()","") ; Konstante Austausch("TRUE","#True",""); Achtung! in GFA=-1, evtl. ist eine globale Variable TRUE=-1 besser Austausch("FALSE","#False","") Austausch("BS_","#BS_","") Austausch("DS_","#DS_","") Austausch("SS_","#SS_","") Austausch("WM_","#WM_","") Austausch("WS_","#WS_","") ; Dialog Spezialtausch("BUTTON ","ButtonGadget(",")",-1,"16") Spezialtausch("PUSHBUTTON ","ButtonGadget(",")",-1,"16") Spezialtausch("CHECKBOX ","CheckBoxGadget(",")",-1,"16") Spezialtausch("RADIOBUTTON ","OptionGadget(",")",-1,"16") Spezialtausch("EDITTEXT ","TextGadget(",")",-1,"16") If Left(Zeile,8)="CONTROL " If Feld(3,8) Select LCase(Mid(zeile,Flags(#LinkesZeichen)+1,Flags(#RechtesZeichen)-2)) Case "static" Spezialtausch("CONTROL ","TextGadget(",")",-1,"182027") Case "button" Spezialtausch("CONTROL ","ButtonGadget(",")",-1,"182027") EndSelect EndIf EndIf ;CONTROL text.s,902,"static",#SS_CENTER,280,50,140,25 ;TextGadget(902, 280,50,140,25, "TextGadget Sta",#SS_CENTER) ;CONTROL "&Ok",1,"button",$10010001,305,105,90,28 ;ButtonGadget(1,35,105,90,28,"&Ok");,$10010001) EndProcedure Procedure Main() Define dummy.w Define dommy.w If FileSize(DateiName+#InputExtension) InputFile=ReadFile(#PB_Any,DateiName+#InputExtension) If InputFile OutputFile=CreateFile(#PB_Any,Dateiname+#OutputExtension) While Not(Eof(InputFile)) Flags(#Bemerkung)=#False Zeile=Trim(ReadString(InputFile)) Bemerkungen() ; Hauptarbeit If Flags(#Bemerkung)=#False Klein=LCase(Zeile) If Left(Klein,10)="procedure " Flags(#Prozedur)=#True Klammern(11) ElseIf Left(Klein,9)="function " dummy=FindeMin(Klein,"$") If dummy And dummy