author | llornkcor <llornkcor> | 2002-07-01 23:24:08 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-01 23:24:08 (UTC) |
commit | 59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2 (patch) (unidiff) | |
tree | f148d4858859dac3b413e675c760acfdab24b8e6 /noncore/apps/opie-reader/pdb.cpp | |
parent | c08be8ae22dcc1bfb83cfdec807149b161d770f5 (diff) | |
download | opie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.zip opie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.tar.gz opie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.tar.bz2 |
initial
Diffstat (limited to 'noncore/apps/opie-reader/pdb.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/pdb.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/pdb.cpp b/noncore/apps/opie-reader/pdb.cpp new file mode 100644 index 0000000..68b904e --- a/dev/null +++ b/noncore/apps/opie-reader/pdb.cpp | |||
@@ -0,0 +1,57 @@ | |||
1 | #include "pdb.h" | ||
2 | |||
3 | size_t Cpdb::recordpos(int n) | ||
4 | { | ||
5 | UInt16 mxn = ntohs(head.recordList.numRecords); | ||
6 | if (n >= mxn) | ||
7 | { | ||
8 | return file_length; | ||
9 | } | ||
10 | else | ||
11 | { | ||
12 | size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16); | ||
13 | dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n; | ||
14 | fseek(fin, dataoffset, SEEK_SET); | ||
15 | RecordListType hdr; | ||
16 | fread(&hdr, 1, sizeof(hdr), fin); | ||
17 | return ntohl(hdr.nextRecordListID); | ||
18 | } | ||
19 | |||
20 | } | ||
21 | |||
22 | size_t Cpdb::recordlength(int n) | ||
23 | { | ||
24 | return recordpos(n+1)-recordpos(n); | ||
25 | } | ||
26 | |||
27 | void Cpdb::gotorecordnumber(int n) | ||
28 | { | ||
29 | fseek(fin, recordpos(n), SEEK_SET); | ||
30 | } | ||
31 | |||
32 | bool Cpdb::openfile(const char *src) | ||
33 | { | ||
34 | |||
35 | // printf("In openfile\n"); | ||
36 | int ret = 0; | ||
37 | // printf("closing fin:%x\n",fin); | ||
38 | if (fin != NULL) fclose(fin); | ||
39 | // printf("opening fin\n"); | ||
40 | fin = fopen(src,"rb"); | ||
41 | |||
42 | if (fin==0) | ||
43 | { | ||
44 | return false; | ||
45 | } | ||
46 | |||
47 | // just holds the first few chars of the file | ||
48 | //char buf[0x100]; | ||
49 | fseek(fin,0,SEEK_END); | ||
50 | file_length = ftell(fin); | ||
51 | |||
52 | fseek(fin,0,SEEK_SET); | ||
53 | |||
54 | fread(&head, 1, sizeof(head), fin); | ||
55 | |||
56 | return true; | ||
57 | } | ||