We made some handy code that will find orphaned puts in our LiveCode projects. I'll post it here in its entirety. It references some UI that is part of a bigger Developer Tool we use in-house. You can focus on the relevant handlers and change the field reference to something else. You could also just dump the results into a variable and out-put it to the message box (hahaha).
You can use regex or filter. I do not remember why I stayed with the filter option. Both options are there for you to use.
Code: Select all
//>GLOBALS
global gSavedStackRect, gSoftwarePasskeys
on mouseUp
local tHeight, tMainStackList, tSavedStackHeight, tSavedTop
//DOCUMENTATION
//THIS CODE WILL FIND ORPHANED PUTS THROUGHOUT YOUR PROGRAM
//YOUR CODE WILL NOT BE TOUCHED IN YOUR PROGRAM
//INPUT: NO INPUT
//ACTION: CLICK 'GLOBAL PUT' BUTTON
//OUTPUT: A DROP DOWN WINDOW WILL APPEAR UNDER THE TOOLS
//A LIST OF LINES THAT WERE FOUND WILL BE GENERATED
//CLICK ANY OF THE LINES TO BE TAKEN TO YOUR ORPHANED PUT LINE
lock screen
put empty into fld "clean put" of this stack
set vis of fld "clean put" of this stack to not(vis of fld "clean put" of this stack)
--HIDE PUT RESULTS
if not(vis of fld "clean put" of this stack) then
if gSavedStackRect is empty then put "0,42,1021,97" into gSavedStackRect
set the rect of stack "dev tools" to gSavedStackRect
delete variable gSavedStackRect
exit to top
end if
put the mainstacks into tMainStackList
put lf & the stacksInUse after tMainStackList
filter tMainStackList without "rev*"
filter tMainStackList without "Message Box"
filter tMainStackList without "DEV TOOLS"
filter tMainStackList without "com.livecode*"
filter tMainStackList without "ws.*"
filter tMainStackList without "tsNet*"
filter tMainStackList without "home"
filter tMainStackList without "answer dialog"
filter tMainStackList without "ask dialog"
csFindErrantPuts tMainStackList
--STORE STANDARD SIZE VALUES
put the rect of stack "dev tools" into gSavedStackRect
put the height of stack "dev tools" into tSavedStackHeight
put the top of stack "dev tools" into tSavedTop
--SIZE DEV TOOLS TO SHOW ALL RESULTS
put the formattedHeight of fld "clean put" into tHeight
put min(tHeight,700) into tHeight
set the height of stack "dev tools" to (tHeight + (tSavedStackHeight * 2))
set the top of stack "dev tools" to tSavedTop
--SIZE CLEAN PUT FIELD TO SHOW ALL RESULTS
set the width of fld "clean put" to the width of stack "dev tools"
set the left of fld "clean put" to 0
set the height of fld "clean put" to (tSavedStackHeight + tHeight)
set the top of fld "clean put" to tSavedStackHeight
unlock screen
end mouseUp
on csFindErrantPuts pMainStacks
local tSubstackList
repeat for each line xMainStack in pMainStacks
--GENERATE LIST OF SUBSTACKS TO MAINSTACK
put the substacks of stack xMainStack into tSubstackList
--CHECK MAINSTACK SCRIPT
checkMainstackScript xMainStack
--CHECK CARD SCRIPT OF MAINSTACK
checkCardScript xMainStack
repeat for each line xSubstack in tSubstackList
--CHECK STACK SCRIPT
checkSubstackScript xSubstack, xMainStack
--CHECK THE CARDS
checkCardScript xSubstack, xMainStack
end repeat
end repeat
end csFindErrantPuts
command checkMainstackScript pStack
local tScript, tStackLongID
put the long id of stack pStack into tStackLongID
put getScript(tStackLongID) into tScript
if tScript is not empty then cleanScript tScript, pStack
end checkMainstackScript
command checkSubstackScript pParentStack, pMainstack
local tScript, tStackLongID
put the long id of stack pParentStack into tStackLongID
put getScript(tStackLongID) into tScript
if tScript is not empty then cleanScript tScript, pParentStack
end checkSubstackScript
on checkCardScript pParentStack, pMainstack
local tCardCount, tCardList, tScript
if pMainstack is not empty then
--CHECKING A SUBSTACK
put num of cards of stack pParentStack of stack pMainstack into tCardCount
--BUILD A LIST OF THE CARD LONG IDS
repeat with xCard = 1 to tCardCount
put the long id of card xCard of stack pParentStack of stack pMainstack & lf after tCardList
end repeat
else
--CHECKING A MAINSTACK
put num of cards of stack pParentStack into tCardCount
--BUILD A LIST OF THE CARD LONG IDS
repeat with xCard = 1 to tCardCount
put the long id of card xCard of stack pParentStack & lf after tCardList
end repeat
end if
repeat for each line xCardLongID in tCardList
--GET CARD SCRIPT
put getScript(xCardLongID) into tScript
--CLEAN CARD SCRIPT
if tScript is not empty then cleanScript tScript, ,xCardLongID
--CHECK CONTROLS FOR THE CARD
checkControlScript xCardLongID, pParentStack, pMainstack
end repeat
end checkCardScript
on checkControlScript pCard, pStack
local tCardName, tControlCount, tControlCounter, tControlID
local tControlLongID, tControlName, tScript
put num of controls in pCard into tControlCount
put 0 into tControlCounter
repeat tControlCount
add 1 to tControlCounter
put the script of control tControlCounter of pCard into tScript
if tScript is not empty then
put the id of control tControlCounter of pCard into tControlID
put the long id of control tControlCounter of pCard into tControlLongID
put the short name of pCard into tCardName
put the name of control tControlCounter of card tCardName of stack pStack into tControlName
cleanScript tScript, pStack, tCardName, tControlLongID --WE WILL WANT TO ADD CARD DETAILS TO OUTPUT
end if
end repeat
end checkControlScript
function getScript pLongID, pItem
local tScript
if pItem is empty then put 1 into pItem
--ATTEMPT TO GET THE SCRIPT
try
put the script of pLongID into tScript
catch tError
try
set the passkey of pLongID to item pItem of gSoftwarePasskeys
put the script of pLongID into tScript
catch tError
add 1 to pItem
get getScript (pLongID,pItem)
end try
end try
put empty into pItem
return tScript
end getScript
command cleanScript pScript, pStack, pCard, pControlLongID
local tCompressedScriptA, tFoundLine, tFoundWord, tNoCommentedCode
local tNumOfDuplicates, tScriptMaster, tSkipLines, tTempLine
local tWordToFind
put pScript into tScriptMaster
--BUILD EXPRESSION
--put "^\s*put\s+\" & quote into tExpression
--FILTER CODE
--filter pScript with regex pattern tExpression
filter lines of pScript with "* put *"
filter lines of pScript without "*into*"
filter lines of pScript without "*after*"
filter lines of pScript without "*before*"
filter lines of pScript without "*\"
--REMOVE COMMENTED OUT CODE
repeat for each line xLine in pScript
put xLine into tTempLine
replace " " with empty in tTempLine
if char 1 to 2 of tTempLine = "//" or char 1 to 2 of tTempLine = "--" or char 1 to 2 of tTempLine = "##" then
--DO NOTHING
else
--REMOVE LINE FROM pScript
put xLine & lf after tNoCommentedCode
end if
end repeat
--PUT NO COMMENTED CODE BACK INTO pScript
put tNoCommentedCode into pScript
--PLACE DUPLICATES NEXT TO EACH OTHER THIS THIS LIST
sort lines of pScript
--COUNT DUPLICATE TERMS
repeat for each line xLine in pScript
add 1 to tCompressedScriptA[xLine]
end repeat
--WE MAY HAVE DUPLICATE TERMS TO SEARCH FOR
--THUS, WE MUST DESIGN THE REPEAT TO SEARCH FOR DUPLICATE TERMS ALL THE WAY THROUGH THE CODE BEFORE MOVING TO THE NEXT SEARCH TERM
set wholeMatches to true
repeat for each key xTerm in tCompressedScriptA
put tCompressedScriptA[xTerm] into tNumOfDuplicates
put 0 into tSkipLines
repeat with xCurrentLine = 1 to tNumOfDuplicates
--FIND TERM
put lineOffset(xTerm,tScriptMaster,tSkipLines) into tFoundLine
if tFoundLine > 0 then put tSkipLines + tFoundline into tFoundline else next repeat
--CLEAN LEADING SPACES IN CODE
//NOTE TO SELF. DO NOT ATTEMPT TO REMOVE SPACES WHEN CREATING tCompressedScriptA
//BECAUSE IT WILL THROW OFF THE lineOffset SEARCH ABOVE AND CAUSE THE LINE NOT TO BE FOUND
put word 1 of xTerm into tWordToFind
put Offset(tWordToFind,xTerm) into tFoundWord
delete char 1 to (tFoundWord - 1) of xTerm
--GENERATE OUTPUT
switch
case pControlLongID is not empty
--CONTROL
put "line" && tFoundLine && "of CONTROL:" && pControlLongID && "CARD:" && pCard && "STACK:" && \
pStack & lf & " " & xTerm & lf after fld "clean put" of this stack
set the textColor of the last line of fld "clean put" to 140,140,140
exit switch
break
case pCard is not empty
--CARD
put "line" && tFoundLine && "of" && "CARD:" && pCard && "STACK:" && pStack & lf & " " & xTerm & lf \
after fld "clean put" of this stack
set the textColor of the last line of fld "clean put" to 140,140,140
exit switch
break
default
put "line" && tFoundLine && "of" && "STACK:" && pStack & lf & " " & xTerm & lf after fld "clean put" of this stack
set the textColor of the last line of fld "clean put" to 140,140,140
break
end switch
put tFoundLine into tSkipLines
end repeat
end repeat
end cleanScript