Commit 2e2aec94 authored by winckel's avatar winckel

Modified display of strings.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4446 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent c5f7ea1e
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "array_type.h"
#include "fundamental_type.h"
......@@ -29,6 +30,8 @@ int array_dissect_from_buffer(
int items = type->size / type_child->size;
int i;
int zero_counter = 0;
gboolean is_string = FALSE;
char *string;
/* Factorizes trailing 0 */
if ((items > 1) && (type_child->type == TYPE_FUNDAMENTAL))
......@@ -44,12 +47,41 @@ int array_dissect_from_buffer(
break;
}
}
/* Do not factorize if there is only one item */
/* Check if this is an array of 8 bits items and if at least the firsts ones are not null */
if ((type_child->size == 8) && ((items - zero_counter) >= 2))
{
/* check if this is a printable string */
is_string = TRUE;
string = calloc(items + 1, 1);
for (i = 0; i < (items - zero_counter); i++)
{
string[i] = fundamental_read_from_buffer(type_child, buffer, parent_offset, offset + i * type_child->size);
if (isprint(string[i]) == 0)
{
/* This is not a printable string */
is_string = FALSE;
break;
}
}
if (is_string)
{
INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d .. %d] \"%s\"\n", 0, (items - zero_counter - 1), string));
ui_set_signal_text_cb(user_data, cbuf, length);
}
}
/* Do not factorize if there is only one null item */
if (zero_counter <= 1)
{
zero_counter = 0;
}
}
if (is_string == FALSE)
{
for (i = 0; i < (items - zero_counter); i++)
{
INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d] ", i));
......@@ -70,6 +102,7 @@ int array_dissect_from_buffer(
buffer, parent_offset, offset + i * type_child->size, indent, FALSE);
}
}
}
if (type->name) {
INDENTED(stdout, indent, fprintf(stdout, "</%s>\n", type->name));
}
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include "fundamental_type.h"
......@@ -64,7 +63,7 @@ int fundamental_dissect_from_buffer(
case 8:
value8 = (uint8_t) value64;
INDENTED_STRING(cbuf, indent,
length = sprintf(cbuf, type_unsigned ? "(0x%02" PRIx8 ") %3" PRIu8 " '%c';\n" : "(0x%02" PRIx8 ") %4" PRId8 " '%c';\n", value8, value8, isprint(value8) ? value8 : '.'));
length = sprintf(cbuf, type_unsigned ? "(0x%02" PRIx8 ") %3" PRIu8 ";\n" : "(0x%02" PRIx8 ") %4" PRId8 ";\n", value8, value8));
break;
case 16:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment