home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 04 / dupes.cpp < prev    next >
C/C++ Source or Header  |  1992-02-05  |  2KB  |  67 lines

  1. // dupes.cpp RHS 8/5/91
  2.  
  3. #include<string.h>
  4. #include"file.h"
  5. #include"dupes.h"
  6.  
  7.  
  8. void Dupes::GetData(File *d, long offset)
  9.     {
  10.     d->ReadAt(offset,sizeof(DataBuf),&DataBuf);
  11.     d->ReadAt(DataBuf.dirnameoffset,sizeof(DirName),&DirName);
  12.     DirName.dirname[DirName.dirnamelen] = '\0';
  13.     }
  14.  
  15. void Dupes::PutData(File *d, void *data)
  16.     {                                       // setup time,date,size 
  17.     memcpy(&DataBuf,data,(sizeof(unsigned)*2)+sizeof(long));
  18.     d->Write(sizeof(DATABUF),&DataBuf);   // write file entry
  19.     }
  20.  
  21. void Dupes::PutIndex(File *i, char *name, long offset, BYTE status)
  22.     {
  23.     strcpy(OutBuf.buf,name);                // setup index name
  24.     OutBuf.offset = offset;                 // setup index data pointer
  25.     OutBuf.status = status;                 // setup index status
  26.     i->Write(sizeof(OUTBUF),&OutBuf);       // write index entry
  27.     }
  28.  
  29. int Dupes::GetRecord(void)
  30.     {
  31.     if(IndexFile.Read(sizeof(OutBuf),&OutBuf) != 0)
  32.         {
  33.         GetData(&DataFile,OutBuf.offset);
  34.         return 1;
  35.         }
  36.     return 0;
  37.     }
  38.  
  39. static char lastdirspec[80];
  40. static long lastdiroffset;
  41.  
  42. BOOL Dupes::PutDirectory(File *f, char *dirspec, BOOL init)
  43.     {
  44.     if(init)
  45.         {
  46.         lastdirspec[0] = '\0';
  47.         lastdiroffset = 0L;
  48.         }
  49.  
  50.     if(strcmp(dirspec,lastdirspec))     // if not the same dirspec
  51.         {
  52.         strcpy(lastdirspec,dirspec);
  53.         lastdiroffset = DataBuf.dirnameoffset = f->CurPosition();
  54.         strcpy(DirName.dirname,strupr(lastdirspec));
  55.         DirName.dirnamelen = strlen(DirName.dirname);
  56.         f->Write((DirName.dirnamelen+sizeof(DirName.dirnamelen)),&DirName);
  57.         return TRUE;
  58.         }
  59.     else
  60.         {
  61.         DataBuf.dirnameoffset = lastdiroffset;
  62.         return FALSE;
  63.         }
  64.     }
  65.  
  66.  
  67.