home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
XGRP_000.SZH
/
DUPES.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-21
|
2KB
|
108 lines
#include "xgroup.h"
/* global vars created here */
DUPES *dupes = NULL;
word nextdupe = 0;
char founddupes = 0;
/* local-only vars */
static word lastnextdupe = 0;
static word lastdupearea = 0;
/* local-only functions */
static void _fastcall rewrite_dupes (void);
/* external var references */
extern word maxdupes;
extern char buffer[1024];
extern GROUP *group;
extern CONTROLS control;
extern ADDR *myaddr;
extern ECHOREC *echos;
extern ASSHOLE *assholes;
extern char *groupin;
extern char *groupout;
extern char *grouphold;
extern char *msgdir;
extern char *outbound;
extern char *inbound;
extern char *archive;
extern char *unarchive;
extern word packsize;
extern word netarea;
void _fastcall free_dupes (void) {
if(!dupes) return;
if(founddupes) rewrite_dupes();
if(dupes) my_free(dupes);
dupes = NULL;
nextdupe = lastdupearea = lastnextdupe = 0;
founddupes = 0;
}
void _fastcall load_dupes (word areano) {
int handle;
char dupefile[257];
if(dupes) free_dupes();
lastdupearea = areano;
dupes = calloc(sizeof(DUPES),maxdupes);
if(!dupes) {
logf("Couldn't allocate memory for dupe records");
return;
}
sprintf(dupefile,"%s/XDUPES.%03x",msgdir,areano);
handle = sopen(dupefile,O_RDWR | O_BINARY,SH_DENYWR);
if(handle == -1) return;
lseek(handle,0L,SEEK_END);
if(!tell(handle)) return;
lseek(handle,0L,SEEK_SET);
read(handle,&nextdupe,sizeof(word));
read(handle,dupes,sizeof(DUPES) * maxdupes);
if(nextdupe >= maxdupes) nextdupe = 0;
lastnextdupe = nextdupe;
close(handle);
}
static void _fastcall rewrite_dupes (void) {
int handle;
char dupefile[257];
if(!dupes) return;
sprintf(dupefile,"%s/XDUPES.%03x",msgdir,lastdupearea);
unlink(dupefile);
handle = sopen(dupefile,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE | S_IREAD);
if(handle == -1) return;
write(handle,&nextdupe,sizeof(word));
write(handle,dupes,sizeof(DUPES) * maxdupes);
close(handle);
}