From 3f1530d2d6b17ee52e8c4dfc95c0ac062b729ff8 Mon Sep 17 00:00:00 2001 From: Olivier Biot Date: Thu, 5 Feb 2004 23:57:15 +0000 Subject: [PATCH] Add new col_append methods which will prepend the (format) string with the provided separator (or a default ", ") if the column is not empty. svn path=/trunk/; revision=9986 --- epan/column-utils.c | 47 ++++++++++++++++++++++++++++++++++++++++++++- epan/column-utils.h | 9 ++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/epan/column-utils.c b/epan/column-utils.c index 3e8901a608..033dd0bb5d 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -1,7 +1,7 @@ /* column-utils.c * Routines for column utilities. * - * $Id: column-utils.c,v 1.44 2004/01/31 04:10:04 guy Exp $ + * $Id: column-utils.c,v 1.45 2004/02/05 23:57:15 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -291,6 +291,41 @@ col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...) va_end(ap); } +/* Appends a vararg list to a packet info string. + * Prefixes it with the given separator if the column is not empty. */ +void +col_append_sep_fstr(column_info *cinfo, gint el, const gchar *separator, + const gchar *format, ...) +{ + va_list ap; + int i; + size_t len, max_len; + + g_assert(cinfo->col_first[el] >= 0); + if (el == COL_INFO) + max_len = COL_MAX_INFO_LEN; + else + max_len = COL_MAX_LEN; + + if (cinfo->col_buf[0]) { + col_append_str(cinfo, el, separator ? separator : ", "); + } + va_start(ap, format); + for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) { + if (cinfo->fmt_matx[i][el]) { + /* + * First arrange that we can append, if necessary. + */ + COL_CHECK_APPEND(cinfo, i, max_len); + len = strlen(cinfo->col_buf[i]); + vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap); + } + } + va_end(ap); +} + + + /* Prepends a vararg list to a packet info string. */ #define COL_BUF_MAX_LEN (((COL_MAX_INFO_LEN) > (COL_MAX_LEN)) ? \ (COL_MAX_INFO_LEN) : (COL_MAX_LEN)) @@ -398,6 +433,16 @@ col_append_str(column_info *cinfo, gint el, const gchar* str) } } +void +col_append_sep_str(column_info *cinfo, gint el, const gchar* separator, + const gchar* str) +{ + if (cinfo->col_buf[0]) { + col_append_str(cinfo, el, separator ? separator : ", "); + } + col_append_str(cinfo, el, str); +} + static void col_set_abs_date_time(frame_data *fd, column_info *cinfo, int col) { diff --git a/epan/column-utils.h b/epan/column-utils.h index f5afb98e22..426862714a 100644 --- a/epan/column-utils.h +++ b/epan/column-utils.h @@ -1,7 +1,7 @@ /* column-utils.h * Definitions for column utility structures and routines * - * $Id: column-utils.h,v 1.11 2003/04/16 05:55:39 guy Exp $ + * $Id: column-utils.h,v 1.12 2004/02/05 23:57:15 obiot Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -53,15 +53,22 @@ extern void col_add_fstr(column_info *, gint, const gchar *, ...) __attribute__((format (printf, 3, 4))); extern void col_append_fstr(column_info *, gint, const gchar *, ...) __attribute__((format (printf, 3, 4))); +extern void col_append_sep_fstr(column_info *, gint, const gchar *sep, + const gchar *fmt, ...) + __attribute__((format (printf, 4, 5))); extern void col_prepend_fstr(column_info *, gint, const gchar *, ...) __attribute__((format (printf, 3, 4))); #else extern void col_add_fstr(column_info *, gint, const gchar *, ...); extern void col_append_fstr(column_info *, gint, const gchar *, ...); +extern void col_append_sep_fstr(column_info *, gint, const gchar *sep, + const gchar *fmt, ...); extern void col_prepend_fstr(column_info *, gint, const gchar *, ...); #endif extern void col_add_str(column_info *, gint, const gchar *); extern void col_append_str(column_info *, gint, const gchar *); +extern void col_append_sep_str(column_info *, gint, const gchar *sep, + const gchar *str); extern void col_set_cls_time(frame_data *, column_info *, int); extern void fill_in_columns(packet_info *);