home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
OTHERUTI
/
WWIV412S.ZIP
/
GFILES.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-25
|
7KB
|
299 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988 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 <sys\stat.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <alloc.h>
#include "vardec.h"
#include "fcns.h"
extern int hangup,checkit,okmacro,two_color,lastcon,using_modem,live_user;
extern char dc[81],dcd[81],odc[81];
extern char charbuffer[161];
extern userrec thisuser;
extern int charbufferpointer,chatting;
extern int usernum,useron,num_sec,helpl;
extern configrec syscfg;
extern int echo;
extern unsigned char realsl;
extern double timeon,extratimecall;
extern char curspeed[80];
extern int cursub,curdir,curdloads,use_workspace,global_xx;
extern usersubrec usub[32],udir[32];
extern statusrec status;
extern int incom,outcom,msgreadlogon;
extern int fsenttoday,userfile,chatcall,mailcheck,smwcheck;
extern char chatreason[81],irt[81];
extern subboardrec subboards[32];
extern long nscandate;
extern float batchtime;
extern int numbatch,numbatchdl,numed,lines_listed;
extern editorrec *editors;
extern gfiledirrec *gfilesec;
extern char xdate[9];
extern int questused[20];
extern unsigned int modem_speed,com_speed;
extern char ctypes[NUM_CTYPES][18];
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("G-Files sections available:",&abort);
pla("",&abort);
for (i=0; (i<nmap) && (!abort) && (!hangup); i++) {
s[0]=32;
if (i<=8)
itoa(i+1,&(s[1]),10);
else
itoa(i+1,s,10);
strcat(s,". ");
strcat(s,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("G-Files in this section:",&abort);
pla("",&abort);
if ((nf==0) && (abort==0)) {
nl();
pl("None.");
nl();
}
for (i=0; (i<nf) && (!abort) && (!hangup); i++) {
s[0]=32;
if (i<=8)
itoa(i+1,&(s[1]),10);
else
itoa(i+1,s,10);
strcat(s,". ");
strcat(s,g[i].description);
pla(s,&abort);
}
nl();
if ((!abort) && (cs())) {
pl("A. Add G-files");
pl("D. Delete 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(2,"Which G-file (Q=Quit) ? ");
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("Deleted.");
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 (thisuser.sl<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("No G-file sections available.");
nl();
return;
}
list_sec(map,nmap);
while ((!done) && (!hangup)) {
nl();
tleft(1);
prt(2,"Which section (Q=Quit) ? ");
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();
print("Now loading files for ",gfilesec[map[i]].name,"");
nl();
i1=fill_sec(map[i]);
}
} else {
i=atoi(ss);
if ((i>0) && (i<=nmap)) {
gfile_sec(map[i-1]);
}
}
}
}