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