File: xcfview.in

package info (click to toggle)
xcftools 1.0.7-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,204 kB
  • ctags: 548
  • sloc: sh: 3,897; ansic: 3,132; perl: 668; makefile: 246
file content (60 lines) | stat: -rwxr-xr-x 1,696 bytes parent folder | download | duplicates (4)
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
#! /usr/bin/perl
#
#  xcfview: a wrapper script that uses xcftools and an external viewer
#  to display XCF images. The external viewer is found through the
#  mailcap(5) database (q.v.) by using xdg-utils.
#
#  Written by Henning Makholm <henning@makholm.net>
#  Derived from the run-mailcap script by Brian White <bcwhite@pobox.com>
#
#  In 2009 almost entirely rewritten by Jan Hauke Rahm <info@jhr-online.de>
#  to make use of xdg-utils instead of parsing /etc/mailcap on its own
#  That makes handling of dependencies *way* easier in Debian
#
#  This script has been placed in the public domain (by both authors)

use strict ;
use warnings ;
use File::Temp qw/ tempfile /;

my $debug=0;

my $png_prog = `xdg-mime query default image/png`;
my $pnm_prog = `xdg-mime query default image/x-portable-pixmap`;

my (@converter, $usecomm);
if ($png_prog) {
    @converter = ("xcf2png");
    $usecomm = $png_prog;
} elsif ($pnm_prog) {
    @converter = ("xcf2pnm","-c","'-#'");
    $usecomm = $pnm_prog;
} else {
    print STDERR "$0: No appropriate way to display PPM or PNG images in mailcap\n" ;
    exit 1 ;
}

$usecomm =~ s/\.desktop$//;
$usecomm =~ s/\n$//;

# quote arguments for converter
for( @ARGV ) {
    next if m{^[-a-z0-9,.:/@%^+=_]+$}i ;
    s/'/\\'/ ;
    $_ = "'$_'" ;
}

my ($fh, $tempfile) = tempfile(UNLINK => 1);
my $retcode = 0 ;
for my $comm ( join(" ",@converter,"-o",$tempfile,@ARGV),
	       join(" ",$usecomm,$tempfile) ) {
    print STDERR " - executing: $comm\n" if $debug ;
    my $res = system $comm;
    $res = int($res/256);
    if ($res != 0) {
	print STDERR "Warning: program returned non-zero exit code \#$res\n";
	$retcode = $res;
	last ;
    }
}
exit $retcode ;