Not code/code formatted difficult to open in PB IDE... Inserting format here...
Code: Select all
; ------------------------------------------------------------
;
; Source Formatting By Berikco
;
; (c) 2002 - Benny Sels
;
; ------------------------------------------------------------
;
; For Purebasic Toolmenu version 3.40 and up
; Will format the source with TABS(Spaces)
; Thanks to PB for his help on the ';' comment finder
;
; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
; 2007 / 12 / 19
; Rook Zimbabwe updated code to PB4.1
;
; 2002/02/18
; some small changes
;
; 2002/10/09
; First version
; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
; Note: When writing PureBasic *.pb sourcefile, don't add CRLF after last line!
; This will produce strange results at end of code
Enumeration
#Window_0
EndEnumeration
Enumeration
#Button_MANGLE
#Text_2
#Text_1
#Text_0
#Combo_EXTRA
#Combo_INDENT
#Button_INFILE
#String_INFILE
#Source
#Destination
EndEnumeration
Structure VisualDesignerGadgets
Gadget.l
EventFunction.l
EndStructure
Global NewList EventProcedures.VisualDesignerGadgets()
Global DestFileName$
Global Numspaces
Global SelectTab
Procedure Button_MANGLE_Event(Window, Event, Gadget, Type)
Debug "#Button_MANGLE"
SourceFileName$ = DestFileName$+"2" ; The backup file *.pb2
Numspaces = GetGadgetData(#Combo_INDENT)
SelectTab = GetGadgetData(#Combo_EXTRA)
If FileSize(DestFileName$) < 1
MessageRequester("INPUT ERROR", "There is no file selected..."+Chr(10)+"Please Select a file...", #PB_MessageRequester_Ok); Do nothing if source empty
Goto Zoe
EndIf
If FileSize(SourceFileName$) ; If old backupFile exist, delete it
DeleteFile(SourceFileName$)
EndIf
If RenameFile(DestFileName$, SourceFileName$) ; Rename source to backup
If OpenFile(#Source,SourceFilename$) ; Open Source, now with *.pb2 extension
If CreateFile(#Destination,DestFileName$) ; Create new source
While Eof(#source)=false
; UseFile(#Source)
a$=ReadString(#source)
If Eof(#source)=false ; Check if read is last line in source
; If this is the case, must not write CRLF
a$=LTrim(a$) ;Remove old TABs (spaces in front)
a$=RTrim(a$) ;Remove all spaces at end
Tab+NextTab
NextTab=0
in=FindString(a$," ",1) ; Find PureBasic Keyword
If in>0
Vgl$=LCase(Left(a$,in-1)) ; Get only Keyword
Else
Vgl$=LCase(a$) ; Nothing after Keyword, use whole string
EndIf
; Check For Keyword that needs formatting
If Left(a$,1)=";"
;nope
ElseIf Vgl$="procedure" Or Vgl$="procedure.b" Or Vgl$="procedure.w" Or Vgl$="procedure.l" Or Vgl$="procedure.s" Or Vgl$="procedure$" Or Vgl$="datasection"
Tab=0
NextTab=1
ElseIf Vgl$="endprocedure" Or Vgl$="enddatasection"
Tab=0
ElseIf Vgl$="if" Or vgl$="select" Or Vgl$="for" Or Vgl$="repeat" Or Vgl$="while" Or Vgl$="structure" Or Vgl$="compilerif" Or Vgl$="opensubmenu"
b$=a$+";" ;little trick, add comment to line, only one routine needed to scan
For r=1 To Len(b$)
a=Asc(Mid(b$,r,1))
If a=34 : q=1-q : EndIf
If a=58 And q=0 : NextTab=0 : r=Len(b$) : EndIf
If a=59 And q=0
If Vgl$="select" And SelectTab=1
NextTab=2
Else
NextTab=1
EndIf
r=Len(b$)
EndIf
Next
ElseIf Vgl$="endif" Or Vgl$="endstructure" Or Vgl$="return" Or Vgl$="next" Or Vgl$="until" Or Vgl$="wend" Or Vgl$="forever" Or Vgl$="compilerendif" Or Vgl$="closesubmenu"
Tab-1
NextTab=0
ElseIf Vgl$="endselect"
If SelectTab=1
Tab-2
Else
Tab-1
EndIf
NextTab=0
ElseIf Vgl$="elseif" Or Vgl$="else" Or Vgl$="case" Or Vgl$="compilerelse" Or Vgl$="default"
Tab-1
NextTab=1
Else
b$=a$+";" ;little trick, add comment to line, only one routine needed to scan
KeyWord$=""
For r=1 To Len(b$)
a=Asc(Mid(b$,r,1))
If a=34 : q=1-q : EndIf
If a=59 And q=0
KeyWord$=LTrim(KeyWord$) ;Remove spaces in front
KeyWord$=LCase(RTrim(KeyWord$)) ;Remove all spaces at end and put lowercase
If KeyWord$="endif" Or KeyWord$="endstructure" Or KeyWord$="next" Or KeyWord$="until" Or KeyWord$="Wend" Or KeyWord$="ForEver"
If tab>0 : tab-1 : EndIf
EndIf
EndIf
keyword$+Chr(a)
If a=58 And q=0
If keyword$=a$
Tab=0
NextTab=1
r=Len(b$)
EndIf
KeyWord$=""
EndIf
Next
EndIf
Front$=Space(Tab * NumSpaces) ; Create Spaces needed
a$ = Front$ + a$ ; Put spaces before the line code
; UseFile(#Destination)
WriteStringN(#Destination,a$) ; Write in new source
Else
; UseFile(#Destination)
WriteString(#Destination,a$)
EndIf
Wend
CloseFile(#source)
CloseFile(#destination)
DeleteFile(SourceFileName$)
EndIf
EndIf
EndIf
Zoe:
EndProcedure
Procedure Text_2_Event(Window, Event, Gadget, Type)
Debug "#Text_2"
EndProcedure
Procedure Text_1_Event(Window, Event, Gadget, Type)
Debug "#Text_1"
EndProcedure
Procedure Text_0_Event(Window, Event, Gadget, Type)
Debug "#Text_0"
EndProcedure
Procedure Combo_EXTRA_Event(Window, Event, Gadget, Type)
Debug "#Combo_EXTRA"
EndProcedure
Procedure Combo_INDENT_Event(Window, Event, Gadget, Type)
Debug "#Combo_INDENT"
EndProcedure
Procedure Button_INFILE_Event(Window, Event, Gadget, Type)
Pattern$ = "PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
Pattern = 0 ; use the first of the three possible patterns as standard
DestFileName$ = OpenFileRequester("Please choose file to load", "", Pattern$, Pattern)
If File$
SetGadgetText(#String_INFILE, DsetFileName$)
Else
MessageRequester("Information", "The requester was canceled.", 0)
EndIf
EndProcedure
Procedure String_INFILE_Event(Window, Event, Gadget, Type)
Debug "#String_INFILE"
EndProcedure
Procedure RegisterGadgetEvent(Gadget, *Function)
If IsGadget(Gadget)
AddElement(EventProcedures())
EventProcedures()\Gadget = Gadget
EventProcedures()\EventFunction = *Function
EndIf
EndProcedure
Procedure CallEventFunction(Window, Event, Gadget, Type)
ForEach EventProcedures()
If EventProcedures()\Gadget = Gadget
CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
LastElement(EventProcedures())
EndIf
Next
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 5, 5, 400, 170, "Code Mangler 1.b - Use at your own risk!", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
If CreateGadgetList(WindowID(#Window_0))
StringGadget(#String_INFILE, 6, 12, 360, 18, "Select File to Abuse...")
RegisterGadgetEvent(#String_INFILE, @String_INFILE_Event())
ButtonGadget(#Button_INFILE, 366, 12, 24, 18, "...")
RegisterGadgetEvent(#Button_INFILE, @Button_INFILE_Event())
ComboBoxGadget(#Combo_INDENT, 132, 48, 60, 180)
RegisterGadgetEvent(#Combo_INDENT, @Combo_INDENT_Event())
AddGadgetItem(#Combo_INDENT, -1,"0")
AddGadgetItem(#Combo_INDENT, -1,"1")
AddGadgetItem(#Combo_INDENT, -1,"2")
AddGadgetItem(#Combo_INDENT, -1,"3")
AddGadgetItem(#Combo_INDENT, -1,"4")
AddGadgetItem(#Combo_INDENT, -1,"5")
AddGadgetItem(#Combo_INDENT, -1,"6")
AddGadgetItem(#Combo_INDENT, -1,"7")
AddGadgetItem(#Combo_INDENT, -1,"8")
AddGadgetItem(#Combo_INDENT, -1,"9")
ComboBoxGadget(#Combo_EXTRA, 312, 48, 66, 180)
RegisterGadgetEvent(#Combo_EXTRA, @Combo_EXTRA_Event())
AddGadgetItem(#Combo_EXTRA, -1,"0")
AddGadgetItem(#Combo_EXTRA, -1,"1")
AddGadgetItem(#Combo_EXTRA, -1,"2")
AddGadgetItem(#Combo_EXTRA, -1,"3")
AddGadgetItem(#Combo_EXTRA, -1,"4")
AddGadgetItem(#Combo_EXTRA, -1,"5")
AddGadgetItem(#Combo_EXTRA, -1,"6")
AddGadgetItem(#Combo_EXTRA, -1,"7")
AddGadgetItem(#Combo_EXTRA, -1,"8")
AddGadgetItem(#Combo_EXTRA, -1,"9")
TextGadget(#Text_0, 6, 48, 114, 18, "SPACES TO INDENT")
RegisterGadgetEvent(#Text_0, @Text_0_Event())
TextGadget(#Text_1, 216, 48, 90, 18, "EXTRA SPACING")
RegisterGadgetEvent(#Text_1, @Text_1_Event())
TextGadget(#Text_2, 12, 120, 390, 50, "This code was written by BERIKO (Benny Sels) and (c) 2002"+Chr(10)+"No warranty of any sort is implied"+Chr(10)+"Use at your own risk!", #PB_Text_Center)
RegisterGadgetEvent(#Text_2, @Text_2_Event())
ButtonGadget(#Button_MANGLE, 90, 90, 228, 24, "MANGLEIFY THE CODE")
RegisterGadgetEvent(#Button_MANGLE, @Button_MANGLE_Event())
EndIf
EndIf
EndProcedure
Open_Window_0()
SetGadgetState(#Combo_EXTRA, 0)
SetGadgetState(#Combo_INDENT, 3)
Repeat
Event = WaitWindowEvent()
Gadget = EventGadget()
Type = EventType()
Window = EventWindow()
Select Event
Case #PB_Event_Gadget
CallEventFunction(Window, Event, Gadget, Type)
EndSelect
Until Event = #PB_Event_CloseWindow
End
Benny... I could not resist playing with it a bit... Sorry... Will delete if you insist!
{{ DAMN Lucif3r beat me... to my own edit!!! }}