- field_info *fi = (field_info*) (node->data);
- print_data *pdata = (print_data*) data;
- gchar label_str[ITEM_LABEL_LENGTH];
- gchar *label_ptr;
- char psbuffer[MAX_LINE_LENGTH]; /* static sized buffer! */
-
- if (!fi->visible)
- return;
-
- /* was a free format label produced? */
- if (fi->representation) {
- label_ptr = fi->representation;
- }
- else { /* no, make a generic label */
- label_ptr = label_str;
- proto_item_fill_label(fi, label_str);
- }
-
- /* Print the text */
- ps_clean_string(psbuffer, label_ptr, MAX_LINE_LENGTH);
- fprintf(pdata->fh, "%d (%s) putline\n", pdata->level, psbuffer);
-
- /* If it's uninterpreted data, dump it. */
- if (fi->hfinfo->id == proto_data) {
- print_ps_hex(pdata->fh);
- print_hex_data_ps(pdata->fh, &pdata->pd[fi->start], fi->length);
- }
-
- /* Recurse into the subtree, if it exists */
- if (g_node_n_children(node) > 0) {
- pdata->level++;
- g_node_children_foreach(node, G_TRAVERSE_ALL,
- proto_tree_print_node_ps, pdata);
- pdata->level--;
+ register unsigned int ad, i, j, k, l;
+ guchar c;
+ guchar line[MAX_LINE_LEN + 1];
+ unsigned int use_digits;
+ static guchar binhex[16] = {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+ print_line(fh, 0, format, "");
+
+ /*
+ * How many of the leading digits of the offset will we supply?
+ * We always supply at least 4 digits, but if the maximum offset
+ * won't fit in 4 digits, we use as many digits as will be needed.
+ */
+ if (((length - 1) & 0xF0000000) != 0)
+ use_digits = 8; /* need all 8 digits */
+ else if (((length - 1) & 0x0F000000) != 0)
+ use_digits = 7; /* need 7 digits */
+ else if (((length - 1) & 0x00F00000) != 0)
+ use_digits = 6; /* need 6 digits */
+ else if (((length - 1) & 0x000F0000) != 0)
+ use_digits = 5; /* need 5 digits */
+ else
+ use_digits = 4; /* we'll supply 4 digits */
+
+ ad = 0;
+ i = 0;
+ j = 0;
+ k = 0;
+ while (i < length) {
+ if ((i & 15) == 0) {
+ /*
+ * Start of a new line.
+ */
+ j = 0;
+ k = 0;
+ l = use_digits;
+ do {
+ l--;
+ c = (ad >> (l*4)) & 0xF;
+ line[j++] = binhex[c];
+ } while (l != 0);
+ line[j++] = ' ';
+ line[j++] = ' ';
+ memset(line+j, ' ', DATA_DUMP_LEN);
+
+ /*
+ * Offset in line of ASCII dump.
+ */
+ k = j + HEX_DUMP_LEN + 2;
+ }
+ c = *cp++;
+ line[j++] = binhex[c>>4];
+ line[j++] = binhex[c&0xf];
+ j++;
+ if (encoding == CHAR_EBCDIC) {
+ c = EBCDIC_to_ASCII1(c);
+ }
+ line[k++] = c >= ' ' && c < 0x7f ? c : '.';
+ i++;
+ if ((i & 15) == 0 || i == length) {
+ /*
+ * We'll be starting a new line, or
+ * we're finished printing this buffer;
+ * dump out the line we've constructed,
+ * and advance the offset.
+ */
+ line[k] = '\0';
+ print_line(fh, 0, format, line);
+ ad += 16;
+ }