home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
GFILES.C
< prev
next >
Wrap
Text File
|
1991-12-26
|
5KB
|
252 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988-1991 by Wayne Bell
Distribution of the source code for WWIV, in any form, modified or unmodified,
without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
Distribution of compiled versions of WWIV is limited to copies compiled BY
THE AUTHOR. Distribution of any copies of WWIV not compiled by the author
is expressly prohibited.
*****************************************************************************/
#include "vars.h"
#pragma hdrstop
char *get_file(char *fn, long *len)
{
int i;
char *s;
i=open(fn,O_RDWR | O_BINARY);
if (i<0) {
*len=0L;
return(NULL);
}
if ((s=malloca(filelength(i)+50))==NULL) {
*len=0L;
close(i);
return(NULL);
}
*len=(long) read(i,(void *)s, filelength(i));
close(i);
return(s);
}
gfilerec *read_sec(int sn, int *nf)
{
gfilerec *g;
int f,i;
char s[81];
i=sizeof(gfilerec)*(gfilesec[sn].maxfiles);
if ((g=malloca((long) i))==NULL) {
*nf=0;
return(NULL);
}
sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
f=open(s,O_RDWR | O_BINARY);
if (f<0)
*nf=0;
else
*nf=read(f,(void *)g,i)/sizeof(gfilerec);
close(f);
return(g);
}
void list_sec(int *map, int nmap)
{
int i,abort;
char s[81];
abort=0;
pla("",&abort);
pla("",&abort);
pla("1G-Files sections available3:",&abort);
pla("",&abort);
for (i=0; (i<nmap) && (!abort) && (!hangup); i++) {
sprintf(s,"7[1%2d7]1.3 %s",i+1, gfilesec[map[i]].name);
pla(s,&abort);
}
nl();
}
void list_gfiles(gfilerec *g, int nf)
{
int i,abort;
char s[81];
abort=0;
pla("",&abort);
pla("",&abort);
pla("1G-Files in this section3:",&abort);
pla("",&abort);
if ((nf==0) && (abort==0)) {
nl();
pl("3None1.");
nl();
}
for (i=0; (i<nf) && (!abort) && (!hangup); i++) {
sprintf(s,"7[1%2d7]1.3 %s",i+1, g[i].description);
pla(s,&abort);
}
nl();
if ((!abort) && (cs())) {
pl("7A1. 5Add G-files");
pl("7D1. 5Delete G-files");
nl();
}
}
void gfile_sec(int sn)
{
gfilerec *g;
int i,done,nf,i1;
char xdc[81],*ss,*ss1,s[81];
g=read_sec(sn,&nf);
if (g==NULL)
return;
strcpy(xdc,odc);
for (i=0; i<20; i++)
odc[i]=0;
for (i=1; i<=nf/10; i++)
odc[i-1]=i+'0';
list_gfiles(g,nf);
done=0;
while ((!done) && (!hangup)) {
nl();
tleft(1);
prt(3,"Which G-file 5(1Q=Quit5) 3? ");
ss=mmkey(2);
i=atoi(ss);
if (strcmp(ss,"Q")==0)
done=1;
else
if ((strcmp(ss,"A")==0) && (cs())) {
farfree(g);
fill_sec(sn);
g=read_sec(sn,&nf);
if (g==NULL)
return;
for (i=0; i<20; i++)
odc[i]=0;
for (i=1; i<=nf/10; i++)
odc[i-1]=i+'0';
} else
if ((strcmp(ss,"D")==0) && (cs())) {
nl();
prt(2,"G-file number to delete? ");
ss1=mmkey(2);
i=atoi(ss1);
if ((i>0) && (i<=nf)) {
sprintf(s,"Remove %s? ",g[i-1].description);
prt(5,s);
if (yn()) {
prt(5,"Erase file too? ");
if (yn()) {
sprintf(s,"%s%s\\%s",syscfg.gfilesdir,
gfilesec[sn].filename,g[i-1].filename);
unlink(s);
}
for (i1=i; i1<nf; i1++)
g[i1-1]=g[i1];
--nf;
sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
i=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
write(i,(void *)g,nf*sizeof(gfilerec));
close(i);
nl();
pl("6Deleted.");
nl();
}
}
} else
if (strcmp(ss,"?")==0)
list_gfiles(g,nf);
else
if ((i>0) && (i<=nf)) {
sprintf(s,"%s\\%s",gfilesec[sn].filename,g[i-1].filename);
i1=printfile(s);
if (i1==0) {
sprintf(s,"Read G-file '%s'",g[i-1].filename);
sysoplog(s);
}
}
}
farfree(g);
strcpy(odc,xdc);
}
void gfiles()
{
int i,i1,i2,done,abort,map[32],nmap,ok;
char s[81],s1[81],s2[81],*ss;
done=0;
nmap=0;
for (i=0; i<20; i++)
odc[i]=0;
for (i=0; i<num_sec; i++) {
ok=1;
if (thisuser.age<gfilesec[i].age)
ok=0;
if (actsl<gfilesec[i].sl)
ok=0;
if (((thisuser.ar & gfilesec[i].ar)==0) && (gfilesec[i].ar))
ok=0;
if (ok) {
map[nmap++]=i;
if ((nmap % 10)==0)
odc[nmap/10-1]='0'+(nmap/10);
}
}
if (nmap==0) {
nl();
pl("7No G-file sections available.");
nl();
return;
}
list_sec(map,nmap);
while ((!done) && (!hangup)) {
nl();
tleft(1);
prt(3,"Which section 5(1Q=Quit5) 3? ");
ss=mmkey(2);
if (strcmp(ss,"Q")==0)
done=1;
else
if (strcmp(ss,"?")==0)
list_sec(map,nmap);
else
if ((strcmp(ss,"A")==0) && (cs())) {
i1=0;
for (i=0; (i<nmap) && (!i1); i++) {
nl();
npr("Now loading files for %s\r\n",gfilesec[map[i]].name);
nl();
i1=fill_sec(map[i]);
}
} else {
i=atoi(ss);
if ((i>0) && (i<=nmap)) {
gfile_sec(map[i-1]);
}
}
}
}