author | llornkcor <llornkcor> | 2002-07-01 23:24:08 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-01 23:24:08 (UTC) |
commit | 59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2 (patch) (side-by-side diff) | |
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 @@ +#include "pdb.h" + +size_t Cpdb::recordpos(int n) +{ + UInt16 mxn = ntohs(head.recordList.numRecords); + if (n >= mxn) + { + return file_length; + } + else + { + size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16); + dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n; + fseek(fin, dataoffset, SEEK_SET); + RecordListType hdr; + fread(&hdr, 1, sizeof(hdr), fin); + return ntohl(hdr.nextRecordListID); + } + +} + +size_t Cpdb::recordlength(int n) +{ + return recordpos(n+1)-recordpos(n); +} + +void Cpdb::gotorecordnumber(int n) +{ + fseek(fin, recordpos(n), SEEK_SET); +} + +bool Cpdb::openfile(const char *src) +{ + + // printf("In openfile\n"); + int ret = 0; + // printf("closing fin:%x\n",fin); + if (fin != NULL) fclose(fin); + // printf("opening fin\n"); + fin = fopen(src,"rb"); + + if (fin==0) + { + return false; + } + + // just holds the first few chars of the file + // char buf[0x100]; + fseek(fin,0,SEEK_END); + file_length = ftell(fin); + + fseek(fin,0,SEEK_SET); + + fread(&head, 1, sizeof(head), fin); + + return true; +} |