Bracket Checking Tool
Jump to navigation
Jump to search
This script contains a tool for checking the number of opening and closing brackets in a scriptfile or line against each other. It is not flawless and there can be cases where it flags an error when there is none. For example when using a smiley in a /msg. This works the other way around, too. When you missed a bracket but, for example, a smiley in a /msg makes up for that missing bracket, this tool will not flag an error.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Bracket checking tool
; Written by Shenghi
; Contact in #help.script @ irc.quakenet.org
;
; Small tool that checks closing and opening brackets
; in a single line or a file.
;
; Note: With brackets we (I) mean the ( and ) characters.
;
; Usage: /bcheck [-f] <text|file>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias bcheck {
if ($0 == 2) && ($1 == -f) {
if (!$isfile($2)) echo -ag mdt: No such file.
else {
echo -ag Debugging file: $2
var %ticks = $ticks
var %pos = 0
var %l = 1
var %fs = $file($2).size
while (%pos < %fs) {
bread -t $2 %pos %fs &n
if (!$iscomment(&n)) {
if ($obrack(&n) != $cbrack(&n)) echo -ag bcheck: Error on line %l $+ : number of opening brackets = $v1 -=- number of closing brackets = $v2 $+ .
}
inc %l
var %pos = $calc(%pos + $bvar(&n,0) + 2)
}
echo -ag End of debug. $calc(%l - 1) lines debugged in $calc($ticks - %ticks) ms.
}
}
elseif ($1 != -f) {
if ($count($1-,$chr(40)) != $count($1-,$chr(41))) echo -ag bcheck: Error: number of opening brackets = $v1 -=- number of closing brackets = $v2 $+ .
else echo -ag bcheck: No errors found.
}
else echo -ag bcheck: Error. Erronious syntax.
}
alias -l iscomment {
if ($bfind($1,1,59)) {
var %bd_semicolon = $v1
var %i = $calc(%bd_semicolon - 1)
while %i {
if ($bvar($1,%i) != 32) return $null
else dec %i
}
return 1
}
}
alias -l obrack {
if ($bvar($1,0) < 900) return $count($bvar($1,1,$v1).text,$chr(40))
var %num = 0
var %bpos = 1
while ($bvar($1,%bpos)) {
if ($bfind($1,%bpos,40)) {
inc %num
var %bpos = $calc($v1 + 1)
}
else var %bpos = $calc($bvar($1,0) + 1)
}
return %num
}
alias -l cbrack {
if ($bvar($1,0) < 900) return $count($bvar($1,1,$v1).text,$chr(41))
var %num = 0
var %bpos = 1
while ($bvar($1,%bpos)) {
if ($bfind($1,%bpos,41)) {
inc %num
var %bpos = $calc($v1 + 1)
}
else var %bpos = $calc($bvar($1,0) + 1)
}
return %num
}