#!/opt/perl/bin/perl -w use strict; use CGI qw/:standard :escape/; use URI::Escape; use File::stat; $| = 1; sub mysort { my ($d, $sf, $ns, $rs) = @_; my @i = (); foreach my $r (@$d) { chomp $r; my @f = split(/\t/, $r); push @i, $f[$sf]; } my $cmp; if ($ns) { $cmp = $rs ? '$i[$b] <=> $i[$a]' : '$i[$a] <=> $i[$b]'; } else { $cmp = $rs ? '$i[$b] cmp $i[$a]' : '$i[$a] cmp $i[$b]'; } return (eval '@$d[sort {' . $cmp . '} 0 .. $#i]'); } my ($n_so, $r_so, $s_so) = ("D", "A", "A"); my ($sf, $ns, $rs); my $nosort; SWITCH: { if (param("N")) { param("N") eq "A" ? do {$n_so = "D"} : do {$n_so = "A"; $rs++}; ($r_so, $s_so) = ("A", "A"); $sf = 0; last; } if (param("R")) { param("R") eq "A" ? do {$r_so = "D"} : do {$r_so = "A"; $rs++}; ($n_so, $s_so) = ("A", "A"); $sf = 3; $ns++; last; } if (param("S")) { param("S") eq "A" ? do {$s_so = "D"} : do {$s_so = "A"; $rs++}; ($n_so, $r_so) = ("A", "A"); $sf = 4; $ns++; last; } $nosort++; } my (@dirs, @thumbs, @images, @sorted); my $ht_path = ($ENV{"SCRIPT_NAME"} =~ /^(.*)\//)[0]; my $ht_clp_path = ($ht_path =~ /^(.*\/clipart)\//)[0]; my $path = ($ENV{"SCRIPT_FILENAME"} =~ /^(.*)\//)[0]; my $dir = ($path =~ /\/clipart\/(.*)$/)[0]; my $type = "jbig1"; SWITCH: { $dir =~ s/^gif/jbig1/ and do {$type = "gif"; last}; $dir =~ s/^tiff/jbig1/ and do {$type = "tiff"; last}; $dir =~ s/^eps/jbig1/ and do {$type = "eps"; last}; } my $edir = uri_escape("$dir"); my $esl = uri_escape("/"); opendir(DIR, ".") or die "Cannot opendir .: $!\n"; foreach my $name (sort readdir(DIR)) { $name =~ /^\.+$/ and next; $name =~ /\.gif$/ and do {push @thumbs, $name; next}; (stat($name)->mode & 0170000) == 040000 and push @dirs, $name; } close(DIR); if (open(FILE, ".jbginfo")) { @images = (); close(FILE); (! $nosort) and @sorted = mysort \@images, $sf, $ns, $rs; } print header, start_html({title=>"Index of $ht_path"}), h1("Index of $ht_path"), "
",
img({src=>"/icons/blank.gif", alt=>"     "}) . " " .
	a({href=>"index.cgi?N=$n_so"}, "Name") .
	"                                    " .
	a({href=>"index.cgi?R=$r_so"}, "Resolution"),
"\n", hr, "\n",
img({src=>"/icons/back.gif", alt=>"[DIR]"}) . " " .
	a({href=>"../"}, "Parent Directory"), "\n";

foreach my $d (@dirs) {
    chomp $d;
    print img({src=>"/icons/folder.gif", alt=>"[DIR]"}) . " " .
	    a({href=>"$d/"}, $d), "\n";
}

foreach my $f (@thumbs) {
    chomp $f;
    print img({src=>"/icons/index.gif", alt=>"[TMB]"}) . " " .
	    a({href=>"$f"}, $f), "\n";
}

foreach my $r ($nosort ? @images : @sorted) {
    chomp $r;
    my ($f, $xres, $yres, $pix, $size) = split(/\t/, $r);
    my $ef = uri_escape($f);
    my $eparm = "file=${edir}${esl}${ef}&type=";
    my ($href, $dname) = ($ef, $f);
    if ($type eq "gif" or $type eq "tiff" or $type eq "eps") {
	$href = "$ht_clp_path/conv.fcgi?${eparm}${type}";
	$dname = ($f =~ /^(.*)\.jbg$/)[0] .
		($type eq "tiff" ? ".tif" : ".$type");
    }
    printf "%s%" . (50 - length($dname)) . "s\n",
	    img({src=>"/icons/image2.gif", alt=>"[IMG]"}) . " " .
		    a({href=>$href}, $dname),
	    "${xres}x${yres}";
}

print "
", hr, end_html; .