E-Books reader

E-Books reader (Alpha)

Web reader for ebooks text files.

Demo

Bibbia (Italian)

Source

#!/usr/local/bin/perl 
#
# E-book reader 1.0
# Copyright (C) 1998-2000 Roan Soldaini <roan @qbit .it>

#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# All copyright notices must remain intact in the scripts and in the outputted HTML

# --- Parameters ------------------------------------------------------------
$datafile = "bibbia.txt";
$outfile = "./bibbia/";

$createfile = 0; # 1: Create multiple files
$usefile = 0;    # 0: Use datafile - 1: Use multiple files

# ---------------------------------------------------------------------------
&CGI_Form;
$ql = $FORM{ql};
$qc = $FORM{qc};
$qv = $FORM{qv};
print "Content-type: text/html\n\n";
$script = $ENV{'DOCUMENT_URI'};
$script = $ENV{'SCRIPT_NAME'} if !$script;
$datafile = "$outfile$ql.txt" if $ql && $usefile;
$newlibro = $libro = $ql;
open INDEX, ">$outfile"."index.txt" if $createfile;
open FILE, $datafile;
while(<FILE>) {
  next if /^\n/; 
  chop($_);
  if (/^\t/) {
    print "$vv<hr size=1>",$vi=$vf=$vv='' if /^\t\[/ && $vv;
    $vi=$vf=$vv='' if /^\t\[/;
    @av = m|\[(\d+)\]|g;
    $vi = $av[0] if $vi eq ''; 
    $vf = "-$av[-1]" if $#av > 0; 
    if ($newlibro) {
      print "<h1><a href=\"$script?ql=$libro\"><center>$libro</center></a></h1>";
      $newlibro='';
      close OUT if OUT;
      open OUT, ">$outfile$libro.txt" if $createfile;
      print INDEX "$libro\n" if INDEX;
    }
    if ($newcap) {
      print "<h2><a href=\"$script?ql=$libro&qc=$cap\">Capitolo $cap</a></h2>";; 
      $newcap='';
      print OUT "$cap\n" if OUT;
    }
    if (OUT) {
      print OUT "$_\n" if OUT;
    }
    next if ($qc ne $cap) || ($ql ne $libro);
    next if $qv && ($qv < $vi);
    next if $qv && $vf && ($qv > -$vf);
    next if $qv && !$vf && ($qv > $vi);
    $vv = "(<a href=\"$script?ql=$libro\">$libro</a> <a href=\"$script?ql=$libro&qc=$cap\">$cap</a>, <a href=\"$script?ql=$libro&qc=$cap&qv=$vi\">$vi$vf</a>)";
    $_ =~ s|\[(\d+\w?)\]|<sup><small>$1</small></sup>|g;
    $_ = '&nbsp;&nbsp;&nbsp;'.$_;
    print "<p>$_</p>"; 
  }
  else{
    print "$vv<hr size=1>",$vi=$vf=$vv='' if $vv;
    if (/^\d/) {
      $cap = $_; 
      next if !$ql && !$createfile;
      next if $ql && ($libro ne $ql);
      next if $qc && ($cap ne $qc);
      $newcap = true;
    }
    elsif (/^\w/) {
      $libro = $_;
      $cap = '';
      next if $ql && ($libro ne $ql);
      $newlibro = true;
    }
  }
}
print $vv if $vv;
print '<div align="right"><small>Powered by <a href="http://www.qbit.it/">Ebook-reader</a></small></div>';
close FILE;
# ---------------------------------------------------------------------------
sub CGI_Form{
if($ENV{'REQUEST_METHOD'} eq 'GET' || $ENV{'REQUEST_METHOD'} eq 'HEAD'){
   $buffer = $ENV{'QUERY_STRING'};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/</&lt;/g;
   $value =~ s/>/&gt;/g;
   $value =~ s/<([^>]|\n)*>//g;
   $value =~ s/\n/<br>/g; #
   ; #
   $FORM{$name} = $value;
}
}
# ---------------------------------------------------------------------------
QBit