#!/usr/bin/perl

$CONVERT='/usr/bin/convert'   ;
$RM = '/bin/rm'; 
$MV = '/bin/mv';

# オプション
while (@ARGV) {
    last unless ($ARGV[0] =~ /^-/);
    $_ = shift;                           
    if (/^-p/) { $prefix = shift; next; };   # ファイル形式
    if (/^-stime/) { $stime = shift; next; };     # 
    if (/^-dtime/) { $dtime = shift; next; };     # 
    die "unknown option $_";
}

opendir(DIR, ".");
@FILES_TMP = grep(/xwd$/, readdir(DIR));
@FILES = sort(@FILES_TMP);
$i = $stime ; 
print @FILES, "\n"; 

foreach $file (@FILES){

    $num = sprintf("%04d", $i);
    $file2 = "$prefix-$num.png" ;
    
    print "xwdtopnm $file | pnmtopng > $file2 \n" ;
    system ("xwdtopnm $file | pnmtopng > $file2 ") ;

    $i = $i + $dtime;
}




