2 * Routines for printing packet analysis trees.
6 * Gilbert Ramirez <gram@alumni.rice.edu>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
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.
27 /* With MSVC and a libethereal.dll this file needs to import some variables
28 in a special way. Therefore _NEED_VAR_IMPORT_ is defined. */
29 #define _NEED_VAR_IMPORT_
38 #include <epan/epan.h>
39 #include <epan/epan_dissect.h>
40 #include <epan/tvbuff.h>
41 #include <epan/packet.h>
43 #include "packet-range.h"
46 #include <epan/charsets.h>
47 #include <epan/dissectors/packet-data.h>
48 #include <epan/dissectors/packet-frame.h>
50 #define PDML_VERSION "0"
51 #define PSML_VERSION "0"
55 print_stream_t *stream;
58 print_dissections_e print_dissections;
59 gboolean print_hex_for_data;
71 static void proto_tree_print_node(proto_node *node, gpointer data);
72 static void proto_tree_write_node_pdml(proto_node *node, gpointer data);
73 static const guint8 *get_field_data(GSList *src_list, field_info *fi);
74 static void write_pdml_field_hex_value(write_pdml_data *pdata, field_info *fi);
75 static gboolean print_hex_data_buffer(print_stream_t *stream, const guchar *cp,
76 guint length, char_enc encoding);
77 static void ps_clean_string(unsigned char *out, const unsigned char *in,
79 static void print_escaped_xml(FILE *fh, char *unescaped_string);
81 static void print_pdml_geninfo(proto_tree *tree, FILE *fh);
84 open_print_dest(int to_file, const char *dest)
88 /* Open the file or command for output */
90 fh = fopen(dest, "w");
92 fh = popen(dest, "w");
98 close_print_dest(int to_file, FILE *fh)
100 /* Close the file or command */
102 return (fclose(fh) == 0);
104 return (pclose(fh) == 0);
107 #define MAX_PS_LINE_LENGTH 256
110 proto_tree_print(print_args_t *print_args, epan_dissect_t *edt,
111 print_stream_t *stream)
115 /* Create the output */
117 data.stream = stream;
119 data.src_list = edt->pi.data_src;
120 data.encoding = edt->pi.fd->flags.encoding;
121 data.print_dissections = print_args->print_dissections;
122 /* If we're printing the entire packet in hex, don't
123 print uninterpreted data fields in hex as well. */
124 data.print_hex_for_data = !print_args->print_hex;
127 proto_tree_children_foreach(edt->tree, proto_tree_print_node, &data);
131 #define MAX_INDENT 160
133 /* Print a tree's data, and any child nodes. */
135 void proto_tree_print_node(proto_node *node, gpointer data)
137 field_info *fi = PITEM_FINFO(node);
138 print_data *pdata = (print_data*) data;
140 gchar label_str[ITEM_LABEL_LENGTH];
143 /* Don't print invisible entries. */
144 if (PROTO_ITEM_IS_HIDDEN(node))
147 /* Give up if we've already gotten an error. */
151 /* was a free format label produced? */
153 label_ptr = fi->rep->representation;
155 else { /* no, make a generic label */
156 label_ptr = label_str;
157 proto_item_fill_label(fi, label_str);
160 if (!print_line(pdata->stream, pdata->level, label_ptr)) {
161 pdata->success = FALSE;
165 /* If it's uninterpreted data, dump it (unless our caller will
166 be printing the entire packet in hex). */
167 if (fi->hfinfo->id == proto_data && pdata->print_hex_for_data) {
169 * Find the data for this field.
171 pd = get_field_data(pdata->src_list, fi);
173 if (!print_hex_data_buffer(pdata->stream, pd,
174 fi->length, pdata->encoding)) {
175 pdata->success = FALSE;
181 /* If we're printing all levels, or if this node is one with a
182 subtree and its subtree is expanded, recurse into the subtree,
184 g_assert(fi->tree_type >= -1 && fi->tree_type < num_tree_types);
185 if (pdata->print_dissections == print_dissections_expanded ||
186 (pdata->print_dissections == print_dissections_as_displayed &&
187 fi->tree_type >= 0 && tree_is_expanded[fi->tree_type])) {
188 if (node->first_child != NULL) {
190 proto_tree_children_foreach(node,
191 proto_tree_print_node, pdata);
200 write_pdml_preamble(FILE *fh)
202 fputs("<?xml version=\"1.0\"?>\n", fh);
203 fputs("<pdml version=\"" PDML_VERSION "\" ", fh);
204 fprintf(fh, "creator=\"%s/%s\">\n", PACKAGE, VERSION);
208 proto_tree_write_pdml(epan_dissect_t *edt, FILE *fh)
210 write_pdml_data data;
212 /* Create the output */
215 data.src_list = edt->pi.data_src;
218 fprintf(fh, "<packet>\n");
220 /* Print a "geninfo" protocol as required by PDML */
221 print_pdml_geninfo(edt->tree, fh);
223 proto_tree_children_foreach(edt->tree, proto_tree_write_node_pdml,
226 fprintf(fh, "</packet>\n\n");
229 /* Write out a tree's data, and any child nodes, as PDML */
231 proto_tree_write_node_pdml(proto_node *node, gpointer data)
233 field_info *fi = PITEM_FINFO(node);
234 write_pdml_data *pdata = (write_pdml_data*) data;
236 gchar label_str[ITEM_LABEL_LENGTH];
237 char *dfilter_string;
241 for (i = -1; i < pdata->level; i++) {
242 fputs(" ", pdata->fh);
245 /* Text label. It's printed as a field with no name. */
246 if (fi->hfinfo->id == hf_text_only) {
249 label_ptr = fi->rep->representation;
255 fputs("<field show=\"", pdata->fh);
256 print_escaped_xml(pdata->fh, label_ptr);
258 fprintf(pdata->fh, "\" size=\"%d", fi->length);
259 fprintf(pdata->fh, "\" pos=\"%d", fi->start);
261 fputs("\" value=\"", pdata->fh);
262 write_pdml_field_hex_value(pdata, fi);
264 if (node->first_child != NULL) {
265 fputs("\">\n", pdata->fh);
268 fputs("\"/>\n", pdata->fh);
271 /* Uninterpreted data, i.e., the "Data" protocol, is
272 * printed as a field instead of a protocol. */
273 else if (fi->hfinfo->id == proto_data) {
275 fputs("<field name=\"data\" value=\"", pdata->fh);
277 write_pdml_field_hex_value(pdata, fi);
279 fputs("\"/>\n", pdata->fh);
282 /* Normal protocols and fields */
284 if (fi->hfinfo->type == FT_PROTOCOL) {
285 fputs("<proto name=\"", pdata->fh);
288 fputs("<field name=\"", pdata->fh);
290 print_escaped_xml(pdata->fh, fi->hfinfo->abbrev);
294 * http://analyzer.polito.it/30alpha/docs/dissectors/PDMLSpec.htm
296 * the show fields contains things in 'human readable' format
297 * showname: contains only the name of the field
298 * show: contains only the data of the field
299 * showdtl: contains additional details of the field data
300 * showmap: contains mappings of the field data (e.g. the hostname to an IP address)
302 * XXX - the showname shouldn't contain the field data itself
303 * (like it's contained in the fi->rep->representation).
304 * Unfortunately, we don't have the field data representation for
305 * all fields, so this isn't currently possible */
306 fputs("\" showname=\"", pdata->fh);
307 print_escaped_xml(pdata->fh, fi->hfinfo->name);
311 fputs("\" showname=\"", pdata->fh);
312 print_escaped_xml(pdata->fh, fi->rep->representation);
315 label_ptr = label_str;
316 proto_item_fill_label(fi, label_str);
317 fputs("\" showname=\"", pdata->fh);
318 print_escaped_xml(pdata->fh, label_ptr);
321 if (PROTO_ITEM_IS_HIDDEN(node))
322 fprintf(pdata->fh, "\" hide=\"yes");
324 fprintf(pdata->fh, "\" size=\"%d", fi->length);
325 fprintf(pdata->fh, "\" pos=\"%d", fi->start);
326 /* fprintf(pdata->fh, "\" id=\"%d", fi->hfinfo->id);*/
328 if (fi->hfinfo->type != FT_PROTOCOL) {
331 /* XXX - this is a hack until we can just call
332 * fvalue_to_string_repr() for *all* FT_* types. */
333 dfilter_string = proto_construct_dfilter_string(fi,
335 if (dfilter_string != NULL) {
336 chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
338 /* XXX - Remove double-quotes. Again, once we
339 * can call fvalue_to_string_repr(), we can
340 * ask it not to produce the version for
341 * display-filters, and thus, no
343 if (dfilter_string[strlen(dfilter_string)-1] == '"') {
344 dfilter_string[strlen(dfilter_string)-1] = '\0';
348 fputs("\" show=\"", pdata->fh);
349 print_escaped_xml(pdata->fh, &dfilter_string[chop_len]);
351 if (fi->length > 0) {
352 fputs("\" value=\"", pdata->fh);
353 write_pdml_field_hex_value(pdata, fi);
357 if (node->first_child != NULL) {
358 fputs("\">\n", pdata->fh);
360 else if (fi->hfinfo->id == proto_data) {
361 fputs("\">\n", pdata->fh);
364 fputs("\"/>\n", pdata->fh);
368 /* We always print all levels for PDML. Recurse here. */
369 if (node->first_child != NULL) {
371 proto_tree_children_foreach(node,
372 proto_tree_write_node_pdml, pdata);
376 if (node->first_child != NULL) {
377 for (i = -1; i < pdata->level; i++) {
378 fputs(" ", pdata->fh);
380 if (fi->hfinfo->type == FT_PROTOCOL) {
381 fputs("</proto>\n", pdata->fh);
384 fputs("</field>\n", pdata->fh);
389 /* Print info for a 'geninfo' pseudo-protocol. This is required by
390 * the PDML spec. The information is contained in Ethereal's 'frame' protocol,
391 * but we produce a 'geninfo' protocol in the PDML to conform to spec.
392 * The 'frame' protocol follows the 'geninfo' protocol in the PDML. */
394 print_pdml_geninfo(proto_tree *tree, FILE *fh)
396 guint32 num, len, caplen;
398 GPtrArray *finfo_array;
399 field_info *frame_finfo;
401 /* Get frame protocol's finfo. */
402 finfo_array = proto_find_finfo(tree, proto_frame);
403 if (g_ptr_array_len(finfo_array) < 1) {
406 frame_finfo = finfo_array->pdata[0];
407 g_ptr_array_free(finfo_array, FALSE);
409 /* frame.number --> geninfo.num */
410 finfo_array = proto_find_finfo(tree, hf_frame_number);
411 if (g_ptr_array_len(finfo_array) < 1) {
414 num = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
415 g_ptr_array_free(finfo_array, FALSE);
417 /* frame.pkt_len --> geninfo.len */
418 finfo_array = proto_find_finfo(tree, hf_frame_packet_len);
419 if (g_ptr_array_len(finfo_array) < 1) {
422 len = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
423 g_ptr_array_free(finfo_array, FALSE);
425 /* frame.cap_len --> geninfo.caplen */
426 finfo_array = proto_find_finfo(tree, hf_frame_capture_len);
427 if (g_ptr_array_len(finfo_array) < 1) {
430 caplen = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
431 g_ptr_array_free(finfo_array, FALSE);
433 /* frame.time --> geninfo.timestamp */
434 finfo_array = proto_find_finfo(tree, hf_frame_arrival_time);
435 if (g_ptr_array_len(finfo_array) < 1) {
438 timestamp = fvalue_get(&((field_info*)finfo_array->pdata[0])->value);
439 g_ptr_array_free(finfo_array, FALSE);
441 /* Print geninfo start */
443 " <proto name=\"geninfo\" pos=\"0\" showname=\"General information\" size=\"%u\">\n",
444 frame_finfo->length);
446 /* Print geninfo.num */
448 " <field name=\"num\" pos=\"0\" show=\"%u\" showname=\"Number\" value=\"%x\" size=\"%u\"/>\n",
449 num, num, frame_finfo->length);
451 /* Print geninfo.len */
453 " <field name=\"len\" pos=\"0\" show=\"%u\" showname=\"Packet Length\" value=\"%x\" size=\"%u\"/>\n",
454 len, len, frame_finfo->length);
456 /* Print geninfo.caplen */
458 " <field name=\"caplen\" pos=\"0\" show=\"%u\" showname=\"Captured Length\" value=\"%x\" size=\"%u\"/>\n",
459 caplen, caplen, frame_finfo->length);
461 /* Print geninfo.timestamp */
463 " <field name=\"timestamp\" pos=\"0\" show=\"%s\" showname=\"Captured Time\" value=\"%d.%09d\" size=\"%u\"/>\n",
464 abs_time_to_str(timestamp), (int) timestamp->secs, timestamp->nsecs, frame_finfo->length);
466 /* Print geninfo end */
472 write_pdml_finale(FILE *fh)
474 fputs("</pdml>\n", fh);
478 write_psml_preamble(FILE *fh)
480 fputs("<?xml version=\"1.0\"?>\n", fh);
481 fputs("<psml version=\"" PSML_VERSION "\" ", fh);
482 fprintf(fh, "creator=\"%s/%s\">\n", PACKAGE, VERSION);
486 proto_tree_write_psml(epan_dissect_t *edt, FILE *fh)
490 /* if this is the first packet, we have to create the PSML structure output */
491 if(edt->pi.fd->num == 1) {
492 fprintf(fh, "<structure>\n");
494 for(i=0; i < edt->pi.cinfo->num_cols; i++) {
495 fprintf(fh, "<section>");
496 print_escaped_xml(fh, edt->pi.cinfo->col_title[i]);
497 fprintf(fh, "</section>\n");
500 fprintf(fh, "</structure>\n\n");
503 fprintf(fh, "<packet>\n");
505 for(i=0; i < edt->pi.cinfo->num_cols; i++) {
506 fprintf(fh, "<section>");
507 print_escaped_xml(fh, edt->pi.cinfo->col_data[i]);
508 fprintf(fh, "</section>\n");
511 fprintf(fh, "</packet>\n\n");
515 write_psml_finale(FILE *fh)
517 fputs("</psml>\n", fh);
521 * Find the data source for a specified field, and return a pointer
522 * to the data in it. Returns NULL if the data is out of bounds.
524 static const guint8 *
525 get_field_data(GSList *src_list, field_info *fi)
530 gint length, tvbuff_length;
532 for (src_le = src_list; src_le != NULL; src_le = src_le->next) {
535 if (fi->ds_tvb == src_tvb) {
539 * XXX - a field can have a length that runs past
540 * the end of the tvbuff. Ideally, that should
541 * be fixed when adding an item to the protocol
542 * tree, but checking the length when doing
543 * that could be expensive. Until we fix that,
544 * we'll do the check here.
546 tvbuff_length = tvb_length_remaining(src_tvb,
548 if (tvbuff_length < 0) {
552 if (length > tvbuff_length)
553 length = tvbuff_length;
554 return tvb_get_ptr(src_tvb, fi->start, length);
557 g_assert_not_reached();
558 return NULL; /* not found */
561 /* Print a string, escaping out certain characters that need to
562 * escaped out for XML. */
564 print_escaped_xml(FILE *fh, char *unescaped_string)
568 for (p = unescaped_string; *p != '\0'; p++) {
592 write_pdml_field_hex_value(write_pdml_data *pdata, field_info *fi)
597 if (fi->length > tvb_length_remaining(fi->ds_tvb, fi->start)) {
598 fprintf(pdata->fh, "field length invalid!");
602 /* Find the data for this field. */
603 pd = get_field_data(pdata->src_list, fi);
606 /* Print a simple hex dump */
607 for (i = 0 ; i < fi->length; i++) {
608 fprintf(pdata->fh, "%02x", pd[i]);
614 print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
616 gboolean multiple_sources;
626 * Set "multiple_sources" iff this frame has more than one
627 * data source; if it does, we need to print the name of
628 * the data source before printing the data from the
631 multiple_sources = (edt->pi.data_src->next != NULL);
633 for (src_le = edt->pi.data_src; src_le != NULL;
634 src_le = src_le->next) {
637 if (multiple_sources) {
639 print_line(stream, 0, "");
640 line = g_malloc(strlen(name) + 2); /* <name>:\0 */
643 print_line(stream, 0, line);
646 length = tvb_length(tvb);
647 cp = tvb_get_ptr(tvb, 0, length);
648 if (!print_hex_data_buffer(stream, cp, length,
649 edt->pi.fd->flags.encoding))
656 * This routine is based on a routine created by Dan Lasley
657 * <DLASLEY@PROMUS.com>.
659 * It was modified for Ethereal by Gilbert Ramirez and others.
662 #define MAX_OFFSET_LEN 8 /* max length of hex offset of bytes */
663 #define BYTES_PER_LINE 16 /* max byte values printed on a line */
664 #define HEX_DUMP_LEN (BYTES_PER_LINE*3)
665 /* max number of characters hex dump takes -
666 2 digits plus trailing blank */
667 #define DATA_DUMP_LEN (HEX_DUMP_LEN + 2 + BYTES_PER_LINE)
668 /* number of characters those bytes take;
669 3 characters per byte of hex dump,
670 2 blanks separating hex from ASCII,
671 1 character per byte of ASCII dump */
672 #define MAX_LINE_LEN (MAX_OFFSET_LEN + 2 + DATA_DUMP_LEN)
673 /* number of characters per line;
674 offset, 2 blanks separating offset
675 from data dump, data dump */
678 print_hex_data_buffer(print_stream_t *stream, const guchar *cp,
679 guint length, char_enc encoding)
681 register unsigned int ad, i, j, k, l;
683 guchar line[MAX_LINE_LEN + 1];
684 unsigned int use_digits;
685 static guchar binhex[16] = {
686 '0', '1', '2', '3', '4', '5', '6', '7',
687 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
689 if (!print_line(stream, 0, ""))
693 * How many of the leading digits of the offset will we supply?
694 * We always supply at least 4 digits, but if the maximum offset
695 * won't fit in 4 digits, we use as many digits as will be needed.
697 if (((length - 1) & 0xF0000000) != 0)
698 use_digits = 8; /* need all 8 digits */
699 else if (((length - 1) & 0x0F000000) != 0)
700 use_digits = 7; /* need 7 digits */
701 else if (((length - 1) & 0x00F00000) != 0)
702 use_digits = 6; /* need 6 digits */
703 else if (((length - 1) & 0x000F0000) != 0)
704 use_digits = 5; /* need 5 digits */
706 use_digits = 4; /* we'll supply 4 digits */
715 * Start of a new line.
722 c = (ad >> (l*4)) & 0xF;
723 line[j++] = binhex[c];
727 memset(line+j, ' ', DATA_DUMP_LEN);
730 * Offset in line of ASCII dump.
732 k = j + HEX_DUMP_LEN + 2;
735 line[j++] = binhex[c>>4];
736 line[j++] = binhex[c&0xf];
738 if (encoding == CHAR_EBCDIC) {
739 c = EBCDIC_to_ASCII1(c);
741 line[k++] = c >= ' ' && c < 0x7f ? c : '.';
743 if ((i & 15) == 0 || i == length) {
745 * We'll be starting a new line, or
746 * we're finished printing this buffer;
747 * dump out the line we've constructed,
748 * and advance the offset.
751 if (!print_line(stream, 0, line))
760 void ps_clean_string(unsigned char *out, const unsigned char *in,
766 for (rd = 0, wr = 0 ; wr < outbuf_size; rd++, wr++ ) {
787 /* Some formats need stuff at the beginning of the output */
789 print_preamble(print_stream_t *self, gchar *filename)
791 return (self->ops->print_preamble)(self, filename);
795 print_line(print_stream_t *self, int indent, const char *line)
797 return (self->ops->print_line)(self, indent, line);
800 /* Insert bookmark */
802 print_bookmark(print_stream_t *self, const gchar *name, const gchar *title)
804 return (self->ops->print_bookmark)(self, name, title);
808 new_page(print_stream_t *self)
810 return (self->ops->new_page)(self);
813 /* Some formats need stuff at the end of the output */
815 print_finale(print_stream_t *self)
817 return (self->ops->print_finale)(self);
821 destroy_print_stream(print_stream_t *self)
823 return (self->ops->destroy)(self);
832 print_preamble_text(print_stream_t *self _U_, gchar *filename _U_)
835 return TRUE; /* always succeeds */
839 print_line_text(print_stream_t *self, int indent, const char *line)
841 output_text *output = self->data;
842 char space[MAX_INDENT+1];
846 /* Prepare the tabs for printing, depending on tree level */
847 num_spaces = indent * 4;
848 if (num_spaces > MAX_INDENT) {
849 num_spaces = MAX_INDENT;
851 for (i = 0; i < num_spaces; i++) {
854 /* The string is NUL-terminated */
855 space[num_spaces] = '\0';
857 fputs(space, output->fh);
858 fputs(line, output->fh);
859 putc('\n', output->fh);
860 return !ferror(output->fh);
864 print_bookmark_text(print_stream_t *self _U_, const gchar *name _U_,
865 const gchar *title _U_)
872 new_page_text(print_stream_t *self)
874 output_text *output = self->data;
876 fputs("\f", output->fh);
877 return !ferror(output->fh);
881 print_finale_text(print_stream_t *self _U_)
884 return TRUE; /* always succeeds */
888 destroy_text(print_stream_t *self)
890 output_text *output = self->data;
893 ret = close_print_dest(output->to_file, output->fh);
899 static const print_stream_ops_t print_text_ops = {
909 print_stream_text_new(int to_file, const char *dest)
912 print_stream_t *stream;
915 fh = open_print_dest(to_file, dest);
919 output = g_malloc(sizeof *output);
920 output->to_file = to_file;
922 stream = g_malloc(sizeof (print_stream_t));
923 stream->ops = &print_text_ops;
924 stream->data = output;
930 print_stream_text_stdio_new(FILE *fh)
932 print_stream_t *stream;
935 output = g_malloc(sizeof *output);
936 output->to_file = TRUE;
938 stream = g_malloc(sizeof (print_stream_t));
939 stream->ops = &print_text_ops;
940 stream->data = output;
951 print_preamble_ps(print_stream_t *self, gchar *filename)
953 output_ps *output = self->data;
954 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
956 print_ps_preamble(output->fh);
958 fputs("%% Set the font to 10 point\n", output->fh);
959 fputs("/Courier findfont 10 scalefont setfont\n", output->fh);
960 fputs("\n", output->fh);
961 fputs("%% the page title\n", output->fh);
962 ps_clean_string(psbuffer, filename, MAX_PS_LINE_LENGTH);
963 fprintf(output->fh, "/eth_pagetitle (%s - Ethereal) def\n", psbuffer);
964 fputs("\n", output->fh);
965 return !ferror(output->fh);
969 print_line_ps(print_stream_t *self, int indent, const char *line)
971 output_ps *output = self->data;
972 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
974 ps_clean_string(psbuffer, line, MAX_PS_LINE_LENGTH);
975 fprintf(output->fh, "%d (%s) putline\n", indent, psbuffer);
976 return !ferror(output->fh);
980 print_bookmark_ps(print_stream_t *self, const gchar *name, const gchar *title)
982 output_ps *output = self->data;
983 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
986 * See the Adobe "pdfmark reference":
988 * http://partners.adobe.com/asn/acrobat/docs/pdfmark.pdf
990 * The pdfmark stuff tells code that turns PostScript into PDF
991 * things that it should do.
993 * The /OUT stuff creates a bookmark that goes to the
994 * destination with "name" as the name and "title" as the title.
996 * The "/DEST" creates the destination.
998 ps_clean_string(psbuffer, title, MAX_PS_LINE_LENGTH);
999 fprintf(output->fh, "[/Dest /%s /Title (%s) /OUT pdfmark\n", name,
1001 fputs("[/View [/XYZ -4 currentpoint matrix currentmatrix matrix defaultmatrix\n",
1003 fputs("matrix invertmatrix matrix concatmatrix transform exch pop 20 add null]\n",
1005 fprintf(output->fh, "/Dest /%s /DEST pdfmark\n", name);
1006 return !ferror(output->fh);
1010 new_page_ps(print_stream_t *self)
1012 output_ps *output = self->data;
1014 fputs("formfeed\n", output->fh);
1015 return !ferror(output->fh);
1019 print_finale_ps(print_stream_t *self)
1021 output_ps *output = self->data;
1023 print_ps_finale(output->fh);
1024 return !ferror(output->fh);
1028 destroy_ps(print_stream_t *self)
1030 output_ps *output = self->data;
1033 ret = close_print_dest(output->to_file, output->fh);
1039 static const print_stream_ops_t print_ps_ops = {
1049 print_stream_ps_new(int to_file, const char *dest)
1052 print_stream_t *stream;
1055 fh = open_print_dest(to_file, dest);
1059 output = g_malloc(sizeof *output);
1060 output->to_file = to_file;
1062 stream = g_malloc(sizeof (print_stream_t));
1063 stream->ops = &print_ps_ops;
1064 stream->data = output;
1070 print_stream_ps_stdio_new(FILE *fh)
1072 print_stream_t *stream;
1075 output = g_malloc(sizeof *output);
1076 output->to_file = TRUE;
1078 stream = g_malloc(sizeof (print_stream_t));
1079 stream->ops = &print_ps_ops;
1080 stream->data = output;