/** * Simple program to convert Palm Fuel Log data into csv files. * This program has been tested data from an IBM C3 (Palm Vx) * with Fuel Log 1.0. * * License: Do whatever you want. * * Warranty: No warranty. None. Nil. * * Build: * javac FuelLog.java * jar cvf fuellog.jar *.class * Usage: * java -cp fuellog.jar FuelLog fuelLogDB.PDB * * Alternate Build: * javac FuelLog.java * Alternate Usage: * java -cp . FuelLog fuelLogDB.PDB */ import java.io.*; import java.nio.*; import java.nio.channels.*; import java.util.*; public class FuelLog { public static void main(String []argv) throws Exception { if (argv.length < 1) { System.out.println("Usage: java -cp . FuelLog [filename]"); } FileInputStream input = new FileInputStream(argv[0]); FileChannel channel = input.getChannel(); int fileLength = (int)channel.size(); MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength); int n = buffer.getShort(76); ArrayList offsets = new ArrayList(n); ArrayList cats = new ArrayList(n); for(int i=0; i 16) ncars = 16; where += 2; ArrayList carNames = new ArrayList(16); Map> entries = new HashMap>(16); for(int i=0; i<16; ++i) { String s = getCString(buffer, where + 16*i).trim(); carNames.add(s); entries.put(i, new ArrayList()); } where += 16*16 + 22; int dfuel, dprice, dodometer; dfuel = buffer.getShort(where); dprice = buffer.getShort(where + 2); dodometer = buffer.getShort(where + 4); where += 6; for(int i=0; i list = entries.get(i); if (list.size() == 0) continue; String out = carNames.get(i) + ".csv"; PrintStream printer = new PrintStream(new FileOutputStream(out)); printer.print("date, odometer, volume, cost, full\n"); for(int j=0; j> 5; month = d & 15; year = ((d >> 4) & 127 ) + 1904; } } static String getCString(ByteBuffer b, int i) { byte c = 127; String s = ""; for(int j=0; j<16 && c != 0; ++j) { c = b.get(i + j); if (c == 0) break; s = s + (char)(c & 0xFF); } return s; } }