| PALMFILE(2) | System Calls Manual | PALMFILE(2) |
Palmfile: Categories, DBInfo, Doc, Entry, Pfile, Record - read Palm™ file formats
include "bufio.m";
include "palmfile.m";
palmfile := load Palmfile Palmfile->PATH;
Pfile: adt {
fname: string;
appinfo: array of byte;
sortinfo: array of int;
entries: array of ref Entry;
open: fn(name: string, mode: int): (ref Pfile, string);
close: fn(pf: self ref Pfile): int;
read: fn(pf: self ref Pfile, index: int): (ref Record, string);
stat: fn(pf: self ref Pfile): ref DBInfo;
};
DBInfo: adt {
name: string; # database name on Palm
attr: int; # file attributes (defined below)
dtype: string; # database type (byte[4])
version: int; # version of data layout, defined by application
creator: string; # creating application (byte[4])
ctime: int; # creation time
mtime: int; # modification time
btime: int; # last backup
modno: int; # modification number
uidseed: int; # unique record ID seed
new: fn(name: string, attr: int, dtype: string,
version: int, creator: string): ref DBInfo;
};
Entry: adt {
id: int; # resource: id; record: unique ID
offset: int; # offset in file
size: int; # size in bytes
name: int; # resource entry only
attr: int; # record entry only
};
Record: adt {
id: int; # resource: ID; data: unique record ID
index: int; # record index (origin 0)
name: int; # byte[4]: resource record only
attr: int; # attributes, defined below, data record only
cat: int; # category, data record only
data: array of byte; # content of record
};
Categories: adt {
renamed: int; # which categories have been renamed
labels: array of string; # category names
uids: array of int; # corresponding unique IDs
lastuid: int; # last unique ID assigned
appdata: array of byte; # remaining application-specific data
new: fn(labels: array of string): ref Categories;
unpack: fn(a: array of byte): ref Categories;
pack: fn(c: self ref Categories): array of byte;
};
Doc: adt {
version: int;
length: int; # uncompressed
nrec: int; # text records only
recsize: int; # uncompressed
position: int;
sizes: array of int; # sizes of uncompressed records
open: fn(file: ref Pfile): (ref Doc, string);
read: fn(doc: self ref Doc, i: int): (string, string);
iscompressed: fn(doc: self ref Doc): int;
unpacktext: fn(doc: self ref Doc, a: array of byte):
(string, string);
textlength: fn(doc: self ref Doc, a: array of byte): int;
};
init: fn(): string;
filename: fn(s: string): string;
dbname: fn(s: string): string;
gets: fn(a: array of byte): string;
puts: fn(a: array of byte, s: string);
get2: fn(a: array of byte): int;
get3: fn(a: array of byte): int;
get4: fn(a: array of byte): int;
put2: fn(a: array of byte, v: int);
put3: fn(a: array of byte, v: int);
put4: fn(a: array of byte, v: int);
Palmfile provides read-only access to files in the Palm™ database and document formats. It currently handles three types of files: Palm Database (.pdb) files, which store data for applications; Palm Resource (.prc) files, which store code resources and user interface resource elements; and Palm Doc (.doc) files, which store compressed documents for the Palm document and e-book readers. Database and resource files have a similar structure, with slight differences in representation, and differing mainly in how the contents are used.
Init must be called before any other function in the file. It returns a diagnostic if it cannot initialise the module.
Pfile represents an open Palm file of any type:
DBInfo gives the database information for a file:
In some applications, it is useful to use a data base name (ie, DBInfo.name) as a component of an Inferno file name. The device allows space and slash characters in names, though, which makes it hard to use the name directly. Filename maps each space character in s to U+00A0 (unpaddable space) and each slash character to U+2215 (`division /'), and returns the result. Dbname maps the other way.
Each record in the file is represented by an Entry in memory, which holds the record's essential attributes, leaving the data on file. The meaning of some of the elements depends on whether the file is a data file or a resource file.
Records read from the file are represented by a Record adt containing its data and associated values. Some fields are valid only for particular classes of records.
The contents of both the ``application information'' and ``sort information'' sections of the file are defined by an application in general. Even so, both have conventional uses with many Palm applications. The Palm software often assigns data records to particular categories (eg, ``Business'' or ``Personal''), and stores up to 16 category names and IDs in the application data in a fixed format (possibly followed by further data that is application specific). This is represented by an instance of Categories, which provides the following:
Binary data in Palm files is typically encoded in big-endian form. Palmfile functions account for that internally, but some Palm applications might use big-endian data in their own data records. Several functions are therefore provided to decode and encode big-endian data: getn retrieves an integer from the first n bytes of array a; putn stores a big-endian representation of the value v in the first n bytes of array a.
Strings are stored in fixed-length arrays of bytes, always terminated by a zero byte. The character encoding is (apparently) Latin-1 (ISO 8859-1), not UTF-8, so functions gets and puts are provided to convert between that representation and a Limbo string.
Doc provides read-only access to Palm documents and (unencrypted) e-books:
Most document-reading applications require only Doc.open and Doc.read, and perhaps Doc.length to guide the construction of scroll bars (for instance).
/appl/lib/palmfile.b
Palm® File Format Specification, Gary Hillerson,
Palm Inc., Document Number 3008-004, 1 May 2001.
[Palm®] standard text document file format, Paul Lucas, 18
August 1998.