Donate Now Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

Results 1 to 10 of 10

Thread: SubFcnList.tbasic - Adds Sub&Function summary to your scripts

  1. #1
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    76
    Posts
    67
    Rep Power
    12

    SubFcnList.tbasic - Adds Sub&Function summary to your scripts

    Hello,
    This isn't rocket science, but I wrote it, use it, and like it.
    It scans a program for "Sub"s and "Functions"s and adds those lines
    as a summary at the top of the program (removing the old summary).
    You need to change:
    1) the Const BkupFile to a place where you want to have a backup file.
    2) the Const FileName to the program you want processed. A good addition
    would be to have a file dialog instead of a Const.
    Deleted -- I'm thinking it needs some work.  I'll re-post in a day or two.  dCromley
    
    Last edited by dcromley; 15-11-2011 at 12:12. Reason: I'm thinking it needs work

  2. #2
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    76
    Posts
    67
    Rep Power
    12
    OK, now I'm proud of this program. I got to thinking that in the
    first version, it seemed possible to mess up both the program and
    the backup. Now the program is copied to the backup and that is
    not touched. From my first post:

    Hello,
    This isn't rocket science, but I wrote it, use it, and like it.
    It scans a program for "Sub"s and "Functions"s and adds those lines
    as a summary at the top of the program (removing the old summary).
    You need to change:
    1) the Const BkupFile to a place where you want to have a backup file.
    2) the Const FileName to the program you want processed. A good addition
    would be to have a file dialog instead of a Const.
    ' [re-posted on 16-11-2011 with suggestions from thread]
    ' ---- sub/function summary
    ' Sub      TBMain()
    ' Function CkIterate(txt As String) As Long
    ' Function LFill(s1 As String, pl As Long) As String
    ' Sub      ErrStop(txt As String)
    ' ---- end of sub/function summary
    
      Uses "Console", "file", "UI" ' by dCromley 11/2011
      Const sHeader As String = "' ---- sub/function summary"
      Const sFooter As String = "' ---- end of sub/function summary"     
      Const BkupFile As String = APP_ScriptName + ".BACKUP"
      
    Sub TBMain()
      Local fhin, fhout As Long
      Local i1 As Long, s1, s1u, s2, sRec As String
      Local FileName As String
      FileName = Dialog_OpenFile(0, "Select a file", DIR_GetCurrent, _
        "TB Files (*.tBasic*)|*.tBasic*|All Files (*.*)|*.*", "", 0)        
      If FileName = "" Then Exit Sub  
      ' -- copy the file to the backup
      If Not FILE_Exists(FileName) Then ErrStop "<" & FileName & "> doesn't exist"
      fhout = FILE_Open(BkupFile, "output") ' check the output file
      If fhout = 0 Then ErrStop "Open Output " & BkupFile
      FILE_Close(fhout)    
      FILE_Copy(FileName, BkupFile)
      PrintL FileName & " copied to " & bkupfile & $CRLF
      ' -- now output to the original file
      fhout = FILE_Open(FileName, "output")
      If fhout = 0 Then ErrStop "Open Output " & FileName
      ' -- pass 1, delete old summary and make new summary 
      fhin = FILE_Open(BkupFile, "input")
      If fhin = 0 Then ErrStop "Open Input " & BkupFile
      FILE_LinePrint(fhout, sHeader) ' header
      PrintL sHeader
      Do While Not FILE_EOF(fhin)
        sRec = FILE_LineInput(fhin)
        If CkIterate(srec) Then Iterate Do ' bypass old list
        s1 = Parse$(srec, " ", 1) ' get "Sub" or "Function" or ..
        s1u = Ucase$(s1) ' ensure no case difference
        If s1u = "SUB" Or s1u = "FUNCTION" Or s1u = "CALLBACK" Then
          i1 = InStr(1, srec, s1) ' get rest of line
          s2 = "' " & LFill(s1, 9) & Mid$(srec, Len(s1)+2)
          PrintL s2 ' re-constructed line
          FILE_LinePrint(fhout, s2)
        End If   
      Loop   
      FILE_Close(fhin)
      FILE_LinePrint(fhout, sFooter) ' footer
      PrintL sFooter & $CRLF
      FILE_Close(fhin)
      ' -- pass 2, the rest of the file
      fhin = FILE_Open(BkupFile, "input")
      If fhin = 0 Then ErrStop "Open Input " & BkupFile
      Do While Not FILE_EOF(fhin)
        srec = FILE_LineInput(fhin)
        If CkIterate(srec) Then Iterate Do ' bypass old list again
        FILE_LinePrint(fhout, srec)
      Loop           
      FILE_Close(fhin)
      ' -- end of pass 2
      FILE_Close(fhout) 
      PrintL "End - reveiw " & FileName
      WaitKey
    End Sub
     
    Function CkIterate(txt As String) As Long
      Static swIterate As Long
      ' set bypass if header
      If txt = sHeader Then swIterate = 1
      Function = swIterate
      ' reset bypass if footer
      If txt = sFooter Then swIterate = 0
      If LEFT$(txt, 1) <> "'" Then ' safety ck
        swIterate = 0
        Function = 0
      End If
    End Function 
    
    Function LFill(s1 As String, pl As Long) As String
      ' Left$, but fill with " "s
      Function = LEFT$(s1 & String$(pl, " "), pl)
    End Function
    
    Sub ErrStop(txt As String)
      MsgBox 0, "Err: " & txt: Stop
    End Sub
    
    Last edited by dcromley; 16-11-2011 at 18:43. Reason: make suggested changes

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,403
    Rep Power
    650
    Thanks for the example,

    to make it work "out of the box", you might want to change two lines in the code to:
    Const BkupFile As String = APP_ScriptName + ".BACKUP"
    Const FileName As String = APP_ScriptName
    
    ... this will analyze the code itself


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  4. #4
    thinBasic MVPs Michael Clease's Avatar
    Join Date
    May 2007
    Posts
    1,414
    Blog Entries
    1
    Rep Power
    149

    Post

    I like this very useful, here is something to make sure that it catches scripts that are not formatted to first char upper case and have callbacks.

        If Ucase$(s1) = "SUB" Or Ucase$(s1) = "FUNCTION" Or Ucase$(s1) = "CALLBACK" Then
    
    thanks

    Mike C.
    Why is the world full of nobs trying to push my buttons!!

    Home Desktop : WinXP Pro SP3 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : WinXP Pro SP3 - Intel Pentium 4 - 3 Ghz - 512 MB - ATI Mobile Radeon 7000 IGP
    Work Desktop : WinXP Pro SP3 - Intel core 2 Quad Q8200 - 2.33 Ghz - 2 Gb - Quadro Fx 370

  5. #5
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    76
    Posts
    67
    Rep Power
    12
    Michael,
    Very good! Thanks

    Petr,

    > Const BkupFile As String = APP_ScriptName + ".BACKUP"
    It took awhile for me to process this, but I like it.
    Just taking the "z:\" out of "z:\zbkup.tbasic" would have allowed
    it to work "out of the box", which I like. So I have your
      Const BkupFile As String = APP_ScriptName + ".BACKUP"
    
    Thank you for the idea.

    > Const FileName As String = APP_ScriptName
    "FileName" needs to selected by the user. So instead of
    "Const FileName ..", I want the Dialog_OpenFile(), which I haven't
    used before. But you made me look into it The following
    (from samplescripts) works GREAT:
    ' (have to add "UI")
      uses "Console", "File", "UI"
    ' (early in TBMain)
      Local FileName As String
      FileName = Dialog_OpenFile(0, "Select a file", DIR_GetCurrent, _
        "TB Files (*.tBasic*)|*.tBasic*|All Files (*.*)|*.*", "", 0)
      If FileName = "" Then Exit Sub
    
    > Thanks for the example
    I appreciate your comments very much!

  6. #6
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    76
    Posts
    67
    Rep Power
    12
    I want to make it easier for somebody who wants the updated script.
    I could have posted it here, or replaced the version in the top post.
    I replaced the version in the top post.
    Is this unethically changing history?

  7. #7
    for me i prefer to see the history of the examples, and anyway in a time travel movie they said that it is prohibited to change the history.this is a useful example thanks

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,556
    Blog Entries
    2
    Rep Power
    10
    Dave,

    I saw you developed LFill function.
    thinBasic has LSET$, RSET$ and CSET$ functions that can be used for string alignment.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  9. #9
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    76
    Posts
    67
    Rep Power
    12
    < .. LSet ..
    Yup, that's what I wanted. Thanks for pointing that out, Eros.

    Good point, Zak.

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,556
    Blog Entries
    2
    Rep Power
    10
    My idea is that if there are general purpose functions enough general and interesting to also be used by other programmers, I add them as native in thinBasic.
    Like Lerp function you suggested and that will be present in next thinBasic release.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. Passing Arguments To Tbasic Program
    By peralta_mike in forum Core module
    Replies: 4
    Last Post: 03-11-2011, 19:12
  2. Invoking One .tbasic Program From Another .tbasic Program
    By gungadout in forum thinBasic General
    Replies: 46
    Last Post: 23-11-2009, 12:01
  3. obfuscated scripts?
    By marcuslee in forum thinAir General
    Replies: 9
    Last Post: 22-03-2009, 11:18
  4. difference between .tbasic and .tbasicc
    By sandyrepope in forum Console
    Replies: 4
    Last Post: 22-05-2008, 23:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •