mobi2html 0000755 0001750 0001750 00000016556 10735527500 011754 0 ustar tompe tompe #!/usr/bin/env perl
# Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# mobi2html, Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
use HTML::TreeBuilder;
use Palm::PDB;
use Palm::Doc;
use Image::Size;
use Date::Parse;
use Date::Format;
use Getopt::Mixed;
use strict;
use vars qw ($opt_rawhtml $opt_record0 $opt_saveallrecords);
Getopt::Mixed::getOptions ("rawhtml record0 saveallrecords");
my $filename = shift;
my $explodedir = shift;
die "A directory to exlode the mobi file must be specified as second argument"
unless defined $explodedir;
die "File does not exist: $filename" unless -e $filename;
mkdir $explodedir;
my $pdb = new Palm::PDB;
$pdb->Load($filename);
my $name = $pdb->{"name"};
my $version = $pdb->{"version"};
my $type = $pdb->{"type"};
my $creator = $pdb->{"creator"};
my $seed = $pdb->{"uniqueIDseed"};
my $ctime = $pdb->{"ctime"};
my $mtime = $pdb->{"mtime"};
my $sctime = ctime ($ctime);
my $smtime = ctime ($mtime);
print STDERR "Name: $name\n";
print STDERR "Version: $version\n";
print STDERR "Type: $type\n";
print STDERR "Creator: $creator\n";
print STDERR "Seed: $seed\n";
print STDERR "Resdb: " . $pdb->{"attributes"}{"ResDB"} . "\n";
print STDERR "AppInfoDirty: " . $pdb->{"attributes"}{"AppInfoDirty"} . "\n";
print STDERR "ctime: $ctime - $sctime\n";
print STDERR "mtime: $mtime - $smtime\n";
print STDERR "baktime: " . $pdb->{"baktime"} . "\n";
my @records = @{$pdb->{"records"}};
print STDERR "Number of record: " . $#records . "\n";
my $image_index = 0;
my %image_index_to_filename = ();
foreach my $r (@records) {
my $id = $r->{"id"};
my $cat = $r->{"category"};
my $offset = $r->{"offset"};
my $data = $r->{"data"};
my $size = length ($data);
my $filename = "record-$id";
my ($x, $y, $type) = imgsize(\$data);
if (defined $x) {
print STDERR "Record $id - $cat - $offset - $size - $x x $ y\n";
$image_index++;
$image_index_to_filename{$image_index} = "$filename.$type";
open DATA, ">$explodedir/$filename.$type";
binmode (DATA);
print DATA $data;
close DATA;
# print STDERR "SIZE: $x $y\n";
} else {
if (defined $opt_record0 or defined $opt_saveallrecords) {
open DATA, ">$filename";
print DATA $data;
close DATA;
}
}
if (defined $opt_record0) {
exit (0);
}
if ($id == 0) {
parse_record_0 ($data);
}
}
#my @resources = @{$pdb->{"resources"}};
#print STDERR "Number of resources: " . $#resources . "\n";
my $text = $pdb->text;
#{
# local $/;
# $text =~ s/\r//g;
#}
if (defined $opt_rawhtml) {
binmode (STDOUT);
print $text;
}
my %fileposmap;
print STDERR "Looking for filepos\n";
my $cp = 0;
my $len = length ($text);
while ($cp < $len) {
my $s = substr ($text, $cp, 50);
if (substr ($s, 0, 7) eq "filepos") {
if ($s =~ /^filepos=(\d+)/) {
print STDERR "FILEPOS: $cp - $1\n";
$fileposmap{$1} = 1;
}
if ($s =~ /^filepos=\"(\d+)\"/) {
print STDERR "FILEPOS: $cp - $1\n";
$fileposmap{$1} = 1;
}
}
$cp++;
}
print STDERR "Found all filepos\n";
my $offset = 0;
foreach my $pos (sort keys %fileposmap) {
print STDERR "NAMEPOS: $pos\n";
my $a = substr ($text, $pos+$offset, 2);
if ($a eq "ignore_unknown (0);
$tree->parse ($text);
$tree->eof ();
#my $tree = HTML::TreeBuilder->new_from_content ($text);
fix_filepos_attributes ($tree);
fix_image_tags ($tree);
my $htmlfile = $filename;
$htmlfile =~ s/\.mobi/.html/;
$htmlfile =~ s/\.prc/.html/;
$htmlfile =~ s/\.pdb/.html/;
open HTML, ">$explodedir/$htmlfile" or die "Could not open file $explodedir/$htmlfile";
print HTML $tree->as_HTML;
close HTML;
sub fix_image_tags {
my $tree = shift;
my @imgel = $tree->find ("img");
foreach my $img (@imgel) {
my $recindex = $img->attr ("recindex");
my $ind = int ($recindex);
my $filename = $image_index_to_filename{$ind};
print STDERR "FIX IMAGE TAGS: $recindex - $ind - $filename\n";
$img->attr ("recindex", undef);
$img->attr ("src", $filename);
}
}
sub fix_filepos_attributes {
my $tree = shift;
my @ael = $tree->find ("a");
foreach my $a (@ael) {
my $filepos = $a->attr ("filepos");
if ($filepos) {
$a->attr ("href", "\#$filepos");
print STDERR "FIX FILEPOS ATTR: $filepos\n";
}
}
}
sub parse_record_0 {
my $rec = shift;
my $palmdocheader = substr ($rec, 0, 16);
parse_palmdoc_header ($palmdocheader);
if ($type eq "BOOK" and $creator eq "MOBI") {
my $mobiheader = substr ($rec, 16);
parse_mobi_header ($mobiheader);
}
}
sub parse_palmdoc_header {
my $data = shift;
my ($version, $length, $nrecords, $recsize, $unknown) =
unpack ("nxxNnnN", $data);
print STDERR "PDHEADER Version: $version\n";
print STDERR "PDHEADER Length: $length\n";
print STDERR "PDHEADER NRecords: $nrecords\n";
print STDERR "PDHEADER Recsize: $recsize\n";
print STDERR "PDHEADER Unknown: $unknown\n";
}
sub parse_mobi_header {
my $data = shift;
my ($doctype, $length, $type, $codepage, $uniqueid, $ver) =
unpack ("a4NNNNN", $data);
my ($exthflg) = unpack ("N", substr ($data, 0x70));
print STDERR "MOBIHEADER doctype: $doctype\n";
print STDERR "MOBIHEADER length: $length\n";
print STDERR "MOBIHEADER type: $type\n";
print STDERR "MOBIHEADER codep: $codepage\n";
print STDERR "MOBIHEADER uniqid: $uniqueid\n";
print STDERR "MOBIHEADER ver: $ver\n";
print STDERR "MOBIHEADER exthflg: $exthflg\n";
if ($exthflg & 0x40) {
my $exth = substr ($data, $length);
parse_mobi_exth ($exth);
}
}
sub parse_mobi_exth {
my $data = shift;
my ($doctype, $len, $n_items) = unpack ("a4NN", $data);
print STDERR "EXTH doctype: $doctype\n";
print STDERR "EXTH length: $len\n";
print STDERR "EXTH n_items: $n_items\n";
my $pos = 12;
foreach (1..$n_items) {
my ($id, $size) = unpack ("NN", substr ($data, $pos));
my $contlen = $size-8;
my ($id, $size, $content) = unpack ("NNa$contlen", substr ($data, $pos));
my $hid = sprintf ("%x", $id);
my $hsize = sprintf ("%x", $size);
print STDERR "ITEM: $hid $hsize - $id $size - $content\n";
$pos += $size;
}
}
=pod
=head1 NAME
mobi2html - A script to explode a DRM-free MobiPocket file to html
=head1 SYNOPSIS
mobi2html file.mobi unpackdir
=head1 DESCRIPTION
A script to explode a DRM-free MobiPocket file to html.
=head1 OPTIONS
=over 4
=item B<--rawhtml>
Output the unmodified HTML code on STDOUT. Mostly useful for debugging.
=back
=head1 EXAMPLES
mobi2html "Bleak House.prc" unpack
mobi2html "Bleak House.prc" unpack --rawhtml > t.html
=head1 AUTHOR
Tommy Persson (tpe@ida.liu.se)
=cut
html2mobi 0000755 0001750 0001750 00000020305 10735463375 011750 0 ustar tompe tompe #!/usr/bin/env perl
# html2mobi, Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
use FindBin qw($RealBin);
use lib "$RealBin";
use MobiPerl::MobiFile;
use MobiPerl::Opf;
use MobiPerl::Config;
use MobiPerl::LinksInfo;
use HTML::TreeBuilder;
use Getopt::Mixed;
use strict;
use vars qw ($opt_title $opt_author $opt_htmlfile $opt_mobifile $opt_gentoc
$opt_coverimage $opt_noimages $opt_addcoverlink
$opt_prefixtitle);
Getopt::Mixed::getOptions ("title=s author=s htmlfile=s mobifile=s gentoc
coverimage=s noimages addcoverlink
prefixtitle=s");
#
# expand html document with links...
# Generate TOC automatically, guide thingy
# Getting images to work...
# Small image in library, 8 record, 180x240 jpeg
# make testhtmlsgentoc, links in non generatec toc is not working
#
#
# Debian: libpalm-perl
# libimage-size-perl
#
# 8 DWord dwType //pub type: 2=book,3=palmdoc,4=audio,news=257,feed=258,magazin e=259 etc
# C DWord dwCodepage //1252=western, 65001 = UTF8. Better not use anything else
my @filenames = @ARGV;
my $tree = 0;
my %file_to_tree = ();
my %file_to_title = ();
my $namerefindex = 0;
my %file_to_nameref = ();
my $linksinfo = new MobiPerl::LinksInfo;
my $mobifile = "t.mobi";
my $config = new MobiPerl::Config;
$config->add_cover_link (1) if defined $opt_addcoverlink;
$config->no_images (1) if defined $opt_noimages;
$config->cover_image ($opt_coverimage);
$config->author ("Unspecified Author");
$config->author ($opt_author) if defined $opt_author;
$config->title ($opt_title);
$config->prefix_title ($opt_prefixtitle);
my $filename = $filenames[0];
$mobifile = $filename;
$mobifile =~ s/\.html/\.mobi/;
$mobifile =~ s/\.htm/\.mobi/;
if ($#filenames == 0) {
$tree = one_html_file ($filename, $linksinfo);
} else {
if (not defined $opt_title) {
$config->title ("dummycollectiontitle")
}
$tree = get_collection ($config, $linksinfo, @filenames);
}
if (defined $opt_htmlfile) {
open HTML, ">$opt_htmlfile" or die "Could not open html file $opt_htmlfile: $!\n";
print HTML $tree->as_HTML;
close HTML;
}
if (defined $opt_mobifile) {
$mobifile = $opt_mobifile;
}
if ($mobifile eq $filename) {
$mobifile .= ".mobi";
}
MobiPerl::MobiFile::save_mobi_file ($tree, $mobifile, $linksinfo, $config);
#
# HTML manipulation functions
#
sub one_html_file {
my $filename = shift;
my $linksinfo = shift;
print STDERR "ONEHTMLFILE: $filename\n";
my $tree = new HTML::TreeBuilder ();
$tree->ignore_unknown (0);
$tree->parse_file ($filename) || die "Could not find file: $filename\n";
$linksinfo->check_for_links ($tree);
my $titleelement = $tree->find ("title");
if ($titleelement and not $config->title ()) {
$config->title ($titleelement->as_trimmed_text ());
}
if (not $config->title ()) {
my $title = $filename;
$title =~ s/\.html//;
$title =~ s/\.htm//;
$config->title ($title);
}
return $tree;
}
sub get_trees {
my @files = @_;
my @res = ();
foreach my $filename (@files) {
my $tree = new HTML::TreeBuilder ();
$tree->ignore_unknown (0);
$tree->parse_file ($filename) || die "Could not find file: $filename\n";
push @res, $tree;
}
return @res;
}
sub get_title {
my $t = shift;
my $res = "";
my $titleelement = $t->find ("title");
if ($titleelement) {
$res = $titleelement->as_trimmed_text ();
}
return $res;
}
sub get_titles {
my @trees = @_;
my @res = ();
foreach my $t (@trees) {
my $title = get_title ($t);
push @res, $title;
}
return @res;
}
sub get_toc_tree {
my @files = @_;
my $res = HTML::Element->new('ul');
my @trees = get_trees (@filenames);
my @titles = get_titles (@trees);
foreach my $i (0..@titles-1) {
my $title = $titles[$i];
my $file = $files[$i];
my $name = "tocname-" . $namerefindex++;
$file_to_tree{$file} = $trees[$i];
$file_to_title{$file} = $title;
$file_to_nameref{$file} = $name;
print STDERR "GETTOCTREETITLE: $title - $file - $name\n";
my $li = HTML::Element->new('li');
my $a = HTML::Element->new('a', href => "\#$name");
$a->push_content ($title);
$li->push_content ($a);
$res->push_content ($li);
}
return $res;
}
sub get_collection {
my $config = shift;
my $linksinfo = shift;
my @files = @_;
my $toctree = get_toc_tree (@filenames);
# print $toctree->as_HTML;
my $title = $config->title ();
my $html = HTML::Element->new('html');
my $head = HTML::Element->new('head');
my $titleel = HTML::Element->new('title');
$titleel->push_content ($title);
$head->push_content ($titleel);
my $body = HTML::Element->new('body',
topmargin => "0",
leftmargin => "0",
bottommargin => "0",
rightmargin => "0");
# topmargin="1em" leftmargin="2em" bottommargin="0" rightmargin="0"
#
# Title
#
my $h1 = HTML::Element->new('h1');
$h1->push_content ($title);
$body->push_content ($h1);
#
# Table of content
#
if (defined $opt_gentoc) {
my $h2 = HTML::Element->new('h2');
$h2->push_content ("TABLE OF CONTENTS");
$body->push_content ($h2);
$body->push_content ($toctree);
}
#
# All files
#
foreach my $file (@files) {
print STDERR "ADDING TO COLLECTION: $file\n";
my $tree = $file_to_tree{$file};
$linksinfo->check_for_links ($tree);
my $title = $file_to_title{$file};
my $nameref = $file_to_nameref{$file};
my $h2 = HTML::Element->new('h2');
my $a = HTML::Element->new('a', name => "$nameref");
$a->push_content ("$title");
$h2->push_content ($a);
$body->push_content ($h2);
my $b = $tree->find ("body");
$body->push_content ($b->content_list());
}
$html->push_content ($head);
$html->push_content ($body);
return $html;
}
=pod
=head1 NAME
html2mobi - A script to convert html files or a collection of html files
to a MobiPocket file
=head1 SYNOPSIS
html2mobi file.html
html2mobi file1.html file2.html ...
=head1 DESCRIPTION
A script to convert html files or a collection of html files to a
MobiPocket file
=head1 OPTIONS
=over 4
=item B<--title TITLE>
Specify the title for the book. This overrides the value given in the
html file.
=item B<--prefixtitle PREFIX>
Add a prefix to the title of the book. Useful for specifying number
for books in series.
=item B<--author AUTHOR>
Specify the author of the book.
=item B<--mobifile MOBIFILE>
Name of the output file. This overrides the default value.
=item B<--htmlfile HTMLFILE>
Saves the html that is packed into mobi format. This html code contains
Mobipocket specific things that are added automatically. This is mostly
useful for debugging.
=item B<--coverimage IMAGE>
The image to be used as cover in a library listing like the one in
Cybook Gen3. The image will be rescaled to a suitable format (180x240).
If no image is specified the first image in the source files is used.
=item B<--addcoverlink>
Add link to cover image first in main document.
=item B<--gentoc>
For a collection of html files generate the table of contents automatically.
=back
=head1 EXAMPLES
html2mobi Alice_In_Wonderland.html
=head1 TODO
- Specify margins with flags
- Follow local links when given a root html file
- Get meta information from somewhere...
- Include wget
- News argument (bbc, ....)
=head1 BUGS
- Images larger than a certain size less than 600x800 does
not work on the Gen3. I now resize so that maximum width
is 480. But 600x800 gif file did work with the demo Alice
mobi file. So there is a bug here somewhere.
=head1 AUTHOR
Tommy Persson (tpe@ida.liu.se)
=cut
lit2mobi 0000755 0001750 0001750 00000010236 10735463326 011572 0 ustar tompe tompe #!/usr/bin/env perl
# Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# mobi2html, Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
use strict;
use FindBin qw($RealBin);
use lib "$RealBin";
use MobiPerl::MobiFile;
use MobiPerl::Opf;
use MobiPerl::Config;
use MobiPerl::LinksInfo;
use Getopt::Mixed;
use File::Copy;
use vars qw ($opt_title $opt_author $opt_htmlfile $opt_mobifile
$opt_coverimage $opt_noimages
$opt_tocfirst $opt_addcoverlink
$opt_prefixtitle);
Getopt::Mixed::getOptions ("title=s author=s htmlfile=s mobifile=s
coverimage=s noimages tocfirst addcoverlink
prefixtitle=s");
#my @args = map { s/\s/\\ /g; $_ } @ARGV;
#my $command = "html2mobi " . join " ", @args;
#print STDERR "Command: $command\n";
#system ($command) == 0 or die "system ($command) failed: $!\n";
my $filename = shift;
if (not $filename =~ /\.lit$/) {
die "File $filename has wrong extension\n";
}
my $config = new MobiPerl::Config;
$config->add_cover_link (1) if defined $opt_addcoverlink;
$config->toc_first (1) if defined $opt_tocfirst;
$config->no_images (1) if defined $opt_noimages;
$config->cover_image ($opt_coverimage);
$config->author ($opt_author);
$config->title ($opt_title);
$config->prefix_title ($opt_prefixtitle);
MobiPerl::Util::unpack_lit_file ($filename, "ctmp");
my $opffile = $filename;
my $mobifile = $filename;
$mobifile =~ s/\.lit/\.mobi/;
$mobifile = $opt_mobifile if defined $opt_mobifile;
if ($mobifile eq $filename) {
$mobifile .= ".mobi";
}
$opffile =~ s/\.lit/.opf/;
chdir "ctmp";
my $linksinfo = new MobiPerl::LinksInfo;
my $tree = MobiPerl::Util::get_tree_from_opf ($opffile, $config, $linksinfo);
if (defined $opt_htmlfile) {
open HTML, ">$opt_htmlfile" or die "Could not open html file $opt_htmlfile: $!\n";
print HTML $tree->as_HTML;
close HTML;
}
MobiPerl::MobiFile::save_mobi_file ($tree, $mobifile, $linksinfo, $config);
move ($mobifile, "../");
=pod
=head1 NAME
lit2mobi - A script to convert a lit file to a MobiPocket file
=head1 SYNOPSIS
html2mobi file.lit
=head1 DESCRIPTION
A script to convert a lit file to a MobiPocket file
This requires clit (ConvertLit) to be installed and in the path.
=head1 OPTIONS
=over 4
=item B<--title TITLE>
Specify the title for the book. This overrides the value given in the
opf file.
=item B<--prefixtitle PREFIX>
Add a prefix to the title of the book. Useful for specifying number
for books in series.
=item B<--author AUTHOR>
Specify the author of the book. This overrides the value given in the
opf file. This value is stored in the EXTH part of record 0.
=item B<--mobifile MOBIFILE>
Name of the output file. This overrides the default value.
=item B<--addcoverlink>
Add link to cover image first in main document.
=item B<--tocfirst>
Make a copy of the toc and place it first.
=item B<--htmlfile HTMLFILE>
Saves the html that is packed into mobi format. This html code contains
Mobipocket specific things that are added automatically. This is mostly
useful for debugging.
=back
=head1 EXAMPLES
lit2mobi Alice_In_Wonderland.lit
lit2mobi --tocfirst --addcoverlink The_Railway_Children.lit
=head1 TODO
- Extract language information from opf file
=head1 BUGS
- Images larger than a certain size less than 600x800 does
not work on the Gen3. I now resize so that maximum width
is 480. But 600x800 gif file did work with the demo Alice
mobi file. So there is a bug here somewhere.
=head1 AUTHOR
Tommy Persson (tpe@ida.liu.se)
=cut
mobi2mobi 0000755 0001750 0001750 00000027764 10735522067 011744 0 ustar tompe tompe #!/usr/bin/env perl
# Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# mobi2html, Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
use FindBin qw($RealBin);
use lib "$RealBin";
#
# TODO:
#
# - add extended tags to existing tags, test with I, Robot
# - perldoc, document which packages are needed
# - add arbitrary meta information...
#
#
# These packages need to be installed via CPAN or via distribution
# specific packages.
#
use Palm::PDB;
use Palm::Doc;
use Date::Format; # for ctime call
use Getopt::Mixed;
use Image::Size; # Used to recognize the first record that is an image
#
# The ActivePerl ppm packaged corresponding to the above is:
#
# p5-Palm
# TimeDate
# Getopt-Mixed
# Image-Size
#
use MobiPerl::MobiHeader; # The MobiHeader package file is in the distribution
use strict;
use vars qw ($opt_outfile $opt_title $opt_prefixtitle $opt_author
$opt_publisher $opt_databasename
$opt_addthumbnail $opt_coverimage $opt_patch);
Getopt::Mixed::getOptions ("outfile=s title=s prefixtitle=s author=s
publisher=s databasename=s patch
addthumbnail=s coverimage=s");
my $filename = shift;
my $pdb = new Palm::PDB;
$pdb->Load($filename);
my $name = $pdb->{"name"};
my $version = $pdb->{"version"};
my $type = $pdb->{"type"};
my $creator = $pdb->{"creator"};
my $seed = $pdb->{"uniqueIDseed"};
my $ctime = $pdb->{"ctime"};
my $mtime = $pdb->{"mtime"};
my $btime = $pdb->{"baktime"};
my $sctime = ctime ($ctime);
my $smtime = ctime ($mtime);
my $sbtime = ctime ($btime);
print "Database Name: $name\n";
print " Version: $version\n";
print " Type: $type\n";
print " Creator: $creator\n";
print " Seed: $seed\n";
print " Resdb: " . $pdb->{"attributes"}{"ResDB"} . "\n";
print " AppInfoDirty: " . $pdb->{"attributes"}{"AppInfoDirty"} . "\n";
print " ctime: $ctime - $sctime";
print " mtime: $mtime - $smtime";
print " baktime: $btime - $sbtime";
print "---------------------------------------------------\n";
#
#
#
$pdb->{"name"} = $opt_databasename if defined $opt_databasename;
my @records = @{$pdb->{"records"}};
#
# Find the first record with an image
#
my $imgindex = 0;
foreach my $r (@records) {
my $data = $r->{"data"};
my ($x, $y) = imgsize (\$data);
if (defined $x) {
print "Image record index: $imgindex ($x x $y)\n";
last;
}
$imgindex++;
}
my $coverimageindex = $imgindex;
my $r0 = $records[0];
my $ismobi = parse_record_0 ($r0->{"data"});
my $palmdocheader = substr ($r0->{"data"}, 0, 16);
my $lastid = $records[$#records]->{"id"};
print "LASTID: $lastid\n";
print "-----------------\n";
if (defined $opt_outfile) {
my $coveroffset = -1;
my $thumboffset = -1;
if (defined $opt_addthumbnail) {
my $img = Palm::PDB->new_Record();
$img->{"categori"} = 0;
$img->{"attributes"}{"Dirty"} = 1;
$img->{"id"} = $lastid+1;
my $data = get_cover_image_data ($opt_addthumbnail);
$img->{"data"} = $data;
$pdb->append_Record ($img);
my @records = @{$pdb->{"records"}};
my $thumbindex = $#records;
$thumboffset = $thumbindex-$imgindex;
}
if (defined $opt_coverimage) {
if ($coverimageindex != 0) {
print STDERR "Setting record $coverimageindex to $opt_coverimage\n";
my $data = get_cover_image_data ($opt_coverimage);
$pdb->{"records"}->[$coverimageindex]->{"data"} = $data;
$coveroffset = $coverimageindex-$imgindex;
} else {
my $img = Palm::PDB->new_Record();
$img->{"categori"} = 0;
$img->{"attributes"}{"Dirty"} = 1;
$img->{"id"} = $lastid+1;
my $data = get_cover_image_data ($opt_coverimage);
$img->{"data"} = $data;
$pdb->append_Record ($img);
my @records = @{$pdb->{"records"}};
my $coverindex = $#records;
$coveroffset = $coverindex-$imgindex;
}
}
if ($ismobi) {
my $mh = substr ($r0->{"data"}, 16);
if (defined $opt_author) {
$mh = MobiPerl::MobiHeader::set_exth_data ($mh, "author", $opt_author);
}
if (defined $opt_publisher) {
$mh = MobiPerl::MobiHeader::set_exth_data ($mh, "publisher", $opt_publisher);
}
if (defined $opt_title) {
print STDERR "Setting new title: $opt_title\n";
$mh = MobiPerl::MobiHeader::set_extended_title ($mh, $opt_title);
}
if (defined $opt_prefixtitle) {
my $title = MobiPerl::MobiHeader::get_extended_title ($mh);
$title = $opt_prefixtitle . $title;
print STDERR "Setting new title: $title\n";
$mh = MobiPerl::MobiHeader::set_extended_title ($mh, $title);
}
if (defined $opt_patch) {
my ($imgflg, $imgindex) = unpack ("nn", substr ($mh, 0xb0));
my $newimgindex = $imgindex;
print STDERR "PATCHING INGINDEX $imgindex -> $newimgindex\n";
substr ($mh, 0xb0, 4, pack ("nn", 0, $newimgindex));
}
$mh->set_thumb_offset ($thumboffset) if ($thumboffset >= 0);
$mh->set_cover_offset ($coveroffset) if ($coveroffset >= 0);
$r0->{"data"} = $palmdocheader . $mh;
} else {
my $mh = new MobiPerl::MobiHeader;
my $title = $filename;
$title =~ s/\.prc$//;
$title =~ s/\.pdb$//;
$title =~ s/\.mobi$//;
$mh->set_title ($title);
$mh->set_title ($opt_title) if defined $opt_title;
$mh->set_author ($opt_author) if defined $opt_author;
$mh->set_publisher ($opt_publisher) if defined $opt_publisher;
$mh->set_image_record_index ($imgindex);
$mh->set_thumb_offset ($thumboffset) if ($thumboffset >= 0);
$mh->set_cover_offset ($coveroffset) if ($coveroffset >= 0);
$pdb->{"type"} = "BOOK";
$pdb->{"creator"} = "MOBI";
$r0->{"data"} = $palmdocheader . $mh->get_data ();
}
$pdb->Write ($opt_outfile);
}
sub iso2hex($) {
my $hex = '';
for (my $i = 0; $i < length($_[0]); $i++) {
my $ordno = ord substr($_[0], $i, 1);
$hex .= sprintf("%lx", $ordno);
}
$hex =~ s/ $//;;
$hex;
}
sub parse_record_0 {
my $rec = shift;
my $res = 0;
my $palmdocheader = substr ($rec, 0, 16);
parse_palmdoc_header ($palmdocheader);
if ($type eq "BOOK" and $creator eq "MOBI") {
my $mobiheader = substr ($rec, 16);
parse_mobi_header ($mobiheader);
$res = 1;
}
return $res;
}
sub parse_palmdoc_header {
my $data = shift;
my ($version, $length, $nrecords, $recsize, $unknown) =
unpack ("nxxNnnN", $data);
print "PDHEADER Version: $version\n";
print "PDHEADER Length: $length\n";
print "PDHEADER NRecords: $nrecords\n";
print "PDHEADER Recsize: $recsize\n";
print "PDHEADER Unknown: $unknown\n";
}
sub parse_mobi_header {
my $data = shift;
my ($doctype, $length, $type, $codepage, $uniqueid, $ver) =
unpack ("a4NNNNN", $data);
my ($exthflg) = unpack ("N", substr ($data, 0x70));
if ($ver > 3) {
my ($ciflg, $ciptr) = unpack ("nn", substr ($data, 0xb0));
print "MOBIHEADER ciflg: $ciflg\n";
print "MOBIHEADER ciptr: $ciptr\n";
}
print "MOBIHEADER doctype: $doctype\n";
print "MOBIHEADER length: $length\n";
print "MOBIHEADER type: $type\n";
print "MOBIHEADER codep: $codepage\n";
print "MOBIHEADER uniqid: $uniqueid\n";
print "MOBIHEADER ver: $ver\n";
print "MOBIHEADER exthflg: $exthflg\n";
if ($exthflg & 0x40) {
my $exth = substr ($data, $length);
my $eh = new MobiPerl::EXTH ($exth);
my $cover_offset = $eh->get_cover_offset ();
print "COVEROFFSET: $cover_offset\n";
$coverimageindex += $cover_offset;
parse_mobi_exth ($exth);
}
my $title = MobiPerl::MobiHeader::get_extended_title ($data);
print "LONGTITLE: $title\n";
}
sub parse_mobi_exth {
my $data = shift;
my ($doctype, $len, $n_items) = unpack ("a4NN", $data);
print "EXTH doctype: $doctype\n";
print "EXTH length: $len\n";
print "EXTH n_items: $n_items\n";
my $pos = 12;
foreach (1..$n_items) {
my ($id, $size) = unpack ("NN", substr ($data, $pos));
my $contlen = $size-8;
my ($id, $size, $content) = unpack ("NNa$contlen", substr ($data, $pos));
my $hid = sprintf ("%x", $id);
my $hsize = sprintf ("%x", $size);
my $desc = MobiPerl::EXTH::get_description ($id);
if (MobiPerl::EXTH::is_binary_data ($id)) {
$content = iso2hex ($content);
}
print "EXTH item: $id - $desc - $contlen - $content\n";
$pos += $size;
}
}
sub get_cover_image_data {
my $filename = shift;
my $data = "";
if (not -e $filename) {
print STDERR "Image file does not exist: $filename\n";
return $data;
}
open(IMG, $filename) or die "can't open $filename: $!";
binmode(IMG); # now DOS won't mangle binary input from GIF
my $buff;
while (read(IMG, $buff, 8 * 2**10)) {
$data .= $buff;
}
return $data;
}
=pod
=head1 NAME
mobi2mobi - A program to manipulate mobi files
=head1 SYNOPSIS
mobi2mobi file.mobi
mobi2mobi file.prc
mobi2mobi --outfile out.mobi --prefixtitle "01-" file.mobi
=head1 DESCRIPTION
A program to manipulate MobiPocket files. Author and title can be set
and a cover image (also thumb nail image for Gen3) can be added.
There are two kind of prc files used for electronic books. One is a
PalmDOC file which does not have a MOBI header but can contain HTML
code marked up with MobiPocket specific markup and it can be read by a
MobiPocket reader. For this format you cannot store meta information
in the header. The other format is MobiPocket and it has a MOBI header
and some additional data where you can store meta information and an
extended title.
This program can change the extended title for a MobiPocket file. It
can also automatically convert a PalmDOC file to a MobiPocket file and
set the title.
It can also add author information to a PalmDOC file by converting it
to a MobiPocket file and set the author meta information. It can also
change or set the author information for a MobiPocket file.
You can also add a prefix to a title in a MobiPocket file. This does
not work for PalmDOC files.
It is possible to add an image to the file. If there are no other
images in the file then the added image will be used as cover image
and thumb nail image for Cybook Gen3. You can also replace the cover
image if it already exists.
Just running the program on a mobifile without any flags will print
some information about the file.
Since there is no specification available for the MOBI header this
program might generate books that are not entirely correct. So keep the
original files...
=head1 OPTIONS
=over 4
=item B<--databasename NAME>
Change the database name of the file (the first 31 characters in the file).
=item B<--title TITLE>
Change the the title of the book.
=item B<--prefixtitle prefix>
Add a prefix to the title of the book.
=item B<--author AUTHOR>
Set the author of the book.
=item B<--publisher PUBLISHER>
Set the publisher of the book.
=item B<--addthumbnail IMAGEFILE>
Add an image that will be used as thumbnail image for Gen3 devices.
This will only work if the book contains no other images.
=item B<--coverimage IMAGEFILE>
Set the over image of a book. If there already is a cover image it will
be replaced.
=item B<--outfile OUTFILE>
Name of the output file. No conversion is done if this is not
specified.
=back
=head1 EXAMPLES
mobi2mobi file.mobi
mobi2mobi --outfile out.mobi --prefixtitle "01-" file.mobi
mobi2mobi --outfile out.mobi --title "Correction of title" file.mobi
mobi2mobi --addthumbnail cover.jpg --outfile out.mobi file.mobi
=head1 TODO
- Functionality to change or add other meta information then author.
=head1 BUGS
- according to the Mobilread thread there is some problem with DRM:ed
files...
=head1 AUTHOR
Tommy Persson (tpe@ida.liu.se)
=cut
opf2mobi 0000755 0001750 0001750 00000007712 10735463421 011567 0 ustar tompe tompe #!/usr/bin/env perl
# Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# mobi2html, Copyright (C) 2007 Tommy Persson, tpe@ida.liu.se
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
use strict;
use FindBin qw($RealBin);
use lib "$RealBin";
use MobiPerl::MobiFile;
use MobiPerl::Opf;
use MobiPerl::Config;
use MobiPerl::LinksInfo;
use Getopt::Mixed;
use File::Copy;
use vars qw ($opt_title $opt_author $opt_htmlfile $opt_mobifile
$opt_coverimage $opt_noimages
$opt_tocfirst $opt_addcoverlink
$opt_prefixtitle);
Getopt::Mixed::getOptions ("title=s author=s htmlfile=s mobifile=s
coverimage=s noimages tocfirst addcoverlink
prefixtitle=s");
#my @args = map { s/\s/\\ /g; $_ } @ARGV;
#my $command = "html2mobi " . join " ", @args;
#print STDERR "Command: $command\n";
#system ($command) == 0 or die "system ($command) failed: $!\n";
my $filename = shift;
if (not $filename =~ /\.opf$/) {
die "File $filename has wrong extension\n";
}
my $config = new MobiPerl::Config;
$config->add_cover_link (1) if defined $opt_addcoverlink;
$config->toc_first (1) if defined $opt_tocfirst;
$config->no_images (1) if defined $opt_noimages;
$config->cover_image ($opt_coverimage);
$config->author ($opt_author);
$config->title ($opt_title);
$config->prefix_title ($opt_prefixtitle);
my $mobifile = $filename;
$mobifile =~ s/\.opf/\.mobi/;
$mobifile = $opt_mobifile if defined $opt_mobifile;
if ($mobifile eq $filename) {
$mobifile .= ".mobi";
}
my $linksinfo = new MobiPerl::LinksInfo;
my $tree = MobiPerl::Util::get_tree_from_opf ($filename, $config, $linksinfo);
if (defined $opt_htmlfile) {
open HTML, ">$opt_htmlfile" or die "Could not open html file $opt_htmlfile: $!\n";
print HTML $tree->as_HTML;
close HTML;
}
MobiPerl::MobiFile::save_mobi_file ($tree, $mobifile, $linksinfo, $config);
=pod
=head1 NAME
opf2mobi - A script to convert an opf file to a MobiPocket file
=head1 SYNOPSIS
opf2mobi file.opf
=head1 DESCRIPTION
A script to convert an opf file to a MobiPocket file.
=head1 OPTIONS
=over 4
=item B<--title TITLE>
Specify the title for the book. This overrides the value given in the
opf file.
=item B<--prefixtitle PREFIX>
Add a prefix to the title of the book. Useful for specifying number
for books in series.
=item B<--author AUTHOR>
Specify the author of the book. This overrides the value given in the
opf file. This value is stored in the EXTH part of record 0.
=item B<--mobifile MOBIFILE>
Name of the output file. This overrides the default value.
=item B<--addcoverlink>
Add link to cover image first in main document.
=item B<--tocfirst>
Make a copy of the toc and place it first.
=item B<--htmlfile HTMLFILE>
Saves the html that is packed into mobi format. This html code contains
Mobipocket specific things that are added automatically. This is mostly
useful for debugging.
=back
=head1 EXAMPLES
lit2mobi Alice_In_Wonderland.lit
lit2mobi --tocfirst --addcoverlink The_Railway_Children.lit
=head1 TODO
- Extract language information from opf file
=head1 BUGS
- Images larger than a certain size less than 600x800 does
not work on the Gen3. I now resize so that maximum width
is 480. But 600x800 gif file did work with the demo Alice
mobi file. So there is a bug here somewhere.
=head1 AUTHOR
Tommy Persson (tpe@ida.liu.se)
=cut
MobiPerl/Config.pm 0000644 0001750 0001750 00000003016 10734275006 013370 0 ustar tompe tompe package MobiPerl::Config;
use FindBin qw($RealBin);
use lib "$RealBin";
use strict;
sub new {
my $this = shift;
my $data = shift;
my $class = ref($this) || $this;
my $obj = bless {
ADDCOVERLINK => 0,
TOCFIRST => 0,
COVERIMAGE => "",
AUTHOR => "",
TITLE => "",
PREFIXTITLE => "",
NOIMAGES => 0,
@_
}, $class;
$obj->initialize_from_file ($data) if defined $data;
return $obj;
}
sub add_cover_link {
my $self = shift;
my $val = shift;
if (defined $val) {
$self->{ADDCOVERLINK} = $val;
} else {
return $self->{ADDCOVERLINK};
}
}
sub toc_first {
my $self = shift;
my $val = shift;
if (defined $val) {
$self->{TOCFIRST} = $val;
} else {
return $self->{TOCFIRST};
}
}
sub cover_image {
my $self = shift;
my $val = shift;
if (defined $val) {
$self->{COVERIMAGE} = $val;
} else {
return $self->{COVERIMAGE};
}
}
sub author {
my $self = shift;
my $val = shift;
if (defined $val) {
$self->{AUTHOR} = $val;
} else {
return $self->{AUTHOR};
}
}
sub title {
my $self = shift;
my $val = shift;
if (defined $val) {
$self->{TITLE} = $val;
} else {
return $self->{TITLE};
}
}
sub prefix_title {
my $self = shift;
my $val = shift;
if (defined $val) {
$self->{PREFIXTITLE} = $val;
} else {
return $self->{PREFIXTITLE};
}
}
sub no_images {
my $self = shift;
my $val = shift;
if (defined $val) {
$self->{NOIMAGES} = $val;
} else {
return $self->{NOIMAGES};
}
}
return 1;
MobiPerl/EXTH.pm 0000644 0001750 0001750 00000011354 10734325270 012736 0 ustar tompe tompe package MobiPerl::EXTH;
use FindBin qw($RealBin);
use lib "$RealBin";
use strict;
my %typename_to_type = ("author" => 100,
"publisher" => 101,
"imprint" => 102,
"subject" => 105,
"publishingdate" => 106,
"coveroffset" => 201,
"thumboffset" => 202,
"hasfakecover" => 203,
);
my %type_to_desc = (1 => "drm_server_id",
2 => "drm_commerce_id",
3 => "drm_ebookbase_book_id",
100 => "Author",
101 => "Publisher",
102 => "Imprint",
104 => "ISBN",
105 => "Subject",
106 => "PublishingDate",
107 => "Review",
108 => "Contributor",
109 => "Rights",
110 => "SubjectCode",
111 => "Type",
112 => "Source",
113 => "ASIN",
114 => "VersionNumber",
115 => "Sample",
116 => "StartReading",
201 => "CoverOffset",
202 => "ThumbOffset",
203 => "hasFakeCover");
my %binary_data = (300 => 1,
201 => 1,
202 => 1,
203 => 1);
sub new {
my $this = shift;
my $data = shift;
my $class = ref($this) || $this;
my $obj = bless {
TYPE => [],
DATA => [],
@_
}, $class;
$obj->initialize_from_data ($data) if defined $data;
return $obj;
}
sub get_string {
my $self = shift;
my @type = @{$self->{TYPE}};
my @data = @{$self->{DATA}};
my $res = "";
foreach my $i (0..$#type) {
my $type = $type[$i];
my $data = $data[$i];
my $typedesc = $type;
if (defined $type_to_desc{$type}) {
$typedesc = $type_to_desc{$type};
if (defined $binary_data{$type}) {
$res .= $typedesc . " - " . "not printable" . "\n";
} else {
$res .= $typedesc . " - " . $data . "\n";
}
}
}
return $res;
}
sub add {
my $self = shift;
my $typename = shift;
my $data = shift;
my $type = $self->get_type ($typename);
if (is_binary_data ($type)) {
print STDERR "EXTH add: $typename - $type - ", int($data), "\n";
} else {
print STDERR "EXTH add: $typename - $type - $data\n";
}
if ($type) {
push @{$self->{TYPE}}, $type;
push @{$self->{DATA}}, $data;
}
return $type;
}
sub get_type {
my $self = shift;
my $typename = shift;
my $res = 0;
### print STDERR "EXTH: GETTYPE: $typename\n";
if (defined $typename_to_type{$typename}) {
$res = $typename_to_type{$typename};
}
return $res;
}
sub set {
my $self = shift;
my $typename = shift;
my $data = shift;
my $type = $self->get_type ($typename);
### print STDERR "EXTH setting data: $type - $data\n";
if ($type) {
my @type = @{$self->{TYPE}};
my @data = @{$self->{DATA}};
my $found = 0;
foreach my $i (0..$#type) {
if ($type[$i] == $type) {
print STDERR "EXTH setting data: $data - $type\n";
$self->{TYPE}->[$i] = $type;
$self->{DATA}->[$i] = $data;
$found = 1;
last;
}
}
if (not $found) {
$self->add ($typename, $data);
}
}
return $type;
}
sub initialize_from_data {
my $self = shift;
my $data = shift;
my ($doctype, $len, $n_items) = unpack ("a4NN", $data);
## print "EXTH doctype: $doctype\n";
## print "EXTH length: $len\n";
## print "EXTH n_items: $n_items\n";
my $pos = 12;
foreach (1..$n_items) {
my ($id, $size) = unpack ("NN", substr ($data, $pos));
my $contlen = $size-8;
my ($type, $size, $content) = unpack ("NNa$contlen", substr ($data, $pos));
push @{$self->{TYPE}}, $type;
push @{$self->{DATA}}, $content;
$pos += $size;
}
if ($self->get_data () ne substr ($data, 0, $len)) {
print STDERR "ERROR: generated EXTH does not match original\n";
}
## open EXTH0, ">exth0";
## print EXTH0 substr ($data, 0, $len);
## open EXTH1, ">exth1";
## print EXTH1 $self->get_data ();
}
sub get_data {
my $self = shift;
my @type = @{$self->{TYPE}};
my @data = @{$self->{DATA}};
my $exth = pack ("a*", "EXTH");
my $content = "";
my $n_items = 0;
foreach my $i (0..$#type) {
my $type = $type[$i];
my $data = $data[$i];
$content .= pack ("NNa*", $type, length ($data)+8, $data);
$n_items++;
}
#
# Maybe fill up to even 4...
#
my $comp = length ($content) % 4;
if ($comp) {
foreach ($comp .. 3) {
$content .= pack ("C", 0);
}
}
$exth .= pack ("NN", length ($content)+12, $n_items);
$exth .= $content;
return $exth;
}
sub get_cover_offset {
my $self = shift;
my $res = 0;
my @type = @{$self->{TYPE}};
my @data = @{$self->{DATA}};
my $res = 0;
foreach my $i (0..$#type) {
if ($type[$i] == 201) {
($res) = unpack ("N", $data[$i]);
}
}
return $res;
}
#
# Non object methods
#
sub get_description {
my $type = shift;
my $res = $type;
if (defined $type_to_desc{$type}) {
$res = $type_to_desc{$type};
}
return $res;
}
sub is_binary_data {
my $type = shift;
return $binary_data{$type};
}
return 1;
MobiPerl/LinksInfo.pm 0000644 0001750 0001750 00000004001 10734170275 014054 0 ustar tompe tompe package MobiPerl::LinksInfo;
use FindBin qw($RealBin);
use lib "$RealBin";
use strict;
###use MobiPerl::Util;
##use Data::Dumper;
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $obj = bless {
LINKEXISTS => {},
RECORDINDEX => 0,
RECORDTOIMAGEFILE => {},
@_
}, $class;
return $obj;
}
sub link_exists {
my $self = shift;
return $self->{LINKEXISTS};
}
sub add_image_link {
my $self = shift;
my $image = shift;
## print STDERR "ADD_IMAGE_LINK: $image\n";
$self->{RECORDINDEX}++;
$self->{RECORDTOIMAGEFILE}->{$self->get_record_index ()} = $image;
}
sub get_record_index {
my $self = shift;
return $self->{RECORDINDEX};
}
sub get_image_file {
my $self = shift;
my $val = shift;
return $self->{RECORDTOIMAGEFILE}->{$val};
}
sub get_n_images {
my $self = shift;
my $res = keys %{$self->{RECORDTOIMAGEFILE}};
return $res;
}
sub check_for_links {
my $self = shift;
my $html = shift;
for (@{$html->extract_links('a', 'img')}) {
my($link, $element, $attr, $tag) = @$_;
next if ($link =~ /http/);
next if ($link =~ /mailto/);
next if ($link =~ /www/);
# print STDERR "LINK: $tag $link $attr at ", $element->address(), " ";
if ($tag eq "a") {
my $filename = $element->as_trimmed_text ();
## print STDERR "LINKEXISTS $filename -> $link - ";
#
# Remove possible prefix file name in link
#
$link =~ s/^.*\#//;
## print STDERR "$link\n";
$element->attr("href", "\#$link");
$self->{LINKEXISTS}->{$link} = 1;
next;
}
if ($tag eq "img") {
my $src = $element->attr("src");
$element->attr("src", undef);
$self->{RECORDINDEX}++;
#
# Does not work for more than 9 images
#
$element->attr("recindex", sprintf ("%05d", $self->{RECORDINDEX}));
$self->{RECORDTOIMAGEFILE}->{$self->{RECORDINDEX}} = $src;
next;
}
print STDERR "LINK: $tag $link $attr at ", $element->address(), " ";
# print STDERR $element->as_HTML;
}
}
return 1;
MobiPerl/MobiFile.pm 0000644 0001750 0001750 00000013555 10734260773 013667 0 ustar tompe tompe package MobiPerl::MobiFile;
use Palm::PDB;
use Palm::Doc;
use MobiPerl::MobiHeader;
use MobiPerl::Util;
use constant DOC_UNCOMPRESSED => scalar 1;
use constant DOC_COMPRESSED => scalar 2;
use constant DOC_RECSIZE => scalar 4096;
use strict;
sub save_mobi_file {
my $html = shift;
my $filename = shift;
my $linksinfo = shift;
my $config = shift;
my $author = $config->author ();
my $title = $config->title ();
print STDERR "Saving mobi file (version 4): $filename\n";
my $mobi = new Palm::Doc;
$mobi->{attributes}{"resource"} = 0;
$mobi->{attributes}{"ResDB"} = 0;
$mobi->{"name"} = $title;
$mobi->{"type"} = "BOOK";
$mobi->{"creator"} = "MOBI";
$mobi->{"version"} = 0;
$mobi->{"uniqueIDseed"} = 28;
# $mobi->{"attributes"}{"resource"} = $data;
# my $header = Palm::PDB->new_Record();
# $header->{"categori"} = 0;
# $header->{"attributes"}{"Dirty"} = 1;
# $header->{"id"} = 0;
# $header->{"data"} = $data;
# $mobi->append_Record ($header);
## $mobi->text ([$data, $html->as_HTML ()]);
## $mobi->text ($html->as_HTML ());
#
# From Doc.pm and modified
#
my $version = DOC_COMPRESSED;
$mobi->{'records'} = [];
$mobi->{'resources'} = [];
my $header = $mobi->append_Record();
$header->{'version'} = $version;
$header->{'length'} = 0;
$header->{'records'} = 0;
$header->{'recsize'} = DOC_RECSIZE;
my $body = $html->as_HTML ();
# print STDERR "HTMLSIZE: " . length ($body) . "\n";
my $current_record_index = 1;
# break the document into record-sized chunks
for( my $i = 0; $i < length($body); $i += DOC_RECSIZE ) {
my $record = $mobi->append_Record;
my $chunk = substr($body,$i,DOC_RECSIZE);
$record->{'data'} = Palm::Doc::_compress_record( $version, $chunk );
$record->{'id'} = $current_record_index++;
$header->{'records'} ++;
}
$header->{'length'} += length $body;
$header->{'recsize'} = $header->{'length'} if $header->{'length'} < DOC_RECSIZE;
#
# pack the Palm Doc header
#
$header->{'data'} = pack( 'n xx N n n N',
$header->{'version'}, $header->{'length'},
$header->{'records'}, $header->{'recsize'}, 0 );
#
# Add MOBI header
#
my $mh = new MobiPerl::MobiHeader;
$mh->set_title ($title);
$mh->set_author ($author);
$mh->set_image_record_index ($current_record_index);
$mh->set_cover_offset (0);
# $mh->set_thumb_offset (0);
## my $codepage = 65001; # utf-8
# my $codepage = 1252; # westerner
# my $ver = 3;
# my $type = 2; # book
# my $mobiheadersize = 0x74;
# my $unique_id = 17;
# if ($ver == 4) {
# $mobiheadersize = 0xE4;
# }
#
# my $extended_title_offset = $mobiheadersize + 16;
# my $extended_title_length = length ($title);
#
# my $use_extended_header = 1;
# my $extended_header_flag = 0x00;
# if ($use_extended_header) {
# $extended_header_flag = 0x50; # At MOBI+0x70
# }
#
# my $exth = "";
# if ($use_extended_header) {
# $exth = pack ("a*", "EXTH");
# my $content = "";
# my $n_items = 1;
# $content .= pack ("NNa*", 100, length ($author)+8, $author);
# $exth .= pack ("NN", length ($content), $n_items);
# $exth .= $content;
# $extended_title_offset += length ($exth);
# }
#
#
# # NNNN Number of char, N1 N2 N3
# # N3 = Pointer to start of Title
# # Not true in Alice Case...
# #
#
# my $vie1 = 0; # 0x11 Alice 0x0D Rosenbaum
#
# print STDERR "MOBIHDR: imgrecpointer: $current_record_index\n";
#
# $header->{'data'} .= pack ("a*NNNNN", "MOBI",
# $mobiheadersize, $type,
# $codepage, $unique_id, $ver);
#
# $header->{'data'} .= pack ("NN", 0xFFFFFFFF, 0xFFFFFFFF);
# $header->{'data'} .= pack ("NNNN", 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
# $header->{'data'} .= pack ("NNNN", 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
# $header->{'data'} .= pack ("NNNN", $vie1, $extended_title_offset, $extended_title_length, 0x0409);
# $header->{'data'} .= pack ("NNNN", 0, 0, 0x04, $current_record_index);
# $header->{'data'} .= pack ("NNNN", 0, 0, 0, 0);
# $header->{'data'} .= pack ("N", $extended_header_flag);
## print STDERR "MOBIHEADERSIZE: $mobiheadersize " . length ($header->{'data'}). "\n";
# while (length ($header->{'data'}) < ($mobiheadersize+16)) {
# print STDERR "LEN: " . length ($header->{'data'}). " - $mobiheadersize
#\n";
# $header->{'data'} .= pack ("N", 0);
# }
# $header->{'data'} .= $exth;
# $header->{'data'} .= pack ("a*", $title);
# for (1..48) {
# $header->{'data'} .= pack ("N", 0);
# }
#
$header->{'data'} .= $mh->get_data ();
#
# End from Doc.pm
#
if (not $config->no_images ()) {
for my $i (1..$linksinfo->get_record_index ()) {
my $filename = $linksinfo->get_image_file ($i);
print STDERR "New record for image $current_record_index: $filename\n";
#
# Is it really correct to assign id and categori?
#
my $img = Palm::PDB->new_Record();
$img->{"categori"} = 0;
$img->{"attributes"}{"Dirty"} = 1;
$img->{"id"} = $current_record_index++;
my $data = MobiPerl::Util::get_image_data ($filename);
$img->{"data"} = $data;
$mobi->append_Record ($img);
}
my $coverimage = $config->cover_image ();
#
# This will not work since EXTH information not set
#
#
# Adding thumb for Cybook does not seem to be neccessary.
# To automatically add the first image seems wrong...
# So functionality disabled for now.
#
if ($coverimage and 0) {
print STDERR "New record for library image $current_record_index: $coverimage\n";
my $img = Palm::PDB->new_Record();
$img->{"categori"} = 0;
$img->{"attributes"}{"Dirty"} = 1;
$img->{"id"} = $current_record_index++;
my $data = MobiPerl::Util::get_thumb_cover_image_data ($coverimage);
$img->{"data"} = $data;
$mobi->append_Record ($img);
}
}
$mobi->Write ($filename);
}
return 1;
MobiPerl/MobiHeader.pm 0000644 0001750 0001750 00000024402 10734252365 014167 0 ustar tompe tompe use strict;
#
# This is a patch of a function in Palm::Doc to be able to handle
# DRM:ed files.
#
package Palm::Doc;
sub _parse_headerrec($) {
my $record = shift;
return undef unless exists $record->{'data'};
# Doc header is minimum of 16 bytes
return undef if length $record->{'data'} < 16;
my ($version,$spare,$ulen, $records, $recsize, $position)
= unpack( 'n n N n n N', $record->{'data'} );
# the header is followed by a list of record sizes. We don't use
# this since we can guess the sizes pretty easily by looking at
# the actual records.
# According to the spec, $version is either 1 (uncompressed)
# or 2 (compress), while spare is always zero. AportisDoc supposedly sets
# spare to something else, so screw AportisDoc.
#
# $version is 17480 for DRM:ed MobiPocket books
#
# So comment away the check
### return undef if $version != DOC_UNCOMPRESSED and $version != DOC_COMPRESSED;
return undef if $spare != 0;
$record->{'version'} = $version;
$record->{'length'} = $ulen;
$record->{'records'} = $records;
$record->{'recsize'} = $recsize;
$record->{'position'} = $position;
return $record;
}
package MobiPerl::MobiHeader;
use FindBin qw($RealBin);
use lib "$RealBin";
use MobiPerl::EXTH;
use strict;
#
# TYPE: 2=book
#
# VERSION: Should be 3 or 4
#
# CODEPAGE: utf-8: 65001; westerner: 1252
#
# IMAGERECORDINDEX: the index of the first record with image in it
#
# Language seems to be stored in 4E: en-us 0409
# sv 041d
# fi 000b
# en 0009
#
# 0x50 and 0x54 might also be some kind of language specification
#
#
# 0000: MOBI header-size type codepage
# 0010: unique-id version FFFFFFFF FFFFFFFF
#
# header-size = E4 if version = 4
# type = 2 - book
# codepage = 1252 - westerner
# unique-id = seems to be random
# version = 3 or 4
#
# 0040: data4 exttitleoffset exttitlelength language
# 0050: data1 data2 data3 nonbookrecordpointer
# 0060: data5
#
# data1 and data2 id 09 in Oxford dictionary. The same as languange...
# nonbookrecordpointer in Oxford is 0x7167. data5 is 0x7157
# data3 is 05 in Oxford so maybe this is the version?
#
my %langmap = ("en-us" => 0x0409,
"sv" => 0x041d,
"fi" => 0x000b,
"en" => 0x0009,
"en-gb" => 0x0809);
sub new {
my $this = shift;
my $class = ref($this) || $this;
bless {
TYPE => 2,
VERSION => 4,
CODEPAGE => 1252,
TITLE => "Unspecified Title",
AUTHOR => "Unspecified Author",
PUBLISHER => "",
IMAGERECORDINDEX => 0,
LANGUAGE => "en",
COVEROFFSET => -1,
THUMBOFFSET => -1,
@_
}, $class;
}
sub set_author {
my $self = shift;
my $val = shift;
$self->{AUTHOR} = $val;
}
sub get_author {
my $self = shift;
return $self->{AUTHOR};
}
sub set_cover_offset {
my $self = shift;
my $val = shift;
$self->{COVEROFFSET} = $val;
}
sub get_cover_offset {
my $self = shift;
return $self->{COVEROFFSET};
}
sub set_thumb_offset {
my $self = shift;
my $val = shift;
$self->{THUMBOFFSET} = $val;
}
sub get_thumb_offset {
my $self = shift;
return $self->{THUMBOFFSET};
}
sub set_publisher {
my $self = shift;
my $val = shift;
$self->{PUBLISHER} = $val;
}
sub get_publisher {
my $self = shift;
return $self->{PUBLISHER};
}
sub set_language {
my $self = shift;
my $val = shift;
$self->{LANGUAGE} = $val;
}
sub get_language {
my $self = shift;
return $self->{LANGUAGE};
}
sub set_title {
my $self = shift;
my $val = shift;
$self->{TITLE} = $val;
}
sub get_title {
my $self = shift;
return $self->{TITLE};
}
sub set_image_record_index {
my $self = shift;
my $val = shift;
$self->{IMAGERECORDINDEX} = $val;
}
sub get_image_record_index {
my $self = shift;
return $self->{IMAGERECORDINDEX};
}
sub get_type {
my $self = shift;
return $self->{TYPE};
}
sub get_codepage {
my $self = shift;
return $self->{CODEPAGE};
}
sub set_version {
my $self = shift;
my $val = shift;
$self->{VERSION} = $val;
}
sub get_version {
my $self = shift;
return $self->{VERSION};
}
sub get_unique_id {
my $self = shift;
my $r1 = int (rand (256));
my $r2 = int (rand (256));
my $r3 = int (rand (256));
my $r4 = int (rand (256));
my $res = $r1+$r2*256+$r3*256*256+$r4*256*256*256;
return $res;
}
sub get_header_size {
my $self = shift;
my $res = 0x74;
if ($self->get_version () == 4) {
$res = 0xE4;
}
return $res;
}
sub get_extended_header_data {
my $self = shift;
my $author = $self->get_author ();
my $eh = new MobiPerl::EXTH;
$eh->set ("author", $author);
my $pub = $self->get_publisher ();
$eh->set ("pubisher", $pub) if $pub;
my $coffset = $self->get_cover_offset ();
if ($coffset >= 0) {
$eh->set ("coveroffset", pack ("N", $coffset));
}
my $toffset = $self->get_thumb_offset ();
if ($toffset >= 0) {
$eh->set ("thumboffset", pack ("N", $toffset));
}
# $eh->set ("hasfakecover", pack ("N", 0));
return $eh->get_data ();
}
sub get_data {
my $self = shift;
my $res = "";
my $vie1 = 0; # 0x11 Alice 0x0D Rosenbaum 0xFFFFFFFF, Around the world
$vie1 = 0xFFFFFFFF;
my $vie2 = 0x04; # had this, around the world have 0x01
my $use_extended_header = 1;
my $extended_header_flag = 0x00;
if ($use_extended_header) {
$extended_header_flag = 0x50; # At MOBI+0x70
}
my $extended_title_offset = $self->get_header_size () + 16 + length ($self->get_extended_header_data ());
my $extended_title_length = length ($self->get_title ());
print STDERR "MOBIHDR: imgrecpointer: ", $self->get_image_record_index (), "\n";
$res .= pack ("a*NNNNN", "MOBI",
$self->get_header_size (),
$self->get_type (),
$self->get_codepage (),
$self->get_unique_id (),
$self->get_version ());
$res .= pack ("NN", 0xFFFFFFFF, 0xFFFFFFFF);
$res .= pack ("NNNN", 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
$res .= pack ("NNNN", 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
$res .= pack ("NNNN", $vie1, $extended_title_offset,
$extended_title_length, $langmap{$self->get_language ()});
$res .= pack ("NNNN", 0xFFFFFFFF, 0xFFFFFFFF, $vie2, $self->get_image_record_index ());
$res .= pack ("NNNN", 0xFFFFFFFF, 0, 0xFFFFFFFF, 0);
$res .= pack ("N", $extended_header_flag);
# print STDERR "MOBIHEADERSIZE: $mobiheadersize " . length ($header->{'data'}). "\n";
while (length ($res) < $self->get_header_size ()) {
### print STDERR "LEN: " . length ($res) . " - " . $self->get_header_size () . "\n";
$res .= pack ("N", 0);
}
substr ($res, 0x94, 4, pack ("N", 0xFFFFFFFF));
substr ($res, 0x98, 4, pack ("N", 0xFFFFFFFF));
substr ($res, 0xb0, 4, pack ("N", 0xFFFFFFFF));
# maybe pointer to last image or to thumbnail image record
substr ($res, 0xb8, 4, pack ("N", 0xFFFFFFFF)); # record pointer
substr ($res, 0xc0, 4, pack ("N", 0xFFFFFFFF)); # record pointer
substr ($res, 0xc8, 4, pack ("N", 0xFFFFFFFF)); # record pointer
#
# unknown
#
substr ($res, 0xd0, 4, pack ("N", 0xFFFFFFFF));
substr ($res, 0xd8, 4, pack ("N", 0xFFFFFFFF));
substr ($res, 0xdc, 4, pack ("N", 0xFFFFFFFF));
$res .= $self->get_extended_header_data ();
$res .= pack ("a*", $self->get_title ());
#
# Why?
#
for (1..48) {
$res .= pack ("N", 0);
}
return $res;
}
#
# Help function that is not dependent on object state
#
sub get_extended_title {
my $h = shift;
my $len = length ($h);
my ($exttitleoffset) = unpack ("N", substr ($h, 0x44));
my ($exttitlelength) = unpack ("N", substr ($h, 0x48));
my ($title) = unpack ("a$exttitlelength", substr ($h, $exttitleoffset-16));
return $title;
}
sub set_extended_title {
my $mh = shift;
my $len = length ($mh);
my $title = shift;
my $titlelen = length ($title);
my ($exttitleoffset) = unpack ("N", substr ($mh, 0x44));
my ($exttitlelength) = unpack ("N", substr ($mh, 0x48));
my ($version) = unpack ("N", substr ($mh, 0x14));
my $res = substr ($mh, 0, $exttitleoffset-16);
my $aftertitle = substr ($mh, $exttitleoffset-16+$exttitlelength);
$res .= $title;
my $diff = $titlelen - $exttitlelength;
if ($diff <= 0) {
foreach ($diff .. -1) {
$res .= pack ("C", 0);
$diff++;
}
} else {
my $comp = $diff % 4;
if ($comp) {
foreach ($comp .. 3) {
$res .= pack ("C", 0);
$diff++;
}
}
}
$res = fix_pointers ($res, $exttitleoffset, $diff);
$res .= $aftertitle;
substr ($res, 0x48, 4, pack ("N", $titlelen));
return $res;
}
sub set_exth_data {
my $h = shift;
my $len = length ($h);
my $type = shift;
my $data = shift;
my $res = $h;
print STDERR "Setting extended header data: $type - $data\n";
my ($doctype, $length, $htype, $codepage, $uniqueid, $ver) =
unpack ("a4NNNNN", $h);
my ($exthflg) = unpack ("N", substr ($h, 0x70));
if ($exthflg & 0x40) {
my $exth = substr ($h, $length);
my ($doctype, $exthlen, $n_items) = unpack ("a4NN", $exth);
my $prefix = substr ($h, 0, $length);
my $suffix = substr ($exth, $exthlen);
my $eh = new MobiPerl::EXTH ($exth);
$eh->set ($type, $data);
print STDERR "GETSTRING: ", $eh->get_string ();
#
# Fix DRM and TITLE info pointers...
#
my $exthdata = $eh->get_data ();
my $diff = length ($exthdata)-$exthlen;
if ($diff <= 0) {
foreach ($diff .. -1) {
$exthdata .= pack ("C", 0);
$diff++;
}
}
$res = $prefix . $exthdata . $suffix;
$res = fix_pointers ($res, $length, $diff);
} else {
print STDERR "EXTH does not exist, data not set: $type - $data\n";
}
return $res;
}
sub fix_pointers {
my $mh = shift;
my $startblock = shift;
my $diff = shift;
#
# Fix pointers to long title and to DRM record
#
my ($exttitleoffset) = unpack ("N", substr ($mh, 0x44));
if ($exttitleoffset > $startblock and $diff > 0) {
substr ($mh, 0x44, 4, pack ("N", $exttitleoffset+$diff));
}
my ($drmoffset) = unpack ("N", substr ($mh, 0x98));
if ($drmoffset != 0xFFFFFFFF and
$drmoffset > $startblock and $diff > 0) {
substr ($mh, 0x98, 4, pack ("N", $drmoffset+$diff));
}
return $mh;
}
return 1;
MobiPerl/Opf.pm 0000644 0001750 0001750 00000016447 10734274674 012735 0 ustar tompe tompe package MobiPerl::Opf;
use FindBin qw($RealBin);
use lib "$RealBin";
use strict;
use XML::Parser::Lite::Tree;
use MobiPerl::Util;
##use Data::Dumper;
sub new {
my $this = shift;
my $data = shift;
my $class = ref($this) || $this;
my $obj = bless {
OPF => 0,
TITLE => "",
AUTHOR => "Unspecified Author",
IDTOHREF => {},
IDTOMEDIATYPE => {},
MANIFESTIDS => [],
COVERIMAGE => "",
SPINEIDS => [],
TOCHREF => "",
@_
}, $class;
$obj->initialize_from_file ($data) if defined $data;
return $obj;
}
sub get_href {
my $self = shift;
my $val = shift;
return $self->{IDTOHREF}->{$val};
}
sub get_media_type {
my $self = shift;
my $val = shift;
return $self->{IDTOMEDIATYPE}->{$val};
}
sub get_spine_ids {
my $self = shift;
return @{$self->{SPINEIDS}};
}
sub get_manifest_ids {
my $self = shift;
return @{$self->{MANIFESTIDS}};
}
sub set_opf {
my $self = shift;
my $val = shift;
$self->{OPF} = $val;
}
sub get_opf {
my $self = shift;
return $self->{OPF};
}
sub set_title {
my $self = shift;
my $val = shift;
$self->{TITLE} = $val;
}
sub get_title {
my $self = shift;
return $self->{TITLE};
}
sub set_author {
my $self = shift;
my $val = shift;
$self->{AUTHOR} = $val;
}
sub get_author {
my $self = shift;
return $self->{AUTHOR};
}
sub set_toc_href {
my $self = shift;
my $val = shift;
$self->{TOCHREF} = $val;
}
sub get_toc_href {
my $self = shift;
return $self->{TOCHREF};
}
sub set_cover_image {
my $self = shift;
my $val = shift;
$self->{COVERIMAGE} = $val;
}
sub get_cover_image {
my $self = shift;
return $self->{COVERIMAGE};
}
sub initialize_from_file {
my $self = shift;
my $filename = shift;
print STDERR "Opf: Initialize from file: $filename\n";
open OPF, "<$filename" or die "Could not open opf file: $filename\n";
local $/;
my $content = ;
print STDERR "CONTENT: $content\n";
my $tree_parser = XML::Parser::Lite::Tree::instance();
my $opf = $tree_parser->parse($content);
$self->set_opf ($opf);
# print STDERR Dumper($opf);
my $title = opf_get_title ($opf);
# global variable $title, bad...
print STDERR "OPF: TITLE: $title\n";
$self->set_title ($title);
my $creator = opf_get_tag ($opf, "dc:Creator");
# global variable $title, bad...
print STDERR "OPF: CREATOR: $creator\n";
$self->set_author ($creator);
$self->parse_manifest ($opf);
$self->parse_spine ($opf);
$self->parse_guide ($opf);
}
sub parse_manifest {
my $self = shift;
my $opf = shift;
my $type = $opf->{"type"};
# print STDERR "TYPE: $type - ";
if ($type eq "tag") {
my $name = $opf->{"name"};
# print STDERR "$name\n";
if ($name eq "manifest") {
print STDERR "Init from manifest\n";
my $children = $opf->{"children"};
foreach my $c (@{$children}) {
if ($c->{name} eq "item") {
my $id = $c->{"attributes"}->{"id"};
my $href= $c->{"attributes"}->{"href"};
my $mediatype = $c->{"attributes"}->{"media-type"};
print STDERR "$id - $href - $mediatype\n";
$self->{IDTOHREF}->{$id} = $href;
$self->{IDTOMEDIATYPE}->{$id} = $mediatype;
push @{$self->{MANIFESTIDS}}, $id;
# $opf_id_to_href{$id} = $href;
# $opf_id_to_mediatype{$id} = $mediatype;
# push @opf_manifest_ids, $id;
#
# Check if image is coverimage file
#
if ($mediatype =~ /image/) {
if (MobiPerl::Util::is_cover_image ($href)) {
$self->set_cover_image ($href);
## $coverimage = $href;
}
}
}
}
return;
}
}
if ($type eq "data") {
return "";
}
if ($type eq "tag" or $type eq "root") {
my $children = $opf->{"children"};
foreach my $c (@{$children}) {
$self->parse_manifest ($c);
}
}
}
sub parse_spine {
my $self = shift;
my $opf = shift;
my $type = $opf->{"type"};
# print STDERR "TYPE: $type - ";
if ($type eq "tag") {
my $name = $opf->{"name"};
# print STDERR "$name\n";
if ($name eq "spine") {
# print STDERR "Init from spine\n";
my $children = $opf->{"children"};
my %idcheck = ();
foreach my $c (@{$children}) {
if ($c->{name} eq "itemref") {
my $idref = $c->{"attributes"}->{"idref"};
if ($idcheck{$idref}) {
print STDERR "WARNING: Spine, duplice idref: $idref\n";
} else {
push @{$self->{SPINEIDS}}, $idref;
## push @opf_spine_ids, $idref;
$idcheck{$idref} = 1;
}
}
}
foreach my $id (@{$self->{MANIFESTIDS}}) {
## print STDERR "CHECK FOR ADDING to spine from manifest - $id\n";
if (not $idcheck{$id}) {
print STDERR "Warning, $id missing from spine, adding\n";
push @{$self->{SPINEIDS}}, $id;
## push @opf_spine_ids, $id;
}
}
return;
}
}
if ($type eq "data") {
return "";
}
if ($type eq "tag" or $type eq "root") {
my $children = $opf->{"children"};
foreach my $c (@{$children}) {
$self->parse_spine ($c);
}
}
}
sub parse_guide {
my $self = shift;
my $opf = shift;
my $type = $opf->{"type"};
# print STDERR "TYPE: $type - ";
if ($type eq "tag") {
my $name = $opf->{"name"};
# print STDERR "$name\n";
if ($name eq "guide") {
print STDERR "Init from guide\n";
my $children = $opf->{"children"};
foreach my $c (@{$children}) {
if ($c->{name} eq "reference") {
my $type = $c->{"attributes"}->{"type"};
# print STDERR "TYPE: $type\n";
if ($type eq "toc") {
$self->set_toc_href ($c->{"attributes"}->{"href"});
print STDERR "TOCHREF: ", $self->get_toc_href (), "\n";
}
}
}
return;
}
}
if ($type eq "data") {
return "";
}
if ($type eq "tag" or $type eq "root") {
my $children = $opf->{"children"};
foreach my $c (@{$children}) {
$self->parse_guide ($c);
}
}
}
#
# Non object methods
#
sub opf_get_title {
my $opf = shift;
# print STDERR "SELF:$self\n";
my $type = $opf->{"type"};
# print STDERR "TYPE: $type - ";
if ($type eq "tag") {
my $name = $opf->{"name"};
# print STDERR "$name\n";
if ($name eq "dc:Title") {
my $children = $opf->{"children"};
return @{$children}[0]->{"content"};
}
}
if ($type eq "data") {
return "";
my $content = $opf->{"content"};
chomp $content;
chomp $content;
print STDERR "$content\n";
}
if ($type eq "tag" or $type eq "root") {
my $children = $opf->{"children"};
foreach my $c (@{$children}) {
my $res = opf_get_title ($c);
if ($res) {
return $res;
}
}
}
return "";
}
sub opf_get_tag {
my $opf = shift;
my $tag = shift;
## print STDERR "opf_get_tag: $tag\n";
# print STDERR "SELF:$self\n";
my $type = $opf->{"type"};
# print STDERR "TYPE: $type - ";
if ($type eq "tag") {
my $name = $opf->{"name"};
## print STDERR "$name - $tag\n";
if ($name eq $tag) {
my $children = $opf->{"children"};
return @{$children}[0]->{"content"};
}
}
if ($type eq "data") {
return "";
my $content = $opf->{"content"};
chomp $content;
chomp $content;
print STDERR "$content\n";
}
if ($type eq "tag" or $type eq "root") {
my $children = $opf->{"children"};
foreach my $c (@{$children}) {
my $res = opf_get_tag ($c, $tag);
if ($res) {
return $res;
}
}
}
return "";
}
return 1;
MobiPerl/Util.pm 0000644 0001750 0001750 00000027153 10734274334 013113 0 ustar tompe tompe package MobiPerl::Util;
use strict;
use GD;
use HTML::TreeBuilder;
my $rescale_large_images = 1;
sub is_cover_image {
my $file = shift;
my $res = 0;
if (not -e $file) {
die "ERROR: File does not exist: $file";
}
my $p = new GD::Image ($file);
if (not defined $p) {
print STDERR "Could not read image file: $file\n";
}
my ($x, $y) = $p->getBounds();
# my $x = $p->width;
# my $y = $p->height;
if ($x == 510 and $y == 680) {
print STDERR "GUESSING COVERIMAGE: $file\n";
$res = 1;
}
if ($x == 600 and $y == 800) {
print STDERR "GUESSING COVERIMAGE: $file\n";
$res = 1;
}
return $res;
}
#
# OPF related functions
#
sub get_tree_from_opf {
my $file = shift;
my $config = shift;
my $linksinfo = shift;
my $opf = new MobiPerl::Opf ($file);
my $tochref = $opf->get_toc_href ();
my @opf_spine_ids = $opf->get_spine_ids ();
my @opf_manifest_ids = $opf->get_manifest_ids ();
my $title = $opf->get_title ();
print STDERR "OPFTITLE: $title\n";
if ($config->title ()) {
$title = $config->title ();
}
$title = $title = $config->prefix_title () . $title;
$config->title ($title);
my $author = $opf->get_author ();
print STDERR "OPFAUTHOR: $author\n";
if (not $config->author ()) {
$config->author ($author);
}
#
# If cover image not assigned search all files in current dir
# and see if some file is a coverimage
#
my $coverimage = $opf->get_cover_image ();
if ($coverimage eq "") {
opendir DIR, ".";
my @files = readdir (DIR);
foreach my $f (@files) {
if ($f =~ /\.jpg/ or
$f =~ /\.JPG/ or
$f =~ /\.gif/) {
# print STDERR "Checking if file is coverimage: $f\n";
if (MobiPerl::Util::is_cover_image ($f)) {
$coverimage = $f;
}
}
}
}
my $html = HTML::Element->new('html');
my $head = HTML::Element->new('head');
#
# Generate guide tag, specific for Mobipocket and is
# not understood by HTML::TreeBuilder...
#
my $guide = HTML::Element->new('guide');
if ($tochref) {
my $tocref = HTML::Element->new('reference',
title=>"Table of Contents",
type=>"toc",
href=>"\#$tochref");
$guide->push_content ($tocref);
}
if ($config->add_cover_link ()) {
my $coverref = HTML::Element->new('reference',
title=>"Cover",
type=>"cover",
href=>"\#addedcoverlink");
$guide->push_content ($coverref);
}
$head->push_content ($guide);
my $titleel = HTML::Element->new('title');
$titleel->push_content ($title);
$head->push_content ($titleel);
#
# Generate body
#
my $body = HTML::Element->new('body');
# topmargin => "0",
# leftmargin => "0",
# bottommargin => "0",
# rightmargin => "0");
my $coverp = HTML::Element->new('p',
id=>"addedcoverlink",
align=>"center");
my $coverimageel = HTML::Element->new('a',
onclick =>
"document.goto_page_relative(1)");
$coverp->push_content ($coverimageel);
if ($config->add_cover_link ()) {
$body->push_content ($coverp);
$body->push_content (HTML::Element->new('mbp:pagebreak'));
}
#
#
# Add TOC first also if --tocfirst
#
if ($tochref and $config->toc_first ()) {
print STDERR "ADDING TOC FIRST ALSO: $tochref\n";
my $tree = new HTML::TreeBuilder ();
$tree->ignore_unknown (0);
$tree->parse_file ($tochref) || die "Could not find file: $tochref\n";
### check_for_links ($tree);
$linksinfo->check_for_links ($tree);
my $b = $tree->find ("body");
$body->push_content ($b->content_list());
$body->push_content (HTML::Element->new('mbp:pagebreak'));
}
#
# All files in manifest
#
foreach my $id (@opf_spine_ids) {
my $filename = $opf->get_href ($id);
my $mediatype = $opf->get_media_type ($id);
## print STDERR "SPINE: adding $id - $filename - $mediatype\n";
next unless ($mediatype =~ /text/); # only include text content
my $tree = new HTML::TreeBuilder ();
$tree->ignore_unknown (0);
$tree->parse_file ($filename) || die "Could not find file: $filename\n";
### check_for_links ($tree);
$linksinfo->check_for_links ($tree);
print STDERR "Adding: $filename - $id\n";
# my $tree = $file_to_tree{$file};
# my $title = $file_to_title{$file};
# my $nameref = $file_to_nameref{$file};
# my $h2 = HTML::Element->new('h2');
# my $a = HTML::Element->new('a', name => "$nameref");
# $a->push_content ("$title");
# $h2->push_content ($a);
# $body->push_content ($h2);
## print STDERR "FILETOLINKCHECK:$filename:\n";
if ($linksinfo->link_exists ($filename)) {
## print STDERR "FILETOLINKCHECK:$filename: SUCCESS\n";
my $a = HTML::Element->new('a', name => $filename);
$body->push_content ($a);
}
my $b = $tree->find ("body");
$body->push_content ($b->content_list());
}
#
# Check if no images in document and include cover image if it exists
#
if ($config->cover_image ()) {
$coverimage = $config->cover_image ();
}
if ($linksinfo->get_n_images () == 0) {
if ($coverimage) {
print STDERR "NO IMAGES IN BOOK: Adding cover image: $coverimage\n";
$linksinfo->add_image_link ($coverimage);
#### $record_index++;
#### $record_to_image_file{$record_index} = $coverimage;
if ($config->add_cover_link ()) {
my $el = HTML::Element->new ('img', recindex => "00001");
$coverimageel->push_content ($el);
}
}
}
#
# Fix anchor to positions given by id="III"...
#
# filepos="0000057579"
#
my @refs = $body->look_down ("href", qr/^\#/);
push @refs, $head->look_down ("href", qr/^\#/);
my @hrefs = ();
my @refels = ();
my %href_to_ref = ();
foreach my $r (@refs) {
$r->attr ("filepos", "0000000000");
my $key = $r->attr ("href");
$key =~ s/\#//g;
push @hrefs, $key;
push @refels, $r;
# $r->attr ("href", undef);
}
$html->push_content ($head);
$html->push_content ($body);
my $data = $html->as_HTML ();
foreach my $i (0..$#hrefs) {
my $h = $hrefs[$i];
my $r = $refels[$i];
my $searchfor1 = "id=\"$h\"";
my $searchfor2 = "= 0) {
#
# search backwards for <
#
while (substr ($data, $pos, 1) ne "<") {
$pos--;
}
## $pos -=4; # back 4 positions to get to attr ("filepos", "$form");
} else {
### print STDERR "SEARCHFOR2: $searchfor2\n";
$pos = index ($data, $searchfor2);
if ($pos >= 0) {
my $form = "0" x (10-length($pos)) . "$pos";
### print STDERR "POSITION: $pos - $searchfor2 - $form\n";
$r->attr ("filepos", "$form");
} else {
}
}
}
# my @anchors = $body->look_down ("id", qr/./);
# foreach my $a (@anchors) {
# my $name = $a->attr("id");
# my $tag = $a->tag ();
# my $text = $a->as_trimmed_text ();
# if ($link_exists{$name}) {
# $a->delete_content ();
# my $ael = HTML::Element->new('a', name => $name);
# $ael->push_content ($text);
# $a->push_content ($ael);
# }
# print STDERR "ANCHORS: $tag - $name - $text\n";
# }
# $html->push_content ($head);
# $html->push_content ($body);
return $html;
}
#
# lit file functons
#
sub unpack_lit_file {
my $litfile = shift;
my $unpackdir = shift;
print STDERR "Unpack file $litfile in dir $unpackdir\n";
mkdir $unpackdir;
opendir DIR, $unpackdir;
my @files = readdir (DIR);
foreach my $f (@files) {
if ($f =~ /^\./) {
next;
}
if ($f =~ /^\.\./) {
next;
}
# print STDERR "FILE: $f\n";
unlink "$unpackdir/$f";
}
system ("clit \"$litfile\" $unpackdir") == 0
or die "system (clit $litfile $unpackdir) failed: $?";
}
sub get_thumb_cover_image_data {
my $filename = shift;
## print STDERR "COVERIMAGE: $filename\n";
my $data = "";
if (not -e $filename) {
print STDERR "Image file does not exist: $filename\n";
return $data;
}
my $p = new GD::Image ("$filename");
my ($x, $y) = $p->getBounds();
# my $x = $p->width;
# my $y = $p->height;
## add_text_to_image ($p, $opt_covertext);
my $scaled = scale_gd_image ($p, 180, 240);
print STDERR "Resizing image $x x $y -> 180 x 240 -> scaled.jpg\n";
return $scaled->jpeg ();
}
sub scale_gd_image {
my $im = shift;
my $x = shift;
my $y = shift;
my ($w0, $h0) = $im->getBounds();
# my $w0 = $im->width;
# my $h0 = $im->height;
my $w1 = $w0*$x;
my $h1 = $h0*$x;
## print STDERR "SCALE GD: $w0 $h0 $w1 $h1\n";
if (defined $y) {
$w1 = $x;
$h1 = $y;
}
my $res = new GD::Image ($w1, $h1);
$res->copyResized ($im, 0, 0, 0, 0, $w1, $h1, $w0, $h0);
return $res;
}
sub get_text_image {
my $width = shift;
my $height = shift;
my $text = shift;
my $image = Image::Magick->new;
# $image->Set(size=>"$width x $height");
# $image->ReadImage('xc:white');
# $image->Draw (pen => "red",
# primitive => "text",
# x => 200,
# y => 200,
# font => "Bookman-DemiItalic",
# text => "QQQQ$text, 200, 200",
# fill => "black",
# pointsize => 40);
# $image->Draw(pen => 'red', fill => 'red', primitive => 'rectangle',
# points => '20,20 100,100');
# $image->Write (filename => "draw2.jpg");
}
sub get_gd_image_data {
my $im = shift;
my $filename = shift;
my $quality = shift;
$quality = -1 if not defined $quality;
#
# For some strange reason it does not work if using
# the gif file with size 600x800
#
# if ($filename =~ /\.gif/) {
# return $im->gif ();
# }
if ($quality <= 0) {
return $im->jpeg ();
} else {
return $im->jpeg ($quality);
}
}
sub add_text_to_image {
my $im = shift;
my $text = shift;
my $x = $im->Get ("width");
my $y = $im->Get ("height");
if (defined $text and $text) {
print STDERR "DRAW TEXT: $text\n";
my $textim = get_text_image ($x, $y, $text);
$im->Draw (primitive => "text",
text => $text,
points => "50,50",
fill => "red",
pointsize => 72);
}
$im->Write (filename => "draw.jpg");
}
sub get_image_data {
my $filename = shift;
my $data = "";
if (not -e $filename) {
print STDERR "Image file does not exist: $filename\n";
return $data;
}
my $p = new GD::Image ("$filename");
my ($x, $y) = $p->getBounds();
# my $x = $p->width;
# my $y = $p->height;
#
# If I do not resize 600x800 images it does not work on Gen3
#
# check this one more time, 600x800 gif and jpeg with size
# less than 64K does not work on Gen3
#
if ($rescale_large_images) {
if ($x > 480) {
# width might be the problem...
my $scale = 480.0/$x; # 0.99 does not work, 480x640 works
$p = MobiPerl::Util::scale_gd_image ($p, $scale);
}
}
#
# Scale if scale option given
# or does it work just setting width?
#
my $quality = -1;
my $size = length (MobiPerl::Util::get_gd_image_data ($p, $filename));
my $maxsize = 65536;
if ($size > $maxsize) {
$quality = 100;
while (length (MobiPerl::Util::get_gd_image_data ($p, $filename, $quality)) >
$maxsize and $quality >= 0) {
$quality -= 10;
}
if ($quality < 0) {
die "Could not shrink image file size for $filename";
}
}
## if ($y < 640 and $x < 480 and defined $opt_scale) {
## my $scale = $opt_scale;
## $p = MobiPerl::Util::scale_gd_image ($p, $scale);
## print STDERR "Rescaling $$scale\n";
## }
my $data = MobiPerl::Util::get_gd_image_data ($p, $filename, $quality);
return $data;
}
return 1;
Palm/Doc.pm 0000444 0001750 0001750 00000026166 10733026614 012057 0 ustar tompe tompe # Palm::Doc.pm
#
# Palm::PDB helper for handling Palm Doc databases
#
# Copyright (C) 2004 Christophe Beauregard
#
# $Id: Doc.pm,v 1.19 2005/05/12 01:36:49 cpb Exp $
use strict;
package Palm::Doc;
use Palm::PDB;
use Palm::Raw();
use vars qw( $VERSION @ISA );
$VERSION = do { my @r = (q$Revision: 1.19 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
@ISA = qw( Palm::Raw );
use constant DOC_UNCOMPRESSED => scalar 1;
use constant DOC_COMPRESSED => scalar 2;
use constant DOC_RECSIZE => scalar 4096;
=head1 NAME
Palm::Doc - Handler for Palm Doc books
=head1 SYNOPSIS
use Palm::Doc;
=head1 DESCRIPTION
Helper for reading and writing Palm Doc books. The interface is based on
L since it just makes sense. However, because of the nature
of these databases, record-level processing is just a Bad Idea. Use
the C and C calls rather than do direct access of the
C<@records> array.
=head1 EXAMPLES
Convert a text file to a .pdb:
use Palm::Doc;
my $doc = new Palm::Doc;
$doc->textfile( $ARGV[0] );
$doc->Write( $ARGV[0] . ".pdb" );
Convert an HTML file to a .prc:
use HTML::TreeBuilder;
use HTML::FormatText;
use Palm::Doc;
my $tree = HTML::TreeBuilder->new_from_file( $ARGV[0] );
my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 80 );
my $doc = new Palm::Doc;
$doc->{attributes}{resource} = 1;
$doc->text( $formatter->format( $tree ) );
$doc->Write( $ARGV[0] . ".prc" );
=cut
#'
sub import
{
&Palm::PDB::RegisterPDBHandlers( __PACKAGE__, [ "REAd", "TEXt" ], );
&Palm::PDB::RegisterPRCHandlers( __PACKAGE__, [ "REAd", "TEXt" ], );
&Palm::PDB::RegisterPDBHandlers( __PACKAGE__, [ "MOBI", "BOOK" ], );
&Palm::PDB::RegisterPRCHandlers( __PACKAGE__, [ "MOBI", "BOOK" ], );
}
=head2 new
$doc = new Palm::Doc;
Create a new Doc object. By default, it's not a resource database. Setting
C<$self->{attributes}{resource}> to C<1> before any manipulations will
cause it to become a resource database.
=cut
sub new
{
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{'creator'} = 'REAd';
$self->{'type'} = 'TEXt';
$self->{attributes}{resource} = 0;
$self->{appinfo} = undef;
$self->{sort} = undef;
$self->{records} = [];
return $self;
}
# determine if the given (raw) record is a Doc header record and fill in the
# record with appropriate fields if it is.
sub _parse_headerrec($) {
my $record = shift;
return undef unless exists $record->{'data'};
# Doc header is minimum of 16 bytes
return undef if length $record->{'data'} < 16;
my ($version,$spare,$ulen, $records, $recsize, $position)
= unpack( 'n n N n n N', $record->{'data'} );
# the header is followed by a list of record sizes. We don't use
# this since we can guess the sizes pretty easily by looking at
# the actual records.
# According to the spec, $version is either 1 (uncompressed)
# or 2 (compress), while spare is always zero. AportisDoc supposedly sets
# spare to something else, so screw AportisDoc.
return undef if $version != DOC_UNCOMPRESSED and $version != DOC_COMPRESSED;
return undef if $spare != 0;
$record->{'version'} = $version;
$record->{'length'} = $ulen;
$record->{'records'} = $records;
$record->{'recsize'} = $recsize;
$record->{'position'} = $position;
return $record;
}
sub _compress_record($$) {
my ($version,$in) = @_;
return $in if $version == DOC_UNCOMPRESSED;
my $out = '';
my $lin = length $in;
my $i = 0;
while( $i < $lin ) {
# See http://patb.dyndns.org/Programming/PilotDoc.htm for the code type
# taxonomy.
# Try type B compression first.
# If the next 3 to 10 bytes are already in the compressed buffer, we can
# encode them into a 2 byte sequence. Don't bother too close to the ends,
# however... Makes the boundary conditions simpler.
if( $i > 10 and $lin - $i > 10 ) {
my $chunk = '';
my $match = -1;
# the preamble is what'll be in the decoders output buffer.
my $preamble = substr( $in, 0, $i );
for( my $j = 10; $j >= 3; $j -- ) {
$chunk = substr( $in, $i, $j ); # grab next $j characters
$match = rindex( $preamble, $chunk ); # in the output?
# type B code has a 2047 byte sliding window, so matches have to be
# within that range to be useful
last if $match >= 0 and ($i - $match) <= 2047;
$match = -1;
}
my $n = length $chunk;
if( $match >= 0 and $n <= 10 and $n >= 3 ) {
my $m = $i - $match;
# first 2 bits are 10, next 11 are offset, next 3 are length-3
$out .= pack( "n", 0x8000 + (($m<<3)&0x3ff8) + ($n-3) );
$i += $n;
next;
}
}
my $ch = substr( $in, $i ++, 1 );
my $och = ord($ch);
# Try type C compression.
if( $i+1 < $lin and $ch eq ' ' ) {
my $nch = substr( $in, $i, 1 );
my $onch = ord($nch);
if( $onch >= 0x40 and $onch < 0x80 ) {
# space plus ASCII character compression
$out .= chr($onch ^ 0x80);
$i ++;
next;
}
}
if( $och == 0 or ($och >= 9 and $och < 0x80) ) {
# pass through
$out .= $ch;
} else {
# type A code. This is essentially an 'escape' like '\\' in strings.
# For efficiency, it's best to encode as long a sequence as
# possible with one copy. This might seem like it would cause us to miss
# out on a type B sequence, but in actuality keeping long binary strings
# together improves the likelyhood of a later type B sequence than
# interspersing them with x01's.
my $next = substr($in,$i - 1);
if( $next =~ /([\x01-\x08\x80-\xff]{1,8})/o ) {
my $binseq = $1;
$out .= chr(length $binseq);
$out .= $binseq;
$i += length( $binseq ) - 1; # first char, $ch, is already counted
}
}
}
return $out;
}
# algorithm taken from makedoc7.cpp with reference to
# http://patb.dyndns.org/Programming/PilotDoc.htm and
# http://www.pyrite.org/doc_format.html
sub _decompress_record($$) {
my ($version,$in) = @_;
return $in if $version == DOC_UNCOMPRESSED;
my $out = '';
my $lin = length $in;
my $i = 0;
while( $i < $lin ) {
my $ch = substr( $in, $i ++, 1 );
my $och = ord($ch);
if( $och >= 1 and $och <= 8 ) {
# copy this many bytes... basically a way to 'escape' data
$out .= substr( $in, $i, $och );
$i += $och;
} elsif( $och < 0x80 ) {
# pass through 0, 9-0x7f
$out .= $ch;
} elsif( $och >= 0xc0 ) {
# 0xc0-0xff are 'space' plus ASCII char
$out .= ' ';
$out .= chr($och ^ 0x80);
} else {
# 0x80-0xbf is sequence from already decompressed buffer
my $nch = substr( $in, $i ++, 1 );
$och = ($och << 8) + ord($nch);
my $m = ($och & 0x3fff) >> 3;
my $n = ($och & 0x7) + 3;
# This isn't very perl-like, but a simple
# substr($out,$lo-$m,$n) doesn't work.
my $lo = length $out;
for( my $j = 0; $j < $n; $j ++, $lo ++ ) {
die "bad Doc compression" unless ($lo-$m) >= 0;
$out .= substr( $out, $lo-$m, 1 );
}
}
}
return $out;
}
sub Write {
my $self = shift;
my $prc = $self->{attributes}{resource};
my $recs = $prc ? $self->{'resources'} : $self->{'records'};
my $header = $recs->[0];
unless( defined _parse_headerrec($header) ) {
die "@_: Doesn't appear to be a correct book...";
}
$self->SUPER::Write(@_);
}
=head2 text
$text = $doc->text;
Return the contents of the Doc database.
$text = $doc->text( @text );
Set the contents of the Doc book to the specified arguments. All the list arguments
will simply be concatenated together.
=cut
sub text {
my $self = shift;
my $body = '';
my $prc = $self->{attributes}{resource};
if( @_ > 0 ) {
$body = join( '', @_ );
my $version = DOC_COMPRESSED;
$self->{'records'} = [];
$self->{'resources'} = [];
# first record is the header
my $header = $prc ? $self->append_Resource() : $self->append_Record();
$header->{'version'} = $version;
$header->{'length'} = 0;
$header->{'records'} = 0;
$header->{'recsize'} = DOC_RECSIZE;
# break the document into record-sized chunks
for( my $i = 0; $i < length($body); $i += DOC_RECSIZE ) {
my $record = $prc ? $self->append_Resource : $self->append_Record;
my $chunk = substr($body,$i,DOC_RECSIZE);
$record->{'data'} = _compress_record( $version, $chunk );
$header->{'records'} ++;
$header->{'length'} += length $body;
}
$header->{'recsize'} = $header->{'length'}
if $header->{'length'} < DOC_RECSIZE;
# pack up the header
$header->{'data'} = pack( 'n xx N n n N',
$header->{'version'}, $header->{'length'},
$header->{'records'}, $header->{'recsize'}, 0 );
} elsif( defined wantarray ) {
my $recs = $prc ? $self->{'resources'} : $self->{'records'};
my $header = $recs->[0];
if( defined _parse_headerrec($header) ) {
# a proper Doc file should be fine, but if it's not Doc
# compression like some Mobi docs seem to be we want to
# bail early. Otherwise we end up with a huge stream of
# substr() errors and we _still_ don't get any content.
eval {
sub min { return ($_[0]<$_[1]) ? $_[0] : $_[1] }
my $maxi = min($#$recs, $header->{'records'});
for( my $i = 1; $i <= $maxi; $i ++ ) {
$body .= _decompress_record( $header->{'version'},
$recs->[$i]->{'data'} );
}
};
return undef if $@;
}
}
return $body;
}
=head2 textfile
$doc->textfile( "README.txt" );
Set the contents of the Doc to the contents of the file and sets the name of the PDB to
the specified filename.
=cut
sub textfile($$) {
my ($self, $filename) = @_;
open IN, "< $filename" or return undef;
binmode IN;
$self->text( '', );
close IN;
$self->{'name'} = $filename;
}
1;
__END__
=head1 BUGS
Bookmarks are unsupported. I've never had any use for them.
Output databases are always compressed and there's no option to
disable compression. I consider this a feature, to be honest.
=head2 Note On Character Sets
L doesn't do anything with character sets. This might be a bug,
depending on how you feel about this kind of thing, but the reality is that
we're generally converting between text and Doc files, neither of which are
real great at telling us what encoding we're supposed to use.
My understanding of PalmOS character sets is that Doc books should be
encoded in either Windows Code Page 1252 or, for Japanese, 932. Actually,
the PalmOS encoding is a small variation on those. In practice, ISO 8859-1
works okay for western languages which is real nice because L
doesn't know about the PalmOS stuff.
This gist of all this is that when you're creating a L, you may
need to do something along the lines of:
use Encode 'from_to';
my $text = read_my_text();
from_to( $text, $charset, 'iso-8859-1' ) unless $charset =~ /8859-1$/;
my $doc = new Palm::Doc();
$doc->text( $text );
And when you're reading a L and you care about the character
set, you're pretty much going to have to guess the encoding and act
appropriately:
use Encode 'decode';
my $doc = new Palm::PDB;
$doc->Load( $pdbname );
my $text = decode("iso-8859-1", $doc->text());
=head1 AUTHOR
Christophe Beauregard Ecpb@cpan.orgE
=head1 SEE ALSO
L
L
makedoc
L
L
L is another CPAN module for handling Doc databases,
but doesn't use L and doesn't handle reading Docs.
L for details on PalmOS
text encoding
=cut
gpl-3.0.txt 0000644 0001750 0001750 00000104513 10722600625 011735 0 ustar tompe tompe GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
Makefile 0000644 0001750 0001750 00000004551 10735530214 011555 0 ustar tompe tompe
TARFILE = mobiperl-0.0.18.tar
FILES = mobi2html html2mobi lit2mobi \
mobi2mobi opf2mobi \
MobiPerl/Config.pm \
MobiPerl/EXTH.pm \
MobiPerl/LinksInfo.pm \
MobiPerl/MobiFile.pm \
MobiPerl/MobiHeader.pm \
MobiPerl/Opf.pm \
MobiPerl/Util.pm \
Palm/Doc.pm \
gpl-3.0.txt \
Makefile
dist:
tar cvf $(TARFILE) $(FILES)
pod2html mobi2mobi > html/mobi2mobi.html
pod2html mobi2html > html/mobi2html.html
pod2html lit2mobi > html/lit2mobi.html
pod2html opf2mobi > html/opf2mobi.html
pod2html html2mobi > html/html2mobi.html
copy:
scp $(TARFILE) remote.ida.liu.se:www-pub/mobiperl/
scp html/*.html remote.ida.liu.se:www-pub/mobiperl/
copyhtml:
scp html/*.html remote.ida.liu.se:www-pub/mobiperl/
hm:
pp -M FindBin -M Palm::PDB -M Palm::Doc -M Date::Format -M Getopt::Mixed -M Image::Size -M MobiPerl::MobiHeader -M MobiPerl::MobiFile -M MobiPerl::Opf -M MobiPerl::Config -M MobiPerl::LinksInfo -M XML::Parser::Lite::Tree -M Data::Dumper -M GD -M HTML::TreeBuilder -o html2mobi.exe html2mobi
copy html2mobi.exe c:\Perlb820\bin\
om:
pp -M FindBin -M Palm::PDB -M Palm::Doc -M Date::Format -M Getopt::Mixed -M Image::Size -M MobiPerl::MobiHeader -M MobiPerl::MobiFile -M MobiPerl::Opf -M MobiPerl::Config -M MobiPerl::LinksInfo -M XML::Parser::Lite::Tree -M Data::Dumper -M GD -M HTML::TreeBuilder -o opf2mobi.exe opf2mobi
copy opf2mobi.exe c:\Perlb820\bin\
lm:
pp -M FindBin -M Palm::PDB -M Palm::Doc -M Date::Format -M Getopt::Mixed -M Image::Size -M MobiPerl::MobiHeader -M MobiPerl::MobiFile -M MobiPerl::Opf -M MobiPerl::Config -M MobiPerl::LinksInfo -M XML::Parser::Lite::Tree -M Data::Dumper -M GD -M HTML::TreeBuilder -o lit2mobi.exe lit2mobi
copy lit2mobi.exe c:\Perlb820\bin\
mm:
pp -M FindBin -M Palm::PDB -M Palm::Doc -M Date::Format -M Getopt::Mixed -M Image::Size -M MobiPerl::MobiHeader -M MobiPerl::MobiFile -M MobiPerl::Opf -M MobiPerl::Config -M MobiPerl::LinksInfo -o mobi2mobi.exe mobi2mobi
copy mobi2mobi.exe c:\Perlb820\bin\
mh:
pp -M FindBin -M Palm::PDB -M Palm::Doc -M Date::Format -M Date::Parse -M Getopt::Mixed -M Image::Size -M MobiPerl::MobiHeader -M MobiPerl::MobiFile -M MobiPerl::Opf -M MobiPerl::Config -M MobiPerl::LinksInfo -o mobi2html.exe mobi2html
copy mobi2html.exe c:\Perlb820\bin\
all: hm om lm mm mh
pack:
"c:\Program Files\WinRAR\rar" a mobiperl-0.0.17-win.rar html2mobi.exe opf2mobi.exe lit2mobi.exe mobi2mobi.exe mobi2html.exe