2 * Routines for printing packet analysis trees.
6 * Gilbert Ramirez <gram@alumni.rice.edu>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/epan.h>
35 #include <epan/epan_dissect.h>
36 #include <epan/tvbuff.h>
37 #include <epan/packet.h>
39 #include "packet-range.h"
42 #include "file_util.h"
43 #include <epan/charsets.h>
44 #include <epan/dissectors/packet-data.h>
45 #include <epan/dissectors/packet-frame.h>
47 #define PDML_VERSION "0"
48 #define PSML_VERSION "0"
52 print_stream_t *stream;
55 print_dissections_e print_dissections;
56 gboolean print_hex_for_data;
68 static void proto_tree_print_node(proto_node *node, gpointer data);
69 static void proto_tree_write_node_pdml(proto_node *node, gpointer data);
70 static const guint8 *get_field_data(GSList *src_list, field_info *fi);
71 static void write_pdml_field_hex_value(write_pdml_data *pdata, field_info *fi);
72 static gboolean print_hex_data_buffer(print_stream_t *stream, const guchar *cp,
73 guint length, char_enc encoding);
74 static void ps_clean_string(unsigned char *out, const unsigned char *in,
76 static void print_escaped_xml(FILE *fh, const char *unescaped_string);
78 static void print_pdml_geninfo(proto_tree *tree, FILE *fh);
81 open_print_dest(int to_file, const char *dest)
85 /* Open the file or command for output */
87 fh = eth_fopen(dest, "w");
89 fh = popen(dest, "w");
95 close_print_dest(int to_file, FILE *fh)
97 /* Close the file or command */
99 return (fclose(fh) == 0);
101 return (pclose(fh) == 0);
104 #define MAX_PS_LINE_LENGTH 256
107 proto_tree_print(print_args_t *print_args, epan_dissect_t *edt,
108 print_stream_t *stream)
112 /* Create the output */
114 data.stream = stream;
116 data.src_list = edt->pi.data_src;
117 data.encoding = edt->pi.fd->flags.encoding;
118 data.print_dissections = print_args->print_dissections;
119 /* If we're printing the entire packet in hex, don't
120 print uninterpreted data fields in hex as well. */
121 data.print_hex_for_data = !print_args->print_hex;
124 proto_tree_children_foreach(edt->tree, proto_tree_print_node, &data);
128 #define MAX_INDENT 160
130 /* Print a tree's data, and any child nodes. */
132 void proto_tree_print_node(proto_node *node, gpointer data)
134 field_info *fi = PITEM_FINFO(node);
135 print_data *pdata = (print_data*) data;
137 gchar label_str[ITEM_LABEL_LENGTH];
140 /* Don't print invisible entries. */
141 if (PROTO_ITEM_IS_HIDDEN(node))
144 /* Give up if we've already gotten an error. */
148 /* was a free format label produced? */
150 label_ptr = fi->rep->representation;
152 else { /* no, make a generic label */
153 label_ptr = label_str;
154 proto_item_fill_label(fi, label_str);
157 if(PROTO_ITEM_IS_GENERATED(node)) {
158 label_ptr = g_strdup_printf("[%s]", label_ptr);
161 if (!print_line(pdata->stream, pdata->level, label_ptr)) {
162 pdata->success = FALSE;
166 if(PROTO_ITEM_IS_GENERATED(node)) {
170 /* If it's uninterpreted data, dump it (unless our caller will
171 be printing the entire packet in hex). */
172 if (fi->hfinfo->id == proto_data && pdata->print_hex_for_data) {
174 * Find the data for this field.
176 pd = get_field_data(pdata->src_list, fi);
178 if (!print_hex_data_buffer(pdata->stream, pd,
179 fi->length, pdata->encoding)) {
180 pdata->success = FALSE;
186 /* If we're printing all levels, or if this node is one with a
187 subtree and its subtree is expanded, recurse into the subtree,
189 g_assert(fi->tree_type >= -1 && fi->tree_type < num_tree_types);
190 if (pdata->print_dissections == print_dissections_expanded ||
191 (pdata->print_dissections == print_dissections_as_displayed &&
192 fi->tree_type >= 0 && tree_is_expanded[fi->tree_type])) {
193 if (node->first_child != NULL) {
195 proto_tree_children_foreach(node,
196 proto_tree_print_node, pdata);
205 write_pdml_preamble(FILE *fh)
207 fputs("<?xml version=\"1.0\"?>\n", fh);
208 fputs("<pdml version=\"" PDML_VERSION "\" ", fh);
209 fprintf(fh, "creator=\"%s/%s\">\n", PACKAGE, VERSION);
213 proto_tree_write_pdml(epan_dissect_t *edt, FILE *fh)
215 write_pdml_data data;
217 /* Create the output */
220 data.src_list = edt->pi.data_src;
223 fprintf(fh, "<packet>\n");
225 /* Print a "geninfo" protocol as required by PDML */
226 print_pdml_geninfo(edt->tree, fh);
228 proto_tree_children_foreach(edt->tree, proto_tree_write_node_pdml,
231 fprintf(fh, "</packet>\n\n");
234 /* Write out a tree's data, and any child nodes, as PDML */
236 proto_tree_write_node_pdml(proto_node *node, gpointer data)
238 field_info *fi = PITEM_FINFO(node);
239 write_pdml_data *pdata = (write_pdml_data*) data;
240 const gchar *label_ptr;
241 gchar label_str[ITEM_LABEL_LENGTH];
242 char *dfilter_string;
246 for (i = -1; i < pdata->level; i++) {
247 fputs(" ", pdata->fh);
250 /* Text label. It's printed as a field with no name. */
251 if (fi->hfinfo->id == hf_text_only) {
254 label_ptr = fi->rep->representation;
260 fputs("<field show=\"", pdata->fh);
261 print_escaped_xml(pdata->fh, label_ptr);
263 fprintf(pdata->fh, "\" size=\"%d", fi->length);
264 fprintf(pdata->fh, "\" pos=\"%d", fi->start);
266 fputs("\" value=\"", pdata->fh);
267 write_pdml_field_hex_value(pdata, fi);
269 if (node->first_child != NULL) {
270 fputs("\">\n", pdata->fh);
273 fputs("\"/>\n", pdata->fh);
276 /* Uninterpreted data, i.e., the "Data" protocol, is
277 * printed as a field instead of a protocol. */
278 else if (fi->hfinfo->id == proto_data) {
280 fputs("<field name=\"data\" value=\"", pdata->fh);
282 write_pdml_field_hex_value(pdata, fi);
284 fputs("\"/>\n", pdata->fh);
287 /* Normal protocols and fields */
289 if (fi->hfinfo->type == FT_PROTOCOL) {
290 fputs("<proto name=\"", pdata->fh);
293 fputs("<field name=\"", pdata->fh);
295 print_escaped_xml(pdata->fh, fi->hfinfo->abbrev);
299 * http://analyzer.polito.it/30alpha/docs/dissectors/PDMLSpec.htm
301 * the show fields contains things in 'human readable' format
302 * showname: contains only the name of the field
303 * show: contains only the data of the field
304 * showdtl: contains additional details of the field data
305 * showmap: contains mappings of the field data (e.g. the hostname to an IP address)
307 * XXX - the showname shouldn't contain the field data itself
308 * (like it's contained in the fi->rep->representation).
309 * Unfortunately, we don't have the field data representation for
310 * all fields, so this isn't currently possible */
311 fputs("\" showname=\"", pdata->fh);
312 print_escaped_xml(pdata->fh, fi->hfinfo->name);
316 fputs("\" showname=\"", pdata->fh);
317 print_escaped_xml(pdata->fh, fi->rep->representation);
320 label_ptr = label_str;
321 proto_item_fill_label(fi, label_str);
322 fputs("\" showname=\"", pdata->fh);
323 print_escaped_xml(pdata->fh, label_ptr);
326 if (PROTO_ITEM_IS_HIDDEN(node))
327 fprintf(pdata->fh, "\" hide=\"yes");
329 fprintf(pdata->fh, "\" size=\"%d", fi->length);
330 fprintf(pdata->fh, "\" pos=\"%d", fi->start);
331 /* fprintf(pdata->fh, "\" id=\"%d", fi->hfinfo->id);*/
333 /* show, value, and unmaskedvalue attributes */
334 switch (fi->hfinfo->type)
339 fputs("\" show=\"\" value=\"", pdata->fh);
342 /* XXX - this is a hack until we can just call
343 * fvalue_to_string_repr() for *all* FT_* types. */
344 dfilter_string = proto_construct_dfilter_string(fi,
346 if (dfilter_string != NULL) {
347 chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
349 /* XXX - Remove double-quotes. Again, once we
350 * can call fvalue_to_string_repr(), we can
351 * ask it not to produce the version for
352 * display-filters, and thus, no
354 if (dfilter_string[strlen(dfilter_string)-1] == '"') {
355 dfilter_string[strlen(dfilter_string)-1] = '\0';
359 fputs("\" show=\"", pdata->fh);
360 print_escaped_xml(pdata->fh, &dfilter_string[chop_len]);
362 if (fi->length > 0) {
363 fputs("\" value=\"", pdata->fh);
365 if (fi->hfinfo->bitmask!=0) {
366 fprintf(pdata->fh, "%X", fvalue_get_integer(&fi->value));
367 fputs("\" unmaskedvalue=\"", pdata->fh);
368 write_pdml_field_hex_value(pdata, fi);
371 write_pdml_field_hex_value(pdata, fi);
376 if (node->first_child != NULL) {
377 fputs("\">\n", pdata->fh);
379 else if (fi->hfinfo->id == proto_data) {
380 fputs("\">\n", pdata->fh);
383 fputs("\"/>\n", pdata->fh);
387 /* We always print all levels for PDML. Recurse here. */
388 if (node->first_child != NULL) {
390 proto_tree_children_foreach(node,
391 proto_tree_write_node_pdml, pdata);
395 if (node->first_child != NULL) {
396 for (i = -1; i < pdata->level; i++) {
397 fputs(" ", pdata->fh);
399 if (fi->hfinfo->type == FT_PROTOCOL) {
400 fputs("</proto>\n", pdata->fh);
403 fputs("</field>\n", pdata->fh);
408 /* Print info for a 'geninfo' pseudo-protocol. This is required by
409 * the PDML spec. The information is contained in Wireshark's 'frame' protocol,
410 * but we produce a 'geninfo' protocol in the PDML to conform to spec.
411 * The 'frame' protocol follows the 'geninfo' protocol in the PDML. */
413 print_pdml_geninfo(proto_tree *tree, FILE *fh)
415 guint32 num, len, caplen;
417 GPtrArray *finfo_array;
418 field_info *frame_finfo;
420 /* Get frame protocol's finfo. */
421 finfo_array = proto_find_finfo(tree, proto_frame);
422 if (g_ptr_array_len(finfo_array) < 1) {
425 frame_finfo = finfo_array->pdata[0];
426 g_ptr_array_free(finfo_array, FALSE);
428 /* frame.number --> geninfo.num */
429 finfo_array = proto_find_finfo(tree, hf_frame_number);
430 if (g_ptr_array_len(finfo_array) < 1) {
433 num = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
434 g_ptr_array_free(finfo_array, FALSE);
436 /* frame.pkt_len --> geninfo.len */
437 finfo_array = proto_find_finfo(tree, hf_frame_packet_len);
438 if (g_ptr_array_len(finfo_array) < 1) {
441 len = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
442 g_ptr_array_free(finfo_array, FALSE);
444 /* frame.cap_len --> geninfo.caplen */
445 finfo_array = proto_find_finfo(tree, hf_frame_capture_len);
446 if (g_ptr_array_len(finfo_array) < 1) {
449 caplen = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
450 g_ptr_array_free(finfo_array, FALSE);
452 /* frame.time --> geninfo.timestamp */
453 finfo_array = proto_find_finfo(tree, hf_frame_arrival_time);
454 if (g_ptr_array_len(finfo_array) < 1) {
457 timestamp = fvalue_get(&((field_info*)finfo_array->pdata[0])->value);
458 g_ptr_array_free(finfo_array, FALSE);
460 /* Print geninfo start */
462 " <proto name=\"geninfo\" pos=\"0\" showname=\"General information\" size=\"%u\">\n",
463 frame_finfo->length);
465 /* Print geninfo.num */
467 " <field name=\"num\" pos=\"0\" show=\"%u\" showname=\"Number\" value=\"%x\" size=\"%u\"/>\n",
468 num, num, frame_finfo->length);
470 /* Print geninfo.len */
472 " <field name=\"len\" pos=\"0\" show=\"%u\" showname=\"Packet Length\" value=\"%x\" size=\"%u\"/>\n",
473 len, len, frame_finfo->length);
475 /* Print geninfo.caplen */
477 " <field name=\"caplen\" pos=\"0\" show=\"%u\" showname=\"Captured Length\" value=\"%x\" size=\"%u\"/>\n",
478 caplen, caplen, frame_finfo->length);
480 /* Print geninfo.timestamp */
482 " <field name=\"timestamp\" pos=\"0\" show=\"%s\" showname=\"Captured Time\" value=\"%d.%09d\" size=\"%u\"/>\n",
483 abs_time_to_str(timestamp), (int) timestamp->secs, timestamp->nsecs, frame_finfo->length);
485 /* Print geninfo end */
491 write_pdml_finale(FILE *fh)
493 fputs("</pdml>\n", fh);
497 write_psml_preamble(FILE *fh)
499 fputs("<?xml version=\"1.0\"?>\n", fh);
500 fputs("<psml version=\"" PSML_VERSION "\" ", fh);
501 fprintf(fh, "creator=\"%s/%s\">\n", PACKAGE, VERSION);
505 proto_tree_write_psml(epan_dissect_t *edt, FILE *fh)
509 /* if this is the first packet, we have to create the PSML structure output */
510 if(edt->pi.fd->num == 1) {
511 fprintf(fh, "<structure>\n");
513 for(i=0; i < edt->pi.cinfo->num_cols; i++) {
514 fprintf(fh, "<section>");
515 print_escaped_xml(fh, edt->pi.cinfo->col_title[i]);
516 fprintf(fh, "</section>\n");
519 fprintf(fh, "</structure>\n\n");
522 fprintf(fh, "<packet>\n");
524 for(i=0; i < edt->pi.cinfo->num_cols; i++) {
525 fprintf(fh, "<section>");
526 print_escaped_xml(fh, edt->pi.cinfo->col_data[i]);
527 fprintf(fh, "</section>\n");
530 fprintf(fh, "</packet>\n\n");
534 write_psml_finale(FILE *fh)
536 fputs("</psml>\n", fh);
540 write_csv_preamble(FILE *fh _U_)
546 proto_tree_write_csv(epan_dissect_t *edt, FILE *fh)
550 /* if this is the first packet, we have to write the CSV header */
551 if(edt->pi.fd->num == 1) {
552 for(i=0; i < edt->pi.cinfo->num_cols - 1; i++)
553 fprintf(fh, "\"%s\",", edt->pi.cinfo->col_title[i]);
555 fprintf(fh, "\"%s\"\n", edt->pi.cinfo->col_title[i]);
558 for(i=0; i < edt->pi.cinfo->num_cols - 1; i++)
559 fprintf(fh, "\"%s\",", edt->pi.cinfo->col_data[i]);
561 fprintf(fh, "\"%s\"\n", edt->pi.cinfo->col_data[i]);
565 write_csv_finale(FILE *fh _U_)
571 * Find the data source for a specified field, and return a pointer
572 * to the data in it. Returns NULL if the data is out of bounds.
574 static const guint8 *
575 get_field_data(GSList *src_list, field_info *fi)
580 gint length, tvbuff_length;
582 for (src_le = src_list; src_le != NULL; src_le = src_le->next) {
585 if (fi->ds_tvb == src_tvb) {
589 * XXX - a field can have a length that runs past
590 * the end of the tvbuff. Ideally, that should
591 * be fixed when adding an item to the protocol
592 * tree, but checking the length when doing
593 * that could be expensive. Until we fix that,
594 * we'll do the check here.
596 tvbuff_length = tvb_length_remaining(src_tvb,
598 if (tvbuff_length < 0) {
602 if (length > tvbuff_length)
603 length = tvbuff_length;
604 return tvb_get_ptr(src_tvb, fi->start, length);
607 g_assert_not_reached();
608 return NULL; /* not found */
611 /* Print a string, escaping out certain characters that need to
612 * escaped out for XML. */
614 print_escaped_xml(FILE *fh, const char *unescaped_string)
616 const unsigned char *p;
618 for (p = unescaped_string; *p != '\0'; p++) {
642 write_pdml_field_hex_value(write_pdml_data *pdata, field_info *fi)
647 if (fi->length > tvb_length_remaining(fi->ds_tvb, fi->start)) {
648 fprintf(pdata->fh, "field length invalid!");
652 /* Find the data for this field. */
653 pd = get_field_data(pdata->src_list, fi);
656 /* Print a simple hex dump */
657 for (i = 0 ; i < fi->length; i++) {
658 fprintf(pdata->fh, "%02x", pd[i]);
664 print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
666 gboolean multiple_sources;
676 * Set "multiple_sources" iff this frame has more than one
677 * data source; if it does, we need to print the name of
678 * the data source before printing the data from the
681 multiple_sources = (edt->pi.data_src->next != NULL);
683 for (src_le = edt->pi.data_src; src_le != NULL;
684 src_le = src_le->next) {
687 if (multiple_sources) {
689 print_line(stream, 0, "");
690 line = g_malloc(strlen(name) + 2); /* <name>:\0 */
693 print_line(stream, 0, line);
696 length = tvb_length(tvb);
699 cp = tvb_get_ptr(tvb, 0, length);
700 if (!print_hex_data_buffer(stream, cp, length,
701 edt->pi.fd->flags.encoding))
708 * This routine is based on a routine created by Dan Lasley
709 * <DLASLEY@PROMUS.com>.
711 * It was modified for Wireshark by Gilbert Ramirez and others.
714 #define MAX_OFFSET_LEN 8 /* max length of hex offset of bytes */
715 #define BYTES_PER_LINE 16 /* max byte values printed on a line */
716 #define HEX_DUMP_LEN (BYTES_PER_LINE*3)
717 /* max number of characters hex dump takes -
718 2 digits plus trailing blank */
719 #define DATA_DUMP_LEN (HEX_DUMP_LEN + 2 + BYTES_PER_LINE)
720 /* number of characters those bytes take;
721 3 characters per byte of hex dump,
722 2 blanks separating hex from ASCII,
723 1 character per byte of ASCII dump */
724 #define MAX_LINE_LEN (MAX_OFFSET_LEN + 2 + DATA_DUMP_LEN)
725 /* number of characters per line;
726 offset, 2 blanks separating offset
727 from data dump, data dump */
730 print_hex_data_buffer(print_stream_t *stream, const guchar *cp,
731 guint length, char_enc encoding)
733 register unsigned int ad, i, j, k, l;
735 guchar line[MAX_LINE_LEN + 1];
736 unsigned int use_digits;
737 static guchar binhex[16] = {
738 '0', '1', '2', '3', '4', '5', '6', '7',
739 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
741 if (!print_line(stream, 0, ""))
745 * How many of the leading digits of the offset will we supply?
746 * We always supply at least 4 digits, but if the maximum offset
747 * won't fit in 4 digits, we use as many digits as will be needed.
749 if (((length - 1) & 0xF0000000) != 0)
750 use_digits = 8; /* need all 8 digits */
751 else if (((length - 1) & 0x0F000000) != 0)
752 use_digits = 7; /* need 7 digits */
753 else if (((length - 1) & 0x00F00000) != 0)
754 use_digits = 6; /* need 6 digits */
755 else if (((length - 1) & 0x000F0000) != 0)
756 use_digits = 5; /* need 5 digits */
758 use_digits = 4; /* we'll supply 4 digits */
767 * Start of a new line.
774 c = (ad >> (l*4)) & 0xF;
775 line[j++] = binhex[c];
779 memset(line+j, ' ', DATA_DUMP_LEN);
782 * Offset in line of ASCII dump.
784 k = j + HEX_DUMP_LEN + 2;
787 line[j++] = binhex[c>>4];
788 line[j++] = binhex[c&0xf];
790 if (encoding == CHAR_EBCDIC) {
791 c = EBCDIC_to_ASCII1(c);
793 line[k++] = c >= ' ' && c < 0x7f ? c : '.';
795 if ((i & 15) == 0 || i == length) {
797 * We'll be starting a new line, or
798 * we're finished printing this buffer;
799 * dump out the line we've constructed,
800 * and advance the offset.
803 if (!print_line(stream, 0, line))
812 void ps_clean_string(unsigned char *out, const unsigned char *in,
818 for (rd = 0, wr = 0 ; wr < outbuf_size; rd++, wr++ ) {
839 /* Some formats need stuff at the beginning of the output */
841 print_preamble(print_stream_t *self, gchar *filename)
843 return (self->ops->print_preamble)(self, filename);
847 print_line(print_stream_t *self, int indent, const char *line)
849 return (self->ops->print_line)(self, indent, line);
852 /* Insert bookmark */
854 print_bookmark(print_stream_t *self, const gchar *name, const gchar *title)
856 return (self->ops->print_bookmark)(self, name, title);
860 new_page(print_stream_t *self)
862 return (self->ops->new_page)(self);
865 /* Some formats need stuff at the end of the output */
867 print_finale(print_stream_t *self)
869 return (self->ops->print_finale)(self);
873 destroy_print_stream(print_stream_t *self)
875 return (self->ops->destroy)(self);
884 print_preamble_text(print_stream_t *self _U_, gchar *filename _U_)
887 return TRUE; /* always succeeds */
891 print_line_text(print_stream_t *self, int indent, const char *line)
893 output_text *output = self->data;
894 char space[MAX_INDENT+1];
898 /* Prepare the tabs for printing, depending on tree level */
899 num_spaces = indent * 4;
900 if (num_spaces > MAX_INDENT) {
901 num_spaces = MAX_INDENT;
903 for (i = 0; i < num_spaces; i++) {
906 /* The string is NUL-terminated */
907 space[num_spaces] = '\0';
909 fputs(space, output->fh);
910 fputs(line, output->fh);
911 putc('\n', output->fh);
912 return !ferror(output->fh);
916 print_bookmark_text(print_stream_t *self _U_, const gchar *name _U_,
917 const gchar *title _U_)
924 new_page_text(print_stream_t *self)
926 output_text *output = self->data;
928 fputs("\f", output->fh);
929 return !ferror(output->fh);
933 print_finale_text(print_stream_t *self _U_)
936 return TRUE; /* always succeeds */
940 destroy_text(print_stream_t *self)
942 output_text *output = self->data;
945 ret = close_print_dest(output->to_file, output->fh);
951 static const print_stream_ops_t print_text_ops = {
961 print_stream_text_new(int to_file, const char *dest)
964 print_stream_t *stream;
967 fh = open_print_dest(to_file, dest);
971 output = g_malloc(sizeof *output);
972 output->to_file = to_file;
974 stream = g_malloc(sizeof (print_stream_t));
975 stream->ops = &print_text_ops;
976 stream->data = output;
982 print_stream_text_stdio_new(FILE *fh)
984 print_stream_t *stream;
987 output = g_malloc(sizeof *output);
988 output->to_file = TRUE;
990 stream = g_malloc(sizeof (print_stream_t));
991 stream->ops = &print_text_ops;
992 stream->data = output;
1003 print_preamble_ps(print_stream_t *self, gchar *filename)
1005 output_ps *output = self->data;
1006 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
1008 print_ps_preamble(output->fh);
1010 fputs("%% Set the font to 10 point\n", output->fh);
1011 fputs("/Courier findfont 10 scalefont setfont\n", output->fh);
1012 fputs("\n", output->fh);
1013 fputs("%% the page title\n", output->fh);
1014 ps_clean_string(psbuffer, filename, MAX_PS_LINE_LENGTH);
1015 fprintf(output->fh, "/eth_pagetitle (%s - Wireshark) def\n", psbuffer);
1016 fputs("\n", output->fh);
1017 return !ferror(output->fh);
1021 print_line_ps(print_stream_t *self, int indent, const char *line)
1023 output_ps *output = self->data;
1024 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
1026 ps_clean_string(psbuffer, line, MAX_PS_LINE_LENGTH);
1027 fprintf(output->fh, "%d (%s) putline\n", indent, psbuffer);
1028 return !ferror(output->fh);
1032 print_bookmark_ps(print_stream_t *self, const gchar *name, const gchar *title)
1034 output_ps *output = self->data;
1035 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
1038 * See the Adobe "pdfmark reference":
1040 * http://partners.adobe.com/asn/acrobat/docs/pdfmark.pdf
1042 * The pdfmark stuff tells code that turns PostScript into PDF
1043 * things that it should do.
1045 * The /OUT stuff creates a bookmark that goes to the
1046 * destination with "name" as the name and "title" as the title.
1048 * The "/DEST" creates the destination.
1050 ps_clean_string(psbuffer, title, MAX_PS_LINE_LENGTH);
1051 fprintf(output->fh, "[/Dest /%s /Title (%s) /OUT pdfmark\n", name,
1053 fputs("[/View [/XYZ -4 currentpoint matrix currentmatrix matrix defaultmatrix\n",
1055 fputs("matrix invertmatrix matrix concatmatrix transform exch pop 20 add null]\n",
1057 fprintf(output->fh, "/Dest /%s /DEST pdfmark\n", name);
1058 return !ferror(output->fh);
1062 new_page_ps(print_stream_t *self)
1064 output_ps *output = self->data;
1066 fputs("formfeed\n", output->fh);
1067 return !ferror(output->fh);
1071 print_finale_ps(print_stream_t *self)
1073 output_ps *output = self->data;
1075 print_ps_finale(output->fh);
1076 return !ferror(output->fh);
1080 destroy_ps(print_stream_t *self)
1082 output_ps *output = self->data;
1085 ret = close_print_dest(output->to_file, output->fh);
1091 static const print_stream_ops_t print_ps_ops = {
1101 print_stream_ps_new(int to_file, const char *dest)
1104 print_stream_t *stream;
1107 fh = open_print_dest(to_file, dest);
1111 output = g_malloc(sizeof *output);
1112 output->to_file = to_file;
1114 stream = g_malloc(sizeof (print_stream_t));
1115 stream->ops = &print_ps_ops;
1116 stream->data = output;
1122 print_stream_ps_stdio_new(FILE *fh)
1124 print_stream_t *stream;
1127 output = g_malloc(sizeof *output);
1128 output->to_file = TRUE;
1130 stream = g_malloc(sizeof (print_stream_t));
1131 stream->ops = &print_ps_ops;
1132 stream->data = output;