1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# Convert global.def file to .h or .texi format.
# Copyright (C) 2011-2018 Sergey Poznyakoff
#
# Mailfromd 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.
#
# Mailfromd 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 Mailfromd. If not, see <http://www.gnu.org/licenses/>.
BEGIN {
if (format == "C") {
comment[0] = "/*"
comment[1] = " *"
comment[2] = " */"
} else if (format == "texinfo") {
comment[0] = "@c"
comment[1] = "@c"
comment[2] = ""
} else {
print "usage: awk -f global.awk -v format={C|texinfo}" > "/dev/stderr"
exit 1
}
print comment[0] " -*- buffer-read-only: t -*- vi: set ro:"
print comment[1] " THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT."
if (comment[2]) print comment[2]
if (format == "C") {
print "#ifndef __MAILFROMD_GLOBAL_H"
print "#define __MAILFROMD_GLOBAL_H"
}
}
END {
if (format == "C")
print "#endif"
}
function output(keyword, value) {
if (format == "C") {
print "#line",NR,("\"" FILENAME "\"")
print "#define",keyword,value
} else if (format == "texinfo") {
if (match(value,/^".*"$/))
value = substr(value,2,RLENGTH-2)
print "@set",keyword,value
}
}
state == 0 && /^#/ { print comment[0] substr($0,2); state = 1; next }
state == 1 && /^#/ { print comment[1] substr($0,2); next }
state == 1 { if (comment[2]) print comment[2]; state = 0 }
/^@/ { if (format == "texinfo") print; next }
{ sub(/#.*/,""); }
NF == 0 { next }
{ keyword=$1;
sub((keyword "[ \t][ \t]*"), "")
value = $0;
if (match(value, "`[^`]*`")) {
newval = ""
do {
newval = newval substr(value, 1, RSTART - 1)
cmd = substr(value, RSTART+1, RLENGTH-2)
while ((cmd | getline) > 0)
newval = newval $0
close(cmd)
value = substr(value, RSTART+RLENGTH)
} while (match(value, "`[^`]*`"))
value = (newval value)
} else if (match(value, "^@")) {
file = substr(value, 2)
while ((getline < file) > 0) {
if ($1 == "#define" && $2 == keyword) {
sub(("#define " keyword "[ \t][ \t]*"), "")
value = $0
if (format == "texinfo")
output(keyword, value)
next
}
}
print FILENAME ":" NR ": definition of " keyword " not found in " file > "/dev/stderr"
next
}
output(keyword, value)
}
|