Snippets Project Page
Author: maroon
Added: 6y
Updated: 4y
mIRC: used 6.35 & 7.51+
Hits: 2,395
Downloads: 33
Review: entropy
Size: 13.72KB
3 0
Login to vote.
Search scripts for matchtext or mismatched Pairs
v1.4
A quick tool to help find script errors due to mismatched (mis-matched parenthesis) or [square quotes]
Also Search remote-scripts, aliases-files, and popups for matching text
If only searching for 1 'word', assumes all-files: /srch :TEXT
otherwise if 2+ parameters, assumes 1st is filespec: /srch foo*.mrc :sock
Regex search script for trailing spaces: /srch -r * \s$
Download
JSON
▲ Review
▲ Log
▼ Source
;---------- /* Srch & Pairs v1.4 by maroon Srch: Hunts for strings quickly, instead of manually searching each script 1-by-1 with Ctrl+F Pairs: finds most mis-matched parenthesis and square-brackets Both scripts search: all REMOTE-tab scripts + all ALIASES-tab files + all alt+P popups. "pairs" searches for lines with unmatched counts of (parenthesis) and [braces] "srch" searches your scripts for the string. Can be regex or wildcard /pairs [-spa] 1stChar 2ndChar [WildcardFilename] /pairs ( ) filename If /pairs 3rd parameter is missing, uses * as filespec /pairs [ ] is the same as /pairs [ ] * /srch [-spar] WildcardFilename more than 1 text words that can have wildcards /srch [-spar] 1_word_searchtext -a overrides default -s output to status window * -as outputs to both (Default is -sg) -p overrides default to NOT change some of the consecutive spaces into $chr(160)'s -r assumes the searchtext is a regex pattern. It defaults to case-sensitive unless pattern enables the 'i' flag. If only searching for 1 'word', then filename is optional, and assumed to be * search all files for SOCK* :label or :eventname: /srch :sock search script1.mrc for word1 word2: /srch script1.mrc word1 word2 case-insensitive search all files for 'srch': /srch -r * /srch/i find 'alias' keyword at beginning of line without indent: /srch -r * ^alias to ignore color codes in script lines, use regex /S flag similar to /srch -sapr * /string/S ('sa' combo outputs to active+status windows. 'p' preserves appearance of consecutive spaces using chr(160)'s) v1.1=-j99999 to override @window size limit. notice about .ini (largely irrelevant with 1.3+ using /filter) v1.2= Hid n123= from .ini display. Added -r switch=regex. Don't force text color in case of blackground. Srch shows filenames only if has matches. v1.3= fixed .ini handling. Added -spa switches. Faster search finding matches using /filter not $fline (enables searches including color codes) -s= (default) status window -a= is active win -sa=both -p= display imitates consecutive spaces using chr(160)'s. v1.4= added search of popups.ini (reports line# of popups.ini, not the line showin in alt+P) */ ; made this a subroutine so both srch and pairs could use it alias -l srch_headers { if ($2 == n) { if ($1 == $null) return return %a $replace($1,bpopup,StatusPop,cpopup,ChannelPop,lpopup,NickListPop,mpopup,MenuBarPop,qpopup,QueryPop) } var %a , %i 1 | while ($ini($1,%i)) { noop $read($1,ntw,$+([,$v1,])) | if ($readn) var %a %a $v1 | inc %i } return %a } ; %echotarget -sg sends to status window. Remove the 'g' to enable logging, or change to -ag to default to active window alias srch { var %echotarget -sg , %spaces , %regex 0 , %switches | if ($regex($1,/^-[sparg]+$/)) { var %switches $1 | tokenize 32 $2- } if ($remove(%switches,r,p) != -) var %echotarget $v1 ; if wanting to avoid echo -g switch, must comment-out next line too if (g !isincs %echotarget) var %echotarget $replace(%echotarget,-,-g) if (r isin %switches) var %regex 2 ; change %switches in next line to "p" to make the default be preserving appearance of consecutive spaces, affecting clipboard if (p isin %switches) var %spaces [160's] if ($0 == 1) tokenize 32 * $1 | var %sc $color(notice) , %lum $lum(%sc) , %fg $contrast(%sc) , %screv $+($chr(3),%fg,$chr(44),%sc) echo %sc %echotarget =/=/=/=/=/=/= echo %sc %echotarget /srch v1.4 by maroon $+ $chr(169) searches scripts/aliases.ini for text. Syntax: "/srch [-spa] ScriptName/wildcard one-or-more-searchwords" or "/srch -[spa] OneWordSearchText" or "/srch -r[spa] ScriptName RegexPattern" echo %echotarget -a -> active, -s -> status, -as -> both. -p = preserve appearance of consecutive spaces with $ $+ chr(160)'s echo %echotarget Display: $+(#Match:,$chr(22),ScriptLine#,$chr(22) script line) echo %sc %echotarget Example: /srch * :sock (find eventname or label begins with 'sock') echo %sc %echotarget Example: /srch alias*srch (assumes 1 word is search term in all files) echo %sc %echotarget Example: /srch -r * \s$ (find script lines with trailing space) echo %sc %echotarget Example: /srch -rp * \S\s\s$ (consecutive spaces not at beginning of line) if (!$0) return | var %pattern $2- | if (!%regex) var %pattern $+(*,$2-,*) echo %sc %echotarget =/=/=/=/=/=/= var %totalscripts $script(0) , %s -1 , %type script , %ticks $ticks , %win @maroonSrch , %MatchCount 0 , %ScriptsWithMatch 0 , %searchedcount 0 , %done , %pfiles , %poplabel window -c %win | window -hj99999 %win while (%s < %totalscripts) { inc %s | if (%s == 0) goto top | var %f $iif(%type == script,$script(%s),$alias(%s)) if (%type == popups) { var %f $readini($mircini,n,pfiles,n $+ $calc(%s -1)) | if ($istok(%pfiles,%f,1)) goto top | var %pfiles $addtok(%pfiles,%f,1) if ((%type == popups) && (*.ini iswm %f)) { var %headers $srch_headers(%f) 999999999 if (%headers) var %header_n $gettok(%headers,1,32) , %header_n+1 $gettok(%headers,2,32) , %headers $gettok(%headers,2-,32) , %poplabel $srch_headers($read(%f,nt,%header_n),n) } } if (!$file(%f).size) echo %echotarget %screv Warning: loaded %type does not exist or is zero size: %f $chr(3) elseif ($+(*,$1,*) iswm $remove(%f,$mircdir)) { filter -fwcn $+ $iif(%regex,g) $qt(%f) %win %pattern | var %line 0 , %tl $filtered | inc %searchedcount if (%tl) { echo %sc %echotarget $+(ticks:,$calc($ticks -%ticks)) %done %screv searching $ord(%s) %type -> $remove(%f,$mircdir) $chr(3) $iif(*.ini iswm %f,You can remove 'n1234=' from scripts/aliases by renaming to another filetype besides .ini) inc %ScriptsWithMatch } while (%line < %tl) { inc %line | var %linetext $line(%win,%line) , %linenum $gettok(%linetext,1,32) , %pos 1 + $pos(%linetext,$chr(32),1) , %linetext $mid(%linetext,%pos) if ((*.ini iswm %f) && (n*=* iswm %linetext)) { var %pos 1 + $pos(%linetext,=,1) | var %linetext $mid(%linetext,%pos) if (%type == popups) { while ((%headers) && (%header_n+1 <= %linenum)) { var %header_n $gettok(%headers,1,32) , %header_n+1 $gettok(%headers,2,32) , %headers $gettok(%headers,2-,32) , %poplabel $srch_headers($read(%f,nt,%header_n),n) } if (%headers) var %linenum %linenum - %header_n | else dec %linenum } else dec %linenum } if (!%regex) var %linetext $replace(%linetext,$2-,$+($chr(22),$2-,$chr(22))) if (%spaces) var %linetext $replace(%linetext,$chr(32) $+ $chr(32),$chr(32) $+ $chr(160)) inc %matchcount | echo %echotarget $+($chr(35),%matchcount,:,$chr(22),%poplabel,%linenum,$chr(22)) %linetext } if (%tl) var %done $chr(3) done searching $remove(%f,$mircdir) * } :top if (%s == %totalscripts) { if (%type == script) var %s 0 , %totalscripts $alias(0) , %type alias elseif (%type == alias) var %s 0 , %totalscripts 5 , %type popups } } echo %sc %echotarget $+(ticks:,$calc($ticks -%ticks)) %done %screv Finished! $calc($ticks - %ticks) $+ ms $chr(9) %matchcount Matches in %ScriptsWithMatch files out of %searchedcount searched files. Total Scripts: $script(0) Aliases: $alias(0) $chr(3) $+ $contrast(8) $+ ,8 This search: %spaces $iif(%regex,[Regex]) echo %echotarget /srch $replace(%echotarget,-,$iif(%regex,-r,-),-,$iif(%spaces,-p,-)) $1- $chr(9) | :exit | window -c %win } ; %echotarget -sg sends to status window. Remove the 'g' to enable logging, or change to -ag to default to active window alias pairs { var %echotarget -sg , %spaces , %regex 0 , %switches | if ($regex($1,/^-[spag]+$/)) { var %switches $1 | tokenize 32 $2- } if ($remove(%switches,p) != -) var %echotarget $v1 ; if wanting to avoid echo -g switch, must comment-out next line too if (g !isincs %echotarget) var %echotarget $replace(%echotarget,-,-g) if (r isin %switches) var %regex 2 ; change %switches in next line to "p" to make the default be preserving appearance of consecutive spaces, affecting clipboard if (p isin %switches) var %spaces [160's] if ($0 == 1) tokenize 32 * $1 | var %sc $color(notice) , %lum $lum(%sc) , %fg $contrast(%sc) , %screv $+($chr(3),%fg,$chr(44),%sc) if (($len($1) $len($2) == 1 1) && ($1 !isnum) && ($2 !isnum)) tokenize 32 $asc($1) $asc($2) $iif($3-,$3-,*) if ($0 isnum 0-1) tokenize 32 40 41 $iif($1,$1,*) | var %sc $color(notice) , %lum $lum(%sc) , %fg $contrast(%sc) , %screv $+($chr(3),%fg,$chr(44),%sc) echo %sc %echotarget =/=/=/=/=/=/= echo %sc %echotarget Pairs v1.4 by maroon $+ $chr(169) warns of lines having different counts of a pair of ASCII numbers. Syntax: "/pairs ASCIInumber ASCIInumber scriptname/wildcard" or "/pairs [-spa] Char1 Char2 *" or "/pairs ( )" or "/pairs [ ]" echo %echotarget -a -> active, -s -> status, -as -> both. -p = preserve appearance of consecutive spaces with $ $+ chr(160)'s echo %echotarget False alarms include $chr(22) emoticons like :) $chr(22) or $chr(22) lines divided across $ $+ & $chr(22) or $chr(22) 1 side of pair using $ $+ chr(N) i.e. $ $+ chr(40) with ) $chr(22) <- these mis-matches causes this line to be reported by this script as 8-vs-10 echo %echotarget Suggest fixing from the bottom upwards if add/removing lines echo %echotarget Displays: Count1-vs-Count2 $+(Line:,$chr(22),N,$chr(22)) script-line echo %sc %echotarget =/=/=/=/=/=/= Example: /pairs -a ( ) aliases.ini var %totalscripts $script(0) , %s -1 , %type script , %ticks $ticks , %win @maroon_pairs , %MatchCount 0 , %ScriptsWithMatch 0 , %searchedcount 0 , %pfiles , %poplabel window -c %win | window -hj99999 %win | if (!$2) tokenize 32 40 41 $iif($1,$1,*) | if (($1 !isnum 1-65535) || ($2 !isnum 1-65535)) goto exit var %pattern ^.*(\ $+ $chr($1) $+ |\ $+ $chr($2) $+ ) while (%s < %totalscripts) { inc %s | if (%s == 0) goto top | var %f $iif(%type == script,$script(%s),$alias(%s)) , %flag 1 if (%type == popups) { var %f $readini($mircini,n,pfiles,n $+ $calc(%s -1)) | if ($istok(%pfiles,%f,1)) goto top | var %pfiles $addtok(%pfiles,%f,1) if ((%type == popups) && (*.ini iswm %f)) { var %headers $srch_headers(%f) 999999999999 if (%headers) var %header_n $gettok(%headers,1,32) , %header_n+1 $gettok(%headers,2,32) , %headers $gettok(%headers,2-,32) , %poplabel $srch_headers($read(%f,nt,%header_n),n) } } if (!$file(%f).size) echo %echotarget %screv Warning: loaded %type does not exist or is zero size: %f $chr(3) elseif ($+(*,$3-,*) iswm $remove(%f,$mircdir)) { filter -fwcgn $qt(%f) %win %pattern | var %line 0 , %tl $filtered , %matchflag 1 | inc %searchedcount if (%tl) { echo %sc %echotarget $+(ticks:,$calc($ticks -%ticks)) %done %screv searching $ord(%s) %type -> $remove(%f,$mircdir) $chr(3) $iif(*.ini iswm %f,You can remove 'n1234=' from scripts/aliases by renaming to another filetype besides .ini) } while (%line < %tl) { inc %line | var %linetext $line(%win,%line) , %linenum $gettok(%linetext,1,32) , %pos 1 + $pos(%linetext,$chr(32),1) , %linetext $mid(%linetext,%pos) if ((*.ini iswm %f) && (n*=* iswm %linetext)) { var %pos 1 + $pos(%linetext,=,1) | var %linetext $mid(%linetext,%pos) if (%type == popups) { while ((%headers) && (%header_n+1 <= %linenum)) { var %header_n $gettok(%headers,1,32) , %header_n+1 $gettok(%headers,2,32) , %headers $gettok(%headers,2-,32) , %poplabel $srch_headers($read(%f,nt,%header_n),n) } if (%headers) var %linenum %linenum - %header_n | else dec %linenum } else dec %linenum } if ($count(%linetext,$chr($1)) != $count(%linetext,$chr($2))) { var %v1 $v1 , %v2 $v2 inc %ScriptsWithMatch %matchflag | var %matchflag 0 if (%spaces) var %linetext $replace(%linetext,$chr(32) $+ $chr(32),$chr(32) $+ $chr(160)) inc %matchcount | echo %echotarget $+(%screv %v1,-vs-,%v2) $+($chr(3) Line:,$chr(22),%poplabel,%linenum,$chr(22)) %linetext } } ;if (%tl) var %done $chr(3) done searching $remove(%f,$mircdir) * } :top if (%s == %totalscripts) { if (%type == script) var %s 0 , %totalscripts $alias(0) , %type alias elseif (%type == alias) var %s 0 , %totalscripts 5 , %type popups } } echo %sc %echotarget %screv Finished! $calc($ticks - %ticks) $+ ms $chr(9) %matchcount mismatched lines in %ScriptsWithMatch files out of %searchedcount searched files. Total Scripts: $script(0) Aliases: $alias(0) $chr(3) $+ $contrast(8) $+ ,8 This search: %spaces echo %echotarget /pairs $chr($1) $chr($2) $iif($3- == *,*, $+(*,$3-,*) ) $chr(9) | :exit | window -c %win } alias -l lum { tokenize 44 $rgb($color($1)) | return $calc(0.2126 * $brightness($1) + 0.7152 * $brightness($2) + 0.0722 * $brightness($3)) } alias -l brightness { var %res $1 / 255 | return $iif(%res <= 0.03928, $calc(%res / 12.92), $calc((( %res + 0.055) / 1.055) ^ 2.4)) } ; borrowed lum/brightness from xpallette, user can change .179 to .3 to have more colors use white text alias -l contrast { var %a $lum($1) | return $iif(0.179 < $lum($1), 1, 0) } ;---------------
Changelog:
v1.4= Added handling of Alt+P popups
v1.3= fixed .ini handling.
Added -spa switches.
Faster search finding matches using /filter not $fline (enables searches including color codes)
-p display imitates consecutive spaces using chr(160)'s.
v1.2= Hide n123= from .ini display.
Added -r switch=regex.
Doesn't force text color in case of black background. Srch shows filenames only if has matches.
v1.4= Added handling of Alt+P popups
v1.3= fixed .ini handling.
Added -spa switches.
Faster search finding matches using /filter not $fline (enables searches including color codes)
-p display imitates consecutive spaces using chr(160)'s.
v1.2= Hide n123= from .ini display.
Added -r switch=regex.
Doesn't force text color in case of black background. Srch shows filenames only if has matches.
Review: entropy
This is truly neat! A simple "srch" through $script(N) and highlights the results (if matching). Also included, is a "pairs" alias to check for mis-matching () and [].
Well done maroon!
This is truly neat! A simple "srch" through $script(N) and highlights the results (if matching). Also included, is a "pairs" alias to check for mis-matching () and [].
Well done maroon!