Snippets
  • Uploaded By: maroon
  • Author: maroon
  • Added: 8 months ago
  • Last Updated: 1 month ago
  • mIRC Version: used 6.35 & 7.51+
  • Hits: 365
  • Size: 10.1KB
  • Downloads: 19
  • Review By: entropy



Search scripts for matchtext or mismatched Pairs v1.3

A quick tool to help find script errors due to mismatched braces/symbols!
Search *.remote-scripts and *.aliases-files for matching text
or
Find lines with (mis-matched parenthesis) or [square quotes]

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. /* Srch & Pairs v1.3 by maroon
  2. Srch: hunts for strings quickly, instead of manually searching each script 1-by-1 with Ctrl+F
  3. Pairs: finds most mis-matched parenthesis and square-brackets
  4. Both scripts search all REMOTE-tab scripts - then search all ALIASES-tab files.
  5. "pairs" searches for lines with unmatched counts of (parenthesis) and [braces]
  6. "srch" searches your scripts for the string. Can be regex or wildcard
  7.  
  8. /pairs [-spa] 1stChar 2ndChar [WildcardFilename]
  9. /pairs ( ) filename
  10.  
  11. If /pairs 3rd parameter is missing, uses * as filespec
  12. /pairs [ ] is the same as /pairs [ ] *
  13.  
  14. /srch [-spar] WildcardFilename more than 1 text words that can have wildcards
  15. /srch [-spar] 1_word_searchtext
  16.  
  17. If only searching for 1 'word', then filename is optional, and assumed to be *
  18. -a overrides default -s output to status window. -as outputs to both
  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. search script1.mrc for word1 word2: /srch script1.mrc word1 word2
  23. search all files for SOCK* :label or :eventname: /srch :sock
  24. case-insensitive search all files: /srch -r * /srch/i
  25. to ignore color codes in script lines, use regex /S flag similar to /srch -r * /string/S
  26.  
  27. v1.1=-j99999 to override @window size limit. notice about .ini
  28. v1.2= Hid n123= from .ini display. Added -r switch=regex. Don't force text color in case of black background. Srch shows filenames only if has matches.
  29. v1.3= fixed .ini handling. Added -spa switches. Faster search finding matches using /filter not $fline (enables searches including color codes)
  30. -p display imitates consecutive spaces using chr(160)'s.
  31. */
  32.  
  33. alias srch {
  34. ; %echotarget -sg sends to status window. Remove the 'g' to enable logging, or change to -ag to default to active window
  35. var %echotarget -sg , %spaces , %regex 0 , %switches | if ($regex($1,/^-[spar]+$/)) { var %switches $1 | tokenize 32 $2- }
  36. if ($remove(%switches,r,p) != -) var %echotarget $v1
  37. if (r isin %switches) var %regex 2
  38. ; change %switches in next line to "p" to make the default be preserving appearance of consecutive spaces, affecting clipboard
  39. if (p isin %switches) var %spaces [160's]
  40. if ($0 == 1) tokenize 32 * $1 | var %sc $color(notice) , %lum $lum(%sc) , %fg $contrast(%sc) , %screv $+($chr(3),%fg,$chr(44),%sc)
  41. echo %sc %echotarget =/=/=/=/=/=/=
  42. echo %sc %echotarget /srch v1.3 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"
  43. echo %echotarget -a -> active, -s -> status, -as -> both. -p = preserve appearance of consecutive spaces with $ $+ chr(160)'s
  44. echo %echotarget Display: $+(#Match:,$chr(22),ScriptLine#,$chr(22) script line)
  45. echo %sc %echotarget Example: /srch * :sock (find eventname or label begins with 'sock')
  46. echo %sc %echotarget Example: /srch alias*srch (assumes 1 word is search term in all files)
  47. echo %sc %echotarget Example: /srch -r * \s$ (find script lines with trailing space)
  48. echo %sc %echotarget Example: /srch -rp * \S\s\s$ (consecutive spaces not at beginning of line)
  49.  
  50. if (!$0) return | var %pattern $2- | if (!%regex) var %pattern $+(*,$2-,*)
  51. echo %sc %echotarget =/=/=/=/=/=/=
  52. var %totalscripts $script(0) , %s -1 , %s_or_a 1 , %ticks $ticks , %win @maroonSrch , %MatchCount 0 , %ScriptsWithMatch 0 , %searchedcount 0 , %done
  53. window -c %win | window -hj99999 %win
  54. while (%s < %totalscripts) {
  55. inc %s | if (%s == 0) goto top | var %f $iif(%s_or_a,$script(%s),$alias(%s))
  56. if (!$file(%f).size) echo %echotarget %screv Warning: loaded scriptfile does not exist or is zero size: %f $chr(3)
  57. elseif ($+(*,$1,*) iswm $remove(%f,$mircdir)) {
  58. filter -fwcn $+ $iif(%regex,g) $qt(%f) %win %pattern | var %line 0 , %tl $filtered | inc %searchedcount
  59. if (%tl) {
  60. echo %sc %echotarget %done %screv searching $ord(%s) $iif(%s_or_a,script,alias) file -> $remove(%f,$mircdir) $chr(3) $iif(*.ini iswm %f,You can remove 'n1234=' from scripts/aliases by renaming to another filetype besides .ini)
  61. inc %ScriptsWithMatch
  62. }
  63. while (%line < %tl) {
  64. inc %line | var %linetext $line(%win,%line) , %linenum $gettok(%linetext,1,32) , %pos 1 + $pos(%linetext,$chr(32),1) , %linetext $mid(%linetext,%pos)
  65. if ((*.ini iswm %f) && (n*=* iswm %linetext)) { var %pos 1 + $pos(%linetext,=,1) | var %linetext $mid(%linetext,%pos) | dec %linenum }
  66. if (!%regex) var %linetext $replace(%linetext,$2-,$+($chr(22),$2-,$chr(22)))
  67. if (%spaces) var %linetext $replace(%linetext,$chr(32) $+ $chr(32),$chr(32) $+ $chr(160))
  68. inc %matchcount | echo %echotarget $+($chr(35),%matchcount,:,$chr(22),%linenum,$chr(22)) %linetext
  69. }
  70. if (%tl) var %done $chr(3) done searching $remove(%f,$mircdir) *
  71. }
  72. :top
  73. if ((%s == %totalscripts) && (%s_or_a)) { var %s 0, %totalscripts $alias(0) , %s_or_a 0 }
  74. }
  75. echo %echotarget %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 $1- $chr(9) | :exit | window -c %win
  76. }
  77.  
  78. alias pairs {
  79. ; %echotarget -sg sends to status window. Remove the 'g' to enable logging, or change to -ag to default to active window
  80. var %echotarget -sg , %spaces , %regex 0 , %switches | if ($regex($1,/^-[spa]+$/)) { var %switches $1 | tokenize 32 $2- }
  81. if ($remove(%switches,p) != -) var %echotarget $v1
  82. if (r isin %switches) var %regex 2
  83. ; change %switches in next line to "p" to make the default be preserving appearance of consecutive spaces, affecting clipboard
  84. if (p isin %switches) var %spaces [160's]
  85. if ($0 == 1) tokenize 32 * $1 | var %sc $color(notice) , %lum $lum(%sc) , %fg $contrast(%sc) , %screv $+($chr(3),%fg,$chr(44),%sc)
  86.  
  87. if (($len($1) $len($2) == 1 1) && ($1 !isnum) && ($2 !isnum)) tokenize 32 $asc($1) $asc($2) $iif($3-,$3-,*)
  88. 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)
  89. echo %sc %echotarget =/=/=/=/=/=/=
  90. echo %sc %echotarget Pairs v1.3 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 [ ]"
  91. echo %echotarget -a -> active, -s -> status, -as -> both. -p = preserve appearance of consecutive spaces with $ $+ chr(160)'s
  92. 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
  93. echo %echotarget Suggest fixing from the bottom upwards if add/removing lines
  94. echo %echotarget Displays: Count1-vs-Count2 $+(Line:,$chr(22),N,$chr(22)) script-line
  95. echo %sc %echotarget =/=/=/=/=/=/= Example: /pairs -a ( ) aliases.ini
  96. var %totalscripts $script(0) , %s -1 , %s_or_a 1 , %ticks $ticks , %win @maroon_pairs , %MatchCount 0 , %ScriptsWithMatch 0 , %searchedcount 0
  97. 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
  98. var %pattern ^.*(\ $+ $chr($1) $+ |\ $+ $chr($2) $+ )
  99. while (%s < %totalscripts) {
  100. inc %s | if (%s == 0) goto top | var %f $iif(%s_or_a,$script(%s),$alias(%s)) , %flag 1
  101. if (!$file(%f).size) echo %echotarget %screv Warning: loaded file does not exist or is zero size: %f $chr(3)
  102. elseif ($+(*,$3-,*) iswm $remove(%f,$mircdir)) {
  103. filter -fwcgn $qt(%f) %win %pattern | var %line 0 , %tl $filtered , %matchflag 1 | inc %searchedcount
  104. if (%tl) {
  105. echo %echotarget %done %screv searching $ord(%s) $iif(%s_or_a,script,alias) file -> $remove(%f,$mircdir) $chr(3) $iif(*.ini iswm %f,You can remove 'n1234=' from scripts/aliases by renaming to another filetype besides .ini)
  106. }
  107. while (%line < %tl) {
  108. inc %line | var %linetext $line(%win,%line) , %linenum $gettok(%linetext,1,32) , %pos 1 + $pos(%linetext,$chr(32),1) , %linetext $mid(%linetext,%pos)
  109. if ((*.ini iswm %f) && (n*=* iswm %linetext)) { var %pos 1 + $pos(%linetext,=,1) | var %linetext $mid(%linetext,%pos) | dec %linenum }
  110. if ($count(%linetext,$chr($1)) != $count(%linetext,$chr($2))) { var %v1 $v1 , %v2 $v2
  111. inc %ScriptsWithMatch %matchflag | var %matchflag 0
  112. if (%spaces) var %linetext $replace(%linetext,$chr(32) $+ $chr(32),$chr(32) $+ $chr(160))
  113. inc %matchcount | echo %echotarget $+(%screv %v1,-vs-,%v2) $+($chr(3) Line:,$chr(22),%linenum,$chr(22)) %linetext }
  114. }
  115. ;if (%tl) var %done $chr(3) done searching $remove(%f,$mircdir) *
  116. }
  117. :top
  118. if ((%s == %totalscripts) && (%s_or_a)) { var %s 0, %totalscripts $alias(0) , %s_or_a 0 }
  119. }
  120. echo %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
  121. }
  122.  
  123. alias -l lum { tokenize 44 $rgb($color($1)) | return $calc(0.2126 * $brightness($1) + 0.7152 * $brightness($2) + 0.0722 * $brightness($3)) }
  124. alias -l brightness { var %res = $1 / 255 | return $iif(%res <= 0.03928, $calc(%res / 12.92), $calc((( %res + 0.055) / 1.055) ^ 2.4)) }
  125. ; borrowed lum/brightness from xpallette, user can change .179 to .3 to have more colors use white text
  126. alias -l contrast { var %a $lum($1) | return $iif(0.179 < $lum($1), 1, 0) }
  127.  


Comments
No Comments.

Login to Comment.