Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ MUSH softcode Formatter Plugin

MUSH softcode Formatter Plugin

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Krenath   USA  (76 posts)  Bio
Date Wed 30 Apr 2003 04:17 PM (UTC)

Amended on Wed 30 Apr 2003 04:23 PM (UTC) by Krenath

Message
Thie following plugin tries to accomplish some rudimentary formatting of an attribute grabbed from a MUSH.

It included an alias for ex */* and a trigger on FugueEdit > * like the 'grab' plugin does. This differes from the 'grab' plugin in the following ways:

1. Opens a new notepad window or appends to the window if already open.

2. Outputs formatted MUSH softcode to the notepad with each line separated by a dash on a line by itself.

Already built into MUSHclient's notepad is a convenient feature for sending the formatted softcode back to the MUSH. But you'll first want to configure "Paste To World" to handle Formatted Softcode and probably ensure that "confirm on each paste to world" is disabled. You may or may not want to echo the pasted code to the output window. I turn that option off.

Using this plugin, it's possible to examine a lengthy, complex attribute, switch to the notepad window and make whatever changes you want, and simply type control-shift-s to save the changes back to the MUSH. I can pretend that unformatted softcode no longer exists :)

It's posted in two parts since it was too large to post as a single message. Yay.


- Krenath from
bDv TrekMUSH
ATS TrekMUSH
TNG TrekMUSE
TOS TrekMUSE
Top

Posted by Krenath   USA  (76 posts)  Bio
Date Reply #1 on Wed 30 Apr 2003 04:22 PM (UTC)

Amended on Fri 02 May 2003 12:07 AM (UTC) by Krenath

Message

<?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 &gt; *"
   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>

- Krenath from
bDv TrekMUSH
ATS TrekMUSH
TNG TrekMUSE
TOS TrekMUSE
Top

Posted by Neva   USA  (117 posts)  Bio
Date Reply #2 on Wed 30 Apr 2003 06:19 PM (UTC)
Message
I don't know much about this kind of thing, granted, but might you get better formatting easier if you used something like Greg Kempe's formatting program? It's supposed to have some way of interfacing with stuff like this. (URL: http://mform.kempe.net/ )
Top

Posted by Krenath   USA  (76 posts)  Bio
Date Reply #3 on Wed 30 Apr 2003 10:11 PM (UTC)
Message
Well, with MUSH Formatter being a compiled program (and therefore unmodifiable by me) and with precious few options for exactly how individual functions would be formatted, I decided a scripted version would be more in line with what I wanted. Sure, I dont have a nice interface that lets you easily say "nest and indent all parameters for the if() function" but it still makes it possible.

MUSH Formatter would be a much more convenient program if you could configure each of the recognized functions in its Functions menu and instruct the Formatter whether you want it all on one line or nested and indented.





- Krenath from
bDv TrekMUSH
ATS TrekMUSH
TNG TrekMUSE
TOS TrekMUSE
Top

Posted by Neva   USA  (117 posts)  Bio
Date Reply #4 on Wed 30 Apr 2003 10:44 PM (UTC)
Message
Have you suggested that to Greg? :) I only brought it up because I figured it'd be easier than trying to program the same stuff all over again--if you're doing it differently, that's obviously not the same story, but it was just an idea.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Wed 30 Apr 2003 11:14 PM (UTC)
Message
Krenath, I have fixed it so you can do unlimited length posts, and amended your original plugin into one piece.

I suggest for pasting code you use the Notepad "quote forum codes" function to "escape" out backslashes and square brackets, or you might find things like [b] becoming bold text, and not executing correctly.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Wed 30 Apr 2003 11:18 PM (UTC)

Amended on Wed 30 Apr 2003 11:21 PM (UTC) by Nick Gammon

Message
Sorry, think I corrupted it - can you repost in one piece and after doing the quote forum codes?


Update - think I might have fixed it, it seems to load OK now.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Krenath   USA  (76 posts)  Bio
Date Reply #7 on Thu 01 May 2003 02:17 PM (UTC)

Amended on Thu 01 May 2003 02:18 PM (UTC) by Krenath

Message
If anyone's wondering about the way the code works, all it does is make multiple passes over the string 'tokenizing' as it goes.

On each pass, it looks for the innermost functions, replaces the commas, parenthesis, braces and brackets with 'placeholders' so it can later remember where all these things came from. By replacing all these characters out, it can, on the next pass, concentrate on the next-innermost function, easily locating it because the current innermost commas, parenthesis, braces, and brackets are guaranteed to be related to each other.

In some cases, while replacing punctuation with 'tokens', indent and outdent codes are inserted.

Once the string has been combed over and no more commas, braces, or brackets can be found within the string, a second subroutine is used to change all the tokens back to their original characters, then makes a pass through the string to format the string according to the embedded indent/outdent/carriage return codes.

The resulting string is then appended to the notepad window, followed by a dash on a line by itself.

Since the code appends to the notepad, one can actualy type 'ex <object>/*' and a mush like PennMUSH will @decompile the entire object, sending each line to the Notepad window in a formatted form.

As the script is not compiled and the source is provided, if your formatting preferences differ from mine (or your regular expression pattern skills are greater) you can freely modify the included code to format as you like it.

I'm still trying to figure out how to write a regular expression pattern that matches a function with any number of parameters (such as switch()). I'd prefer to have switch() formatted as
Quote:

[switch(
        [<condition>]
        [<condition>]
        [<condition>]
        ,000,[<result>]
        ,001,[<result>]
        ,010,[<result>]
     ...
        ,[<default>]
)]

...but I'm still working on that. :)

- Krenath from
bDv TrekMUSH
ATS TrekMUSH
TNG TrekMUSE
TOS TrekMUSE
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


28,483 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.