]> bicyclesonthemoon.info Git - ott/enhance/blob - bb2html.awk
Initial state as of 10.01.2019
[ott/enhance] / bb2html.awk
1 #// bb2html.awk\r
2 #// converts bbcode to html.\r
3 #// 30.03.2015\r
4 #// \r
5 #// Copyright (C) 2015  Balthasar Szczepański\r
6 #// \r
7 #// This program is free software: you can redistribute it and/or modify\r
8 #// it under the terms of the GNU Affero General Public License as\r
9 #// published by the Free Software Foundation, either version 3 of the\r
10 #// License, or (at your option) any later version.\r
11 #// \r
12 #// This program is distributed in the hope that it will be useful,\r
13 #// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 #// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 #// GNU Affero General Public License for more details.\r
16 #// \r
17 #// You should have received a copy of the GNU Affero General Public License\r
18 #// along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
19 #//\r
20 \r
21 BEGIN{\r
22         FS="="\r
23         debug="debug=bb2html.awk:"\r
24         automome="/eizm/pro/ong1/mome.pl"\r
25         memepath="/eizm/mem/ong1/mome.txt"\r
26         \r
27         for(i=0;i<256;++i)\r
28         {\r
29                 ch=sprintf("%c",i)\r
30                 hex=sprintf("%02X",i)\r
31                 dec=sprintf("%u",i)\r
32                 ch2hex[ch]=hex\r
33                 ch2dec[ch]=dec\r
34         }\r
35 };\r
36 {\r
37         eq=index($0,"=")\r
38         argtab[substr($0,1,eq-1)]=substr($0,eq+1)\r
39 };\r
40 END{\r
41         if(argtab["disable_bbcode"]!="")\r
42         {\r
43                 debug=debug"###nl;BBcode disabled"\r
44                 print debug>>outfile\r
45                 exit 0\r
46         }\r
47         text=argtab["BB"]\r
48         html=bb2html(text)\r
49         print "HTML="html>>outfile\r
50         print debug>>outfile\r
51         \r
52         # if(tempfile!="")\r
53         # {\r
54                 # text=argtab["message"]\r
55                 # gsub(/%5Bbr%5D/,"\n",text)\r
56                 # while(sub(/%5Bong%5D/,ong(),text)>0){print text}\r
57                 # while(sub(/%5Bung%5D/,ung(),text)>0){print text}\r
58                 # while(sub(/%5Bong%3Ddecree%5D/,ong("decree"),text)>0){print text}\r
59                 # while(sub(/%5Bung%3Ddecree%5D/,ung("decree"),text)>0){print text}\r
60                 # if(text!=argtab["message"])\r
61                         # print "message="text >> outfile\r
62         # }\r
63 };\r
64 \r
65 function bb2html(text,   depth,count,bbtree,html,tag,tagstart,taglength,elm,tagv,tagname,tagvalue,matchname)\r
66 {\r
67         depth=0\r
68         count[0]=1\r
69         bbtree["0"]=""\r
70         bbtree["0.n"]=0\r
71         bbtree["0.t"]="post"\r
72         bbtree["0.v"]=argtab["subject"]\r
73         html=""\r
74         gsub(/&#61;/,"=",text)\r
75         debug = debug "###nl;###nl;Build BBcode tree:"\r
76         while(length(text)!=0)\r
77         {\r
78                 tag=match(text, /\[\/?[a-z0-9\*]+(=(([^\[<>\"\]]*)|(\"[^\"<>]*\")))?\]/)\r
79                 #"#\""\r
80                 # debug = debug "###nl;" RSTART " " RLENGTH\r
81                 if (tag==0)\r
82                 {\r
83                         debug = debug "###nl;text: " text\r
84                         bbtree[ind(count,depth)]=text\r
85                         bbtree[indt(count,depth)".n"]=count[depth]\r
86                         ++count[depth]\r
87                         text=""\r
88                         break;\r
89                 }\r
90                 tagstart=RSTART\r
91                 taglength=RLENGTH\r
92                 if(tagstart>1)\r
93                 {\r
94                         elm=substr(text,1,tagstart-1)\r
95                         debug = debug "###nl;text: " elm\r
96                         bbtree[ind(count,depth)]=elm\r
97                         bbtree[indt(count,depth)".n"]=count[depth]\r
98                         ++count[depth]\r
99                 }\r
100                 tag=substr(text,tagstart,taglength)\r
101                 text=substr(text,tagstart+taglength)\r
102                 debug = debug "###nl;tag: " tag\r
103                 if(tag!~/^\[\//)\r
104                 {\r
105                         tagv=index(tag,"=")\r
106                         if(tagv<2)\r
107                         {\r
108                                 tagname=substr(tag,2,length(tag)-2)\r
109                                 tagvalue=""\r
110                         }\r
111                         else\r
112                         {\r
113                                 tagname=substr(tag,2,tagv-2)\r
114                                 tagvalue=substr(tag,tagv+1,length(tag)-tagv-1)\r
115                         }\r
116                         if(tagname !~ /^((quote)|b|i|u|(code)|(img)|(url)|(size)|(color)|(center)|(right)|(sub)|(sup)|(s)|(spoiler)|(list)|(\*))$/)\r
117                         {\r
118                                 debug = debug "###nl;unknown tag"\r
119                                 bbtree[ind(count,depth)]=tag\r
120                                 bbtree[indt(count,depth)".n"]=count[depth]\r
121                                 ++count[depth]\r
122                                 continue\r
123                         }\r
124                         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
125                         {\r
126                                 debug = debug "###nl;this tag forbidden here"\r
127                                 bbtree[ind(count,depth)]=tag\r
128                                 bbtree[indt(count,depth)".n"]=count[depth]\r
129                                 ++count[depth]\r
130                                 continue\r
131                         }\r
132                         if(tagname=="*")\r
133                         {\r
134                                 if(bbtree[indt(count,depth)".t"]==tagname)\r
135                                 {\r
136                                         debug = debug "###nl;implied tag: [/"tagname"]"\r
137                                         debug = debug "###nl;matched"\r
138                                         bbtree[ind(count,depth)]="[/"tagname"]"\r
139                                         bbtree[ind(count,depth)".k"]="e"\r
140                                         bbtree[ind(count,depth)".m"]=1\r
141                                         bbtree[ind(count,depth)".t"]=tagname\r
142                                         bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
143                                         bbtree[indt(count,depth)".n"]=count[depth]\r
144                                         bbtree[indt(count,depth)".m"]=1\r
145                                         count[depth]=""\r
146                                         --depth\r
147                                         ++count[depth]\r
148                                 }\r
149                                 else if(bbtree[indt(count,depth)".t"]!="list")\r
150                                 {\r
151                                         debug = debug "###nl;this tag forbidden here"\r
152                                         bbtree[ind(count,depth)]=tag\r
153                                         bbtree[indt(count,depth)".n"]=count[depth]\r
154                                         ++count[depth]\r
155                                         continue\r
156                                 }\r
157                         }\r
158                         debug = debug "###nl;name: " tagname " value: " tagvalue\r
159                         bbtree[ind(count,depth)]=tagname" "tagvalue\r
160                         bbtree[ind(count,depth)".k"]="s"\r
161                         bbtree[indt(count,depth)".n"]=count[depth]\r
162                         ++depth\r
163                         count[depth]=1\r
164                         bbtree[indt(count,depth)]=tag\r
165                         bbtree[indt(count,depth)".n"]=0\r
166                         bbtree[indt(count,depth)".t"]=tagname\r
167                         bbtree[indt(count,depth)".v"]=tagvalue\r
168                 }\r
169                 else\r
170                 {\r
171                         if(depth<=0)\r
172                         {\r
173                                 debug = debug "###nl;""unmatched"\r
174                                 bbtree[ind(count,depth)]=tag\r
175                                 bbtree[indt(count,depth)".n"]=count[depth]\r
176                                 ++count[depth]\r
177                                 continue\r
178                         }\r
179                         tagname=substr(tag,3,length(tag)-3)\r
180                         if(tagname=="list"&&bbtree[indt(count,depth)".t"]=="*")\r
181                         {\r
182                                 debug = debug "###nl;implied tag: [/*]"\r
183                                 debug = debug "###nl;matched"\r
184                                 bbtree[ind(count,depth)]="[/*]"\r
185                                 bbtree[ind(count,depth)".k"]="e"\r
186                                 bbtree[ind(count,depth)".m"]=1\r
187                                 bbtree[ind(count,depth)".t"]="*"\r
188                                 bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
189                                 bbtree[indt(count,depth)".n"]=count[depth]\r
190                                 bbtree[indt(count,depth)".m"]=1\r
191                                 count[depth]=""\r
192                                 --depth\r
193                                 ++count[depth]\r
194                         }\r
195                         debug = debug "###nl;name: " tagname\r
196                         matchname=bbtree[indt(count,depth)".t"]\r
197                         if((bbtree[indt(count,depth)".t"] == "code" && tagname!="code")||(bbtree[indt(count,depth)".t"] == "img" && tagname != "img"))\r
198                         {\r
199                                 debug = debug "###nl;this tag forbidden here"\r
200                                 bbtree[ind(count,depth)]=tag\r
201                                 bbtree[indt(count,depth)".n"]=count[depth]\r
202                                 ++count[depth]\r
203                                 continue\r
204                         }\r
205                         if(tagname!=matchname)\r
206                         {\r
207                                 debug = debug "###nl;mismatched: " matchname\r
208                                 # bbtree[ind(count,depth)]=tag\r
209                                 # bbtree[indt(count,depth)".n"]=count[depth]\r
210                                 # ++count[depth]\r
211                                 # continue\r
212                                 bbtree[ind(count,depth)]=tag\r
213                                 bbtree[ind(count,depth)".k"]="e"\r
214                                 bbtree[ind(count,depth)".t"]=bbtree[indt(count,depth)".t"]\r
215                                 bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
216                                 bbtree[indt(count,depth)".n"]=count[depth]\r
217                                 count[depth]=""\r
218                                 --depth\r
219                                 ++count[depth]\r
220                                 continue\r
221                         }\r
222                         debug = debug "###nl;matched"\r
223                         bbtree[ind(count,depth)]=tag\r
224                         bbtree[ind(count,depth)".k"]="e"\r
225                         bbtree[ind(count,depth)".m"]=1\r
226                         bbtree[ind(count,depth)".t"]=tagname\r
227                         bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"]\r
228                         bbtree[indt(count,depth)".n"]=count[depth]\r
229                         bbtree[indt(count,depth)".m"]=1\r
230                         count[depth]=""\r
231                         --depth\r
232                         ++count[depth]\r
233                 }\r
234         }\r
235         if(depth>0)\r
236                 debug = debug "###nl;unclosed tags: " depth\r
237         \r
238         debug = debug "###nl;###nl;""generate HTML:"\r
239         depth=0\r
240         count[0]=0\r
241         while(count[0]<=bbtree["0.n"]&&depth>=0)\r
242         {\r
243                 if(count[depth]==0)\r
244                 {\r
245                         tag=bbtree[indt(count,depth)]\r
246                         tagname=bbtree[indt(count,depth)".t"]\r
247                         tagvalue=bbtree[indt(count,depth)".v"]\r
248                         debug = debug "###nl;name: "tagname" value: "tagvalue" elements: "bbtree[indt(count,depth)".n"]\r
249                         if(tagname == "post")\r
250                         {\r
251                         }\r
252                         else if(bbtree[indt(count,depth)".m"]=="")\r
253                         {\r
254                                 debug = debug "###nl;unmatched"\r
255                                 html = html tag\r
256                         }\r
257                         else if(tagname == "quote")\r
258                         {\r
259                                 if (tagvalue=="")\r
260                                 {\r
261                                         html = html "<blockquote class=\"pq\"><div>"\r
262                                 }\r
263                                 else\r
264                                 {\r
265                                         if(tagvalue !~ /^\".*\"$/)\r
266                                         #"#\""\r
267                                                 tagvalue="You forgot about the quote marks, "tagvalue\r
268                                         else\r
269                                                 tagvalue=bb2html(substr(tagvalue,2,length(tagvalue)-2))\r
270                                         html = html "<blockquote class=\"pq\"><div><cite class=\"pq\"><b class=\"br\">"tagvalue"</b> wrote:</cite><br>"\r
271                                 }\r
272                         }\r
273                         else if (tagname == "b")\r
274                         {\r
275                                 html = html"<span style=\"font-weight: bold\">"\r
276                                 if(tagvalue!="")\r
277                                         html=html"This tag shouldn't have any value. " \r
278                         }\r
279                         else if (tagname == "i")\r
280                         {\r
281                                 html = html"<span style=\"font-style: italic\">"\r
282                                 if(tagvalue!="")\r
283                                         html=html"This tag shouldn't have any value. " \r
284                         }\r
285                         else if (tagname == "u")\r
286                         {\r
287                                 html = html"<span style=\"text-decoration: underline\">"\r
288                                 if(tagvalue!="")\r
289                                         html=html"This tag shouldn't have any value. " \r
290                         }\r
291                         else if (tagname == "code")\r
292                         {\r
293                                 if(bbtree[indtu(count,depth)".t"] == "code")\r
294                                 {\r
295                                         html=html tag\r
296                                         debug = debug "###nl;not a tag, actually"\r
297                                 }\r
298                                 else\r
299                                 {\r
300                                         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
301                                         if(tagvalue!="")\r
302                                                 html=html"This tag shouldn't have any value. "\r
303                                 }\r
304                         }\r
305                         else if (tagname == "img")\r
306                                 html=html"<img src=\""\r
307                         else if (tagname == "url")\r
308                         {\r
309                                 if(tagvalue=="")\r
310                                 {\r
311                                         ++count[depth]\r
312                                         tagvalue=bbtree[ind(count,depth)]\r
313                                         --count[depth]\r
314                                         debug = debug "###nl;implied value: " tagvalue\r
315                                 }\r
316                                 html=html"<a href=\""tagvalue"\" class=\"postlink\">"\r
317                         }\r
318                         else if (tagname == "size")\r
319                         {\r
320                                 if (tagvalue==""||(tagvalue !~ /^[0-9]+$/)||(tagvalue+0)>200)\r
321                                         html=html"<span style=\"font-size: 130%; line-height: 116%;\"> This tag should have a correct value. "\r
322                                 else\r
323                                         html=html"<span style=\"font-size: "tagvalue"%; line-height: 116%;\">"\r
324                         }\r
325                         else if (tagname == "color")\r
326                         {\r
327                                 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
328                                         html=html"<span style=\"color: #EE0000\"> This tag should have a correct value. "\r
329                                 else\r
330                                         html=html"<span style=\"color: "tagvalue"\">"\r
331                         }\r
332                         else if (tagname ~ /^((center)|(right))$/)\r
333                         {\r
334                                 html=html"<div align=\""tagname"\">"\r
335                                 if(tagvalue!="")\r
336                                         html=html"This tag shouldn't have any value. "\r
337                         }\r
338                         else if (tagname =="s")\r
339                         {\r
340                                 html=html"<strike>"\r
341                                 if(tagvalue!="")\r
342                                         html=html"This tag shouldn't have any value. "\r
343                         }\r
344                         else if (tagname =="sub")\r
345                         {\r
346                                 html=html"<sub>"\r
347                                 if(tagvalue!="")\r
348                                         html=html"This tag shouldn't have any value. "\r
349                         }\r
350                         else if (tagname =="sup")\r
351                         {\r
352                                 html=html"<sup>"\r
353                                 if(tagvalue!="")\r
354                                         html=html"This tag shouldn't have any value. "\r
355                         }\r
356                         else if (tagname=="spoiler")\r
357                         {\r
358                                 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
359                                 if(tagvalue!="")\r
360                                         html=html"This tag shouldn't have any value. "\r
361                         }\r
362                         else if (tagname=="list")\r
363                         {\r
364                                 if(tagvalue=="")\r
365                                         html=html"<ul>"\r
366                                 else\r
367                                 {\r
368                                         if (tagvalue=="1")\r
369                                                 tagvalue="decimal"\r
370                                         else if (tagvalue=="i")\r
371                                                 tagvalue="lower-roman"\r
372                                         else if (tagvalue=="I")\r
373                                                 tagvalue="upper-roman"\r
374                                         else if (tagvalue=="a")\r
375                                                 tagvalue="lower-alpha"\r
376                                         else if (tagvalue=="A")\r
377                                                 tagvalue="upper-alpha"\r
378                                         else\r
379                                         {\r
380                                                 html=html"This tag should have a correct value. "\r
381                                                 tagvalue="decimal"\r
382                                         }\r
383                                         html=html"<ol style=\"list-style-type: "tagvalue"\">"\r
384                                 }\r
385                         }\r
386                         else if (tagname=="*")\r
387                         {\r
388                                 html=html"<li>"\r
389                                 if(tagvalue!="")\r
390                                         html=html"This tag shouldn't have any value. "\r
391                         }\r
392                         else\r
393                         {\r
394                                 debug = debug "###nl;unknown tag"\r
395                                 html = html tag\r
396                         }\r
397                         ++count[depth]\r
398                 }\r
399                 else if(bbtree[ind(count,depth)".k"]=="s")\r
400                 {\r
401                         debug = debug "###nl;entering tag:"\r
402                         ++depth\r
403                         count[depth]=0\r
404                 }\r
405                 else if(bbtree[ind(count,depth)".k"]=="e")\r
406                 {\r
407                         debug = debug "###nl;leaving tag:"\r
408                         tag=bbtree[ind(count,depth)]\r
409                         tagname=bbtree[ind(count,depth)".t"]\r
410                         tagvalue=bbtree[ind(count,depth)".v"]\r
411                         debug = debug "###nl;name: "tagname" value: "tagvalue\r
412                         if (tagname == "post")\r
413                         {\r
414                         }\r
415                         else if(bbtree[ind(count,depth)".m"]=="")\r
416                         {\r
417                                 debug = debug "###nl;unmatched"\r
418                                 html = html tag\r
419                         }\r
420                         else if(tagname == "quote")\r
421                                 html = html "</div></blockquote>"\r
422                         else if (tagname ~/^(b|i|u|(size)|(color))$/)\r
423                                 html = html"</span>"\r
424                         else if (tagname == "code")\r
425                         {\r
426                                 if(bbtree[indtu(count,depth)".t"] == "code")\r
427                                 {\r
428                                         html=html tag\r
429                                         debug = debug "###nl;not a tag, actually"\r
430                                 }\r
431                                 else\r
432                                         html = html"</code></dd></dl>"\r
433                         }\r
434                         else if (tagname == "img")\r
435                         {\r
436                                 html = html"\" alt=\"Image\" />"\r
437                                 if(tagvalue!="")\r
438                                         html=html"This tag shouldn't have any value. "\r
439                         }\r
440                         else if(tagname=="url")\r
441                                 html=html"</a>"\r
442                         else if (tagname ~ /^((center)|(right))$/)\r
443                                 html=html"</div>"\r
444                         else if (tagname =="s")\r
445                                 html=html"</strike>"\r
446                         else if (tagname =="sub")\r
447                                 html=html"</sub>"\r
448                         else if (tagname =="sup")\r
449                                 html=html"</sup>"\r
450                         else if (tagname=="spoiler")\r
451                                 html=html"</div></div></div>"\r
452                         else if (tagname=="list")\r
453                         {\r
454                                 if (tagvalue=="")\r
455                                         html=html"</ul>"\r
456                                 else\r
457                                         html=html"</ol>"\r
458                         }\r
459                         else if (tagname=="*")\r
460                                 html=html"</li>"\r
461                         else\r
462                         {\r
463                                 debug = debug "###nl;unknown tag"\r
464                                 html = html tag\r
465                         }\r
466                         count[depth]=""\r
467                         --depth\r
468                         ++count[depth]\r
469                 }\r
470                 else if(count[depth]>bbtree[indt(count,depth)".n"])\r
471                 {\r
472                         debug = debug "###nl;run out of elements in this tag; leaving"\r
473                         count[depth]=""\r
474                         --depth\r
475                         ++count[depth]\r
476                 }\r
477                 else\r
478                 {\r
479                         tag=bbtree[ind(count,depth)]\r
480                         debug = debug "###nl;text: "tag\r
481                         if(bbtree[indt(count,depth)".t"] == "code")\r
482                         {\r
483                                 # gsub(/ ?<br> ?/,"<br>",tag)\r
484                                 gsub(/ /,"\\&nbsp;",tag)\r
485                                 gsub(/\t/,"\\&nbsp;\\&nbsp;",tag)\r
486                         }\r
487                         if(argtab["disable_magic_url"]==""&& bbtree[indt(count,depth)".t"] !~ /^((code)|(img)|(url))$/)\r
488                                 gsub(/https?:\/\/[^\n\r\t<> ]+/,"<a href=\"&\" class=\"postlink\">&</a>",tag)\r
489                         if(argtab["disable_smilies"]=="" && bbtree[indt(count,depth)".t"] !~ /^((code)|(img))$/)\r
490                         {\r
491                                 gsub(/(^|[\n\r\t ]):D($|[\n\r\t ])/," <img title=\"Very Happy\" alt=\":D\" src=\"/ott/prosilver/smilies/icon_biggrin.gif\" /> ",tag)\r
492                                 gsub(/(^|[\n\r\t ]):\)($|[\n\r\t ])/," <img title=\"Smile\" alt=\":)\" src=\"/ott/prosilver/smilies/icon_smile.gif\" /> ",tag)\r
493                                 gsub(/(^|[\n\r\t ]):\(($|[\n\r\t ])/," <img title=\"Sad\" alt=\":(\" src=\"/ott/prosilver/smilies/icon_sad.gif\" /> ",tag)\r
494                                 gsub(/(^|[\n\r\t ]):o($|[\n\r\t ])/," <img title=\"Surprised\" alt=\":o\" src=\"/ott/prosilver/smilies/icon_surprised.gif\" /> ",tag)\r
495                                 gsub(/(^|[\n\r\t ]):shock:($|[\n\r\t ])/," <img title=\"Shocked\" alt=\":shock:\" src=\"/ott/prosilver/smilies/icon_eek.gif\" /> ",tag)\r
496                                 gsub(/(^|[\n\r\t ]):\?($|[\n\r\t ])/," <img title=\"Confused\" alt=\":?\" src=\"/ott/prosilver/smilies/icon_confused.gif\" /> ",tag)\r
497                                 gsub(/(^|[\n\r\t ])8-\)($|[\n\r\t ])/," <img title=\"Cool\" alt=\"8-)\" src=\"/ott/prosilver/smilies/icon_cool.gif\" /> ",tag)\r
498                                 gsub(/(^|[\n\r\t ]):lol:($|[\n\r\t ])/," <img title=\"Laughing\" alt=\":lol:\" src=\"/ott/prosilver/smilies/icon_lol.gif\" /> ",tag)\r
499                                 gsub(/(^|[\n\r\t ]):x($|[\n\r\t ])/," <img title=\"Mad\" alt=\":x\" src=\"/ott/prosilver/smilies/icon_mad.gif\" /> ",tag)\r
500                                 gsub(/(^|[\n\r\t ]):P($|[\n\r\t ])/," <img title=\"Razz\" alt=\":P\" src=\"/ott/prosilver/smilies/icon_razz.gif\" /> ",tag)\r
501                                 gsub(/(^|[\n\r\t ]):oops:($|[\n\r\t ])/," <img title=\"Embarassed\" alt=\":oops:\" src=\"/ott/prosilver/smilies/icon_redface.gif\" /> ",tag)\r
502                                 gsub(/(^|[\n\r\t ]):cry:($|[\n\r\t ])/," <img title=\"Crying or Very Sad\" alt=\":cry:\" src=\"/ott/prosilver/smilies/icon_cry.gif\" /> ",tag)\r
503                                 gsub(/(^|[\n\r\t ]):evil:($|[\n\r\t ])/," <img title=\"Evil or Very Mad\" alt=\":evil:\" src=\"/ott/prosilver/smilies/icon_evil.gif\" /> ",tag)\r
504                                 gsub(/(^|[\n\r\t ]):twisted:($|[\n\r\t ])/," <img title=\"Twisted Evil\" alt=\":twisted:\" src=\"/ott/prosilver/smilies/icon_twisted.gif\" /> ",tag)\r
505                                 gsub(/(^|[\n\r\t ]):roll:($|[\n\r\t ])/," <img title=\"Rolling Eyes\" alt=\":roll:\" src=\"/ott/prosilver/smilies/icon_rolleyes.gif\" /> ",tag)\r
506                                 gsub(/(^|[\n\r\t ]):wink:($|[\n\r\t ])/," <img title=\"Wink\" alt=\":wink:\" src=\"/ott/prosilver/smilies/icon_wink.gif\" /> ",tag)\r
507                                 gsub(/(^|[\n\r\t ]);\)($|[\n\r\t ])/," <img title=\"Wink\" alt=\":wink:\" src=\"/ott/prosilver/smilies/icon_wink.gif\" /> ",tag)\r
508                                 gsub(/(^|[\n\r\t ]):!:($|[\n\r\t ])/," <img title=\"Exclamation\" alt=\":!:\" src=\"/ott/prosilver/smilies/icon_exclaim.gif\" /> ",tag)\r
509                                 gsub(/(^|[\n\r\t ]):\?:($|[\n\r\t ])/," <img title=\"Question\" alt=\":?:\" src=\"/ott/prosilver/smilies/icon_question.gif\" /> ",tag)\r
510                                 gsub(/(^|[\n\r\t ]):idea:($|[\n\r\t ])/," <img title=\"Idea\" alt=\":idea:\" src=\"/ott/prosilver/smilies/icon_idea.gif\" /> ",tag)\r
511                                 gsub(/(^|[\n\r\t ]):arrow:($|[\n\r\t ])/," <img title=\"Arrow\" alt=\":arrow:\" src=\"/ott/prosilver/smilies/icon_arrow.gif\" /> ",tag)\r
512                                 gsub(/(^|[\n\r\t ]):\|($|[\n\r\t ])/," <img title=\"Neutral\" alt=\":|\" src=\"/ott/prosilver/smilies/icon_neutral.gif\" /> ",tag)\r
513                                 gsub(/(^|[\n\r\t ]):mrgreen:($|[\n\r\t ])/," <img title=\"Mr. Green\" alt=\":mrgreen:\" src=\"/ott/prosilver/smilies/icon_mrgreen.gif\" /> ",tag)\r
514                         }\r
515                         \r
516                         html = html tag\r
517                         ++count[depth]\r
518                 }\r
519         }\r
520         debug = debug "###nl;done"\r
521         return html\r
522 }\r
523 \r
524 function ind(count,depth,   ii,iindex)\r
525 {\r
526         iindex = ""\r
527         for(ii=0;ii<=depth;++ii)\r
528         {\r
529                 if(ii!=0)\r
530                         iindex = iindex "."\r
531                 iindex = iindex count[ii]\r
532         }\r
533         # debug = debug "###nl;" iindex\r
534         return iindex\r
535 }\r
536 function indt(count,depth,   ii,iindex)\r
537 {\r
538         iindex = ""\r
539         for(ii=0;ii<depth;++ii)\r
540         {\r
541                 if(ii!=0)\r
542                         iindex = iindex "."\r
543                 iindex = iindex count[ii]\r
544         }\r
545         if(depth>0)\r
546                 iindex=iindex"."\r
547         iindex = iindex "0"\r
548         # debug = debug "###nl;" iindex\r
549         return iindex\r
550 }\r
551 function indtu(count,depth,   ii,iindex)\r
552 {\r
553         iindex = ""\r
554         for(ii=0;ii<depth-1;++ii)\r
555         {\r
556                 if(ii!=0)\r
557                         iindex = iindex "."\r
558                 iindex = iindex count[ii]\r
559         }\r
560         if(depth>0)\r
561                 iindex=iindex"."\r
562         iindex = iindex "0"\r
563         # debug = debug "###nl;" iindex\r
564         return iindex\r
565 }\r
566 function ong(decree,   line)\r
567 {\r
568         system (automome" -lc 256 -n 67 -d "memepath(decree!=""?" -t \"[decr]\"":"")" > "tempfile)\r
569         \r
570         while((getline line < tempfile)>0)\r
571         {\r
572                 gsub(/[\r\n]/,"",line)\r
573                 if(sub(/[AEIOUY]-N-G/,"#O-N-G#",line)>0)\r
574                 {\r
575                         close(tempfile)\r
576                         return preparebb(line)\r
577                 }\r
578                 if(sub(/O+N+G+/,"#&#",line)>0)\r
579                 {\r
580                         close(tempfile)\r
581                         return preparebb(line)\r
582                 }\r
583                 if(sub(/DON'T/,"D#ON'G#T",line)>0)\r
584                 {\r
585                         close(tempfile)\r
586                         return preparebb(line)\r
587                 }\r
588                 if(sub(/[AEIOUY]NG/,"#ONG#",line)>0)\r
589                 {\r
590                         if($0!~/TH\[b\]ONG/)\r
591                                 return preparebb(line)\r
592                 }\r
593                 if(sub(/ON /,"#ONG# ",line)>0)\r
594                 {\r
595                         close(tempfile)\r
596                         return preparebb(line)\r
597                 }\r
598                 if(sub(/O\.?$/,"#ONG# ",$0)>0)\r
599                 {\r
600                         close(tempfile)\r
601                         return preparebb(line)\r
602                 }\r
603         }\r
604         close(tempfile)\r
605         return "Ong"\r
606 }\r
607 \r
608 function ung(decree,   line)\r
609 {\r
610         system (automome" -lc 256 -n 67 -d "memepath(decree!=""?" -t \"[decr]\"":"")" > "tempfile)\r
611         \r
612         while((getline line < tempfile)>0)\r
613         {\r
614                 gsub(/[\r\n]/,"",line)\r
615                 if(sub(/[AEIOUY]-N-G/,"#U-N-G#",line)>0)\r
616                 {\r
617                         close(tempfile)\r
618                         return preparebb(line)\r
619                 }\r
620                 if(sub(/U+N+G+/,"#&#",line)>0)\r
621                 {\r
622                         close(tempfile)\r
623                         return preparebb(line)\r
624                 }\r
625                 if(sub(/[AEIOUY]NG/,"#UNG#",line)>0)\r
626                 {\r
627                         close(tempfile)\r
628                         return preparebb(line)\r
629                 }\r
630                 if(sub(/UN /,"#UNG# ",line)>0)\r
631                 {\r
632                         close(tempfile)\r
633                         return preparebb(line)\r
634                 }\r
635                 if(sub(/U\.?$/,"#UNG# ",$0)>0)\r
636                 {\r
637                         close(tempfile)\r
638                         return preparebb(line)\r
639                 }\r
640         }\r
641         close(tempfile)\r
642         return "Ung"\r
643 }\r
644 \r
645 function preparebb(rh)\r
646 {\r
647         if(nobb=="")\r
648         {\r
649                 gsub(/\*\*/,"¤",rh)\r
650                 gsub(/\*[^\*]+\*/,"±&±",rh)\r
651                 gsub(/±\*/,"[i]",rh)\r
652                 gsub(/\*±/,"[/i]",rh)\r
653                 gsub(/¤/,"*",rh)\r
654                 \r
655                 gsub(/__/,"¤",rh)\r
656                 gsub(/_[^_]+_/,"±&±",rh)\r
657                 gsub(/±_/,"[u]",rh)\r
658                 gsub(/_±/,"[/u]",rh)\r
659                 gsub(/¤/,"_",rh)\r
660                 \r
661                 gsub(/##/,"¤",rh)\r
662                 gsub(/#[^#]+#/,"±&±",rh)\r
663                 gsub(/±#/,"[b]",rh)\r
664                 gsub(/#±/,"[/b]",rh)\r
665                 gsub(/¤/,"#",rh)\r
666                 \r
667                 gsub(/\$\$/,"¤",rh)\r
668                 gsub(/\$[^\$]+\$/,"±&±",rh)\r
669                 gsub(/±\$/,"[size=80]",rh)\r
670                 gsub(/\$±/,"[/size]",rh)\r
671                 gsub(/¤/,"$",rh)\r
672         }\r
673         \r
674         return rh (nobb==""?" -- [url=http://mrob.com/time/automome]automome[/url]":" -- automome")\r
675 }\r
676 function urlencode(name,all,   len,iii,escaped,ch)\r
677 {\r
678         len=length(name)\r
679         escaped=""\r
680         for(iii=1;iii<=len;++iii)\r
681         {\r
682                 ch=substr(name,iii,1);\r
683                 if ((ch ~ /[a-zA-Z0-9\.\-_~]/)&&(all==""))\r
684                         escaped = escaped ch\r
685                 else\r
686                         escaped = escaped "%" ch2hex[ch]\r
687         }\r
688         return escaped\r
689 }\r