CODE: [Copy to clipboard]
###########################################################
# Batch2ubb.awk -V0.2 -- 批处理转 UBB 代码脚本
# 无奈何 - 2005-7-2 -- GAWK 脚本
###########################################################
#读取配置文件,获取关键字
BEGIN {
IGNORECASE=1
while ((getline<"batch.esy") >0){
if ($0!~/^[ \t]*;/ && $0!~/^$/) {
if ($0~/^[ \t]*#LINECOMMENT=/){
LineComment=substr($0,index($0,"=")+1)
} else if ($0~/^[ \t]*#VARIABLE=/){
Variable=substr($0,index($0,"=")+1)
} else if ($0~/^[ \t]*#PARAMETER=/){
Parameter=substr($0,index($0,"=")+1)
} else if ($0~/^[ \t]*#LABEL=/){
Label=substr($0,index($0,"=")+1)
} else if ($0~/^[ \t]*#KEYWORD/){
color[++i]=substr($0,index($0,"=")+1)
} else {
keyword[$0]=color[i]
}
}
}
print "[quote]"
if (line) print "[list=1]"
}
#主程序开始
{
before="[color=]"
after="[/color]"
#处理注释行及标签行
if (($0~/^[ \t]*::/) || ($0~/^[ \t]*REM\>/)){
gsub(/=.*]/,"=" LineComment "]",before)
$0=before $0 after
}else if ($0~/^[ \t]*:[^:]+/){
gsub(/=.*]/,"=" Label "]",before)
$0=before $0 after
} else {
temp=$0
#分割出关键字
gsub(/[][ \t,;'`~:+"=()<>{}^&|@\.]+/,"□",temp)
gsub(/(^□|□$)/,"",temp)
len=split(temp,word,"□+")
for (i=1;i<=len;i++){
# COLOR 关键字与 UBB 颜色字符重叠,单独处理
if (word[i]~/COLOR/){
if(!fcolor){
gsub(/=.*]/,"=" keyword["COLOR"] "]",before)
gsub("\\<" word[i] "\\>",before "&" after,$0)
delete word[i]
fcolor=1
} else
delete word[i]
}
#删除重复关键字
for (j=i+1;j<=len;j++){
if (word[i]==word[j])
delete word[j]
}
}
for (i=1;i<=len;i++){
for (aa in keyword){
if (aa==toupper(word[i])){
gsub(/=.*]/,"=" keyword[aa] "]",before)
gsub("\\<" word[i] "\\>",before "&" after,$0)
}
}
}
#处理变量及命令参数等细节部分
gsub(/=.*]/,"=" Variable "]",before)
gsub (/%+[A-Za-z0-9:~]*%?/,before "&" after,$0)
gsub (/!+[A-Za-z0-9:~]*!*/,before "&" after,$0)
gsub(/=.*]/,"=" Parameter "]",before)
gsub (/ \/[A-Za-z?\-]+/,before "&" after,$0)
gsub (/(\(|\))/,"[b]&[/b]",$0)
gsub (/(\")/,"[b]&[/b]",$0)
}
if (line) print "[*]" $0
else print $0
}
END {
if (line) printf "[/list]"
#添加时间戳自行修改作者名
print "[color=White]" strftime("\t无奈何发表于: %Y-%m-%d %H:%M") "[/color]"
print "[/quote]"
}
所有文件打包下载见附件: