Use consistent indentation & formatting style.

svn path=/trunk/; revision=47727
This commit is contained in:
Bill Meier 2013-02-18 01:59:17 +00:00
parent 1c289aa89a
commit 6bdb92dd8a

203
print.c
View file

@ -71,7 +71,7 @@ typedef struct {
} write_pdml_data; } write_pdml_data;
typedef struct { typedef struct {
output_fields_t* fields; output_fields_t *fields;
epan_dissect_t *edt; epan_dissect_t *edt;
} write_field_data_t; } write_field_data_t;
@ -80,9 +80,9 @@ struct _output_fields {
gchar separator; gchar separator;
gchar occurrence; gchar occurrence;
gchar aggregator; gchar aggregator;
GPtrArray* fields; GPtrArray *fields;
GHashTable* field_indicies; GHashTable *field_indicies;
GPtrArray** field_values; GPtrArray **field_values;
gchar quote; gchar quote;
gboolean includes_col_fields; gboolean includes_col_fields;
}; };
@ -91,7 +91,7 @@ GHashTable *output_only_tables = NULL;
static gboolean write_headers = FALSE; static gboolean write_headers = FALSE;
static const gchar* get_field_hex_value(GSList* src_list, field_info *fi); static const gchar *get_field_hex_value(GSList *src_list, field_info *fi);
static void proto_tree_print_node(proto_node *node, gpointer data); static void proto_tree_print_node(proto_node *node, gpointer data);
static void proto_tree_write_node_pdml(proto_node *node, gpointer data); static void proto_tree_write_node_pdml(proto_node *node, gpointer data);
static const guint8 *get_field_data(GSList *src_list, field_info *fi); static const guint8 *get_field_data(GSList *src_list, field_info *fi);
@ -202,8 +202,8 @@ void proto_tree_print_node(proto_node *node, gpointer data)
* subitems whose abbreviation doesn't match the protocol--for example * subitems whose abbreviation doesn't match the protocol--for example
* text items (whose abbreviation is simply "text"). * text items (whose abbreviation is simply "text").
*/ */
if (output_only_tables != NULL && pdata->level == 0 if ((output_only_tables != NULL) && (pdata->level == 0)
&& g_hash_table_lookup(output_only_tables, fi->hfinfo->abbrev) == NULL) { && (g_hash_table_lookup(output_only_tables, fi->hfinfo->abbrev) == NULL)) {
pdata->success = TRUE; pdata->success = TRUE;
return; return;
} }
@ -214,7 +214,7 @@ void proto_tree_print_node(proto_node *node, gpointer data)
/* If it's uninterpreted data, dump it (unless our caller will /* If it's uninterpreted data, dump it (unless our caller will
be printing the entire packet in hex). */ be printing the entire packet in hex). */
if (fi->hfinfo->id == proto_data && pdata->print_hex_for_data) { if ((fi->hfinfo->id == proto_data) && (pdata->print_hex_for_data)) {
/* /*
* Find the data for this field. * Find the data for this field.
*/ */
@ -235,10 +235,10 @@ void proto_tree_print_node(proto_node *node, gpointer data)
/* If we're printing all levels, or if this node is one with a /* If we're printing all levels, or if this node is one with a
subtree and its subtree is expanded, recurse into the subtree, subtree and its subtree is expanded, recurse into the subtree,
if it exists. */ if it exists. */
g_assert(fi->tree_type >= -1 && fi->tree_type < num_tree_types); g_assert((fi->tree_type >= -1) && (fi->tree_type < num_tree_types));
if (pdata->print_dissections == print_dissections_expanded || if ((pdata->print_dissections == print_dissections_expanded) ||
(pdata->print_dissections == print_dissections_as_displayed && ((pdata->print_dissections == print_dissections_as_displayed) &&
fi->tree_type >= 0 && tree_is_expanded[fi->tree_type])) { (fi->tree_type >= 0) && tree_is_expanded[fi->tree_type])) {
if (node->first_child != NULL) { if (node->first_child != NULL) {
pdata->level++; pdata->level++;
proto_tree_children_foreach(node, proto_tree_children_foreach(node,
@ -252,11 +252,12 @@ void proto_tree_print_node(proto_node *node, gpointer data)
#define PDML2HTML_XSL "pdml2html.xsl" #define PDML2HTML_XSL "pdml2html.xsl"
void void
write_pdml_preamble(FILE *fh, const gchar* filename) write_pdml_preamble(FILE *fh, const gchar *filename)
{ {
time_t t=time(NULL); time_t t = time(NULL);
char *ts=asctime(localtime(&t)); char *ts = asctime(localtime(&t));
ts[strlen(ts)-1]=0; /* overwrite \n */
ts[strlen(ts)-1] = 0; /* overwrite \n */
fputs("<?xml version=\"1.0\"?>\n", fh); fputs("<?xml version=\"1.0\"?>\n", fh);
fputs("<?xml-stylesheet type=\"text/xsl\" href=\"" PDML2HTML_XSL "\"?>\n", fh); fputs("<?xml-stylesheet type=\"text/xsl\" href=\"" PDML2HTML_XSL "\"?>\n", fh);
@ -370,7 +371,7 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
} }
/* Normal protocols and fields */ /* Normal protocols and fields */
else { else {
if (fi->hfinfo->type == FT_PROTOCOL && fi->hfinfo->id != proto_expert) { if ((fi->hfinfo->type == FT_PROTOCOL) && (fi->hfinfo->id != proto_expert)) {
fputs("<proto name=\"", pdata->fh); fputs("<proto name=\"", pdata->fh);
} }
else { else {
@ -500,7 +501,7 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
} }
/* Close off current element */ /* Close off current element */
/* Data and expert "protocols" use simple tags */ /* Data and expert "protocols" use simple tags */
if (fi->hfinfo->id != proto_data && fi->hfinfo->id != proto_expert) { if ((fi->hfinfo->id != proto_data) && (fi->hfinfo->id != proto_expert)) {
if (fi->hfinfo->type == FT_PROTOCOL) { if (fi->hfinfo->type == FT_PROTOCOL) {
fputs("</proto>\n", pdata->fh); fputs("</proto>\n", pdata->fh);
} }
@ -572,32 +573,32 @@ print_pdml_geninfo(proto_tree *tree, FILE *fh)
/* Print geninfo start */ /* Print geninfo start */
fprintf(fh, fprintf(fh,
" <proto name=\"geninfo\" pos=\"0\" showname=\"General information\" size=\"%u\">\n", " <proto name=\"geninfo\" pos=\"0\" showname=\"General information\" size=\"%u\">\n",
frame_finfo->length); frame_finfo->length);
/* Print geninfo.num */ /* Print geninfo.num */
fprintf(fh, fprintf(fh,
" <field name=\"num\" pos=\"0\" show=\"%u\" showname=\"Number\" value=\"%x\" size=\"%u\"/>\n", " <field name=\"num\" pos=\"0\" show=\"%u\" showname=\"Number\" value=\"%x\" size=\"%u\"/>\n",
num, num, frame_finfo->length); num, num, frame_finfo->length);
/* Print geninfo.len */ /* Print geninfo.len */
fprintf(fh, fprintf(fh,
" <field name=\"len\" pos=\"0\" show=\"%u\" showname=\"Frame Length\" value=\"%x\" size=\"%u\"/>\n", " <field name=\"len\" pos=\"0\" show=\"%u\" showname=\"Frame Length\" value=\"%x\" size=\"%u\"/>\n",
len, len, frame_finfo->length); len, len, frame_finfo->length);
/* Print geninfo.caplen */ /* Print geninfo.caplen */
fprintf(fh, fprintf(fh,
" <field name=\"caplen\" pos=\"0\" show=\"%u\" showname=\"Captured Length\" value=\"%x\" size=\"%u\"/>\n", " <field name=\"caplen\" pos=\"0\" show=\"%u\" showname=\"Captured Length\" value=\"%x\" size=\"%u\"/>\n",
caplen, caplen, frame_finfo->length); caplen, caplen, frame_finfo->length);
/* Print geninfo.timestamp */ /* Print geninfo.timestamp */
fprintf(fh, fprintf(fh,
" <field name=\"timestamp\" pos=\"0\" show=\"%s\" showname=\"Captured Time\" value=\"%d.%09d\" size=\"%u\"/>\n", " <field name=\"timestamp\" pos=\"0\" show=\"%s\" showname=\"Captured Time\" value=\"%d.%09d\" size=\"%u\"/>\n",
abs_time_to_str(timestamp, ABSOLUTE_TIME_LOCAL, TRUE), (int) timestamp->secs, timestamp->nsecs, frame_finfo->length); abs_time_to_str(timestamp, ABSOLUTE_TIME_LOCAL, TRUE), (int) timestamp->secs, timestamp->nsecs, frame_finfo->length);
/* Print geninfo end */ /* Print geninfo end */
fprintf(fh, fprintf(fh,
" </proto>\n"); " </proto>\n");
} }
void void
@ -621,10 +622,10 @@ proto_tree_write_psml(epan_dissect_t *edt, FILE *fh)
gint i; gint i;
/* if this is the first packet, we have to create the PSML structure output */ /* if this is the first packet, we have to create the PSML structure output */
if(write_headers) { if (write_headers) {
fprintf(fh, "<structure>\n"); fprintf(fh, "<structure>\n");
for(i=0; i < edt->pi.cinfo->num_cols; i++) { for (i = 0; i < edt->pi.cinfo->num_cols; i++) {
fprintf(fh, "<section>"); fprintf(fh, "<section>");
print_escaped_xml(fh, edt->pi.cinfo->col_title[i]); print_escaped_xml(fh, edt->pi.cinfo->col_title[i]);
fprintf(fh, "</section>\n"); fprintf(fh, "</section>\n");
@ -637,7 +638,7 @@ proto_tree_write_psml(epan_dissect_t *edt, FILE *fh)
fprintf(fh, "<packet>\n"); fprintf(fh, "<packet>\n");
for(i=0; i < edt->pi.cinfo->num_cols; i++) { for (i = 0; i < edt->pi.cinfo->num_cols; i++) {
fprintf(fh, "<section>"); fprintf(fh, "<section>");
print_escaped_xml(fh, edt->pi.cinfo->col_data[i]); print_escaped_xml(fh, edt->pi.cinfo->col_data[i]);
fprintf(fh, "</section>\n"); fprintf(fh, "</section>\n");
@ -685,14 +686,14 @@ proto_tree_write_csv(epan_dissect_t *edt, FILE *fh)
gint i; gint i;
/* if this is the first packet, we have to write the CSV header */ /* if this is the first packet, we have to write the CSV header */
if(write_headers) { if (write_headers) {
for(i=0; i < edt->pi.cinfo->num_cols - 1; i++) for (i = 0; i < edt->pi.cinfo->num_cols - 1; i++)
csv_write_str(edt->pi.cinfo->col_title[i], ',', fh); csv_write_str(edt->pi.cinfo->col_title[i], ',', fh);
csv_write_str(edt->pi.cinfo->col_title[i], '\n', fh); csv_write_str(edt->pi.cinfo->col_title[i], '\n', fh);
write_headers = FALSE; write_headers = FALSE;
} }
for(i=0; i < edt->pi.cinfo->num_cols - 1; i++) for (i = 0; i < edt->pi.cinfo->num_cols - 1; i++)
csv_write_str(edt->pi.cinfo->col_data[i], ',', fh); csv_write_str(edt->pi.cinfo->col_data[i], ',', fh);
csv_write_str(edt->pi.cinfo->col_data[i], '\n', fh); csv_write_str(edt->pi.cinfo->col_data[i], '\n', fh);
} }
@ -714,12 +715,12 @@ proto_tree_write_carrays(guint32 num, FILE *fh, epan_dissect_t *edt)
{ {
guint32 i = 0, src_num = 0; guint32 i = 0, src_num = 0;
GSList *src_le; GSList *src_le;
struct data_source *src;
tvbuff_t *tvb; tvbuff_t *tvb;
const char *name; const char *name;
const guchar *cp; const guchar *cp;
guint length; guint length;
char ascii[9]; char ascii[9];
struct data_source *src;
for (src_le = edt->pi.data_src; src_le != NULL; src_le = src_le->next) { for (src_le = edt->pi.data_src; src_le != NULL; src_le = src_le->next) {
memset(ascii, 0, sizeof(ascii)); memset(ascii, 0, sizeof(ascii));
@ -790,9 +791,9 @@ static const guint8 *
get_field_data(GSList *src_list, field_info *fi) get_field_data(GSList *src_list, field_info *fi)
{ {
GSList *src_le; GSList *src_le;
struct data_source *src;
tvbuff_t *src_tvb; tvbuff_t *src_tvb;
gint length, tvbuff_length; gint length, tvbuff_length;
struct data_source *src;
for (src_le = src_list; src_le != NULL; src_le = src_le->next) { for (src_le = src_list; src_le != NULL; src_le = src_le->next) {
src = (struct data_source *)src_le->data; src = (struct data_source *)src_le->data;
@ -889,12 +890,12 @@ print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
{ {
gboolean multiple_sources; gboolean multiple_sources;
GSList *src_le; GSList *src_le;
struct data_source *src;
tvbuff_t *tvb; tvbuff_t *tvb;
const char *name; const char *name;
char *line; char *line;
const guchar *cp; const guchar *cp;
guint length; guint length;
struct data_source *src;
/* /*
* Set "multiple_sources" iff this frame has more than one * Set "multiple_sources" iff this frame has more than one
@ -935,15 +936,15 @@ print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
#define MAX_OFFSET_LEN 8 /* max length of hex offset of bytes */ #define MAX_OFFSET_LEN 8 /* max length of hex offset of bytes */
#define BYTES_PER_LINE 16 /* max byte values printed on a line */ #define BYTES_PER_LINE 16 /* max byte values printed on a line */
#define HEX_DUMP_LEN (BYTES_PER_LINE*3) #define HEX_DUMP_LEN (BYTES_PER_LINE*3)
/* max number of characters hex dump takes - /* max number of characters hex dump takes -
2 digits plus trailing blank */ 2 digits plus trailing blank */
#define DATA_DUMP_LEN (HEX_DUMP_LEN + 2 + BYTES_PER_LINE) #define DATA_DUMP_LEN (HEX_DUMP_LEN + 2 + BYTES_PER_LINE)
/* number of characters those bytes take; /* number of characters those bytes take;
3 characters per byte of hex dump, 3 characters per byte of hex dump,
2 blanks separating hex from ASCII, 2 blanks separating hex from ASCII,
1 character per byte of ASCII dump */ 1 character per byte of ASCII dump */
#define MAX_LINE_LEN (MAX_OFFSET_LEN + 2 + DATA_DUMP_LEN) #define MAX_LINE_LEN (MAX_OFFSET_LEN + 2 + DATA_DUMP_LEN)
/* number of characters per line; /* number of characters per line;
offset, 2 blanks separating offset offset, 2 blanks separating offset
from data dump, data dump */ from data dump, data dump */
@ -1007,9 +1008,9 @@ print_hex_data_buffer(print_stream_t *stream, const guchar *cp,
if (encoding == PACKET_CHAR_ENC_CHAR_EBCDIC) { if (encoding == PACKET_CHAR_ENC_CHAR_EBCDIC) {
c = EBCDIC_to_ASCII1(c); c = EBCDIC_to_ASCII1(c);
} }
line[k++] = c >= ' ' && c < 0x7f ? c : '.'; line[k++] = ((c >= ' ') && (c < 0x7f)) ? c : '.';
i++; i++;
if ((i & 15) == 0 || i == length) { if (((i & 15) == 0) || (i == length)) {
/* /*
* We'll be starting a new line, or * We'll be starting a new line, or
* we're finished printing this buffer; * we're finished printing this buffer;
@ -1324,9 +1325,9 @@ print_stream_ps_stdio_new(FILE *fh)
return print_stream_ps_alloc(TRUE, fh); return print_stream_ps_alloc(TRUE, fh);
} }
output_fields_t* output_fields_new(void) output_fields_t *output_fields_new(void)
{ {
output_fields_t* fields = g_new(output_fields_t, 1); output_fields_t *fields = g_new(output_fields_t, 1);
fields->print_header = FALSE; fields->print_header = FALSE;
fields->separator = '\t'; fields->separator = '\t';
fields->occurrence = 'a'; fields->occurrence = 'a';
@ -1334,44 +1335,44 @@ output_fields_t* output_fields_new(void)
fields->fields = NULL; /*Do lazy initialisation */ fields->fields = NULL; /*Do lazy initialisation */
fields->field_indicies = NULL; fields->field_indicies = NULL;
fields->field_values = NULL; fields->field_values = NULL;
fields->quote='\0'; fields->quote = '\0';
fields->includes_col_fields = FALSE; fields->includes_col_fields = FALSE;
return fields; return fields;
} }
gsize output_fields_num_fields(output_fields_t* fields) gsize output_fields_num_fields(output_fields_t *fields)
{ {
g_assert(fields); g_assert(fields);
if(NULL == fields->fields) { if (NULL == fields->fields) {
return 0; return 0;
} else { } else {
return fields->fields->len; return fields->fields->len;
} }
} }
void output_fields_free(output_fields_t* fields) void output_fields_free(output_fields_t *fields)
{ {
g_assert(fields); g_assert(fields);
if(NULL != fields->field_indicies) { if (NULL != fields->field_indicies) {
/* Keys are stored in fields->fields, values are /* Keys are stored in fields->fields, values are
* integers. * integers.
*/ */
g_hash_table_destroy(fields->field_indicies); g_hash_table_destroy(fields->field_indicies);
} }
if(NULL != fields->field_values) { if (NULL != fields->field_values) {
gsize i; gsize i;
for(i = 0; i < fields->fields->len; ++i) { for (i = 0; i < fields->fields->len; ++i) {
GPtrArray* fv_p; GPtrArray *fv_p;
fv_p = fields->field_values[i]; fv_p = fields->field_values[i];
g_ptr_array_free(fv_p, TRUE); g_ptr_array_free(fv_p, TRUE);
} }
} }
if(NULL != fields->fields) { if (NULL != fields->fields) {
gsize i; gsize i;
for(i = 0; i < fields->fields->len; ++i) { for (i = 0; i < fields->fields->len; ++i) {
gchar* field = (gchar *)g_ptr_array_index(fields->fields,i); gchar *field = (gchar *)g_ptr_array_index(fields->fields, i);
g_free(field); g_free(field);
} }
g_ptr_array_free(fields->fields, TRUE); g_ptr_array_free(fields->fields, TRUE);
@ -1382,15 +1383,15 @@ void output_fields_free(output_fields_t* fields)
#define COLUMN_FIELD_FILTER "col." #define COLUMN_FIELD_FILTER "col."
void output_fields_add(output_fields_t* fields, const gchar* field) void output_fields_add(output_fields_t *fields, const gchar *field)
{ {
gchar* field_copy; gchar *field_copy;
g_assert(fields); g_assert(fields);
g_assert(field); g_assert(field);
if(NULL == fields->fields) { if (NULL == fields->fields) {
fields->fields = g_ptr_array_new(); fields->fields = g_ptr_array_new();
} }
@ -1404,24 +1405,24 @@ void output_fields_add(output_fields_t* fields, const gchar* field)
} }
gboolean output_fields_set_option(output_fields_t* info, gchar* option) gboolean output_fields_set_option(output_fields_t *info, gchar *option)
{ {
const gchar* option_name; const gchar *option_name;
const gchar* option_value; const gchar *option_value;
g_assert(info); g_assert(info);
g_assert(option); g_assert(option);
if('\0' == *option) { if ('\0' == *option) {
return FALSE; /* Is this guarded against by option parsing? */ return FALSE; /* Is this guarded against by option parsing? */
} }
option_name = strtok(option,"="); option_name = strtok(option, "=");
if (!option_name) { if (!option_name) {
return FALSE; return FALSE;
} }
option_value = option + strlen(option_name) + 1; option_value = option + strlen(option_name) + 1;
if(0 == strcmp(option_name, "header")) { if (0 == strcmp(option_name, "header")) {
switch(NULL == option_value ? '\0' : *option_value) { switch (NULL == option_value ? '\0' : *option_value) {
case 'n': case 'n':
info->print_header = FALSE; info->print_header = FALSE;
break; break;
@ -1434,12 +1435,12 @@ gboolean output_fields_set_option(output_fields_t* info, gchar* option)
return TRUE; return TRUE;
} }
if(0 == strcmp(option_name,"separator")) { if (0 == strcmp(option_name, "separator")) {
switch(NULL == option_value ? '\0' : *option_value) { switch (NULL == option_value ? '\0' : *option_value) {
case '\0': case '\0':
return FALSE; return FALSE;
case '/': case '/':
switch(*++option_value) { switch (*++option_value) {
case 't': case 't':
info->separator = '\t'; info->separator = '\t';
break; break;
@ -1457,8 +1458,8 @@ gboolean output_fields_set_option(output_fields_t* info, gchar* option)
return TRUE; return TRUE;
} }
if(0 == strcmp(option_name, "occurrence")) { if (0 == strcmp(option_name, "occurrence")) {
switch(NULL == option_value ? '\0' : *option_value) { switch (NULL == option_value ? '\0' : *option_value) {
case 'f': case 'f':
case 'l': case 'l':
case 'a': case 'a':
@ -1470,12 +1471,12 @@ gboolean output_fields_set_option(output_fields_t* info, gchar* option)
return TRUE; return TRUE;
} }
if(0 == strcmp(option_name,"aggregator")) { if (0 == strcmp(option_name, "aggregator")) {
switch(NULL == option_value ? '\0' : *option_value) { switch (NULL == option_value ? '\0' : *option_value) {
case '\0': case '\0':
return FALSE; return FALSE;
case '/': case '/':
switch(*++option_value) { switch (*++option_value) {
case 's': case 's':
info->aggregator = ' '; info->aggregator = ' ';
break; break;
@ -1490,20 +1491,20 @@ gboolean output_fields_set_option(output_fields_t* info, gchar* option)
return TRUE; return TRUE;
} }
if(0 == strcmp(option_name, "quote")) { if (0 == strcmp(option_name, "quote")) {
switch(NULL == option_value ? '\0' : *option_value) { switch (NULL == option_value ? '\0' : *option_value) {
default: /* Fall through */ default: /* Fall through */
case '\0': case '\0':
info->quote='\0'; info->quote = '\0';
return FALSE; return FALSE;
case 'd': case 'd':
info->quote='"'; info->quote = '"';
break; break;
case 's': case 's':
info->quote='\''; info->quote = '\'';
break; break;
case 'n': case 'n':
info->quote='\0'; info->quote = '\0';
break; break;
} }
return TRUE; return TRUE;
@ -1522,26 +1523,26 @@ void output_fields_list_options(FILE *fh)
fputs("quote=d|s|n Print either d: double-quotes, s: single quotes or \n n: no quotes around field values (def: n: none)\n", fh); fputs("quote=d|s|n Print either d: double-quotes, s: single quotes or \n n: no quotes around field values (def: n: none)\n", fh);
} }
gboolean output_fields_has_cols(output_fields_t* fields) gboolean output_fields_has_cols(output_fields_t *fields)
{ {
g_assert(fields); g_assert(fields);
return fields->includes_col_fields; return fields->includes_col_fields;
} }
void write_fields_preamble(output_fields_t* fields, FILE *fh) void write_fields_preamble(output_fields_t *fields, FILE *fh)
{ {
gsize i; gsize i;
g_assert(fields); g_assert(fields);
g_assert(fh); g_assert(fh);
if(!fields->print_header) { if (!fields->print_header) {
return; return;
} }
for(i = 0; i < fields->fields->len; ++i) { for (i = 0; i < fields->fields->len; ++i) {
const gchar* field = (const gchar *)g_ptr_array_index(fields->fields,i); const gchar *field = (const gchar *)g_ptr_array_index(fields->fields, i);
if(i != 0 ) { if (i != 0 ) {
fputc(fields->separator, fh); fputc(fields->separator, fh);
} }
fputs(field, fh); fputs(field, fh);
@ -1549,12 +1550,12 @@ void write_fields_preamble(output_fields_t* fields, FILE *fh)
fputc('\n', fh); fputc('\n', fh);
} }
static void format_field_values(output_fields_t* fields, gpointer field_index, const gchar* value) static void format_field_values(output_fields_t *fields, gpointer field_index, const gchar *value)
{ {
guint idx; guint idx;
GPtrArray* fv_p; GPtrArray *fv_p;
if (NULL == value || '\0' == *value) if ((NULL == value) || ('\0' == *value))
return; return;
/* Unwrap change made to disambiguiate zero / null */ /* Unwrap change made to disambiguiate zero / null */
@ -1583,7 +1584,7 @@ static void format_field_values(output_fields_t* fields, gpointer field_index, c
/* print the value of all accurrences of the field */ /* print the value of all accurrences of the field */
/* If not the first, add the 'aggregator' */ /* If not the first, add the 'aggregator' */
if (g_ptr_array_len(fv_p) > 0) { if (g_ptr_array_len(fv_p) > 0) {
g_ptr_array_add(fv_p, (gpointer)ep_strdup_printf("%c",fields->aggregator)); g_ptr_array_add(fv_p, (gpointer)ep_strdup_printf("%c", fields->aggregator));
} }
break; break;
default: default:
@ -1607,7 +1608,7 @@ static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
g_assert(fi); g_assert(fi);
field_index = g_hash_table_lookup(call_data->fields->field_indicies, fi->hfinfo->abbrev); field_index = g_hash_table_lookup(call_data->fields->field_indicies, fi->hfinfo->abbrev);
if(NULL != field_index) { if (NULL != field_index) {
format_field_values(call_data->fields, field_index, format_field_values(call_data->fields, field_index,
get_node_field_value(fi, call_data->edt) /* static or ep_alloc'd string */ get_node_field_value(fi, call_data->edt) /* static or ep_alloc'd string */
); );
@ -1620,11 +1621,11 @@ static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
} }
} }
void proto_tree_write_fields(output_fields_t* fields, epan_dissect_t *edt, column_info *cinfo, FILE *fh) void proto_tree_write_fields(output_fields_t *fields, epan_dissect_t *edt, column_info *cinfo, FILE *fh)
{ {
gsize i; gsize i;
gint col; gint col;
gchar* col_name; gchar *col_name;
gpointer field_index; gpointer field_index;
write_field_data_t data; write_field_data_t data;
@ -1636,13 +1637,13 @@ void proto_tree_write_fields(output_fields_t* fields, epan_dissect_t *edt, colum
data.fields = fields; data.fields = fields;
data.edt = edt; data.edt = edt;
if(NULL == fields->field_indicies) { if (NULL == fields->field_indicies) {
/* Prepare a lookup table from string abbreviation for field to its index. */ /* Prepare a lookup table from string abbreviation for field to its index. */
fields->field_indicies = g_hash_table_new(g_str_hash, g_str_equal); fields->field_indicies = g_hash_table_new(g_str_hash, g_str_equal);
i = 0; i = 0;
while( i < fields->fields->len) { while( i < fields->fields->len) {
gchar* field = (gchar *)g_ptr_array_index(fields->fields, i); gchar *field = (gchar *)g_ptr_array_index(fields->fields, i);
/* Store field indicies +1 so that zero is not a valid value, /* Store field indicies +1 so that zero is not a valid value,
* and can be distinguished from NULL as a pointer. * and can be distinguished from NULL as a pointer.
*/ */
@ -1663,41 +1664,41 @@ void proto_tree_write_fields(output_fields_t* fields, epan_dissect_t *edt, colum
col_name = ep_strdup_printf("%s%s", COLUMN_FIELD_FILTER, cinfo->col_title[col]); col_name = ep_strdup_printf("%s%s", COLUMN_FIELD_FILTER, cinfo->col_title[col]);
field_index = g_hash_table_lookup(fields->field_indicies, col_name); field_index = g_hash_table_lookup(fields->field_indicies, col_name);
if(NULL != field_index) { if (NULL != field_index) {
format_field_values(fields, field_index, cinfo->col_data[col]); format_field_values(fields, field_index, cinfo->col_data[col]);
} }
} }
} }
for(i = 0; i < fields->fields->len; ++i) { for (i = 0; i < fields->fields->len; ++i) {
if(0 != i) { if (0 != i) {
fputc(fields->separator, fh); fputc(fields->separator, fh);
} }
if(NULL != fields->field_values[i]) { if (NULL != fields->field_values[i]) {
GPtrArray *fv_p; GPtrArray *fv_p;
gsize j; gsize j;
fv_p = fields->field_values[i]; fv_p = fields->field_values[i];
if(fields->quote != '\0') { if (fields->quote != '\0') {
fputc(fields->quote, fh); fputc(fields->quote, fh);
} }
for (j = 0; j < g_ptr_array_len(fv_p); j++ ) { for (j = 0; j < g_ptr_array_len(fv_p); j++ ) {
fputs((gchar *)g_ptr_array_index(fv_p, j), fh); fputs((gchar *)g_ptr_array_index(fv_p, j), fh);
} }
if(fields->quote != '\0') { if (fields->quote != '\0') {
fputc(fields->quote, fh); fputc(fields->quote, fh);
} }
} }
} }
} }
void write_fields_finale(output_fields_t* fields _U_ , FILE *fh _U_) void write_fields_finale(output_fields_t *fields _U_ , FILE *fh _U_)
{ {
/* Nothing to do */ /* Nothing to do */
} }
/* Returns an ep_alloced string or a static constant*/ /* Returns an ep_alloced string or a static constant*/
const gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt) const gchar *get_node_field_value(field_info *fi, epan_dissect_t *edt)
{ {
if (fi->hfinfo->id == hf_text_only) { if (fi->hfinfo->id == hf_text_only) {
/* Text label. /* Text label.
@ -1760,7 +1761,7 @@ const gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt)
} }
static const gchar* static const gchar*
get_field_hex_value(GSList* src_list, field_info *fi) get_field_hex_value(GSList *src_list, field_info *fi)
{ {
const guint8 *pd; const guint8 *pd;
@ -1776,8 +1777,8 @@ get_field_hex_value(GSList* src_list, field_info *fi)
if (pd) { if (pd) {
int i; int i;
gchar* buffer; gchar *buffer;
gchar* p; gchar *p;
int len; int len;
const int chars_per_byte = 2; const int chars_per_byte = 2;