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.
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 <epan/charsets.h>
43 #include <epan/dissectors/packet-data.h>
44 #include <epan/dissectors/packet-frame.h>
46 #define PDML_VERSION "0"
47 #define PSML_VERSION "0"
51 print_stream_t *stream;
54 print_dissections_e print_dissections;
55 gboolean print_hex_for_data;
67 static void proto_tree_print_node(proto_node *node, gpointer data);
68 static void proto_tree_write_node_pdml(proto_node *node, gpointer data);
69 static const guint8 *get_field_data(GSList *src_list, field_info *fi);
70 static void write_pdml_field_hex_value(write_pdml_data *pdata, field_info *fi);
71 static gboolean print_hex_data_buffer(print_stream_t *stream, const guchar *cp,
72 guint length, char_enc encoding);
73 static void ps_clean_string(unsigned char *out, const unsigned char *in,
75 static void print_escaped_xml(FILE *fh, const char *unescaped_string);
77 static void print_pdml_geninfo(proto_tree *tree, FILE *fh);
80 open_print_dest(int to_file, const char *dest)
84 /* Open the file or command for output */
86 fh = fopen(dest, "w");
88 fh = popen(dest, "w");
94 close_print_dest(int to_file, FILE *fh)
96 /* Close the file or command */
98 return (fclose(fh) == 0);
100 return (pclose(fh) == 0);
103 #define MAX_PS_LINE_LENGTH 256
106 proto_tree_print(print_args_t *print_args, epan_dissect_t *edt,
107 print_stream_t *stream)
111 /* Create the output */
113 data.stream = stream;
115 data.src_list = edt->pi.data_src;
116 data.encoding = edt->pi.fd->flags.encoding;
117 data.print_dissections = print_args->print_dissections;
118 /* If we're printing the entire packet in hex, don't
119 print uninterpreted data fields in hex as well. */
120 data.print_hex_for_data = !print_args->print_hex;
123 proto_tree_children_foreach(edt->tree, proto_tree_print_node, &data);
127 #define MAX_INDENT 160
129 /* Print a tree's data, and any child nodes. */
131 void proto_tree_print_node(proto_node *node, gpointer data)
133 field_info *fi = PITEM_FINFO(node);
134 print_data *pdata = (print_data*) data;
136 gchar label_str[ITEM_LABEL_LENGTH];
139 /* Don't print invisible entries. */
140 if (PROTO_ITEM_IS_HIDDEN(node))
143 /* Give up if we've already gotten an error. */
147 /* was a free format label produced? */
149 label_ptr = fi->rep->representation;
151 else { /* no, make a generic label */
152 label_ptr = label_str;
153 proto_item_fill_label(fi, label_str);
156 if (!print_line(pdata->stream, pdata->level, label_ptr)) {
157 pdata->success = FALSE;
161 /* If it's uninterpreted data, dump it (unless our caller will
162 be printing the entire packet in hex). */
163 if (fi->hfinfo->id == proto_data && pdata->print_hex_for_data) {
165 * Find the data for this field.
167 pd = get_field_data(pdata->src_list, fi);
169 if (!print_hex_data_buffer(pdata->stream, pd,
170 fi->length, pdata->encoding)) {
171 pdata->success = FALSE;
177 /* If we're printing all levels, or if this node is one with a
178 subtree and its subtree is expanded, recurse into the subtree,
180 g_assert(fi->tree_type >= -1 && fi->tree_type < num_tree_types);
181 if (pdata->print_dissections == print_dissections_expanded ||
182 (pdata->print_dissections == print_dissections_as_displayed &&
183 fi->tree_type >= 0 && tree_is_expanded[fi->tree_type])) {
184 if (node->first_child != NULL) {
186 proto_tree_children_foreach(node,
187 proto_tree_print_node, pdata);
196 write_pdml_preamble(FILE *fh)
198 fputs("<?xml version=\"1.0\"?>\n", fh);
199 fputs("<pdml version=\"" PDML_VERSION "\" ", fh);
200 fprintf(fh, "creator=\"%s/%s\">\n", PACKAGE, VERSION);
204 proto_tree_write_pdml(epan_dissect_t *edt, FILE *fh)
206 write_pdml_data data;
208 /* Create the output */
211 data.src_list = edt->pi.data_src;
214 fprintf(fh, "<packet>\n");
216 /* Print a "geninfo" protocol as required by PDML */
217 print_pdml_geninfo(edt->tree, fh);
219 proto_tree_children_foreach(edt->tree, proto_tree_write_node_pdml,
222 fprintf(fh, "</packet>\n\n");
225 /* Write out a tree's data, and any child nodes, as PDML */
227 proto_tree_write_node_pdml(proto_node *node, gpointer data)
229 field_info *fi = PITEM_FINFO(node);
230 write_pdml_data *pdata = (write_pdml_data*) data;
232 gchar label_str[ITEM_LABEL_LENGTH];
233 char *dfilter_string;
237 for (i = -1; i < pdata->level; i++) {
238 fputs(" ", pdata->fh);
241 /* Text label. It's printed as a field with no name. */
242 if (fi->hfinfo->id == hf_text_only) {
245 label_ptr = fi->rep->representation;
251 fputs("<field show=\"", pdata->fh);
252 print_escaped_xml(pdata->fh, label_ptr);
254 fprintf(pdata->fh, "\" size=\"%d", fi->length);
255 fprintf(pdata->fh, "\" pos=\"%d", fi->start);
257 fputs("\" value=\"", pdata->fh);
258 write_pdml_field_hex_value(pdata, fi);
260 if (node->first_child != NULL) {
261 fputs("\">\n", pdata->fh);
264 fputs("\"/>\n", pdata->fh);
267 /* Uninterpreted data, i.e., the "Data" protocol, is
268 * printed as a field instead of a protocol. */
269 else if (fi->hfinfo->id == proto_data) {
271 fputs("<field name=\"data\" value=\"", pdata->fh);
273 write_pdml_field_hex_value(pdata, fi);
275 fputs("\"/>\n", pdata->fh);
278 /* Normal protocols and fields */
280 if (fi->hfinfo->type == FT_PROTOCOL) {
281 fputs("<proto name=\"", pdata->fh);
284 fputs("<field name=\"", pdata->fh);
286 print_escaped_xml(pdata->fh, fi->hfinfo->abbrev);
290 * http://analyzer.polito.it/30alpha/docs/dissectors/PDMLSpec.htm
292 * the show fields contains things in 'human readable' format
293 * showname: contains only the name of the field
294 * show: contains only the data of the field
295 * showdtl: contains additional details of the field data
296 * showmap: contains mappings of the field data (e.g. the hostname to an IP address)
298 * XXX - the showname shouldn't contain the field data itself
299 * (like it's contained in the fi->rep->representation).
300 * Unfortunately, we don't have the field data representation for
301 * all fields, so this isn't currently possible */
302 fputs("\" showname=\"", pdata->fh);
303 print_escaped_xml(pdata->fh, fi->hfinfo->name);
307 fputs("\" showname=\"", pdata->fh);
308 print_escaped_xml(pdata->fh, fi->rep->representation);
311 label_ptr = label_str;
312 proto_item_fill_label(fi, label_str);
313 fputs("\" showname=\"", pdata->fh);
314 print_escaped_xml(pdata->fh, label_ptr);
317 if (PROTO_ITEM_IS_HIDDEN(node))
318 fprintf(pdata->fh, "\" hide=\"yes");
320 fprintf(pdata->fh, "\" size=\"%d", fi->length);
321 fprintf(pdata->fh, "\" pos=\"%d", fi->start);
322 /* fprintf(pdata->fh, "\" id=\"%d", fi->hfinfo->id);*/
324 if (fi->hfinfo->type != FT_PROTOCOL) {
327 /* XXX - this is a hack until we can just call
328 * fvalue_to_string_repr() for *all* FT_* types. */
329 dfilter_string = proto_construct_dfilter_string(fi,
331 if (dfilter_string != NULL) {
332 chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
334 /* XXX - Remove double-quotes. Again, once we
335 * can call fvalue_to_string_repr(), we can
336 * ask it not to produce the version for
337 * display-filters, and thus, no
339 if (dfilter_string[strlen(dfilter_string)-1] == '"') {
340 dfilter_string[strlen(dfilter_string)-1] = '\0';
344 fputs("\" show=\"", pdata->fh);
345 print_escaped_xml(pdata->fh, &dfilter_string[chop_len]);
347 if (fi->length > 0) {
348 fputs("\" value=\"", pdata->fh);
349 write_pdml_field_hex_value(pdata, fi);
353 if (node->first_child != NULL) {
354 fputs("\">\n", pdata->fh);
356 else if (fi->hfinfo->id == proto_data) {
357 fputs("\">\n", pdata->fh);
360 fputs("\"/>\n", pdata->fh);
364 /* We always print all levels for PDML. Recurse here. */
365 if (node->first_child != NULL) {
367 proto_tree_children_foreach(node,
368 proto_tree_write_node_pdml, pdata);
372 if (node->first_child != NULL) {
373 for (i = -1; i < pdata->level; i++) {
374 fputs(" ", pdata->fh);
376 if (fi->hfinfo->type == FT_PROTOCOL) {
377 fputs("</proto>\n", pdata->fh);
380 fputs("</field>\n", pdata->fh);
385 /* Print info for a 'geninfo' pseudo-protocol. This is required by
386 * the PDML spec. The information is contained in Ethereal's 'frame' protocol,
387 * but we produce a 'geninfo' protocol in the PDML to conform to spec.
388 * The 'frame' protocol follows the 'geninfo' protocol in the PDML. */
390 print_pdml_geninfo(proto_tree *tree, FILE *fh)
392 guint32 num, len, caplen;
394 GPtrArray *finfo_array;
395 field_info *frame_finfo;
397 /* Get frame protocol's finfo. */
398 finfo_array = proto_find_finfo(tree, proto_frame);
399 if (g_ptr_array_len(finfo_array) < 1) {
402 frame_finfo = finfo_array->pdata[0];
403 g_ptr_array_free(finfo_array, FALSE);
405 /* frame.number --> geninfo.num */
406 finfo_array = proto_find_finfo(tree, hf_frame_number);
407 if (g_ptr_array_len(finfo_array) < 1) {
410 num = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
411 g_ptr_array_free(finfo_array, FALSE);
413 /* frame.pkt_len --> geninfo.len */
414 finfo_array = proto_find_finfo(tree, hf_frame_packet_len);
415 if (g_ptr_array_len(finfo_array) < 1) {
418 len = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
419 g_ptr_array_free(finfo_array, FALSE);
421 /* frame.cap_len --> geninfo.caplen */
422 finfo_array = proto_find_finfo(tree, hf_frame_capture_len);
423 if (g_ptr_array_len(finfo_array) < 1) {
426 caplen = fvalue_get_integer(&((field_info*)finfo_array->pdata[0])->value);
427 g_ptr_array_free(finfo_array, FALSE);
429 /* frame.time --> geninfo.timestamp */
430 finfo_array = proto_find_finfo(tree, hf_frame_arrival_time);
431 if (g_ptr_array_len(finfo_array) < 1) {
434 timestamp = fvalue_get(&((field_info*)finfo_array->pdata[0])->value);
435 g_ptr_array_free(finfo_array, FALSE);
437 /* Print geninfo start */
439 " <proto name=\"geninfo\" pos=\"0\" showname=\"General information\" size=\"%u\">\n",
440 frame_finfo->length);
442 /* Print geninfo.num */
444 " <field name=\"num\" pos=\"0\" show=\"%u\" showname=\"Number\" value=\"%x\" size=\"%u\"/>\n",
445 num, num, frame_finfo->length);
447 /* Print geninfo.len */
449 " <field name=\"len\" pos=\"0\" show=\"%u\" showname=\"Packet Length\" value=\"%x\" size=\"%u\"/>\n",
450 len, len, frame_finfo->length);
452 /* Print geninfo.caplen */
454 " <field name=\"caplen\" pos=\"0\" show=\"%u\" showname=\"Captured Length\" value=\"%x\" size=\"%u\"/>\n",
455 caplen, caplen, frame_finfo->length);
457 /* Print geninfo.timestamp */
459 " <field name=\"timestamp\" pos=\"0\" show=\"%s\" showname=\"Captured Time\" value=\"%d.%09d\" size=\"%u\"/>\n",
460 abs_time_to_str(timestamp), (int) timestamp->secs, timestamp->nsecs, frame_finfo->length);
462 /* Print geninfo end */
468 write_pdml_finale(FILE *fh)
470 fputs("</pdml>\n", fh);
474 write_psml_preamble(FILE *fh)
476 fputs("<?xml version=\"1.0\"?>\n", fh);
477 fputs("<psml version=\"" PSML_VERSION "\" ", fh);
478 fprintf(fh, "creator=\"%s/%s\">\n", PACKAGE, VERSION);
482 proto_tree_write_psml(epan_dissect_t *edt, FILE *fh)
486 /* if this is the first packet, we have to create the PSML structure output */
487 if(edt->pi.fd->num == 1) {
488 fprintf(fh, "<structure>\n");
490 for(i=0; i < edt->pi.cinfo->num_cols; i++) {
491 fprintf(fh, "<section>");
492 print_escaped_xml(fh, edt->pi.cinfo->col_title[i]);
493 fprintf(fh, "</section>\n");
496 fprintf(fh, "</structure>\n\n");
499 fprintf(fh, "<packet>\n");
501 for(i=0; i < edt->pi.cinfo->num_cols; i++) {
502 fprintf(fh, "<section>");
503 print_escaped_xml(fh, edt->pi.cinfo->col_data[i]);
504 fprintf(fh, "</section>\n");
507 fprintf(fh, "</packet>\n\n");
511 write_psml_finale(FILE *fh)
513 fputs("</psml>\n", fh);
517 * Find the data source for a specified field, and return a pointer
518 * to the data in it. Returns NULL if the data is out of bounds.
520 static const guint8 *
521 get_field_data(GSList *src_list, field_info *fi)
526 gint length, tvbuff_length;
528 for (src_le = src_list; src_le != NULL; src_le = src_le->next) {
531 if (fi->ds_tvb == src_tvb) {
535 * XXX - a field can have a length that runs past
536 * the end of the tvbuff. Ideally, that should
537 * be fixed when adding an item to the protocol
538 * tree, but checking the length when doing
539 * that could be expensive. Until we fix that,
540 * we'll do the check here.
542 tvbuff_length = tvb_length_remaining(src_tvb,
544 if (tvbuff_length < 0) {
548 if (length > tvbuff_length)
549 length = tvbuff_length;
550 return tvb_get_ptr(src_tvb, fi->start, length);
553 g_assert_not_reached();
554 return NULL; /* not found */
557 /* Print a string, escaping out certain characters that need to
558 * escaped out for XML. */
560 print_escaped_xml(FILE *fh, const char *unescaped_string)
562 const unsigned char *p;
564 for (p = unescaped_string; *p != '\0'; p++) {
588 write_pdml_field_hex_value(write_pdml_data *pdata, field_info *fi)
593 if (fi->length > tvb_length_remaining(fi->ds_tvb, fi->start)) {
594 fprintf(pdata->fh, "field length invalid!");
598 /* Find the data for this field. */
599 pd = get_field_data(pdata->src_list, fi);
602 /* Print a simple hex dump */
603 for (i = 0 ; i < fi->length; i++) {
604 fprintf(pdata->fh, "%02x", pd[i]);
610 print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
612 gboolean multiple_sources;
622 * Set "multiple_sources" iff this frame has more than one
623 * data source; if it does, we need to print the name of
624 * the data source before printing the data from the
627 multiple_sources = (edt->pi.data_src->next != NULL);
629 for (src_le = edt->pi.data_src; src_le != NULL;
630 src_le = src_le->next) {
633 if (multiple_sources) {
635 print_line(stream, 0, "");
636 line = g_malloc(strlen(name) + 2); /* <name>:\0 */
639 print_line(stream, 0, line);
642 length = tvb_length(tvb);
643 cp = tvb_get_ptr(tvb, 0, length);
644 if (!print_hex_data_buffer(stream, cp, length,
645 edt->pi.fd->flags.encoding))
652 * This routine is based on a routine created by Dan Lasley
653 * <DLASLEY@PROMUS.com>.
655 * It was modified for Ethereal by Gilbert Ramirez and others.
658 #define MAX_OFFSET_LEN 8 /* max length of hex offset of bytes */
659 #define BYTES_PER_LINE 16 /* max byte values printed on a line */
660 #define HEX_DUMP_LEN (BYTES_PER_LINE*3)
661 /* max number of characters hex dump takes -
662 2 digits plus trailing blank */
663 #define DATA_DUMP_LEN (HEX_DUMP_LEN + 2 + BYTES_PER_LINE)
664 /* number of characters those bytes take;
665 3 characters per byte of hex dump,
666 2 blanks separating hex from ASCII,
667 1 character per byte of ASCII dump */
668 #define MAX_LINE_LEN (MAX_OFFSET_LEN + 2 + DATA_DUMP_LEN)
669 /* number of characters per line;
670 offset, 2 blanks separating offset
671 from data dump, data dump */
674 print_hex_data_buffer(print_stream_t *stream, const guchar *cp,
675 guint length, char_enc encoding)
677 register unsigned int ad, i, j, k, l;
679 guchar line[MAX_LINE_LEN + 1];
680 unsigned int use_digits;
681 static guchar binhex[16] = {
682 '0', '1', '2', '3', '4', '5', '6', '7',
683 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
685 if (!print_line(stream, 0, ""))
689 * How many of the leading digits of the offset will we supply?
690 * We always supply at least 4 digits, but if the maximum offset
691 * won't fit in 4 digits, we use as many digits as will be needed.
693 if (((length - 1) & 0xF0000000) != 0)
694 use_digits = 8; /* need all 8 digits */
695 else if (((length - 1) & 0x0F000000) != 0)
696 use_digits = 7; /* need 7 digits */
697 else if (((length - 1) & 0x00F00000) != 0)
698 use_digits = 6; /* need 6 digits */
699 else if (((length - 1) & 0x000F0000) != 0)
700 use_digits = 5; /* need 5 digits */
702 use_digits = 4; /* we'll supply 4 digits */
711 * Start of a new line.
718 c = (ad >> (l*4)) & 0xF;
719 line[j++] = binhex[c];
723 memset(line+j, ' ', DATA_DUMP_LEN);
726 * Offset in line of ASCII dump.
728 k = j + HEX_DUMP_LEN + 2;
731 line[j++] = binhex[c>>4];
732 line[j++] = binhex[c&0xf];
734 if (encoding == CHAR_EBCDIC) {
735 c = EBCDIC_to_ASCII1(c);
737 line[k++] = c >= ' ' && c < 0x7f ? c : '.';
739 if ((i & 15) == 0 || i == length) {
741 * We'll be starting a new line, or
742 * we're finished printing this buffer;
743 * dump out the line we've constructed,
744 * and advance the offset.
747 if (!print_line(stream, 0, line))
756 void ps_clean_string(unsigned char *out, const unsigned char *in,
762 for (rd = 0, wr = 0 ; wr < outbuf_size; rd++, wr++ ) {
783 /* Some formats need stuff at the beginning of the output */
785 print_preamble(print_stream_t *self, gchar *filename)
787 return (self->ops->print_preamble)(self, filename);
791 print_line(print_stream_t *self, int indent, const char *line)
793 return (self->ops->print_line)(self, indent, line);
796 /* Insert bookmark */
798 print_bookmark(print_stream_t *self, const gchar *name, const gchar *title)
800 return (self->ops->print_bookmark)(self, name, title);
804 new_page(print_stream_t *self)
806 return (self->ops->new_page)(self);
809 /* Some formats need stuff at the end of the output */
811 print_finale(print_stream_t *self)
813 return (self->ops->print_finale)(self);
817 destroy_print_stream(print_stream_t *self)
819 return (self->ops->destroy)(self);
828 print_preamble_text(print_stream_t *self _U_, gchar *filename _U_)
831 return TRUE; /* always succeeds */
835 print_line_text(print_stream_t *self, int indent, const char *line)
837 output_text *output = self->data;
838 char space[MAX_INDENT+1];
842 /* Prepare the tabs for printing, depending on tree level */
843 num_spaces = indent * 4;
844 if (num_spaces > MAX_INDENT) {
845 num_spaces = MAX_INDENT;
847 for (i = 0; i < num_spaces; i++) {
850 /* The string is NUL-terminated */
851 space[num_spaces] = '\0';
853 fputs(space, output->fh);
854 fputs(line, output->fh);
855 putc('\n', output->fh);
856 return !ferror(output->fh);
860 print_bookmark_text(print_stream_t *self _U_, const gchar *name _U_,
861 const gchar *title _U_)
868 new_page_text(print_stream_t *self)
870 output_text *output = self->data;
872 fputs("\f", output->fh);
873 return !ferror(output->fh);
877 print_finale_text(print_stream_t *self _U_)
880 return TRUE; /* always succeeds */
884 destroy_text(print_stream_t *self)
886 output_text *output = self->data;
889 ret = close_print_dest(output->to_file, output->fh);
895 static const print_stream_ops_t print_text_ops = {
905 print_stream_text_new(int to_file, const char *dest)
908 print_stream_t *stream;
911 fh = open_print_dest(to_file, dest);
915 output = g_malloc(sizeof *output);
916 output->to_file = to_file;
918 stream = g_malloc(sizeof (print_stream_t));
919 stream->ops = &print_text_ops;
920 stream->data = output;
926 print_stream_text_stdio_new(FILE *fh)
928 print_stream_t *stream;
931 output = g_malloc(sizeof *output);
932 output->to_file = TRUE;
934 stream = g_malloc(sizeof (print_stream_t));
935 stream->ops = &print_text_ops;
936 stream->data = output;
947 print_preamble_ps(print_stream_t *self, gchar *filename)
949 output_ps *output = self->data;
950 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
952 print_ps_preamble(output->fh);
954 fputs("%% Set the font to 10 point\n", output->fh);
955 fputs("/Courier findfont 10 scalefont setfont\n", output->fh);
956 fputs("\n", output->fh);
957 fputs("%% the page title\n", output->fh);
958 ps_clean_string(psbuffer, filename, MAX_PS_LINE_LENGTH);
959 fprintf(output->fh, "/eth_pagetitle (%s - Ethereal) def\n", psbuffer);
960 fputs("\n", output->fh);
961 return !ferror(output->fh);
965 print_line_ps(print_stream_t *self, int indent, const char *line)
967 output_ps *output = self->data;
968 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
970 ps_clean_string(psbuffer, line, MAX_PS_LINE_LENGTH);
971 fprintf(output->fh, "%d (%s) putline\n", indent, psbuffer);
972 return !ferror(output->fh);
976 print_bookmark_ps(print_stream_t *self, const gchar *name, const gchar *title)
978 output_ps *output = self->data;
979 char psbuffer[MAX_PS_LINE_LENGTH]; /* static sized buffer! */
982 * See the Adobe "pdfmark reference":
984 * http://partners.adobe.com/asn/acrobat/docs/pdfmark.pdf
986 * The pdfmark stuff tells code that turns PostScript into PDF
987 * things that it should do.
989 * The /OUT stuff creates a bookmark that goes to the
990 * destination with "name" as the name and "title" as the title.
992 * The "/DEST" creates the destination.
994 ps_clean_string(psbuffer, title, MAX_PS_LINE_LENGTH);
995 fprintf(output->fh, "[/Dest /%s /Title (%s) /OUT pdfmark\n", name,
997 fputs("[/View [/XYZ -4 currentpoint matrix currentmatrix matrix defaultmatrix\n",
999 fputs("matrix invertmatrix matrix concatmatrix transform exch pop 20 add null]\n",
1001 fprintf(output->fh, "/Dest /%s /DEST pdfmark\n", name);
1002 return !ferror(output->fh);
1006 new_page_ps(print_stream_t *self)
1008 output_ps *output = self->data;
1010 fputs("formfeed\n", output->fh);
1011 return !ferror(output->fh);
1015 print_finale_ps(print_stream_t *self)
1017 output_ps *output = self->data;
1019 print_ps_finale(output->fh);
1020 return !ferror(output->fh);
1024 destroy_ps(print_stream_t *self)
1026 output_ps *output = self->data;
1029 ret = close_print_dest(output->to_file, output->fh);
1035 static const print_stream_ops_t print_ps_ops = {
1045 print_stream_ps_new(int to_file, const char *dest)
1048 print_stream_t *stream;
1051 fh = open_print_dest(to_file, dest);
1055 output = g_malloc(sizeof *output);
1056 output->to_file = to_file;
1058 stream = g_malloc(sizeof (print_stream_t));
1059 stream->ops = &print_ps_ops;
1060 stream->data = output;
1066 print_stream_ps_stdio_new(FILE *fh)
1068 print_stream_t *stream;
1071 output = g_malloc(sizeof *output);
1072 output->to_file = TRUE;
1074 stream = g_malloc(sizeof (print_stream_t));
1075 stream->ops = &print_ps_ops;
1076 stream->data = output;