summaryrefslogtreecommitdiffstats
path: root/util/BBSFileHeader.pm
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-07-03 13:49:06 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-07-03 13:49:06 +0800
commitc6ce21a8f241d028c5df5c3275df264b1857fe23 (patch)
treedb2e78e9285d86254b9b4a94878617915df0e0c3 /util/BBSFileHeader.pm
parent7ff23307751ae09c504d6586ceaefa650c7d62e1 (diff)
downloadpttbbs-c6ce21a8f241d028c5df5c3275df264b1857fe23.tar
pttbbs-c6ce21a8f241d028c5df5c3275df264b1857fe23.tar.gz
pttbbs-c6ce21a8f241d028c5df5c3275df264b1857fe23.tar.bz2
pttbbs-c6ce21a8f241d028c5df5c3275df264b1857fe23.tar.lz
pttbbs-c6ce21a8f241d028c5df5c3275df264b1857fe23.tar.xz
pttbbs-c6ce21a8f241d028c5df5c3275df264b1857fe23.tar.zst
pttbbs-c6ce21a8f241d028c5df5c3275df264b1857fe23.zip
move BBSFileHeader.pm to util/
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1002 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/BBSFileHeader.pm')
-rw-r--r--util/BBSFileHeader.pm58
1 files changed, 58 insertions, 0 deletions
diff --git a/util/BBSFileHeader.pm b/util/BBSFileHeader.pm
new file mode 100644
index 00000000..e9cf3cdd
--- /dev/null
+++ b/util/BBSFileHeader.pm
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+package BBSFileHeader;
+use strict;
+use IO::Handle;
+use Data::Dumper;
+
+use fields qw/dir fh cache/;
+
+sub TIEHASH
+{
+ my($class, $dir) = @_;
+ my $self = fields::new($class);
+
+ open $self->{fh}, "<$dir/.DIR";
+ return undef if( !$self->{fh} );
+
+ $self->{dir} = $dir;
+ return $self;
+}
+
+sub FETCH
+{
+ my($self, $k) = @_;
+
+ return $self->{dir} if( $k eq 'dir' );
+ return ((-s "$self->{dir}/.DIR") / 128) if( $k eq 'num' );
+
+ my($num, $key) = $k =~ /(.*)\.(.*)/;
+ my($t, %h);
+
+ $num += $self->FETCH('num') if( $num < 0 );
+
+ return $self->{cache}{$num}{$key} if( $self->{cache}{$num}{$key} );
+
+ seek($self->{fh}, $num * 128, 0);
+ $self->{fh}->read($t, 128);
+
+ if( $key eq 'isdir' ){
+ my $fn = "$self->{dir}/" . $self->FETCH("$num.filename");
+ return (-d $fn);
+ }
+ elsif( $key eq 'content' ){
+ my $fn = "$self->{dir}/" . $self->FETCH("$num.filename");
+ return `/bin/cat $fn`;
+ }
+ else{
+ ($h{filename}, $h{recommend}, $h{owner}, $h{date}, $h{title},
+ $h{money}, undef, $h{filemode}) =
+ unpack('Z33cZ14Z6Z65iCC', $t);
+ $h{title} = substr($h{title}, 3);
+ $self->{cache}{$num}{$_} = $h{$_}
+ foreach( 'filename', 'owner', 'date',
+ 'title', 'money', 'filemode' );
+ return $h{$key};
+ }
+}
+
+1;