Skip to content

Commit d674bea

Browse files
committed
PLplot use plplot API to get devices, as the prophecy foretold
1 parent 95570a2 commit d674bea

File tree

1 file changed

+3
-69
lines changed

1 file changed

+3
-69
lines changed

lib/PDL/Graphics/Simple/PLplot.pm

+3-69
Original file line numberDiff line numberDiff line change
@@ -59,81 +59,15 @@ sub check {
5959
}
6060

6161
# Module loaded OK, now try to extract valid devices from it.
62-
# We would use a pipe, but Microsoft Windows doesn't play nice
63-
# with them - so we use a temp file instead.
64-
my ($fh1, $gzinta) = tempfile('pgs_gzinta_XXXX');
65-
close $fh1;
66-
my ($fh2, $gzouta) = tempfile('pgs_gzouta_XXXX');
67-
close $fh2;
68-
69-
open my $fh3, ">", $gzinta or die "Couldn't write to temp file";
70-
print $fh3 "1\n"; #Just one line
71-
close $fh3;
72-
73-
if($^O =~ /MSWin32/i) {
74-
eval {require Win32::Process};
75-
die "Win32::Process didn't load: $@"
76-
if $@;
77-
78-
my $cmd_location = -e "\\Windows\\system32\\cmd.exe"
79-
? "\\Windows\\system32\\cmd.exe"
80-
: cmd_location();
81-
82-
Win32::Process::Create(
83-
my $ProcessObj,
84-
$cmd_location,
85-
"cmd /c \"$^X -MPDL -MPDL::Graphics::PLplot -e \"PDL::Graphics::PLplot->new() \" <$gzinta >$gzouta\"",
86-
0,
87-
32, #NORMAL_PRIORITY_CLASS
88-
".")|| die ErrorReport();
89-
90-
sleep 1; # Don't read $gzouta before it's written
91-
}
92-
else {
93-
my $pid = fork();
94-
unless(defined($pid)) {
95-
print STDERR +($mod->{msg} = "Fork failed in PLplot probe -- returning 0"), "\n";
96-
return 0;
97-
}
98-
99-
if( $pid==0 ) { # assignment
100-
101-
# Daughter: try to create a PLplot window with a bogus device, to stimulate a driver listing
102-
open STDOUT,">", $gzouta;
103-
open STDERR,">&", STDOUT;
104-
open STDIN, "<", $gzinta;
105-
PDL::Graphics::PLplot->new(DEV=>'?');
106-
exit(0);
107-
}
108-
109-
# Parent - snarf up the results from the daughter
110-
usleep(2e5); # hang around for 0.2 seconds
111-
eval {kill 9,$pid;}; # kill it dead, just in case it buzzed or hung (I'm looking at you, Microsoft Windows)
112-
waitpid($pid,0); # Clean up.
113-
}
114-
115-
# Snarf up the file.
116-
open my $fh4, "<", $gzouta;
117-
my @lines = <$fh4>;
118-
close $fh4;
119-
120-
unlink $gzinta;
121-
unlink $gzouta;
122-
123-
$mod->{devices} = {};
124-
for my $l(@lines) {
125-
if( $l=~ m/^\s+\<\s*\d+\>\s+(\w+)/ ) {
126-
$mod->{devices}->{$1} = 1;
127-
}
128-
}
62+
my $plgDevs = plgDevs();
63+
$mod->{devices} = {map +($_=>1), keys %$plgDevs};
12964

13065
if( my ($good_dev) = grep $mod->{devices}{$_}, @DEVICES ) {
13166
$mod->{disp_dev} = $good_dev;
13267
} else {
13368
$mod->{ok} = 0;
13469
$mod->{msg} = join("\n\t", "No suitable display device found among:",
135-
sort keys %{ $mod->{devices} }) . join("\n\t", "Lines read:",
136-
map {chomp; $_} @lines);
70+
sort keys %{ $mod->{devices} }) . "\n";
13771
return 0;
13872
}
13973

0 commit comments

Comments
 (0)