Joined: Thu Feb 09, 2006 11:27 pm Posts: 2557
|
Quote: Name: Auto Indent Known Supported OS: PB Version: 4.x, 5.x Description: adds/removes tabs to indent the active source code into a structured form. Setup: see below Code: ;{ AutoIndent by Michael Vogel V2.o2}
; INSTALLATION: ; copy compiled exe into the directory "...\Purbasic\Catalogs" ; install the tool using the parameter "%TEMPFILE" %SELECTION ; use the PureBasic as the working directory (or adapt the OpenPreferences path below) ; Select 'Wait until tool quits' And 'Reload source after tool has quit' ; %COMPILEFILE\..\Catalogs\Tool AutoIndent.exe ; "%TEMPFILE" %SELECTION ; %COMPILEFILE\.. ; Auto &Indent ; Menu Or Shortcut
; × Wait until tool quits ; × Reload Source after tool has quit ; × into the current source ; DESCRIPTION: ; With pressed shift key: eliminates tabs and spaces ; without shift key: indents source code ; no selection: complete source code is affected ; selection of lines: only selected lines are changed ; HISTORY & ISSUES: ; known problems: when cursor is in line 1, the Procedure folds up (editor bug?) ; ":" in remark, like in "Until x>1; x : 0...5" ; solved: "Else" was seen twice: because of "Else" and "ElseIf"
;}
; Define
Global LeftC.l Global LeftD.l Global RightC.l Global RightD.l Global RightP.l
#Words=51
Global Dim Word.s(#Words) Global Dim Exception.s(4) Global exceptions.l=0 Global Dim Border(3)
z.l=0 i.l=0 While i<#Words i+1 Read.s Word(i) If Asc(word(i))=254 ; "þ" exceptions+1 exception(exceptions)=Mid(word(i),2,Len(word(i))-1) EndIf If Word(i)="!" i-1 Border(z)=i ;Debug Str(z)+": "+Str(i-1)+" = "+word(border(z)) z+1 EndIf Wend
DataSection Data.s "þ Define" Data.s "þ{" Data.s "Procedure " Data.s "Procedure." Data.s "ProcedureC" Data.s "ProcedureDLL" Data.s "DataSection" Data.s "Macro " Data.s "If " Data.s "With " Data.s "Select " Data.s "While " Data.s "For " Data.s "ForEach " Data.s "Repeat" Data.s "Structure " Data.s "StructureUnion" Data.s "Interface " Data.s "Enumeration" Data.s "CompilerIf " Data.s "CompilerSelect " Data.s "ImportC " Data.s "Import " Data.s "!" ; border(0)
; kurzzeitig ''ausrücken'' Data.s "Case " Data.s "Else:" Data.s "Else " Data.s "ElseIf " Data.s "Default " Data.s "Default:" Data.s "CompilerElse" Data.s "CompilerCase" Data.s "CompilerDefault" Data.s "!" ; border(1)
Data.s "þ EndDefine" Data.s "þ}" Data.s "EndProcedure" Data.s "EndDataSection" Data.s "EndMacro" Data.s "EndIf" Data.s "EndWith" Data.s "EndSelect" Data.s "Wend" Data.s "ForEver" Data.s "EndStructure" Data.s "EndStructureUnion" Data.s "EndInterface" Data.s "EndEnumeration" ;Data.s "CompilerEndIf" ;Data.s "CompilerEndSelect" Data.s "EndImport" Data.s "!" ; border(2)
Data.s "Next " Data.s "Next:" Data.s "Until " Data.s "!","" ; border(3)
EndDataSection ; EndDefine
Procedure.s RightTrim(s.s) l.l=Len(s) While l l-1 b.l=PeekB(@s+l) If b<>9 And b<>32 Break EndIf Wend ProcedureReturn Left(s,l+1) EndProcedure Procedure.s LeftTrim(s.s) l.l=Len(s) c.l=0 While c<l b.l=PeekB(@s+c) If b<>9 And b<>32 ; Space & Tab Break EndIf c+1 Wend ProcedureReturn Mid(s,c+1,l-c) EndProcedure Procedure FindCommas(s.s) LeftC=0 LeftD=0 RightC=0 RightD=0 RightP=0 l.l=Len(s) c.l=0 While c<l b.l=PeekB(@s+c) c+1 Select b Case 59 ; Semicolon RightC=c If LeftC=0 : LeftC=c : EndIf Case 34 ; DoubleQuote RightD=c If LeftD=0 : LeftD=c : EndIf Case 58 ; Colon RightP=c Case 9,32 If c=RightP+1 : RightP+1 : EndIf EndSelect
Wend EndProcedure Procedure.s RightCut(s.s,x.l) ProcedureReturn RTrim(Left(s,x-1)) EndProcedure Procedure.s StringS(n, chars.s) Protected s.s="" While n>0 s+chars n-1 Wend ProcedureReturn s EndProcedure
Procedure Init()
; Dateinamen holen... CompilerIf 1 If CountProgramParameters()<>2 MessageBox_(0,"'AutoIndent' benötigt Parameter!"+#CR$+"(%TEMPFILE und %SELECTION)","Fehler",#MB_ICONERROR| #MB_OK) End EndIf Global OutputFile.s=ProgramParameter() CompilerElse Global OutputFile.s="Test.pb" CompilerEndIf
Global InputFile.s=OutputFile+"~" DeleteFile(InputFile) If RenameFile(OutputFile,InputFile)=0 MessageBox_(0,"'AutoIndent' konnte keine Temporärdatei erstellen","Fehler",#MB_ICONERROR| #MB_OK) End EndIf
; Selektion abfragen... Global zeile.l=0 selektion.s=ProgramParameter() Global Startzeile.l=Val(StringField(selektion, 1, "x")) Global Endzeile.l=Val(StringField(selektion, 3, "x"))
;CreateFile(3,"c:\debug.log") ;WriteStringN(3,Str(Startzeile)) ;WriteStringN(3,Str(Endzeile)) ;CloseFile(3)
If Startzeile>=Endzeile Startzeile=1 Endzeile=#MAXSHORT EndIf
OpenPreferences(GetPathPart(ProgramFilename())+"..\PureBasic.prefs"); ok
PreferenceGroup("Global") If Val(ReadPreferenceString("RealTab","0")) Or (GetKeyState_(#VK_CONTROL)&$80) Global indtxt.s=#TAB$ Else Global indtxt.s=Space(Val(ReadPreferenceString("TabLength", "2"))) EndIf ClosePreferences()
EndProcedure Procedure Doit(mode.l)
; Doit(0) auto indent the source code ; Doit(1) trims source code from space And tab characters
;CreateFile(3,"c:\debug.log") ;WriteStringN(3,"s "+FormatDate("%hh:%ii:%ss", Date())+#TAB$+Str(GetTickCount_()))
init()
ReadFile(1,InputFile) CreateFile(2,OutputFile)
indent.l=0
While Not(Eof(1)) z.s=ReadString(1) zeile.l+1
z=righttrim(z) ; rechts kann man immer säubern
If zeile>=Startzeile And zeile<=Endzeile
z=lefttrim(z) ; links nur, wenn gewünscht...
afterburner.l=0
If (mode=0) And (Len(z)>0)
If Asc(z)=';'; ";" If Left(z,25)="; IDE Options = PureBasic" indent=0 Else For i=1 To exceptions If Mid(z,2,Len(exception(i)))=exception(i) PokeB(@z,254) ; "þ" Break EndIf Next i EndIf EndIf
s.s=z
FindCommas(s) ; [1] If a=0 ; remark ; [2] If a=''x'' ; remark ; [3] If a=0 ; ''remark'' ; [x] If a=''x'' ; ''remark'' If LeftC If LeftD=0 Or LeftC<LeftD ; [1], [3] s=RightCut(s,LeftC) ElseIf RightC>RightD ; [2] s=RightCut(s,RightC) EndIf EndIf
For i=1 To #Words l.l=Len(word(i)) Select i Case 1 To border(1) p.l=1 Case 1 To border(2) p.l=Len(s)-l+1 Case 1 To border(3) p.l=RightP+1 EndSelect
If Mid(s+":",p,l)=word(i)
Select i Case 1 To border(0) afterburner.l+1
Case 1 To border(1) indent-1 afterburner.l+1
Case 1 To border(3) If afterburner afterburner-1 Else indent-1 EndIf
EndSelect EndIf
Next i
If Asc(z)=254 ; "þ" PokeB(@z,';') ; ";" EndIf
z=strings(indent,indtxt)+z ;WriteStringN(3,s)
EndIf ; mode
EndIf ; Zeilenselektion
WriteStringN(2,z) indent+afterburner Wend CloseFile(1) CloseFile(2)
;WriteStringN(3,"e "+FormatDate("%hh:%ii:%ss", Date())+#TAB$+Str(GetTickCount_())) ;CloseFile(3)
EndProcedure
Doit((GetKeyState_(#VK_SHIFT)&$80))
Quote: Name: Resource File Path Known Supported OS: PB Version: 4.x, 5.x Description: allows to compile your PB sources from memory sticks, even when resource files (icons etc.) are used. Setup: see below Code: ;{ Resource File by Michael Vogel V1.oo}
; DESCRIPTION: ; Adjusts drive letters for resource files added in the compiler options. This is useful, if you have your source files ; on a memory stick or USB drive, where the drive letter may change. ; INSTALLATION: ; copy the tool into the directory "...\Purbasic\Catalogs" to use the following settings: ; %COMPILEFILE\..\Catalogs\Tool ResourceFile.exe ; "%FILE" ; %COMPILEFILE\.. ; Ressource File Path Corrector ; Menu Or Shortcut ; <your shortcut>
; [_] Wait until tool quits ; [_] Run hidden ; [_] Hide Editor ; [_] Reload Source after tool has quit ; (•) into new source ; (_) into current source ; [_] Hide Tool from Main menu ; [_] Enable Tool on a per-source basis ;}
"%FILE"
Source.s=ProgramParameter(); "I:\Forerunner\Forerunner.pb"
Drive.s=UCase(Left(Source,3)) Resource.s Backup.s
If Mid(Drive,2,2)=":\"
If ReadFile(#True,Source)
While Eof(#True)=#False Line.s=ReadString(#True) If PeekA(@Line)=';' If Left(Line,15)="; AddResource =" Resource=Trim(Mid(Line,16)) EndIf EndIf Wend CloseFile(#True)
If Resource
If Left(Resource,1)="\" Or Mid(Resource,2,1)=":" Debug resource MessageRequester("Panik","Illegal resource file definition."+#CR$+"Please use relative path for your resource file definitions.") Else Resource=GetPathPart(Source)+Resource Backup=GetExtensionPart(Resource) Backup=Left(Resource,Len(Resource)-Len(GetExtensionPart(Resource)))+"bak" DeleteFile(Backup) If FileSize(Resource)>#True If RenameFile(Resource,Backup) If CreateFile(#True,Resource) And ReadFile(#False,Backup) While Eof(#False)=#False Line.s=ReadString(#False) n=FindString(Line," ICON ") If n n+5 If PeekA(@Line+n)='"' n+1 EndIf If PeekA(@Line+n+1)=':' PokeA(@Line+n,PeekA(@Drive)) EndIf EndIf Debug Line WriteStringN(#True,Line) Wend CloseFile(#False) CloseFile(#True) MessageRequester("Ok","Modified resource file.",#MB_ICONINFORMATION|#MB_OK) Else MessageRequester("Panik","Could not write a new resource file"+#CR$+"'"+Resource+"'.") EndIf Else MessageRequester("Panik","Could not create a backup for the resource file"+#CR$+"'"+Resource+"'.") EndIf Else MessageRequester("Panik","Could not locate the resource file"+#CR$+"'"+Resource+"'.") EndIf EndIf
Else MessageRequester("Panik","No resource file defined."+#CR$+"Compiler options / Resources") EndIf
EndIf
Else MessageRequester("Panik","Wrong tool configuration."+#CR$+"Please use ''%FILE'' as start parameter.",#MB_ICONERROR|#MB_OK) EndIf
Quote: Name: Show Procedure Information Known Supported OS: PB Version: 4.x, 5.x Description: simply pops up the name of the actual procedure Setup: see below Code: ;{ ShowInformation by Michael Vogel Vo.o1}
; INSTALLATION: ; ; • copy the compiled exe file into the directory "...\Purbasic\Catalogs" ; • set up the tool using "Configure Tools..." with the following parameters (from top to bottom): ; ; %COMPILEFILE\..\Catalogs\Tool ShowInfo.exe ; "%TEMPFILE" %CURSOR ; %COMPILEFILE\.. ; Show I&nformation ; Menu Or Shortcut ; Alt+N ; ; [_] Wait until tool quits ; [_] Reload Source after tool has quit ; [_] into the current source
;} ; Define
#Programtitle="Show Information"
Enumeration #CopyNothing #CopyProcedureLine #CopyCursorText ; #Source #Window #Info EndEnumeration
#CopyMode=#CopyProcedureLine; GetKeyState_(#VK_MENU)&128
If CountProgramParameters()<>2 MessageBox_(0,"'Show Information' needs two parameters!"+#CR$+"(''%TEMPFILE'' %CURSOR)","Error",#MB_ICONERROR|#MB_OK) End EndIf
Global SourceFile.s=ProgramParameter() Global Zeile.s=ProgramParameter() Global Info.s Global Cursor.i=Val(StringField(Zeile,1,"x")) Global Count.i Global n
; MessageBox_(0,"Filename: "+SourceFile+#CR$+"Cursor-Position: "+Str(Cursor),"Ok",#MB_ICONINFORMATION|#MB_OK)
If OpenFile(#Source,SourceFile)
While Eof(#Source)=#Null And Cursor Count+1 Zeile=Trim(ReadString(#Source)) If LCase(Left(Zeile,9))="procedure" Info=StringField(Zeile,2," ") n=Count EndIf Cursor-1 Wend CloseFile(#Source)
CompilerSelect #CopyMode CompilerCase #CopyProcedureLine SetClipboardText(Str(n)) CompilerCase #CopyCursorText SetClipboardText(Zeile) CompilerEndSelect
n=Len(Info) If n n*6+10 GetCursorPos_(Mouse.POINT) OpenWindow(#Window,Mouse\x+10,Mouse\y-15,n,18,#Programtitle,#PB_Window_BorderLess|#PB_Window_Invisible) SetWindowColor(#Window,#Black) StickyWindow(#Window,#True) TextGadget(#Info,1,1,n-2,16," "+Info,#SS_NOPREFIX|#SS_LEFTNOWORDWRAP) SetGadgetColor(#Info,#PB_Gadget_BackColor,#Yellow) SetGadgetColor(#Info,#PB_Gadget_FrontColor,#Black) HideWindow(#Window,#Null) AddWindowTimer(#Window,#Null,250)
n=ElapsedMilliseconds()+1500 Repeat WaitWindowEvent() Until ElapsedMilliseconds()>n End
EndIf
Else MessageBox_(0,"The source code file '"+GetFilePart(SourceFile)+"' is locked!"+#CR$,"Error",#MB_ICONERROR|#MB_OK) End EndIf
; EndDefine
|
|