home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
bbs_opus
/
topten.arj
/
TOPTEN.C
next >
Wrap
C/C++ Source or Header
|
1991-02-09
|
4KB
|
124 lines
/*--------------------------------------------------------------------------*/
/* COUNT.C by Doug Boone, Reads Opus 1.20 FILESBBS.DAT files and generates */
/* a list of files that have been downloaded recently. You're welcome to */
/* modify the source for your own needs, so long as any programs you */
/* distribute based on it are freely available. (Shareware is freely */
/* available even if it isn't free.) Doug Boone 1:119/5 */
/* 1-21-91 */
/*--------------------------------------------------------------------------*/
#include <dos.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "opus.h"
#include "nfile.h"
struct _files {
long offset;
int count;
};
struct _files top[10];
int low;
int hits;
void cdecl main(int argc,char *argv[])
{
struct _afile afile;
char *description;
int datfh;
FILE *output;
int i,j;
long jump;
long pos;
char outfile[80];
low = 0;
hits = 0;
if (argc <2)
strcpy(outfile,"topten.bbs");
else
strcpy(outfile,argv[1]);
datfh = open("FILESBBS.DAT",O_RDONLY|O_BINARY);
pos = 0L;
while ((read(datfh,(char *)&afile,sizeof(struct _afile))) == sizeof(struct _afile)) {
jump = (long) afile.descr_len;
jump += (long) afile.altpath_len;
jump += (long) afile.upld_by_len;
lseek(datfh,jump,SEEK_CUR);
if ((afile.aflag & IS_FILE) && (afile.down_cntr >= low) && (afile.dl_priv < _EXTRA) ) {
if (hits) {
i = j = 0;
while ((i<10) && (afile.down_cntr < top[i].count))
i++;
if (i<10) {
for (j = 9; j > i; j--) {
top[j].offset = top[j-1].offset;
top[j].count = top[j-1].count;
}
}
}
else
i = 0;
hits++;
if (i<10) {
top[i].count = afile.down_cntr;
top[i].offset = pos;
}
low = top[9].count;
}
pos = tell(datfh);
};
if (!low) {
printf("\n No files have been downloaded!\n");
exit(1);
}
output = fopen(outfile,"wt");
if (hits>10)
hits = 10;
fprintf(output,"\n\n\t\t\tTop %d Downloads\n",hits);
printf("\n\n\t\t\tTop %d Downloads\n",hits);
i = 0;
while (top[i].count) {
lseek(datfh,top[i].offset,SEEK_SET);
read(datfh,(char *)&afile,sizeof(struct _afile));
description = (char *) malloc(afile.descr_len + 1);
memset(description,'\0',(afile.descr_len+1));
read(datfh,description,afile.descr_len);
fprintf(output,"\nCount: %3d Area: %3d File: %-13s Size: %7ld Date: %02d-%02d-%02d\n",
afile.down_cntr,
afile.area_number,
afile.name,
afile.size,
((afile.date>>5) & 0x0f),
(afile.date & 0x1f),
((afile.date >> 9) + 80));
fprintf(output,"%s\n",description);
printf("\nCount: %3d Area: %3d File: %-13s Size: %7ld Date: %02d-%02d-%02d\n",
afile.down_cntr,
afile.area_number,
afile.name,
afile.size,
((afile.date>>5) & 0x0f),
(afile.date & 0x1f),
((afile.date >> 9) + 80));
printf("%s\n",description);
free(description);
i++;
}
fputs("\n\r\n\r",output);
fclose(output);
close(datfh);
exit(0);
}