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
This commit is contained in:
Olivier Biot 2004-02-05 23:57:15 +00:00
parent d2d98c3891
commit 3f1530d2d6
2 changed files with 54 additions and 2 deletions

View File

@ -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 <gerald@ethereal.com>
@ -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)
{

View File

@ -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 <gerald@ethereal.com>
@ -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 *);