home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* 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 {
- char name[14];
- int count;
- long offset;
- struct _files *next;
- };
-
- struct _files *head;
- struct _files *current;
- struct _files *next;
-
- void cdecl main(int argc,char *argv[])
- {
- struct _afile afile;
- char *description;
- int datfh;
- FILE *output;
- unsigned long Pos = 0L;
- word where;
- int max;
- int target = 2;
-
- max = 0;
- datfh = open("FILESBBS.DAT",O_RDONLY|O_BINARY);
- head = current = NULL;
- Pos = tell(datfh);
- if (argc>1)
- target = atoi(argv[1]);
-
- while ((read(datfh,(char *)&afile,sizeof(struct _afile))) == sizeof(struct _afile)) {
- if ((afile.aflag & IS_FILE) && (afile.down_cntr > target) && (afile.dl_priv < _EXTRA)) {
- printf("\n%-13s %3d %lu",afile.name,afile.down_cntr,Pos);
- if (NULL == head) {
- head = (struct _files *) malloc(sizeof(struct _files));
- current = head;
- }
- else {
- current->next = (struct _files *) malloc(sizeof(struct _files));
- current = current->next;
- }
- strcpy(current->name,afile.name);
- current->count = afile.down_cntr;
- if (max < afile.down_cntr)
- max = afile.down_cntr;
- current->offset = Pos;
- current->next = NULL;
- }
- where = afile.descr_len;
- where += afile.upld_by_len;
- where += afile.altpath_len;
- lseek(datfh,((long)(where)),SEEK_CUR);
- Pos = tell(datfh);
- };
- if (head == NULL) {
- printf("\n No files have been downloaded more than %d times!\n",target);
- exit(1);
- }
- output = fopen("COUNT.BBS","wt");
- while (max > target) {
- current = head;
- max--;
- do {
- if (current->count > max) {
- lseek(datfh,current->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 %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);
- current->count = 0;
- free(description);
- }
- current = current->next;
- } while (current != NULL);
- }
- fclose(output);
- close(datfh);
- current = head;
- do {
- next = current->next;
- free(current);
- current = next;
- } while (current != NULL);
- exit(0);
- }
-
-