diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2010-08-14 17:24:21 +0000 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2010-08-14 17:24:21 +0000 |
commit | 90cb202dbd4a40861d812f60760586ff64f28bab (patch) | |
tree | f2683d1b9210e369111cbf68a348feb2320ff759 /epan/proto.c | |
parent | 026f4dfa7be71f00851ebcff47c5e04127083eb3 (diff) |
Added proto_item_prepend_text().
svn path=/trunk/; revision=33800
Diffstat (limited to 'epan/proto.c')
-rw-r--r-- | epan/proto.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/epan/proto.c b/epan/proto.c index c4024ea2e7..933479d1fb 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -3677,6 +3677,47 @@ proto_item_append_text(proto_item *pi, const char *format, ...) } } +/* Prepend to text of proto_item after having already been created. */ +void +proto_item_prepend_text(proto_item *pi, const char *format, ...) +{ + field_info *fi = NULL; + char representation[ITEM_LABEL_LENGTH]; + size_t curlen; + va_list ap; + + if (pi==NULL) { + return; + } + + fi = PITEM_FINFO(pi); + if (fi==NULL) { + return; + } + + if (!PROTO_ITEM_IS_HIDDEN(pi)) { + /* + * If we don't already have a representation, + * generate the default representation. + */ + if (fi->rep == NULL) { + ITEM_LABEL_NEW(fi->rep); + proto_item_fill_label(fi, fi->rep->representation); + } + + strcpy(representation, fi->rep->representation); + va_start(ap, format); + g_vsnprintf(fi->rep->representation, + ITEM_LABEL_LENGTH, format, ap); + va_end(ap); + curlen = strlen(fi->rep->representation); + if (ITEM_LABEL_LENGTH > curlen) { + strncpy(fi->rep->representation + curlen, representation, + ITEM_LABEL_LENGTH - (gulong) curlen); + } + } +} + void proto_item_set_len(proto_item *pi, const gint length) { |