summaryrefslogtreecommitdiffstats
path: root/blog/BBSFileHeader.pm
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-05-23 17:02:26 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-05-23 17:02:26 +0800
commit5e882dd4ce4d2a84fd63f38bc2ff195fae0ab7ec (patch)
tree8efab6cbf57bb5001c63aefc3c94a27855f67c30 /blog/BBSFileHeader.pm
parent2fb9c23b681dc58ec8132ec01e2ac09ce5dd55c3 (diff)
downloadpttbbs-5e882dd4ce4d2a84fd63f38bc2ff195fae0ab7ec.tar
pttbbs-5e882dd4ce4d2a84fd63f38bc2ff195fae0ab7ec.tar.gz
pttbbs-5e882dd4ce4d2a84fd63f38bc2ff195fae0ab7ec.tar.bz2
pttbbs-5e882dd4ce4d2a84fd63f38bc2ff195fae0ab7ec.tar.lz
pttbbs-5e882dd4ce4d2a84fd63f38bc2ff195fae0ab7ec.tar.xz
pttbbs-5e882dd4ce4d2a84fd63f38bc2ff195fae0ab7ec.tar.zst
pttbbs-5e882dd4ce4d2a84fd63f38bc2ff195fae0ab7ec.zip
add BBSFileHeader.pm, builddb.pl
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@889 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'blog/BBSFileHeader.pm')
-rw-r--r--blog/BBSFileHeader.pm56
1 files changed, 56 insertions, 0 deletions
diff --git a/blog/BBSFileHeader.pm b/blog/BBSFileHeader.pm
new file mode 100644
index 00000000..4865da8b
--- /dev/null
+++ b/blog/BBSFileHeader.pm
@@ -0,0 +1,56 @@
+#!/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}) =
+ unpack('Z33cZ14Z6Z65', $t);
+ $h{title} = substr($h{title}, 3);
+ $self->{cache}{$num}{$_} = $h{$_}
+ foreach( 'filename', 'owner', 'date', 'title' );
+ return $h{$key};
+ }
+}
+
+1;