Plugin for checking brackets , etc, in MUSH code?

Posted by Linda on Thu 15 Jul 2004 12:20 AM — 3 posts, 18,253 views.

Sweden #0
Would it be possible to use a plugin as a replacement for a softcoded command that checks a MUSH code attribute and reports back the number of braces, brackets and parenthesis?

Essentiall, you need something where you can do 'check <#dbref>/<attribute>' or 'check <#dbref>/<attributepattern>' and where it puts out something like this:

ATTRIBUTE: { }: 4/4 [ ]: 26/26 ( ): 40/40

If that looks doable, could someone perhaps give me some pointers towards how to construct one? Unless there's one out there already, of course. :)
Australia Forum Administrator #1
This should do it Linda. It only does one attribute at a time at present, but it should give you a kickstart for modifying to handle more.

You can copy and paste the code below into a file, or simply download it from the plugins page (name CheckAttribute):


http://www.gammon.com.au/mushclient/plugins/



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, July 15, 2004, 1:30 PM -->
<!-- MuClient version 3.50 -->

<!-- Plugin "CheckAttribute" generated by Plugin Wizard -->

<muclient>
<plugin
   name="CheckAttribute"
   author="Nick Gammon"
   id="a3e213677c69a51c376ba5d8"
   language="VBscript"
   purpose="Counts brackets in a MUSH attribute"
   date_written="2004-07-15 13:23:44"
   requires="3.25"
   version="1.0"
   >
<description trim="y">
<![CDATA[
This counts brackets in a MUSH attribute.

Usage
-----

Type:  check dbref/attribute

eg. 

check me/name

It will send a request to the MUSH for the attribute, when it replies
a trigger will catch it and count the various bracket types.

For this help, type: CheckAttribute:help
]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="@password *=*"
   name="attribute_editor"
   omit_from_output="y"
   script="count_brackets"
   sequence="100"
  >
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   match="check */*"
   enabled="y"
   expand_variables="y"
   omit_from_output="y"
  >
  <send>@@pemit/silent me=@password %2=[get(%1/%2)]
</send>
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[
'
'  count number of times one character appears in a string
'

function count_one_thing (txt, what)
dim i
dim count

'
'  zero counter
'
  count = 0

'
'  process whole string
'
  for i = 1 to len (txt)
    if mid (txt, i, 1) = what then
      count = count + 1
    end if  ' item found
  next

'
'  return result
'
  count_one_thing = count  

end function  ' count_one_thing 

'
'  counts number of various types of brackets in an attribute
'
sub count_brackets (thename, theoutput, thewildcards)
dim txt

'
'  show the attribute name (wildcard 1) and the contents 
'       (wildcard 2)
'
  Note "Attribute: " & thewildcards (1) & _
        " = " & thewildcards (2)

'
'  save contents in temporary variable
'
  txt = thewildcards (2)

'
'  show the counts
'
  Note "Attribute: { }: " & _
       count_one_thing (txt, "{") & "/" & _
       count_one_thing (txt, "}") & " [ ]: " & _
       count_one_thing (txt, "[") & "/" & _
       count_one_thing (txt, "]") & " ( ): " & _
       count_one_thing (txt, "(") & "/" & _
       count_one_thing (txt, ")") 

end sub ' count_brackets 

'
'  initialise a unique password to prevent spoofing
'
Sub OnPluginInstall
  world.setvariable "password", world.getuniqueid
End Sub

]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="CheckAttribute:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
  world.Note world.GetPluginInfo (world.GetPluginID, 3)
End Sub
]]>
</script> 

</muclient>

Amended on Thu 15 Jul 2004 03:40 AM by Nick Gammon
Sweden #2
Thank you, works like a charm. :) If I manage to make some useful modifications, I'll make sure to post them.