Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pdb.cpp

Go to the documentation of this file.
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 += /*dataoffset%4 + */ 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   //qDebug("cpdb openfile:%s", src);
00062 
00063     //  printf("In openfile\n");
00064     //  printf("closing fin:%x\n",fin);
00065     if (fin != NULL) fclose(fin);
00066     //  printf("opening fin\n");
00067     fin = fopen(src,"rb");
00068 
00069     if (fin==0)
00070     {
00071         return false;
00072     }
00073 
00074     // just holds the first few chars of the file
00075     //  char buf[0x100];
00076       struct stat _stat;
00077       stat(src,&_stat);
00078       file_length = _stat.st_size;
00079       //    fseek(fin,0,SEEK_END);
00080       //    file_length = ftell(fin);
00081 
00082     fseek(fin,0,SEEK_SET);
00083 
00084     fread(&head, 1, sizeof(head), fin);
00085 
00086     //qDebug("Database name:%s", head.name);
00087     //qDebug("Total number of records:%u", ntohs(head.recordList.numRecords));
00088 
00089     return true;
00090 }

Generated on Sat Nov 5 16:16:56 2005 for OPIE by  doxygen 1.4.2