Purebasic-Tipps and Code > Purebasic-Code

Example Function converted PowB->PurB

(1/2) > >>

Theo Gottwald:
This is the original PowerBasic Function:


--- Code: ---' WaitForInputIdle(PID,opt MaxTime in ms)
' If Maxtime was reached, function returns 1 Else 0 * Default mxt=5000
FUNCTION X_CS(BYVAL h As LONG,OPT BYVAL mxt As DWORD) As LONG
LOCAL r,ProcID As LONG
If (mxt=0) THEN mxt=5000
GetWindowThreadProcessId(h,ProcID)
H = OpenProcess(%PROCESS_ALL_ACCESS,1,ProcID)
r = WaitForInputIdle(H,BYVAL mxt)
CloseHandle H
If (r<>0) THEN r=1
FUNCTION=r
End FUNCTION 
--- End code ---

1. The first thing to do is, to replace the comment-sign ' against the ;
2. Second change the Variable declarations from "AS LONG" etc. to ".l"
3. Change the API-Constants from "%PROCESS*" to "#PROCESS*"
4. Change the API Names and add a "_" at their end.
5. Remove the "THEN" from all IF .. THEN and make them Multi-Liners
6. Change all "END IF" to "Endif" and also "END SELECT" to "EndSelect"
7. SUB and Function becomes "Procedure" with the appropriate ".x" Datatype
8. "LOCAL" becomes "Protected"
9. There is no "BYREF" or "BYVAL" available. Also there is no DWORD Datatype.
    Also there is not the WSTRING Datatype. In PureBasic you compile either with ANSI OR with Unicode. You can't easily mix.

Now in PureBasic it looks somehow like this:


--- Code: ---; WaitForInputIdle(PID,opt MaxTime in ms)
; If Maxtime was reached, function returns 1 Else 0 * Default mxt=5000
;
Procedure.l X_CS(h.l,mxt.l=5000)
Protected r.l,ProcID.l
GetWindowThreadProcessId_(h,ProcID)
H = OpenProcess_(#PROCESS_ALL_ACCESS,1,ProcID)
r = WaitForInputIdle_(H,mxt)
CloseHandle_(H)
If (r<>0)
  r=1
EndIf 
ProcedureReturn r
EndProcedure

--- End code ---

Patrice Terrier:
And the funny thing is that it is called PURE Basic, i would rather call it ObscureBasic  :P

What about this syntax:
// WaitForInputIdle(PID, opt MaxTime in ms)
// If Maxtime was reached, function returns 1 Else 0 * Default mxt=5000
FUNCTION X_CS(LOCAL h is int, LOCAL mxt is unsigned int)
r, ProcID is int
IF (mxt = 0) THEN mxt = 5000
GetWindowThreadProcessId(h, ProcID)
h = OpenProcess(PROCESS_ALL_ACCESS, 1, ProcID)
r = WaitForInputIdle(h, mxt)
CloseHandle(h)
IF (r<>0) THEN r = 1
RESULT r

Is not that closer to the original  ::)

Theo--
Fill free to remove this post from your PureBasic thread, but i couldn't resist.

Mike Stefanik:

--- Quote from: Patrice Terrier on October 29, 2013, 09:39:41 AM ---And the funny thing is that it is called PURE Basic, i would rather call it ObscureBasic  :P

--- End quote ---

That's always been my issue with PureBasic. The technical foundation for the language is great, but the syntax of the language is just bizarre. Particularly the use of "." to designate type when virtually every other implementation of Basic out there uses it in an object-oriented context. It's one of the least "Basic-like" languages out there that claims to be in the Basic family (at least by name).

Daniel Corbier:
Here's a transform based on Theo's steps.  It's not complete, plus there are several ways of doing it, but it gives an idea of how you might translate with uCalc Transform:



Notice how each line consists simply of listing the changes you want to make, without requiring a lot of extra code to actually do it.  You would simply load your file, then click Transform.

Patrice Terrier:
Daniel--

Just out of curiosity, did you have done one already to translate from PowerBASIC to C++ ?

Navigation

[0] Message Index

[#] Next page

Go to full version