How to use it: Just copy the source code you want to process into the clipboard, then run this.
Note: This is *very* quick and dirty, unoptimized code. Works best on short (PurePunch style) demo programs.
There are a lot of things that it doesn't handle, so feel free to improve it.
Code: Select all
; firace's automatic puncher :)
Texte$ = GetClipboardText()
For i = 1 To CountString(texte$, #CRLF$) + 1
thisline.s = StringField(texte$, i, #CRLF$) ; strip all mid-line comments
If Left(thisline, 1) <> ";"
If FindString(thisline,";")
thisline = Mid(thisline, 1, FindString(thisline,";")-1)
EndIf
thisline = ReplaceString(thisline, #CRLF$,":") : result$ + ":" + thisline
EndIf
Next
While FindString(result$, ", ") : result$ = ReplaceString(result$, ", ",",",1,1) : Wend
While FindString(result$, "= ") : result$ = ReplaceString(result$, "= ","=",1,1) : Wend
While FindString(result$, " =") : result$ = ReplaceString(result$, " =","=",1,1) : Wend
While FindString(result$, ": ") : result$ = ReplaceString(result$, ": ",":",1,1) : Wend
While FindString(result$, " :") : result$ = ReplaceString(result$, " :",":",1,1) : Wend
While FindString(result$, "+ ") : result$ = ReplaceString(result$, "+ ","+",1,1) : Wend
While FindString(result$, " +") : result$ = ReplaceString(result$, " +","+",1,1) : Wend
While FindString(result$, "::") : result$ = ReplaceString(result$, "::",":",1,1) : Wend
L = Len(result$)
For j = 1 To L
xx$ = Mid(result$, j, 1)
finalresult$ + xx$
If xx$ = ":" And LP >= 40
finalresult$ + #CRLF$
If LP > longestlineLength
longestlineLength = LP
EndIf
LP = 0
EndIf
LP + 1
Next
For i = 1 To CountString(finalresult$, #CRLF$) + 1
thisline.s = StringField(finalresult$, i, #CRLF$)
If Right(thisline,1) = ":" : thisline = Left(thisline,Len(thisline)-1) : EndIf
If Left(thisline,1) = ":" : thisline = Right(thisline,Len(thisline)-1) : EndIf
While Len(thisline) < longestlineLength : thisline + ";" : Wend
finalresult2$ + thisline + #CRLF$
Next
Debug finalresult2$
SetClipboardText(finalresult2$)
Example:
(before)
Code: Select all
InitSprite() : W=750 : H=540
OpenWindow(0, 1, 1, W+1, H+1, "Ex07")
OpenWindowedScreen(WindowID(0),0,0,W+1,H+1,1,0,0)
StartDrawing(ScreenOutput())
For a = 0 To W-30 Step 30 : For b = 0 To H-30 Step 30
If Not Random(4) : Box(a, b, 30, 30, Random($124F12)) : EndIf
Next : Next
For i = 0 To H Step 30 : Line(0, i, W+1, 1, $FF00) : Next
For j = 0 To W Step 30 : Line(j, 0, 1, H+1, $FF00) : Next
StopDrawing() : FlipBuffers()
Repeat : Until WaitWindowEvent() = 13116
(After)
Code: Select all
InitSprite():W=750:H=540:OpenWindow(0,1,1,W+1,H+1,"Ex07");
OpenWindowedScreen(WindowID(0),0,0,W+1,H+1,1,0,0);;;;;;;;;
StartDrawing(ScreenOutput()):For a=0 To W-30 Step 30;;;;;;
For b=0 To H-30 Step 30:If Not Random(4);;;;;;;;;;;;;;;;;;
Box(a,b,30,30,Random($124F12)):EndIf:Next;;;;;;;;;;;;;;;;;
Next:For i=0 To H Step 30:Line(0,i,W+1,1,$FF00);;;;;;;;;;;
Next:For j=0 To W Step 30:Line(j,0,1,H+1,$FF00);;;;;;;;;;;
Next:StopDrawing():FlipBuffers():Repeat;;;;;;;;;;;;;;;;;;;
Until WaitWindowEvent()=13116;;;;;;;;;;;;;;;;;;;;;;;;;;;;;