<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, May 23, 2007, 1:44 AM -->
<!-- MuClient version 4.01 -->

<!-- Plugin "Paste_As_MU" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Paste_As_MU"
   author="Malix@8bit"
   id="a121e4feb06fbf0f141d3498"
   language="JScript"
   purpose="Insert clipboard converted to MushCode"
   date_written="2007-05-23 01:40:39"
   requires="3.69"
   version="1.0"
   >
<description trim="y">
<![CDATA[
This plugin allows you to insert the contents of the clipboard converted into MU format into the command window.

Just Ctrl-Click to bring up the alias menu, then click Paste As MU.

If it doesn't work, check if scripts are enabled(Shift-Ctrl-6) and that you have JavaScript installed.

'Paste_As_MU:help' brings up this text.
]]>
</description>

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   name="Paste_as_MU"
   script="PasteAsMU"
   match="PasteAsMU"
   enabled="y"
   menu="y"
   sequence="100"
  >
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[
function PasteAsMU(thename, theoutput, wildcardsVB)
{
	world.PasteCommand(convertAnsi2Mu(world.getClipboard()));
}

function isFANSI(sChar)
{
	uchr = sChar.charCodeAt(0);
	if (uchr == 1 || (uchr >= 3 && uchr <= 6) || (uchr >= 14 && uchr <= 26) ||
		(uchr >= 28 && uchr <= 31) || (uchr >= 127 && uchr <= 254)) {
		return 1;
	}
	else
		return 0;
}

function convertAnsi2Mu(sInput)
{
	len = sInput.length;
	sOutput = "";
	for(i = 0; i < len; i++)
	{
		thisChar = sInput.charAt(i);
		charCount = 1;
		if ((thisChar == " " || isFANSI(thisChar)) && thisChar == sInput.charAt(i+1)) {
			charCount = 2;
			for (srch=i+2; srch<len && thisChar==sInput.charAt(srch); srch++)
				charCount++;
			i = srch-1;
		}
		if (thisChar == " ") {
			if (charCount == 1) {
				sOutput = sOutput + " ";
			}
			else if (charCount <= 4) {
				for (x=0;x<charCount;x++) {
					sOutput = sOutput + "%b";
				}
			}
			else {
				sOutput = sOutput + "[space(" + charCount + ")]";
			}
		}
		else if (isFANSI(thisChar)) {
			if (charCount == 1) {
				sOutput = sOutput + "[c(" + thisChar.charCodeAt(0) + ")]";
			}
			else if (charCount > 1) {
				sOutput = sOutput + "[c(" + thisChar.charCodeAt(0) + "," + charCount + ")]";
			}
		}
		else {
			switch (thisChar) {
				case "[":
				case "]":
				case ")":
				case "(":
				case "}":
				case "{":
				case "\\":
				case ",":
				case "%":
					thisChar = "\\" + thisChar;
					break;
				case '\r':
					thisChar = "";
					break;
				case '\n':
					thisChar = "%r";
					break;
				case '\t':
					thisChar = "%t";
					break;
			}
			sOutput = sOutput + thisChar;
		}
	}
	return sOutput;
}

]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="Paste_As_MU:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
function OnHelp (sName, sLine, wildcards)
  {
  world.Note (world.GetPluginInfo (world.GetPluginID, 3));
  }
]]>
</script> 

</muclient>
