00001 #include "pdb.h"
00002 #ifdef _WINDOWS
00003 #include <winsock2.h>
00004 #endif
00005
00006 #ifdef USEQPE
00007 void Cpdb::suspend()
00008 {
00009 CExpander::suspend(fin);
00010 }
00011 void Cpdb::unsuspend()
00012 {
00013 CExpander::unsuspend(fin);
00014 }
00015 #endif
00016
00017 Cpdb::~Cpdb()
00018 {
00019 if (fin != NULL)
00020 {
00021 #ifdef USEQPE
00022 unsuspend();
00023 #endif
00024 fclose(fin);
00025 }
00026 }
00027
00028 size_t Cpdb::recordpos(int n)
00029 {
00030 UInt16 mxn = ntohs(head.recordList.numRecords);
00031 if (n >= mxn)
00032 {
00033 return file_length;
00034 }
00035 else
00036 {
00037 size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16);
00038 dataoffset += sizeof(RecordListType) * n;
00039 unsuspend();
00040 fseek(fin, dataoffset, SEEK_SET);
00041 RecordListType hdr;
00042 fread(&hdr, 1, sizeof(hdr), fin);
00043 return ntohl(hdr.nextRecordListID);
00044 }
00045
00046 }
00047
00048 size_t Cpdb::recordlength(int n)
00049 {
00050 return recordpos(n+1)-recordpos(n);
00051 }
00052
00053 void Cpdb::gotorecordnumber(int n)
00054 {
00055 unsuspend();
00056 fseek(fin, recordpos(n), SEEK_SET);
00057 }
00058
00059 bool Cpdb::openpdbfile(const char *src)
00060 {
00061
00062
00063
00064
00065 if (fin != NULL) fclose(fin);
00066
00067 fin = fopen(src,"rb");
00068
00069 if (fin==0)
00070 {
00071 return false;
00072 }
00073
00074
00075
00076 struct stat _stat;
00077 stat(src,&_stat);
00078 file_length = _stat.st_size;
00079
00080
00081
00082 fseek(fin,0,SEEK_SET);
00083
00084 fread(&head, 1, sizeof(head), fin);
00085
00086
00087
00088
00089 return true;
00090 }