Revert "cmake: fix version check for c-ares and gnuTLS"
[metze/wireshark/wip.git] / tools / convert-proto-tree-new.awk
1 #!/usr/bin/gawk -f
2
3 function again(i)
4 {
5  # shift remaining arguments up
6  for (i = ARGC; i > ARGIND; i--)
7      ARGV[i] = ARGV[i-1]
8
9  # make sure gawk knows to keep going
10  ARGC++
11
12  # make current file next to get done
13  ARGV[ARGIND+1] = FILENAME
14 }
15
16 BEGIN {
17         while (getline x) {
18                 if (x ~ /^static\s*(int|gint)\s*hf_(.*)=\s*-1/) {
19                         hf = gensub(/^static\s*(int|gint)\s*(\S*).*/, "\\2", "g", x)
20
21                         HFS[hf] = ""
22                 }
23
24                 if (x ~ /\{\s*&hf_(.*)/) {
25                         hf = gensub(/\s*\{\s*\&(.*),(.*)/, "\\1", "g", x)
26
27                         if (hf in HFS) {
28                                 hf_descr = gensub(/\s*\{\s*\&(.*),(.*)/, "\\2", "g", x)
29
30                                 do { 
31                                         getline x
32                                         hf_descr = hf_descr "\n" x
33                                         # XXX, below regex should check if we have { hf description }},
34                                 } while (!(hf_descr ~ /[^{}]*}[^{}]*}[^{}]*,/))
35
36                                 # get rid of one }
37                                 hf_descr = gensub(/}\S*},/, "}", "g", hf_descr);
38
39                                 HFS[hf] = hf_descr
40                         }
41                 }
42         }
43
44         print "#define NEW_PROTO_TREE_API"
45         print "converted " length(HFS) > "/dev/stderr"
46
47         again()
48         TWOPASS = 1
49 }
50
51 TWOPASS {
52         x = $0
53         do {
54                 if (x ~ /^static\s*(int|gint)\s*hf_(.*)=\s*-1/) {
55                         hf = gensub(/^static\s*(int|gint)\s*(\S*).*/, "\\2", "g", x)
56                         ## XXX, it can have some comment or smth, copy?
57
58                         if (hf in HFS && HFS[hf] != "") {
59                                 print "static header_field_info " gensub("^hf_", "hfi_", "g", hf) " THIS_HF_INIT =" HFS[hf] ";"
60                                 print ""
61                         } else
62                                 print x
63                 }
64
65                 else if (x ~ /\{\s*&hf_(.*)/) {
66                         hf = gensub(/\s*\{\s*\&(.*),(.*)/, "\\1", "g", x)
67
68                         if (hf in HFS) {
69                                 ## keep indent
70                                 new_x = gensub(/(\s*)\{\s*\&hf_(.*),(.*)/, "\\1\\&" "hfi_" "\\2" ",", "g", x)
71
72                                 hf_descr = gensub(/\s*\{\s*\&(.*),(.*)/, "\\2", "g", x)
73
74                                 do {
75                                         getline x
76                                         hf_descr = hf_descr "\n" x
77                                 } while (!(hf_descr ~ /}/))
78
79                                 print new_x
80
81                         } else
82                                 print x
83                 } else
84                         print gensub("hf_", "\\&hfi_", "g", x)
85
86         } while (getline x);
87 }