home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
RBBS in a Box Volume 1 #2
/
RBBS_vol1_no2.iso
/
add2
/
fc_v003.exe
/
FCLIST.C
< prev
next >
Wrap
Text File
|
1989-04-24
|
7KB
|
242 lines
/***************************************************************************
*
* FCLIST.C
*
* Linked List Management functions for
* File Commentor.
*
* Author: Ronald C. Bieber
*
*
***************************************************************************/
#include <stdio.h>
#include <dos.h>
#include <dir.h>
#include "fc.h"
/****************************************************************************
*
* Name: mk_info
* Synopsis: int mk_info(void);
*
*
*
* Description: Creates new COMMENTS.FC file
*
* Returns: File handle of new file.
*
***************************************************************************/
int mk_info()
{
int fh;
unsigned wr;
fh = _creat(comment_file, 0);
if (fh == -1) {
fprintf(stderr, "Can't open COMMENTS.FC\n");
quit(FAILURE);
}
write(fh, "RBCI", 4);
return(fh);
}
/****************************************************************************
*
* Name: mk_node
* Synopsis: FILELIST *mk_node(phead);
* FILELIST *phead; beginning of linked list
*
*
* Description: Creates new node to store more information
*
* Returns: a pointer of type FILELIST to the new node.
*
***************************************************************************/
FILELIST *mk_node(phead)
FILELIST *phead;
{
FILELIST *new,
*tmp,
*pred;
tmp = phead;
while (tmp != NULL) {
pred = tmp;
tmp = tmp->next;
}
if ((new = (FILELIST *) calloc(1, sizeof(FILELIST))) == NULL)
return(NULL);
new->prev = pred;
new->next = NULL;
new->fileinfo.sig = sig;
pred->next = new;
return(new);
}
/****************************************************************************
*
* Name: search
* Synopsis: FILELIST *search(phead, s);
* FILELIST *phead; beginning of linked list
* char s; pointer to filename to search for
*
* Description: Searches list PHEAD for filename S
* Returns: pointer to node containing information for S
*
***************************************************************************/
FILELIST *search(phead, s)
FILELIST *phead;
char *s;
{
FILELIST *p = phead;
while(p != NULL)
if (wildcards(s, p->fileinfo.filename))
return(p);
else
p = p->next;
return(NULL);
}
/****************************************************************************
*
* Name: read_info
* Synopsis: int read_info(phead, fh);
* FILELIST *phead; beginning of linked list
* int fh; handle of file to read from
*
* Description: Reads the contents of file FH and stores it in
* linked list PHEAD
*
* Returns: How many items were read
*
***************************************************************************/
int read_info(phead, fh)
FILELIST *phead;
int fh;
{
int count = 0;
char tmp[4];
struct _fi fi;
FILELIST *next;
next = phead;
read(fh, tmp, sizeof(tmp));
while (read(fh, &fi, sizeof(fi)) == sizeof(fi)) {
if (fi.sig != sig) {
printf("Comment file COMMENTS.FC is corrupted!\n");
quit(FAILURE);
}
next = mk_node(phead);
memmove(&(next)->fileinfo, &fi, sizeof(fi));
count++;
}
return(count);
}
/****************************************************************************
*
* Name: write_info
* Synopsis: int write_info(phead, fh);
* FILELIST *phead; beginning of linked list
* int fh; handle of file to write to
*
* Description: Writes the contents of list PHEAD to file FH
*
* Returns: How many items were written
*
***************************************************************************/
int write_info(phead, fh)
FILELIST *phead;
int fh;
{
int numread,
count = 0;
FILELIST *next;
FILE *fp;
next = phead->next;
lseek(fh, 4L, SEEK_SET);
while(next != NULL) {
if (strlen(next->fileinfo.comment) > 0)
write(fh, &(next)->fileinfo, sizeof(next->fileinfo));
next = next->next;
count++;
}
}
/****************************************************************************
*
* Name: node_delete
* Synopsis: void node_delete(phead, s);
* FILELIST *phead; beginning of linked list
* char s; pointer to filename to search for
*
* Description: Deletes reference to file 's' from phead list
*
***************************************************************************/
void node_delete(phead, s)
FILELIST *phead;
char *s;
{
FILELIST *next = phead;
while (next != NULL) {
if (stricmp(next->fileinfo.filename, s) == 0) {
if (next->prev != NULL)
next->next->prev = next->prev;
else
next->next->prev = NULL;
if (next->next != NULL)
next->prev->next = next->next;
else
next->prev->next = NULL;
free(next);
return;
} else
next = next->next;
}
}
/****************************************************************************
*
* Name: compress
* Synopsis: void compress(phead);
* FILELIST *phead;
*
* Description: Removes all references of files not present on the
* disk from the list (phead).
*
***************************************************************************/
void compress(phead)
FILELIST *phead;
{
struct ffblk files;
FILELIST *next = phead;
int attr = FA_ARCH + FA_HIDDEN + FA_RDONLY + FA_SYSTEM + FA_DIREC;
while (next != NULL) {
if (findfirst(next->fileinfo.filename, &files, attr) != 0)
node_delete(phead, next->fileinfo.filename);
next = next->next;
}
}