Snippets
  • Uploaded By: maroon
  • Added: 2 years ago
  • Updated: 4 months ago
  • mIRC Version: used 6.35 & 7.51+
  • Hits: 984
  • Size: 13.31KB
  • Downloads: 27
  • Review By: entropy



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$

    
  2    0  Login to Vote.


Source Code:
  1. ;----------
  2. /* Srch & Pairs v1.4 by maroon
  3. Srch: Hunts for strings quickly, instead of manually searching each script 1-by-1 with Ctrl+F
  4. Pairs: finds most mis-matched parenthesis and square-brackets
  5. Both scripts search: all REMOTE-tab scripts + all ALIASES-tab files + all alt+P popups.
  6. "pairs" searches for lines with unmatched counts of (parenthesis) and [braces]
  7. "srch" searches your scripts for the string. Can be regex or wildcard
  8.  
  9. /pairs [-spa] 1stChar 2ndChar [WildcardFilename]
  10. /pairs ( ) filename
  11.  
  12. If /pairs 3rd parameter is missing, uses * as filespec
  13. /pairs [ ] is the same as /pairs [ ] *
  14.  
  15. /srch [-spar] WildcardFilename more than 1 text words that can have wildcards
  16. /srch [-spar] 1_word_searchtext
  17.  
  18. -a overrides default -s output to status window * -as outputs to both (Default is -sg)
  19. -p overrides default to NOT change some of the consecutive spaces into $chr(160)'s
  20. -r assumes the searchtext is a regex pattern. It defaults to case-sensitive unless pattern enables the 'i' flag.
  21.  
  22. If only searching for 1 'word', then filename is optional, and assumed to be *
  23.  
  24. search all files for SOCK* :label or :eventname: /srch :sock
  25. search script1.mrc for word1 word2: /srch script1.mrc word1 word2
  26. case-insensitive search all files for 'srch': /srch -r * /srch/i
  27. find 'alias' keyword at beginning of line without indent: /srch -r * ^alias
  28. to ignore color codes in script lines, use regex /S flag similar to /srch -sapr * /string/S
  29. ('sa' combo outputs to active+status windows. 'p' preserves appearance of consecutive spaces using chr(160)'s)
  30.  
  31. v1.1=-j99999 to override @window size limit. notice about .ini (largely irrelevant with 1.3+ using /filter)
  32. 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.
  33. v1.3= fixed .ini handling. Added -spa switches. Faster search finding matches using /filter not $fline (enables searches including color codes)
  34. -s= (default) status window
  35. -a= is active win -sa=both
  36. -p= display imitates consecutive spaces using chr(160)'s.
  37. v1.4= added search of popups.ini (reports line# of popups.ini, not the line showin in alt+P)
  38. */
  39.  
  40. ; made this a subroutine so both srch and pairs could use it
  41. alias -l srch_headers {
  42. if ($2 == n) { if ($1 == $null) return
  43. return %a $replace($1,bpopup,StatusPop,cpopup,ChannelPop,lpopup,NickListPop,mpopup,MenuBarPop,qpopup,QueryPop)
  44. }
  45. var %a , %i 1 | while ($ini($1,%i)) { noop $read($1,ntw,$+([,$v1,])) | if ($readn) var %a %a $v1 | inc %i }
  46. return %a
  47. }
  48.  
  49. ; %echotarget -sg sends to status window. Remove the 'g' to enable logging, or change to -ag to default to active window
  50. alias srch {
  51. var %echotarget -sg , %spaces , %regex 0 , %switches | if ($regex($1,/^-[sparg]+$/)) { var %switches $1 | tokenize 32 $2- }
  52. if ($remove(%switches,r,p) != -) var %echotarget $v1
  53. ; if wanting to avoid echo -g switch, must comment-out next line too
  54. if (g !isincs %echotarget) var %echotarget $replace(%echotarget,-,-g)
  55. if (r isin %switches) var %regex 2
  56. ; change %switches in next line to "p" to make the default be preserving appearance of consecutive spaces, affecting clipboard
  57. if (p isin %switches) var %spaces [160's]
  58. if ($0 == 1) tokenize 32 * $1 | var %sc $color(notice) , %lum $lum(%sc) , %fg $contrast(%sc) , %screv $+($chr(3),%fg,$chr(44),%sc)
  59. echo %sc %echotarget =/=/=/=/=/=/=
  60. 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"
  61. echo %echotarget -a -> active, -s -> status, -as -> both. -p = preserve appearance of consecutive spaces with $ $+ chr(160)'s
  62. echo %echotarget Display: $+(#Match:,$chr(22),ScriptLine#,$chr(22) script line)
  63. echo %sc %echotarget Example: /srch * :sock (find eventname or label begins with 'sock')
  64. echo %sc %echotarget Example: /srch alias*srch (assumes 1 word is search term in all files)
  65. echo %sc %echotarget Example: /srch -r * \s$ (find script lines with trailing space)
  66. echo %sc %echotarget Example: /srch -rp * \S\s\s$ (consecutive spaces not at beginning of line)
  67. if (!$0) return | var %pattern $2- | if (!%regex) var %pattern $+(*,$2-,*)
  68. echo %sc %echotarget =/=/=/=/=/=/=
  69. var %totalscripts $script(0) , %s -1 , %type script , %ticks $ticks , %win @maroonSrch , %MatchCount 0 , %ScriptsWithMatch 0 , %searchedcount 0 , %done , %pfiles , %poplabel
  70. window -c %win | window -hj99999 %win
  71. while (%s < %totalscripts) {
  72. inc %s | if (%s == 0) goto top | var %f $iif(%type == script,$script(%s),$alias(%s))
  73. if (%type == popups) {
  74. var %f $readini($mircini,n,pfiles,n $+ $calc(%s -1)) | if ($istok(%pfiles,%f,1)) goto top | var %pfiles $addtok(%pfiles,%f,1)
  75. if ((%type == popups) && (*.ini iswm %f)) {
  76. var %headers $srch_headers(%f) 999999999
  77. 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)
  78. }
  79. }
  80. if (!$file(%f).size) echo %echotarget %screv Warning: loaded %type does not exist or is zero size: %f $chr(3)
  81. elseif ($+(*,$1,*) iswm $remove(%f,$mircdir)) {
  82. filter -fwcn $+ $iif(%regex,g) $qt(%f) %win %pattern | var %line 0 , %tl $filtered | inc %searchedcount
  83. if (%tl) {
  84. 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)
  85. inc %ScriptsWithMatch
  86. }
  87. while (%line < %tl) {
  88. inc %line | var %linetext $line(%win,%line) , %linenum $gettok(%linetext,1,32) , %pos 1 + $pos(%linetext,$chr(32),1) , %linetext $mid(%linetext,%pos)
  89. if ((*.ini iswm %f) && (n*=* iswm %linetext)) { var %pos 1 + $pos(%linetext,=,1) | var %linetext $mid(%linetext,%pos)
  90. if (%type == popups) {
  91. while ((%headers) && (%header_n+1 <= %linenum)) {
  92. 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)
  93. }
  94. if (%headers) var %linenum %linenum - %header_n | else dec %linenum
  95. }
  96. else dec %linenum
  97. }
  98. if (!%regex) var %linetext $replace(%linetext,$2-,$+($chr(22),$2-,$chr(22)))
  99. if (%spaces) var %linetext $replace(%linetext,$chr(32) $+ $chr(32),$chr(32) $+ $chr(160))
  100. inc %matchcount | echo %echotarget $+($chr(35),%matchcount,:,$chr(22),%poplabel,%linenum,$chr(22)) %linetext
  101. }
  102. if (%tl) var %done $chr(3) done searching $remove(%f,$mircdir) *
  103. }
  104. :top
  105. if (%s == %totalscripts) {
  106. if (%type == script) var %s 0 , %totalscripts $alias(0) , %type alias
  107. elseif (%type == alias) var %s 0 , %totalscripts 5 , %type popups
  108. }
  109. }
  110. 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
  111. }
  112.  
  113. ; %echotarget -sg sends to status window. Remove the 'g' to enable logging, or change to -ag to default to active window
  114. alias pairs {
  115. var %echotarget -sg , %spaces , %regex 0 , %switches | if ($regex($1,/^-[spag]+$/)) { var %switches $1 | tokenize 32 $2- }
  116. if ($remove(%switches,p) != -) var %echotarget $v1
  117. ; if wanting to avoid echo -g switch, must comment-out next line too
  118. if (g !isincs %echotarget) var %echotarget $replace(%echotarget,-,-g)
  119. if (r isin %switches) var %regex 2
  120. ; change %switches in next line to "p" to make the default be preserving appearance of consecutive spaces, affecting clipboard
  121. if (p isin %switches) var %spaces [160's]
  122. if ($0 == 1) tokenize 32 * $1 | var %sc $color(notice) , %lum $lum(%sc) , %fg $contrast(%sc) , %screv $+($chr(3),%fg,$chr(44),%sc)
  123. if (($len($1) $len($2) == 1 1) && ($1 !isnum) && ($2 !isnum)) tokenize 32 $asc($1) $asc($2) $iif($3-,$3-,*)
  124. 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)
  125. echo %sc %echotarget =/=/=/=/=/=/=
  126. 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 [ ]"
  127. echo %echotarget -a -> active, -s -> status, -as -> both. -p = preserve appearance of consecutive spaces with $ $+ chr(160)'s
  128. 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
  129. echo %echotarget Suggest fixing from the bottom upwards if add/removing lines
  130. echo %echotarget Displays: Count1-vs-Count2 $+(Line:,$chr(22),N,$chr(22)) script-line
  131. echo %sc %echotarget =/=/=/=/=/=/= Example: /pairs -a ( ) aliases.ini
  132. var %totalscripts $script(0) , %s -1 , %type script , %ticks $ticks , %win @maroon_pairs , %MatchCount 0 , %ScriptsWithMatch 0 , %searchedcount 0 , %pfiles , %poplabel
  133. 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
  134. var %pattern ^.*(\ $+ $chr($1) $+ |\ $+ $chr($2) $+ )
  135. while (%s < %totalscripts) {
  136. inc %s | if (%s == 0) goto top | var %f $iif(%type == script,$script(%s),$alias(%s)) , %flag 1
  137. if (%type == popups) {
  138. var %f $readini($mircini,n,pfiles,n $+ $calc(%s -1)) | if ($istok(%pfiles,%f,1)) goto top | var %pfiles $addtok(%pfiles,%f,1)
  139. if ((%type == popups) && (*.ini iswm %f)) {
  140. var %headers $srch_headers(%f) 999999999999
  141. 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)
  142. }
  143. }
  144. if (!$file(%f).size) echo %echotarget %screv Warning: loaded %type does not exist or is zero size: %f $chr(3)
  145. elseif ($+(*,$3-,*) iswm $remove(%f,$mircdir)) {
  146. filter -fwcgn $qt(%f) %win %pattern | var %line 0 , %tl $filtered , %matchflag 1 | inc %searchedcount
  147. if (%tl) {
  148. 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)
  149. }
  150. while (%line < %tl) {
  151. inc %line | var %linetext $line(%win,%line) , %linenum $gettok(%linetext,1,32) , %pos 1 + $pos(%linetext,$chr(32),1) , %linetext $mid(%linetext,%pos)
  152. if ((*.ini iswm %f) && (n*=* iswm %linetext)) { var %pos 1 + $pos(%linetext,=,1) | var %linetext $mid(%linetext,%pos)
  153. if (%type == popups) {
  154. while ((%headers) && (%header_n+1 <= %linenum)) {
  155. 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)
  156. }
  157. if (%headers) var %linenum %linenum - %header_n | else dec %linenum
  158. }
  159. else dec %linenum
  160. }
  161. if ($count(%linetext,$chr($1)) != $count(%linetext,$chr($2))) { var %v1 $v1 , %v2 $v2
  162. inc %ScriptsWithMatch %matchflag | var %matchflag 0
  163. if (%spaces) var %linetext $replace(%linetext,$chr(32) $+ $chr(32),$chr(32) $+ $chr(160))
  164. inc %matchcount | echo %echotarget $+(%screv %v1,-vs-,%v2) $+($chr(3) Line:,$chr(22),%poplabel,%linenum,$chr(22)) %linetext }
  165. }
  166. ;if (%tl) var %done $chr(3) done searching $remove(%f,$mircdir) *
  167. }
  168. :top
  169. if (%s == %totalscripts) {
  170. if (%type == script) var %s 0 , %totalscripts $alias(0) , %type alias
  171. elseif (%type == alias) var %s 0 , %totalscripts 5 , %type popups
  172. }
  173. }
  174. 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
  175. }
  176.  
  177. alias -l lum { tokenize 44 $rgb($color($1)) | return $calc(0.2126 * $brightness($1) + 0.7152 * $brightness($2) + 0.0722 * $brightness($3)) }
  178. alias -l brightness { var %res $1 / 255 | return $iif(%res <= 0.03928, $calc(%res / 12.92), $calc((( %res + 0.055) / 1.055) ^ 2.4)) }
  179. ; borrowed lum/brightness from xpallette, user can change .179 to .3 to have more colors use white text
  180. alias -l contrast { var %a $lum($1) | return $iif(0.179 < $lum($1), 1, 0) }
  181. ;---------------
  182.  


Comments
No Comments.

Login to Comment.