I wrote a utlity to help convert proto_tree_add_text calls into proto_tree_add_item calls. The script is convert_proto_tree_add_text.pl and it can be found in the tools directory. I wanted to share the data (attached) of my first test run on packet-dlsw.c as a guide to those interested in using the script.
File info:
packet-dlsw.c.original - dlsw dissector file in SVN before I ran convert_proto_tree_add_text.pl
packet-dlsw.c.proto_tree_input.original - original "input" file created when running "generate"
packet-dlsw.c.proto_tree_input - "input" file actually used when running "fix-all"
packet-dlsw.c.proto_tree_add_text.original - output when running "fix-all"
packet-dlsw.c.hf - hf variable declarations that needed to be copied into dissector
packet-dlsw.c.hf_array - hf_register_info items that needed to be copied into dissector
packet-dlsw.c.committed - actual file committed to SVN. Note that I did some additional "cleanup" in addition to merging the hf files
I got lucky in that the dissector passed checkAPIs.pl, checkhf.pl and checkfiltername.pl on the first try. Running them may catch any "typos" in the .proto_tree_input file that a compiler won't. Also note that the script works better on files where tvb_ function (ie tvb_get_guint8) is one of the printf style parameters in the proto_tree_add_text. Having
foo = tvb_get_ntohs(tvb, 42);
proto_tree_add_text(tree, tvb, 42, 2, "My foo: %d", foo);
means more manual editting of the .proto_tree_input file.
Also note that switching to proto_tree_add_item from proto_tree_add_text may generate a lot more "unused variable" warnings from your compiler (like "foo" in the above example). That can be considered part of the "cleanup".
For this particular dissector, it took me less than 30 minutes to update/verify the .proto_tree_input file and the output, which is significantly faster than when I've done things like this by hand.
Attachment:
dlsw.tar.gz
Description: GNU Zip compressed data