Skip to content

Instantly share code, notes, and snippets.

@gonter
Last active August 29, 2015 14:03
Show Gist options
  • Save gonter/9cbb3e2826d6d5583fee to your computer and use it in GitHub Desktop.
Save gonter/9cbb3e2826d6d5583fee to your computer and use it in GitHub Desktop.
missing POD for PDA::Pilot

While pilot-link.org may be dead now, my Palm T5 is certainly not the only surviving device for which someone still uses that software. The CVS repository doesn’t seem to have been stashed away in time and other pieces of information are missing, but some items are still out there and should be preserved.

TODO

  • [_] collect links to current sources
    • [_] maybe re-create a version controlled repository
  • [_] fix the documentation
  • [_] collect example code or code that actually someone uses
creator type application notes
npad DATA notepad raw contains structure with embedded PNG image
#!/usr/bin/perl
# $Id: palm.pl,v 1.3 2014/07/13 18:57:26 gonter Exp $
=head1 NAME
dummy script doing nothing
=cut
use strict;
use PDA::Pilot;
use Data::Dumper;
$Data::Dumper::Indent= 1;
# use Module;
my $x_flag= 0;
my @PARS;
my $arg;
while (defined ($arg= shift (@ARGV)))
{
print "arg=[$arg]\n";
if ($arg eq '--') { push (@PARS, @ARGV); @ARGV= (); }
elsif ($arg =~ /^--(.+)/)
{
my ($opt, $val)= split ('=', $1, 2);
if ($opt eq 'help') { usage(); }
else { usage(); }
}
elsif ($arg =~ /^-(.+)/)
{
foreach my $opt (split ('', $1))
{
if ($opt eq 'h') { usage(); exit (0); }
elsif ($opt eq 'x') { $x_flag= 1; }
else { usage(); }
}
}
else
{
push (@PARS, $arg);
}
}
while (defined ($arg= shift (@PARS)))
{
&main_function ($arg);
}
exit (0);
sub usage
{
print <<EOX;
usage: $0 [-opts] pars
options:
-h ... help
-x ... set x flag
-- ... remaining args are parameters
EOX
}
# ----------------------------------------------------------------------------
sub main_function
{
my $fnm= shift;
print "fnm=[$fnm]\n";
my $f= PDA::Pilot::File::open ($fnm);
print "f: ", Dumper ($f);
my $info= $f->getDBInfo();
my ($is_res, $creator, $type)= map { $info->{$_} } qw(flagResource creator type);
my $is_strange= 0;
printf ("main_function: %s %s (res=%d) %s\n", $creator, $type, $is_res, $fnm);
if ($creator eq 'MOBI')
{ # at least my files which originate from Mobi Creator are somewhat strange
$is_strange= 1;
print "MOBI files are strange, please check carefully\n";
}
print "info: ", Dumper ($info);
# if ($creator eq 'memo' || $creator eq 'PDat')
unless ($is_res)
{
dump_db($f);
}
}
sub dump_db
{
my $f= shift;
my $records= $f->getRecords();
print "records=[$records]\n";
for (my $i= 0; $i < $records; $i++)
{
print '='x72, "\n";
print "Record [$i]\n";
my $rec= $f->getRecord($i);
print "rec=[$rec] ", Dumper ($rec);
if (exists ($rec->{'raw'}))
{
print '-'x64, "\nraw:\n";
hex_dump ($rec->{'raw'});
}
print '='x72, "\n\n";
}
}
# ----------------------------------------------------------------------------
sub hex_dump
{
my $data= shift;
local *FX= shift || *STDOUT;
my $off= 0;
my ($i, $c, $v);
while ($data)
{
my $char= '';
my $hex= '';
my $offx= sprintf ('%08X', $off);
$off += 0x10;
for ($i= 0; $i < 16; $i++)
{
$c= substr ($data, 0, 1);
if ($c ne '')
{
$data= substr ($data, 1);
$v= unpack ('C', $c);
$c= '.' if ($v < 0x20 || $v >= 0x7F);
$char .= $c;
$hex .= sprintf (' %02X', $v);
}
else
{
$char .= ' ';
$hex .= ' ';
}
}
print FX "$offx $hex |$char|\n";
}
}
__END__
=head1 AUTHOR
Gerhard Gonter <[email protected]>

NAME

PDA::Pilot

DESCRIPTION

As the beginning of PDA::Pilot from pilot-link says, the documentation there might be misleading. This is true. This file is an attempt to fix parts of it....

SYNOPSIS

my $f= PDA::Pilot::File::open($fnm);
my $info= $f->getDBInfo();

my $records= $f->getRecords();
for (my $i= 0; $i < $records; $i++)
{
  my $rec= $f->getRecord($i);
}
 

METHODS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment