Automatic PurePuncher

Share your advanced PureBasic knowledge/code with the community.
firace
Addict
Addict
Posts: 902
Joined: Wed Nov 09, 2011 8:58 am

Automatic PurePuncher

Post by firace »

Turns your PB code into a compact, unreadable wall of text :)

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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Last edited by firace on Sun Jun 10, 2018 8:54 pm, edited 1 time in total.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Automatic PurePuncher

Post by falsam »

Thanks Firace. I saved your code in my toolbox. :wink:

A similar purecrunch (2014) coded by Majikeyric has often been used in PurePunch contests
viewtopic.php?p=448851#p448851

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
Post Reply