It is currently Wed Jun 20, 2018 10:32 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Finder all occurences of %WORD (line# & line to log window)
PostPosted: Mon Mar 12, 2018 1:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Feb 01, 2012 3:30 pm
Posts: 676
Location: Nottinghamshire UK
Hi to all. I have created this simple pb ide tool as I think its lacking in the ide thought some may like its use too.

Basically the tool searches for all occurrences of the word under the cursor and displays the line nbr and the line itself in
the ide console log windows
thanks to RSBasic for the speech dll`s :)

usage:
set as tool in the tools section:
params : %FILE %WORD
Set Icon to tool bar (finder icon in the zip package) (ico file, pb source file, x2 dll files)

cursor over word and select finder icon in toolbar.
Zebuddi. :)

https://goo.gl/mtijCn dll`s & icon file/s

Code:
EnableExplicit

;{ Thanks to RSBasic :) and all others not mentioned for use of there code
Define PBEx_Speech
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
   PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x86.dll")
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
   PBEx_Speech = OpenLibrary(#PB_Any, "PB.Ex_Speech_x64.dll")
CompilerEndIf

Prototype TextToSpeaker(Text.p-Unicode, Voice.p-Unicode, Speed, Volume, Asynchronous, ErrorOutput)
Global TextToSpeaker.TextToSpeaker = GetFunction(PBEx_Speech, "TextToSpeaker")   
;}


#Partition$ = "----------------------------------------------------------------------------------------------------------" +
              "----------------------------------------------------------------------------------------------------------"

Structure LINEDATA
   iLineNbr.i
   sLine.s
EndStructure : NewMap _map_linedata.LINEDATA() : NewList _ll_linedata.LINEDATA()

Procedure.s sGetLastErrorAsText() ; Used to get Last Win32 API Error
   Protected sMessage.s, iLastError.i, *ErrorBuffer
   iLastError=GetLastError_()
   If iLastError=1309 : iLastError=0 : EndIf
   If iLastError
      *ErrorBuffer = AllocateMemory(1024)
      FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, iLastError, 0, *ErrorBuffer, 1024, 0)
      sMessage = PeekS(*ErrorBuffer)
      FreeMemory(*ErrorBuffer)
   EndIf
   ProcedureReturn sMessage
EndProcedure

Procedure   WriteIDELog(Message$)
   Protected CopyData.COPYDATASTRUCT
   Protected IDEWindow = Val(GetEnvironmentVariable("PB_Tool_MainWindow"))
   If IDEWindow And Message$
      CopyData\dwData = ('L' << 16) | ('O' << 8) | 'G'
      CopyData\cbData = StringByteLength(Message$, #PB_Ascii)
      CopyData\lpData = AllocateMemory(CopyData\cbData + 1)
      If CopyData\lpData
         PokeS(CopyData\lpData, Message$, -1, #PB_Ascii)
         SendMessage_(IDEWindow, #WM_COPYDATA, #Null, @CopyData)
         FreeMemory(CopyData\lpData)
      EndIf   
   EndIf
EndProcedure

Procedure.s ProcessFileToString(sFileName.s)
   Protected *Buffer, iFileNbr.i, iFileSize.i, iNbrReadBytes.i, sReturn.s
   If ReadFile(iFileNbr, sFileName)
      iFileSize = Lof(iFileNbr)
      *Buffer = AllocateMemory(iFileSize)
      If *Buffer
         ReadStringFormat(iFileNbr)
         iNbrReadBytes = ReadData(iFileNbr, *Buffer, iFileSize)
         If iNbrReadBytes ;= (iFileSize - bBom)
            sReturn = PeekS(*Buffer, iNbrReadBytes, ReadStringFormat(iFileNbr))
            FreeMemory(*Buffer)
            CloseFile(iFileNbr)
            ProcedureReturn sReturn
         EndIf
      Else
         WriteIDELog("Finder: --->    [Memory Allocation Error ---> Failed To Allocate Memory" + Chr(32) +
                     " *Buffer " + Chr(32) + " --->    SysERR( " + sGetLastErrorAsText() + " )")
         CloseFile(iFileNbr)
      EndIf
   Else
      WriteIDELog("Finder: --->    [ ReadFile() Error ---> Failed To ReadFile() ]    " + Chr(34) +
                  sFileName + Chr(34) +   " --->    SysERR( " + sGetLastErrorAsText() + " )")
   EndIf   
EndProcedure

Procedure MapToList(Map _map_linedata.LINEDATA(), List _ll_linedata.LINEDATA())
   ForEach _map_linedata()
      AddElement(_ll_linedata())
      _ll_linedata()\iLineNbr = Val(MapKey(_map_linedata()))
      _ll_linedata()\sLine   = _map_linedata()\sLine
   Next   
   SortStructuredList(_ll_linedata(), #PB_Sort_Ascending, OffsetOf(LINEDATA\iLineNbr), TypeOf(LINEDATA\iLineNbr))
EndProcedure

Procedure processData(sString.s, sWordUnderCursor.s, Map _map_linedata.LINEDATA(), List _ll_linedata.LINEDATA())
   If ProgramParameter(0) And ProgramParameter(1)
      Protected iIndex.i, iNbrLinesInFile.i = CountString((sString + #CRLF$), #CRLF$)
      For iIndex = 0 To iNbrLinesInFile
         If FindString(StringField(sString, (iIndex + 1), #CRLF$), sWordUnderCursor)
            AddMapElement(_map_linedata(), Str(iIndex + 1))
            _map_linedata()\sLine = StringField(sString, (iIndex + 1), #CRLF$)
         EndIf   
      Next
      
      MapToList(_map_linedata(), _ll_linedata())
      WriteIDELog(" ")
      WriteIDELog(#Partition$)
      ForEach _ll_linedata()
         WriteIDELog( "[ " + sWordUnderCursor + " ]  " + "Line @ " + RSet(Str(_ll_linedata()\iLineNbr), 5, "0") + ".  " +  _ll_linedata()\sLine)
      Next
      WriteIDELog("Hit`s: ---> " + ListSize(_ll_linedata()))
      WriteIDELog(#Partition$)
      WriteIDELog(" ")
      
      FreeList(_ll_linedata())
      FreeMap(_map_linedata())
   Else
      If Not Bool(ProgramParameter(1))
         Define ErrorOutput$
         WriteIDELog("You " + UserName() + " For got To put your word on the cursor. Or was it. The other way around.")
         ;large spaces required for pausing in speech
         If Not TextToSpeaker("Hey    " + UserName() + ".          You forgot To put your word on the cursor.             Or was it            the other way around",
                              "Microsoft Hazel Desktop", 0.4, 100, 0, @ErrorOutput$)
            WriteIDELog(ErrorOutput$)
         EndIf   
      EndIf   
   EndIf
EndProcedure

;---------MAIN-------------

processData(ProcessFileToString(ProgramParameter(0)), ProgramParameter(1), _map_linedata(), _ll_linedata())
CloseLibrary(PBEx_Speech)
End



Image

_________________
malleo, caput, bang. Ego, comprehendunt in tempore


Top
 Profile  
Reply with quote  
 Post subject: Re: Finder all occurences of %WORD (line# & line to log win
PostPosted: Mon Mar 12, 2018 1:42 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 558
Location: Berlin and Ibiza
Image

Zebuddi123 wrote:
thanks to RSBasic for the speech dll`s :)

Thanks for the feedback. :)
I thought I had programmed my DLL for nothing. :D

\\Edit:
Please use:
Code:
Define ErrorOutput$ = ""

Otherwise my DLL cannot save the error in the variable.

And note the following:
Quote:
Return value:
  • 0: The process was successful.

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: Finder all occurences of %WORD (line# & line to log win
PostPosted: Thu Mar 15, 2018 3:03 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4132
Location: Lyon - France
Works great on W10 x64, without sound
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye