UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on March 16, 2010, 10:35:31 PM

Title: Compiler Log File Viewer
Post by: kevin on March 16, 2010, 10:35:31 PM
 Compiler Log File Viewer

    This example loads the PB compilers log file and lets you view it..

    Controls,
 
            Up Arrow = Up one line
        Down Arrow = Down one line

          Left Arrow = Back one page
        Right Arrow = forward one page

        Left Shift+  Left Arrow =  start of file
        Left Shift+  Right Arrow = End of File


[pbcode]

   File$=GetLogPath()

dim l$(0)
if fileexist(File$)
   Size=Filesize(file$)
   print "Loading Log FIle ("+Str$(Size)+")bytes...Please wait.."
   Sync
      
   t=timer()
    LoadTextFileToArray_String(File$,L$())
   t=timer()-t

   print "Load Time In Seconds"+Str$(t/1000)
   sync

   SetFps 40
   Offset=0
   Do
      Cls 0
      th=GetTextHeight("Y")      

      Rows=GetArrayElements(l$(),1)
      ScreenRowcount=GetScreenHeight()/th
      If (ScreenRowCount*Th) < ScreenRowCount then Inc ScreenRowCount

      Ypos=0
      for lp=Index to GetArrayElements(l$(),1)
         text Xpos,Ypos,l$(lp)      
         Ypos=Ypos+th
         if Ypos>=GetScreenHeight() then exit
      next

      if upkey()=true and Index>0
            dec index
      endif
      if downkey()=true  and  Index<=(GetArrayElements(l$(),1)-ScreenRowCount)
            inc index
      endif

      if leftkey()=true
            Index=Index-(ScreenRowCount-1)
            if shiftkeys(1)=true
                  Index=0
            endif
      endif


      if rightkey()=true
            Index=Index+(ScreenRowCount-1)
            if shiftkeys(1)=true
                  Index=GetArrayElements(l$(),1)
            endif
      endif

      Clip=(GetArrayElements(l$(),1)-ScreenRowCount)
      Index=ClipRange(Index,0,Clip)

      ink $00ff00
      t$="Line:"+digits$(Index,6)+" Of "+digits$(GetarrayElements(l$(),1),6)
      text GetScreenWidth()-(GetTextWidth(t$)+10),GetScreenheight()-30,t$
      ink $ffffff

      sync
   loop esckey()




else
   Print "error Can't find log file"
endif

Sync
waitkey

end


Constant  CSIDL_LOCAL_APPDATA = $1C          ;{user}\Local App Data Settings _

Function GetLogPath()
// Get the location of a Special windows folder
AppDir$=GetSpecialFolderPath(CSIDL_LOCAL_APPDATA)
File$=AppDir$+"\PlayBasic\Logs\Compiler.log"

EndFunction File$
                             
LinkDll "shell32"
   SHGetFolderPath(hWndOwner,nFolder,hToken,dwFlags,pszPath) Alias "SHGetFolderPathA"  as integer
EndLinkDll


Function GetSpecialFolderPath(nFolderID)
   // Alloc a bank of 1024 bytes for the function to return the path in
   Size=1024
   ThisBank=newbank(Size)
   Ptr=GetBankPtr(thisBank)
   Status=SHGetFolderPath(0,nFolderID,0,0,ptr)
   if Status=0
         // if status is 0 then the function worked
         Path$=PeekString(ptr,0)   ; peek a null termed string         
   else
         #print "error polling path"
   endif
   Deletebank ThisBank
EndFunction path$





; *=----------------------------------------------------------------------=*
;                    >> Load Text File To Array (String Version) <<
; *=----------------------------------------------------------------------=*
;
;   This function loads the text file into the array. It uses PB's build in
;  string function to the brute parsing force work.  Unlike the SplitToArray
; version, the resulting String Array with retain the NUll lines and original
;  formatting.  So This is probably the best all around general solution.
;
; *=----------------------------------------------------------------------=*



Function LoadTextFileToArray_String(Filename$,me$())
      ; Load the TextFile to array
   Dim me$(0)   
   if fileexist(FIlename$)

      Size=FileSize(filename$)

      TempBank=NewBank(Size+100)

      ; Load the data into this bank directly
      f=OpenNewfile(Filename$)
         ReadMemory  f,getbankptr(TempBank),Size
      CloseFile f         

      s$=PeekString(GetBankPtr(tempBank),Size)

      DeleteBank TempBank

      ArraySize      =0
      StringCount      =0               
      Output=0         

      LineBreak$   =(chr$(13)+chr$(10))
      LastPos      =1

      Size=Len(s$)
         While   LastPos<Size   
            LineBreakPos=Instring(s$,LineBreak$,LastPos,false)
            if lineBreakPos>0
               ThisLine$=Mid$(s$,LastPos,LineBreakPos-LastPos)      
               LastPos   =LineBreakPos+Len(LineBreak$)
            else
               ThisLine$=Mid$(s$,LastPos,Size-LastPos)      
               LastPos=Size+1
            endif


            // Add fragment to arrya
            if ArraySize<=StringCount
               ArraySize=ArraySize+4096
               redim Me$(ArraySize)
            endif
            if Len(ThisLine$)
               Me$(StringCount)=ThisLine$
            endif
            inc StringCount
         EndWhile

      ; resize the array to the number of strings read
      Redim me$(StringCount)

   endif
EndFunction





[/pbcode]