1Palm: module { 2 3 # 4 # basic Palm data types 5 # 6 7 PATH: con "/dis/lib/palm.dis"; 8 9 DBInfo: adt { 10 name: string; 11 attr: int; 12 dtype: string; # database type (byte[4]) 13 version: int; # defined by application 14 creator: string; # creating application (byte[4]) 15 ctime: int; 16 mtime: int; 17 btime: int; # last backup 18 modno: int; # modification number: set to zero 19 uidseed: int; # unique record ID seed (unused, set to zero) 20 21 # the following is used by the database access protocol 22 index: int; 23 24 new: fn(name: string, attr: int, dtype: string, version: int, creator: string): ref DBInfo; 25 }; 26 27 # file attributes: 28 29 Fresource: con 1<<0; # file is .prc not .pdb 30 Fronly: con 1<<1; # read only 31 Fappinfodirty: con 1<<2; 32 Fbackup: con 1<<3; # no conduit exists 33 Foverwrite: con 1<<4; # overwrite older copy if present 34 Freset: con 1<<5; # reset after installation 35 Fprivate: con 1<<6; # don't allow copy of this to be beamed 36 Fstream: con 1<<7; # file is an array of bytes, not a database 37 38 # extended (misc) attributes for Desklink->ReadDBList 39 Fnosync: con (1<<7)<<16; 40 Frambased: con (1<<6)<<16; 41 42 Noindex: con 16rFFFF; # unknown index 43 44 Record: adt { 45 id: int; # unique record ID (24 bits) 46 attr: int; # record attributes 47 cat: int; # category 48 data: array of byte; 49 50 new: fn(id: int, attr: int, cat: int, size: int): ref Record; 51 }; 52 53 # Record.attr values: 54 55 Rdelete: con 16r80; # delete next sync 56 Rdirty: con 16r40; # record modified 57 Rinuse: con 16r20; # record in use 58 Rsecret: con 16r10; # record is secret 59 Rarchive: con 16r08; # archive next sync 60 Rmcat: con 16r0F; # mask for category field in Palmdb->Entry.attrs 61 62 Resource: adt { 63 name: int; # byte[4]: resource name or type 64 id: int; # resource ID (16 bits) 65 data: array of byte; 66 67 new: fn(name: int, id: int, size: int): ref Resource; 68 }; 69 70 # common form of category data in appinfo 71 Categories: adt { 72 renamed: int; # which categories have been renamed 73 labels: array of string; # 16 category names 74 uids: array of int; # corresponding unique IDs 75 lastuid: int; # last unique ID assigned 76 appdata: array of byte; # remaining data is application-specific 77 78 new: fn(labels: array of string): ref Categories; 79 unpack: fn(a: array of byte): ref Categories; 80 pack: fn(c: self ref Categories): array of byte; 81 mkidmap: fn(c: self ref Categories): array of int; 82 }; 83 84 Doc: adt { 85 m: Palmdb; 86 file: ref Palmdb->PDB; 87 version: int; 88 length: int; # uncompressed 89 nrec: int; # text records only 90 recsize: int; # uncompressed 91 position: int; 92 sizes: array of int; # sizes of uncompressed records 93 94 open: fn(m: Palmdb, file: ref Palmdb->PDB): (ref Doc, string); 95 read: fn(nil: self ref Doc, i: int): (string, string); 96 iscompressed: fn(nil: self ref Doc): int; 97 unpacktext: fn(d: self ref Doc, a: array of byte): (string, string); 98 textlength: fn(d: self ref Doc, a: array of byte): int; 99 }; 100 101 init: fn(): string; 102 103 # name mapping 104 filename: fn(s: string): string; 105 dbname: fn(s: string): string; 106 107 # convert between resource/application ID and string 108 id2s: fn(id: int): string; 109 s2id: fn(s: string): int; 110 111 # time conversion 112 pilot2epoch: fn(t: int): int; 113 epoch2pilot: fn(t: int): int; 114 115 # Latin-1 to string conversion 116 gets: fn(a: array of byte): string; 117 puts: fn(a: array of byte, s: string); 118 119 # big-endian conversion 120 get2: fn(a: array of byte): int; 121 get3: fn(a: array of byte): int; 122 get4: fn(a: array of byte): int; 123 put2: fn(a: array of byte, v: int); 124 put3: fn(a: array of byte, v: int); 125 put4: fn(a: array of byte, v: int); 126 127 # argument wrapping for Desklink and CMP 2.x 128 ArgIDbase: con 16r20; # first argument ID 129 argsize: fn(args: array of (int, array of byte)): int; 130 packargs: fn(out: array of byte, args: array of (int, array of byte)): array of byte; 131 unpackargs: fn(argc: int, reply: array of byte): (array of (int, array of byte), string); 132 133}; 134 135Palmdb: module { 136 137 PATH: con "/dis/lib/palmdb.dis"; 138 139 DB: adt { 140 x: int; # instance index, used internally 141 142 mode: int; 143 attr: int; # essential database attributes 144 145 open: fn(nil: string, mode: int): (ref DB, string); 146 create: fn(nil: string, mode: int, perm: int, nil: ref Palm->DBInfo): (ref DB, string); 147 close: fn(nil: self ref DB): string; 148 149 stat: fn(nil: self ref DB): ref Palm->DBInfo; 150 wstat: fn(nil: self ref DB, nil: ref Palm->DBInfo, flags: int); 151 152 rdappinfo: fn(nil: self ref DB): (array of byte, string); 153 wrappinfo: fn(nil: self ref DB, nil: array of byte): string; 154 155 rdsortinfo: fn(nil: self ref DB): (array of int, string); 156 wrsortinfo: fn(nil: self ref DB, nil: array of int): string; 157 158 readidlist: fn(nil: self ref DB, sort: int): array of int; 159 nentries: fn(nil: self ref DB): int; 160 resetsyncflags: fn(nil: self ref DB): string; 161 162 records: fn(nil: self ref DB): ref PDB; 163 resources: fn(nil: self ref DB): ref PRC; 164 }; 165 166 # database files (.pdb, .doc, and most others) 167 PDB: adt { 168 db: ref DB; 169 170 read: fn(nil: self ref PDB, index: int): ref Palm->Record; 171 readid: fn(nil: self ref PDB, id: int): (ref Palm->Record, int); 172 173 resetnext: fn(nil: self ref PDB): int; 174 readnextmod: fn(nil: self ref PDB): (ref Palm->Record, int); 175# DLP 1.1 functions: 176# readnextincat(nil: self ref DB, cat: int): (ref Palm->Record, string); 177# readnextmodincat(nil: self ref DB, cat: int): (ref Palm->Record, string); 178 179 write: fn(nil: self ref PDB, r: ref Palm->Record): string; 180 181 truncate: fn(nil: self ref PDB): string; 182 delete: fn(nil: self ref PDB, id: int): string; 183 deletecat: fn(nil: self ref PDB, cat: int): string; 184 purge: fn(nil: self ref PDB): string; 185 186 movecat: fn(nil: self ref PDB, old: int, new: int): string; 187 188 }; 189 190 # resource files (.prc) 191 PRC: adt { 192 db: ref DB; 193 194 # read by index, or by type & id 195 read: fn(nil: self ref PRC, index: int): ref Palm->Resource; 196 readtype: fn(nil: self ref PRC, name: int, id: int): (ref Palm->Resource, int); 197 198 # write by type and id only (desklink) 199 write: fn(nil: self ref PRC, r: ref Palm->Resource): string; 200 201 truncate: fn(nil: self ref PRC): string; 202 delete: fn(nil: self ref PRC, name: int, id: int): string; 203 }; 204 205 # open modes (not the same as Sys->) 206 OREAD: con 16r80; 207 OWRITE: con 16r40; 208 ORDWR: con OREAD|OWRITE; 209 OEXCL: con 16r20; 210 OSECRET: con 16r10; 211 212 init: fn(m: Palm): string; 213}; 214