<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, April 29, 2003, 11:01 AM -->
<!-- MuClient version 3.41 -->
<!-- Plugin "MUSHCodeFormatter" generated by Plugin Wizard -->
<muclient>
<plugin
name="MUSHCodeFormatter"
author="Krenath"
id="610e45660aa64285ae03fd74"
language="VBscript"
purpose="Grabs attributes and formats them in the Notepad window"
date_written="2003-04-29 10:56:22"
requires="3.26"
version="1.0"
>
<description trim="y">
<![CDATA[
This plugin will create appropriate aliases and triggers so that examining an attribute in the world will open/append to a notepad window and display formatted softcode instead of one giant chunk.
The formatting isn't the greatest, but is still being worked on. It's better than a giant lump of code, however
Written by Krenath
]]>
</description>
</plugin>
<!-- Get our standard constants -->
<include name="constants.vbs"/>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="FugueEdit > *"
omit_from_output="y"
script="onEdit"
sequence="100"
other_text_colour="black"
other_back_colour="black"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
match="ex */*"
enabled="y"
>
<send>@dec/tf %1/%2</send>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
Sub OnEdit(a,b,c)
world.AppendToNotepad "Code Editor (Ctrl-Shift-S to send to world)",ufmt(fmt(c(1)))
End Sub
Function fmt(String)
Dim Changed,OldString
Changed = False
'tokens for comma, parenthesis, bracket, brace &cm &lp &rp &lb %rb &lc &rc
'tokens for indent & outdent &id &od
'token for cr keeps current intentlevel in mind &cr
String = replace(String,"/","&fs")
String = replace(String,"\","&bs")
Do
Changed = False
OldString = String
' Replace leftover wrapping chars with tokens
String = regreplace(String , "^([-_.A-Z@a-z&0-9*]*) (#[0-9]*)=(.*)" , "$1 $2&eq&cr$3" , "attrb")
String = regreplace(string , pFix("\(<param>\)") , "&lp$1&rp" , "paren")
String = regreplace(string , pFix("\[<param>\]") , "&lb$1&rb" , "brack")
String = regreplace(string , pFix("\{<param>\}") , "&lc$1&rc" , "brace")
String = replace(string,"] [","]%b&cr[")
String = replace(string,"]%b[","]%b&cr[")
String = replace(string,"][","]&cr[")
string = replace(string,"%b","&sp")
String = replace(string,"%r","&rr&cr")
'handle If/else indentation
String = regreplace(string,pFix("ifelse\(<param>,<param>,<param>\)"),"if(&tb$1&cm&id&cr$2&od&cr&cm&id&cr$3&od&cr)","if1 ")
String = regreplace(string,pFix("if\(<param>,<param>,<param>\)"),"if(&tb$1&cm&id&cr$2&od&cr&cm&id&cr$3&od&cr)","if2 ")
String = regreplace(string,pFix("if\(<param>,<param>\)"),"if(&tb$1&cm&id&cr$2&od&cr)","if3 ")
'handle iter
String = regreplace(string,pFix("iter\(<param>,<param>,<param>,<param>\)"),"iter(&tb$1&cm&id&cr$2&od&cr&cm&id&cr$3&od&cr&cm&id&cr$4&od&cr)","iter4")
String = regreplace(string,pFix("iter\(<param>,<param>,<param>\)"),"iter(&tb$1&cm&id&cr$2&od&cr&cm&id&cr$3&od&cr)","iter3")
String = regreplace(string,pFix("iter\(<param>,<param>\)"),"iter(&tb$1&cm&id&cr$2&od&cr)","iter2")
'handle switches that should have been ifs
String = regreplace(string,pFix("switch\(<param>,1,<param>,<param2>\)"),"if(&tb$1&cm&id&cr$3&od&cr&cm&id&cr$4&od&cr)","swif2")
String = regreplace(string,pFix("switch\(<param>,1,<param>\)"),"if(&tb$1&cm&id&cr$3&od&cr)","swif1")
'handle switches
String = regreplace(string,pFix("switch\(<param>,<param>,<param>,<param>,<param>\)"),"switch(&tb$1&cm&id&cr$2&cm$3&cr&cm$4&cm$5&od&cr)","swit5 ")
String = regreplace(string,pFix("switch\(<param>,<param>,<param>,<param>\)"),"switch(&tb$1&cm&id&cr$2&cm$3&cr&cm$4&od&cr)","swit4")
String = regreplace(string,pFix("switch\(<param>,<param>,<param>\)"),"switch(&tb$1&id&cr&cm$2&cm$3&od&cr)","swit3")
'Replace commas out of innermost functions.
String = regreplace(string,pfix("\(<param>,<param>,<param>,<param>\)"),"($1&cm$2&cm$3&cm$4)","4prm,")
String = regreplace(string,pfix("\(<param>,<param>,<param>\)"),"($1&cm$2&cm$3)","3prm,")
String = regreplace(string,pfix("\(<param>,<param>\)"),"($1&cm$2)","2prm,")
If String <> OldString then Changed=true
Loop While Changed
fmt = String
End Function
Function ufmt(string)
Dim x,indentlvl,Step,xi,xo,xc
x=0
indentlvl=0
step=2
string = replace(string,"&tb",vbTab)
string = replace(string,"&bs","\")
string = replace(string,"&fs","/")
string = replace(string,"&eq","=")
string = replace(string,"&lp","(")
string = replace(string,"&rp",")")
string = replace(string,"&lb","[")
string = replace(string,"&rb","]")
string = replace(string,"&lc","{")
string = replace(string,"&rc","}")
string = replace(string,"&cm",",")
string = replace(string,"&rr","%r")
string = replace(string,"&sp","%b")
While ( instr(string,"&id")>0 or instr(string,"&od")>0 or instr(string,"&cr")>0 ) and X<100
xi = instr(string,"&id")
xo = instr(string,"&od")
xc = instr(string,"&cr")
IF xi > 0 and (xo=0 or xo>xi) and (xc=0 or xc>xi) then
'world.note "indent"
indentlvl = indentlvl + 1
string = replace(string,"&id","",1,1) 'perform one replace only
ElseIF xo > 0 and (xi=0 or xi>xo) and (xc=0 or xc>xo) then
'world.note "outdent"
indentlvl = indentlvl -1
string = replace(string,"&od","",1,1) 'perform one replace only
ElseIF xc > 0 and (xi=0 or xi>xc) and (xo=0 or xo>xc) then
'world.note "c/r"
string = replace(string,"&cr",vbcrlf & tab(indentlvl),1,1) 'perform one replace only
End IF
x=x+1
Wend
ufmt = string & vbcrlf & vbcrlf & "-" & vbcrlf & vbcrlf
End Function
Function pFix(String)
pFix = replace(string,"<,param>","([^][{}()]*)")
pFix = replace(string,"<param>","([^][{}(),]*)")
End Function
Function RegReplace(sText,sOldPattern,sNewPattern,comment)
'Follows same syntax as normal Replace, but allows for some really impressive stunts.
Dim RegEx
Set RegEx = new RegExp
RegEx.Pattern = sOldPattern
RegEx.IgnoreCase = True
RegEx.Global = True
RegReplace = RegEx.Replace(sText,sNewPattern)
Set RegEx = Nothing
'if RegReplace <> stext then
'world.colourtell "red","black",comment
'World.note " > " & RegReplace
'end if
End Function
Function Tab(qty)
Dim i,temp
for i = 1 to qty
temp = temp & vbTab
next
tab = temp
End Function
]]>
</script>
<!-- Plugin help -->
<aliases>
<alias
script="OnHelp"
match="MUSHCodeFormatter:help"
enabled="y"
>
</alias>
</aliases>
<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
world.Note world.GetPluginInfo (world.GetPluginID, 3)
End Sub
]]>
</script>
</muclient>
|