added some options and enhancements to the print output:

-ps: added formatting hints for ghostscript, so pdf conversion will be much better
-ps: print a thin line at the top and bottom of each page
-ps/text: add an option to start a new page for every packet (formfeed)

svn path=/trunk/; revision=10660
This commit is contained in:
Ulf Lamping 2004-04-22 17:03:21 +00:00
parent f205304ed4
commit 51f987e04f
6 changed files with 207 additions and 21 deletions

28
file.c
View File

@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
* $Id: file.c,v 1.376 2004/04/20 22:34:08 ulfl Exp $
* $Id: file.c,v 1.377 2004/04/22 17:03:20 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1491,6 +1491,7 @@ typedef struct {
gboolean print_header_line;
char *header_line_buf;
int header_line_buf_len;
gboolean print_formfeed;
gboolean print_separator;
char *line_buf;
int line_buf_len;
@ -1520,10 +1521,14 @@ print_packet(capture_file *cf, frame_data *fdata,
epan_dissect_run(edt, pseudo_header, pd, fdata, &cf->cinfo);
epan_dissect_fill_in_columns(edt);
if (args->print_separator)
print_line(args->print_fh, 0, args->print_args->format, "");
if (args->print_formfeed) {
print_formfeed(args->print_fh, args->print_args->format);
} else {
if (args->print_separator)
print_line(args->print_fh, 0, args->print_args->format, "");
}
if (args->print_args->print_summary) {
if (args->print_args->print_summary || args->print_args->format == PR_FMT_PS) {
if (args->print_header_line) {
print_line(args->print_fh, 0, args->print_args->format,
args->header_line_buf);
@ -1557,7 +1562,12 @@ print_packet(capture_file *cf, frame_data *fdata,
*cp++ = ' ';
}
*cp = '\0';
print_line(args->print_fh, 0, args->print_args->format, args->line_buf);
print_packet_header(args->print_fh, args->print_args->format, fdata->num, args->line_buf);
if (args->print_args->print_summary) {
print_line(args->print_fh, 0, args->print_args->format, args->line_buf);
}
} /* if (print_summary) */
if (args->print_args->print_dissections != print_dissections_none) {
@ -1589,6 +1599,11 @@ print_packet(capture_file *cf, frame_data *fdata,
epan_dissect_free(edt);
/* do we want to have a formfeed between each packet from now on? */
if(args->print_args->print_formfeed) {
args->print_formfeed = TRUE;
}
return !ferror(args->print_fh);
}
@ -1619,11 +1634,12 @@ print_packets(capture_file *cf, print_args_t *print_args)
callback_args.print_header_line = TRUE;
callback_args.header_line_buf = NULL;
callback_args.header_line_buf_len = 256;
callback_args.print_formfeed = FALSE;
callback_args.print_separator = FALSE;
callback_args.line_buf = NULL;
callback_args.line_buf_len = 256;
callback_args.col_widths = NULL;
if (print_args->print_summary) {
if (print_args->print_summary || print_args->format == PR_FMT_PS) {
/* We're printing packet summaries. Allocate the header line buffer
and get the column widths. */
callback_args.header_line_buf = g_malloc(callback_args.header_line_buf_len + 1);

View File

@ -1,7 +1,7 @@
/* print_dlg.c
* Dialog boxes for printing
*
* $Id: print_dlg.c,v 1.67 2004/04/17 11:50:14 ulfl Exp $
* $Id: print_dlg.c,v 1.68 2004/04/22 17:03:21 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -92,6 +92,7 @@ static gchar * print_cmd;
#define PRINT_AS_DISPLAYED_RB_KEY "printer_as_displayed_radio_button"
#define PRINT_EXPAND_ALL_RB_KEY "printer_expand_all_radio_button"
#define PRINT_HEX_CB_KEY "printer_hex_check_button"
#define PRINT_FORMFEED_CB_KEY "printer_formfeed_check_button"
#define PRINT_BT_KEY "printer_button"
@ -340,6 +341,7 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
GtkWidget *details_hb, *details_vb;
GtkWidget *collapse_all_rb, *as_displayed_rb, *expand_all_rb;
GtkWidget *hex_cb;
GtkWidget *sep, *formfeed_cb;
GtkWidget *bbox, *ok_bt, *cancel_bt;
@ -689,6 +691,19 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
gtk_container_add(GTK_CONTAINER(format_vb), hex_cb);
gtk_widget_show(hex_cb);
/* seperator */
sep = gtk_hseparator_new();
gtk_container_add(GTK_CONTAINER(format_vb), sep);
gtk_widget_show(sep);
/* "Each packet on a new page" check button. */
formfeed_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Each packet on a new page", accel_group);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(formfeed_cb), FALSE);
gtk_tooltips_set_tip (tooltips, formfeed_cb, ("When checked, a new page will be used for each packet printed. "
"This is done by adding a formfeed (or similar) between the packet printouts."), NULL);
gtk_container_add(GTK_CONTAINER(format_vb), formfeed_cb);
gtk_widget_show(formfeed_cb);
OBJECT_SET_DATA(print_w, PRINT_SUMMARY_CB_KEY, summary_cb);
OBJECT_SET_DATA(print_w, PRINT_DETAILS_CB_KEY, details_cb);
@ -724,6 +739,7 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
OBJECT_SET_DATA(ok_bt, PRINT_AS_DISPLAYED_RB_KEY, as_displayed_rb);
OBJECT_SET_DATA(ok_bt, PRINT_EXPAND_ALL_RB_KEY, expand_all_rb);
OBJECT_SET_DATA(ok_bt, PRINT_HEX_CB_KEY, hex_cb);
OBJECT_SET_DATA(ok_bt, PRINT_FORMFEED_CB_KEY, formfeed_cb);
SIGNAL_CONNECT(ok_bt, "clicked", print_ok_cb, print_w);
gtk_widget_grab_default(ok_bt);
@ -910,6 +926,9 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_HEX_CB_KEY);
print_args.print_hex = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button));
button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_FORMFEED_CB_KEY);
print_args.print_formfeed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button));
print_args.range = range;
gtk_widget_destroy(GTK_WIDGET(parent_w));

54
print.c
View File

@ -1,7 +1,7 @@
/* print.c
* Routines for printing packet analysis trees.
*
* $Id: print.c,v 1.77 2004/04/20 22:34:08 ulfl Exp $
* $Id: print.c,v 1.78 2004/04/22 17:03:20 ulfl Exp $
*
* Gilbert Ramirez <gram@alumni.rice.edu>
*
@ -715,8 +715,9 @@ print_preamble(FILE *fh, gint format, gchar *filename)
break;
case(PR_FMT_PS):
print_ps_preamble(fh);
fputs("%% Set the font to 8 point\n", fh);
fputs("/Courier findfont 8 scalefont setfont\n", fh);
fputs("%% Set the font to 10 point\n", fh);
fputs("/Courier findfont 10 scalefont setfont\n", fh);
fputs("\n", fh);
fputs("%% the page title\n", fh);
ps_clean_string(psbuffer, filename, MAX_PS_LINE_LENGTH);
@ -738,6 +739,53 @@ print_preamble(FILE *fh, gint format, gchar *filename)
}
}
void
print_packet_header(FILE *fh, gint format, guint32 number, gchar *summary) {
char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
switch(format) {
case(PR_FMT_TEXT):
/* do nothing */
break;
case(PR_FMT_PS):
ps_clean_string(psbuffer, summary, MAX_PS_LINE_LENGTH);
fprintf(fh, "[/Dest /__frame%u__ /Title (%s) /OUT pdfmark\n", number, psbuffer);
fputs("[/View [/XYZ -4 currentpoint matrix currentmatrix matrix defaultmatrix\n", fh);
fputs("matrix invertmatrix matrix concatmatrix transform exch pop 20 add null]\n", fh);
fprintf(fh, "/Dest /__frame%u__ /DEST pdfmark\n", number);
break;
case(PR_FMT_PDML):
/* do nothing */
break;
case(PR_FMT_PSML):
/* do nothing */
break;
default:
g_assert_not_reached();
}
}
void
print_formfeed(FILE *fh, gint format) {
switch(format) {
case(PR_FMT_TEXT):
fputs("\f", fh);
break;
case(PR_FMT_PS):
fputs("formfeed\n", fh);
break;
case(PR_FMT_PDML):
/* do nothing */
break;
case(PR_FMT_PSML):
/* do nothing */
break;
default:
g_assert_not_reached();
}
}
/* Some formats need stuff at the end of the output */
void
print_finale(FILE *fh, gint format)

View File

@ -1,7 +1,7 @@
/* print.h
* Definitions for printing packet analysis trees.
*
* $Id: print.h,v 1.40 2004/04/20 22:34:08 ulfl Exp $
* $Id: print.h,v 1.41 2004/04/22 17:03:20 ulfl Exp $
*
* Gilbert Ramirez <gram@alumni.rice.edu>
*
@ -62,6 +62,8 @@ typedef struct {
print_dissections_e print_dissections;
gboolean print_hex; /* TRUE if we should also print hex data;
FALSE if we should print only if not dissected. */
gboolean print_formfeed; /* TRUE if a formfeed should be printed
before each new packet */
} print_args_t;
/* Functions in print.h */
@ -69,6 +71,8 @@ typedef struct {
FILE *open_print_dest(int to_file, const char *dest);
gboolean close_print_dest(int to_file, FILE *fh);
void print_preamble(FILE *fh, gint format, gchar *filename);
void print_packet_header(FILE *fh, gint format, guint32 number, gchar *summary);
void print_formfeed(FILE *fh, gint format);
void print_finale(FILE *fh, gint format);
void proto_tree_print(print_args_t *print_args, epan_dissect_t *edt,
FILE *fh);

116
print.ps
View File

@ -17,6 +17,30 @@
%%EndComments
%!
%
% Ghostscript http://ghostscript.com/ can convert postscript to pdf files.
%
% To convert this postscript file to pdf, type (for US letter format):
% ps2pdf filename.ps
%
% or (for A4 format):
% ps2pdf -sPAPERSIZE=a4 filename.ps
%
% ... and of course replace filename.ps by your current filename.
%
% The pdfmark's below will help converting to a pdf file, and have no
% effect when printing the postscript directly.
%
% This line is necessary if the file should be printable, and not just used
% for distilling into PDF:
%
/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse
%
% This tells PDF viewers to display bookmarks when the document is opened:
%
[/PageMode /UseOutlines /DOCVIEW pdfmark
% Get the Imagable Area of the page
clippath pathbbox
@ -33,10 +57,10 @@ pop pop % junk
%/pagenumtab hmax 72 sub def
% 1/2-inch margins
/lmargin 36 def
/tmargin vmax 56 sub def
/bmargin 36 def
/pagenumtab hmax 36 sub def
/lmargin 36 def % left margin
/tmargin vmax 56 sub def % top margin
/bmargin 36 def % bottom margin
/pagenumtab hmax 36 sub def % right margin
% Counters
/vpos vmax 40 sub def
@ -46,6 +70,17 @@ pop pop % junk
/pagenostr 7 string def
/formfeed {
printpagedecorations
showpage
% we need a new current point after showpage is done
lmargin % X
vpos % Y
moveto
/vpos tmargin def
} def
% Prints text with possible indenting
/putline_single {
exch 10 mul lmargin add % X
@ -57,9 +92,7 @@ pop pop % junk
vpos bmargin le % is vpos <= bottom margin?
{
printpageheader
showpage
/vpos tmargin def
formfeed
}
if % then formfeed and start at top
} def
@ -89,7 +122,7 @@ pop pop % junk
% Prints the page number at the top right
/printpageheader {
/printpagedecorations {
gsave
% Set the font to 8 point
/Helvetica findfont 8 scalefont setfont
@ -109,6 +142,28 @@ pop pop % junk
% thispagenum++
/thispagenum thispagenum 1 add def
% line at top of page
lmargin % X
vmax 38 sub % Y
moveto
pagenumtab % X
vmax 38 sub % Y
lineto
stroke
% line at bottom of page
lmargin % X
bmargin % Y
moveto
% title
pagenumtab % X
bmargin % Y
lineto
stroke
grestore
} def
@ -124,6 +179,48 @@ pop pop % junk
/eth_pagetitle (Ethereal) def
% Display our output lines.
% PDF bookmark link
[/Dest /__frame1__ /Title (Frame 1) /OUT pdfmark
[/View [/XYZ -4 currentpoint matrix currentmatrix matrix defaultmatrix
matrix invertmatrix matrix concatmatrix transform exch pop 20 add null]
/Dest /__frame1__ /DEST pdfmark
% packet data
0 (Frame 1) putline
0 (Ethernet II \(98 on wire, 68 captured\)) putline
1 (Destination: 00:00:0c:36:00:2a) putline
1 (Source: 00:c0:4f:c7:eb:c0) putline
1 (Type: IP \(0x0800\)) putline
0 (Ethernet II \(98 on wire, 68 captured\)) putline
1 (Source: 00:c0:4f:c7:eb:c0) putline
1 (Type: IP \(0x0800\)) putline
0 (Source: 00:c0:4f:c7:eb:c0) putline
0 () putline
0 (0000 cc 00 00 00 00 00 07 02 00 00 00 00 00 00 00 00 ................ ) putline
0 (0010 00 00 bd 0e fe 16 01 00 3e 00 03 08 58 4c 20 38 ........>...XL 8 ) putline
0 (0020 30 20 49 4d 33 00 16 01 00 34 00 16 01 01 35 00 0 IM3....4....5. ) putline
0 (0030 16 01 02 36 00 16 01 03 6e 00 16 01 ff 6f 00 16 ...6....n....o.. ) putline
0 (0040 01 ff 70 00 16 01 ff 71 00 16 01 ff 48 00 01 04 ..p....q....H... ) putline
0 (0050 ff 03 07 00 24 00 01 01 05 25 00 01 01 05 26 00 ....$....%....&. ) putline
0 (0060 01 01 05 27 00 01 01 05 6a 00 01 01 00 6b 00 01 ...'....j....k.. ) putline
0 (0070 01 00 6c 00 01 01 00 6d 00 01 01 00 3d 00 01 02 ..l....m....=... ) putline
0 (0080 02 00 c0 00 03 08 80 00 00 00 00 00 00 00 b4 00 ................ ) putline
0 (0090 01 04 c0 a8 42 ef 39 00 16 08 05 05 05 05 00 00 ....B.9......... ) putline
0 (00a0 00 00 00 03 20 36 41 20 52 69 6e 67 00 00 00 00 .... 6A Ring.... ) putline
0 (00b0 00 00 00 00 00 00 ...... ) putline
formfeed
% PDF bookmark link
[/Dest /__frame2__ /Title (Frame 2) /OUT pdfmark
[/View [/XYZ -4 currentpoint matrix currentmatrix matrix defaultmatrix
matrix invertmatrix matrix concatmatrix transform exch pop 20 add null]
/Dest /__frame2__ /DEST pdfmark
% packet data
0 (Frame 2) putline
0 (Ethernet II \(98 on wire, 68 captured\)) putline
1 (Destination: 00:00:0c:36:00:2a) putline
1 (Source: 00:c0:4f:c7:eb:c0) putline
@ -148,10 +245,11 @@ pop pop % junk
0 (00b0 00 00 00 00 00 00 ...... ) putline
% ---- ethereal finale start ---- %
% If this is not the first page, then print the page number
thispagenum 1 gt % is thispagenum > 1 ?
{
printpageheader
printpagedecorations
}
if

View File

@ -1,6 +1,6 @@
/* tethereal.c
*
* $Id: tethereal.c,v 1.236 2004/04/20 22:34:08 ulfl Exp $
* $Id: tethereal.c,v 1.237 2004/04/22 17:03:20 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -2611,6 +2611,7 @@ wtap_dispatch_cb_print(guchar *user, const struct wtap_pkthdr *phdr,
print_args.format = print_format;
print_args.print_summary = !verbose;
print_args.print_hex = verbose && print_hex;
print_args.print_formfeed = FALSE;
print_args.print_dissections = verbose ? print_dissections_expanded : print_dissections_none;
/* init the packet range */