diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-08-17 19:35:00 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-08-17 19:35:00 +0000 |
commit | 0c0e568cb1c1edfeb42ac0610479210afc10a2d4 (patch) | |
tree | 77ffa6b7eb73f518c1dee03134be235fe7718d95 /tools | |
parent | 8fc0c287f5c3ee6c6440d4e5c7b615018edff2f8 (diff) |
Commit far from being perfect conversation tool from hfindex to hfinfo.
svn path=/trunk/; revision=51407
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/convert-proto-tree-new.awk | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tools/convert-proto-tree-new.awk b/tools/convert-proto-tree-new.awk new file mode 100755 index 0000000000..c2403870d8 --- /dev/null +++ b/tools/convert-proto-tree-new.awk @@ -0,0 +1,89 @@ +#!/usr/bin/gawk -f + +# $Id$ + +function again(i) +{ + # shift remaining arguments up + for (i = ARGC; i > ARGIND; i--) + ARGV[i] = ARGV[i-1] + + # make sure gawk knows to keep going + ARGC++ + + # make current file next to get done + ARGV[ARGIND+1] = FILENAME +} + +BEGIN { + while (getline x) { + if (x ~ /^static\s*(int|gint)\s*hf_(.*)=\s*-1/) { + hf = gensub(/^static\s*(int|gint)\s*(\S*).*/, "\\2", "g", x) + + HFS[hf] = "" + } + + if (x ~ /\{\s*&hf_(.*)/) { + hf = gensub(/\s*\{\s*\&(.*),(.*)/, "\\1", "g", x) + + if (hf in HFS) { + hf_descr = gensub(/\s*\{\s*\&(.*),(.*)/, "\\2", "g", x) + + do { + getline x + hf_descr = hf_descr "\n" x + # XXX, below regex should check if we have { hf description }}, + } while (!(hf_descr ~ /[^{}]*}[^{}]*}[^{}]*,/)) + + # get rid of one } + hf_descr = gensub(/}\S*},/, "}", "g", hf_descr); + + HFS[hf] = hf_descr + } + } + } + + print "#define NEW_PROTO_TREE_API" + print "converted " length(HFS) > "/dev/stderr" + + again() + TWOPASS = 1 +} + +TWOPASS { + x = $0 + do { + if (x ~ /^static\s*(int|gint)\s*hf_(.*)=\s*-1/) { + hf = gensub(/^static\s*(int|gint)\s*(\S*).*/, "\\2", "g", x) + ## XXX, it can have some comment or smth, copy? + + if (hf in HFS && HFS[hf] != "") { + print "static header_field_info " gensub("^hf_", "hfi_", "g", hf) " THIS_HF_INIT =" HFS[hf] ";" + print "" + } else + print x + } + + else if (x ~ /\{\s*&hf_(.*)/) { + hf = gensub(/\s*\{\s*\&(.*),(.*)/, "\\1", "g", x) + + if (hf in HFS) { + ## keep indent + new_x = gensub(/(\s*)\{\s*\&hf_(.*),(.*)/, "\\1\\&" "hfi_" "\\2" ",", "g", x) + + hf_descr = gensub(/\s*\{\s*\&(.*),(.*)/, "\\2", "g", x) + + do { + getline x + hf_descr = hf_descr "\n" x + } while (!(hf_descr ~ /}/)) + + print new_x + + } else + print x + } else + print gensub("hf_", "\\&hfi_", "g", x) + + } while (getline x); +} |