This file is indexed.

/usr/bin/stag-drawtree is in libdata-stag-perl 0.11-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/perl -w

eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
    if 0; # not running under some shell

# POD docs at end

use strict;

use Data::Stag qw(:all);
use Getopt::Long;

use FileHandle;
use GD;

my $e = "";
my $fmt = 'png';
my $out;
my $parser;
my $fontchoice;
GetOptions("element|e=s"=>\$e,
	   "out|o=s"=>\$out,
           "parser|format|p=s" => \$parser,
	   "font=s"=>\$fontchoice,
	   "help|h"=>sub { system("perldoc $0"); exit },
	  );

my $fn = shift @ARGV;
my $fh;
if ($fn eq '-') {
    $fh = \*STDIN;
}
else {
    $fh = FileHandle->new($fn) || die $fn;
}
my $tab = 4;
my $stag = Data::Stag->parse(-file=>$fn, -format=>$parser);
my $box = box($stag, 0, 0);
my $FONT = gdLargeFont;
if ($fontchoice) {
    if ($fontchoice eq 'gdMediumBoldFont') {
	$FONT = gdMediumBoldFont;
    }
}
my $CW = $FONT->width;
my $CH = $FONT->height;
my $width = $CW * $box->{x2};
my $height = $CH * $box->{y2};
my $im = new GD::Image($width, $height);

my $bgcol = $im->colorAllocate(255, 255, 255);

my $fgcol = $im->colorAllocate(0, 0, 0);
my $linecol = $im->colorAllocate(0, 0, 0);
my $namecol = $im->colorAllocate(0, 0, 0);
my $datacol = $im->colorAllocate(255, 0, 0);
#$im->transparent($bgcol);
$im->interlaced('true');


drawbox($im, $box);
if ($out) {
    open(F, ">$out") || die($out);
    print F $im->$fmt();
    close(F);
}
else {
    print $im->$fmt();
}

sub box {
    my $stag = shift;
    my ($x, $y)= @_;

    my $y1 = $y;
    my $x2 = $x;
    my @kids = $stag->kids;
    my @subboxes = ();
    my $data;
    if ($stag->isterminal) {
	$data = $stag->data;
	$x2 += length($data) + length($stag->element) + 1;
	@kids = ();
    }
    $y++;
    foreach my $kid (@kids) {
	my $subbox = box($kid, $x + $tab, $y);
	push(@subboxes, $subbox);
	$y = $subbox->{y2};
	if ($subbox->{x2} > $x2) {
	    $x2 = $subbox->{x2};
	}
    }
    return 
      {boxes=>\@subboxes,
       name=>$stag->element,
       data=>$data,
       x1=>$x,
       x2=>$x2,
       y1=>$y1,
       y2=>$y,
      };
}

sub drawbox {
    my $im = shift;
    my $box = shift;
    my $sx1 = $box->{x1} * $CW;
    my $sy1 = $box->{y1} * $CH;
    my $name = $box->{name};
    my $data = $box->{data};
    
    $im->string($FONT,
		$sx1,
		$sy1,
		$name,
		$namecol);
    if ($data) {
	$im->string($FONT,
		    $sx1 + length($name) * $CW + 1 * $CW,
		    $sy1,
		    $data,
		    $datacol);
    }
    my $subboxes = $box->{boxes};
    my $XOFF = int($CW / 2);
    my $YOFF = int($CH / 2);
    foreach (@$subboxes) {
	drawbox($im, $_);
	my $ix = $sx1 + $XOFF;
	my $iy = $_->{y1} * $CH + $YOFF;
	my $jx = $_->{x1} * $CW;
	$im->line($ix, $sy1 + $CH, $ix, $iy, $linecol);
	$im->line($ix, $iy, $jx, $iy, $linecol);
    }
}

exit 0;

__END__

=head1 NAME 

stag-drawtree - draws a stag file (xml, itext, sxpr) as a PNG diagram

=head1 SYNOPSIS

  stag-drawtree -o my.png myfile.xml

  stag-drawtree -p My::MyFormatParser -o my.png myfile.myfmt

=head1 DESCRIPTION

requires GD library and GD perl module

=head1 ARGUMENTS

=over

=item -p|parser FORMAT

FORMAT is one of xml, sxpr or itext, or the name of a perl module

xml assumed as default

=back


=head1 SEE ALSO

L<Data::Stag>

=cut