Diffstat (limited to 'noncore/apps/opie-reader/pdb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/pdb.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/noncore/apps/opie-reader/pdb.cpp b/noncore/apps/opie-reader/pdb.cpp index dca67ff..39551cc 100644 --- a/noncore/apps/opie-reader/pdb.cpp +++ b/noncore/apps/opie-reader/pdb.cpp | |||
@@ -1,60 +1,90 @@ | |||
1 | #include "pdb.h" | 1 | #include "pdb.h" |
2 | #ifdef _WINDOWS | 2 | #ifdef _WINDOWS |
3 | #include <winsock2.h> | 3 | #include <winsock2.h> |
4 | #endif | 4 | #endif |
5 | 5 | ||
6 | #include "useqpe.h" | ||
7 | |||
8 | #ifdef USEQPE | ||
9 | void Cpdb::suspend() | ||
10 | { | ||
11 | CExpander::suspend(fin); | ||
12 | } | ||
13 | void Cpdb::unsuspend() | ||
14 | { | ||
15 | CExpander::unsuspend(fin); | ||
16 | } | ||
17 | #endif | ||
18 | |||
19 | Cpdb::~Cpdb() | ||
20 | { | ||
21 | if (fin != NULL) | ||
22 | { | ||
23 | #ifdef USEQPE | ||
24 | unsuspend(); | ||
25 | #endif | ||
26 | fclose(fin); | ||
27 | } | ||
28 | } | ||
29 | |||
6 | size_t Cpdb::recordpos(int n) | 30 | size_t Cpdb::recordpos(int n) |
7 | { | 31 | { |
8 | UInt16 mxn = ntohs(head.recordList.numRecords); | 32 | UInt16 mxn = ntohs(head.recordList.numRecords); |
9 | if (n >= mxn) | 33 | if (n >= mxn) |
10 | { | 34 | { |
11 | return file_length; | 35 | return file_length; |
12 | } | 36 | } |
13 | else | 37 | else |
14 | { | 38 | { |
15 | size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16); | 39 | size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16); |
16 | dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n; | 40 | dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n; |
17 | fseek(fin, dataoffset, SEEK_SET); | 41 | fseek(fin, dataoffset, SEEK_SET); |
18 | RecordListType hdr; | 42 | RecordListType hdr; |
19 | fread(&hdr, 1, sizeof(hdr), fin); | 43 | fread(&hdr, 1, sizeof(hdr), fin); |
20 | return ntohl(hdr.nextRecordListID); | 44 | return ntohl(hdr.nextRecordListID); |
21 | } | 45 | } |
22 | 46 | ||
23 | } | 47 | } |
24 | 48 | ||
25 | size_t Cpdb::recordlength(int n) | 49 | size_t Cpdb::recordlength(int n) |
26 | { | 50 | { |
27 | return recordpos(n+1)-recordpos(n); | 51 | return recordpos(n+1)-recordpos(n); |
28 | } | 52 | } |
29 | 53 | ||
30 | void Cpdb::gotorecordnumber(int n) | 54 | void Cpdb::gotorecordnumber(int n) |
31 | { | 55 | { |
32 | fseek(fin, recordpos(n), SEEK_SET); | 56 | fseek(fin, recordpos(n), SEEK_SET); |
33 | } | 57 | } |
34 | 58 | ||
35 | bool Cpdb::openfile(const char *src) | 59 | bool Cpdb::openpdbfile(const char *src) |
36 | { | 60 | { |
61 | //qDebug("cpdb openfile:%s", src); | ||
37 | 62 | ||
38 | // printf("In openfile\n"); | 63 | // printf("In openfile\n"); |
39 | int ret = 0; | ||
40 | // printf("closing fin:%x\n",fin); | 64 | // printf("closing fin:%x\n",fin); |
41 | if (fin != NULL) fclose(fin); | 65 | if (fin != NULL) fclose(fin); |
42 | // printf("opening fin\n"); | 66 | // printf("opening fin\n"); |
43 | fin = fopen(src,"rb"); | 67 | fin = fopen(src,"rb"); |
44 | 68 | ||
45 | if (fin==0) | 69 | if (fin==0) |
46 | { | 70 | { |
47 | return false; | 71 | return false; |
48 | } | 72 | } |
49 | 73 | ||
50 | // just holds the first few chars of the file | 74 | // just holds the first few chars of the file |
51 | //char buf[0x100]; | 75 | //char buf[0x100]; |
52 | fseek(fin,0,SEEK_END); | 76 | struct stat _stat; |
53 | file_length = ftell(fin); | 77 | stat(src,&_stat); |
78 | file_length = _stat.st_size; | ||
79 | // fseek(fin,0,SEEK_END); | ||
80 | // file_length = ftell(fin); | ||
54 | 81 | ||
55 | fseek(fin,0,SEEK_SET); | 82 | fseek(fin,0,SEEK_SET); |
56 | 83 | ||
57 | fread(&head, 1, sizeof(head), fin); | 84 | fread(&head, 1, sizeof(head), fin); |
58 | 85 | ||
86 | qDebug("Database name:%s", head.name); | ||
87 | qDebug("Total number of records:%u", ntohs(head.recordList.numRecords)); | ||
88 | |||
59 | return true; | 89 | return true; |
60 | } | 90 | } |