home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
bbs_ra
/
msgq160s.arj
/
EIDBASE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-28
|
2KB
|
88 lines
/*
* EIDBASE.C - MsgLink message base functions
*
* This file is not used by Msged/Q
*/
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include "msglink.h"
static char *expandbbs(char *fname);
static int openfile(char *fname);
/*
* Return a pointer to a static expanded path
*/
static char *expandbbs(char *fname)
{
static char name[PATHLEN];
strcpy(name, bbspath);
strcat(name, fname);
return(name);
} /* expandbbs */
static int openfile(char *fname)
{
return(open(expandbbs(fname), O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE));
} /* openfile */
/*
* Open all the message base files
* Returns TRUE if ok
*/
BOOLEAN openmsgbase()
{
struct stat st;
BYTE i;
for (i = f_first; i <= f_last; i++) /* open all files */
if ((F[i] = openfile(FN[i])) == -1)
return(FALSE);
memset(&msginfo, 0, sizeof(msginfo)); /* clear the record */
read(F[f_info], (char *)&msginfo, sizeof(msginfo)); /* if just created - read nothing */
memset(&st, 0, sizeof(st));
fstat(F[f_hdr], &st);
filemsgs = st.st_size/sizeof(MSGHEADER); /* number of messages */
if ((msgidx = calloc(filemsgs+1,sizeof(IDXRECORD))) == NULL)
return FALSE;
read(F[f_idx], (char *)msgidx, (size_t)filemsgs*sizeof(IDXRECORD));
memset(lastread, 0, sizeof(lastread));
if (lseek(F[f_last], (long)usernum * sizeof(lastread), SEEK_SET) == -1) {
fprintf(stderr,"\nNo lastread info exists for '%s' (%d)",username,usernum);
getch();
return FALSE;
} /* if */
read(F[f_last], (char *)lastread, sizeof(lastread));
memset(current, 0, sizeof(current));
read(F[f_cur], (char *)current, sizeof(current));
for (i = 0; i < BLIM; i++) {
int first = firstmsg(i+1);
int last = lastmsg(i+1);
if (lastread[i] > last)
lastread[i] = last;
else if (lastread[i] < first)
lastread[i] = first;
if (current[i] > lastread[i])
current[i] = lastread[i];
else if (current[i] < first)
current[i] = first;
} /* for */
return TRUE;
} /* openmsgbase */