home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
UTILITY
/
TOPTEN.ARJ
/
UPLD
/
999
/
TOPTEN.C
next >
Wrap
Text File
|
1990-02-05
|
4KB
|
152 lines
/* The following program will make a text file for each of your download
directories in a similar format to the way that WWIV does already, and also
create a text file with Ctrl-C color codes containing the ten files that have
been downloaded the most. It uses your vardec.h header file, so that it should
work even if you have modified and of your structures.
[Insert your favorite Standard Mod Disclaimer here] */
/* TOPTEN.C */
#include <stdio.h>
#include <stdlib.h>
#include <sys\stat.h>
#include <fcntl.h>
#include <string.h>
#include <io.h>
#include "vardec.h"
directoryrec directories[64];
configrec syscfg;
int dlf,curdir,numf,num_dirs,i;
usersubrec udir[64];
typedef struct {
char nam[81];
int num ;
} toptype;
toptype top[9];
char s[81];
FILE *f;
#define SETREC(i) lseek(dlf,((long) (i))*((long)sizeof(uploadsrec)),SEEK_SET);
void dliscan1(int dn)
{
char s[81];
int i;
uploadsrec u;
sprintf(s,"%s%s.DIR",syscfg.datadir,directories[dn].filename);
dlf=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
i=filelength(dlf)/sizeof(uploadsrec);
if (i==0) {
u.numbytes=0;
SETREC(0);
write(dlf,(void *)&u,sizeof(uploadsrec));
} else {
SETREC(0);
read(dlf,(void *)&u,sizeof(uploadsrec));
}
numf=u.numbytes;
}
void closedl()
{
if (dlf>0) {
close(dlf);
dlf=-1;
}
}
void sortlist()
{
int i,i1;
toptype temp;
i=9;
temp.num=top[9].num;
strcpy(temp.nam,top[9].nam);
while ((top[9].num>=top[i].num)&&(i>=0))
{ i--; }
for (i1=8;i1>i;) {
top[i1+1].num=top[i1].num;
strcpy(top[i1+1].nam,top[i1].nam);
i1--;
}
top[i+1].num=temp.num;
strcpy(top[i+1].nam,temp.nam);
}
void searchall()
{
int i,i1;
char s[81],s1[81];
uploadsrec u;
FILE *fp;
for (i=0; (i<num_dirs); i++) {
dliscan1(i);
sprintf(s,"d:\\files\\%s.TXT",directories[i].filename); /* NOTE 1 */
fp=fopen(s,"wt");
for (i1=1; (i1<=numf); i1++) {
SETREC(i1);
read(dlf,(void *)&u,sizeof(uploadsrec));
ltoa((((u.numbytes)+1023)/1024),s1,10);
strcat(s1,"k");
fprintf(fp,"%s: %4s (%2d) : %.50s\n",u.filename,s1,u.numdloads,
u.description);
if (u.numdloads>top[9].num) {
strcpy(top[9].nam,u.filename);
top[9].num=u.numdloads;
sortlist();
}
}
fclose(fp);
closedl();
}
}
void main()
{
strcpy(s,"CONFIG.DAT");
i=open(s,O_RDWR | O_BINARY);
if (i<0) {
printf("%s NOT FOUND.\n",s);
exit(1);
}
read(i,(void *) (&syscfg), sizeof(configrec));
close(i);
strcpy(s,syscfg.datadir);
strcat(s,"DIRS.DAT");
i=open(s,O_RDWR | O_BINARY);
if (i<0) {
printf("%s NOT FOUND.\n",s);
exit(1);
}
num_dirs=(read(i,(void *) (&directories), (64*sizeof(directoryrec))))/
sizeof(directoryrec);
close(i);
for (i=0;i<10;strcpy(top[i].nam,"None"),top[i++].num=0);
searchall();
sprintf(s,"%sxfer.msg",syscfg.gfilesdir); /*NOTE 2 */
f=fopen(s,"wt");
if (!f) exit(1);
fprintf(f,"6Welcome to the Transfer Section.\n\n");
fprintf(f," 4Top Ten Downloaded Files\n\n");
for (i=0;i<10;fprintf(f," 3%2d. 5%-15s 1%d\n",i+1,top[i].nam,top[i].num),i++);
fclose(f);
exit(0);
}
/* Note 1: This is where you would place the path that you wish to use for the
text file listings of your download directories.
Note 2: This is where you would place the path and name of where you wish the
top ten file list to be written. */