First Tool For PureBasic 3.40 Editor

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

First Tool For PureBasic 3.40 Editor

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.

Hi,

Here an example for the external tools the new 3.40 editor can use.
3.40 is comming any minute now...Fred..everybody is waiting, where is it? :)

it formats the code with te tabs(spaces) you want.

Update Below

Regards,

Berikco

http://www.benny.zeb.be
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Pressure... Pressure... Pressure... :)

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.
Originally posted by fred

Pressure... Pressure... Pressure... :)

Fred - AlphaSND
3.40 is out, you can take a rest now for 1 minute :)


Regards,

Berikco

http://www.benny.zeb.be
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Thanks my friend.. :)

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.

Update to find things like 'If : doit : EndIf'

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
;
; --- Toolbox settings ---------------------------------------
;
; Arguments:
; First argument "%FILE"
; Second argument #Number of spaces for 1 Tab
; Example: "%FILE" 2
;
; Wait Until tool Quits = On
; Reload source after program is finished = On
;
; ------------------------------------------------------------
;
; 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 :)
; So dont use WriteStringN() for last line
;
; Note: This source is formated by itself :)
;

DestFileName$ = ProgramParameter()    ; Sourcefile to read
NumSpaces = Val(ProgramParameter())   ; Number of spaces

SourceFileName$ = DestFileName$+"2" ; The backup file *.pb2

#Source=1
#Destination=2

If FileSize(DestFileName$) ; Do nothing if source empty
  
  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()
          
          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 Vgl$="procedure" Or Vgl$="procedure.b" Or Vgl$="procedure.w" Or Vgl$="procedure.l"  Or Vgl$="procedure.s"
              Tab=0
              NextTab=1
            ElseIf Vgl$="endprocedure"
              Tab=0
            ElseIf Vgl$="if" Or Vgl$="select" Or Vgl$="for" Or Vgl$="repeat" Or Vgl$="while"
              f=0
              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=59
                  If q=0
                    code$=RTrim(Left(b$,r-1))
                    k=1
                    Repeat
                      k$= StringField(code$, k, " ")
                      k+1
                      If k$>""
                        KeyWord$=LCase(k$)
                      EndIf
                    Until k$=""
                    
                    If keyword$="endif" Or keyword$="next" Or keyword$="wend"
                      NextTab=0
                    Else
                      NextTab=1
                    EndIf
                    
                  EndIf
                  
                EndIf
              Next
              
            ElseIf Vgl$="endif" Or Vgl$="endstructure" Or Vgl$="next" Or Vgl$="until" Or Vgl$="endselect" Or Vgl$="wend"
              Tab-1
            ElseIf Vgl$="elseif" Or Vgl$="else" Or Vgl$="case"
              Tab-1
              NextTab=1
            EndIf
            
            Front$=Space(Tab * NumSpaces) ; Create Spaces needed
            a$ = Front$ + a$              ; Put spaces before the line code
            UseFile(#Destination)
            WriteStringN(a$)              ; Write in new source
            
          Else
            UseFile(#Destination)
            WriteString(a$)
          EndIf
        Wend
        
        CloseFile(#source)
        CloseFile(#destination)
        
      EndIf
    EndIf
  EndIf
EndIf
End

Regards,

Berikco

http://www.benny.zeb.be
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Very nice example, Berikco.

And it can be very useful when i paste unformated
source from the forum in the editor.
1 click and its perfectly readable.. !!

Thank you.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Jose.

Very cool Berikco,

Only one little mod I'd like, just a message box at the end to say it's done, I added this to the bottom of your sample code, above the last Endif;

MessageRequester("Source Formatting Done","New Formatted file Created:" +Chr(13)+Chr(13)+ DestFileName$ +Chr(13)+Chr(13)+ "Please Reload Code",0)

Now it tells me what it just did.

Regards
Jose

Registered PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.
Originally posted by Jose

Very cool Berikco,
MessageRequester("Source Formatting Done","New Formatted file Created:" +Chr(13)+Chr(13)+ DestFileName$ +Chr(13)+Chr(13)+ "Please Reload Code",0)
Hi Jose,

If the tool settings are correct, source will reload automaticly.
A backup *.pb2 is also created.

Regards,

Berikco

http://www.benny.zeb.be
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.
Originally posted by Danilo
And it can be very useful when i paste unformated
source from the forum in the editor.
1 click and its perfectly readable.. !!
Well, i just wrote it because i'm a lazy typer :)

Regards,

Berikco

http://www.benny.zeb.be
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Jose.

Hi Berikco,
I went back and re-configured tool, and yes you are right, now the message box can be a pain.
Thanks, cool tool
Jose

Registered PureBasic User
Post Reply