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
    86
    Posts
    80
    Rep Power
    24

    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
    86
    Posts
    80
    Rep Power
    24
    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
    7,153
    Rep Power
    736
    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 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    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.
    Home Desktop : Windows 7 - 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 : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  5. #5
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    86
    Posts
    80
    Rep Power
    24
    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
    86
    Posts
    80
    Rep Power
    24
    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
    Senior Member zak's Avatar
    Join Date
    Dec 2008
    Posts
    637
    Rep Power
    83
    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
    57
    Posts
    8,817
    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/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    Member dcromley's Avatar
    Join Date
    Apr 2009
    Location
    Wyoming, USA
    Age
    86
    Posts
    80
    Rep Power
    24
    < .. 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
    57
    Posts
    8,817
    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/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

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

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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