File: dns_maketab.awk

package info (click to toggle)
rbldnsd 0.998b~pre1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 744 kB
  • ctags: 1,132
  • sloc: ansic: 8,212; python: 549; sh: 502; makefile: 249; awk: 33
file content (42 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/awk -f
# A script to generate dns_nametab.c from dns.h
# (various name tables like rtype etc)

BEGIN {
  n = ""
  s = ""
  print "/* file automatically generated */"
  print "#include \"dns.h\""
  print "#include <stdio.h>"
}

/^enum dns_/ {
  n = substr($2,5)
  #print "\n#ifdef gen_" n "tab"
  print "\nconst struct dns_nameval dns_" n "tab[] = {"
  i = 0
  next
}

n != "" && /^[ 	]+DNS_[A-Z]_[A-Z0-9_]+[ 	]+=/ {
  print " {"$1",\"" substr($1,7) "\"},"
  s = s "\n case "$1": return dns_" n "tab["i"].name;"
  ++i
  next
}

n != "" && /^}/ {
  print " {0,0}"
  print "};\n"
  print "const char *dns_" n "name(enum dns_" n " code) {"
  print " static char buf[20];"
  print " switch(code) {" s
  print " }"
  print " sprintf(buf, \"" n "%d\", code);"
  print " return buf;"
  print "}"
  #print "#endif /* " n "tab */"
  s = ""
  n = ""
  next
}