Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit 7a8a505535c2ff4dc2af859d2c1a63ff6f8de609 @adamsanderson committed Jul 7, 2010
@@ -0,0 +1,7 @@
+0.0.1 - Initial Release
+
+0.0.3 - Minor bug fixes
+
+0.0.4 - Fixed some really silly binary issues,
+ where I was using platform specific endian encoding.
+ - Added some more unit tests to make myself feel better.
No changes.
@@ -0,0 +1,21 @@
+CHANGELOG.txt
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+lib/palm.rb
+lib/palm/palm_record.rb
+lib/palm/palm_support.rb
+lib/palm/pdb.rb
+lib/palm/raw_record.rb
+lib/palm/version.rb
+lib/palm/waba_db.rb
+lib/palm/waba_io.rb
+lib/palm/waba_record.rb
+setup.rb
+test/HovData.pdb
+test/pdb_test.rb
+test/test_helper.rb
+test/waba_db_test.rb
+test/waba_io_test.rb
+test/waba_records_test.rb
@@ -0,0 +1,40 @@
+= Palm
+The palm library is a pure ruby library for reading and writing Palm PDB
+databases. This library is based off of Andrew Arensburger's pdb.pm.
+
+ Adam Sanderson, 2006
+ netghost@gmail.com
+
+= Usage
+Here is a sample that reads through and prints some metadata.
+ pdb = Palm::PDB.new('palm_db.pdb')
+ puts pdb.name
+ puts "Creator #{pdb.creator} / Type #{pdb.type}"
+ puts "There are #{pdb.data.length} records."
+
+Here is an example of adding and removing records:
+ pdb = Palm::PDB.new('palm_db.pdb')
+ #Remove the last record
+ last_record = pdb.data.pop
+ #Append a new fake record
+ pdb.data << Palm::RawRecord.new("This would be binary data")
+ pdb.write_file('new_palm_db.pdb')
+
+= Extending
+The base Palm::PDB will read and write raw PDB files. Their binary data is
+maintained in each record. This is probably not very useful for most cases, but
+will allow access to all the common metadata.
+
+To create a more specific implementation, you should override pack_entry and
+unpack_entry to handle specific record types. See Palm::WabaDB for an example
+implementation supporting Waba format PDBs.
+
+= Plans I am not entirely sold on the current API, a lot of the structure of
+the code is based on Andrew Arensburger's perl code, which doesn't make for
+great ruby code. Where possible I have tried to make the code simpler, but some
+perly bits show through. So the API might change a little, I would really
+appreciate some input.
+
+I personally have no need for reading and writing the Palm Todo Lists,
+Calendars, Notes, and so forth, however if there is sufficient interest, it
+might be fun to add.
@@ -0,0 +1,50 @@
+require 'rubygems'
+require 'rake'
+require 'rake/clean'
+require 'rake/testtask'
+require 'rake/packagetask'
+require 'rake/gempackagetask'
+require 'rake/rdoctask'
+require 'rake/contrib/rubyforgepublisher'
+require 'fileutils'
+require 'hoe'
+include FileUtils
+require File.join(File.dirname(__FILE__), 'lib', 'palm', 'version')
+
+AUTHOR = "Adam Sanderson"
+EMAIL = "netghost@u.washington.edu"
+DESCRIPTION = "Pure Ruby library for reading and writing Palm PDB databases."
+GEM_NAME = "palm"
+RUBYFORGE_PROJECT = "palm"
+HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
+RELEASE_TYPES = %w( gem tar ) # can use: gem, tar, zip
+
+
+NAME = "palm"
+REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
+VERS = ENV['VERSION'] || (Palm::VERSION::STRING + (REV ? ".#{REV}" : ""))
+CLEAN.include ['**/.*.sw?', '*.gem', '.config']
+RDOC_OPTS = ['--quiet', '--title', "palm documentation",
+ "--opname", "index.html",
+ "--line-numbers",
+ "--main", "README",
+ "--inline-source"]
+
+# Generate all the Rake tasks
+# Run 'rake -T' to see list of generated tasks (from gem root directory)
+hoe = Hoe.new(GEM_NAME, VERS) do |p|
+ p.author = AUTHOR
+ p.description = DESCRIPTION
+ p.email = EMAIL
+ p.summary = DESCRIPTION
+ p.url = HOMEPATH
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
+ p.test_globs = ["test/**/*_test.rb"]
+ p.clean_globs = CLEAN #An array of file patterns to delete on clean.
+
+ # == Optional
+ #p.changes - A description of the release's latest changes.
+ #p.extra_deps - An array of rubygem dependencies.
+ #p.spec_extras - A hash of extra values to set in the gemspec.
+end
+
@@ -0,0 +1 @@
+Dir[File.join(File.dirname(__FILE__), 'palm/**/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,62 @@
+module Palm
+ # Base class for all Palm::PDB Records. This stores the basic metadata for each
+ # record. Subclasses should extend this provide a useful interface for accessing
+ # specific record types.
+ class Record
+ RECORD_ATTRIBUTE_CODES = {
+ :expunged => 0x80,
+ :dirty => 0x40,
+ :deleted => 0x20,
+ :private => 0x10
+ }
+
+ attr_accessor :expunged, :dirty, :deleted, :private, :archive
+ attr_accessor :record_id, :category
+
+ def initialize
+ @category = 0
+ @record_id = 0
+ @dirty = true
+ end
+
+ def packed_attributes
+ encoded = 0
+ if @expunged or @deleted
+ encoded |= 0x08 if @archive
+ else
+ encoded = @category & 0x0f
+ end
+
+ RECORD_ATTRIBUTE_CODES.each do |name,code|
+ encoded |= code if send(name)
+ end
+
+ encoded
+ end
+
+ def packed_attributes=(value)
+ RECORD_ATTRIBUTE_CODES.each do |key,code|
+ self.send("#{key}=", (value & code) > 0)
+ end
+ if (value & 0xa0) == 0
+ @category = (value & 0x0f)
+ else
+ @archive = (value & 0x08) > 0
+ end
+ end
+
+ end
+
+ # Base class for all Palm::PDB Resources. This stores the basic metadata for each
+ # record. Subclasses should extend this provide a useful interface for accessing
+ # specific record types.
+ class Resource
+ attr_accessor :record_type, :record_id
+ def intialize
+ @record_type = "\0\0\0\0"
+ @record_id = 0
+ end
+
+ end
+
+end
@@ -0,0 +1,12 @@
+# Class extensions for making palm data easier to work with
+class Time
+ EPOC_1904 = 2082844800 # Difference between Palm's epoch
+
+ def to_palm_seconds
+ to_i + EPOC_1904
+ end
+
+ def self.at_palm_seconds(seconds)
+ at(seconds - EPOC_1904)
+ end
+end
Oops, something went wrong.

0 comments on commit 7a8a505

Please sign in to comment.