# This file is part of Wydawca
# Copyright (C) 2007, 2009, 2010 Sergey Poznyakoff
#
# Wydawca is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# Wydawca 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Wydawca. If not, see .
state == 1 && NF == 1 && $1 == "end" {
print "EOT;"
state = 0
next
}
state == 1 && $1 == "include" {
printf("m4_include(%s)\n",$2)
next
}
state == 1 { gsub(/%%/, "~~~")
gsub(/%/, "$")
gsub(/~~~/, "%")
print $0
next
}
/[ \t]*#/ { print; next }
NF == 0 { print; next }
{ if (!text) start_line = NR }
/\\$/ { text = text substr($0, 1, length($0)-1); next }
{ if (text) $0 = text $0; text = "" }
$1 == "statistics" { printf("%s;\n", $0); next }
$1 == "syslog-facility" { syslog_facility = $2; next }
$1 == "syslog-tag" { sub(($1 "[ \t]*"),"")
syslog_tag = $0
next }
$1 == "syslog-print-priority" {
sub(($1 "[ \t]*"),"")
syslog_print_prio = $0
next }
function get_indent( i, len) {
len = length($0)
gsub(/^[ \t]*/,"")
return len - length($0)
}
function indent(len) {
while (len--)
printf(" ")
}
$1 == "enable-sendfile" { next }
$1 == "file-sweep-time" || $1 == "tar-program" || $1 == "admin-address" ||
$1 == "from-address" || $1 == "host" || $1 == "database" ||
$1 == "user" || $1 == "password" ||
$1 == "source" || $1 == "destination"{
len = get_indent()
kw = $1
sub(($1 "[ \t]*"),"")
indent(len)
printf("%s \"%s\";\n", kw, $0)
next
}
$1 == "umask" {
len = get_indent()
kw = $1
sub(($1 "[ \t]*"),"")
indent(len)
printf("%s %s;\n", kw, $0)
next
}
$1 == "archive" {
len = get_indent()
kw = $1
indent(len)
printf("archive %s", $2)
if (NF > 2) {
print " {"
indent(len + 2)
printf("name \"%s\";\n", $3)
if (NF > 3) {
indent(len + 2)
printf("backup %s;\n", $4)
}
indent(len)
print "}"
} else
print ";"
}
$1 == "project-owner" || $1 == "user-data" || $1 == "verify-user" ||
$1 == "gpg-key" {
len = get_indent()
indent(len)
printf("access-method %s {\n", $1);
indent(len + 2)
printf("type %s;\n", $2)
if (NF > 2) {
if (NF > 3) {
indent(len + 2)
printf("query \"");
for (i = 4; i < NF; i++)
printf("%s ", $i)
printf("%s\"", $NF)
print ";"
}
indent(len + 2)
printf("params (%s);\n", $3)
}
indent(len)
print("}")
next
}
$1 == "sql" {
printf("sql %s {\n", $2);
next
}
$1 == "directory" {
printf("spool ")
if (NF > 1)
printf("%s ", $2)
print "{"
next
}
$1 == "end" { print "}"; next }
$1 == "mail-admin-stat" {
print "mail-statistics {"
printf(" message @%s;\n", $2);
if (NF > 2) {
printf(" statistics");
for (i = 3; i <= NF; i++)
printf(" %s", $i)
print ";"
}
print "}"
next
}
$1 == "notify-event" {
printf("notify-event {\n");
printf(" event %s;\n", $2);
printf(" recipient %s;\n", $3);
printf(" message @%s;\n", $4);
print "}"
next
}
$1 == "define-message" {
print "define-message", $2, "<\n", $2);
}
END {
if (syslog_facility || syslog_tag || syslog_print_prio) {
print "syslog {"
if (syslog_facility)
printf(" facility %s;\n", syslog_facility);
if (syslog_tag)
printf(" tag %s;\n", syslog_tag);
if (syslog_print_prio)
printf(" print-priority %s;\n", syslog_print_prio);
print "}"
}
}