Announcement

Collapse
No announcement yet.

PbSlice 2

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PbSlice 2

    In a small departure from the original PbSlice I decided to start implementing core abilities available using an API. Here's the first release of PbSlice 2 core functions. It can be either included or used from a DLL. The test directory has a couple examples of using the library as source.

    There about 277 routines in the API that can do things like tokenize code, standardize export aliases, add debugging aliases, remove aliases, format as BBCode or html, remove line continuations, standardize formatting, manage inter routine spacing, etc.

    In addition it's split between two major groups: Project/Files and snippets.

    Projects are essentially all the files loaded from loading a main file. The files api provides a way to work with individual files in the project.

    Snippets are unassociated source code blocks. Can be saved to files.
    LarryC
    Website
    Sometimes life's a dream, sometimes it's a scream

  • #2
    Larry,

    are we supposed to change the directories in any of the files other than what
    you mentioned in the readme?

    the pbstest compiled fine but am getting some missing keywords in the log.
    I've attached a zip with the trace txt file. I seem to be getting a lot of
    messages about being different ( obvious when you look thru the file ).
    I unzipped your files on my E: drive under E:\PBCC and fixed a small error
    when you create clean.cmd to not always default to the C: drive.

    Have you made changes since you first posted?

    Just curious.
    Attached Files

    Comment


    • #3
      I renamed the my directory tree in two places. I edited src\pbslice.inc and did a search/replace. I added the new src path to my search directories and it generally works. It tosses off a few errors because path names have changed in the test files versus the new directory structure but nothing like the errors you're seeing. I did see a couple of PB errors pop-up. I'll peek through and see if I can get rid of those as well.
      LarryC
      Website
      Sometimes life's a dream, sometimes it's a scream

      Comment


      • #4
        weren't the changes to pbslice.inc just to get the test program to compile?
        shouldn't every other reference to a file's location should be based on the
        exe's location as the base?

        I searched all bas & inc files for a reference to c:\prj and after making the changes you mentioned in the
        readme the only ones were in test.bas in 2 sub-dirs. I don't see how they could cause problems as they
        are just input files for your tests.

        am I the only one having problems?
        Last edited by Paul D. Elliott; 22 Aug 2012, 05:41 PM.

        Comment


        • #5
          Larry,

          in debugging.inc did you mean for the 2 macro debug_isequal to be different?
          one checks for = and the other checks for <>.
          that would explain why I got all those extra messages. I had %Review=1.

          Comment


          • #6
            Yes. Review was so I could review the messages and make sure they were ok even when I didn't have errors.
            LarryC
            Website
            Sometimes life's a dream, sometimes it's a scream

            Comment


            • #7
              Larry,

              Very good work. At least on the indenting code ( that's all I've looked at so far).
              Just a minor problem with Thread. You have 2 Thread statements in you GDI
              Plus test program and I think it considers both of them to be Functions.

              I've been looking at how to combine your code into the Code Formatter that
              I've been working on over on Jose's forums. Not sure yet if it is possible but
              may consider calling your FileIndent after all the other formatting is done. The
              only difference I noticed is where I put in extra code to align your array
              assignments and on the Declares to align the continued lines under the
              opening (.

              I was able to create a new array with just the continued lines and can use
              it in certain spots. But am thinking that I may force certain areas to use
              the combined lines instead of the split lines ( mainly in Type/Union/Enum
              blocks ). am still working on your quirks & testindent files to see if I can figure
              a way to handle all those aplit areas.

              If I get time, I'll post the simple program that I did to run FileIndent on the
              output of the formatter.

              Once again, THANKS!

              Comment


              • #8
                Simple ( after a couple hours of trial & error ) and it works.
                Just follow Larry's instructions for setting up PBSlice2.
                Compile with PB CC v6.03 but probably easy to put in the PB Win format.


                Code:
                #Compile Exe
                #Dim All
                
                ' Using PbSlice source for tests (Allows debugging)
                #Include "PBSlice2.inc"
                #Include Once "src\api\file.inc"
                
                Function PBMain () As Long
                   Local tmrBgn As Double
                   Local tmrEnd As Double
                   Local inFile As String
                   Local wrkFile As String
                   Local x As Long
                
                   Do
                      Line Input "base file w/ext ", inFile
                      If inFile = "" Then Exit Function
                      If Not IsFile(inFile) Then
                         Print "can not find "; inFile
                         Print
                         Iterate Do
                      End If
                      x = InStr(inFile, ".")
                      If x > 1 Then
                         wrkFile = Left$(inFile, x) & "out"
                      Else
                         wrkFile = inFile & ".out"
                      End If
                      FileCopy inFile, wrkFile
                   Loop While wrkFile = ""
                
                   tmrBgn = Timer
                   Call pbsProjectLoad(wrkFile)
                   Call pbsFileActivate(0)
                   Call pbsFileIndent
                   Call pbsFileSetIsExternal(0)
                   Call pbsFileSave
                   tmrEnd = Timer
                
                   Beep
                   Print "elapsed "; Format$(tmrEnd - tmrBgn, "##.####")
                   Print "waiting ? ";
                   WaitKey$
                
                
                End Function

                Comment


                • #9
                  Great first pass! The code is a bit unusual in terms of the library (but works). Here's a bit of background on that.

                  Generally projects are all the files loaded by loading a source file.

                  External files are files that are not in the same directory tree as the first file loaded.

                  The file routines are for manipulating a single file in a project.

                  Snippets are for manipulating independent source code (like indenting a single file).

                  What made it unusual to me, is you loaded all the files associated with wrkFile, but then focused on only wrkFile (the first file). Also you ensured wrkFile was not external, which it couldn't be since it was the first file loaded.

                  Here's some variations on the code with comments that might make more sense than my rambling:

                  Code:
                  '=======================================================================
                   ' Original
                  Call pbsProjectLoad(wrkFile)     ' Load all files associated with wrkFile
                  Call pbsFileActivate(0)          ' Focus on wrkFile
                  Call pbsFileIndent               ' Indent only wrkFile
                  Call pbsFileSetIsExternal(0)     ' ? File 0 will always not be external since it's the primary file
                  Call pbsFileSave                 ' Save just the wrkFile
                   ' wrkFile remains part of project
                   '=======================================================================
                   '
                   '=======================================================================
                   ' Snippet based
                  Call pbsSnippetNew("Indent"):  ' creates and activates snippet named indent
                  Call pbsSnippetLoad(wrkFile)   ' Loads a single file
                  Call pbsSnippetIndent          ' Indent single file
                  Call pbsSnippetSave            ' Save single file
                  Call pbsSnippetClose("Indent") ' Close snippet when done (only releases memory)
                   ' Note closing is only needed if you don't intend to use the
                   ' snippet any more.  We could clear it and continue in memory,
                   ' or load another file and work with it also.  You only need
                   ' multiple snippet names if you intend to work with multiple
                   ' unassociated sources.
                   '=======================================================================
                   '
                   '=======================================================================
                   ' Bit unusual, file in a project
                  Local fileNumber As Long
                   Call pbsFileLoad(wrkFile)                      ' Load a file into a project
                  fileNumber = pbsFileIndexFilename( wrkFile )   ' Find # of loaded file
                  Call pbsFileActivate( fileNumber )             ' Activate file
                  Call pbsFileIndent                             ' Indent file
                  Call pbsFileSetIsExternal(0):                  ' Ensure file is not external if not in project directory tree
                  Call pbsFileSave                               ' Save file to disk
                  Call pbsFileClose( fileNumber )                ' Close file: releases memory, removes from project
                   ' The file routines are there when you really don't want every non-external
                   ' file in the project to have some change. (or if you want to do something
                   ' to an external file)
                   '=======================================================================
                   '
                   '=======================================================================
                   ' Indent all files in a project
                  Call pbsProjectLoad( wrkFile ):  ' Load all files loaded by compiling wrkFile
                  Call pbsProjectIndent:           ' Indent all non-external files
                  Call pbsProjectSave:             ' Save all non-external files
                  Call pbsProjectClose:            ' Close project (only releases memory for all files)
                   '=======================================================================
                  Edit: One other thing I could have mentioned. If you prefer spaces instead of tabs you could also use one or more of these:
                  • pbsFileExpandTabs( Optional ByVal tabSize As Long )
                  • pbsProjectExpandTabs( Optional ByVal tabSize As Long )
                  • pbsProjectGetTabsize() As Long
                  • pbsProjectSetTabsize ( ByVal tabSize As Long )
                  • pbsSnippetExpandTabs( Optional ByVal tabSize As Long )
                  Last edited by Larry Charlton; 26 Aug 2012, 07:42 AM.
                  LarryC
                  Website
                  Sometimes life's a dream, sometimes it's a scream

                  Comment


                  • #10
                    Here's the small mods to make it work on PBCC or PbWin;

                    Code:
                    #Compile Exe
                    #Compiler PBCC 6, PBWin 10
                    #Dim All
                    ' Using PbSlice source for tests (Allows debugging)
                    #Include "PBSlice2.inc"
                    #Include Once "src\api\file.inc"
                    Function PBMain () As Long
                       Local tmrBgn As Double
                       Local tmrEnd As Double
                       Local inFile As String
                       Local wrkFile As String
                       Local x As Long
                       Do
                    #If %Def( %PB_CC32 )
                          Line Input "base file w/ext ", inFile
                    #Else
                          inFile = InputBox$("Base file w/ext:" )
                    #EndIf
                          If inFile = "" Then Exit Function
                          If Not IsFile(inFile) Then
                    #If %Def( %PB_CC32 )
                             Print "can not find "; inFile
                             Print
                    #Else
                            MsgBox "Can not file "+inFile
                    #EndIf
                             Iterate Do
                          End If
                          x = InStr(inFile, ".")
                          If x > 1 Then
                             wrkFile = Left$(inFile, x) & "out"
                          Else
                             wrkFile = inFile & ".out"
                          End If
                          FileCopy inFile, wrkFile
                       Loop While wrkFile = ""
                       tmrBgn = Timer
                       Call pbsProjectLoad(wrkFile)
                       Call pbsFileActivate(0)
                       Call pbsFileIndent
                       Call pbsFileSetIsExternal(0)
                       Call pbsFileSave
                       tmrEnd = Timer
                    #If %Def( %PB_CC32 )
                       Beep
                       Print "elapsed "; Format$(tmrEnd - tmrBgn, "##.####")
                       Print "waiting ? ";
                       WaitKey$
                    #Else
                       MsgBox "Elapsed " + Format$(tmrEnd - tmrBgn, "##.####")
                    #EndIf
                    End Function
                    LarryC
                    Website
                    Sometimes life's a dream, sometimes it's a scream

                    Comment


                    • #11
                      Larry,

                      Ok, I probably could have done it easier & better but used the first file I found
                      with all the parts I thought I needed and went from there.

                      On the small thing with Thread, it was just missing a "=0" on the 2nd
                      If statement under the Thread case.

                      As for tabs, I just replaced your Repeat $tab statement with " ". I'm guessing
                      that most of your programs have only tabs at the begining of a line ( no
                      spaces ) because you're replacing a count of both space & tab with tab.
                      wouldn't that throw off any alignment if you had a mixture?
                      will have to check out those routines that you mentioned.

                      I still like it.

                      Comment


                      • #12
                        No worries, looked great and did what you wanted.

                        On the small thing with Thread, it was just missing a "=0" on the 2nd
                        If statement under the Thread case.
                        Context?

                        What the indenter does is remove all leading characters. It then inserts the # of tabs based on the indent level at the begining of the line.

                        When you replace tabs with spaces you can specify how many spaces make up a tab. I originally had the indenter doing either (tabs or spaces) but tabs were more flexible (they adapt automatically to user tab settings and changes in user tab settings) so I split tabs to spaces into a separate routine.
                        LarryC
                        Website
                        Sometimes life's a dream, sometimes it's a scream

                        Comment


                        • #13
                          Context? from memory, in the routine that does the actual indenting you have a
                          Case statment with Thread & something else. there are 2 If statements
                          under the Select and the 2nd If has a PtrStrICmp statement but is missing
                          the "=0" before the Then. You can't miss it. Even I found it but don't have
                          it on this computer.

                          I understand about yout use of tabs but I can never remember how big a tab
                          is supposed to be in the different files ( and just never really liked 8 spaces
                          per tab ).

                          Comment


                          • #14
                            Thanks found it. It'll be at least tommorow before an update posted. Somewhere in the shuffle looks like an issue cropped up with creating DLL includes also, I'll get that fixed before updating.
                            LarryC
                            Website
                            Sometimes life's a dream, sometimes it's a scream

                            Comment


                            • #15
                              Updated. Fixed bug mentioned above. Also fixed issues with some of the declare routines if you have multi-file projects.

                              You can download it here.
                              LarryC
                              Website
                              Sometimes life's a dream, sometimes it's a scream

                              Comment


                              • #16
                                • Fixed bug in pbsSnippetCount
                                • Fixed bug in pbsStringTrimWhitespace
                                Download latest here.
                                LarryC
                                Website
                                Sometimes life's a dream, sometimes it's a scream

                                Comment


                                • #17
                                  Larry,

                                  Just tried your new version and hit a snag.

                                  running the test program, got 2 "System could not find file" messages
                                  and a subscript error. tried commenting out #Display Error and running in
                                  Debugger Animate mode. Gave up after an hour and it still hadn't gotten to
                                  the error. Tried just Run in Debugger but it stopped with the yellow line
                                  hilighted was End Sub. will try again later to see if I can find where in which
                                  source it is stopping.

                                  Does this new version require anything from your updated PBUtil?

                                  Comment


                                  • #18
                                    Ok, I loaded it on this computer & ran in debugger.

                                    in Project.inc line 215 ( the For i = line )
                                    Code:
                                       ' Remove any invalid paths
                                       For i = includePathCount_-1 To 0 Step -1
                                          includePaths_(i) = Trim$( includePaths_(i) ): ' Remove leading/trailing spaces
                                          If Right$( includePaths_(i), 1 )<>"\" Then includePaths_(i) += "\": 'Ensure ends with \
                                    
                                          If IsFalse IsFolder( includePaths_(i) ) Or includePaths_(i)="\" Then
                                             Decr includePathCount_
                                             For j=i To includePathCount_-1
                                                Swap includePaths_(j), includePaths_(j+1)
                                             Next
                                          End If
                                       Next
                                    includePathCount_ = 0
                                    but it seems that err 9 should be on line 216,

                                    I'm not going to try to figure out why
                                    For i = -1 to 0 step -1 runs but I'm not going to worry about it.
                                    And please, don't try to explain it to me.

                                    Comment


                                    • #19
                                      Doesn't require anything from pbutil. There are comments in the include files that need to be followed to recompile. Which program were you trying to compile, the DLL, or one of the test apps?

                                      I've fixed the bug you mentioned with include files. In general it helps to either know the program and circumstances or the code you're trying. I'm in the process of writing more tests so with luck most will be fixed soonish. If you have the option of writing a test that fails, it would really help. Either way thanks for the reports, I really appreciate them.

                                      I'll get it updated sometime this weekend unless you need it sooner. Connections a bit slow at the house
                                      LarryC
                                      Website
                                      Sometimes life's a dream, sometimes it's a scream

                                      Comment


                                      • #20
                                        • Fixed a bug when setting no includePaths
                                        • Fixed a bug in compress signature when the signature was empty
                                        • Fixed a bug in GetToken when token was out of range
                                        • Fixed a bug in ReplaceText for text lines that should be appended
                                        Latest download is here.
                                        LarryC
                                        Website
                                        Sometimes life's a dream, sometimes it's a scream

                                        Comment

                                        Working...
                                        X