diff options
author | Guy Harris <guy@alum.mit.edu> | 2019-03-31 18:17:57 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-04-01 01:41:56 +0000 |
commit | 8b0615de3b747f588387b64d2b7c05e7f6f51487 (patch) | |
tree | 53114e847a9e137b442b26656474800659217ad8 /epan/print_stream.c | |
parent | 8a283325d4d251ef933bdf0897b98b2185ee2ecc (diff) |
Only put generic values into the print_stream_t structure.
Put values used only by particular subclasses into the subclass data
structure.
Change-Id: Ibb995ebf18ba24449467e932084fbeef03ad1abf
Reviewed-on: https://code.wireshark.org/review/32653
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/print_stream.c')
-rw-r--r-- | epan/print_stream.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/epan/print_stream.c b/epan/print_stream.c index 15e0899695..8767bbb2ff 100644 --- a/epan/print_stream.c +++ b/epan/print_stream.c @@ -31,8 +31,13 @@ #define TERM_CSI_EL "\x1B[K" /* EL - Erase in Line (to end of line) */ typedef struct { - gboolean to_file; - FILE *fh; + gboolean to_file; + FILE *fh; + gboolean isatty; + const char *to_codeset; +#ifdef _WIN32 + WORD csb_attrs; +#endif } output_text; static void @@ -204,7 +209,7 @@ print_color_eol(print_stream_t *self) output_text *output = (output_text *)self->data; FILE *fh = output->fh; #ifdef _WIN32 - SetConsoleTextAttribute((HANDLE)_get_osfhandle(_fileno(fh)), self->csb_attrs); + SetConsoleTextAttribute((HANDLE)_get_osfhandle(_fileno(fh)), output->csb_attrs); fprintf(fh, "\n"); #else // UN*X @@ -300,7 +305,7 @@ print_line_color_text(print_stream_t *self, int indent, const char *line, const size_t ret; output_text *output = (output_text *)self->data; unsigned int num_spaces; - gboolean emit_color = self->isatty && (fg != NULL || bg != NULL); + gboolean emit_color = output->isatty && (fg != NULL || bg != NULL); /* should be space, if NUL -> initialize */ if (!spaces[0]) @@ -321,12 +326,12 @@ print_line_color_text(print_stream_t *self, int indent, const char *line, const if (ret == num_spaces) { gchar *tty_out = NULL; - if (self->isatty && self->to_codeset) { + if (output->isatty && output->to_codeset) { /* XXX Allocating a fresh buffer every line probably isn't the * most efficient way to do this. However, this has the side * effect of scrubbing invalid output. */ - tty_out = g_convert_with_fallback(line, -1, self->to_codeset, "UTF-8", "?", NULL, NULL, NULL); + tty_out = g_convert_with_fallback(line, -1, output->to_codeset, "UTF-8", "?", NULL, NULL, NULL); } if (tty_out) { @@ -400,23 +405,22 @@ print_stream_text_alloc(gboolean to_file, FILE *fh) output = (output_text *)g_malloc(sizeof *output); output->to_file = to_file; output->fh = fh; + output->isatty = ws_isatty(ws_fileno(fh)); stream = (print_stream_t *)g_malloc0(sizeof (print_stream_t)); stream->ops = &print_text_ops; - stream->isatty = ws_isatty(ws_fileno(fh)); stream->data = output; #ifndef _WIN32 - /* Is there a more reliable way to do this? */ is_utf8 = g_get_charset(&charset); if (!is_utf8) { - stream->to_codeset = charset; + output->to_codeset = charset; } #else CONSOLE_SCREEN_BUFFER_INFO csb_info; GetConsoleScreenBufferInfo((HANDLE)_get_osfhandle(_fileno(fh)), &csb_info); - stream->csb_attrs = csb_info.wAttributes; + output->csb_attrs = csb_info.wAttributes; - stream->to_codeset = "UTF-16LE"; + output->to_codeset = "UTF-16LE"; #endif return stream; |