From Tyson Key:
[obnox/wireshark/wip.git] / print.c
diff --git a/print.c b/print.c
index 876b04d02f7709b39bc6ebd8e1d221d4b204f8b2..0f0014cbb0e11d9e7896459f6fdd64893c8a13e4 100644 (file)
--- a/print.c
+++ b/print.c
@@ -38,6 +38,7 @@
 #include <epan/tvbuff.h>
 #include <epan/packet.h>
 #include <epan/emem.h>
+#include <epan/expert.h>
 
 #include "packet-range.h"
 #include "print.h"
@@ -313,7 +314,7 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                /* Open fake protocol wrapper */
                fputs("<proto name=\"fake-field-wrapper\">\n", pdata->fh);
 
-               /* Indent to increased level before writint out field */
+               /* Indent to increased level before writing out field */
                pdata->level++;
                for (i = -1; i < pdata->level; i++) {
                        fputs("  ", pdata->fh);
@@ -336,7 +337,11 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                print_escaped_xml(pdata->fh, label_ptr);
 
                fprintf(pdata->fh, "\" size=\"%d", fi->length);
-               fprintf(pdata->fh, "\" pos=\"%d", fi->start);
+               if (node->parent && node->parent->finfo && (fi->start < node->parent->finfo->start)) {
+                       fprintf(pdata->fh, "\" pos=\"%d", node->parent->finfo->start + fi->start);
+               } else {
+                       fprintf(pdata->fh, "\" pos=\"%d", fi->start);
+               }
 
                fputs("\" value=\"", pdata->fh);
                write_pdml_field_hex_value(pdata, fi);
@@ -356,11 +361,11 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                /* Write out field with data */
                fputs("<field name=\"data\" value=\"", pdata->fh);
                write_pdml_field_hex_value(pdata, fi);
-               fputs("\"/>\n", pdata->fh);
+               fputs("\">\n", pdata->fh);
        }
        /* Normal protocols and fields */
        else {
-               if (fi->hfinfo->type == FT_PROTOCOL) {
+               if (fi->hfinfo->type == FT_PROTOCOL && fi->hfinfo->id != proto_expert) {
                        fputs("<proto name=\"", pdata->fh);
                }
                else {
@@ -401,7 +406,11 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                        fprintf(pdata->fh, "\" hide=\"yes");
 
                fprintf(pdata->fh, "\" size=\"%d", fi->length);
-               fprintf(pdata->fh, "\" pos=\"%d", fi->start);
+               if (node->parent && node->parent->finfo && (fi->start < node->parent->finfo->start)) {
+                       fprintf(pdata->fh, "\" pos=\"%d", node->parent->finfo->start + fi->start);
+               } else {
+                       fprintf(pdata->fh, "\" pos=\"%d", fi->start);
+               }
 /*             fprintf(pdata->fh, "\" id=\"%d", fi->hfinfo->id);*/
 
                /* show, value, and unmaskedvalue attributes */
@@ -485,13 +494,16 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                        fputs("  ", pdata->fh);
                }
                /* Close off current element */
-               if (fi->hfinfo->id != proto_data) {   /* Data protocol uses simple tags */
+               /* Data and expert "protocols" use simple tags */
+               if (fi->hfinfo->id != proto_data && fi->hfinfo->id != proto_expert) {
                        if (fi->hfinfo->type == FT_PROTOCOL) {
                                fputs("</proto>\n", pdata->fh);
                        }
                        else {
                                fputs("</field>\n", pdata->fh);
                        }
+               } else {
+                       fputs("</field>\n", pdata->fh);
                }
        }