home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
MYWIVE.ZIP
/
XFEROVL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-21
|
13KB
|
533 lines
#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()
{
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,"Filename to move: ");
input(sx,12);
if (strchr(sx,'.')==NULL)
strcat(sx,".*");
align(sx);
dliscan();
i=recno(sx);
if (i<0) {
nl();
pl("File not found.");
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,"Move this (Y/N/Q)? ");
ch=onek("QNY");
if (ch=='Q')
done=1;
if (ch=='Y') {
sprintf(s1,"%s%s",directories[udir[curdir].subnum].path,u.filename);
do {
nl();
nl();
prt(2,"To which directory? ");
ss=mmkey(1);
if (ss[0]=='?')
dirlist();
} while ((!hangup) && (ss[0]=='?'));
d1=-1;
if (ss[0])
for (i1=0; (i1<64) && (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("Filename already in use in that directory.");
}
if (numf>=directories[d1].maxfiles) {
ok=0;
nl();
pl("Too many files in that directory.");
}
if (freek1(directories[d1].path)<((double)(u.numbytes/1024L)+3)) {
ok=0;
nl();
pl("Not enough disk space to move it.");
}
closedl();
dliscan();
} else
ok=0;
} else
ok=0;
if (ok) {
--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("File moved.");
} 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<64) && (udir[i].subnum!=-1) && (!kbhitb()); i++) {
nl();
ansic(1);
npr("Sorting %s.\r\n",directories[udir[i].subnum].name);
sortdir(i,type);
}
}
void rename_file()
{
char s[81],s1[81],s2[81],*ss,s3[81],ch;
int i,cp;
uploadsrec u;
nl();
nl();
prt(2,"File to rename: ");
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,"Change info for this file (Y/N/Q)? ");
ch=onek("QNY");
if (ch=='Q')
break;
else if (ch=='N') {
i=nrecno(s3,cp);
continue;
}
nl();
prt(2,"New filename? ");
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("Filename already in use; not changed.");
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("Bad filename.");
}
}
}
nl();
pl("New description:");
prt(2,": ");
inputl(s,58);
if (s[0]) {
strcpy(u.description,s);
}
ss=read_extended_description(u.filename);
nl();
nl();
prt(5,"Modify extended description? ");
if (yn()) {
nl();
if (ss) {
prt(5,"Delete it? ");
if (yn()) {
farfree(ss);
delete_extended_description(u.filename);
u.mask &= ~mask_extended;
} else {
u.mask |= mask_extended;
modify_extended_description(&ss);
if (ss) {
delete_extended_description(u.filename);
add_extended_description(u.filename,ss);
farfree(ss);
}
}
} else {
modify_extended_description(&ss);
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)) {
npr("File '%s' deleted by upload event.\r\n",fn);
} else {
sprintf(ff,"%s%s",d.path,s);
f=open(ff,O_RDONLY | O_BINARY);
if (f<=0) {
if (desc && (*desc)) {
npr("ERR: %s: %s\r\n",fn,desc);
} else {
npr("File '%s' doesn't exist.\r\n",fn);
}
return(1);
}
l=filelength(f);
u.numbytes=l;
close(f);
strcpy(u.upby,nam1(&thisuser,usernum,syscfg.systemnumber));
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
inputf(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,"+%s uploaded on %s",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,dn,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(dn);
f=fopen(fn,"r");
if (!f) {
npr("\r\nFile '%s' not found.\r\n\r\n",fn);
} else {
while (ok && fgets(s,250,f)) {
if ((s[0]<=32) || (s[0]>127))
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(dn);
nl();
nl();
strcpy(s,"*.*");
strcpy(s1,(directories[dn].path));
maxf=directories[dn].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("Aborted.");
if (numf>=maxf)
pl("directory full.");
return(i1);
}