diff options
| author | fukachan <fukachan> | 2002-04-11 23:15:26 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2002-04-11 23:15:26 +0000 |
| commit | 3b41bad665efe215d21d73cedf8cc52c34b965a4 (patch) | |
| tree | 179c7b6d3789cccaa6391ab4e8f38e21844f5989 /fml/lib/Mail/Message/Checksum.pm | |
| parent | 26276b6299c456bd471f713319ba76107909ce2d (diff) | |
| download | fml8-3b41bad665efe215d21d73cedf8cc52c34b965a4.tar.gz fml8-3b41bad665efe215d21d73cedf8cc52c34b965a4.tar.bz2 fml8-3b41bad665efe215d21d73cedf8cc52c34b965a4.zip | |
pick up the first \S+ part in string retunred by md5 external program.
FNF-ify.
Diffstat (limited to 'fml/lib/Mail/Message/Checksum.pm')
| -rw-r--r-- | fml/lib/Mail/Message/Checksum.pm | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/fml/lib/Mail/Message/Checksum.pm b/fml/lib/Mail/Message/Checksum.pm index f5d96d94..607e9c87 100644 --- a/fml/lib/Mail/Message/Checksum.pm +++ b/fml/lib/Mail/Message/Checksum.pm @@ -1,10 +1,10 @@ #-*- perl -*- # -# Copyright (C) 2001 Ken'ichi Fukamachi +# Copyright (C) 2001,2002 Ken'ichi Fukamachi # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Checksum.pm,v 1.13 2001/12/22 09:21:00 fukachan Exp $ +# $FML: Checksum.pm,v 1.1 2001/12/22 16:07:09 fukachan Exp $ # package Mail::Message::Checksum; @@ -34,6 +34,10 @@ such as C<md5>, C<cksum>, et.al. =cut +# Descriptions: ordinary constructor +# Arguments: OBJ($self) HASH_REF($args) +# Side Effects: none +# Return Value: OBJ sub new { my ($self, $args) = @_; @@ -46,6 +50,11 @@ sub new } +# Descriptions: initialization routine called at new(). +# search a md5 module or program. +# Arguments: OBJ($self) HASH_REF($args) +# Side Effects: none +# Return Value: none sub _init { my ($self, $args) = @_; @@ -78,6 +87,10 @@ return the md5 checksum of the given string C<$string>. =cut +# Descriptions: dispatcher to calculate the md5 checksum +# Arguments: OBJ($self) STR_REF($r_data) +# Side Effects: none +# Return Value: STR(md5 sum) sub md5 { my ($self, $r_data) = @_; @@ -92,6 +105,10 @@ sub md5 } +# Descriptions: calculate the md5 checksum by MD5 module +# Arguments: OBJ($self) STR_REF($r_data) +# Side Effects: none +# Return Value: STR(md5 sum) sub _md5_native { my ($self, $r_data) = @_; @@ -115,6 +132,10 @@ sub _md5_native } +# Descriptions: calculate the md5 checksum by md5 (external) program +# Arguments: OBJ($self) STR_REF($r_data) +# Side Effects: none +# Return Value: STR(md5 sum) sub _md5_by_program { my ($self, $r_data) = @_; @@ -133,6 +154,7 @@ sub _md5_by_program my $cksum = 0; sysread($rh, $cksum, 1024); $cksum =~ s/[\s\n]*$//; + if ($cksum =~ /^(\S+)/) { $cksum = $1;} close($rh); return $cksum if $cksum; } @@ -162,14 +184,18 @@ See POSIX 1003.2 for more details. =cut +# Descriptions: return the traditional checksum of the given $file +# Arguments: OBJ($self) STR($file) +# Side Effects: none +# Return Value: ARRAY(STR, STR) sub cksum2 { - my ($self, $f) = @_; + my ($self, $file) = @_; my ($crc, $total, $nr, $buf, $r); $crc = $total = 0; - if (open($f, $f)) { - while (($nr = sysread($f, $buf, 1024)) > 0) { + if (open($file, $file)) { + while (($nr = sysread($file, $buf, 1024)) > 0) { my ($i) = 0; $total += $nr; @@ -178,12 +204,12 @@ sub cksum2 $crc += ord($r); } } - close($f); + close($file); $crc = ($crc & 0xffff) + ($crc >> 16); $crc = ($crc & 0xffff) + ($crc >> 16); } else { - Log("ERROR: no such file $f"); + Log("ERROR: no such file $file"); } ($crc, $total); @@ -228,7 +254,7 @@ Ken'ichi Fukamachi =head1 COPYRIGHT -Copyright (C) 2001 Ken'ichi Fukamachi +Copyright (C) 2001,2002 Ken'ichi Fukamachi All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
