home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / XGRP_000.SZH / DUPES.C < prev    next >
C/C++ Source or Header  |  1991-08-21  |  2KB  |  108 lines

  1. #include "xgroup.h"
  2.  
  3. /* global vars created here */
  4.  
  5. DUPES *dupes = NULL;
  6. word  nextdupe = 0;
  7. char  founddupes = 0;
  8.  
  9. /* local-only vars */
  10.  
  11. static word  lastnextdupe = 0;
  12. static word  lastdupearea = 0;
  13.  
  14. /* local-only functions */
  15.  
  16. static void _fastcall rewrite_dupes (void);
  17.  
  18. /* external var references */
  19.  
  20. extern word     maxdupes;
  21. extern char     buffer[1024];
  22. extern GROUP    *group;
  23. extern CONTROLS control;
  24. extern ADDR     *myaddr;
  25. extern ECHOREC  *echos;
  26. extern ASSHOLE  *assholes;
  27. extern char     *groupin;
  28. extern char     *groupout;
  29. extern char     *grouphold;
  30. extern char     *msgdir;
  31. extern char     *outbound;
  32. extern char     *inbound;
  33. extern char     *archive;
  34. extern char     *unarchive;
  35. extern word     packsize;
  36. extern word     netarea;
  37.  
  38.  
  39.  
  40.  
  41.  
  42. void _fastcall free_dupes (void) {
  43.  
  44.     if(!dupes) return;
  45.     if(founddupes) rewrite_dupes();
  46.     if(dupes) my_free(dupes);
  47.     dupes = NULL;
  48.     nextdupe = lastdupearea = lastnextdupe = 0;
  49.     founddupes = 0;
  50. }
  51.  
  52.  
  53.  
  54.  
  55. void _fastcall load_dupes (word areano) {
  56.  
  57.     int handle;
  58.     char dupefile[257];
  59.  
  60.  
  61.     if(dupes) free_dupes();
  62.  
  63.     lastdupearea = areano;
  64.  
  65.     dupes = calloc(sizeof(DUPES),maxdupes);
  66.     if(!dupes) {
  67.         logf("Couldn't allocate memory for dupe records");
  68.         return;
  69.     }
  70.  
  71.     sprintf(dupefile,"%s/XDUPES.%03x",msgdir,areano);
  72.     handle = sopen(dupefile,O_RDWR | O_BINARY,SH_DENYWR);
  73.     if(handle == -1) return;
  74.  
  75.     lseek(handle,0L,SEEK_END);
  76.     if(!tell(handle)) return;
  77.     lseek(handle,0L,SEEK_SET);
  78.  
  79.     read(handle,&nextdupe,sizeof(word));
  80.     read(handle,dupes,sizeof(DUPES) * maxdupes);
  81.  
  82.     if(nextdupe >= maxdupes) nextdupe = 0;
  83.     lastnextdupe = nextdupe;
  84.  
  85.     close(handle);
  86. }
  87.  
  88.  
  89.  
  90. static void _fastcall rewrite_dupes (void) {
  91.  
  92.     int handle;
  93.     char dupefile[257];
  94.  
  95.  
  96.     if(!dupes) return;
  97.  
  98.     sprintf(dupefile,"%s/XDUPES.%03x",msgdir,lastdupearea);
  99.     unlink(dupefile);
  100.     handle = sopen(dupefile,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE | S_IREAD);
  101.     if(handle == -1) return;
  102.  
  103.     write(handle,&nextdupe,sizeof(word));
  104.     write(handle,dupes,sizeof(DUPES) * maxdupes);
  105.  
  106.     close(handle);
  107. }
  108.