to your request to select the number of displayed
+# lines
+#
+__EOF
+
+}
+
+sub analyze($) {
+ my %r;
+ $r{name} = shift;
+ $r{size} = -s $r{name};
+ open($r{fh}, $r{name}) or do {
+ $@ = "Can't open $r{name}: $!\n";
+ return ();
+ };
+
+ if ($r{size} == 0) {
+ $r{lines} = 0;
+ }
+ else {
+ my $s;
+ while (defined($_ = $r{fh}->getline)) {
+ $s += length;
+ last if $. == 100;
+ }
+ $r{avglen} = $s / $.;
+ $r{lines} = int($r{size} / $r{avglen});
+ }
+
+ seek($r{fh}, 0, 0);
+ return %r;
+}
+
+sub http($@) {
+ my $code = shift;
+ my $date = date1123();
+
+ my $type = $_[0] =~ /^
+
+400 Bad Request
+
+Bad Request
+Your browser sent a request that this server could not understand.
+
+
+__EOF
+}
+
+__END__
+
+=head1 NAME
+
+hlog - simple http server providing access to some logfile
+
+=head1 SYNOPSIS
+
+ hlog [--[no]daemon]
+ [-k|--kill]
+ [-a|--address address] [-p|--port port]
+ [--lines n]
+ {file|tag=file ...}
+
+ hlog [-h|--help] [-m|--man]
+
+=head1 DESCRIPTION
+
+This script should run as a server providing access to
+the last lines of a logfile. It should understand basic HTTP/1.x.
+
+See the L section for more information on files.
+
+=head1 OPTIONS
+
+=over
+
+=item B<-a>|B<--address> I
+
+The address to listen on. (default: 0.0.0.0)
+
+=item B<--[no]daemon>
+
+Do (or do not) daemonize. (default: do)
+
+=item B<--lines> I
+
+The number of lines to show. (default: 10)
+
+=item B<-k>|B<--kill>
+
+With this option the corresponding (address/port) process gets killed.
+(default: off)
+
+=item B<-p>|B<--port> I
+
+The port to listen on. (default: 8080)
+
+=back
+
+=head1 EXAMPLES
+
+Using tags makes it possible to access more then one log file
+via the same running instance by specifying the tag in the URL.
+
+Once started as:
+
+ hlog error=/var/log/apache/error.log access=/var/log/apache/access.log
+
+The following URLs are valid:
+
+ http://:8080/error
+ http://:8080/access?10
+
+=head1 FILES
+
+The B tool tries to create several files
+
+=head2 F and F
+
+These files will be written to F or F<$HOME/.hlog/> if
+possible. The mentioned directories (the leave part) will be created, if
+possible. It is no fatal error if B fails on this.
+
+=head2 PID file
+
+B tries to create a pid file in F or
+F<$HOME/.hlog>. It even tries to create the leave part the directory.
+Failing on this it not fatal, but then the B<--kill> option will not
+work!
+
+The pid file will be named according to the hostname (see B<--address>)
+beeing used. For safety the hostname will be sanitized to avoid
+dangerous filenames.
+
+=cut