HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / tools / convert-proto-tree-new.awk
blobc2403870d8f7b3d4951425d8334292fff6141ddf
1 #!/usr/bin/gawk -f
3 # $Id$
5 function again(i)
7 # shift remaining arguments up
8 for (i = ARGC; i > ARGIND; i--)
9 ARGV[i] = ARGV[i-1]
11 # make sure gawk knows to keep going
12 ARGC++
14 # make current file next to get done
15 ARGV[ARGIND+1] = FILENAME
18 BEGIN {
19 while (getline x) {
20 if (x ~ /^static\s*(int|gint)\s*hf_(.*)=\s*-1/) {
21 hf = gensub(/^static\s*(int|gint)\s*(\S*).*/, "\\2", "g", x)
23 HFS[hf] = ""
26 if (x ~ /\{\s*&hf_(.*)/) {
27 hf = gensub(/\s*\{\s*\&(.*),(.*)/, "\\1", "g", x)
29 if (hf in HFS) {
30 hf_descr = gensub(/\s*\{\s*\&(.*),(.*)/, "\\2", "g", x)
32 do {
33 getline x
34 hf_descr = hf_descr "\n" x
35 # XXX, below regex should check if we have { hf description }},
36 } while (!(hf_descr ~ /[^{}]*}[^{}]*}[^{}]*,/))
38 # get rid of one }
39 hf_descr = gensub(/}\S*},/, "}", "g", hf_descr);
41 HFS[hf] = hf_descr
46 print "#define NEW_PROTO_TREE_API"
47 print "converted " length(HFS) > "/dev/stderr"
49 again()
50 TWOPASS = 1
53 TWOPASS {
54 x = $0
55 do {
56 if (x ~ /^static\s*(int|gint)\s*hf_(.*)=\s*-1/) {
57 hf = gensub(/^static\s*(int|gint)\s*(\S*).*/, "\\2", "g", x)
58 ## XXX, it can have some comment or smth, copy?
60 if (hf in HFS && HFS[hf] != "") {
61 print "static header_field_info " gensub("^hf_", "hfi_", "g", hf) " THIS_HF_INIT =" HFS[hf] ";"
62 print ""
63 } else
64 print x
67 else if (x ~ /\{\s*&hf_(.*)/) {
68 hf = gensub(/\s*\{\s*\&(.*),(.*)/, "\\1", "g", x)
70 if (hf in HFS) {
71 ## keep indent
72 new_x = gensub(/(\s*)\{\s*\&hf_(.*),(.*)/, "\\1\\&" "hfi_" "\\2" ",", "g", x)
74 hf_descr = gensub(/\s*\{\s*\&(.*),(.*)/, "\\2", "g", x)
76 do {
77 getline x
78 hf_descr = hf_descr "\n" x
79 } while (!(hf_descr ~ /}/))
81 print new_x
83 } else
84 print x
85 } else
86 print gensub("hf_", "\\&hfi_", "g", x)
88 } while (getline x);