#// ongtext.awk
#// ONGification from the ONGtext generator
#// 13.10.2014
#//
#// Copyright (C) 2015 Balthasar SzczepaĆski
#//
#// This program is free software: you can redistribute it and/or modify
#// it under the terms of the GNU Affero General Public License as
#// published by the Free Software Foundation, either version 3 of the
#// License, or (at your option) any later version.
#//
#// This program is distributed in the hope that it will be useful,
#// but WITHOUT ANY WARRANTY; without even the implied warranty of
#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#// GNU Affero General Public License for more details.
#//
#// You should have received a copy of the GNU Affero General Public License
#// along with this program. If not, see .
BEGIN{
automome="/eizm/pro/ong1/mome.pl"
memepath="/eizm/mem/ong1/mome.txt"
for(i=0;i<256;++i)
{
ch=sprintf("%c",i)
hex=sprintf("%02X",i)
dec=sprintf("%u",i)
ch2hex[ch]=hex
ch2dec[ch]=dec
}
if(options ~ /o/)
format="o"
else if(options ~ /u/)
format="u"
else
{
print "Ch*rpin* M*stard!"
exit
}
if(options ~ /d/)
decree=1
if(options ~ /h/)
html=1
if(options ~ /b/)
bbcode=1
if(options ~ /t/)
textonly=1
system (automome" -lc 256 -n 67 -d "memepath(decree!=""?" -t \"[decr]\"":"")" > "tempfile)
if (format=="o")
ongtext=ong(tempfile)
else
ongtext=ung(tempfile)
if(html!="")
print (textonly==""?"":"")preparehtml(ongtext)(textonly==""?"
":"")
if(bbcode!="")
print (textonly==""?"":"")preparebb(ongtext)(textonly==""?"
":"")
if(html=="" && bbcode=="")
print (textonly==""?""htmlescape(ongtext)"
":ongtext)
}
function ong(tempfile, line)
{
while((getline line < tempfile)>0)
{
gsub(/[\r\n]/,"",line)
if(sub(/[AEIOUY]-N-G/,"#O-N-G#",line)>0)
{
close(tempfile)
return line
}
if(sub(/O+N+G+/,"#",line)>0)
{
close(tempfile)
return line
}
if(sub(/DON'T/,"D#ON'G#T",line)>0)
{
close(tempfile)
return line
}
if(sub(/[AEIOUY]NG/,"#ONG#",line)>0)
{
if($0!~/TH\[b\]ONG/)
return line
}
if(sub(/ON /,"#ONG# ",line)>0)
{
close(tempfile)
return line
}
if(sub(/O\.?$/,"#ONG# ",$0)>0)
{
close(tempfile)
return line
}
}
close(tempfile)
return "Ong"
}
function ung(tempfile, line)
{
while((getline line < tempfile)>0)
{
gsub(/[\r\n]/,"",line)
if(sub(/[AEIOUY]-N-G/,"#U-N-G#",line)>0)
{
close(tempfile)
return line
}
if(sub(/U+N+G+/,"#",line)>0)
{
close(tempfile)
return line
}
if(sub(/[AEIOUY]NG/,"#UNG#",line)>0)
{
close(tempfile)
return line
}
if(sub(/UN /,"#UNG# ",line)>0)
{
close(tempfile)
return line
}
if(sub(/U\.?$/,"#UNG# ",$0)>0)
{
close(tempfile)
return line
}
}
close(tempfile)
return "Ung"
}
function preparebb(rh)
{
gsub(/\*\*/,"€",rh)
gsub(/\*[^\*]+\*/,"±&±",rh)
gsub(/±\*/,"[i]",rh)
gsub(/\*±/,"[/i]",rh)
gsub(/€/,"*",rh)
gsub(/__/,"€",rh)
gsub(/_[^_]+_/,"±&±",rh)
gsub(/±_/,"[u]",rh)
gsub(/_±/,"[/u]",rh)
gsub(/€/,"_",rh)
gsub(/##/,"€",rh)
gsub(/#[^#]+#/,"±&±",rh)
gsub(/±#/,"[b]",rh)
gsub(/#±/,"[/b]",rh)
gsub(/€/,"#",rh)
gsub(/\$\$/,"€",rh)
gsub(/\$[^\$]+\$/,"±&±",rh)
gsub(/±\$/,"[size=80]",rh)
gsub(/\$±/,"[/size]",rh)
gsub(/€/,"$",rh)
return (textonly==""?htmlescape(rh):rh)
}
function preparehtml(rh)
{
gsub(/\*\*/,"€",rh)
gsub(/\*[^\*]+\*/,"±&±",rh)
gsub(/±\*/,"«i»",rh)
gsub(/\*±/,"«/i»",rh)
gsub(/€/,"*",rh)
gsub(/__/,"€",rh)
gsub(/_[^_]+_/,"±&±",rh)
gsub(/±_/,"«u»",rh)
gsub(/_±/,"«/u»",rh)
gsub(/€/,"_",rh)
gsub(/##/,"€",rh)
gsub(/#[^#]+#/,"±&±",rh)
gsub(/±#/,"«b»",rh)
gsub(/#±/,"«/b»",rh)
gsub(/€/,"#",rh)
gsub(/\$\$/,"€",rh)
gsub(/\$[^\$]+\$/,"±&±",rh)
gsub(/±\$/,"«span style=\"font-size: 80%;\"»",rh)
gsub(/\$±/,"«/span»",rh)
gsub(/€/,"$",rh)
rh = htmlescape(rh)
gsub(/«/,"<",rh)
gsub(/»/,">",rh)
return rh
}
function htmlescape(name,less,br, len,iii,escaped,ch)
{
len=length(name)
escaped=""
for(iii=1;iii<=len;++iii)
{
ch=substr(name,iii,1);
if(ch ~ /[=<>\r\n\"]/)
escaped = escaped ""ch2dec[ch]";"
else
escaped = escaped ch
}
return escaped
}