h37319
s 00416/00000/00000
d D 1.1 95/07/04 20:12:46 tim 1 0
c 
e
u
U
f e 0
t
T
I 1
#include <stdio.h>
#include <string.h>
#include "project.h"

/* Start of Global data */

/* pointers to the in and out list and the list we are currently working on */
struct ll * inlist ;
struct ll * outlist ;
struct ll * currlist ;

/* End of Global data */

/* Start of function definitions */


/* commands to manipulate the linked list */
struct ll * llnew() ;
struct ll * llnofind() ;

/* End of function definitions */

/* start of actual code */

/* start of linked list code */

/* display the usual header information */
disphdrs(llptr, startno, endno)
struct ll * llptr ;
int startno, endno ;
{
	int mask ;
	if (lldbg == TRUE)
		printf("CALL: disphdrs (llptr = OMITTED, starton = %d, endno = %d)", startno, endno) ;
	/* if llptr is inlist include from, otherwise include to */
	if (llptr == inlist)
		mask = PFROM ;
	else
		mask = PTO ;
	/* add the other stuff */
	mask = mask | PNO | PSUBJECT | PREAD | PACTIVE ;
	/* startno MUST be 1 or higher */
	if (startno < 1)
		startno = 1 ;
	/* endno should be less or equal to llptr->count */
	if (endno > llptr->count)
		endno = llptr->count ;
	llprint(llptr, mask, startno, endno) ;
}
/* print the entire ll list */
lldmpall(llptr)
struct ll * llptr ;
{
	while (llptr != NULL)
	{
		lldump(llptr) ;
		llptr = llptr->next ;
	}
}
/* print the list at start ll, according to the mask, between the numbers startno and end no */
llprint(startll, mask, startno, endno)
struct ll * startll ;
int mask, startno, endno ;
{
	if (lldbg == TRUE)
		printf("CALL: llprint (startll = OMITTED, mask = %x, startno = %d, endno = %d)", mask, startno, endno) ;
	while (startll != NULL)
	{
		if ((startll->no >= startno) && (startll->no <= endno))
		{
			/* should we be printing this record ? */
			if ((mask & PACTIVE) && (startll->status == ACTIVE))
				llprinta(startll, mask) ;
			else if ((mask & PIGNORE) && (startll->status == IGNORE))			llprinta(startll, mask) ;
			else if ((mask & PDELETED) && (startll->status == DELETED))
				llprinta(startll, mask) ;
		}
		startll = startll->next ;
	}
}

/* print the structure according to the mask */
llprinta(llptr, mask)
struct ll * llptr ;
int mask ;
{
	char tmp[100] ;
	char outline[1024] ;
	if (lldbg == TRUE)
		printf("CALL: llprinta (llptr = OMITTED, mask = %x", mask) ;
	outline[0] = '\0' ;
	/* print llptr according to the mask */
	if (mask & PNO)
	{
		sprintf(tmp, "%d", llptr->no) ;
		strcat(outline, tmp) ;
		strcat(outline, " ") ;
	}
	if (mask & PDATAFILE)
	{
		strcat(outline, llptr->datafile) ;
		strcat(outline, " ") ;
	}
	if (mask & PTO)
	{
		strcat(outline, llptr->to) ;
		strcat(outline, " ") ;
	}
	if (mask & PFROM)
	{
		strcat(outline, llptr->from) ;
		strcat(outline, " ") ;
	}
	if (mask & PSUBJECT)
	{
		strcat(outline, llptr->subject) ;
		strcat(outline, " ") ;
	}
	if (mask & PCC)
	{
		strcat(outline, llptr->cc) ;
		strcat(outline, " ") ;
	}
	if(mask & PBCC)
	{
		strcat(outline, llptr->bcc) ;
		strcat(outline, " ") ;
	}
	if (mask & PSTATUS)
	{
		if (llptr->status == ACTIVE)
		{
			strcat(outline, "ACTIVE") ;
			strcat(outline, " ") ;
		}
		else if (llptr->status == IGNORE)
		{
			strcat(outline, "IGNORE") ;
			strcat(outline, " ") ;
		}
		else if (llptr->status == DELETED)
		{
			strcat(outline, "DELETED") ;
			strcat(outline, " ") ;
		}
	}
	if (mask & PREAD)
	{
		if (llptr->read == RD)
		{
			strcat(outline, "READ") ;
			strcat(outline, " ") ;
		}
		else
		{
			strcat(outline, "NEW") ;
			strcat(outline, " ") ;
		}
	}
	if (mask & PCOUNT)
	{
		sprintf(tmp, "%d", llptr->count) ;
		strcat(outline, tmp);
		strcat(outline, " ") ;
	}
	/* print the newline */
	printf("%s\n", outline) ;
}
/* print the current ll entry */
lldump(llptr)
struct ll * llptr ;
{
	if (lldbg == TRUE)
		printf("CALL: lldump (llptr = OMITTED)") ;
	if (llptr == NULL)
	{
		printf("Pointer is NULL") ;
		return ;
	}
	printf("Datafile is: %s", llptr->datafile) ;
	printf("To is: %s", llptr->to) ;
	printf("From is: %s", llptr->from ) ;
	printf("Subject is: %s", llptr->subject) ;
	printf("CC is: %s", llptr->cc) ;
	printf("Bcc is: %s", llptr->bcc) ;
	/* status */
	if (llptr->status == ACTIVE)
		printf("Status is: ACTIVE") ;
	else if (llptr->status == DELETED)
		printf("Status is: DELETED") ;
	else if (llptr->status == IGNORE)
		printf("Status is: IGNORE") ;
	else
		printf("Status is invalid (%d)", llptr->status) ;
	/* read */
	if (llptr->read == RD)
		printf("Read is: RD") ;
	else if (llptr->read == NEW)
		printf("Read is: NEW") ;
	else
		printf("Read is invalid (%d)", llptr->read) ;
	printf("No is: %d", llptr->no) ;
	printf("Count is: %d", llptr->count) ;
	if (llptr->mydata == NULL)
		printf("Mydata is: NULL") ;
	else
	{
		printf("Mydata->myaddr is: %s", llptr->mydata->myaddr) ;
		printf("Mydata->mypath is: %s", llptr->mydata->mypath) ;
	}
	if (llptr->next == NULL)
		printf("Next is: NULL") ;
	else
		printf("Next is: Non NULL") ;
}

/* this command scans the linked lists looking for a deleted entry. the associated file is then deleted */
prgemail(llptr)
struct ll * llptr;
{
	struct ll * llstart ;
	int ret ;
	if (cmddbg == TRUE)
		printf("CALL: prgemail (llstart = OMITTED)") ;
	llstart = llptr ;
	while(llptr != NULL)
	{
		if(llptr->status == DELETED)
		{
			ret = delfile(llptr, llstart) ;
			if (ret == FILEERR)
			{
				printf("FILE ERROR: prgemail, error in deleting message file %s", llptr->datafile) ;
				return(FILEERR) ;
			}
		}
		llptr = llptr->next ;
	}
	return(TRUE) ;
}
/* fill in a ll entry based on the arguments */
llfill(llptr, datafile, to, from, subject, cc, bcc, status, read, no)
struct ll * llptr;
char * datafile, * to, * from, * subject, * cc, * bcc ;
int status, read, no;
{
	if (lldbg == TRUE)
		printf("CALL llfill (llptr = OMITTED, datafile = %s, to = %s, from = %s, subject = %s, cc = %s, bcc = %s, status = %d, read = %d, no = %d)", datafile, to, from, subject, cc, bcc, status, read, no) ;
	strcpy(llptr->datafile, datafile) ;
	strcpy(llptr->to, to) ;
	strcpy(llptr->from, from) ;
	strcpy(llptr->subject, subject) ;
	strcpy(llptr->cc, cc) ;
	strcpy(llptr->bcc, bcc) ;
	llptr->status = status ;
	llptr->read = read ;
	llptr->no = no ;
	if (lldbg == TRUE)
	{
		printf("filled in structure is");
		lldump(llptr) ;
	}
}
/* find a list entry based on the number */
struct ll * llnofind(no, llstart)
int no ;
struct ll * llstart ;
{
	struct ll * llcurrnt ;
	if (lldbg == TRUE)
		printf("CALL: llnofind(no = %d, llstart = OMITTED)", no) ;
	llcurrnt = llstart ;
	while(llcurrnt->no != no)
	{
		if (lldbg == TRUE)
		{
			printf("llnofind is working on") ;
			lldump(llcurrnt) ;
		}
		if(llcurrnt->next == NULL)
		{
			if (lldbg == TRUE)
				printf("llnofind returns NULL");
			return(NULL) ;
		}
		llcurrnt = llcurrnt->next ;

	}
	/* to have got here we must havea match if we could not find a match we would already havereturned NULL */
	if (lldbg == TRUE)
	{
		printf("llnofind returns the following");
		lldump(llcurrnt) ;
	}
	return(llcurrnt) ;
}
		
/* this adds the newll to the end of the list at startll */
lladd(newll, startll)
struct ll * newll, * startll ;
{
	struct ll * llcurrnt ;
	if (lldbg == TRUE)
		printf("lladd (newll = OMITTED, startll = OMITTED)") ;
	llcurrnt = startll ;
	/* scan down the list lokking for NULL) */
	while(llcurrnt->next != NULL)
	{
		llcurrnt = llcurrnt->next ;
	}
	/* we are at the end of the list add the entry */
	llcurrnt->next = newll ;
	/* increment the total in the list counter, held in the first entry in the list only */
	startll->count ++ ;
}
/* this function creates the initial in and out list entries */
llinit()
{
	if (lldbg == TRUE)
		printf("CALL: llinit()") ;
	inlist = llnew() ;
	outlist = llnew() ;
	inlist->mydata = (struct mydata *) calloc((size_t) 1, (size_t) sizeof(struct mydata)) ;
	outlist->mydata = (struct mydata *) calloc((size_t) 1, (size_t) sizeof(struct mydata)) ;
}

/* linked list functions */
/* llnew, create space and fill with defaults */
struct ll * llnew()
{
	struct ll * llptr;
	if (lldbg == TRUE)
		printf("CALL: llnew()") ;
	llptr = (struct ll *) calloc((size_t) 1, (size_t) sizeof(struct ll)) ;
	llptr->datafile[0] = '\0' ;
	llptr->to[0] = '\0' ;
	llptr->from[0] = '\0' ;
	llptr->subject[0] = '\0' ;
	llptr->cc[0] = '\0' ;
	llptr->bcc[0] = '\0' ;
	llptr->status = IGNORE ;
	llptr->read = NEW ;
	llptr->next = NULL ;
	llptr->no = 0 ;
	llptr->count = 0 ;
	llptr->mydata = NULL ;
	return(llptr) ;
}
llcopy (out, in)
struct ll * out, * in;
{
	if (lldbg == TRUE)
	{
		printf("CALL: llcopy (in = OMITTED, out = OMITTED)") ;
		printf("input is ") ;
		lldump(in) ;
	}
	/* copy the strings but status etc remains untouched */
	strcpy(out->datafile, in->datafile) ;
	strcpy(out->to, in->to) ;
	strcpy(out->from, in->from) ;
	strcpy(out->subject, in->subject) ;
	strcpy(out->cc, in->cc) ;
	strcpy(out->bcc, in->bcc) ;
	if (lldbg == TRUE)
	{
		printf("output is ") ;
		lldump(out) ;
	}
}
/* llfree, free llptr and everything it points to */
llfree (llptr)
struct ll * llptr ;
{
	struct ll * llnext;
	if (lldbg == TRUE)
		printf("CALL: llfree(llptr = OMITTED)");
	/* free the mydata section only on the first item */
	free(llptr->mydata) ;
	llnext = llptr;
	while(llptr != NULL)
	{
		llnext = llptr->next ;
		free(llptr) ;
		llptr = llnext ;
	}
}
/* is mailno in the list and marked as ACTIVE ? */
llvalid(mailno, llptr)
int mailno ;
struct ll * llptr ;
{
	if (lldbg == TRUE)
		printf("CALL: llvalid(mailno = %d, llptr = OMITTED)", mailno) ;
	llptr = llnofind(mailno, llptr) ;
	if (llptr != NULL)
	{
		if (llptr->status != ACTIVE)
		{
			printf("%d is not an active message", mailno) ;
			return(FALSE) ;
		}
		else
		{
			return(TRUE) ;
		}
	}
	else
	{
		printf("%d is not a valid message", mailno) ;
		return(FALSE) ;
	}
}

/* end of linked list code */

E 1
