Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
HandX makes IMHO a great utility: webLog, which allows you to enter your weblog entries on your Palm device. The program is, unfortunately, only supporting Windows as host.
This snippet parses the database file (weblog_hXwl.pdb) and just writes them to a file (or STDOUT). It is easily modified to be used directly for websites, etc.

-- JaWi

#!/usr/bin/perl -w use strict; my ( @categories, @record_attributes ); my ( $input, $output ); die usage() unless defined $ARGV[ 0 ] && -e $ARGV[ 0 ]; $input = $ARGV[ 0 ] if ( -e $ARGV[ 0 ] ); if ( defined $ARGV[ 1 ] ) { print STDERR "Warning: overwriting '$ARGV[1]'!\n" if ( -e $ARGV[ 1 ] + ); $output = $ARGV[ 1 ]; } parse_pdb( $input, $output ); sub usage { return "$0 v1.0 - WebLog database parser.\n". "(C) 2002 - J.W. Janssen, janwillem.janssen\@lxtreme.nl\n\n". "usage: $0 <weblog_hXwl.pdb> [<output file>]\n"; } # usage sub parse_pdb { my $name = shift; my $output = shift; # Obtain the necessary header information open PDB, "<$name" || die "Couldn't open '$name'"; binmode PDB; my $line; read( PDB, $line, 78 ); my @header = unpack "A32nnN6A4A4NNn", $line; # Read & parse the record entry headers... my @offsets; # The record entry headers start immediatly after the header # of the PDB file (offset 78). seek( PDB, 78, 0 ); # The header gives us the amount of entries in the PDB file. for ( 0..$header[ 13 ] ) { read( PDB, $line, 8 ); # Entry record: # name | # | description # ----------+---+---------------------- # offset | 0 | the entry file offset # attribute | 1 | the upper 4 bits denote the record # | | attribute, and the lower 4 the # | | category. # uniqueID | 2 | unknown; should be zero. my @record_list = unpack "NC4", $line; # Category == unknown my $category = $record_list[ 1 ] & 0x0F; # Attribute == 0x10: secret record bit # 0x20: busy bit (in use) # 0x40: dirty bit # 0x80: delete on next sync my $attribute = $record_list[ 1 ] & 0xF0; push @offsets, $record_list[ 0 ]; push @record_attributes, $attribute; } # Make sure the last offset is the filesize... $offsets[ -1 ] = int( -s $name ); # Open our output channel ... if ( defined $output and $output ne "-" ) { open OUT, ">$output" || die "Couldn't open '$output' for writing!" +; } else { open OUT, ">&STDOUT"; } # Converting from Palm date format <-> UNIX format: # number of days between # 01/01/1904 and 01/01/1970: 24,107 # number of seconds in one day: 86,400 * # --------------- # number of seconds between # 01/01/1904 and 01/01/1940: 2,082,844,800 my $diff_secs = 24107*86400; print OUT "Last modified on: " . gmtime( $header[ 4 ] - $diff_secs ) + . "\n"; # Read as many entries... for ( 0..$header[ 13 ] - 1 ) { my $offset = $offsets[ $_ ]; my $rec_length = $offsets[ $_ + 1 ] - $offset; seek( PDB, $offset, 0 ); read( PDB, $line, $rec_length ); # Record format for WebLog: # name | # | length | description # -----------+---+---------+------------------------------------ # record idx | 0 | 2 bytes | the logical entry number. # ? | 1 | 2 bytes | unknown # entry date | 2 | 4 bytes | number of seconds since 01/01/1904, # entry text | 3 | ? bytes | the actual entry... my ( $index, $unknown, $date, $text ) = unpack "nnNa*", $line; my $hidden = ( $record_attributes[ $_ ] & 0x10 ) ? 1 : 0; print OUT "($index, $hidden) " . gmtime( $date - $diff_secs ) . " - " . $text . "\n"; } close OUT; close PDB; } # parse_pdb

In reply to HandX weblog parser by JaWi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-04-19 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found