<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brian&#039;s Blog &#187; Eggdrop</title>
	<atom:link href="http://briped.net/tag/eggdrop/feed/" rel="self" type="application/rss+xml" />
	<link>http://briped.net</link>
	<description>Blogging when bored...</description>
	<lastBuildDate>Sun, 08 Jan 2012 17:50:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>calc.tcl</title>
		<link>http://briped.net/2007/06/20/calctcl/</link>
		<comments>http://briped.net/2007/06/20/calctcl/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 09:22:42 +0000</pubDate>
		<dc:creator>Brian Schmidt Pedersen</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[TCL]]></category>
		<category><![CDATA[Eggdrop]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://briped.net/2007/06/20/calctcl/</guid>
		<description><![CDATA[#### calc.tcl v1.0.1 ########################################################### ################################################################################ ## Written by: &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;## ## &#160; KuNgFo0 &#160;(http://www.eggfaq.com/). &#160; &#160; &#160; &#160; &#160; &#160; &#160;## ## &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container tcl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="tcl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#### calc.tcl v1.0.1 ###########################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## Written by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; KuNgFo0 &nbsp;(http://www.eggfaq.com/). &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Modified by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; Brian Schmidt aka. brianMan. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;">#### Readme / Help #############################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## This script is ripped from KuNgFoO's ib.tcl v3.19 (infobot) script. &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Script that can calculate just about anything ;) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Usage: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; To have the .calc[ulate] commands available on a channel you need to set ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; the channel flag +calculator from the console/partyline . &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; ``.chanset #channel +calculator´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Channel Commands (available only if channel is +convert): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; .calc[ulate] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## Example: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; ``.calc 15*20+3´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;">#### Changelog #################################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## v1.0.1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## * Minor code cleanup &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## v1.0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## + Initial release. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## * Changed the default trigger ``botname, calc[ulate]´´ to ``.calc[ulate]´´ ##</span><br />
<span style="color: #808080; font-style: italic;">## + Added the possibility to control which channels could use the commands &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; with the channel flag ``+/-calculator´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
bind pub - .calc pub_calc<br />
bind pub - .calculate pub_calc<br />
bind msg - calc msg_calc<br />
bind msg - calculate msg_calc<br />
<br />
setudef flag calculator<br />
<br />
<span style="color: #808080; font-style: italic;"># You shouldn't change these, however you may add additional variables</span><br />
<span style="color: #808080; font-style: italic;"># These are used via %varname in the 'calculate' command</span><br />
<span style="color: #808080; font-style: italic;"># Example: Mybot, calculate %pi / 2</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> calc_const<span style="color: black;">&#40;</span>pi<span style="color: black;">&#41;</span> <span style="color: #ff4500;">3.14159265358979323846</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># PI</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> calc_const<span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span> &nbsp;<span style="color: #ff4500;">2.7182818284590452354</span> &nbsp;<span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># E</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> calc_const<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span> &nbsp;6.0221367e23 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Avogadro's number [1/mol]</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> calc_const<span style="color: black;">&#40;</span>R<span style="color: black;">&#41;</span> &nbsp;<span style="color: #ff4500;">8.314510</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Universal gas constant [J/(mol*K)]</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> calc_const<span style="color: black;">&#40;</span>k<span style="color: black;">&#41;</span> &nbsp;1.380658e-23 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Boltzmann's constant [J/K]</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> calc_const<span style="color: black;">&#40;</span>G<span style="color: black;">&#41;</span> &nbsp;6.67259e-11 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Universal gravitational constant [N*m^2/kg^2]</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> calc_const<span style="color: black;">&#40;</span>h<span style="color: black;">&#41;</span> &nbsp;6.62606891e-34 &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Planck's constant [J*s]</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> calc_const<span style="color: black;">&#40;</span>c<span style="color: black;">&#41;</span> &nbsp;2.99792458e8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Speed of light [m/s]</span><br />
<br />
<span style="color: #808080; font-style: italic;"># No more editing required</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> xrange <span style="color: black;">&#123;</span>xr xr1 xr2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">join</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lrange</span> <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$xr</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$xr1</span> <span style="color: #ff3333;">$xr2</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> xindex <span style="color: black;">&#123;</span>xr xr1<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">join</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lrange</span> <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$xr</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$xr1</span> <span style="color: #ff3333;">$xr1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> calc_fixdata <span style="color: black;">&#123;</span>arg output<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> botnick<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> index <span style="color: #ff3333;">$output</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;#&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all -nocase <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output</span><span style="color: #483d8b;">'s} $arg &quot;your&quot; arg<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; regsub -all -nocase {$botnick'</span>s<span style="color: black;">&#125;</span> <span style="color: #ff3333;">$arg</span> <span style="color: #483d8b;">&quot;my&quot;</span> arg<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$arg</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> calc_msg <span style="color: black;">&#123;</span>targets arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> target <span style="color: #ff3333;">$targets</span> <span style="color: black;">&#123;</span> puthelp <span style="color: #483d8b;">&quot;PRIVMSG $target :[calc_fixdata $arg $target]&quot;</span> <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> calc_fixtopic <span style="color: black;">&#123;</span>arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>\\\<span style="color: black;">&#123;</span>\<span style="color: black;">&#125;</span>\<span style="color: black;">&#91;</span>\<span style="color: black;">&#93;</span>\<span style="color: #483d8b;">&quot;]} $arg {} &nbsp; arg ; # Bad characters<br />
&nbsp; &nbsp; regsub -all {(<span style="color: #000099; font-weight: bold;">\s</span>)+} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$arg {<span style="color: #000099; font-weight: bold;">\1</span>} arg ; # Double whitespace<br />
&nbsp; &nbsp; regsub -all {^<span style="color: #000099; font-weight: bold;">\s</span>*|<span style="color: #000099; font-weight: bold;">\s</span>*$} &nbsp; &nbsp; &nbsp;$arg {} &nbsp; arg ; # Whitespace at ends<br />
&nbsp; &nbsp; return $arg<br />
}<br />
<br />
# Begin 'calc' code<br />
proc calc_fixexpr {exp} {<br />
&nbsp; &nbsp; global calc_const<br />
&nbsp; &nbsp; set exp [calc_fixtopic $exp]<br />
&nbsp; &nbsp; foreach i [array names calc_const] {<br />
&nbsp; &nbsp; &nbsp; &nbsp; regsub -all &quot;</span>\<span style="color: #66cc66;">%</span><span style="color: #ff3333;">$i</span><span style="color: #483d8b;">&quot; $exp $calc_const($i) exp<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; return $exp<br />
}<br />
# End 'calc' code<br />
<br />
# Begin Public binds code<br />
proc msg_calc {nick uhost hand arg} {<br />
&nbsp; &nbsp; global botnick<br />
&nbsp; &nbsp; pub_calc $nick $uhost $hand &quot;</span><span style="color: #483d8b;">&quot; $arg<br />
}<br />
<br />
proc pub_calc {nick uhost hand chan arg} {<br />
&nbsp; &nbsp; global botnick calc_flag<br />
&nbsp; &nbsp; if {(![isbotnick $nick]) &amp;&amp; (![matchattr $hand +b])} {<br />
&nbsp; &nbsp; &nbsp; &nbsp; if {(![string match &quot;</span><span style="color: #ff3333;">$chan</span><span style="color: #483d8b;">&quot; &quot;</span><span style="color: #483d8b;">&quot;]) &amp;&amp; (![channel get $chan calculator])} {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0 ; # If command comes from a channel, and that channel doesn't have +calculator then ignore<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; set isuser [expr {[matchattr $hand - $chan] || [matchattr $hand -]}] ; # Note that $chan might be &quot;</span><span style="color: #483d8b;">&quot;, so we must handle both cases<br />
&nbsp; &nbsp; &nbsp; &nbsp; if {([validchan $chan]) &amp;&amp; ($isuser)} {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set output1 $chan ; # The bot sends the text to the channel for users<br />
&nbsp; &nbsp; &nbsp; &nbsp; } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set output1 $nick ; # Non-users get privmsg'd<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; if {[set i [string last &quot;</span><span style="color: #66cc66;">&gt;</span><span style="color: #483d8b;">&quot; $arg]] == -1} {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set output2 $output1 ; # By default, output2 (~stdout~) goes to output1 (~stderr~)<br />
&nbsp; &nbsp; &nbsp; &nbsp; } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Output has been redirected<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if {(!$isuser) || ([set output2 [string trim [string range $arg [expr $i + 1] end] &quot;</span> <span style="color: #483d8b;">&quot;]] == &quot;</span><span style="color: #483d8b;">&quot;)} {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set output2 $output1 ; # Error (User doesn't have access, or output was &quot;</span><span style="color: #483d8b;">&quot;), so we go back to the default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set arg [string trim [string range $arg 0 [expr $i - 1]] &quot;</span> <span style="color: #483d8b;">&quot;]<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; set remainder [xrange $arg 0 end]<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; if {$remainder == &quot;</span><span style="color: #483d8b;">&quot;} {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calc_msg $output1 &quot;</span><span style="color: #ff7700;font-weight:bold;">error</span> parsing sentence<span style="color: #483d8b;">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; } elseif {[catch {expr [calc_fixexpr $remainder]} output]} {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calc_msg $output1 &quot;</span><span style="color: #ff7700;font-weight:bold;">error</span> calculating <span style="color: #483d8b;">'$remainder'</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$output</span><span style="color: black;">&#41;</span><span style="color: #483d8b;">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calc_msg $output2 &quot;</span><span style="color: #ff3333;">$remainder</span> = <span style="color: #ff3333;">$output</span><span style="color: #483d8b;">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
}<br />
# End Public binds code<br />
<br />
# Init stuff<br />
if {[catch {package require Tcl 8.2} error]} {<br />
&nbsp; &nbsp; putlog &quot;</span><span style="color: #ff7700;font-weight:bold;">error</span> TCL v8.2 or higher is required to run this script<span style="color: #483d8b;">&quot;<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
putlog &quot;</span><span style="color: #66cc66;">***</span> LOADED: calc.tcl<span style="color: #483d8b;">&quot;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://briped.net/2007/06/20/calctcl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>convert.tcl</title>
		<link>http://briped.net/2007/06/20/converttcl/</link>
		<comments>http://briped.net/2007/06/20/converttcl/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 09:22:00 +0000</pubDate>
		<dc:creator>Brian Schmidt Pedersen</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[TCL]]></category>
		<category><![CDATA[Eggdrop]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://briped.net/2007/06/20/converttcl/</guid>
		<description><![CDATA[#### convert.tcl v1.0.1 ######################################################## ################################################################################ ## Written by: &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;## ## &#160; KuNgFo0 &#160;(http://www.eggfaq.com/). &#160; &#160; &#160; &#160; &#160; &#160; &#160;## ## &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container tcl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="tcl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#### convert.tcl v1.0.1 ########################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## Written by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; KuNgFo0 &nbsp;(http://www.eggfaq.com/). &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Modified by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; Brian Schmidt aka. brianMan. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;">#### Readme / Help #############################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## This script is ripped from KuNgFoO's ib.tcl v3.19 (infobot) script. &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## The script converts between a number of various units, for more speficic &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## information on which untis you should please refer to the source of this &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## script. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Usage: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; To have the .conv[ert] commands available on a channel you need to set &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; the channel flag +convert from the console/partyline . &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; ``.chanset #channel +convert´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Channel Commands (available only if channel is +convert): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; .conv[ert] &nbsp; to &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## Example: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; ``.conv 20 C to F´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; Converts 20 degrees Celcius to it's Fahrenheit equivilant. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;">#### Changelog #################################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## v1.0.1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## * Minor code cleanup &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## v1.0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## + Initial release. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## * Changed the default trigger ``botname, conv[ert]´´ to ``.con[vert]´´ &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## + Added the possibility to control which channels could use the commands &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; with the channel flag ``+/-convert´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
bind pub - .conv pub_conv<br />
bind pub - .convert pub_conv<br />
bind msg - conv msg_conv<br />
bind msg - convert msg_conv<br />
<br />
<span style="color: #808080; font-style: italic;"># Set the name of the channelflag used to tell whether the convert command is</span><br />
<span style="color: #808080; font-style: italic;"># enabled or not for that specific channel.</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_channel_flag <span style="color: #483d8b;">&quot;convert&quot;</span><br />
<br />
setudef flag <span style="color: #ff3333;">$conv_channel_flag</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as the exec command to run the 'units' command from the shell</span><br />
<span style="color: #808080; font-style: italic;"># Note: Not all systems will have this installed</span><br />
<span style="color: #808080; font-style: italic;"># Set to &quot;&quot; to disable</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_units_exec <span style="color: #483d8b;">&quot;units -v&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Conversion formulas - each array is for its own dimension (length, volume, etc).</span><br />
<span style="color: #808080; font-style: italic;"># Each unit is converted to a standard type by multiplying the value by the factors</span><br />
<span style="color: #808080; font-style: italic;"># below. &nbsp;It is then converted from the standard type to any other unit by</span><br />
<span style="color: #808080; font-style: italic;"># dividing the factors. &nbsp;The standard unit used must be the same for everything in</span><br />
<span style="color: #808080; font-style: italic;"># each dimension, and can be anything as long as they are the same. &nbsp;I used the root</span><br />
<span style="color: #808080; font-style: italic;"># metric units for most things (meters, liters, grams, etc).</span><br />
<span style="color: #808080; font-style: italic;"># Note: All strings are matched as regular expressions</span><br />
<span style="color: #808080; font-style: italic;"># * Prefix with (?c) for units that should be case sensitive</span><br />
<span style="color: #808080; font-style: italic;"># * Prefix with (.*?) for metric units</span><br />
<span style="color: #808080; font-style: italic;"># * Append (?:s) for units with an optional plural ending, etc</span><br />
<span style="color: #808080; font-style: italic;"># * Only use multiplication and division in the formulas, no addition or subtraction</span><br />
<span style="color: #808080; font-style: italic;"># * It's a very good idea to have all the formulas return values in decimal form</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp; (&quot;1&quot; doesn't matter, though)</span><br />
<span style="color: #808080; font-style: italic;"># Syntax:</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp;name abbreviation factor</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_unit<span style="color: black;">&#40;</span>length<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>meter<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>m <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; inch<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:es<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp;<span style="color: #ff7700;font-weight:bold;">in</span> &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #ff4500;">2.54</span> / <span style="color: #ff4500;">100</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; foot|feet &nbsp; &nbsp; &nbsp; &nbsp;ft &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #ff4500;">2.54</span> / <span style="color: #ff4500;">100</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">12</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; mile<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; mi &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #ff4500;">2.54</span> / <span style="color: #ff4500;">100</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">12</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">5280</span><span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_unit<span style="color: black;">&#40;</span>volume<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>liter<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>L <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; pint<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; pt &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #ff4500;">3.785</span> / <span style="color: #ff4500;">8</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; quart<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp;qt &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #ff4500;">3.785</span> / <span style="color: #ff4500;">4</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; gallon<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; gal &nbsp; &nbsp;<span style="color: #ff4500;">3.785</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_unit<span style="color: black;">&#40;</span>weight<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>gram<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>g <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; ounce<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; oz &nbsp; &nbsp; <span style="color: #ff4500;">28.35</span><br />
&nbsp; &nbsp; pound<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; lbs &nbsp; &nbsp;<span style="color: #ff4500;">453.59</span><br />
&nbsp; &nbsp; ton<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; T &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: #ff4500;">453.59</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2000</span><span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_unit<span style="color: black;">&#40;</span>work<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>joule<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>J &nbsp; &nbsp; &nbsp;<span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>watt-<span style="color: #66cc66;">?</span>second<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp;<span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>w-<span style="color: #66cc66;">?</span>s &nbsp; <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>watt-<span style="color: #66cc66;">?</span>hour<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp;<span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>w-<span style="color: #66cc66;">?</span>hrs <span style="color: #ff4500;">3600.0</span><br />
&nbsp; &nbsp; britishthermalunit<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> btu &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff4500;">1055.056</span><br />
&nbsp; &nbsp; calorie<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cal &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff4500;">4.1868</span><br />
&nbsp; &nbsp; foot-<span style="color: #66cc66;">?</span>pound<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp;ft-<span style="color: #66cc66;">?</span>lbs &nbsp; &nbsp; <span style="color: #ff4500;">1.356</span><br />
&nbsp; &nbsp; electron-<span style="color: #66cc66;">?</span>volt<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; eV &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.6021917E-19<br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_unit<span style="color: black;">&#40;</span>power<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>watt<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>w <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; volt-<span style="color: #66cc66;">?</span>amp<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> va &nbsp; &nbsp; <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; horsepower &nbsp; &nbsp; &nbsp;hp &nbsp; &nbsp; <span style="color: #ff4500;">746</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_unit<span style="color: black;">&#40;</span><span style="color: #008000;">time</span><span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>second<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>s<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:ec<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; minute<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp;min<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff4500;">60.0</span><br />
&nbsp; &nbsp; hour<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp;h<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:r<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #ff4500;">60.0</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">60</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; day<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: #ff4500;">60.0</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">60</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">24</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; week<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp;wk<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: #ff4500;">60.0</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">60</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">24</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">7</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; year<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp;yr<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: #ff4500;">60.0</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">60</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">24</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">365</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; decade<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: #ff4500;">60.0</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">60</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">24</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">365</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">10</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; century|centuries <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: #ff4500;">60.0</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">60</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">24</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">365</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">100</span><span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_unit<span style="color: black;">&#40;</span><span style="color: #008000;">binary</span><span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; option metric <span style="color: #ff4500;">2</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>byte<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>b <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>.<span style="color: #66cc66;">*?</span><span style="color: black;">&#41;</span>bit<span style="color: black;">&#40;</span><span style="color: #66cc66;">?</span>:s<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span> &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #ff4500;">1.0</span> / <span style="color: #ff4500;">8</span><span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Misc conversion formulas - these are types that cannot</span><br />
<span style="color: #808080; font-style: italic;"># be converted by regular multiplication/division of factors.</span><br />
<span style="color: #808080; font-style: italic;"># The principle is the same as the formulas above, however</span><br />
<span style="color: #808080; font-style: italic;"># the arrays are broken down into *_from and *_to variables.</span><br />
<span style="color: #808080; font-style: italic;"># Note: $value is used as the value being converted.</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_misc_from<span style="color: black;">&#40;</span>num<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; option metric <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; integer|int &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;%d&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; long &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;%u&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; decimal|dec|float|double <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;%f&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; octal|oct &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;%o&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; hexadecimal|hex &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;%x&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">binary</span>|bin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>bin2int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; ip &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>ip2long <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; rgb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>rgb2int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_misc_to<span style="color: black;">&#40;</span>num<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; option metric <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; integer|int &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%d&quot;</span> <span style="color: black;">&#91;</span>conv_int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; long &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%u&quot;</span> <span style="color: black;">&#91;</span>conv_int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; decimal|dec|float|double <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%f&quot;</span> <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; octal|oct &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%o&quot;</span> <span style="color: black;">&#91;</span>conv_int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; hexadecimal|hex &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%X&quot;</span> <span style="color: black;">&#91;</span>conv_int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">binary</span>|bin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>int2bin <span style="color: black;">&#91;</span>conv_int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; ip &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>long2ip <span style="color: black;">&#91;</span>conv_int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; rgb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>int2rgb <span style="color: black;">&#91;</span>conv_int <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_misc_from<span style="color: black;">&#40;</span>temperature<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; option metric <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; fahrenheit &nbsp; &nbsp; &nbsp; &nbsp; F <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$value</span> - <span style="color: #ff4500;">32</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">5</span> / <span style="color: #ff4500;">9.0</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; kelvin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; K <span style="color: black;">&#123;</span><span style="color: #ff3333;">$value</span> - <span style="color: #ff4500;">273.15</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; celsius|centigrade C <span style="color: black;">&#123;</span><span style="color: #ff3333;">$value</span><span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_misc_to<span style="color: black;">&#40;</span>temperature<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; option metric <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; fahrenheit &nbsp; &nbsp; &nbsp; &nbsp; F <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">9</span> / <span style="color: #ff4500;">5.0</span> <span style="color: #66cc66;">*</span> <span style="color: #ff3333;">$value</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">32</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; kelvin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; K <span style="color: black;">&#123;</span><span style="color: #ff3333;">$value</span> + <span style="color: #ff4500;">273.15</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; celsius|centigrade C <span style="color: black;">&#123;</span><span style="color: #ff3333;">$value</span><span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Conversion strings to specificially ignore (that conflict with expr)</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_ignore <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; e abs acos asin<br />
&nbsp; &nbsp; atan atan2 ceil<br />
&nbsp; &nbsp; cos cosh double<br />
&nbsp; &nbsp; exp floor fmod<br />
&nbsp; &nbsp; hypot int log<br />
&nbsp; &nbsp; log10 pow rand<br />
&nbsp; &nbsp; round sin sinh<br />
&nbsp; &nbsp; sqrt srand tan<br />
&nbsp; &nbsp; tanh<br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Metric conversion factors</span><br />
<span style="color: #808080; font-style: italic;"># Note: Abbreviations are case sensitive here</span><br />
<span style="color: #808080; font-style: italic;"># Syntax:</span><br />
<span style="color: #808080; font-style: italic;"># &nbsp;mame abbreviation factor</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> conv_metric <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; Yotta Y &nbsp;<span style="color: #ff4500;">24</span><br />
&nbsp; &nbsp; Zetta Z &nbsp;<span style="color: #ff4500;">21</span><br />
&nbsp; &nbsp; Exa &nbsp; E &nbsp;<span style="color: #ff4500;">18</span><br />
&nbsp; &nbsp; Peta &nbsp;P &nbsp;<span style="color: #ff4500;">15</span><br />
&nbsp; &nbsp; Tera &nbsp;T &nbsp;<span style="color: #ff4500;">12</span><br />
&nbsp; &nbsp; Giga &nbsp;G &nbsp;<span style="color: #ff4500;">9</span><br />
&nbsp; &nbsp; Mega &nbsp;M &nbsp;<span style="color: #ff4500;">6</span><br />
&nbsp; &nbsp; Kilo &nbsp;k &nbsp;<span style="color: #ff4500;">3</span><br />
&nbsp; &nbsp; Hecto h &nbsp;<span style="color: #ff4500;">2</span><br />
&nbsp; &nbsp; Deca &nbsp;dk <span style="color: #ff4500;">1</span><br />
<br />
&nbsp; &nbsp; Deci &nbsp;d &nbsp;-<span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; Centi c &nbsp;-<span style="color: #ff4500;">2</span><br />
&nbsp; &nbsp; Milli m &nbsp;-<span style="color: #ff4500;">3</span><br />
&nbsp; &nbsp; Micro µ &nbsp;-<span style="color: #ff4500;">6</span><br />
&nbsp; &nbsp; Nano &nbsp;n &nbsp;-<span style="color: #ff4500;">9</span><br />
&nbsp; &nbsp; Pico &nbsp;p &nbsp;-<span style="color: #ff4500;">12</span><br />
&nbsp; &nbsp; Femto f &nbsp;-<span style="color: #ff4500;">15</span><br />
&nbsp; &nbsp; Atto &nbsp;a &nbsp;-<span style="color: #ff4500;">18</span><br />
&nbsp; &nbsp; Zepto z &nbsp;-<span style="color: #ff4500;">21</span><br />
&nbsp; &nbsp; Yocto y &nbsp;-<span style="color: #ff4500;">24</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> xrange <span style="color: black;">&#123;</span>xr xr1 xr2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">join</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lrange</span> <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$xr</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$xr1</span> <span style="color: #ff3333;">$xr2</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> anymatch <span style="color: black;">&#123;</span>string1 string2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> <span style="color: #008000;">string</span> <span style="color: #ff3333;">$string2</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">lsearch</span> -exact <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: #ff3333;">$string1</span><span style="color: black;">&#93;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: #ff3333;">$string</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_fixtopic <span style="color: black;">&#123;</span>arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>\\\<span style="color: black;">&#123;</span>\<span style="color: black;">&#125;</span>\<span style="color: black;">&#91;</span>\<span style="color: black;">&#93;</span>\<span style="color: #483d8b;">&quot;]} $arg {} &nbsp; arg ; # Bad characters<br />
&nbsp; &nbsp; regsub -all {(<span style="color: #000099; font-weight: bold;">\s</span>)+} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$arg {<span style="color: #000099; font-weight: bold;">\1</span>} arg ; # Double whitespace<br />
&nbsp; &nbsp; regsub -all {^<span style="color: #000099; font-weight: bold;">\s</span>*|<span style="color: #000099; font-weight: bold;">\s</span>*$} &nbsp; &nbsp; &nbsp;$arg {} &nbsp; arg ; # Whitespace at ends<br />
&nbsp; &nbsp; return $arg<br />
}<br />
<br />
proc conv_fixdata {arg output} {<br />
&nbsp; &nbsp; global botnick<br />
&nbsp; &nbsp; if {[string index $output 0] != &quot;</span><span style="color: #808080; font-style: italic;">#&quot;} {</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all -nocase <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output</span><span style="color: #483d8b;">'s} $arg &quot;your&quot; arg<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; regsub -all -nocase {$botnick'</span>s<span style="color: black;">&#125;</span> <span style="color: #ff3333;">$arg</span> <span style="color: #483d8b;">&quot;my&quot;</span> arg<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$arg</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_msg <span style="color: black;">&#123;</span>targets arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> target <span style="color: #ff3333;">$targets</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; puthelp <span style="color: #483d8b;">&quot;PRIVMSG $target :[conv_fixdata $arg $target]&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_fixexpr <span style="color: black;">&#123;</span>exp<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> ib_const<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> exp <span style="color: black;">&#91;</span>conv_fixtopic <span style="color: #ff3333;">$exp</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> i <span style="color: black;">&#91;</span>array names ib_const<span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\%</span>$i&quot;</span> <span style="color: #ff3333;">$exp</span> <span style="color: #ff3333;">$ib_const</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$i</span><span style="color: black;">&#41;</span> exp<br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$exp</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Begin conversion code</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> int2bin <span style="color: black;">&#123;</span>int<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%s.%s.%s.%s&quot;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span>byte2bin <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$int</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">24</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span>byte2bin <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$int</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span>byte2bin <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$int</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span>byte2bin <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$int</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> byte2bin <span style="color: black;">&#123;</span>byte<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> result <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#123;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$i</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">8</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #008000;">incr</span> i<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">append</span> result <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$byte</span> <span style="color: #66cc66;">&amp;</span> <span style="color: #ff4500;">128</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">7</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> byte <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$byte</span> <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$result</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> bin2int <span style="color: black;">&#123;</span>bin<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> result <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#123;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$i</span> <span style="color: #66cc66;">&lt;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> length <span style="color: #ff3333;">$bin</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #008000;">incr</span> i<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> digit <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> index <span style="color: #ff3333;">$bin</span> <span style="color: #ff3333;">$i</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: #ff3333;">$digit</span> == <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> result <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$result</span> <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">1</span> | <span style="color: #ff3333;">$digit</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$digit</span> == <span style="color: #483d8b;">&quot;.&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#ignore</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> result <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$result</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> ip2long <span style="color: black;">&#123;</span>ip<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$ip</span> <span style="color: #483d8b;">&quot;%d.%d.%d.%d&quot;</span> a b c d<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">4</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> i <span style="color: #483d8b;">&quot;$a $b $c $d&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$i</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: #ff3333;">$i</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> long <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$a</span> <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">24</span> | <span style="color: #ff3333;">$b</span> <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">16</span> | <span style="color: #ff3333;">$c</span> <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">8</span> | <span style="color: #ff3333;">$d</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$long</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> long <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> pow<span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">32</span><span style="color: black;">&#41;</span> + <span style="color: #ff3333;">$long</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$long</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> long2ip <span style="color: black;">&#123;</span>long<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%d.%d.%d.%d&quot;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$long</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">24</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$long</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$long</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$long</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> rgb2int <span style="color: black;">&#123;</span>rgb<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$rgb</span> <span style="color: #483d8b;">&quot;%d.%d.%d&quot;</span> red green blue<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">3</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span> <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$red</span> <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">16</span> | <span style="color: #ff3333;">$green</span> <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">8</span> | <span style="color: #ff3333;">$blue</span> <span style="color: #66cc66;">&lt;&lt;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: black;">&#125;</span> \<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span> <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> int2rgb <span style="color: black;">&#123;</span>long<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%d.%d.%d&quot;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$long</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$long</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span> \<br />
&nbsp; &nbsp; <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$long</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&amp;</span> 0xff<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># expr's abs() and int() can't handle large unsigned integers,</span><br />
<span style="color: #808080; font-style: italic;"># these functions are just to get around this</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_int <span style="color: black;">&#123;</span>value<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;.&quot;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_abs <span style="color: black;">&#123;</span>value<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trimleft <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;-&quot;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_absint <span style="color: black;">&#123;</span>value<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span>conv_int <span style="color: black;">&#91;</span>conv_abs <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_units <span style="color: black;">&#123;</span>value type1 type2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> conv_units_exec<br />
&nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all <span style="color: black;">&#123;</span><span style="color: #483d8b;">'} [conv_fixtopic $type1] {} type1<br />
&nbsp; &nbsp; regsub -all {'</span><span style="color: black;">&#125;</span> <span style="color: black;">&#91;</span>conv_fixtopic <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> type2<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #008000;">exec</span> bash -c <span style="color: #483d8b;">&quot;$conv_units_exec '$value $type1' '$type2'&quot;</span><span style="color: black;">&#125;</span> output<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> line <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$output</span> \n<span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">regexp</span> -- <span style="color: black;">&#123;</span>^\s<span style="color: #66cc66;">*</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>^=<span style="color: black;">&#93;</span>+=.+<span style="color: black;">&#41;</span><span style="color: #66cc66;">$</span><span style="color: black;">&#125;</span> <span style="color: #ff3333;">$line</span> tmp result<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$result</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #483d8b;">&quot;unknown response from units command&quot;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_scan <span style="color: black;">&#123;</span>var_formula var_unit index<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> conv_ignore conv_unit<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">upvar</span> <span style="color: #ff4500;">1</span> <span style="color: #ff3333;">$var_formula</span> formula <span style="color: #ff3333;">$var_unit</span> unit<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #008000;">string</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>a-z<span style="color: black;">&#93;</span>+<span style="color: black;">&#40;</span>-<span style="color: black;">&#91;</span>a-z<span style="color: black;">&#93;</span>+<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">regexp</span> -nocase -start <span style="color: #ff3333;">$index</span> -- <span style="color: #ff3333;">$string</span> <span style="color: #ff3333;">$formula</span> a unit<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">lsearch</span> -exact <span style="color: #ff3333;">$conv_ignore</span> <span style="color: #ff3333;">$unit</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Ignore this unit and search for the next unit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">regexp</span> -nocase -start <span style="color: #ff3333;">$index</span> -indices <span style="color: #ff3333;">$string</span> -- <span style="color: #ff3333;">$formula</span> a index<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span>conv_scan <span style="color: #483d8b;">&quot;formula&quot;</span> <span style="color: #483d8b;">&quot;unit&quot;</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$index</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Found unit, return ok</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># No more units found</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># $var will be either unit, misc_from, or misc_to</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv <span style="color: black;">&#123;</span>value unit var lists<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> conv_<span style="color: #ff3333;">$var</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">upvar</span> <span style="color: #ff4500;">1</span> <span style="color: #008000;">list</span> uplist<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> exists uplist<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> uplist <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> type <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$var</span> == <span style="color: #483d8b;">&quot;unit&quot;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: #ff3333;">$var</span> == <span style="color: #483d8b;">&quot;misc_from&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">?</span> <span style="color: #483d8b;">&quot;*&quot;</span> : <span style="color: #483d8b;">&quot;/&quot;</span><span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># First we check full names, then abbreviations</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> <span style="color: #ff7700;font-weight:bold;">method</span> <span style="color: black;">&#123;</span>name abbv<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> <span style="color: #008000;">list</span> <span style="color: #ff3333;">$lists</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Default options</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> option_absint <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> option_metric <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> <span style="color: black;">&#123;</span>name abbv formula<span style="color: black;">&#125;</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> conv_<span style="color: #ff3333;">$var</span>\<span style="color: black;">&#40;</span><span style="color: #ff3333;">$list</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$name</span> == <span style="color: #483d8b;">&quot;option&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> option_<span style="color: #ff3333;">$abbv</span> <span style="color: #ff3333;">$formula</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">regexp</span> -nocase -- <span style="color: #483d8b;">&quot;^([set $method])<span style="color: #000099; font-weight: bold;">\$</span>&quot;</span> <span style="color: #ff3333;">$unit</span> a b prefix<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> uplist <span style="color: #ff3333;">$list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$formula</span><span style="color: black;">&#125;</span> value<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: #ff3333;">$value</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #483d8b;">&quot;evaluating expression for '$unit'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$option_absint</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> value <span style="color: black;">&#91;</span>conv_absint <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$option_metric</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$prefix</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#91;</span>conv_metric <span style="color: #ff3333;">$prefix</span> <span style="color: #ff3333;">$method</span> <span style="color: #ff3333;">$option_metric</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$type</span> <span style="color: #ff3333;">$value</span><span style="color: black;">&#125;</span> value<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #483d8b;">&quot;evaluating metric conversion for '$unit'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #483d8b;">&quot;unknown conversion type '$unit'&quot;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># $method will be either &quot;name&quot; or &quot;abbv&quot;</span><br />
<span style="color: #808080; font-style: italic;"># $option will be either 1 or 2</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> conv_metric <span style="color: black;">&#123;</span>prefix <span style="color: #ff7700;font-weight:bold;">method</span> option<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> conv_metric<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> <span style="color: black;">&#123;</span>name abbv factor<span style="color: black;">&#125;</span> <span style="color: #ff3333;">$conv_metric</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$method</span> == <span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> equal -nocase <span style="color: #ff3333;">$name</span> <span style="color: #ff3333;">$prefix</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$method</span> == <span style="color: #483d8b;">&quot;abbv&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> equal <span style="color: #ff3333;">$abbv</span> <span style="color: #ff3333;">$prefix</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$option</span> == <span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> pow<span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span>, <span style="color: #ff3333;">$factor</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Regular metric</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$option</span> == <span style="color: #ff4500;">2</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> pow<span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, <span style="color: black;">&#40;</span><span style="color: #ff3333;">$factor</span> / <span style="color: #ff4500;">3</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Binary conversion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #483d8b;">&quot;unknown metric prefix&quot;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #808080; font-style: italic;"># End conversion code</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Begin Public binds code</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> msg_conv <span style="color: black;">&#123;</span>nick uhost hand arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> botnick<br />
&nbsp; &nbsp; pub_conv <span style="color: #ff3333;">$nick</span> <span style="color: #ff3333;">$uhost</span> <span style="color: #ff3333;">$hand</span> <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #ff3333;">$arg</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> pub_conv <span style="color: black;">&#123;</span>nick uhost hand chan arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> botnick value <span style="color: #ff7700;font-weight:bold;">global</span> conv_channel_flag<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> conv_units_exec conv_unit conv_misc_from conv_misc_to<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span>isbotnick <span style="color: #ff3333;">$nick</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span>matchattr <span style="color: #ff3333;">$hand</span> +b<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> match <span style="color: #483d8b;">&quot;$chan&quot;</span> <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span>channel get <span style="color: #ff3333;">$chan</span> <span style="color: #ff3333;">$conv_channel_flag</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># If command comes from a channel, and that channel doesn't have +convert then ignore</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> isuser <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>matchattr <span style="color: #ff3333;">$hand</span> - <span style="color: #ff3333;">$chan</span><span style="color: black;">&#93;</span> || <span style="color: black;">&#91;</span>matchattr <span style="color: #ff3333;">$hand</span> -<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Note that $chan might be &quot;&quot;, so we must handle both cases</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>validchan <span style="color: #ff3333;">$chan</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> output1 <span style="color: #ff3333;">$chan</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># The bot sends the text to the channel for users</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> output1 <span style="color: #ff3333;">$nick</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Non-users get privmsg'd</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> last <span style="color: #483d8b;">&quot;&gt;&quot;</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> == -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> output2 <span style="color: #ff3333;">$output1</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># By default, output2 (~stdout~) goes to output1 (~stderr~)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Output has been redirected</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> output2 <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trim <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> range <span style="color: #ff3333;">$arg</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> end<span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> output2 <span style="color: #ff3333;">$output1</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Error (User doesn't have access, or output was &quot;&quot;), so we go back to the default</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> arg <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trim <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> range <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">0</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> - <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> remainder <span style="color: black;">&#91;</span>xrange <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">0</span> end<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$remainder</span> <span style="color: #483d8b;">&quot;%s from %s to %s&quot;</span> value type1 type2<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>anymatch <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$value</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span>from to<span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$remainder</span> <span style="color: #483d8b;">&quot;%s from %s %s&quot;</span> &nbsp; &nbsp;value type1 type2<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>anymatch <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$value</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span>from to<span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$remainder</span> <span style="color: #483d8b;">&quot;%s %s to %s&quot;</span> &nbsp; &nbsp; &nbsp;value type1 type2<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>anymatch <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$value</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span>from to<span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$remainder</span> <span style="color: #483d8b;">&quot;%s %s %s&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; value type1 type2<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>anymatch <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$value</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span>from to<span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> exists value<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>unset value<span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> || <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$remainder</span> <span style="color: #483d8b;">&quot;from %s to %s&quot;</span> &nbsp; &nbsp;type1 type2<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>anymatch <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span>from to<span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$remainder</span> <span style="color: #483d8b;">&quot;from %s %s&quot;</span> &nbsp; &nbsp; &nbsp; type1 type2<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>anymatch <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span>from to<span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$remainder</span> <span style="color: #483d8b;">&quot;%s to %s&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; type1 type2<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>anymatch <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span>from to<span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$remainder</span> <span style="color: #483d8b;">&quot;%s %s&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type1 type2<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>anymatch <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span>from to<span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error parsing sentence&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> exists value<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> value <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span>conv <span style="color: #ff3333;">$value</span> &nbsp; &nbsp; &nbsp; <span style="color: #ff3333;">$type1</span> <span style="color: #483d8b;">&quot;misc_from&quot;</span> <span style="color: black;">&#91;</span>array names conv_misc_from<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> type1_value<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span>conv <span style="color: #ff3333;">$type1_value</span> <span style="color: #ff3333;">$type2</span> <span style="color: #483d8b;">&quot;misc_to&quot;</span> &nbsp; <span style="color: #ff3333;">$list</span><span style="color: black;">&#125;</span> type2_value<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error $type2_value&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;$value $type1 = $type2_value $type2&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$conv_units_exec</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span>conv_units <span style="color: #ff3333;">$value</span> <span style="color: #ff3333;">$type1</span> <span style="color: #ff3333;">$type2</span><span style="color: black;">&#125;</span> output<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output2</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> type1_formula <span style="color: #ff3333;">$type1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> type2_formula <span style="color: #ff3333;">$type2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> found <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>conv_scan <span style="color: #483d8b;">&quot;type1_formula&quot;</span> <span style="color: #483d8b;">&quot;type1_unit&quot;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span>conv_scan <span style="color: #483d8b;">&quot;type2_formula&quot;</span> <span style="color: #483d8b;">&quot;type2_unit&quot;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error unmatched type '$type1_unit'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span>conv <span style="color: #ff4500;">1</span> <span style="color: #ff3333;">$type1_unit</span> <span style="color: #483d8b;">&quot;unit&quot;</span> <span style="color: black;">&#91;</span>array names conv_unit<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> type1_value<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error $type1_value&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">regsub</span> -nocase <span style="color: #ff3333;">$type1_unit</span> <span style="color: #ff3333;">$type1_formula</span> <span style="color: #ff3333;">$type1_value</span> type1_formula<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error decompiling expression '$type1_unit'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span>conv <span style="color: #ff4500;">1</span> <span style="color: #ff3333;">$type2_unit</span> <span style="color: #483d8b;">&quot;unit&quot;</span> <span style="color: #ff3333;">$list</span><span style="color: black;">&#125;</span> type2_value<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error $type2_value&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">regsub</span> -nocase <span style="color: #ff3333;">$type2_unit</span> <span style="color: #ff3333;">$type2_formula</span> <span style="color: #ff3333;">$type2_value</span> type2_formula<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error decompiling expression '$type2_unit'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> found<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">continue</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>conv_scan <span style="color: #483d8b;">&quot;type2_formula&quot;</span> <span style="color: #483d8b;">&quot;type2_unit&quot;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error unmatched type '$type2_unit'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">break</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># At the end, so stop</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># We got an error somewhere, bail out</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$found</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error no conversion types found&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#91;</span>conv_fixexpr <span style="color: #483d8b;">&quot;($value) * ($type1_formula) / ($type2_formula)&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> value2<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error evaluating expression&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conv_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;$value $type1 = $value2 $type2&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #808080; font-style: italic;"># End Public binds code</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Init stuff</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #008000;">package</span> require Tcl <span style="color: #ff4500;">8.3</span><span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">error</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; putlog <span style="color: #483d8b;">&quot;error TCL v8.3 or higher is required to run this script&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><br />
<span style="color: black;">&#125;</span><br />
<br />
putlog <span style="color: #483d8b;">&quot;*** LOADED: convert.tcl&quot;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://briped.net/2007/06/20/converttcl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>faq.tcl</title>
		<link>http://briped.net/2007/06/20/faqtcl/</link>
		<comments>http://briped.net/2007/06/20/faqtcl/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 09:21:28 +0000</pubDate>
		<dc:creator>Brian Schmidt Pedersen</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[TCL]]></category>
		<category><![CDATA[Eggdrop]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://briped.net/2007/06/20/faqtcl/</guid>
		<description><![CDATA[#### faq.tcl v1.0.0 ############################################################ ################################################################################ ## Written by: &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;## ## &#160; KuNgFo0 &#160;(http://www.eggfaq.com/). &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container tcl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="tcl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#### faq.tcl v1.0.0 ############################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## Written by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; KuNgFo0 &nbsp;(http://www.eggfaq.com/). &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Modified by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; Brian Schmidt aka. brianMan. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;">#### Readme / Help #############################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## This script is ripped from KuNgFoO's ib.tcl v3.19 (infobot) script. &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;">#### Changelog #################################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## v1.0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## + Initial release. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## + Added the possibility to control which channels could use the commands &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; with a channel flag. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## * Applied a dirty hack to solve a minor redirection bug, which caused all &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; add/append/remove commands that contained a &gt; to break the script. &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set next line as the directory where the database files are</span><br />
<span style="color: #808080; font-style: italic;"># located (no other files should be in the same dir)</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_dir <span style="color: #483d8b;">&quot;data/&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as the default database to save changes to</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_database <span style="color: #483d8b;">&quot;FooBot.dat&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># What should the channel flag be, to enable the FAQ for that channel?</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_channel_flag <span style="color: #483d8b;">&quot;faq&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># The default value should be ok for the next two:</span><br />
<span style="color: #808080; font-style: italic;"># Set the next line as the format to display time in (without timezone)</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_format_notz <span style="color: #483d8b;">&quot;%H:%M:%S - %A, %B %d, %Y&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as the format to display time in (with timezone)</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_format <span style="color: #483d8b;">&quot;$faq_format_notz %Z&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as the maxinum number of matches to</span><br />
<span style="color: #808080; font-style: italic;"># return on searches</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_max <span style="color: #ff4500;">5</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as the maxinum number of lines to</span><br />
<span style="color: #808080; font-style: italic;"># return publicly</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_max_lines <span style="color: #ff4500;">3</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as the flag required to add/remove</span><br />
<span style="color: #808080; font-style: italic;"># questions and etc</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_flag <span style="color: #483d8b;">&quot;+f&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as how often to save changes to the database</span><br />
<span style="color: #808080; font-style: italic;"># (in minutes)</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> faq_time <span style="color: #ff4500;">10</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> xrange <span style="color: black;">&#123;</span>xr xr1 xr2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">join</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lrange</span> <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$xr</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$xr1</span> <span style="color: #ff3333;">$xr2</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> xindex <span style="color: black;">&#123;</span>xr xr1<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">join</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lrange</span> <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$xr</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$xr1</span> <span style="color: #ff3333;">$xr1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> validnum <span style="color: black;">&#123;</span>num<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#91;</span><span style="color: #008000;">scan</span> <span style="color: #ff3333;">$num</span> <span style="color: #483d8b;">&quot;%f%s&quot;</span> a b<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> anymatch <span style="color: black;">&#123;</span>string1 string2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> <span style="color: #008000;">string</span> <span style="color: #ff3333;">$string2</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">lsearch</span> -exact <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: #ff3333;">$string1</span><span style="color: black;">&#93;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: #ff3333;">$string</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> parseurl <span style="color: black;">&#123;</span>url<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> var <span style="color: black;">&#123;</span>protocol user pass server port path cgiargs anchor<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span> <span style="color: #ff7700;font-weight:bold;">upvar</span> <span style="color: #ff4500;">1</span> <span style="color: #ff3333;">$var</span> <span style="color: #ff3333;">$var</span> <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">regexp</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>^:<span style="color: black;">&#93;</span>+<span style="color: black;">&#41;</span>://<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>^:<span style="color: black;">&#93;</span>+<span style="color: black;">&#41;</span>:<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>^@<span style="color: black;">&#93;</span>+<span style="color: black;">&#41;</span>@<span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>^:/\<span style="color: #66cc66;">?</span><span style="color: #808080; font-style: italic;">#]+)(:([0-9]+))?(/([^\?#]+))?(\?([^#]+))?(#(.*))?} $url a b protocol c user pass server d port e path f cgiargs g anchor]} {</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$protocol</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> protocol <span style="color: #483d8b;">&quot;http&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span>validnum <span style="color: #ff3333;">$port</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> port <span style="color: #ff4500;">80</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Begin Database code</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_fixtopic <span style="color: black;">&#123;</span>arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>\\\<span style="color: black;">&#123;</span>\<span style="color: black;">&#125;</span>\<span style="color: black;">&#91;</span>\<span style="color: black;">&#93;</span>\<span style="color: #483d8b;">&quot;]} $arg {} &nbsp; arg ; # Bad characters<br />
&nbsp; &nbsp; regsub -all {(<span style="color: #000099; font-weight: bold;">\s</span>)+} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$arg {<span style="color: #000099; font-weight: bold;">\1</span>} arg ; # Double whitespace<br />
&nbsp; &nbsp; regsub -all {^<span style="color: #000099; font-weight: bold;">\s</span>*|<span style="color: #000099; font-weight: bold;">\s</span>*$} &nbsp; &nbsp; &nbsp;$arg {} &nbsp; arg ; # Whitespace at ends<br />
&nbsp; &nbsp; return $arg<br />
}<br />
<br />
proc faq_fixdb {arg} {<br />
&nbsp; &nbsp; global faq_databases<br />
&nbsp; &nbsp; if {[set i [lsearch -exact [string tolower $faq_databases] [string tolower $arg]]] == -1} {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return &quot;</span><span style="color: #ff7700;font-weight:bold;">error</span> no such database <span style="color: #483d8b;">'$arg'</span> loaded<span style="color: #483d8b;">&quot;<br />
&nbsp; &nbsp; } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return [lindex $faq_databases $i]<br />
&nbsp; &nbsp; }<br />
}<br />
<br />
proc faq_fixdata {arg output} {<br />
&nbsp; &nbsp; global botnick<br />
&nbsp; &nbsp; if {[string index $output 0] != &quot;</span><span style="color: #808080; font-style: italic;">#&quot;} {</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all -nocase <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output</span><span style="color: #483d8b;">'s} $arg &quot;your&quot; arg<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; regsub -all -nocase {$botnick'</span>s<span style="color: black;">&#125;</span> <span style="color: #ff3333;">$arg</span> <span style="color: #483d8b;">&quot;my&quot;</span> arg<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$arg</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_msg <span style="color: black;">&#123;</span>targets arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> target <span style="color: #ff3333;">$targets</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; puthelp <span style="color: #483d8b;">&quot;PRIVMSG $target :[faq_fixdata $arg $target]&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_check <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_dir<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">file</span> exists <span style="color: #ff3333;">$faq_dir</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error $faq_dir does not exist&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">file</span> isdirectory <span style="color: #ff3333;">$faq_dir</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error $faq_dir is not a directory&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">file</span> readable <span style="color: #ff3333;">$faq_dir</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error $faq_dir is unreadable&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">file</span> writable <span style="color: #ff3333;">$faq_dir</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error $faq_dir is unwritable&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;&quot;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_loadall <span style="color: black;">&#123;</span>output1 output2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_dir faq_databases<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Unset current databases first</span><br />
&nbsp; &nbsp; faq_unloadall<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_check<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output1</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putlog <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> <span style="color: #008000;">file</span> <span style="color: black;">&#91;</span><span style="color: #008000;">glob</span> -nocomplain <span style="color: black;">&#91;</span><span style="color: #008000;">file</span> <span style="color: #008000;">join</span> <span style="color: #ff3333;">$faq_dir</span> <span style="color: #66cc66;">*</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">file</span> isfile <span style="color: #ff3333;">$file</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> output <span style="color: black;">&#91;</span>faq_load <span style="color: black;">&#91;</span><span style="color: #008000;">file</span> tail <span style="color: #ff3333;">$file</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output1</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putlog <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output2</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putlog <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_load <span style="color: black;">&#123;</span>database<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_dir faq_databases faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #008000;">file</span> <span style="color: black;">&#91;</span><span style="color: #008000;">file</span> <span style="color: #008000;">join</span> <span style="color: #ff3333;">$faq_dir</span> <span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; faq_unload <span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> match <span style="color: #66cc66;">*</span>..<span style="color: #66cc66;">*</span> <span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> index <span style="color: #ff3333;">$database</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;/&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error invalid database name '$database'&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">file</span> exists <span style="color: #ff3333;">$file</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error database '$database' does not exist&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">file</span> isfile <span style="color: #ff3333;">$file</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error database '$database' is not a valid file&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #008000;">open</span> <span style="color: #ff3333;">$file</span> r<span style="color: black;">&#125;</span> fileid<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error could not read database '$database'&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span>array <span style="color: #ff7700;font-weight:bold;">set</span> faq_data_<span style="color: #ff3333;">$database</span> <span style="color: black;">&#91;</span><span style="color: #008000;">read</span> <span style="color: #ff3333;">$fileid</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error could not parse database '$database'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">close</span> <span style="color: #ff3333;">$fileid</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">lappend</span> faq_databases <span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;read database '$database'&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_unloadall <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_databases<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> exists faq_databases<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> database <span style="color: #ff3333;">$faq_databases</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_unload <span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> faq_databases <span style="color: #483d8b;">&quot;&quot;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_unload <span style="color: black;">&#123;</span>database<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_databases faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>array exists faq_data_<span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; array unset faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: black;">&#91;</span><span style="color: #008000;">lsearch</span> -exact <span style="color: #ff3333;">$faq_databases</span> <span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> faq_databases <span style="color: black;">&#91;</span><span style="color: #008000;">lreplace</span> <span style="color: #ff3333;">$faq_databases</span> <span style="color: #ff3333;">$i</span> <span style="color: #ff3333;">$i</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_saveall <span style="color: black;">&#123;</span>output1 output2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_databases faq_save<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> output <span style="color: black;">&#91;</span>faq_check<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output1</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putlog <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> database <span style="color: #ff3333;">$faq_databases</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> output <span style="color: black;">&#91;</span>faq_save <span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output1</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putlog <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$output2</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putlog <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> faq_save <span style="color: #ff3333;">$error</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_save <span style="color: black;">&#123;</span>database<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_dir faq_databases faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #008000;">open</span> <span style="color: black;">&#91;</span><span style="color: #008000;">file</span> <span style="color: #008000;">join</span> <span style="color: #ff3333;">$faq_dir</span> <span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span> w<span style="color: black;">&#125;</span> fileid<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error could not write database 'database'&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">puts</span> <span style="color: #ff3333;">$fileid</span> <span style="color: black;">&#91;</span>array get faq_data_<span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">close</span> <span style="color: #ff3333;">$fileid</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;wrote database '$database'&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_needsave <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_save<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> faq_save <span style="color: #ff4500;">1</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> time_faq <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_time faq_save<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$faq_save</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; faq_saveall <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> match <span style="color: #66cc66;">*</span>time_faq<span style="color: #66cc66;">*</span> <span style="color: black;">&#91;</span>timers<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; timer <span style="color: #ff3333;">$faq_time</span> time_faq<br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_topics <span style="color: black;">&#123;</span>arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> topics <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> arg &nbsp; &nbsp;<span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trimright <span style="color: #ff3333;">$arg</span> <span style="color: #483d8b;">&quot;?! &quot;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> length <span style="color: black;">&#91;</span><span style="color: #008000;">llength</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#123;</span><span style="color: #ff7700;font-weight:bold;">set</span> l <span style="color: #ff3333;">$length</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$l</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #008000;">incr</span> l -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#123;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$length</span> - <span style="color: #ff3333;">$l</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$i</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #008000;">incr</span> i -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">lsearch</span> -exact <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: #ff3333;">$topics</span><span style="color: black;">&#93;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> topic <span style="color: black;">&#91;</span><span style="color: #008000;">lrange</span> <span style="color: #ff3333;">$arg</span> <span style="color: #ff3333;">$i</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> + <span style="color: #ff3333;">$l</span> - <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> == -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">lappend</span> topics <span style="color: #ff3333;">$topic</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$topics</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># {&quot;topic 1&quot; &quot;topic 2&quot; ...} -&gt; faq_find -&gt; {&quot;database&quot; &quot;first topic found&quot;}</span><br />
<span style="color: #808080; font-style: italic;"># note: databases are not checked for validity</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_find <span style="color: black;">&#123;</span>topics<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_databases<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> topic <span style="color: #ff3333;">$topics</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> topic <span style="color: black;">&#91;</span>faq_fixtopic <span style="color: #ff3333;">$topic</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> database <span style="color: #ff3333;">$faq_databases</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> topic2 <span style="color: black;">&#91;</span>faq_exists <span style="color: #ff3333;">$topic</span> <span style="color: #ff3333;">$database</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$database</span> <span style="color: #ff3333;">$topic2</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># &quot;*topic string*&quot; -&gt; faq_find2 -&gt; { {&quot;database&quot; &quot;topic found 1&quot;} {&quot;database&quot; &quot;topic found 2&quot;} ... }</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_find2 <span style="color: black;">&#123;</span>topic<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_databases<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> topic &nbsp;<span style="color: black;">&#91;</span>faq_fixtopic <span style="color: #ff3333;">$topic</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> topics <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> database <span style="color: #ff3333;">$faq_databases</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># [array names faq_data_$database -glob *topic*] would be really nice here, but it has no -nocase option!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> topic2 <span style="color: black;">&#91;</span>array names faq_data_<span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> match -nocase <span style="color: #66cc66;">*</span><span style="color: #ff3333;">$topic</span><span style="color: #66cc66;">*</span> <span style="color: #ff3333;">$topic2</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">lappend</span> topics <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$database</span> <span style="color: #ff3333;">$topic2</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$topics</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_parsetopic <span style="color: black;">&#123;</span>arg var1 var2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> <span style="color: #ff3333;">$var1</span> <span style="color: #ff3333;">$var2</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> i &nbsp; &nbsp; <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> first <span style="color: #483d8b;">&quot;=&quot;</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var1</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trim <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> range <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">0</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> - <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var2</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trim <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> range <span style="color: #ff3333;">$arg</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> end<span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#123;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$i</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #ff4500;">2</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><span style="color: #008000;">incr</span> i<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> match <span style="color: #483d8b;">&quot;topic*&quot;</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> topic_var <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> var<span style="color: #ff3333;">$i</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># if this is a topic, we look for a database too</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> database_var <span style="color: #483d8b;">&quot;database[string range $topic_var 5 end]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_parsedb <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$topic_var</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$topic_var</span> <span style="color: #ff3333;">$database_var</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># we got an error parsing the db</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var1</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var2</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: #ff3333;">$i</span> == -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error parsing sentence&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_parsedb <span style="color: black;">&#123;</span>arg var1 var2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_database <span style="color: #ff3333;">$var1</span> <span style="color: #ff3333;">$var2</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> last <span style="color: #483d8b;">&quot;|&quot;</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var1</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trim <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> range <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">0</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> - <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var2</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trim <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> range <span style="color: #ff3333;">$arg</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> end<span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> tmp <span style="color: black;">&#91;</span>faq_find <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var2</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$tmp</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># we go with the db that this topic is already stored in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var2</span> <span style="color: #ff3333;">$faq_database</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># we go w/ default db</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var1</span> <span style="color: black;">&#91;</span>faq_fixtopic <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var2</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error parsing sentence&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var2</span> <span style="color: black;">&#91;</span>faq_fixdb <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff3333;">$var2</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># this may return an error</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># type = 0, returns 1/0 ; type = 1, returns proper case (or error), for use with existing topics ;</span><br />
<span style="color: #808080; font-style: italic;"># type = 2, returns proper case (or original topic), for use with creating new topics</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_exists <span style="color: black;">&#123;</span>topic database type<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: black;">&#91;</span><span style="color: #008000;">lsearch</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: black;">&#91;</span>array names faq_data_<span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: #ff3333;">$topic</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$type</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: black;">&#91;</span>array names faq_data_<span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$i</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$type</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$type</span> == <span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error topic '$topic' does not exist in database '$database'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$topic</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_write <span style="color: black;">&#123;</span>topic database type arg host<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> topic <span style="color: black;">&#91;</span>faq_exists <span style="color: #ff3333;">$topic</span> <span style="color: #ff3333;">$database</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$type</span> == <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> faq_data_<span style="color: #66cc66;">$</span><span style="color: black;">&#123;</span>database<span style="color: black;">&#125;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$topic</span><span style="color: black;">&#41;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$type</span> == <span style="color: #483d8b;">&quot;a&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">lappend</span> faq_data_<span style="color: #66cc66;">$</span><span style="color: black;">&#123;</span>database<span style="color: black;">&#125;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$topic</span><span style="color: black;">&#41;</span> <span style="color: #ff3333;">$arg</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">lappend</span> faq_data_<span style="color: #66cc66;">$</span><span style="color: black;">&#123;</span>database<span style="color: black;">&#125;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$topic</span><span style="color: black;">&#41;</span> <span style="color: #483d8b;">&quot;#WHOSET $host [clock seconds]&quot;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_read <span style="color: black;">&#123;</span>topic database<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> database <span style="color: black;">&#91;</span>faq_fixdb <span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> topic <span style="color: black;">&#91;</span>faq_exists <span style="color: #ff3333;">$topic</span> <span style="color: #ff3333;">$database</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$topic</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> faq_data_<span style="color: #66cc66;">$</span><span style="color: black;">&#123;</span>database<span style="color: black;">&#125;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$topic</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_copy <span style="color: black;">&#123;</span>topic1 database1 topic2 database2<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_data_<span style="color: #ff3333;">$database1</span> faq_data_<span style="color: #ff3333;">$database2</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>faq_exists <span style="color: #ff3333;">$topic2</span> <span style="color: #ff3333;">$database2</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;error topic '$topic2' already exists in database '$database2'&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> output <span style="color: black;">&#91;</span>faq_read <span style="color: #ff3333;">$topic1</span> <span style="color: #ff3333;">$database1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> faq_data_<span style="color: #66cc66;">$</span><span style="color: black;">&#123;</span>database2<span style="color: black;">&#125;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$topic2</span><span style="color: black;">&#41;</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_remove <span style="color: black;">&#123;</span>topic database<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> topic <span style="color: black;">&#91;</span>faq_exists <span style="color: #ff3333;">$topic</span> <span style="color: #ff3333;">$database</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$topic</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; unset faq_data_<span style="color: #66cc66;">$</span><span style="color: black;">&#123;</span>database<span style="color: black;">&#125;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$topic</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_disp <span style="color: black;">&#123;</span>arg database output1 output2 depth num option nick<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_max_lines<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$depth</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">3</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error recursion too deep&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> -<span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> found <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$database</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #008000;">list</span> <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #ff3333;">$database</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># we have an exact topic/db to display</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #008000;">list</span> <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: black;">&#91;</span>faq_find <span style="color: black;">&#91;</span>faq_topics <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># find topic/db (s)</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># note: the $list vars above needed to be padded with { } - hence the [list] 's</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> tmp <span style="color: #ff3333;">$list</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$tmp</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">continue</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$depth</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> num <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> output <span style="color: black;">&#91;</span>faq_read <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> topic <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$tmp</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> database <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$tmp</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> line <span style="color: #ff3333;">$output</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$line</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;#WHOSET&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#ignore</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;#LINK&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> temp <span style="color: black;">&#91;</span>faq_disp <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output2</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$depth</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #ff3333;">$num</span> <span style="color: #ff4500;">0</span> <span style="color: #ff3333;">$nick</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> num <span style="color: #ff3333;">$temp</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;.&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: black;">&#91;</span>xrange <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">1</span> end<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> num<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$num</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;$topic - $line&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> num<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;... $line&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> num<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$num</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error '$topic' exists, but is empty&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> equal -nocase <span style="color: #ff3333;">$output2</span> <span style="color: #ff3333;">$output1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$depth</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;(sent by $output1)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;sent '$topic' to $output2&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> found<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$found</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$depth</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error invalid link to '$arg'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$num</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #808080; font-style: italic;"># End Database code</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Begin 'calc' code</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_fixexpr <span style="color: black;">&#123;</span>exp<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_const<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> exp <span style="color: black;">&#91;</span>faq_fixtopic <span style="color: #ff3333;">$exp</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> i <span style="color: black;">&#91;</span>array names faq_const<span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">regsub</span> -all <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\%</span>$i&quot;</span> <span style="color: #ff3333;">$exp</span> <span style="color: #ff3333;">$faq_const</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$i</span><span style="color: black;">&#41;</span> exp<br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff3333;">$exp</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #808080; font-style: italic;"># End 'calc' code</span><br />
<br />
<span style="color: #808080; font-style: italic;"># expr's abs() and int() can't handle large unsigned integers,</span><br />
<span style="color: #808080; font-style: italic;"># these functions are just to get around this</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_int <span style="color: black;">&#123;</span>value<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;.&quot;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_abs <span style="color: black;">&#123;</span>value<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trimleft <span style="color: #ff3333;">$value</span> <span style="color: #483d8b;">&quot;-&quot;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> faq_absint <span style="color: black;">&#123;</span>value<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span>faq_int <span style="color: black;">&#91;</span>faq_abs <span style="color: #ff3333;">$value</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Begin Public binds code</span><br />
<span style="color: #ff7700;font-weight:bold;">proc</span> msg_faq <span style="color: black;">&#123;</span>nick uhost hand arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; pub_faq <span style="color: #ff3333;">$nick</span> <span style="color: #ff3333;">$uhost</span> <span style="color: #ff3333;">$hand</span> <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #ff3333;">$arg</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> pub_faq <span style="color: black;">&#123;</span>nick uhost hand chan arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> botnick faq_dir faq_format faq_max faq_flag faq_database faq_databases faq_channel_flag<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> topic topic1 topic2 database database1 database2 value<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span>isbotnick <span style="color: #ff3333;">$nick</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span>matchattr <span style="color: #ff3333;">$hand</span> +b<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff3333;">$chan</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>channel get <span style="color: #ff3333;">$chan</span> <span style="color: #ff3333;">$faq_channel_flag</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: #ff3333;">$chan</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> match -nocase <span style="color: #ff3333;">$botnick</span><span style="color: #66cc66;">*</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> arg <span style="color: black;">&#91;</span>xrange <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">1</span> end<span style="color: black;">&#93;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Only answer channel messages that begin with the bot's nick</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$chan</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Answer all privmsgs</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Msg isn't for us, bail out</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> isuser <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>matchattr <span style="color: #ff3333;">$hand</span> <span style="color: #ff3333;">$faq_flag</span>|<span style="color: #ff3333;">$faq_flag</span> <span style="color: #ff3333;">$chan</span><span style="color: black;">&#93;</span> || <span style="color: black;">&#91;</span>matchattr <span style="color: #ff3333;">$hand</span> <span style="color: #ff3333;">$faq_flag</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Note that $chan might be &quot;&quot;, so we must handle both cases</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>validchan <span style="color: #ff3333;">$chan</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> output1 <span style="color: #ff3333;">$chan</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># The bot sends the text to the channel for users</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> output1 <span style="color: #ff3333;">$nick</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Non-users get privmsg'd</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> output2 <span style="color: #ff3333;">$output1</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># By default, output2 (~stdout~) goes to output1 (~stderr~)</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">lsearch</span> -exact <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #483d8b;">&quot;shutup stop sh database db set learn add unset forget delete del remove rem rm erase append addon link join copy cp move mv rename ren&quot;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: black;">&#91;</span>xindex <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> == -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> last <span style="color: #483d8b;">&quot;&gt;&quot;</span> <span style="color: #ff3333;">$arg</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Output has been redirected</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> output2 <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trim <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> range <span style="color: #ff3333;">$arg</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> end<span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> output2 <span style="color: #ff3333;">$output1</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># Error (User doesn't have access, or output was &quot;&quot;), so we go back to the default</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> arg <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> trim <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> range <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">0</span> <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$i</span> - <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> command &nbsp; <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: black;">&#91;</span>xindex <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> remainder <span style="color: black;">&#91;</span>xrange <span style="color: #ff3333;">$arg</span> <span style="color: #ff4500;">1</span> end<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">switch</span> -- <span style="color: #ff3333;">$command</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;shutup&quot;</span> - <span style="color: #483d8b;">&quot;stop&quot;</span> - <span style="color: #483d8b;">&quot;sh&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>clearqueue help<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;OK, sorry&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;But I'm not saying anything!&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;database&quot;</span> - <span style="color: #483d8b;">&quot;db&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">switch</span> -- <span style="color: black;">&#91;</span><span style="color: #008000;">string</span> tolower <span style="color: black;">&#91;</span>xindex <span style="color: #ff3333;">$remainder</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;reload&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_loadall <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;save&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_saveall <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;list&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;Loaded database(s):&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> database <span style="color: #ff3333;">$faq_databases</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> faq_data_<span style="color: #ff3333;">$database</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: black;">&#91;</span><span style="color: #008000;">format</span> <span style="color: #483d8b;">&quot;%s %-15s %s&quot;</span> <span style="color: #ff3333;">$i</span>. <span style="color: #ff3333;">$database</span> <span style="color: #808080; font-style: italic;">#[array size faq_data_$database]]</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;end&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">default</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error must be one of 'reload', 'save' , or 'list'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;set&quot;</span> - <span style="color: #483d8b;">&quot;learn&quot;</span> - <span style="color: #483d8b;">&quot;add&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_parsetopic <span style="color: #ff3333;">$remainder</span> topic value<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span> || \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_write <span style="color: #ff3333;">$topic</span> <span style="color: #ff3333;">$database</span> <span style="color: #483d8b;">&quot;w&quot;</span> <span style="color: #ff3333;">$value</span> <span style="color: #ff3333;">$nick</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$uhost</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;Set '$topic' in database '$database'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_needsave<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;unset&quot;</span> - <span style="color: #483d8b;">&quot;forget&quot;</span> - <span style="color: #483d8b;">&quot;delete&quot;</span> - <span style="color: #483d8b;">&quot;del&quot;</span> - <span style="color: #483d8b;">&quot;remove&quot;</span> - <span style="color: #483d8b;">&quot;rem&quot;</span> - <span style="color: #483d8b;">&quot;rm&quot;</span> - <span style="color: #483d8b;">&quot;erase&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_parsetopic <span style="color: #483d8b;">&quot;$remainder = null&quot;</span> topic value<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span> || \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_remove <span style="color: #ff3333;">$topic</span> <span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;Unset '$topic' in database '$database'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_needsave<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;append&quot;</span> - <span style="color: #483d8b;">&quot;addon&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_parsetopic <span style="color: #ff3333;">$remainder</span> topic value<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span> || \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_write <span style="color: #ff3333;">$topic</span> <span style="color: #ff3333;">$database</span> <span style="color: #483d8b;">&quot;a&quot;</span> <span style="color: #ff3333;">$value</span> <span style="color: #ff3333;">$nick</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$uhost</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;Appended to '$topic' in database '$database'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_needsave<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;link&quot;</span> - <span style="color: #483d8b;">&quot;join&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_parsetopic <span style="color: #ff3333;">$remainder</span> topic1 topic2<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> topic2 <span style="color: black;">&#91;</span>faq_exists <span style="color: #ff3333;">$topic2</span> <span style="color: #ff3333;">$database2</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$topic2</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># check if 2nd topic exists, get proper casing too (so $topic2 not $error is used)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_write <span style="color: #ff3333;">$topic1</span> <span style="color: #ff3333;">$database1</span> <span style="color: #483d8b;">&quot;a&quot;</span> <span style="color: black;">&#91;</span><span style="color: #008000;">list</span> <span style="color: #808080; font-style: italic;">#LINK $topic2 $database2] $nick!$uhost]] 0] == &quot;error&quot;} {</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;Linked '$topic1' ($database1) to '$topic2' ($database2)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_needsave<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;copy&quot;</span> - <span style="color: #483d8b;">&quot;cp&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_parsetopic <span style="color: #ff3333;">$remainder</span> topic1 topic2<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span> || \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_copy <span style="color: #ff3333;">$topic1</span> <span style="color: #ff3333;">$database1</span> <span style="color: #ff3333;">$topic2</span> <span style="color: #ff3333;">$database2</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;Copied '$topic1' ($database1) to '$topic2' ($database2)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_needsave<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;move&quot;</span> - <span style="color: #483d8b;">&quot;mv&quot;</span> - <span style="color: #483d8b;">&quot;rename&quot;</span> - <span style="color: #483d8b;">&quot;ren&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$isuser</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_parsetopic <span style="color: #ff3333;">$remainder</span> topic1 topic2<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span> || \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_copy <span style="color: #ff3333;">$topic1</span> <span style="color: #ff3333;">$database1</span> <span style="color: #ff3333;">$topic2</span> <span style="color: #ff3333;">$database2</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span> || \<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_remove <span style="color: #ff3333;">$topic1</span> <span style="color: #ff3333;">$database1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;Renamed '$topic1' ($database1) to '$topic2' ($database2)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_needsave<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;list&quot;</span> - <span style="color: #483d8b;">&quot;find&quot;</span> - <span style="color: #483d8b;">&quot;search&quot;</span> - <span style="color: #483d8b;">&quot;locate&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> topics <span style="color: black;">&#91;</span>faq_find2 <span style="color: #ff3333;">$remainder</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">switch</span> -- <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> found <span style="color: black;">&#91;</span><span style="color: #008000;">llength</span> <span style="color: #ff3333;">$topics</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff4500;">0</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;Found no matches to '$remainder'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff4500;">1</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_disp <span style="color: black;">&#91;</span><span style="color: #008000;">join</span> <span style="color: #ff3333;">$topics</span><span style="color: black;">&#93;</span> <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output2</span> <span style="color: #ff4500;">0</span> <span style="color: #ff4500;">0</span> <span style="color: #ff4500;">0</span> <span style="color: #ff3333;">$nick</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">default</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;Found $found matches to '$remainder'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> i <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> topic <span style="color: #ff3333;">$topics</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;$i. [lindex $topic 1]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$i</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff3333;">$faq_max</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">break</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;end&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;whoset&quot;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> <span style="color: #ff7700;font-weight:bold;">error</span> <span style="color: black;">&#91;</span>faq_parsetopic <span style="color: #483d8b;">&quot;$remainder = null&quot;</span> topic value<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> output <span style="color: black;">&#91;</span>faq_read <span style="color: #ff3333;">$topic</span> <span style="color: #ff3333;">$database</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;error&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> found <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> line <span style="color: #ff3333;">$output</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span>xindex <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;#WHOSET&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$found</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;'$topic' (database $database) set by [xindex $line 1] on [clock format [xindex $line 2] -format $faq_format]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">incr</span> found<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output2</span> <span style="color: #483d8b;">&quot;... modified by [xindex $line 1] on [clock format [xindex $line 2] -format $faq_format]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: #ff3333;">$found</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_msg <span style="color: #ff3333;">$output1</span> <span style="color: #483d8b;">&quot;error could not find who set topic '$topic'&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">default</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; faq_disp <span style="color: #ff3333;">$arg</span> <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #ff3333;">$output1</span> <span style="color: #ff3333;">$output2</span> <span style="color: #ff4500;">0</span> <span style="color: #ff4500;">0</span> <span style="color: #ff4500;">1</span> <span style="color: #ff3333;">$nick</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #808080; font-style: italic;"># End Public binds code</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Init stuff</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #008000;">package</span> require Tcl <span style="color: #ff4500;">8.3</span><span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">error</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; putlog <span style="color: #483d8b;">&quot;error TCL v8.3 or higher is required to run this script&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><br />
<span style="color: black;">&#125;</span><br />
putlog <span style="color: #483d8b;">&quot;*** LOADED: faq.tcl&quot;</span><br />
<br />
bind pubm - <span style="color: #66cc66;">*</span> pub_faq<br />
bind msgm - <span style="color: #66cc66;">*</span> msg_faq<br />
setudef flag <span style="color: #ff3333;">$faq_channel_flag</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> exists faq_load<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; faq_loadall <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #483d8b;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> faq_load <span style="color: #ff4500;">1</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> exists faq_save<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> faq_save <span style="color: #ff4500;">0</span><br />
<span style="color: black;">&#125;</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> match <span style="color: #66cc66;">*</span>time_faq<span style="color: #66cc66;">*</span> <span style="color: black;">&#91;</span>timers<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; timer <span style="color: #ff3333;">$faq_time</span> time_faq<br />
<span style="color: black;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://briped.net/2007/06/20/faqtcl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nslookup.tcl</title>
		<link>http://briped.net/2007/06/20/nslookuptcl/</link>
		<comments>http://briped.net/2007/06/20/nslookuptcl/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 09:20:16 +0000</pubDate>
		<dc:creator>Brian Schmidt Pedersen</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[TCL]]></category>
		<category><![CDATA[Eggdrop]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://briped.net/2007/06/20/nslookuptcl/</guid>
		<description><![CDATA[#### nslookup.tcl v1.0.1 ####################################################### ################################################################################ ## Written by: &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;## ## &#160; KuNgFo0 &#160;(http://www.eggfaq.com/). &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container tcl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="tcl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#### nslookup.tcl v1.0.1 #######################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## Written by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; KuNgFo0 &nbsp;(http://www.eggfaq.com/). &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Modified by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; Brian Schmidt aka. brianMan. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;">#### Readme / Help #############################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## This is a slightly modified version of KuNgFoO's nslookup.tcl v0.5 script. ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Script that can do nslookups. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Usage: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; To have the .dns command available on a channel you need to set the &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; channel flag +nslookups from the console/partyline . &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; ``.chanset #channel +nslookups´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Channel Commands (available only if channel is +nslookups): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; .dns [ host|ip|nick[ host|ip|nick][ ...]] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## Example: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; ``.dns www.eggfaq.com´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;">#### Changelog #################################################################</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<span style="color: #808080; font-style: italic;">## v1.0.1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## * Minor code cleanup &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">## v1.0.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## + Initial release. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## + Added the possibility to control which channels could use the commands &nbsp; ##</span><br />
<span style="color: #808080; font-style: italic;">## &nbsp; with the channel flag ``+/-nslookup´´ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;##</span><br />
<span style="color: #808080; font-style: italic;">################################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set then next line as the command you want to initate the nslookup</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> nslookup_command <span style="color: #483d8b;">&quot;.dns&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the flagname used for enabling the channel command</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> nslookup_channel_flag <span style="color: #483d8b;">&quot;nslookup&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as the flag required to use the command</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> nslookup_flag <span style="color: #483d8b;">&quot;-&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Set the next line as the exec command to run</span><br />
<span style="color: #808080; font-style: italic;"># (Only if you're running an older eggdrop or not using the nslookup module)</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> nslookup_exec <span style="color: #483d8b;">&quot;nslookup -silent&quot;</span><br />
<br />
bind pub <span style="color: #ff3333;">$nslookup_flag</span>|<span style="color: #ff3333;">$nslookup_flag</span> <span style="color: #ff3333;">$nslookup_command</span> pub_nslookup<br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> pub_nslookup <span style="color: black;">&#123;</span>nick uhost hand chan arg<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">global</span> nslookup_command nslookup_exec botnick nslookup_channel_flag<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>channel get <span style="color: #ff3333;">$chan</span> <span style="color: #ff3333;">$nslookup_channel_flag</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span>matchattr <span style="color: #ff3333;">$hand</span> b<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: #ff3333;">$nick</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff3333;">$botnick</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$arg</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putserv <span style="color: #483d8b;">&quot;PRIVMSG $chan :Usage: $nslookup_command &nbsp;<span style="color: #000099; font-weight: bold;">\[</span>host/ip/nick #2<span style="color: #000099; font-weight: bold;">\]</span> ...&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> addr <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> addrs <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$arg</span> <span style="color: black;">&#123;</span>,<span style="color: #66cc66;">;</span>| <span style="color: black;">&#125;</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$addr</span> == <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">continue</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># ignore</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">set</span> tmp <span style="color: black;">&#91;</span>getchanhost <span style="color: #ff3333;">$addr</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> addr <span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$tmp</span> @<span style="color: black;">&#93;</span> end<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #66cc66;">!</span><span style="color: black;">&#91;</span><span style="color: #008000;">regexp</span> <span style="color: black;">&#123;</span>^<span style="color: black;">&#91;</span>a-zA-Z0-<span style="color: #ff4500;">9</span>\.\-<span style="color: black;">&#93;</span><span style="color: #66cc66;">*$</span><span style="color: black;">&#125;</span> <span style="color: #ff3333;">$addr</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putserv <span style="color: #483d8b;">&quot;PRIVMSG $chan :Error: Hostname '$addr' contains illegal characters&quot;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># vulnerability</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> index <span style="color: #ff3333;">$addr</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;-&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putserv <span style="color: #483d8b;">&quot;PRIVMSG $chan :Error: Hostnames cannot begin with a - character ($addr)&quot;</span> <span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;"># vulnerability</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> commands dnslookup<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dnslookup <span style="color: #ff3333;">$addr</span> return_nslookup <span style="color: #ff3333;">$chan</span> <span style="color: #ff3333;">$addr</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">catch</span> <span style="color: black;">&#123;</span><span style="color: #008000;">exec</span> bash -c <span style="color: #483d8b;">&quot;$nslookup_exec '$addr'&quot;</span><span style="color: black;">&#125;</span> output<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putserv <span style="color: #483d8b;">&quot;PRIVMSG $chan :Could not resolve $addr&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">foreach</span> line <span style="color: black;">&#91;</span><span style="color: #008000;">split</span> <span style="color: #ff3333;">$output</span> \n<span style="color: black;">&#93;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;Name:&quot;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> host <span style="color: black;">&#91;</span><span style="color: #008000;">lrange</span> <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">1</span> end<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">elseif</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;Address:&quot;</span><span style="color: black;">&#41;</span> || <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">lindex</span> <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;Addresses:&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">set</span> ip <span style="color: black;">&#91;</span><span style="color: #008000;">lrange</span> <span style="color: #ff3333;">$line</span> <span style="color: #ff4500;">1</span> end<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> exists host<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">info</span> exists ip<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return_nslookup <span style="color: #ff3333;">$ip</span> <span style="color: #ff3333;">$host</span> <span style="color: #ff4500;">1</span> <span style="color: #ff3333;">$chan</span> <span style="color: #ff3333;">$addr</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return_nslookup <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: #ff4500;">0</span> <span style="color: #ff3333;">$chan</span> <span style="color: #ff3333;">$addr</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">proc</span> return_nslookup <span style="color: black;">&#123;</span>ip host status chan addr<span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: #ff3333;">$status</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#123;</span><span style="color: black;">&#91;</span><span style="color: #008000;">string</span> match <span style="color: #66cc66;">*</span><span style="color: #ff3333;">$ip</span><span style="color: #66cc66;">*</span> <span style="color: #ff3333;">$addr</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putserv <span style="color: #483d8b;">&quot;PRIVMSG $chan :$ip -&gt; $host&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putserv <span style="color: #483d8b;">&quot;PRIVMSG $chan :$host -&gt; $ip&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; putserv <span style="color: #483d8b;">&quot;PRIVMSG $chan :Could not resolve $addr&quot;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
<span style="color: black;">&#125;</span><br />
<br />
setudef flag <span style="color: #ff3333;">$nslookup_channel_flag</span><br />
putlog <span style="color: #483d8b;">&quot;*** LOADED: nslookup.tcl&quot;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://briped.net/2007/06/20/nslookuptcl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

