Imported Upstream version 1.6.5
[platform/upstream/libksba.git] / tests / mkoidtbl.awk
1 # mkoidtbl.awk  - Create OID table from Peter Gutmann's dumpasn1.cfg
2 # Copyright (C) 2004 g10 Code GmbH
3 #
4 # This file is free software; as a special exception the author gives
5 # unlimited permission to copy and/or distribute it, with or without
6 # modifications, as long as this notice is preserved.
7 #
8 # This file is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
10 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 #
12
13 # This file takes a list of OID description in a format like
14 #
15 #  # Comment line, the next line identifies a new record
16 #  OID = 06 05 02 82 06 01 0A
17 #  Comment = Deutsche Telekom
18 #  Description = Telesec (0 2 262 1 10)
19 #
20 #  And creates a new table in IETF notation with lines like
21 #  0.2.262.1.10 Telesec Deutsche Telekom
22 #  comment lines may also occur in the output.
23 #
24
25
26 BEGIN {
27   print "static struct { char *oid, *desc, *comment; } oidtranstbl[] = {"
28 }
29
30 /^[ \t]*#/ { next }
31 /^OID/     { flush()
32              oid = substr($0, index($0, "=") + 2)
33              gsub (/[ \t]+/, ".", oid)
34 }
35 /^Comment/ { comment = substr($0, index($0, "=") + 2 )
36              gsub(/\r/, "", comment)
37              gsub (/\\/, "\\\\", comment)
38              gsub (/"/, "\\\"", comment)
39              gsub (/\(\?\?\?\)/, "(?)", comment)
40 }
41 /^Description/ {
42   desc = substr($0, index($0, "=") + 2)
43   gsub(/\r/, "", desc)
44   if (match (desc, /\([0-9 \t]+\)/) > 2) {
45     oid = substr(desc, RSTART+1, RLENGTH-2 )
46     desc = substr(desc, 1, RSTART-1);
47   }
48   gsub (/[ \t]+/, ".", oid)
49   gsub (/\\/, "\\\\", desc)
50   gsub (/"/, "\\\"", desc)
51   sub (/[ \t]*$/, "", desc)
52 }
53
54 END { flush();  print "  { NULL, NULL, NULL }\n};"  }
55
56 function flush() {
57   if(oid && desc)
58      printf "  { \"%s\", \"%s\", \"%s\" },\n", oid, desc, comment
59   oid = desc = comment = ""
60 }