It is currently Sun May 31, 2020 12:24 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: IDE tool for the new Define Standard =>5.60
PostPosted: Fri Jan 27, 2017 6:49 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Feb 01, 2012 3:30 pm
Posts: 766
Location: Nottinghamshire UK
Hi to all. Here`s a little tool I made to search the current tab in use in the IDE for the old Define standard. IE: Define.type to the new standard Define var.type

1. opens a small window with list view of any old defines to new defines in a listview
2. right mouse click in the listview popupmenu to copy the selected item to the clipboard, Line Nbr is also shown
3. any var defined as Define.s test, answer, question, t.type, p.option the t.type, p.option will keep there respective type in the new define.

IDE: Tool arguments %FILE %TEMPFILE

Hope its useful to some :)
Zebuddi.

Code:
EnableExplicit

#FileIO = 0

Structure MatchList
   sLnum.s
   sStrf.s
EndStructure

Structure StrList
   sPath.s
   sFile.s
   List MatchList.MatchList()
   sSearchTime.s
EndStructure

Global MainWin,  Button_0, ListIcon_Lnbr, ListIcon_Define

Define sFindStr.s =  "Define\..+?", event.i
Define sThisFile.s = ProgramParameter(0)

NewList gStrFound.StrList() ;Info displayed in a ListIcon, User can delete selected  rows

Procedure.b RegexFileFindString(sFindStr.s, sFile.s, List gStrFound.StrList())
   Protected sLine.s, dgStartTime.d, iLine.i
   Protected regex = CreateRegularExpression(#PB_Any, sFindStr)
   
   SetPriorityClass_(GetCurrentProcess_(), #HIGH_PRIORITY_CLASS) ;#ABOVE_NORMAL_PRIORITY_CLASS)
   
   If ReadFile(#FileIO, sFile)
      
      If(Lof(#FileIO) > 0)
         
         AddElement(gStrFound())
         dgStartTime = ElapsedMilliseconds() : iLine = 0
         
         Repeat
            sLine = ReadString(#FileIO)
            iLine +1
            If regex
               If MatchRegularExpression(regex, sLine)
                  AddElement(gStrFound()\MatchList())
                  gStrFound()\MatchList()\sLnum = Str(iLine)
                  gStrFound()\MatchList()\sStrf = Trim(sLine)
               EndIf
            Else
               Debug "RegularExpression Error"
            EndIf
         Until Eof(#FileIO)
      EndIf
   Else
      Debug " error reading file"
   EndIf
   FreeRegularExpression(regex)
   SetPriorityClass_(GetCurrentProcess_(), #NORMAL_PRIORITY_CLASS)
   
   If ListSize(gStrFound()\MatchList()) > 0
      gStrFound()\sPath = GetPathPart(sFile)
      gStrFound()\sFile = GetFilePart(sFile)
      gStrFound()\sSearchTime = Str(((ElapsedMilliseconds() - dgStartTime))) + "ms"
      ProcedureReturn  #True
   Else
      ClearList(gStrFound())
      ProcedureReturn #False      
   EndIf   
   FreeRegularExpression(regex)
EndProcedure

Procedure.s MakeNewDefine(sString.s)
   
   ; matches the type after  the define."type" and replaces that in the new defenition type ie: Define s.p, o.token , p.i  etc
   ; if another type is defined in the line these are ingnored and kept
   
   Protected Dim _asVarType$(0) , Dim _asVar$(0), iVnbr.i, iIndex.i, n$
   Protected iRegex = CreateRegularExpression(#PB_Any, "(?<=Define\.).+?\s")
   Protected iRegex_vars = CreateRegularExpression(#PB_Any, "\s.+?(?=,)")
   
   sString + Chr(44)
   If MatchRegularExpression(iRegex, sString)
      ExtractRegularExpression(iRegex, sString, _asVarType$())
      iVnbr = ExtractRegularExpression(iRegex_vars, sString, _asVar$())
      For iIndex= 0 To iVnbr-2
         If FindString(_asVar$(iIndex), Chr(46))
            n$ + Trim(_asVar$(iIndex)) + Chr(44) + Chr(32)
         Else
            n$ + Trim(_asVar$(iIndex)) + "." + Trim(_asVarType$(0)) + Chr(44) + Chr(32)
         EndIf   
      Next
      If FindString(_asVar$(iVnbr-1), Chr(46))
         ProcedureReturn "Define " + n$ + _asVar$(iVnbr-1)
      Else
         ProcedureReturn "Define " + n$ + _asVar$(iVnbr-1) + "." +  _asVarType$(0)
      EndIf   
   Else
      ProcedureReturn "Error Processing String"
   EndIf
   FreeRegularExpression(iRegex)
   FreeRegularExpression(iRegex_vars)
   FreeArray(_asVarType$())
   FreeArray(_asVar$())
EndProcedure

Procedure CopyNewDefine()
   DisplayPopupMenu(0, WindowID(MainWin),DesktopMouseX(),DesktopMouseY())
   SetClipboardText(GetGadgetItemText(ListIcon_Define, GetGadgetItemState(ListIcon_Define, #PB_ListIcon_Selected ),0))
EndProcedure

Procedure OpenWindowMain(x = 0, y = 0, width = 600, height = 375)
  MainWin             = OpenWindow(#PB_Any, x, y, width, height, " Pure Define Updater   Create`s the new Define standard  from the old Define standard for PB 5.60+", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ListIcon_Lnbr       = ListIconGadget(#PB_Any, 5, 10, 100, 360, "LineNbr", 97, #PB_ListIcon_GridLines) : SetGadgetColor(ListIcon_Lnbr,  #PB_Gadget_LineColor, $A0A0A0)
  ListIcon_Define    = ListIconGadget(#PB_Any, 110, 10, 485, 360, "New Define String", 482, #PB_ListIcon_GridLines) : SetGadgetColor(ListIcon_Define, #PB_Gadget_LineColor, $A0A0A0)
  If CreatePopupMenu(0)
        MenuItem(0, "Copy")
  EndIf
 EndProcedure

Procedure MainWin_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
       
    Case #PB_Event_Gadget
       Select EventGadget()
          Case ListIcon_Define
             Select EventType()
                Case #PB_EventType_RightClick 
                   CopyNewDefine()
             EndSelect
       EndSelect
EndSelect
ProcedureReturn #True
EndProcedure

OpenWindowMain()

If RegexFileFindString(sFindStr, sThisFile, gStrFound()) =#True
   ForEach gStrFound()\MatchList()
      AddGadgetItem(ListIcon_Lnbr, -1, gStrFound()\MatchList()\sLnum)
      AddGadgetItem(ListIcon_Define, -1, MakeNewDefine(gStrFound()\MatchList()\sStrf))
   Next   
EndIf

Repeat
  event = WaitWindowEvent()
Until MainWin_Events(event) = #False

End

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


Top
 Profile  
Reply with quote  
 Post subject: Re: IDE tool for the new Define Standard =>5.60
PostPosted: Fri Jan 27, 2017 9:00 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14064
Location: France
Code:
Define.s test, answer, question, t.type, p.option


This syntax is still supported in 5.60. Only empty statement like:

Code:
define.b
a = 400 ; I'm a byte


won't be accepted anymore


Top
 Profile  
Reply with quote  
 Post subject: Re: IDE tool for the new Define Standard =>5.60
PostPosted: Fri Jan 27, 2017 9:59 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Feb 01, 2012 3:30 pm
Posts: 766
Location: Nottinghamshire UK
Thanks Fred. Sorry I misunderstood :oops: lol

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


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 11 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