forked from osmocom/wireshark
New rutine tvb_format_text_wsp() which will change "whiite space" characters to space
before output. svn path=/trunk/; revision=18519
This commit is contained in:
parent
0eb577e17b
commit
764e3ac167
|
@ -671,6 +671,7 @@ tvb_find_guint8
|
|||
tvb_find_line_end
|
||||
tvb_find_line_end_unquoted
|
||||
tvb_format_text
|
||||
tvb_format_text_wsp
|
||||
tvb_get_ephemeral_string
|
||||
tvb_get_guid
|
||||
tvb_get_guint8
|
||||
|
|
119
epan/strutil.c
119
epan/strutil.c
|
@ -213,27 +213,136 @@ format_text(const guchar *string, int len)
|
|||
break;
|
||||
|
||||
case '\b':
|
||||
fmtbuf[idx][column] = 'b';
|
||||
fmtbuf[idx][column] = 'b'; /* BS */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\f':
|
||||
fmtbuf[idx][column] = 'f';
|
||||
fmtbuf[idx][column] = 'f'; /* FF */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
fmtbuf[idx][column] = 'n';
|
||||
fmtbuf[idx][column] = 'n'; /* NL */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\r':
|
||||
fmtbuf[idx][column] = 'r';
|
||||
fmtbuf[idx][column] = 'r'; /* CR */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
fmtbuf[idx][column] = 't';
|
||||
fmtbuf[idx][column] = 't'; /* tab */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\v':
|
||||
fmtbuf[idx][column] = 'v';
|
||||
column++;
|
||||
break;
|
||||
|
||||
default:
|
||||
i = (c>>6)&03;
|
||||
fmtbuf[idx][column] = i + '0';
|
||||
column++;
|
||||
i = (c>>3)&07;
|
||||
fmtbuf[idx][column] = i + '0';
|
||||
column++;
|
||||
i = (c>>0)&07;
|
||||
fmtbuf[idx][column] = i + '0';
|
||||
column++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fmtbuf[idx][column] = '\0';
|
||||
return fmtbuf[idx];
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a string, generate a string from it that shows non-printable
|
||||
* characters as C-style escapes except a whitespace character
|
||||
* (space, tab, carriage return, new line, vertical tab, or formfeed)
|
||||
* which will be replaved by a space, and return a pointer to it.
|
||||
*/
|
||||
gchar *
|
||||
format_text_wsp(const guchar *string, int len)
|
||||
{
|
||||
static gchar *fmtbuf[3];
|
||||
static int fmtbuf_len[3];
|
||||
static int idx;
|
||||
int column;
|
||||
const guchar *stringend = string + len;
|
||||
guchar c;
|
||||
int i;
|
||||
|
||||
idx = (idx + 1) % 3;
|
||||
|
||||
/*
|
||||
* Allocate the buffer if it's not already allocated.
|
||||
*/
|
||||
if (fmtbuf[idx] == NULL) {
|
||||
fmtbuf[idx] = g_malloc(INITIAL_FMTBUF_SIZE);
|
||||
fmtbuf_len[idx] = INITIAL_FMTBUF_SIZE;
|
||||
}
|
||||
column = 0;
|
||||
while (string < stringend) {
|
||||
/*
|
||||
* Is there enough room for this character, if it expands to
|
||||
* a backslash plus 3 octal digits (which is the most it can
|
||||
* expand to), and also enough room for a terminating '\0'?
|
||||
*/
|
||||
if (column+3+1 >= fmtbuf_len[idx]) {
|
||||
/*
|
||||
* Double the buffer's size if it's not big enough.
|
||||
* The size of the buffer starts at 128, so doubling its size
|
||||
* adds at least another 128 bytes, which is more than enough
|
||||
* for one more character plus a terminating '\0'.
|
||||
*/
|
||||
fmtbuf_len[idx] = fmtbuf_len[idx] * 2;
|
||||
fmtbuf[idx] = g_realloc(fmtbuf[idx], fmtbuf_len[idx]);
|
||||
}
|
||||
c = *string++;
|
||||
|
||||
if (isprint(c)) {
|
||||
fmtbuf[idx][column] = c;
|
||||
column++;
|
||||
} else if (isspace(c)) {
|
||||
fmtbuf[idx][column] = ' ';
|
||||
column++;
|
||||
}else {
|
||||
fmtbuf[idx][column] = '\\';
|
||||
column++;
|
||||
switch (c) {
|
||||
|
||||
case '\a':
|
||||
fmtbuf[idx][column] = 'a';
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\b':
|
||||
fmtbuf[idx][column] = 'b'; /* BS */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\f':
|
||||
fmtbuf[idx][column] = 'f'; /* FF */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
fmtbuf[idx][column] = 'n'; /* NL */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\r':
|
||||
fmtbuf[idx][column] = 'r'; /* CR */
|
||||
column++;
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
fmtbuf[idx][column] = 't'; /* tab */
|
||||
column++;
|
||||
break;
|
||||
|
||||
|
|
|
@ -64,6 +64,8 @@ int get_token_len(const guchar *linep, const guchar *lineend,
|
|||
*/
|
||||
gchar* format_text(const guchar *line, int len);
|
||||
|
||||
gchar* format_text_wsp(const guchar *line, int len);
|
||||
|
||||
/** Turn an array of bytes into a string showing the bytes in hex.
|
||||
*
|
||||
* @param bd A pointer to the byte array
|
||||
|
|
|
@ -1795,6 +1795,27 @@ tvb_format_text(tvbuff_t *tvb, gint offset, gint size)
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
* Format the data in the tvb from offset for length ...
|
||||
*/
|
||||
|
||||
gchar *
|
||||
tvb_format_text_wsp(tvbuff_t *tvb, gint offset, gint size)
|
||||
{
|
||||
const guint8 *ptr;
|
||||
gint len = size;
|
||||
|
||||
if ((ptr = ensure_contiguous(tvb, offset, size)) == NULL) {
|
||||
|
||||
len = tvb_length_remaining(tvb, offset);
|
||||
ptr = ensure_contiguous(tvb, offset, len);
|
||||
|
||||
}
|
||||
|
||||
return format_text_wsp(ptr, len);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Like "tvb_format_text()", but for null-padded strings; don't show
|
||||
* the null padding characters as "\000".
|
||||
|
|
|
@ -427,6 +427,12 @@ extern char *tvb_get_ephemeral_faked_unicode(tvbuff_t *tvb, int offset, int len,
|
|||
*/
|
||||
extern gchar * tvb_format_text(tvbuff_t *tvb, gint offset, gint size);
|
||||
|
||||
/**
|
||||
* Like "tvb_format_text()", but for 'wsp'; don't show
|
||||
* the characters as C-style escapes.
|
||||
*/
|
||||
extern gchar * tvb_format_text_wsp(tvbuff_t *tvb, gint offset, gint size);
|
||||
|
||||
/**
|
||||
* Like "tvb_format_text()", but for null-padded strings; don't show
|
||||
* the null padding characters as "\000".
|
||||
|
|
|
@ -2562,7 +2562,7 @@ static void tvb_raw_text_add(tvbuff_t *tvb, proto_tree *tree){
|
|||
do {
|
||||
linelen = tvb_find_line_end(tvb,tvb_linebegin,-1,&tvb_lineend,FALSE);
|
||||
proto_tree_add_text(tree, tvb, tvb_linebegin, linelen,
|
||||
"%s", tvb_format_text(tvb,tvb_linebegin,
|
||||
"%s", tvb_format_text_wsp(tvb,tvb_linebegin,
|
||||
linelen));
|
||||
tvb_linebegin = tvb_lineend;
|
||||
} while ( tvb_lineend < tvb_len );
|
||||
|
|
Loading…
Reference in New Issue