+}\r
+\r
+function readspecialfile (datafile, argtab, specialtab, effectivetab, line,undertext,eq,i)\r
+{\r
+ for (i in specialtab)\r
+ delete specialtab[i]\r
+ \r
+ for (i in effectivetab)\r
+ delete effectivetab[i]\r
+ \r
+ if (datafile=="")\r
+ return\r
+ \r
+ line=""\r
+ while((getline line < datafile)>0)\r
+ {\r
+ gsub(/[\r\n]/, "", line)\r
+ \r
+ if (line == "" && !undertext)\r
+ {\r
+ undertext=1\r
+ specialtab["text"]=""\r
+ }\r
+ else if (undertext)\r
+ {\r
+ specialtab["text"] = specialtab["text"] line "\n"\r
+ }\r
+ else\r
+ {\r
+ eq=index(line, "=")\r
+ specialtab[substr(line, 1, eq-1)]=substr(line, eq+1)\r
+ }\r
+ }\r
+ \r
+ for (i in argtab)\r
+ effectivetab[i]=argtab[i]\r
+ \r
+ for (i in specialtab)\r
+ effectivetab[i]=specialtab[i]\r
+ \r
+ \r
+ close (datafile)\r
+ \r
+}\r
+\r
+function writespecialfile (datafile, specialtab, i)\r
+{\r
+ for (i in specialtab)\r
+ {\r
+ if (i!="text")\r
+ print i"="specialtab[i] > specialfile\r
+ }\r
+ \r
+ print "" > specialfile\r
+ if (specialtab["text"]!="")\r
+ printf("%s",specialtab["text"]) > specialfile\r
+ close (specialfile)\r
+}\r
+\r
+#HTML STUFF FROM HERE\r
+function bb2html(text, depth,count,bbtree,html,tag,tagstart,taglength,elm,tagv,tagname,tagvalue,matchname)\r
+{\r
+ depth=0\r
+ count[0]=1\r
+ bbtree["0"]=""\r
+ bbtree["0.n"]=0\r
+ bbtree["0.t"]="post"\r
+ bbtree["0.v"]=argtab["subject"]\r
+ html=""\r
+ # gsub(/=/,"=",text)\r
+ debug = debug "\n\nBuild BBcode tree:"\r
+ while(length(text)!=0)\r
+ {\r
+ tag=match(text, /\[\/?[a-z0-9\*]+(=(([^\[<>\"\]]*)|(\"[^\"<>]*\")))?\]/)\r
+ #"#\""\r
+ if (tag==0)\r
+ {\r
+ debug = debug "\ntext: " text\r
+ bbtree[ind(count,depth)]=text\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ ++count[depth]\r
+ text=""\r
+ break;\r
+ }\r
+ tagstart=RSTART\r
+ taglength=RLENGTH\r
+ if(tagstart>1)\r
+ {\r
+ elm=substr(text,1,tagstart-1)\r
+ debug = debug "\ntext: " elm\r
+ bbtree[ind(count,depth)]=elm\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ ++count[depth]\r
+ }\r
+ tag=substr(text,tagstart,taglength)\r
+ text=substr(text,tagstart+taglength)\r
+ debug = debug "\ntag: " tag\r
+ if(tag!~/^\[\//)\r
+ {\r
+ tagv=index(tag,"=")\r
+ if(tagv<2)\r
+ {\r
+ tagname=substr(tag,2,length(tag)-2)\r
+ tagvalue=""\r
+ }\r
+ else\r
+ {\r
+ tagname=substr(tag,2,tagv-2)\r
+ tagvalue=substr(tag,tagv+1,length(tag)-tagv-1)\r
+ }\r
+ if(tagname !~ /^((fq)|(tq)|(ni)|(po)|(quote)|b|i|u|(code)|(img)|(url)|(size)|(color)|(center)|(right)|(sub)|(sup)|(s)|(spoiler)|(list)|(br)|(\*))$/)\r
+ {\r
+ debug = debug "\nunknown tag"\r
+ bbtree[ind(count,depth)]=tag\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ ++count[depth]\r
+ continue\r
+ }\r
+ if((bbtree[indt(count,depth)".t"] == "code" && tagname!="code")||bbtree[indt(count,depth)".t"] == "img"||(bbtree[indt(count,depth)".t"] == "spoiler" && tagname=="spoiler")||(bbtree[indt(count,depth)".t"] == "size" && tagname=="size"))\r
+ {\r
+ debug = debug "\nthis tag forbidden here"\r
+ bbtree[ind(count,depth)]=tag\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ ++count[depth]\r
+ continue\r
+ }\r
+ if(tagname=="*")\r
+ {\r
+ if(bbtree[indt(count,depth)".t"]==tagname)\r
+ {\r
+ debug = debug "\nimplied tag: [/"tagname"]"\r
+ debug = debug "\nmatched"\r
+ bbtree[ind(count,depth)]="[/"tagname"]"\r
+ bbtree[ind(count,depth)".k"]="e"\r
+ bbtree[ind(count,depth)".m"]=1\r
+ bbtree[ind(count,depth)".t"]=tagname\r
+ bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ bbtree[indt(count,depth)".m"]=1\r
+ count[depth]=""\r
+ --depth\r
+ ++count[depth]\r
+ }\r
+ else if(bbtree[indt(count,depth)".t"]!="list")\r
+ {\r
+ debug = debug "\nthis tag forbidden here"\r
+ bbtree[ind(count,depth)]=tag\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ ++count[depth]\r
+ continue\r
+ }\r
+ }\r
+ debug = debug "\nname: " tagname " value: " tagvalue\r
+ bbtree[ind(count,depth)]=tagname" "tagvalue\r
+ bbtree[ind(count,depth)".k"]="s"\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ ++depth\r
+ count[depth]=1\r
+ bbtree[indt(count,depth)]=tag\r
+ bbtree[indt(count,depth)".n"]=0\r
+ bbtree[indt(count,depth)".t"]=tagname\r
+ bbtree[indt(count,depth)".v"]=tagvalue\r
+ \r
+ # if(tagname=="br") #or other single tags in the future\r
+ # {\r
+ # debug = debug "\nmatched"\r
+ # bbtree[ind(count,depth)]=tag\r
+ # bbtree[ind(count,depth)".k"]="e"\r
+ # bbtree[ind(count,depth)".m"]=1\r
+ # bbtree[ind(count,depth)".t"]=tagname\r
+ # bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+ # bbtree[indt(count,depth)".n"]=count[depth]\r
+ # bbtree[indt(count,depth)".m"]=1\r
+ # count[depth]=""\r
+ # --depth\r
+ # ++count[depth]\r
+ # }\r
+ }\r
+ else\r
+ {\r
+ if(depth<=0)\r
+ {\r
+ debug = debug "\n""unmatched"\r
+ bbtree[ind(count,depth)]=tag\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ ++count[depth]\r
+ continue\r
+ }\r
+ tagname=substr(tag,3,length(tag)-3)\r
+ if(tagname=="list"&&bbtree[indt(count,depth)".t"]=="*")\r
+ {\r
+ debug = debug "\nimplied tag: [/*]"\r
+ debug = debug "\nmatched"\r
+ bbtree[ind(count,depth)]="[/*]"\r
+ bbtree[ind(count,depth)".k"]="e"\r
+ bbtree[ind(count,depth)".m"]=1\r
+ bbtree[ind(count,depth)".t"]="*"\r
+ bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ bbtree[indt(count,depth)".m"]=1\r
+ count[depth]=""\r
+ --depth\r
+ ++count[depth]\r
+ }\r
+ debug = debug "\nname: " tagname\r
+ matchname=bbtree[indt(count,depth)".t"]\r
+ if((bbtree[indt(count,depth)".t"] == "code" && tagname!="code")||(bbtree[indt(count,depth)".t"] == "img" && tagname != "img"))\r
+ {\r
+ debug = debug "\nthis tag forbidden here"\r
+ bbtree[ind(count,depth)]=tag\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ ++count[depth]\r
+ continue\r
+ }\r
+ if(tagname!=matchname)\r
+ {\r
+ debug = debug "\nmismatched: " matchname\r
+ # bbtree[ind(count,depth)]=tag\r
+ # bbtree[indt(count,depth)".n"]=count[depth]\r
+ # ++count[depth]\r
+ # continue\r
+ bbtree[ind(count,depth)]=tag\r
+ bbtree[ind(count,depth)".k"]="e"\r
+ bbtree[ind(count,depth)".t"]=bbtree[indt(count,depth)".t"]\r
+ bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ count[depth]=""\r
+ --depth\r
+ ++count[depth]\r
+ continue\r
+ }\r
+ debug = debug "\nmatched"\r
+ bbtree[ind(count,depth)]=tag\r
+ bbtree[ind(count,depth)".k"]="e"\r
+ bbtree[ind(count,depth)".m"]=1\r
+ bbtree[ind(count,depth)".t"]=tagname\r
+ bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
+ bbtree[indt(count,depth)".n"]=count[depth]\r
+ bbtree[indt(count,depth)".m"]=1\r
+ count[depth]=""\r
+ --depth\r
+ ++count[depth]\r
+ }\r
+ }\r
+ if(depth>0)\r
+ debug = debug "\nunclosed tags: " depth\r
+ \r
+ debug = debug "\n\n""generate HTML:"\r
+ depth=0\r
+ count[0]=0\r
+ while(count[0]<=bbtree["0.n"]&&depth>=0)\r
+ {\r
+ if(count[depth]==0)\r
+ {\r
+ tag=bbtree[indt(count,depth)]\r
+ tagname=bbtree[indt(count,depth)".t"]\r
+ tagvalue=bbtree[indt(count,depth)".v"]\r
+ debug = debug "\nname: "tagname" value: "tagvalue" elements: "bbtree[indt(count,depth)".n"]\r
+ if(tagname == "post")\r
+ {\r
+ }\r
+ else if(bbtree[indt(count,depth)".m"]=="")\r
+ {\r
+ debug = debug "\nunmatched"\r
+ html = html htmlescape(tag)\r
+ }\r
+ else if(tagname == "quote")\r
+ {\r
+ if (tagvalue=="")\r
+ {\r
+ html = html "<blockquote class=\"pq\"><div>"\r
+ }\r
+ else\r
+ {\r
+ if(tagvalue !~ /^\".*\"$/)\r
+ #"#\""\r
+ tagvalue="You forgot about the quote marks, "htmlescape(tagvalue)\r
+ else\r
+ tagvalue=bb2html(substr(tagvalue,2,length(tagvalue)-2))\r
+ html = html "<blockquote class=\"pq\"><div><cite class=\"pq\"><b class=\"br\">"tagvalue"</b> wrote:</cite><br>"\r
+ }\r
+ }\r
+ else if (tagname == "fq")\r
+ {\r
+ html = html"<div class=\"fq\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. " \r
+ }\r
+ else if (tagname == "tq")\r
+ {\r
+ html = html"<div class=\"tq\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. " \r
+ }\r
+ else if (tagname == "br")\r
+ {\r
+ html = html"<span class=\"br\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. " \r
+ }\r
+ else if (tagname == "ni")\r
+ {\r
+ html = html"<span class=\"ni\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. " \r
+ }\r
+ else if (tagname == "po")\r
+ {\r
+ html = html"<span class=\"po\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. " \r
+ }\r
+ else if (tagname == "b")\r
+ {\r
+ html = html"<span style=\"font-weight: bold\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. " \r
+ }\r
+ else if (tagname == "i")\r
+ {\r
+ html = html"<span style=\"font-style: italic\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. " \r
+ }\r
+ else if (tagname == "u")\r
+ {\r
+ html = html"<span style=\"text-decoration: underline\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. " \r
+ }\r
+ else if (tagname == "code")\r
+ {\r
+ if(bbtree[indtu(count,depth)".t"] == "code")\r
+ {\r
+ html=html htmlescape(tag)\r
+ debug = debug "\nnot a tag, actually"\r
+ }\r
+ else\r
+ {\r
+ html=html"<dl class=\"pq\"><dt class=\"pq\">Code: <a href=\"#\" onclick=\"selectCode(this); return false;\">Select all</a></dt><dd><code class=\"pq\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. "\r
+ }\r
+ }\r
+ else if (tagname == "img")\r
+ html=html"<img src=\""\r
+ else if (tagname == "url")\r
+ {\r
+ if(tagvalue=="")\r
+ {\r
+ ++count[depth]\r
+ tagvalue=bbtree[ind(count,depth)]\r
+ --count[depth]\r
+ debug = debug "\nimplied value: " tagvalue\r
+ }\r
+ html=html"<a href=\""htmlescape(tagvalue)"\" class=\"postlink\">"\r
+ }\r
+ else if (tagname == "size")\r
+ {\r
+ if (tagvalue==""||(tagvalue !~ /^[0-9]+$/)||(tagvalue+0)>200)\r
+ html=html"<span style=\"font-size: 130%; line-height: 116%;\"> This tag should have a correct value. "\r
+ else\r
+ html=html"<span style=\"font-size: "htmlescape(tagvalue)"%; line-height: 116%;\">"\r
+ }\r
+ else if (tagname == "color")\r
+ {\r
+ if (tagvalue==""||tagvalue !~ /^#[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]$/) #for some reason /^([0-9A-F]{6})$/ doesn't work.\r
+ html=html"<span style=\"color: #EE0000\"> This tag should have a correct value. "\r
+ else\r
+ html=html"<span style=\"color: "htmlescape(tagvalue)"\">"\r
+ }\r
+ else if (tagname ~ /^((center)|(right))$/)\r
+ {\r
+ html=html"<div align=\""tagname"\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. "\r
+ }\r
+ else if (tagname =="s")\r
+ {\r
+ html=html"<strike>"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. "\r
+ }\r
+ else if (tagname =="sub")\r
+ {\r
+ html=html"<sub>"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. "\r
+ }\r
+ else if (tagname =="sup")\r
+ {\r
+ html=html"<sup>"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. "\r
+ }\r
+ else if (tagname=="spoiler")\r
+ {\r
+ html=html"<div style=\"margin:20px; margin-top:5px\"><div class=\"quotetitle\"><b>Spoiler:</b> <input type=\"button\" class=\"pk\" value=\"Show\" style=\"width:45px;font-size:10px;margin:0px;padding:0px;\" onclick=\"if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }\" /></div><div class=\"quotecontent\"><div style=\"display: none;\">"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. "\r
+ }\r
+ else if (tagname=="list")\r
+ {\r
+ if(tagvalue=="")\r
+ html=html"<ul>"\r
+ else\r
+ {\r
+ if (tagvalue=="1")\r
+ tagvalue="decimal"\r
+ else if (tagvalue=="i")\r
+ tagvalue="lower-roman"\r
+ else if (tagvalue=="I")\r
+ tagvalue="upper-roman"\r
+ else if (tagvalue=="a")\r
+ tagvalue="lower-alpha"\r
+ else if (tagvalue=="A")\r
+ tagvalue="upper-alpha"\r
+ else\r
+ {\r
+ html=html"This tag should have a correct value. "\r
+ tagvalue="decimal"\r
+ }\r
+ html=html"<ol style=\"list-style-type: "tagvalue"\">"\r
+ }\r
+ }\r
+ else if (tagname=="*")\r
+ {\r
+ html=html"<li>"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. "\r
+ }\r
+ # else if (tagname == "br")\r
+ # {\r
+ # html = html"<br>"\r
+ # if(tagvalue!="")\r
+ # html=html"This tag shouldn't have any value. " \r
+ # }\r
+ else\r
+ {\r
+ debug = debug "\nunknown tag"\r
+ html = html htmlescape(tag)\r
+ }\r
+ ++count[depth]\r
+ }\r
+ else if(bbtree[ind(count,depth)".k"]=="s")\r
+ {\r
+ debug = debug "\nentering tag:"\r
+ ++depth\r
+ count[depth]=0\r
+ }\r
+ else if(bbtree[ind(count,depth)".k"]=="e")\r
+ {\r
+ debug = debug "\nleaving tag:"\r
+ tag=bbtree[ind(count,depth)]\r
+ tagname=bbtree[ind(count,depth)".t"]\r
+ tagvalue=bbtree[ind(count,depth)".v"]\r
+ debug = debug "\nname: "tagname" value: "tagvalue\r
+ if (tagname == "post")\r
+ {\r
+ }\r
+ else if(bbtree[ind(count,depth)".m"]=="")\r
+ {\r
+ debug = debug "\nunmatched"\r
+ html = html htmlescape(tag)\r
+ }\r
+ else if(tagname == "quote")\r
+ html = html "</div></blockquote>"\r
+ else if (tagname ~/^(b|i|u|(size)|(color)|(br)|(ni)|(po))$/)\r
+ html = html"</span>"\r
+ else if (tagname == "code")\r
+ {\r
+ if(bbtree[indtu(count,depth)".t"] == "code")\r
+ {\r
+ html=html htmlescape(tag)\r
+ debug = debug "\nnot a tag, actually"\r
+ }\r
+ else\r
+ html = html"</code></dd></dl>"\r
+ }\r
+ else if (tagname == "img")\r
+ {\r
+ html = html"\" alt=\"Image\" />"\r
+ if(tagvalue!="")\r
+ html=html"This tag shouldn't have any value. "\r
+ }\r
+ else if(tagname=="url")\r
+ html=html"</a>"\r
+ else if (tagname ~ /^((center)|(right)|(fq)|(tq))$/)\r
+ html=html"</div>"\r
+ else if (tagname =="s")\r
+ html=html"</strike>"\r
+ else if (tagname =="sub")\r
+ html=html"</sub>"\r
+ else if (tagname =="sup")\r
+ html=html"</sup>"\r
+ else if (tagname=="spoiler")\r
+ html=html"</div></div></div>"\r
+ else if (tagname=="list")\r
+ {\r
+ if (tagvalue=="")\r
+ html=html"</ul>"\r
+ else\r
+ html=html"</ol>"\r
+ }\r
+ else if (tagname=="*")\r
+ html=html"</li>"\r
+ # else if (tagname == "br") #\r
+ # {\r
+ # #\r
+ # }\r
+ else\r
+ {\r
+ debug = debug "\nunknown tag"\r
+ html = html htmlescape(tag)\r
+ }\r
+ count[depth]=""\r
+ --depth\r
+ ++count[depth]\r
+ }\r
+ else if(count[depth]>bbtree[indt(count,depth)".n"])\r
+ {\r
+ debug = debug "\nrun out of elements in this tag; leaving"\r
+ count[depth]=""\r
+ --depth\r
+ ++count[depth]\r
+ }\r
+ else\r
+ {\r
+ tag=bbtree[ind(count,depth)]\r
+ debug = debug "\ntext: "tag\r
+ \r
+ tag=htmlescape(tag,"","br")\r
+ \r
+ if(bbtree[indt(count,depth)".t"] == "code")\r
+ {\r
+ gsub(/ /,"\\ ",tag)\r
+ gsub(/\t/,"\\ \\ ",tag)\r
+ }\r
+ else{\r
+ gsub(/ /,"\\ ",tag)\r
+ gsub(/ /," \\ ",tag)\r
+ # gsub(/<br> /,"<br>\\ ",tag)\r
+ }\r
+ \r
+ \r
+ if(nourl==""&& bbtree[indt(count,depth)".t"] !~ /^((code)|(img)|(url))$/)\r
+ gsub(/https?:\/\/[^\n\r\t<> ]+/,"<a href=\"&\" class=\"postlink\">&</a>",tag)\r
+ # if(nosmil=="" && bbtree[indt(count,depth)".t"] !~ /^((code)|(img))$/)\r
+ # {\r
+ # gsub(/(^|[\n\r\t ]):D($|[\n\r\t ])/," <img title=\"Very Happy\" alt=\":D\" src=\"http://forums.xkcd.com/images/smilies/icon_biggrin.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):\)($|[\n\r\t ])/," <img title=\"Smile\" alt=\":)\" src=\"http://forums.xkcd.com/images/smilies/icon_smile.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):\(($|[\n\r\t ])/," <img title=\"Sad\" alt=\":(\" src=\"http://forums.xkcd.com/images/smilies/icon_sad.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):o($|[\n\r\t ])/," <img title=\"Surprised\" alt=\":o\" src=\"http://forums.xkcd.com/images/smilies/icon_surprised.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):shock:($|[\n\r\t ])/," <img title=\"Shocked\" alt=\":shock:\" src=\"http://forums.xkcd.com/images/smilies/icon_eek.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):\?($|[\n\r\t ])/," <img title=\"Confused\" alt=\":?\" src=\"http://forums.xkcd.com/images/smilies/icon_confused.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ])8-\)($|[\n\r\t ])/," <img title=\"Cool\" alt=\"8-)\" src=\"http://forums.xkcd.com/images/smilies/icon_cool.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):lol:($|[\n\r\t ])/," <img title=\"Laughing\" alt=\":lol:\" src=\"http://forums.xkcd.com/images/smilies/icon_lol.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):x($|[\n\r\t ])/," <img title=\"Mad\" alt=\":x\" src=\"http://forums.xkcd.com/images/smilies/icon_mad.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):P($|[\n\r\t ])/," <img title=\"Razz\" alt=\":P\" src=\"http://forums.xkcd.com/images/smilies/icon_razz.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):oops:($|[\n\r\t ])/," <img title=\"Embarassed\" alt=\":oops:\" src=\"http://forums.xkcd.com/images/smilies/icon_redface.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):cry:($|[\n\r\t ])/," <img title=\"Crying or Very Sad\" alt=\":cry:\" src=\"http://forums.xkcd.com/images/smilies/icon_cry.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):evil:($|[\n\r\t ])/," <img title=\"Evil or Very Mad\" alt=\":evil:\" src=\"http://forums.xkcd.com/images/smilies/icon_evil.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):twisted:($|[\n\r\t ])/," <img title=\"Twisted Evil\" alt=\":twisted:\" src=\"http://forums.xkcd.com/images/smilies/icon_twisted.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):roll:($|[\n\r\t ])/," <img title=\"Rolling Eyes\" alt=\":roll:\" src=\"http://forums.xkcd.com/images/smilies/icon_rolleyes.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):wink:($|[\n\r\t ])/," <img title=\"Wink\" alt=\":wink:\" src=\"http://forums.xkcd.com/images/smilies/icon_wink.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]);\)($|[\n\r\t ])/," <img title=\"Wink\" alt=\":wink:\" src=\"http://forums.xkcd.com/images/smilies/icon_wink.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):!:($|[\n\r\t ])/," <img title=\"Exclamation\" alt=\":!:\" src=\"http://forums.xkcd.com/images/smilies/icon_exclaim.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):\?:($|[\n\r\t ])/," <img title=\"Question\" alt=\":?:\" src=\"http://forums.xkcd.com/images/smilies/icon_question.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):idea:($|[\n\r\t ])/," <img title=\"Idea\" alt=\":idea:\" src=\"http://forums.xkcd.com/images/smilies/icon_idea.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):arrow:($|[\n\r\t ])/," <img title=\"Arrow\" alt=\":arrow:\" src=\"http://forums.xkcd.com/images/smilies/icon_arrow.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):\|($|[\n\r\t ])/," <img title=\"Neutral\" alt=\":|\" src=\"http://forums.xkcd.com/images/smilies/icon_neutral.gif\" /> ",tag)\r
+ # gsub(/(^|[\n\r\t ]):mrgreen:($|[\n\r\t ])/," <img title=\"Mr. Green\" alt=\":mrgreen:\" src=\"http://forums.xkcd.com/images/smilies/icon_mrgreen.gif\" /> ",tag)\r
+ # }\r
+ \r
+ html = html tag\r
+ ++count[depth]\r
+ }\r
+ }\r
+ debug = debug "\ndone\n"\r
+ return html\r
+}\r
+\r
+function ind(count,depth, ii,iindex)\r
+{\r
+ iindex = ""\r
+ for(ii=0;ii<=depth;++ii)\r
+ {\r
+ if(ii!=0)\r
+ iindex = iindex "."\r
+ iindex = iindex count[ii]\r
+ }\r
+ # debug = debug "\n" iindex\r
+ return iindex\r
+}\r
+function indt(count,depth, ii,iindex)\r
+{\r
+ iindex = ""\r
+ for(ii=0;ii<depth;++ii)\r
+ {\r
+ if(ii!=0)\r
+ iindex = iindex "."\r
+ iindex = iindex count[ii]\r
+ }\r
+ if(depth>0)\r
+ iindex=iindex"."\r
+ iindex = iindex "0"\r
+ # debug = debug "\n" iindex\r
+ return iindex\r
+}\r
+function indtu(count,depth, ii,iindex)\r
+{\r
+ iindex = ""\r
+ for(ii=0;ii<depth-1;++ii)\r
+ {\r
+ if(ii!=0)\r
+ iindex = iindex "."\r
+ iindex = iindex count[ii]\r
+ }\r
+ if(depth>0)\r
+ iindex=iindex"."\r
+ iindex = iindex "0"\r
+ # debug = debug "\n" iindex\r
+ return iindex\r
+}\r
+function htmlescape(name,less,br, len,iii,escaped,ch)\r
+{\r
+ len=length(name)\r
+ escaped=""\r
+ for(iii=1;iii<=len;++iii)\r
+ {\r
+ ch=substr(name,iii,1);\r
+ if(ch == "\n")\r
+ escaped = escaped ((br!="")?"<br>":"&#"ch2dec[ch]";")\r
+ else if(ch =="\r")\r
+ escaped = escaped ((br!="")?"":"&#"ch2dec[ch]";")\r
+ else if(ch == "\"" && less=="")\r
+ escaped = escaped "&#"ch2dec[ch]";"\r
+ else if(ch ~ /[=<>&]/)\r
+ escaped = escaped "&#"ch2dec[ch]";"\r
+ else\r
+ escaped = escaped ch\r
+ }\r
+ return escaped\r
+}\r
+function hexencode(name, len,iii,escaped,ch)\r
+{\r
+ len=length(name)\r
+ escaped=""\r
+ for(iii=1;iii<=len;++iii)\r
+ {\r
+ ch=substr(name,iii,1)\r
+ escaped = escaped ch2hex[ch]\r
+ }\r
+ return escaped\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r