diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-07-27 20:10:02 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-07-27 20:10:02 +0000 |
commit | 999867b7109f584f2fcb5fb043d4e7e5bc9bd725 (patch) | |
tree | e6b6bdbf14c68a335daab799ef0b60ae657ff00d | |
parent | d03b6c614a7a9c1b341efd5a2091410a9e7e1651 (diff) | |
download | wireshark-999867b7109f584f2fcb5fb043d4e7e5bc9bd725.tar.gz wireshark-999867b7109f584f2fcb5fb043d4e7e5bc9bd725.tar.bz2 wireshark-999867b7109f584f2fcb5fb043d4e7e5bc9bd725.zip |
Move the code to open the printer/print file from "print_packets()" to
"print_ok_cb()", and have "print_packets()" just work on a
"print_stream_t" handed to it, so that different platforms can open the
printer/print file in different ways (opening the file is probably not
going to be platform-dependent, but opening the printer will be).
svn path=/trunk/; revision=11544
-rw-r--r-- | file.c | 69 | ||||
-rw-r--r-- | gtk/print_dlg.c | 41 | ||||
-rw-r--r-- | print.h | 79 |
3 files changed, 104 insertions, 85 deletions
@@ -1495,7 +1495,6 @@ retap_packets(capture_file *cf) typedef struct { print_args_t *print_args; - print_stream_t *stream; gboolean print_header_line; char *header_line_buf; int header_line_buf_len; @@ -1538,11 +1537,11 @@ print_packet(capture_file *cf, frame_data *fdata, epan_dissect_run(edt, pseudo_header, pd, fdata, NULL); if (args->print_formfeed) { - if (!new_page(args->stream)) + if (!new_page(args->print_args->stream)) goto fail; } else { if (args->print_separator) { - if (!print_line(args->stream, 0, "")) + if (!print_line(args->print_args->stream, 0, "")) goto fail; } } @@ -1555,7 +1554,7 @@ print_packet(capture_file *cf, frame_data *fdata, if (args->print_args->print_summary) { if (args->print_header_line) { - if (!print_line(args->stream, 0, args->header_line_buf)) + if (!print_line(args->print_args->stream, 0, args->header_line_buf)) goto fail; args->print_header_line = FALSE; /* we might not need to print any more */ } @@ -1591,10 +1590,11 @@ print_packet(capture_file *cf, frame_data *fdata, /* * Generate a bookmark, using the summary line as the title. */ - if (!print_bookmark(args->stream, bookmark_name, args->line_buf)) + if (!print_bookmark(args->print_args->stream, bookmark_name, + args->line_buf)) goto fail; - if (!print_line(args->stream, 0, args->line_buf)) + if (!print_line(args->print_args->stream, 0, args->line_buf)) goto fail; } else { /* @@ -1602,19 +1602,20 @@ print_packet(capture_file *cf, frame_data *fdata, * printing the summary line. */ sprintf(bookmark_title, "Frame %u", fdata->num); - if (!print_bookmark(args->stream, bookmark_name, bookmark_title)) + if (!print_bookmark(args->print_args->stream, bookmark_name, + bookmark_title)) goto fail; } /* if (print_summary) */ if (args->print_args->print_dissections != print_dissections_none) { if (args->print_args->print_summary) { /* Separate the summary line from the tree with a blank line. */ - if (!print_line(args->stream, 0, "")) + if (!print_line(args->print_args->stream, 0, "")) goto fail; } /* Print the information in that tree. */ - if (!proto_tree_print(args->print_args, edt, args->stream)) + if (!proto_tree_print(args->print_args, edt, args->print_args->stream)) goto fail; /* Print a blank line if we print anything after this (aka more than one packet). */ @@ -1626,7 +1627,7 @@ print_packet(capture_file *cf, frame_data *fdata, if (args->print_args->print_hex) { /* Print the full packet data as hex. */ - if (!print_hex_data(args->stream, edt)) + if (!print_hex_data(args->print_args->stream, edt)) goto fail; /* Print a blank line if we print anything after this (aka more than one packet). */ @@ -1662,40 +1663,6 @@ print_packets(capture_file *cf, print_args_t *print_args) int line_len; psp_return_t ret; - switch (print_args->format) { - - case PR_FMT_TEXT: - if (print_args->to_file) { - callback_args.stream = print_stream_text_new(print_args->to_file, - print_args->file); - } else { - callback_args.stream = print_stream_text_new(print_args->to_file, - print_args->cmd); - } - break; - - case PR_FMT_PS: - if (print_args->to_file) { - callback_args.stream = print_stream_ps_new(print_args->to_file, - print_args->file); - } else { - callback_args.stream = print_stream_ps_new(print_args->to_file, - print_args->cmd); - } - break; - - default: - g_assert_not_reached(); - return PP_OPEN_ERROR; - } - if (callback_args.stream == NULL) - return PP_OPEN_ERROR; /* attempt to open destination failed */ - - if (!print_preamble(callback_args.stream, cf->filename)) { - destroy_print_stream(callback_args.stream); - return PP_WRITE_ERROR; - } - callback_args.print_args = print_args; callback_args.print_header_line = TRUE; callback_args.header_line_buf = NULL; @@ -1705,6 +1672,12 @@ print_packets(capture_file *cf, print_args_t *print_args) callback_args.line_buf = NULL; callback_args.line_buf_len = 256; callback_args.col_widths = NULL; + + if (!print_preamble(print_args->stream, cf->filename)) { + destroy_print_stream(print_args->stream); + return PP_WRITE_ERROR; + } + if (print_args->print_summary) { /* We're printing packet summaries. Allocate the header line buffer and get the column widths. */ @@ -1795,16 +1768,16 @@ print_packets(capture_file *cf, print_args_t *print_args) will get printed if we're piping to a print program; we'd have to write to a file and then hand that to the print program to make it actually not print anything. */ - destroy_print_stream(callback_args.stream); + destroy_print_stream(print_args->stream); return PP_WRITE_ERROR; } - if (!print_finale(callback_args.stream)) { - destroy_print_stream(callback_args.stream); + if (!print_finale(print_args->stream)) { + destroy_print_stream(print_args->stream); return PP_WRITE_ERROR; } - if (!destroy_print_stream(callback_args.stream)) + if (!destroy_print_stream(print_args->stream)) return PP_WRITE_ERROR; return PP_OK; diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c index bd111dc078..aa8531c7de 100644 --- a/gtk/print_dlg.c +++ b/gtk/print_dlg.c @@ -826,8 +826,47 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w) status = write_pdml_packets(&cfile, args); else if (export_as_psml) status = write_psml_packets(&cfile, args); - else + else { + switch (args->format) { + + case PR_FMT_TEXT: + if (args->to_file) { + args->stream = print_stream_text_new(TRUE, args->file); + if (args->stream == NULL) { + open_failure_alert_box(args->file, errno, TRUE); + return; + } + } else { + args->stream = print_stream_text_new(FALSE, args->cmd); + if (args->stream == NULL) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Couldn't run print command %s.", args->cmd); + } + } + break; + + case PR_FMT_PS: + if (args->to_file) { + args->stream = print_stream_ps_new(TRUE, args->file); + if (args->stream == NULL) { + open_failure_alert_box(args->file, errno, TRUE); + return; + } + } else { + args->stream = print_stream_ps_new(FALSE, args->cmd); + if (args->stream == NULL) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Couldn't run print command %s.", args->cmd); + } + } + break; + + default: + g_assert_not_reached(); + return; + } status = print_packets(&cfile, args); + } switch (status) { case PP_OK: @@ -29,6 +29,41 @@ #include <epan/packet.h> +/* + * Print stream code; this provides a "print stream" class with subclasses + * of various sorts. Additional subclasses might be implemented elsewhere. + */ +struct print_stream; + +typedef struct print_stream_ops { + gboolean (*print_preamble)(struct print_stream *self, gchar *filename); + gboolean (*print_line)(struct print_stream *self, int indent, + const char *line); + gboolean (*print_bookmark)(struct print_stream *self, + const gchar *name, const gchar *title); + gboolean (*new_page)(struct print_stream *self); + gboolean (*print_finale)(struct print_stream *self); + gboolean (*destroy)(struct print_stream *self); +} print_stream_ops_t; + +typedef struct print_stream { + const print_stream_ops_t *ops; + void *data; +} print_stream_t; + +extern print_stream_t *print_stream_text_new(int to_file, const char *dest); +extern print_stream_t *print_stream_text_stdio_new(FILE *fh); +extern print_stream_t *print_stream_ps_new(int to_file, const char *dest); +extern print_stream_t *print_stream_ps_stdio_new(FILE *fh); + +extern gboolean print_preamble(print_stream_t *self, gchar *filename); +extern gboolean print_line(print_stream_t *self, int indent, const char *line); +extern gboolean print_bookmark(print_stream_t *self, const gchar *name, + const gchar *title); +extern gboolean new_page(print_stream_t *self); +extern gboolean print_finale(print_stream_t *self); +extern gboolean destroy_print_stream(print_stream_t *self); + /* print output format */ typedef enum { PR_FMT_TEXT, /* plain text */ @@ -52,6 +87,7 @@ typedef enum { } print_dissections_e; typedef struct { + print_stream_t *stream; /* the stream to which we're printing */ print_format_e format; /* plain text or PostScript */ gboolean to_file; /* TRUE if we're printing to a file */ char *file; /* file output pathname */ @@ -67,7 +103,13 @@ typedef struct { before each new packet */ } print_args_t; -/* Functions in print.h */ +/* + * Higher-level packet-printing code. + */ + +extern gboolean proto_tree_print(print_args_t *print_args, epan_dissect_t *edt, + print_stream_t *stream); +extern gboolean print_hex_data(print_stream_t *stream, epan_dissect_t *edt); extern void write_pdml_preamble(FILE *fh); extern void proto_tree_write_pdml(epan_dissect_t *edt, FILE *fh); @@ -77,39 +119,4 @@ extern void write_psml_preamble(FILE *fh); extern void proto_tree_write_psml(epan_dissect_t *edt, FILE *fh); extern void write_psml_finale(FILE *fh); -struct print_stream; - -typedef struct print_stream_ops { - gboolean (*print_preamble)(struct print_stream *self, gchar *filename); - gboolean (*print_line)(struct print_stream *self, int indent, - const char *line); - gboolean (*print_bookmark)(struct print_stream *self, - const gchar *name, const gchar *title); - gboolean (*new_page)(struct print_stream *self); - gboolean (*print_finale)(struct print_stream *self); - gboolean (*destroy)(struct print_stream *self); -} print_stream_ops_t; - -typedef struct print_stream { - const print_stream_ops_t *ops; - void *data; -} print_stream_t; - -extern gboolean proto_tree_print(print_args_t *print_args, epan_dissect_t *edt, - print_stream_t *stream); -extern gboolean print_hex_data(print_stream_t *stream, epan_dissect_t *edt); - -extern print_stream_t *print_stream_text_new(int to_file, const char *dest); -extern print_stream_t *print_stream_text_stdio_new(FILE *fh); -extern print_stream_t *print_stream_ps_new(int to_file, const char *dest); -extern print_stream_t *print_stream_ps_stdio_new(FILE *fh); - -extern gboolean print_preamble(print_stream_t *self, gchar *filename); -extern gboolean print_line(print_stream_t *self, int indent, const char *line); -extern gboolean print_bookmark(print_stream_t *self, const gchar *name, - const gchar *title); -extern gboolean new_page(print_stream_t *self); -extern gboolean print_finale(print_stream_t *self); -extern gboolean destroy_print_stream(print_stream_t *self); - #endif /* print.h */ |