home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
WWIV2.ZIP
/
XFEROVL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-31
|
13KB
|
580 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988-1993 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
#include <time.h>
#include <dir.h>
#define SETREC(i) lseek(dlf,((long) (i))*((long)sizeof(uploadsrec)),SEEK_SET);
void move_file(void)
{
char sx[81],s[81],s1[81],s2[81],ch,*ss;
int i,i1,ok,d1,d2,done,cp;
uploadsrec u,u1,u2;
char *b;
ok=0;
nl();
nl();
prt(2,get_string(821));
input(sx,12);
if (strchr(sx,'.')==NULL)
strcat(sx,".*");
align(sx);
dliscan();
i=recno(sx);
if (i<0) {
nl();
pl(get_string(89));
closedl();
return;
}
done=0;
while ((!hangup) && (i>0) && (!done)) {
cp=i;
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
nl();
printfileinfo(&u,udir[curdir].subnum);
nl();
prt(5,get_string(822));
ch=ynq();
if (ch=='Q')
done=1;
else if (ch=='Y') {
sprintf(s1,"%s%s",directories[udir[curdir].subnum].path,u.filename);
do {
nl();
nl();
prt(2,get_string(823));
ss=mmkey(1);
if (ss[0]=='?')
dirlist();
} while ((!hangup) && (ss[0]=='?'));
d1=-1;
if (ss[0])
for (i1=0; (i1<num_dirs) && (udir[i1].subnum!=-1); i1++)
if (strcmp(udir[i1].keys,ss)==0)
d1=i1;
if (d1!=-1) {
ok=1;
d1=udir[d1].subnum;
closedl();
dliscan1(d1);
if (recno(u.filename)>0) {
ok=0;
nl();
pl(get_string(824));
}
if (numf>=directories[d1].maxfiles) {
ok=0;
nl();
pl(get_string(825));
}
if (freek1(directories[d1].path)<((double)(u.numbytes/1024L)+3)) {
ok=0;
nl();
pl(get_string(826));
}
closedl();
dliscan();
} else
ok=0;
} else
ok=0;
if (ok && !done) {
--cp;
for (i1=i; i1<numf; i1++) {
SETREC(i1+1);
read(dlf,(void *)&u1,sizeof(uploadsrec));
SETREC(i1);
write(dlf,(void *)&u1,sizeof(uploadsrec));
}
--numf;
SETREC(0);
read(dlf, &u1, sizeof(uploadsrec));
u1.numbytes=numf;
SETREC(0);
write(dlf,(void *)&u1,sizeof(uploadsrec));
ss=read_extended_description(u.filename);
if (ss)
delete_extended_description(u.filename);
closedl();
sprintf(s2,"%s%s",directories[d1].path,u.filename);
dliscan1(d1);
for (i=numf; i>=1; i--) {
SETREC(i);
read(dlf,(void *)&u1,sizeof(uploadsrec));
SETREC(i+1);
write(dlf,(void *)&u1,sizeof(uploadsrec));
}
SETREC(1);
write(dlf,(void *)&u,sizeof(uploadsrec));
++numf;
SETREC(0);
read(dlf, &u1, sizeof(uploadsrec));
u1.numbytes=numf;
if (u.daten>u1.daten) {
u1.daten = u.daten;
dir_dates[d1]=u.daten;
}
SETREC(0);
write(dlf,(void *)&u1,sizeof(uploadsrec));
if (ss) {
add_extended_description(u.filename,ss);
farfree(ss);
}
closedl();
if ((strcmp(s1,s2)!=0) && (exist(s1))) {
d2=0;
if ((s1[1]!=':') && (s2[1]!=':'))
d2=1;
if ((s1[1]==':') && (s2[1]==':') && (s1[0]==s2[0]))
d2=1;
if (d2) {
rename(s1,s2);
unlink(s1);
} else {
if ((b=malloca(16400))==NULL)
return;
d1=open(s1,O_RDONLY | O_BINARY);
d2=open(s2,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
i=read(d1,(void *)b,16384);
while (i>0) {
write(d2,(void *)b,i);
i=read(d1,(void *)b,16384);
}
close(d1);
close(d2);
unlink(s1);
farfree(b);
}
}
nl();
pl(get_string(827));
} else
closedl();
dliscan();
i=nrecno(sx,cp);
}
closedl();
}
int comparedl(uploadsrec *x, uploadsrec *y, int type)
{
switch(type) {
case 0:
return(strcmp(x->filename,y->filename));
case 1:
if (x->daten < y->daten)
return(-1);
else
if (x->daten > y->daten)
return(1);
else
return(0);
case 2:
if (x->daten < y->daten)
return(1);
else
if (x->daten > y->daten)
return(-1);
else
return(0);
}
return(0);
}
void quicksort(int l,int r,int type)
{
register int i,j;
uploadsrec a,a2,x;
i=l; j=r;
SETREC(((l+r)/2));
read(dlf, (void *)&x,sizeof(uploadsrec));
do {
SETREC(i);
read(dlf, (void *)&a,sizeof(uploadsrec));
while (comparedl(&a,&x,type)<0) {
SETREC(++i);
read(dlf, (void *)&a,sizeof(uploadsrec));
}
SETREC(j);
read(dlf, (void *)&a2,sizeof(uploadsrec));
while (comparedl(&a2,&x,type)>0) {
SETREC(--j);
read(dlf, (void *)&a2,sizeof(uploadsrec));
}
if (i<=j) {
if (i!=j) {
SETREC(i);
write(dlf,(void *)&a2,sizeof(uploadsrec));
SETREC(j);
write(dlf,(void *)&a,sizeof(uploadsrec));
}
i++;
j--;
}
} while (i<j);
if (l<j)
quicksort(l,j,type);
if (i<r)
quicksort(i,r,type);
}
void sortdir(int dn, int type)
{
dliscan1(dn);
if (numf>1)
quicksort(1,numf,type);
closedl();
}
void sort_all(int type)
{
int i;
for (i=0; (i<num_dirs) && (udir[i].subnum!=-1) && (!kbhitb()); i++) {
nl();
ansic(1);
outstr(get_string(828));
pl(directories[udir[i].subnum].name);
sortdir(i,type);
}
}
void rename_file(void)
{
char s[81],s1[81],s2[81],*ss,s3[81],ch;
int i,cp;
uploadsrec u;
nl();
nl();
prt(2,get_string(829));
input(s,12);
if (s[0]==0)
return;
if (strchr(s,'.')==NULL)
strcat(s,".*");
align(s);
dliscan();
nl();
strcpy(s3,s);
i=recno(s);
while (i>0) {
cp=i;
SETREC(i);
read(dlf,(void *)&u,sizeof(uploadsrec));
nl();
printfileinfo(&u,udir[curdir].subnum);
nl();
prt(5,get_string(830));
ch=ynq();
if (ch=='Q')
break;
else if (ch=='N') {
i=nrecno(s3,cp);
continue;
}
nl();
prt(2,get_string(72));
input(s,12);
if (!okfn(s))
s[0]=0;
if (s[0]) {
align(s);
if (strcmp(s," . ")) {
strcpy(s1,directories[udir[curdir].subnum].path);
strcpy(s2,s1);
strcat(s1,s);
if (exist(s1))
pl(get_string(831));
else {
strcat(s2,u.filename);
rename(s2,s1);
if (exist(s1)) {
ss=read_extended_description(u.filename);
if (ss) {
delete_extended_description(u.filename);
add_extended_description(s,ss);
farfree(ss);
}
strcpy(u.filename,s);
} else
pl(get_string(832));
}
}
}
nl();
pl(get_string(833));
prt(2,": ");
inputl(s,58);
if (s[0]) {
strcpy(u.description,s);
}
ss=read_extended_description(u.filename);
nl();
nl();
prt(5,get_string(834));
if (yn()) {
nl();
if (ss) {
prt(5,get_string(835));
if (yn()) {
farfree(ss);
delete_extended_description(u.filename);
u.mask &= ~mask_extended;
} else {
u.mask |= mask_extended;
modify_extended_description(&ss,
directories[udir[curdir].subnum].name,u.filename);
if (ss) {
delete_extended_description(u.filename);
add_extended_description(u.filename,ss);
farfree(ss);
}
}
} else {
modify_extended_description(&ss,
directories[udir[curdir].subnum].name,u.filename);
if (ss) {
add_extended_description(u.filename,ss);
farfree(ss);
u.mask |= mask_extended;
} else
u.mask &= ~mask_extended;
}
} else
if (ss) {
farfree(ss);
u.mask |= mask_extended;
} else
u.mask &= ~mask_extended;
SETREC(i);
write(dlf,(void *)&u,sizeof(uploadsrec));
i=nrecno(s3,cp);
}
closedl();
}
int upload_file(char *fn, int dn, char *desc)
{
directoryrec d;
uploadsrec u,u1;
int i,i1,i2,ok,f;
char s[81],s1[81],ff[81];
long l;
double ti;
d=directories[dn];
strcpy(s,fn);
align(s);
strcpy(u.filename,s);
u.ownerusr=usernum;
u.ownersys=0;
u.numdloads=0;
u.filetype=0;
u.mask=0;
if (check_ul_event(dn,&u)) {
outstr(fn);
pl(get_string(836));
} else {
sprintf(ff,"%s%s",d.path,s);
f=open(ff,O_RDONLY | O_BINARY);
if (f<=0) {
if (desc && (*desc)) {
outstr(get_string(837));
outstr(fn);
outstr(": ");
pl(desc);
} else {
outstr(fn);
pl(get_string(838));
}
return(1);
}
l=filelength(f);
u.numbytes=l;
close(f);
strcpy(u.upby, nam(&thisuser,usernum));
strcpy(u.date,date());
if (d.mask & mask_PD)
d.mask=mask_PD;
npr("%s: %4ldk :",u.filename,((u.numbytes)+1023)/1024);
if ((desc) && (*desc)) {
strncpy(u.description,desc,58);
u.description[58]=0;
pl(u.description);
} else
inputl(u.description,58);
if (u.description[0]==0)
return(0);
++thisuser.uploaded;
thisuser.uk += ((l+1023)/1024);
time(&l);
u.daten=l;
for (i=numf; i>=1; i--) {
SETREC(i);
read(dlf,(void *)&u1,sizeof(uploadsrec));
SETREC(i+1);
write(dlf,(void *)&u1,sizeof(uploadsrec));
}
SETREC(1);
write(dlf,(void *)&u,sizeof(uploadsrec));
++numf;
SETREC(0);
read(dlf, &u1, sizeof(uploadsrec));
u1.numbytes=numf;
u1.daten=l;
dir_dates[dn]=l;
SETREC(0);
write(dlf,(void *)&u1,sizeof(uploadsrec));
++status.uptoday;
save_status();
sprintf(s,get_stringx(1,42),u.filename,d.name);
sysoplog(s);
}
return(1);
}
int maybe_upload(char *fn, int dn, char *desc)
{
char s[81];
int i,i1=0,ok=1,ocd;
uploadsrec u;
strcpy(s,fn);
align(s);
i=recno(s);
if (i==-1) {
if (!upload_file(s,udir[dn].subnum,desc))
ok=0;
} else {
SETREC(i);
read(dlf,(void *)&u, sizeof(uploadsrec));
ocd=curdir;
curdir=dn;
printinfo(&u,&i1);
curdir=ocd;
if (i1)
ok=0;
}
return(ok);
}
void upload_files(char *fn, int dn, int type)
/* This assumes the file holds listings of files, one per line, to be
* uploaded. The first word (delimited by space/tab) must be the filename.
* after the filename are optional tab/space separated words (such as file
* size or date/time). After the optional words is the description, which
* is from that position to the end of the line. the "type" parameter gives
* the number of optional words between the filename and description.
* the optional words (size, date/time) are ignored completely.
*/
{
char s[255],*fn1,*desc;
FILE *f;
int ok=1,abort=0,next=0,ok1,i;
dliscan1(udir[dn].subnum);
f=fopen(fn,"r");
if (!f) {
sprintf(s,"%s%s",directories[udir[dn].subnum].path,fn);
f=fopen(s,"r");
}
if (!f) {
outstr(fn);
pl(": not found.");
} else {
while (ok && fgets(s,250,f)) {
if (s[0]<=32)
continue;
ok1=0;
fn1=strtok(s," \t\n");
if (fn1) {
ok1=1;
for (i=0; ok1 && (i<type); i++)
if (strtok(NULL," \t\n")==NULL)
ok1=0;
if (ok1) {
desc=strtok(NULL,"\n");
if (!desc)
ok1=0;
}
}
if (ok1) {
while ((*desc==' ') || (*desc=='\t'))
++desc;
ok=maybe_upload(fn1,dn,desc);
checka(&abort,&next);
if (abort)
ok=0;
}
}
fclose(f);
}
closedl();
}
int uploadall(int dn)
{
int i,i1,f1,maxf,ok;
char s[81],s1[81];
struct ffblk ff;
dliscan1(udir[dn].subnum);
nl();
nl();
strcpy(s,"*.*");
strcpy(s1,(directories[udir[dn].subnum].path));
maxf=directories[udir[dn].subnum].maxfiles;
strcat(s1,s);
f1=findfirst(s1,&ff,0);
ok=1;
i1=0;
while ((f1==0) && (!hangup) && (numf<maxf) && (ok) && (!i1)) {
ok=maybe_upload(ff.ff_name,dn,NULL);
f1=findnext(&ff);
}
closedl();
if (!ok)
pl(get_string(14));
if (numf>=maxf)
pl(get_string(839));
return(i1);
}