#======================================================== # CSV #======================================================== package BibFile; use Common; @ISA = qw(Common); #公開したいサブルーチン #@EXPORT = qw(DelSpace Reduce01 MakePath RegExpQuote); use strict; use LWP::Simple; #============================================================ # 変数等取得関数 #============================================================ #============================================================ # 静的関数 #============================================================ #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, $path, $mode) = @_; my $this = {}; bless $this; return $this; } sub DESTROY { my $this = shift; $this->Close(); } #============================================================ # 一般関数 #============================================================ sub GetHashByKey { my ($this, $key, $phash, $path) = @_; $this->Read($path) if(!$this->{pList}); return {} if(!$this->{pList}); return Utils::BuildHashFromHashArray($this->{pList}, $phash, $key); } sub GetHash { my ($this, $idx, $path) = @_; $this->Read($path) if(!$this->{pList}); return $this->{pList}->[$idx]; } sub Read { my ($this, $path, $pList, $App) = @_; $pList = [] if(!$pList); my $in = new JFile; if(!-e $path or !$in->Open($path, 'r')) { $App->print("Error in BibFile::Read: Can not read [$path]: $!.\n") if($App); return $pList; } my %Keys; my $count = 0; while(1) { my $line = $in->ReadLine(); last if(!$line); $count++; #last if($count > 10); my %hash; if($line =~ /^\s*\@(\w+?)\{(.*),$/) { $hash{type} = $1; $hash{RefKey} = $2; #print "$count: [$hash{type}][$hash{RefKey}]\n"; while(1) { my $line = $in->ReadLine(); last if($line =~ /^\}/); last if(!$line); my ($key, $val) = ($line =~ /^\s*(.*?)\s*=\s*(.*)/); $val =~ s/^[\{:]+//; $val =~ s/\}+,?$//; if($key eq 'file') { $val =~ s/\\_/_/g; $val =~ s/:\w+?$//; $val =~ s/\$\\backslash\$//; $val =~ s/\\/\//g; } if($key eq 'pages') { $val =~ s/--/-/; } $Keys{$key}++; $hash{$key} = $val; #print " $key: $val\n"; if($key eq 'file') { my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($hash{file}); $hash{FilePath} = $filename; $directory =~ s/\\/\//g; $hash{DirPath} = "$drive$directory"; } } } elsif($line =~ /^\s*\@/) { while(1) { my $line = $in->ReadLine(); last if($line =~ /^\}/); last if(!$line); } } #print "key: $hash{type}\n"; if($hash{RefKey} =~ /Mendeley/i) { } elsif($hash{type} eq '') { } else { push(@$pList, \%hash); } } $in->Close(); return $this->{pList} = $pList; } 1;